-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4 design document for mvp #5
Changes from 6 commits
05e92c5
1441c41
8f9593d
3483e38
4207445
792255a
99fe6e2
6abb8be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# Asteria dApp Design | ||
|
||
## Introduction | ||
This document describes the technical design of the Asteria dApp - the script UTxOs involved, the operations that take place both during the game and in the setup phase, and the necessary validators and minting policies. | ||
|
||
There will be a single script UTxO for the `Pot`, several `PelletState` UTxOs and a `ShipState` UTxO for every user. The `Pot` UTxO locks the ada amount paid by each user when creating a ship, and it's position on the board is always assumed to be (0,0). Both `PelletState` and `ShipState` UTxOs have their positions specified in the datum. In order to identify valid game UTxOs, the admin will deposit a special token in the `PelletState` and `Pot` UTxOs when creating them. | ||
|
||
Each ship will be identified by a `ShipToken`, with a fixed policy id but a token name of their own. This is the token that is minted by the _Ship minting policy_, described in the validators section. | ||
|
||
|
||
## UTxOs specification | ||
|
||
### ShipState UTxO: | ||
|
||
>#### Address | ||
>* Parameterized on admin token, `Pot` validator address and `PelletState` validator address. | ||
> | ||
>#### Datum | ||
>* pos_x: **Int** | ||
>* pos_y: **Int** | ||
>* fuel: **Int** | ||
>* pilot_token: **ByteArray** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be an AssetClass |
||
> | ||
>#### Value | ||
>* minAda | ||
>* `ShipToken` | ||
|
||
### PelletState UTxO: | ||
|
||
>#### Address | ||
>* Parameterized on the admin token. | ||
> | ||
>#### Datum | ||
>* pos_x: **Int** | ||
>* pos_y: **Int** | ||
>* fuel: **Int** | ||
>* ship_token_policy: **PolicyId** | ||
> | ||
>#### Value | ||
>* minAda | ||
>* admin token | ||
|
||
### Pot UTxO: | ||
|
||
>#### Address | ||
>* Parameterized on the admin token. | ||
> | ||
>#### Datum | ||
>* ship_token_policy: **PolicyId** | ||
> | ||
>#### Value | ||
>* minAda | ||
>* reward amount. | ||
>* admin token | ||
> | ||
>Note: the reward amount is updated during the course of the game, whenever a new user joins or reaches the pot. | ||
|
||
|
||
## Transactions | ||
|
||
### Create Pot UTxO: | ||
This transaction creates the unique `Pot` UTxO locking min ada and an admin token. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should indicate that the tx stores in the datum the ship token policy id. Something like: This transaction creates...... and an admin token. It stores in the datum the ShipToken policy id for being able to reference it in the validator. |
||
|
||
 | ||
|
||
|
||
### Create a PelletState UTxO: | ||
Creates one `PelletState` UTxO locking min ada and an admin token, setting in the datum the `pos_x` and `pos_y` coordinates where the pellet will be located on the grid and the `fuel` value equal to some initial value. | ||
|
||
 | ||
|
||
|
||
### Create a ShipState UTxO: | ||
Creates a `ShipState` UTxO locking min ada and a ship token (minted in this tx), specifying in the datum the initial `pos_x` and `pos_y` coordinates of the ship, and setting `fuel` to an initial amount. Also adds to the `Pot` UTxO value the inscription fee paid by the user. | ||
|
||
 | ||
|
||
|
||
### Move a Ship: | ||
Updates the `pos_x`, `pos_y` and `fuel` datum fields of the `ShipState` UTxO by adding the `delta_x` and `delta_y` values specified in the redeemer, and subtracting the fuel amount needed for the displacement. | ||
|
||
 | ||
|
||
|
||
### Gather Fuel: | ||
Updates the `fuel` datum field of both the `ShipState` and `PelletState` UTxOs, adding the `amount` (specified in the redeemer) from the first and subtracting it from the latter. | ||
|
||
 | ||
|
||
|
||
### Collect Rewards: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User wallet must be shown in the inputs, given that the pilot token is needed for this operation. |
||
Subtracts from the `Pot` UTxO 50% of the ada value, and pays that amount to the owner of the ship that reached the pot, together with the min ada locked in the `ShipState` UTxO. The ship token is burnt. | ||
|
||
 | ||
|
||
|
||
### Quit Game: | ||
Pays the min ada locked in the `ShipState` UTxO back to the ship owner and burns the ship token. | ||
|
||
 | ||
|
||
|
||
## Validators & Minting Policies | ||
|
||
### Pot validator: | ||
* Params: admin token. | ||
|
||
#### *AddNewPlayer Redeemer* | ||
* `Pot` output value equals input value plus the inscription fee. | ||
* adminToken is in the input. | ||
* datum doesn't change. | ||
|
||
#### *Collect Redeemer (includes address of the player that reached the pot)* | ||
* ship token is present in some input. | ||
* `Pot` output value has at most 50% adas less than input value. | ||
|
||
### PelletState validator: | ||
* Params: admin token. | ||
|
||
#### *Gather Redeemer (includes gathering amount)* | ||
* ship token is present in some input. | ||
* there is a `ShipState` input with the same x and y datum coordinates as the `PelletState` UTxO. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be checked in the ship validator, not here. The rule should be "ship validator reads the pellet datum, but not the other way" |
||
* the amount specified is not greater than the fuel available in the pellet. | ||
* the amount specified is subtracted from the output `PelletState` fuel datum field, and the other fields remain unchanged. | ||
|
||
### ShipState validator: | ||
* Params: admin token, `Pot` validator address and `PelletState` validator address. | ||
|
||
#### *MoveShip Redeemer (includes delta_x and delta_y displacements)* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ship state output value doesn't change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check that ship token is present? In that case, the ship token policy id should be stored in the datum, to reference it. |
||
* there is a single `ShipState` input. | ||
* there is a single `ShipState` output. | ||
* the `PilotToken` is present in an input. | ||
* the `ShipState` input has enough fuel to move the desired delta. | ||
* the pilot_token datum field is not changed. | ||
* the x and y output datum values are updated as the previous ones (input values) plus the corresponding deltas. | ||
* the output fuel datum field equals the input fuel minus the fuel required for the displacement. | ||
* the distance advanced doesn't exceed the `MAX_SHIP_MOVEMENT_PER_TX`. | ||
* the tx is signed by the ship owner. | ||
|
||
#### *Gather Redeemer (includes gathering amount)* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why we don't check here that only one ship state is in the input/output? |
||
* the amount specified plus the fuel before charging does not exceed the ship's capacity. | ||
* the amount specified is added to the output `ShipState` fuel datum field, and the other fields remain unchanged. | ||
* the `ShipState` output value is the same as the input. | ||
|
||
#### *Collect Redeemer* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you forgot the fundamental check: ship position is (0,0) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also: ship token is burnt (if not here, it should be checked in the pot validator). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also: pilot token is present. |
||
* `Pot` UTxO is input. | ||
* the ada value in the `ShipState` UTxO plus at least 50% of the ada value in the `Pot` UTxO is paid to the ship owner. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not necessary. User could pay wherever they want. The change in the pot is validated in the other validator, so nothing to check about the rewards here. |
||
|
||
#### *Quit Redeemer* | ||
* there is a single `ShipState` input. | ||
* the `PilotToken` is present in an input. | ||
* no `ShipState` output. | ||
* signed by ship owner. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do you know who is the ship owner?? The pilot token is representing this, so no need to this check. |
||
|
||
### Ship minting policy: | ||
* Params: `ShipState` validator address. | ||
|
||
#### MINT: | ||
|
||
***TX:*** | ||
* a single token is minted. | ||
* there is a single `ShipState` output. | ||
* signed by the player joining the game. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this mean? |
||
|
||
***DATUM:*** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's use constants to refer to game parameters, like the "minimum distance", also the fuel capacity, etc. |
||
* the `ShipState` output datum has x and y coordinates such that distance from (0,0) is above the minimum. | ||
* the `ShipState` fuel datum field equals some initial value. | ||
|
||
***VALUE:*** | ||
* the minted token is paid to the `ShipState` validator address. | ||
|
||
#### BURN: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only one token is being burnt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ship validator is in the input |
||
|
||
***TX:*** | ||
* the `ShipState` input is at coordinates (0,0). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add at the end of this paragraph that the "admin token" is also used for parameterizing the pot and fuel validators, so we could have different "versions" of the game, each one with a different admin token.