-
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.
53 implement admin operations for consuming pellets and asteria (#56)
* onchain for consuming Asteria & pellets * offchain for consuming Asteria * Add consumePellet function * Refactor consumeAsteria function to include adminUTxO parameter * fixed network name. * fixed deploy validator check. * updated script refs. * fixed script outputs offchain indexing. --------- Co-authored-by: sofia-bobbiesi <[email protected]>
- Loading branch information
1 parent
d5b4006
commit e21b964
Showing
22 changed files
with
628 additions
and
72 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":"c2badd0df205f93fef630785163b86d6872c2190cf4dd7628a3934b89b56f9bb"} | ||
{"txHash":"4e4d2261932fc8f0c2645c666afe8088fa1919f16394af751c17fd9b39c2064a"} |
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":"87f626782b975a1496d751746b2a78579f9378a4843e00e72c4e9a74f519f24f"} | ||
{"txHash":"c7336f19dca642132eabab80fac385576aec37dc16811b0aaf1bbbe68bca76ee"} |
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":"431aaa1871f6187d3f3ebebafd41ef17f712d3af54c0bba4ff780ed176179603"} | ||
{"txHash":"1ba88f50f12a3415c4651d334a71f5520d8f9ba29037afa2e37b187d435cb28d"} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { admin_token } from "../constants.ts"; | ||
import { consumeAsteria } from "../transactions/consume-asteria.ts"; | ||
import { printTxURL } from "../utils.ts"; | ||
|
||
const asteria_tx_hash = | ||
"b661437c389a4bd8db770145980030af22729f9c03be442329c60389e4168c81"; | ||
const asteria_tx_index = 0; | ||
|
||
const txHash = await consumeAsteria( | ||
admin_token, | ||
asteria_tx_hash, | ||
asteria_tx_index | ||
); | ||
|
||
printTxURL(txHash); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { admin_token } from "../constants.ts"; | ||
import { consumePellet } from "../transactions/consume-pellet.ts"; | ||
import { printTxURL } from "../utils.ts"; | ||
|
||
const pellet_tx_hash = | ||
"65328c6dee12b38ec11049554ba91fa8da9b1f3471a849ef63141883cf2b27cf"; | ||
|
||
const txHash = await consumePellet(admin_token, pellet_tx_hash); | ||
printTxURL(txHash); |
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { admin_token } from "../constants.ts"; | ||
import { admin_token, max_asteria_mining } from "../constants.ts"; | ||
import { mineAsteria } from "../transactions/mine-asteria.ts"; | ||
import { printTxURL } from "../utils.ts"; | ||
|
||
const ship_tx_hash = | ||
"40930f706ba2bb29be56326a3171ffa17e2d7f4e1d9cdeac347e05f3559efcd8"; | ||
"a528f7e89227b16d769e46b81fae20ba223b3f8fd23d82bb61aa6298f53eb5be"; | ||
const asteria_tx_hash = | ||
"6ca378639a51b1283ec2c84deb772f62bff59603eca230aeb711fedee8389d69"; | ||
const max_asteria_mining = 50n; | ||
"aff7cd18d9bf623cdf94544837a450323db2298913b7f6d353e51d9ac109a72a"; | ||
const asteria_tx_index = 1; | ||
|
||
const txHash = await mineAsteria( | ||
admin_token, | ||
max_asteria_mining, | ||
ship_tx_hash, | ||
asteria_tx_hash, | ||
max_asteria_mining | ||
asteria_tx_index | ||
); | ||
|
||
printTxURL(txHash); |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
Data, | ||
toUnit, | ||
TxHash, | ||
Constr, | ||
UTxO, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { fetchReferenceScript, lucidBase } from "../utils.ts"; | ||
import { AssetClassT } from "../types.ts"; | ||
|
||
async function consumeAsteria( | ||
admin_token: AssetClassT, | ||
asteria_tx_hash: TxHash, | ||
asteria_tx_index: number | ||
): Promise<TxHash> { | ||
const lucid = await lucidBase(); | ||
const seed = Deno.env.get("SEED"); | ||
if (!seed) { | ||
throw Error("Unable to read wallet's seed from env"); | ||
} | ||
lucid.selectWalletFromSeed(seed); | ||
|
||
const asteriaRefTxHash: { txHash: string } = JSON.parse( | ||
await Deno.readTextFile("./script-refs/asteria-ref.json") | ||
); | ||
const asteriaRef = await fetchReferenceScript(lucid, asteriaRefTxHash.txHash); | ||
|
||
const asteria: UTxO = ( | ||
await lucid.utxosByOutRef([ | ||
{ | ||
txHash: asteria_tx_hash, | ||
outputIndex: asteria_tx_index, | ||
}, | ||
]) | ||
)[0]; | ||
if (!asteria.datum) { | ||
throw Error("Asteria datum not found"); | ||
} | ||
|
||
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(2, [])); | ||
const tx = await lucid | ||
.newTx() | ||
.readFrom([asteriaRef]) | ||
.collectFrom([asteria], consumeRedeemer) | ||
.collectFrom([adminUTxO]) | ||
.complete(); | ||
|
||
const signedTx = await tx.sign().complete(); | ||
return signedTx.submit(); | ||
} | ||
|
||
export { consumeAsteria }; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
Data, | ||
toUnit, | ||
TxHash, | ||
Constr, | ||
UTxO, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { fetchReferenceScript, lucidBase } from "../utils.ts"; | ||
import { AssetClassT } from "../types.ts"; | ||
|
||
async function consumePellet( | ||
admin_token: AssetClassT, | ||
pellet_tx_hash: TxHash | ||
): Promise<TxHash> { | ||
const lucid = await lucidBase(); | ||
const seed = Deno.env.get("SEED"); | ||
if (!seed) { | ||
throw Error("Unable to read wallet's seed from env"); | ||
} | ||
lucid.selectWalletFromSeed(seed); | ||
|
||
const asteriaRefTxHash: { txHash: string } = JSON.parse( | ||
await Deno.readTextFile("./script-refs/pellet-ref.json") | ||
); | ||
const asteriaRef = await fetchReferenceScript(lucid, asteriaRefTxHash.txHash); | ||
|
||
const pellet: UTxO = ( | ||
await lucid.utxosByOutRef([ | ||
{ | ||
txHash: pellet_tx_hash, | ||
outputIndex: 0, | ||
}, | ||
]) | ||
)[0]; | ||
if (!pellet.datum) { | ||
throw Error("Pellet datum not found"); | ||
} | ||
|
||
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 tx = await lucid | ||
.newTx() | ||
.readFrom([asteriaRef]) | ||
.collectFrom([pellet], consumeRedeemer) | ||
.collectFrom([adminUTxO]) | ||
.complete(); | ||
|
||
const signedTx = await tx.sign().complete(); | ||
return signedTx.submit(); | ||
} | ||
|
||
export { consumePellet }; |
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,4 +1,9 @@ | ||
import { Data, TxHash, toUnit } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { | ||
Data, | ||
TxHash, | ||
UTxO, | ||
toUnit, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { buildDeployValidator } from "../../scripts/deploy.ts"; | ||
import { lucidBase } from "../../utils.ts"; | ||
import { AssetClassT } from "../../types.ts"; | ||
|
@@ -20,11 +25,14 @@ async function spendRefUTxOs(admin_token: AssetClassT): Promise<TxHash> { | |
} | ||
|
||
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 tx = await lucid | ||
.newTx() | ||
.payToAddress(await lucid.wallet.address(), { | ||
[adminTokenUnit]: BigInt(1), | ||
}) | ||
.collectFrom([adminUTxO]) | ||
.collectFrom(refUTxOs, Data.void()) | ||
.attachSpendingValidator(deployValidator) | ||
.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
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
Oops, something went wrong.