Skip to content

Commit

Permalink
68 remove hardcoded minada (#69)
Browse files Browse the repository at this point in the history
* included minADA in asteria rewards (onchain)

* considering changes in ship minADA.

* re-deployed ref scripts.

* included minADA in asteria rewards (offchain)

* removed hardcoded minADA from offchain code.

* updated design document.

* updated check of initial ship value.

* updated spacetime ref script.

* added ship multivalidator section.

* cleaned code.

* added script inputs amount checks.

* updated script refs.
  • Loading branch information
franciscojoray authored Jun 11, 2024
1 parent 861866a commit 523823b
Show file tree
Hide file tree
Showing 25 changed files with 319 additions and 211 deletions.
2 changes: 1 addition & 1 deletion offchain/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const admin_token: AssetClassT = {
name: fromText("asteriaAdmin"),
};
const ship_mint_lovelace_fee = 3_000_000n;
const max_asteria_mining = 100n;
const max_asteria_mining = 50n;
const max_speed: SpeedT = {
distance: 1n,
time: 30n * 1000n, //milliseconds
Expand Down
2 changes: 1 addition & 1 deletion offchain/script-refs/asteria-ref.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"txHash":"dc3f0b00161f7c7db78734fb458d34f591b182991dab9df7bfae3be031a25631"}
{"txHash":"8734a7c57080e71f04618fa59cc94f5216eecda8a3ff2229947087838074aa8d"}
2 changes: 1 addition & 1 deletion offchain/script-refs/pellet-ref.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"txHash":"2ead0a8f05c4ff750b708da18e0f56d72d5d91af313b5a611661d546e78cfa69"}
{"txHash":"7c215f620bdb549479eefec6bc8b97aed6f4b8d48bc99775d5560190475f0b45"}
2 changes: 1 addition & 1 deletion offchain/script-refs/spacetime-ref.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"txHash":"98f9f1163a9395261ee27a0eaded2224d5e953b796bd7aa911c1eed7383bc542"}
{"txHash":"669b5cc55b7c93c1728cb0413a69ad319d87cdfdf650cbef162792554bca328f"}
1 change: 0 additions & 1 deletion offchain/transactions/admin/asteria/create-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async function createAsteria(admin_token: AssetClassT): Promise<TxHash> {
{ inline: asteriaDatum },
{
[adminTokenUnit]: BigInt(1),
lovelace: 2_000_000n,
}
)
.complete();
Expand Down
2 changes: 1 addition & 1 deletion offchain/transactions/admin/deploy/deploy-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function deployAsteria(
.payToContract(
deployAddressBech32,
{ inline: Data.void(), scriptRef: asteriaValidator },
{ lovelace: 2_000_000n }
{}
)
.complete();

Expand Down
2 changes: 1 addition & 1 deletion offchain/transactions/admin/deploy/deploy-pellet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function deployPellet(admin_token: AssetClassT): Promise<TxHash> {
.payToContract(
deployAddressBech32,
{ inline: Data.void(), scriptRef: pelletValidator },
{ lovelace: 2_000_000n }
{}
)
.complete();

Expand Down
2 changes: 1 addition & 1 deletion offchain/transactions/admin/deploy/deploy-spacetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function deploySpacetime(
.payToContract(
deployAddressBech32,
{ inline: Data.void(), scriptRef: spacetimeValidator },
{ lovelace: 2_000_000n }
{}
)
.complete();

Expand Down
1 change: 0 additions & 1 deletion offchain/transactions/admin/pellets/create-pellets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ async function createPellets(
{ inline: pelletDatum },
{
[adminTokenUnit]: BigInt(1),
lovelace: 2_000_000n,
...prize_tokens,
}
);
Expand Down
1 change: 0 additions & 1 deletion offchain/transactions/user/create-ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ async function createShip(
{ inline: shipDatum },
{
[shipTokenUnit]: BigInt(1),
lovelace: 2_000_000n,
}
)
.payToContract(
Expand Down
6 changes: 3 additions & 3 deletions offchain/transactions/user/mine-asteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ async function mineAsteria(
if (!asteria.datum) {
throw Error("Asteria datum not found");
}
const rewards = asteria.assets.lovelace - 2_000_000n;
const rewards = asteria.assets.lovelace;
const minedRewards = BigInt(
(Number(rewards) * Number(max_asteria_mining)) / 100
Math.floor((Number(rewards) * Number(max_asteria_mining)) / 100)
);

const asteriaInputDatum = Data.from<AsteriaDatumT>(
Expand Down Expand Up @@ -120,7 +120,7 @@ async function mineAsteria(
{ inline: asteriaOutputDatum },
{
[adminTokenUnit]: BigInt(1),
lovelace: rewards - minedRewards + 2_000_000n,
lovelace: rewards - minedRewards,
}
)
.payToAddress(await lucid.wallet.address(), {
Expand Down
30 changes: 14 additions & 16 deletions onchain/docs/mvp-design/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Each ship will be identified by a `ShipToken`, with a fixed policy id but a toke

>#### Address
>
>- Parameterized on `AdminToken`, Asteria validator address, pellet validator address, MAX_SPEED, MAX_SHIP_FUEL, FUEL_PER_STEP, INITIAL_FUEL and MIN_ASTERIA_DISTANCE.
>- Parameterized on `AdminToken`, Asteria validator address, pellet validator address, MAX_SPEED, MAX_SHIP_FUEL, FUEL_PER_STEP, INITIAL_FUEL and MIN_ASTERIA_DISTANCE. The validator corresponding to this address is in `spacetime.ak`.
>
>#### Datum
>
Expand Down Expand Up @@ -171,17 +171,20 @@ Pays the admin the value locked in the `PelletState` UTxO.

- `AdminToken` is present in some wallet input.

## Ship Multivalidator

Includes the Spacetime validator and the Shipyard policy.

### SpaceTime validator

- Params: `AdminToken`, Asteria validator address, pellet validator address, MAX_SPEED, MAX_SHIP_FUEL, FUEL_PER_STEP, INITIAL_FUEL and MIN_ASTERIA_DISTANCE.

#### *MoveShip Redeemer (includes delta_x and delta_y displacements)*

- `ShipToken` is present.
- there is a single `ShipState` input.
- the `ShipState` input is the only script input.
- there is a single `ShipState` output.
- the `PilotToken` is present in an input.
- the `ShipState` output value doesn't change.
- the `ShipState` output value only has the `ShipToken` and some amount of ada.
- the `ShipState` input has enough fuel to move the desired delta.
- the distance advanced divided by the tx validity range (posix time) doesn't exceed the maximum speed.
- the `ShipState` input `last_move_latest_time` datum field is not greater than the earliest posix time of the tx validity range.
Expand All @@ -192,34 +195,30 @@ Pays the admin the value locked in the `PelletState` UTxO.

#### *GatherFuel Redeemer (includes gathering amount)*

- `ShipToken` is present.
- there is a single `ShipState` input.
- there are two script inputs: `ShipState` and `PelletState`.
- there is a single `ShipState` output.
- `PilotToken` is present.
- there is a `PelletState` input with the same x and y datum coordinates as the `ShipState` UTxO.
- the `ShipState` output value only has the `ShipToken` and some amount of ada.
- the `PelletState` input has the same x and y datum coordinates as the `ShipState` UTxO.
- the amount specified plus the fuel before charging does not exceed `MAX_SHIP_FUEL` 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.
- `ShipState` datum's `last_move_latest_time` is not greater than the earliest posix time of the tx validity range.

#### *MineAsteria Redeemer*

- there is a single `ShipState` input.
- there are two script inputs: `ShipState` and `AsteriaUTxO`.
- `PilotToken` is present.
- `ShipToken` is present.
- `ShipToken` is burnt.
- `AsteriaUTxO` is input.
- `ShipState` position is (0,0).
- `ShipState` datum's `last_move_latest_time` is not greater than the earliest posix time of the tx validity range.

#### *Quit Redeemer*

- `ShipToken` is present.
- there is a single `ShipState` input.
- the `ShipState` input is the only script input.
- the `PilotToken` is present in an input.
- `ShipToken` is burnt.

### Ship minting policy or "ShipyardPolicy"
### Shipyard policy

- Params: same as SpaceTime validator.

Expand All @@ -235,9 +234,8 @@ Pays the admin the value locked in the `PelletState` UTxO.
- the `ShipState` output datum has the `ship_token_name` set as the name of the `ShipToken`.
- the `ShipState` output datum has the `pilot_token_name` set as the name of the `PilotToken`.
- the `ShipState` output datum has the `last_move_latest_time` set as the latest posix time of the tx validity range.
- the `ShipToken` is paid to the `SpaceTimeScript` validator address.
- the `ShipState` output value only has the `ShipToken` and some amount of ada.

#### *BurnShip Redeemer*

- there is a `ShipState` input.
- only one token is burnt.
Binary file modified onchain/docs/mvp-design/img/consumeAsteria.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified onchain/docs/mvp-design/img/createShip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified onchain/docs/mvp-design/img/mineAsteria.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 4 additions & 21 deletions onchain/src/lib/asteria/utils.ak
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
use aiken/bytearray.{length, take}
use aiken/dict.{keys}
use aiken/list.{any}
use aiken/math
use aiken/transaction.{Output}
use aiken/transaction/credential.{
Address, ScriptCredential, VerificationKeyCredential,
}
use aiken/transaction/value.{AssetName, PolicyId, tokens}

pub fn is_ship_token_in_utxo(utxo: Output, shipyard_policy: PolicyId) -> Bool {
let token_names = keys(tokens(utxo.value, shipyard_policy))
any(token_names, fn(name) { has_prefix("SHIP", name) })
}

pub fn is_pilot_token_in_utxo(
utxo: Output,
shipyard_policy: PolicyId,
pilot_token_name: AssetName,
) -> Bool {
let token_names = keys(tokens(utxo.value, shipyard_policy))
any(token_names, fn(name) { name == pilot_token_name })
}
use aiken/transaction/value.{AssetName}

pub fn has_prefix(prefix: ByteArray, name: AssetName) -> Bool {
take(name, length(prefix)) == prefix
Expand All @@ -34,9 +17,9 @@ pub fn required_fuel(distance: Int, fuel_per_step: Int) -> Int {
distance * fuel_per_step
}

pub fn is_wallet_address(address: Address) -> Bool {
pub fn is_script_address(address: Address) -> Bool {
when address.payment_credential is {
VerificationKeyCredential(_) -> True
ScriptCredential(_) -> False
VerificationKeyCredential(_) -> False
ScriptCredential(_) -> True
}
}
Loading

0 comments on commit 523823b

Please sign in to comment.