-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated design document. * onchain with fuel tokens. * fixed shipyard unit tests. * offchain for creating ship with fuel tokens. * moving ship with fuel tokens. * gathering fuel tokens. * burning remaining fuel tokens when mining asteria. * burning remaining fuel tokens when quitting. * creating pellets with fuel tokens. * removed burn of fuel check when admin consumes pellets. * consuming pellets with fuel tokens. * refactored unit tests. * WIP: fuel policy tests * removed vscode settings file. * fuel policy tests * fixed name * updated plutus.json * updated script refs * fixed typo. * minting no tokens check on GatherFuel redeemer. * updated spacetime script ref.
- Loading branch information
1 parent
523823b
commit 07d712f
Showing
47 changed files
with
3,157 additions
and
2,389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"txHash":"8734a7c57080e71f04618fa59cc94f5216eecda8a3ff2229947087838074aa8d"} | ||
{"txHash":"999eb94c9fa1df83e7a18d074f4da5963c5945ed4410fa9fd402435d35a3991c"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"txHash":"7c215f620bdb549479eefec6bc8b97aed6f4b8d48bc99775d5560190475f0b45"} | ||
{"txHash":"bfc7523659c6e649d72f1931e3d8bfe200bb51d3634b36249b68f96172de0b3b"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"txHash":"669b5cc55b7c93c1728cb0413a69ad319d87cdfdf650cbef162792554bca328f"} | ||
{"txHash":"7853afe4445954b0b09262bfee4031d3100e7d976b0125fb9fea8130d36b1157"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import { | |
TxHash, | ||
Constr, | ||
UTxO, | ||
Script, | ||
fromText, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { fetchReferenceScript, lucidBase } from "../../../utils.ts"; | ||
import { AssetClassT } from "../../../types.ts"; | ||
|
@@ -24,25 +26,39 @@ async function consumePellets( | |
await Deno.readTextFile("./script-refs/pellet-ref.json") | ||
); | ||
const pelletRef = await fetchReferenceScript(lucid, pelletRefTxHash.txHash); | ||
const pelletValidator = pelletRef.scriptRef as Script; | ||
const fuelPolicyId = lucid.utils.mintingPolicyToId(pelletValidator); | ||
const fuelTokenUnit = toUnit(fuelPolicyId, fromText("FUEL")); | ||
|
||
const pellets: UTxO[] = await lucid.utxosByOutRef( | ||
pellets_tx_indexes.map((i) => ({ | ||
txHash: pellets_tx_hash, | ||
outputIndex: i, | ||
})) | ||
); | ||
const totalFuel = pellets.reduce( | ||
(sum, pellet) => sum + pellet.assets[fuelTokenUnit], | ||
0n | ||
); | ||
|
||
const adminTokenUnit = toUnit(admin_token.policy, admin_token.name); | ||
const adminUTxO: UTxO = await lucid.wallet | ||
.getUtxos() | ||
.then((us) => us.filter((u) => u.assets[adminTokenUnit] >= 1n)) | ||
.then((us) => us[0]); | ||
|
||
const consumeRedeemer = Data.to(new Constr(1, [])); | ||
const consumePelletRedeemer = Data.to(new Constr(1, [new Constr(1, [])])); | ||
const burnFuelRedeemer = Data.to(new Constr(1, [])); | ||
const tx = await lucid | ||
.newTx() | ||
.mintAssets( | ||
{ | ||
[fuelTokenUnit]: -totalFuel, | ||
}, | ||
burnFuelRedeemer | ||
) | ||
.readFrom([pelletRef]) | ||
.collectFrom(pellets, consumeRedeemer) | ||
.collectFrom(pellets, consumePelletRedeemer) | ||
.collectFrom([adminUTxO]) | ||
.complete(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
Constr, | ||
UTxO, | ||
Script, | ||
fromText, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { fetchReferenceScript, lucidBase } from "../../utils.ts"; | ||
import { | ||
|
@@ -48,6 +49,7 @@ async function gatherFuel( | |
const pelletRef = await fetchReferenceScript(lucid, pelletRefTxHash.txHash); | ||
const pelletValidator = pelletRef.scriptRef as Script; | ||
const pelletAddressBech32 = lucid.utils.validatorToAddress(pelletValidator); | ||
const fuelPolicyId = lucid.utils.mintingPolicyToId(pelletValidator); | ||
|
||
const ship: UTxO = ( | ||
await lucid.utxosByOutRef([ | ||
|
@@ -70,8 +72,8 @@ async function gatherFuel( | |
}, | ||
]) | ||
)[0]; | ||
if (!ship.datum) { | ||
throw Error("Ship datum not found"); | ||
if (!pellet.datum) { | ||
throw Error("Pellet datum not found"); | ||
} | ||
const pelletAda = pellet.assets.lovelace; | ||
|
||
|
@@ -80,7 +82,6 @@ async function gatherFuel( | |
ShipDatum as unknown as ShipDatumT | ||
); | ||
const shipInfo = { | ||
fuel: shipInputDatum.fuel + gather_amount, | ||
pos_x: shipInputDatum.pos_x, | ||
pos_y: shipInputDatum.pos_y, | ||
ship_token_name: shipInputDatum.ship_token_name, | ||
|
@@ -97,7 +98,6 @@ async function gatherFuel( | |
PelletDatum as unknown as PelletDatumT | ||
); | ||
const pelletInfo = { | ||
fuel: pelletInputDatum.fuel - gather_amount, | ||
pos_x: pelletInputDatum.pos_x, | ||
pos_y: pelletInputDatum.pos_y, | ||
shipyard_policy: shipyardPolicyId, | ||
|
@@ -117,8 +117,14 @@ async function gatherFuel( | |
); | ||
const adminTokenUnit = toUnit(admin_token.policy, admin_token.name); | ||
|
||
const fuelTokenUnit = toUnit(fuelPolicyId, fromText("FUEL")); | ||
const shipFuel = ship.assets[fuelTokenUnit]; | ||
const pelletFuel = pellet.assets[fuelTokenUnit]; | ||
|
||
const shipRedeemer = Data.to(new Constr(1, [new Constr(1, [gather_amount])])); | ||
const pelletRedeemer = Data.to(new Constr(0, [gather_amount])); | ||
const pelletRedeemer = Data.to( | ||
new Constr(1, [new Constr(0, [gather_amount])]) | ||
); | ||
const tx = await lucid | ||
.newTx() | ||
.validFrom(Number(tx_earliest_posix_time)) | ||
|
@@ -130,6 +136,7 @@ async function gatherFuel( | |
{ inline: shipOutputDatum }, | ||
{ | ||
[shipTokenUnit]: BigInt(1), | ||
[fuelTokenUnit]: shipFuel + gather_amount, | ||
lovelace: shipAda, | ||
} | ||
) | ||
|
@@ -138,6 +145,7 @@ async function gatherFuel( | |
{ inline: pelletOutputDatum }, | ||
{ | ||
[adminTokenUnit]: BigInt(1), | ||
[fuelTokenUnit]: pelletFuel - gather_amount, | ||
lovelace: pelletAda, | ||
} | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
Constr, | ||
UTxO, | ||
Script, | ||
fromText, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { fetchReferenceScript, lucidBase } from "../../utils.ts"; | ||
import { | ||
|
@@ -36,6 +37,15 @@ async function mineAsteria( | |
spacetimeRefTxHash.txHash | ||
); | ||
const spacetimeValidator = spacetimeRef.scriptRef as Script; | ||
const shipyardPolicyId = lucid.utils.mintingPolicyToId(spacetimeValidator); | ||
|
||
const pelletRefTxHash: { txHash: string } = JSON.parse( | ||
await Deno.readTextFile("./script-refs/pellet-ref.json") | ||
); | ||
const pelletRef = await fetchReferenceScript(lucid, pelletRefTxHash.txHash); | ||
const pelletValidator = pelletRef.scriptRef as Script; | ||
const fuelPolicyId = lucid.utils.mintingPolicyToId(pelletValidator); | ||
const fuelTokenUnit = toUnit(fuelPolicyId, fromText("FUEL")); | ||
|
||
const asteriaRefTxHash: { txHash: string } = JSON.parse( | ||
await Deno.readTextFile("./script-refs/asteria-ref.json") | ||
|
@@ -44,8 +54,6 @@ async function mineAsteria( | |
const asteriaValidator = asteriaRef.scriptRef as Script; | ||
const asteriaAddressBech32 = lucid.utils.validatorToAddress(asteriaValidator); | ||
|
||
const shipyardPolicyId = lucid.utils.mintingPolicyToId(spacetimeValidator); | ||
|
||
const ship: UTxO = ( | ||
await lucid.utxosByOutRef([ | ||
{ | ||
|
@@ -61,6 +69,7 @@ async function mineAsteria( | |
ship.datum as string, | ||
ShipDatum as unknown as ShipDatumT | ||
); | ||
const shipFuel = ship.assets[fuelTokenUnit]; | ||
|
||
const asterias: UTxO[] = await lucid.utxosAt(asteriaAddressBech32); | ||
if (asterias.length != 1) { | ||
|
@@ -91,6 +100,7 @@ async function mineAsteria( | |
); | ||
|
||
const adminTokenUnit = toUnit(admin_token.policy, admin_token.name); | ||
|
||
const shipTokenUnit = toUnit( | ||
shipyardPolicyId, | ||
shipInputDatum.ship_token_name | ||
|
@@ -102,19 +112,26 @@ async function mineAsteria( | |
|
||
const shipRedeemer = Data.to(new Constr(1, [new Constr(2, [])])); | ||
const asteriaRedeemer = Data.to(new Constr(1, [])); | ||
const burnRedeemer = Data.to(new Constr(1, [])); | ||
const burnShipRedeemer = Data.to(new Constr(1, [])); | ||
const burnFuelRedeemer = Data.to(new Constr(1, [])); | ||
const tx = await lucid | ||
.newTx() | ||
.validFrom(Number(tx_earliest_posix_time)) | ||
.mintAssets( | ||
{ | ||
[shipTokenUnit]: BigInt(-1), | ||
}, | ||
burnRedeemer | ||
burnShipRedeemer | ||
) | ||
.mintAssets( | ||
{ | ||
[fuelTokenUnit]: -shipFuel, | ||
}, | ||
burnFuelRedeemer | ||
) | ||
.collectFrom([ship], shipRedeemer) | ||
.collectFrom([asteria], asteriaRedeemer) | ||
.readFrom([spacetimeRef, asteriaRef]) | ||
.readFrom([spacetimeRef, asteriaRef, pelletRef]) | ||
.payToContract( | ||
asteriaAddressBech32, | ||
{ inline: asteriaOutputDatum }, | ||
|
Oops, something went wrong.