Skip to content

Commit

Permalink
66 add prize tokens to pellets (#67)
Browse files Browse the repository at this point in the history
* onchain for adding prices into pellets.

* offchain for creating pellets with prizes.

* fixed typo.

* updated mvp doc.
  • Loading branch information
franciscojoray authored Jun 4, 2024
1 parent b4814b1 commit 861866a
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 17 deletions.
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":"6c8a843625a261c2be8119b83fca0d504100a1faa8d117e51725187143ed12e6"}
{"txHash":"dc3f0b00161f7c7db78734fb458d34f591b182991dab9df7bfae3be031a25631"}
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":"368f05bd14617c5f78479c3d05affee3ae94dd7f55d2e2a40dabfefdb0137bba"}
{"txHash":"2ead0a8f05c4ff750b708da18e0f56d72d5d91af313b5a611661d546e78cfa69"}
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":"10b9d30439c45d536882304148ff1269b150434d4196cda50062d15611d24458"}
{"txHash":"98f9f1163a9395261ee27a0eaded2224d5e953b796bd7aa911c1eed7383bc542"}
23 changes: 22 additions & 1 deletion offchain/tests/admin/pellets/create-pellets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@ import { admin_token } from "../../../constants.ts";
import { createPellets } from "../../../transactions/admin/pellets/create-pellets.ts";
import { readPelletsCSV } from "./utils.ts";
import { printTxURL } from "../../../utils.ts";
import { AssetClassT } from "../../../types.ts";
import {
Assets,
fromText,
toUnit,
} from "https://deno.land/x/[email protected]/mod.ts";

const tokenA: AssetClassT = {
policy: "255d6456fa68e3d858d80e3168b0d76d57b6c4033c6234e2f0de8499",
name: fromText("tokenA"),
};
const tokenB: AssetClassT = {
policy: "b7341c90d38390ae3a890435559184f01fac24f79df06fd5c02f7fe4",
name: fromText("tokenB"),
};
const tokenAUnit = toUnit(tokenA.policy, tokenA.name);
const tokenBUnit = toUnit(tokenB.policy, tokenB.name);
const prize_tokens: Assets = {
[tokenAUnit]: 1n,
[tokenBUnit]: 2n,
};

const params = await readPelletsCSV("tests/admin/pellets/pellets.csv");
const txHash = await createPellets(admin_token, params);
const txHash = await createPellets(prize_tokens, admin_token, params);
printTxURL(txHash);
3 changes: 3 additions & 0 deletions offchain/transactions/admin/pellets/create-pellets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Assets,
Data,
Script,
toUnit,
Expand All @@ -8,6 +9,7 @@ import { fetchReferenceScript, lucidBase } from "../../../utils.ts";
import { AssetClassT, PelletDatum, PelletDatumT } from "../../../types.ts";

async function createPellets(
prize_tokens: Assets,
admin_token: AssetClassT,
params: { fuel: bigint; pos_x: bigint; pos_y: bigint }[]
): Promise<TxHash> {
Expand Down Expand Up @@ -56,6 +58,7 @@ async function createPellets(
{
[adminTokenUnit]: BigInt(1),
lovelace: 2_000_000n,
...prize_tokens,
}
);
}
Expand Down
7 changes: 4 additions & 3 deletions onchain/docs/mvp-design/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Each ship will be identified by a `ShipToken`, with a fixed policy id but a toke
>
>- minADA
>- `AdminToken`
>- prizeTokens
### Asteria Utxo:

Expand Down Expand Up @@ -86,7 +87,7 @@ This transaction creates the unique `AsteriaUtxo` locking min ada and an `AdminT

### Create a PelletState UTxO

Creates one `PelletState` UTxO locking min ada and an `AdminToken`, 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.
Creates one `PelletState` UTxO locking min ada, an `AdminToken` and some extra tokens ("prize tokens") that ship owners can retrieve besides gathering fuel when they reach the pellet. Also sets the `pos_x` and `pos_y` datum coordinates where the pellet will be located on the grid and the `fuel` value equal to some initial value.

![createPellet diagram](img/createPellet.png)

Expand All @@ -104,7 +105,7 @@ Updates the `pos_x`, `pos_y` and `fuel` datum fields of the `ShipState` UTxO by

### 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.
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. Also allows the ship owner to get any amount of the prize tokens held in the pellet.

![gatherFuel diagram](img/gatherFuel.png)

Expand Down Expand Up @@ -164,7 +165,7 @@ Pays the admin the value locked in the `PelletState` UTxO.
- 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.
- The admin token is present in the input `PelletState`.
- The `PelletState` value doesn't change.
- The admin token is present in the output `PelletState`.

#### *ConsumePellet Redeemer*

Expand Down
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/consumePellet.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/createPellet.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/gatherFuel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions onchain/src/plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
}
}
],
"compiledCode": "59092e010000323232323232323232323232323222323232322323232253330113232323232323232323232533301c3013301e375401e264646464a666040602460446ea80384c8c8c94ccc09c00454cc090078584c94ccc0a0c0ac0084c94ccc0a400454cc098084584c94ccc0a8c0b40084c94ccc09ccdc3a400860526ea80044c8c8c94ccc0a8c084c0b0dd51980880b119191980080099801001192999817181018181baa00114bd6f7b63009bab3034303137540026602c6eacc04cc0c0dd5180998181baa00300e22533303200114a0264a66605e66e3cccdc6240006e352201045348495000375c606a00491104534849500014a2266006006002606a00244a666062002297ae0133032302f30330013300200230340011323232533302d533302d3371202201e294454cc0b92401176861735f656e6f7567685f6675656c203f2046616c73650014a02a66605aa66605a002294454cc0b924117646174756d5f7570646174655f6f6b203f2046616c73650014a02a66605aa66605a004294454cc0b92411976616c75655f6e6f745f6368616e676564203f2046616c73650014a02a66605a006294454cc0b92401216f776e5f696e7075745f6861735f61646d696e5f746f6b656e203f2046616c73650014a029405280a503375e008602c660626ea0cdc0807008181998179baa0243375e6022605c6ea8c044c0b8dd5004180898171baa006301c33301237566020605a6ea8c040c0b4dd50039bae300f302d37540486eb8c040c0b4dd50120a99815a49b565787065637420536f6d65285f29203d0a202020202020202020206c6973742e66696e64280a202020202020202020202020696e707574732c0a202020202020202020202020666e28696e70757429207b0a20202020202020202020202020207574696c732e69735f736869705f746f6b656e5f696e5f7574786f28696e7075742e6f75747075742c2073686970796172645f706f6c696379290a2020202020202020202020207d2c0a202020202020202020202900163301f00102653333330300011001153302902516153302902516153302902516153302902516302d302a37540022a6605092013065787065637420496e6c696e65446174756d286f75745f646174756d29203d206f776e5f6f75747075742e646174756d0016302c302d302d302937540022a6604e0442c60560026600601e466ebcc028c0a0dd5000980518141baa300b302837540042a6604a03e2c60520026600201c466ebcc020c098dd50008019119198008008019129998148008a5eb804c8c94ccc09cc0140084cc0b0008cc0100100044cc010010004c0b4008c0ac004c098c08cdd50070a99810a4920657870656374205370656e64287574786f5f72656629203d20707572706f73650016375c604a604c604c604c0046eb4c090004c080dd500a9bad3022301f375401e2a666038a6660386026603c6ea8cc00c02094ccc0754ccc074c050c07cdd5180118101baa300230203754600660406ea80045288a5013371090001998029bab300330203754600660406ea8004dd7180118101baa017375c600660406ea805c5280a5114a0294454cc0752401296f7074696f6e2e69735f736f6d652861646d696e5f746f6b656e5f696e70757429203f2046616c73650014a04604400246042604400244646600200200644a6660420022980103d87a800013232533301f300500213009330240024bd700998020020009812801181180091119299980e1807180f1baa0011480004dd69811180f9baa00132533301c300e301e37540022980103d87a8000132330010013756604660406ea8008894ccc088004530103d87a8000132323253330213371e00e6eb8c08c00c4c02ccc098dd4000a5eb804cc014014008dd69811801181300118120009980200180111191980080080191299980f8008a60103d87a80001323232533301e3371e00c6eb8c08000c4c020cc08cdd3000a5eb804cc014014008dd59810001181180118108009ba548000dd6180d980e180e0011bac301a0013016375460320046030603200260286ea8004526153301249011856616c696461746f722072657475726e65642066616c7365001365632533301030070011325333015001153301200f1613253330163019002149854cc04c04058c94cccccc06800454cc04c0405854cc04c0405854cc04c040584dd68008a998098080b180b80098099baa00315333010300200115333014301337540062930a998088070b0a998088070b18089baa002370e9001299999980a80088008a998070058b0a998070058b0a998070058b0a998070058b19800801805112999806180198071baa0021325333011001153300e002161323253330130011533010004161323253330150011533012006161323253330170011533014008161325333018301b002149854cc05402458c94cccccc07000454cc0540245854cc0540245854cc0540245854cc054024584dd7000980c800980c80119299999980d0008a998098038b0a998098038b0a998098038b09bad001153301300716301700130170023253333330180011533011005161533011005161533011005161375a0022a6602200a2c602a002602a00464a66666602c0022a6601e0062c2a6601e0062c2a6601e0062c26eb400454cc03c00c58c04c004c03cdd50010a998068008b1b87480014cccccc040004400454cc02401c5854cc02401c5854cc02401c5854cc02401c59240164657870656374205b6f776e5f696e7075745d203d0a202020202020202020206c6973742e66696c74657228696e707574732c20666e28696e70757429207b20696e7075742e6f75747075745f7265666572656e6365203d3d207574786f5f726566207d290049018f657870656374205b6f776e5f6f75747075745d203d0a2020202020202020202066696c746572280a2020202020202020202020206f7574707574732c0a202020202020202020202020666e286f757470757429207b206f75747075742e61646472657373203d3d206f776e5f696e7075742e6f75747075742e61646472657373207d2c0a202020202020202020202900490129657870656374206f75745f646174756d3a2050656c6c6574446174756d203d206f75745f646174756d0049011872656465656d65723a2050656c6c657452656465656d657200490112646174756d3a2050656c6c6574446174756d005734ae7155ceaab9e5573eae815d0aba257481",
"hash": "8f572037c560197fae69b90b2f5a03e5229f546cb92973aad2772433"
"compiledCode": "590941010000323232323232323232323232323222323232322323232253330113232323232323232323232533301c3013301e375401e264646464a666040602460446ea80384c8c8c94ccc09c00454cc090078584c94ccc0a0c0ac0084c94ccc0a400454cc098084584c94ccc0a8c0b40084c94ccc09ccdc3a400860526ea80044c8c8c94ccc0a8c084c0b0dd51980880b119191980080099801001192999817181018181baa00114bd6f7b63009bab3034303137540026602c6eacc04cc0c0dd5180998181baa00300e22533303200114a0264a66605e66e3cccdc6240006e352201045348495000375c606a00491104534849500014a2266006006002606a00244a666062002297ae0133032302f30330013300200230340011323232533302d533302d3371202201e294454cc0b92401176861735f656e6f7567685f6675656c203f2046616c73650014a02a66605aa66605a002294454cc0b924117646174756d5f7570646174655f6f6b203f2046616c73650014a02a66605aa66605a006294454cc0b9241216f776e5f696e7075745f6861735f61646d696e5f746f6b656e203f2046616c73650014a02a66605a004294454cc0b92401226f776e5f6f75747075745f6861735f61646d696e5f746f6b656e203f2046616c73650014a029405280a503375e008602c660626ea0cdc0807008181998179baa024301d33301337566022605c6ea8018dd7180818171baa025375c6022605c6ea8094c070ccc048dd5980818169baa3010302d375400e6eb8c03cc0b4dd50121bae3010302d37540482a66056921b565787065637420536f6d65285f29203d0a202020202020202020206c6973742e66696e64280a202020202020202020202020696e707574732c0a202020202020202020202020666e28696e70757429207b0a20202020202020202020202020207574696c732e69735f736869705f746f6b656e5f696e5f7574786f28696e7075742e6f75747075742c2073686970796172645f706f6c696379290a2020202020202020202020207d2c0a202020202020202020202900163301f00102653333330300011001153302902516153302902516153302902516153302902516302d302a37540022a6605092013065787065637420496e6c696e65446174756d286f75745f646174756d29203d206f776e5f6f75747075742e646174756d0016302c302d302d302937540022a6604e0442c60560026600601e466ebcc028c0a0dd5000980518141baa300b302837540042a6604a03e2c60520026600201c466ebcc020c098dd50008019119198008008019129998148008a5eb804c8c94ccc09cc0140084cc0b0008cc0100100044cc010010004c0b4008c0ac004c098c08cdd50070a99810a4920657870656374205370656e64287574786f5f72656629203d20707572706f73650016375c604a604c604c604c0046eb4c090004c080dd500a9bad3022301f375401e2a666038a6660386026603c6ea8cc00c02094ccc0754ccc074c050c07cdd5180118101baa300230203754600660406ea80045288a5013371090001998029bab300330203754600660406ea8004dd7180118101baa017375c600660406ea805c5280a5114a0294454cc0752401296f7074696f6e2e69735f736f6d652861646d696e5f746f6b656e5f696e70757429203f2046616c73650014a04604400246042604400244646600200200644a6660420022980103d87a800013232533301f300500213009330240024bd700998020020009812801181180091119299980e1807180f1baa0011480004dd69811180f9baa00132533301c300e301e37540022980103d87a8000132330010013756604660406ea8008894ccc088004530103d87a8000132323253330213371e00e6eb8c08c00c4c02ccc098dd4000a5eb804cc014014008dd69811801181300118120009980200180111191980080080191299980f8008a60103d87a80001323232533301e3371e00c6eb8c08000c4c020cc08cdd3000a5eb804cc014014008dd59810001181180118108009ba548000dd6180d980e180e0011bac301a0013016375460320046030603200260286ea8004526153301249011856616c696461746f722072657475726e65642066616c7365001365632533301030070011325333015001153301200f1613253330163019002149854cc04c04058c94cccccc06800454cc04c0405854cc04c0405854cc04c040584dd68008a998098080b180b80098099baa00315333010300200115333014301337540062930a998088070b0a998088070b18089baa002370e9001299999980a80088008a998070058b0a998070058b0a998070058b0a998070058b19800801805112999806180198071baa0021325333011001153300e002161323253330130011533010004161323253330150011533012006161323253330170011533014008161325333018301b002149854cc05402458c94cccccc07000454cc0540245854cc0540245854cc0540245854cc054024584dd7000980c800980c80119299999980d0008a998098038b0a998098038b0a998098038b09bad001153301300716301700130170023253333330180011533011005161533011005161533011005161375a0022a6602200a2c602a002602a00464a66666602c0022a6601e0062c2a6601e0062c2a6601e0062c26eb400454cc03c00c58c04c004c03cdd50010a998068008b1b87480014cccccc040004400454cc02401c5854cc02401c5854cc02401c5854cc02401c59240164657870656374205b6f776e5f696e7075745d203d0a202020202020202020206c6973742e66696c74657228696e707574732c20666e28696e70757429207b20696e7075742e6f75747075745f7265666572656e6365203d3d207574786f5f726566207d290049018f657870656374205b6f776e5f6f75747075745d203d0a2020202020202020202066696c746572280a2020202020202020202020206f7574707574732c0a202020202020202020202020666e286f757470757429207b206f75747075742e61646472657373203d3d206f776e5f696e7075742e6f75747075742e61646472657373207d2c0a202020202020202020202900490129657870656374206f75745f646174756d3a2050656c6c6574446174756d203d206f75745f646174756d0049011872656465656d65723a2050656c6c657452656465656d657200490112646174756d3a2050656c6c6574446174756d005734ae7155ceaab9e5573eae815d0aba257481",
"hash": "4af787b962f1e5430cc9dac37a42a530b6c7d2f43b0831952c5b5add"
},
{
"title": "spacetime.spend",
Expand Down
5 changes: 3 additions & 2 deletions onchain/src/validators/pellet.ak
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ validator(admin_token: AssetClass) {
admin_token.policy,
admin_token.name,
) == 1
let value_not_changed = own_input.output.value == own_output.value
let own_output_has_admin_token =
quantity_of(own_output.value, admin_token.policy, admin_token.name) == 1
let datum_update_ok =
out_datum == PelletDatum { ..datum, fuel: fuel - amount }

and {
has_enough_fuel?,
datum_update_ok?,
value_not_changed?,
own_input_has_admin_token?,
own_output_has_admin_token?,
}
}

Expand Down
9 changes: 3 additions & 6 deletions onchain/src/validators/tests/pellet.ak
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use aiken/transaction.{
use aiken/transaction/credential.{
Address, ScriptCredential, VerificationKeyCredential,
}
use aiken/transaction/value.{
PolicyId, Value, add, from_lovelace, without_lovelace, zero,
}
use aiken/transaction/value.{PolicyId, Value, add, from_lovelace, zero}
use asteria/test_mock as mock
use asteria/test_utils
use asteria/types.{AssetClass, ConsumePellet, PelletDatum, Provide}
Expand Down Expand Up @@ -243,12 +241,11 @@ test provide_no_admin_token() fail {
provide(options)
}

test provide_wrong_value_update() fail {
let default = default_provide_test_options()
test provide_no_admin_token_output() fail {
let options =
ProvideTestOptions {
..default_provide_test_options(),
pellet_output_value: without_lovelace(default.pellet_input_value),
pellet_output_value: from_lovelace(2_000_000),
}
provide(options)
}
Expand Down

0 comments on commit 861866a

Please sign in to comment.