diff --git a/README.md b/README.md index 2481857..0b9ad16 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,19 @@ -# Fresh project +# Okapi -Your new Fresh project is ready to go. You can follow the Fresh "Getting -Started" guide here: https://fresh.deno.dev/docs/getting-started +Okapi is a helper function library written aiken to make drafting cardano smart contracts easier and faster. -### Usage - -Make sure to install Deno: https://deno.land/manual/getting_started/installation - -Then start the project: +add the `lib/okapi-aiken` directory to your aiken project and import it with ``` -deno task start +use okapi-aiken/okapi as ok ``` -This will watch the project directory and restart as necessary. - -in case of deno commad issues: +now you can use any of the okapi helper functions to your validators ``` -export DENO_INSTALL="/home/plutus/.deno" -export PATH="$DENO_INSTALL/bin:$PATH" +validator(o: VerificationKeyCredential) { + fn spend(d: Datum, r: Redeemer, c: ScriptContext) -> Bool { + ok.tx_signed_by(c.transaction, o) + } +} ``` \ No newline at end of file diff --git a/beneficiary.addr b/beneficiary.addr deleted file mode 100644 index e7867c2..0000000 --- a/beneficiary.addr +++ /dev/null @@ -1 +0,0 @@ -addr_test1vr4m7cd94yhymrwcmgs2k6zs00jql9d075ms0dgxjv2tuxqjy82wz \ No newline at end of file diff --git a/beneficiary.sk b/beneficiary.sk deleted file mode 100644 index a9d9d8f..0000000 --- a/beneficiary.sk +++ /dev/null @@ -1 +0,0 @@ -ed25519_sk1c4ehmsgfw2egqdr92lamsvl38aj2f6tues73x4r66sdkauhaxj2scexqs5 \ No newline at end of file diff --git a/components/Button.tsx b/components/Button.tsx deleted file mode 100644 index f593e22..0000000 --- a/components/Button.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { JSX } from "preact"; -import { IS_BROWSER } from "$fresh/runtime.ts"; - -export function Button(props: JSX.HTMLAttributes) { - return ( - - - ) - : ( -
- setTokenName(e.currentTarget.value)} - > - Token Name - - - {tokenName && ( - - )} -
- )} - {lucid && parameterizedContracts && ( - <> -

Redeem

-
-            {parameterizedContracts.redeem.script}
-          
- -

Gift Card

-
-            {parameterizedContracts.giftCard.script}
-          
- -
- setGiftADA(e.currentTarget.value)} - > - ADA Amount - - - - - {lockTxHash && ( - <> -

ADA Locked

- - - {lockTxHash} - - - - - )} - - {unlockTxHash && ( - <> -

ADA Unlocked

- - - {unlockTxHash} - - - )} -
- - )} - - ); -} \ No newline at end of file diff --git a/islands/SoundRig.tsx b/islands/SoundRig.tsx deleted file mode 100644 index c89aef6..0000000 --- a/islands/SoundRig.tsx +++ /dev/null @@ -1,324 +0,0 @@ -import { useEffect, useState } from "preact/hooks"; -import { Blockfrost, Constr, Data, fromText, Lucid } from "lucid/mod.ts"; - -import { Input } from "~/components/Input.tsx"; -import { Button } from "~/components/Button.tsx"; - -import { - AppliedValidators, - applyParams, - LocalCache, - Validators, -} from "~/utils.ts"; - -export interface AppProps { - validators: Validators; -} - -export default function App({ validators }: AppProps) { - const [lucid, setLucid] = useState(null); - const [blockfrostAPIKey, setBlockfrostAPIKey] = useState(""); - const [owner, setOwner] = useState(""); - const [giftADA, setGiftADA] = useState(); - const [lockTxHash, setLockTxHash] = useState(undefined); - const [waitingLockTx, setWaitingLockTx] = useState(false); - const [unlockTxHash, setUnlockTxHash] = useState( - undefined, - ); - const [waitingUnlockTx, setWaitingUnlockTx] = useState(false); - const [parameterizedContracts, setParameterizedContracts] = useState< - AppliedValidators | null - >(null); - - const setupLucid = async (e: Event) => { - e.preventDefault(); - - const lucid = await Lucid.new( - new Blockfrost( - "https://cardano-preprod.blockfrost.io/api/v0", - blockfrostAPIKey, - ), - "Preview", - ); - - const cache = localStorage.getItem("cache"); - - if (cache) { - const { - owner, - parameterizedValidators, - lockTxHash, - }: LocalCache = JSON.parse(cache); - - setOwner(owner); - setParameterizedContracts(parameterizedValidators); - setLockTxHash(lockTxHash); - } - - setLucid(lucid); - }; - - useEffect(() => { - if (lucid) { - window.cardano - .nami - .enable() - .then((wallet) => { - lucid.selectWallet(wallet); - }); - } - }, [lucid]); - - const Metadata222 = Data.Map(Data.Bytes(), Data.Any()); - type Metadata222 = Data.Static; - - const DatumMetadata = Data.Object({ - metadata: Metadata222, - version: Data.Integer({ minimum: 1, maximum: 1 }), - extra: Data.Any(), - }); - type DatumMetadata = Data.Static; - - const initValidators = async (e: Event) => { - e.preventDefault(); - - const owner = await lucid?.utils.paymentCredentialOf("addr_test1vqlhvhcwaddssxnkfugwlvmk69925xjdx7nc20j2nzuc0gq43pzgq").hash!; - - const contracts = applyParams( - owner, - validators, - lucid!, - ); - - setParameterizedContracts(contracts); - }; - - const mintRef = async (e: Event) => { - e.preventDefault(); - - setMintRefTx(true); - - try { - const lovelace = Number(2) * 1000000; - - const assetName = `${parameterizedContracts!.refpolicyId}${ - fromText("refToken") - }`; - - // Action::Mint - const mintRedeemer = Data.to(new Constr(0, [ - new Constr(0, [parameterizedContracts!.refscriptHash]), - new Constr(0, [parameterizedContracts!.lockHash]), - ])); - - const refDatum = Data.to({ - metadata_script_hash: parameterizedContracts!.lockHash, - refCS: parameterizedContracts!.refpolicyId, - }) - - const utxos = await lucid?.wallet.getUtxos()!; - const utxo = utxos[0]; - - const tx = await lucid! - .newTx() - .collectFrom([utxo]) - .attachMintingPolicy(parameterizedContracts!.refmint) - .mintAssets( - { [assetName]: BigInt(1) }, - mintRedeemer, - ) - .payToContract( - parameterizedContracts!.lockAddress, - { inline: Data.void() }, - { "lovelace": BigInt(lovelace) }, - ) - .complete(); - - const txSigned = await tx.sign().complete(); - - const txHash = await txSigned.submit(); - - const success = await lucid!.awaitTx(txHash); - - // Wait a little bit longer so ExhaustedUTxOError doesn't happen - // in the next Tx - setTimeout(() => { - setWaitingLockTx(false); - - if (success) { - localStorage.setItem( - "cache", - JSON.stringify({ - owner, - parameterizedValidators: parameterizedContracts, - lockTxHash: txHash, - }), - ); - - setLockTxHash(txHash); - } - }, 3000); - } catch { - setWaitingLockTx(false); - } - }; - - const redeemGiftCard = async (e: Event) => { - e.preventDefault(); - - setWaitingUnlockTx(true); - - try { - const utxos = await lucid!.utxosAt(parameterizedContracts!.lockAddress); - - const assetName = `${parameterizedContracts!.policyId}${ - fromText(tokenName) - }`; - - // Action::Burn - const burnRedeemer = Data.to(new Constr(1, [])); - - const tx = await lucid! - .newTx() - .collectFrom(utxos, Data.void()) - .attachMintingPolicy(parameterizedContracts!.giftCard) - .attachSpendingValidator(parameterizedContracts!.redeem) - .mintAssets( - { [assetName]: BigInt(-1) }, - burnRedeemer, - ) - .complete(); - - const txSigned = await tx.sign().complete(); - - const txHash = await txSigned.submit(); - - const success = await lucid!.awaitTx(txHash); - - setWaitingUnlockTx(false); - - if (success) { - localStorage.removeItem("cache"); - - setUnlockTxHash(txHash); - } - } catch { - setWaitingUnlockTx(false); - } - }; - - return ( -
- {!lucid - ? ( -
- setBlockfrostAPIKey(e.currentTarget.value)} - > - Blockfrost API Key - - - -
- ) - : ( -
- setTokenName(e.currentTarget.value)} - > - Token Name - - - {tokenName && ( - - )} -
- )} - {lucid && parameterizedContracts && ( - <> -

Redeem

-
-            {parameterizedContracts.redeem.script}
-          
- -

Gift Card

-
-            {parameterizedContracts.giftCard.script}
-          
- -
- setGiftADA(e.currentTarget.value)} - > - ADA Amount - - - - - {lockTxHash && ( - <> -

ADA Locked

- - - {lockTxHash} - - - - - )} - - {unlockTxHash && ( - <> -

ADA Unlocked

- - - {unlockTxHash} - - - )} -
- - )} -
- ); -} \ No newline at end of file diff --git a/lib/okapi-aiken/okapi.ak b/lib/okapi-aiken/okapi.ak index 3496edc..8f45f0e 100644 --- a/lib/okapi-aiken/okapi.ak +++ b/lib/okapi-aiken/okapi.ak @@ -181,13 +181,11 @@ pub fn init_68_datum( pub fn make_token_names(tn) -> List { let tokenName: value.AssetName = tn - trace string.from_bytearray(tokenName) let refTn = tokenName - trace string.from_bytearray(refTn) let userTn = tokenName - trace string.from_bytearray(userTn) + [refTn, userTn] } @@ -263,4 +261,3 @@ pub fn datum_match(in: Output, out: Output) -> Bool { // _ -> False // } // }) - diff --git a/lib/okapi-aiken/tests.ak b/lib/okapi-aiken/tests.ak index daeb0da..d1d0dc1 100644 --- a/lib/okapi-aiken/tests.ak +++ b/lib/okapi-aiken/tests.ak @@ -3,6 +3,7 @@ use aiken/transaction.{ Input, NoDatum, OutputReference, ScriptContext, Spend, Transaction, TransactionId, placeholder, } +use aiken/transaction/credential as c use aiken/transaction/value use okapi_aiken/okapi as ok use tests/tools as t @@ -26,6 +27,10 @@ test get_spend_ref() { ok.get_spend_ref(ctx) == placeholder_utxo } +// test not_spend_ref() { +// let placeholder_utxo = OutputReference() +// } + test get_own_input() { let addr = t.test_script_address(#"face") let placeholder_utxo = @@ -110,8 +115,8 @@ test get_own_outputs() { purpose: Spend(placeholder_utxo), transaction: placeholder() |> fn(transaction) { - Transaction { ..transaction, inputs: [pinput], outputs: outs } - }, + Transaction { ..transaction, inputs: [pinput], outputs: outs } + }, } ok.get_own_outputs(ctx) == outs } @@ -136,8 +141,8 @@ test has_one_sigleton_output() { purpose: Spend(placeholder_utxo), transaction: placeholder() |> fn(transaction) { - Transaction { ..transaction, inputs: [pinput], outputs: outs } - }, + Transaction { ..transaction, inputs: [pinput], outputs: outs } + }, } ok.has_own_singleton_output(ctx) } @@ -166,8 +171,8 @@ test has_more_singleton_output() { purpose: Spend(placeholder_utxo), transaction: placeholder() |> fn(transaction) { - Transaction { ..transaction, inputs: [pinput], outputs: outs } - }, + Transaction { ..transaction, inputs: [pinput], outputs: outs } + }, } ok.has_own_singleton_output(ctx) == False } @@ -192,8 +197,8 @@ test get_own_singleton_output() { purpose: Spend(placeholder_utxo), transaction: placeholder() |> fn(transaction) { - Transaction { ..transaction, inputs: [pinput], outputs: outs } - }, + Transaction { ..transaction, inputs: [pinput], outputs: outs } + }, } ok.get_own_singleton_output(ctx) == t.test_output( addr, @@ -201,3 +206,145 @@ test get_own_singleton_output() { NoDatum, ) } + +test get_own_singleton_output_value() { + let addr = t.test_script_address(#"face") + let outs = + [t.test_output(addr, value.from_lovelace(5), NoDatum)] + let oref = + OutputReference { transaction_id: TransactionId(""), output_index: 0 } + let tinput = + Input { + output_reference: oref, + output: t.test_output(addr, value.from_lovelace(5), NoDatum), + } + let ctx = + ScriptContext { + purpose: Spend(oref), + transaction: placeholder() + |> fn(transaction) { + Transaction { ..transaction, inputs: [tinput], outputs: outs } + }, + } + ok.get_own_singleton_output_value(ctx) == value.from_lovelace(5) +} + +test keep_own_lovelace_value() { + let addr = t.test_script_address(#"face") + let outs = + [t.test_output(addr, value.from_lovelace(5), NoDatum)] + let oref = + OutputReference { transaction_id: TransactionId(""), output_index: 0 } + let tinput = + Input { + output_reference: oref, + output: t.test_output(addr, value.from_lovelace(5), NoDatum), + } + let ctx = + ScriptContext { + purpose: Spend(oref), + transaction: placeholder() + |> fn(transaction) { + Transaction { ..transaction, inputs: [tinput], outputs: outs } + }, + } + ok.keep_own_lovelace_value(ctx) +} + +test contains_single_token_of() { + let p = #"beef" + let tn = #"face" + let value = value.from_asset(p, tn, 1) + + ok.contains_single_token_of(value, p) +} + +test contains_only_lovelace() { + let v = value.from_lovelace(5) + + ok.contains_only_lovelace(v) +} + +test tx_signed_by() { + let s = t.test_address(#"face") + let sigs = t.test_signatories() + let t = + placeholder() + |> fn(transaction) { Transaction { ..transaction, extra_signatories: sigs } } + ok.tx_signed_by(t, #"face") +} + +test tx_signed_by_no_list() { + let s = t.test_address(#"face") + let sigs = t.test_signatories() + let i = 1 + let t = + placeholder() + |> fn(transaction) { + Transaction { ..transaction, extra_signatories: t.test_signatories() } + } + ok.tx_signed_by_no_list(t, i, sigs) +} + +test tx_signed_by_list() { + let sigs = t.test_signatories() + + let t = + placeholder() + |> fn(transaction) { + Transaction { ..transaction, extra_signatories: t.test_signatories() } + } + ok.tx_signed_by_list(t, sigs) +} + +// FIX ME // +// test token_metadata_name_check() { +// let in = +// ok.TokenMetadata { name: #"face", image: #"cafe", mediaType: #"dead" } +// let out = +// ok.TokenMetadata { name: #"face", image: #"beef", mediaType: #"dead" } +// ok.token_metadata_name_check(in, out) +// } + +// compare_token_names +// init_68_datum + +test make_token_names() { + let tn = "face" + ok.make_token_names(tn) == ["face", "face"] +} + +test make_token_prefix() { + ok.make_token_prefix() == [#"000643b0", #"000de140"] +} + +test token_pair_prefix() { + let tn = #"face" + ok.token_pair_prefix(tn) == [#"000643b0face", #"000de140face"] +} + +test make_fraction_prefix() { + ok.make_fraction_prefix() == [#"000643b0", #"001bc280"] +} + +test fraction_pair_prefix() { + let tn = #"face" + ok.fraction_pair_prefix(tn) == [#"000643b0face", #"001bc280face"] +} + +test has_one_singleton_asset_less() { + let p: value.PolicyId = #"dead" + let t: value.AssetName = #"cafe" + let in = value.from_asset(p, t, 2) + let out = value.from_asset(p, t, 1) + + ok.has_one_singleton_asset_less(in, out) +} + +test how_many_tokens() { + let p: value.PolicyId = #"dead" + let t: value.AssetName = #"cafe" + let v = value.from_asset(p, t, 2) + + ok.how_many_tokens(v, p) == 2 +} diff --git a/lib/tests/tools.ak b/lib/tests/tools.ak index 5fe7061..7b690bb 100644 --- a/lib/tests/tools.ak +++ b/lib/tests/tools.ak @@ -63,7 +63,7 @@ pub fn test_transaction() -> Transaction { output_index: 1, }, output: Output { - address: test_address(#"face"), + address: test_script_address(#"face"), value: value.from_lovelace(5), datum: NoDatum, reference_script: None, @@ -72,7 +72,7 @@ pub fn test_transaction() -> Transaction { ], outputs: [ Output { - address: test_address(#"face"), + address: test_script_address(#"face"), value: value.from_lovelace(5), datum: NoDatum, reference_script: None, diff --git a/main.ts b/main.ts deleted file mode 100644 index 675f529..0000000 --- a/main.ts +++ /dev/null @@ -1,13 +0,0 @@ -/// -/// -/// -/// -/// - -import "$std/dotenv/load.ts"; - -import { start } from "$fresh/server.ts"; -import manifest from "./fresh.gen.ts"; -import config from "./fresh.config.ts"; - -await start(manifest, config); diff --git a/owner.addr b/owner.addr deleted file mode 100644 index 0233122..0000000 --- a/owner.addr +++ /dev/null @@ -1 +0,0 @@ -addr_test1vqlhvhcwaddssxnkfugwlvmk69925xjdx7nc20j2nzuc0gq43pzgq \ No newline at end of file diff --git a/owner.sk b/owner.sk deleted file mode 100644 index 978f215..0000000 --- a/owner.sk +++ /dev/null @@ -1 +0,0 @@ -ed25519_sk16dqkksjz64sevys5q8glcj0h3xjrfezgkzd5yzzr6selghu3nrzqfv809v \ No newline at end of file diff --git a/param.ts b/param.ts deleted file mode 100644 index b6ea4ce..0000000 --- a/param.ts +++ /dev/null @@ -1,294 +0,0 @@ -import { - Blockfrost, - C, - Data, - Lucid, - SpendingValidator, - TxHash, - fromHex, - toHex, - toUnit, - Constr, - MintingPolicy, - fromText, - mintingPolicyToId, - applyParamsToScript, - applyDoubleCborEncoding, - attachSpendingValidator, - UTxO, -} from "https://deno.land/x/lucid@0.10.6/mod.ts"; -import * as cbor from "https://deno.land/x/cbor@v1.4.1/index.js"; - -// deno run --allow-net --allow-read --allow-env inc.ts - -// assumes vesting validator is [0] if validators list - -const lucid = await Lucid.new( - new Blockfrost( - "https://cardano-preview.blockfrost.io/api/v0", - "previewLtKSAAN8MBR9TjuZwIVwvBnFJ1YKB6Y7", - ), - "Preview", -); - -lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./owner.sk")); -// lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./beneficiary.sk")); - -const ownerPKH = lucid.utils.getAddressDetails(await Deno.readTextFile("owner.addr")) -.paymentCredential.hash; - -const authm = await readAuthValidator() -const authCS = lucid.utils.mintingPolicyToId(authm) -const ref = await readRefValidator() -const mint = await readMintValidator() -const mintCS = lucid.utils.mintingPolicyToId(mint) -const lock = await readLockValidator() -const vest = await readVestValidator() - -// --- Supporting functions - -async function readAuthValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[1]; - return { - type: "PlutusV2", - script: applyParamsToScript(applyDoubleCborEncoding(validator.compiledCode), [ownerPKH]), - }; -} - -async function readRefValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0]; - return { - type: "PlutusV2", - script: applyParamsToScript(applyDoubleCborEncoding(validator.compiledCode), [ownerPKH, authCS]), - }; -} - -async function readMintValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[3]; - return { - type: "PlutusV2", - script: applyParamsToScript(applyDoubleCborEncoding(validator.compiledCode), [ownerPKH]), - }; -} - -async function readVestValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[4]; - return { - type: "PlutusV2", - script: applyParamsToScript(applyDoubleCborEncoding(validator.compiledCode), [ownerPKH]), - }; -} - -async function readLockValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[2]; - return { - type: "PlutusV2", - script: applyParamsToScript(applyDoubleCborEncoding(validator.compiledCode), [ownerPKH, mintCS]), - }; -} - - -const ownerAddress = await Deno.readTextFile("./owner.addr"); - -const beneficiaryPublicKeyHash = - lucid.utils.getAddressDetails(await Deno.readTextFile("beneficiary.addr")) -.paymentCredential.hash; - -const beneficiaryAddress = await Deno.readTextFile("./beneficiary.addr"); - -const Metadata222 = Data.Map(Data.Bytes(), Data.Any()); -type Metadata222 = Data.Static; - -const DatumMetadata = Data.Object({ - metadata: Metadata222, - version: Data.Integer({ minimum: 1, maximum: 99 }), -}); -type DatumMetadata = Data.Static; - -const metadata = { - "name": "Rose Riot", - "image": "ipfs://QmZBdUTpsZjLFfQvJ7bgcZNpEJqTTHUCtjEnqJSp22gXfi", - "mediaType": "image/png", -} - -const newMetadata = { - "name": "Nose Riot", - "image": "ipfs://QmZBdUTpsZjLFfQvJ7bgcZNpEJqTTHUCtjEnqJSp22gXfi", - "mediaType": "image/png", -} - -const metadataDatum = Data.to({ - metadata: Data.castFrom(Data.fromJson(metadata), Metadata222), - version: BigInt(1), -}, DatumMetadata) - -const newMetaDatum = Data.to({ - metadata: Data.castFrom(Data.fromJson(newMetadata), Metadata222), - version: BigInt(1), -}, DatumMetadata) - -const rHash = lucid.utils.validatorToScriptHash(ref) -const rAddress = lucid.utils.validatorToAddress(ref) - -const lDatum = metadataDatum -const lHash = lucid.utils.validatorToScriptHash(lock) -const lAddress = lucid.utils.validatorToAddress(lock) - -const vDatum = Data.to(new Constr(0, [BigInt(1000)])) -const vHash = lucid.utils.validatorToScriptHash(vest) -const vAddress = lucid.utils.validatorToAddress(vest) - -const aDatum = Data.to(new Constr(0, [lHash])) - -console.log(lHash) - -const tokenName = fromText("SRFX20") - -const redeemer = Data.to(new Constr(0, [BigInt(1), BigInt(0)])) - -const mintRedeemer = Data.to(new Constr(0, [BigInt(1), BigInt(1000), tokenName])) - -// const lockRedeemer = Data.to(new Constr(0, [BigInt(1), newMetadata])) - -// const splitUtxo1 = await splitUtxos() - -// await lucid.awaitTx(splitUtxo1) - -// console.log(`Transactions Split! -// Tx Hash: ${splitUtxo1} -// `) - -const authTx = await authMint(); - -await lucid.awaitTx(authTx); - -console.log(`Transaction Outputs - Tx Hash: ${authTx} - PolicyId: ${authCS} -`); - -const txLock = await mintTokens(); - -await lucid.awaitTx(txLock); - -console.log(`Transaction Outputs - Tx Hash: ${txLock} - Address: ${lAddress} -`); - -const txRedeem = await userRedeem(); - -await lucid.awaitTx(txRedeem) - -console.log(`Transaction Outputs - Tx Hash: ${txRedeem} - Signer: ${ownerPKH} -`); - -const txUpdate = await updateMetadata(); - -await lucid.awaitTx(txUpdate) - -console.log(`Transaction Outputs - TxHash: ${txUpdate} - Signer: ${mintCS} -`) - -// --- Supporting functions - -async function authMint() { - const tx = await lucid - .newTx() - .mintAssets({ - [toUnit(authCS, fromText("ref10"))]: BigInt(1) - }, redeemer) - .attachMintingPolicy(authm) - .payToContract(rAddress, { inline: aDatum }, { [toUnit(authCS, fromText("ref10"))]: BigInt(1)}) - .addSignerKey(ownerPKH) - .complete() - - const signedTx = await tx.sign().complete() - - return signedTx.submit() -} - -async function mintTokens() { - const refUtxos = await lucid.utxosAtWithUnit(rAddress, [toUnit(authCS, fromText("ref10"))]) - console.log(refUtxos) - - const tx = await lucid - .newTx() - .readFrom(refUtxos) - .mintAssets({ - [toUnit(mintCS, tokenName, 100)]: BigInt(1), - [toUnit(mintCS, tokenName, 444)]: BigInt(1000) - }, mintRedeemer) - .attachMintingPolicy(mint) - .payToContract(lAddress, { inline: lDatum }, { [toUnit(mintCS, tokenName, 100)]: BigInt(1) }) - .payToContract(vAddress, { inline: vDatum }, { [toUnit(mintCS, tokenName, 444)]: BigInt(1000) }) - .addSignerKey(ownerPKH) - .complete(); - - const signedTx = await tx.sign().complete(); - - return signedTx.submit(); -} - -async function updateMetadata() { - const utxos = await lucid.utxosAtWithUnit(lAddress, [toUnit(mintCS, tokenName, 100)]) - - const utxo = utxos[0] - console.log(utxo) - const lDatum2 = newMetaDatum - - const tx = await lucid - .newTx() - .collectFrom([utxo], redeemer) - .attachSpendingValidator(lock) - .payToContract(lAddress, { inline: lDatum2 }, { [toUnit(mintCS, tokenName, 100)]: BigInt(1) }) - .addSignerKey(ownerPKH) - .complete() - - const signedTx = await tx.sign().complete() - - return signedTx.submit() -} - -async function userRedeem() { - - const unit = toUnit(mintCS, tokenName, 444) - const utxos: [UTxO] = await lucid.utxosAtWithUnit(vAddress, [toUnit(mintCS, tokenName, 444)]) - const utxo: UTxO = utxos[0] - const value = await utxo.assets[unit] - const outValue = value - 1n - - console.log(value) - - const tx = await lucid - .newTx() - .collectFrom([utxo], redeemer) - .attachSpendingValidator(vest) - .payToAddress(beneficiaryAddress, { [toUnit(mintCS, tokenName, 444)]: 1n }) - .payToContract(vAddress, vDatum, { [toUnit(mintCS, tokenName, 444)]: outValue }) - // .addSignerKey(ownerPKH) - .complete() - - const signedTx = await tx.sign().complete() - - return signedTx.submit() -} - -async function splitUtxos() { - const tx = await lucid - .newTx() - .payToAddress(ownerAddress, {lovelace: 100000000n}) - .payToAddress(ownerAddress, {lovelace: 100000000n}) - .payToAddress(ownerAddress, {lovelace: 100000000n}) - .payToAddress(ownerAddress, {lovelace: 100000000n}) - .payToAddress(ownerAddress, {lovelace: 100000000n}) - .complete() - - const signedTx = await tx.sign().complete() - - return signedTx.submit() -} \ No newline at end of file diff --git a/plutus.json b/plutus.json deleted file mode 100644 index a2d2925..0000000 --- a/plutus.json +++ /dev/null @@ -1,268 +0,0 @@ -{ - "preamble": { - "title": "rhystmorgan/okapi-aiken", - "description": "Aiken contracts for project 'rhystmorgan/okapi-aiken'", - "version": "0.0.0", - "plutusVersion": "v2", - "compiler": { - "name": "Aiken", - "version": "v1.0.20-alpha+49bd4ba" - }, - "license": "Apache-2.0" - }, - "validators": [ - { - "title": "param.authl", - "datum": { - "title": "d", - "schema": { - "$ref": "#/definitions/param~1AuthDatum" - } - }, - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/param~1AuthAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - }, - { - "title": "cs", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "5903780100003232323232323232322322322223232533300c323232533300f3370e90010010a9998079980098019806803005899919191919191919119b89300237566012602c601000260046eacc024c058c94ccc064cdc39803998029bac30043017300d30170023006002480084c94ccc068cdc3a400060320022603e60300022c64a66603a002298103d87a800013374a90001980f180f800a5eb80cc014dd61802180b9806980b8010008b1802800919199119299980d99b874800800440084dd69810180c801980c80119299980c99b8748008004530103d87a8000132323300100100222533301f00114c103d87a800013232323253330203371e9110000213374a9000198121ba80014bd700998030030019bad3021003375c603e004604600460420026eacc078c05c008c05c0052000323300100100222533301c00114c0103d87a8000132323232533301d3371e9110000213374a9000198109ba60014bd700998030030019bab301e003375c60380046040004603c002460366038603800244646600200200644a666036002297ae013232533301a3232533301c3370e9001000899b8f007375c604260340042940c068004c038c060c038c0600084cc078008cc0100100044cc010010004c07c008c0740048c8c94ccc058cdc3a4004602a00226eb8c06cc05000458c024c04cc024c04c004c010004c004004894ccc05800452000133700900119801001180c80091919299980999b8748000c0480044c8c8c8c01cc050008c04c004c064004c04400458cc88c8cc00400400c894ccc064004530103d87a80001323253330183375e6018602c00400a266e9520003301c0024bd70099802002000980e801180d8009bac30063010300630100020013253330123370e900118088008980b98080008b180118078009180a980b0008030a501330013003300d00600b223322323300100100322533301700114a026464a66602c66e3c008014528899802002000980d8011bae30190013758602a602c602c602c602c602c602c602c602c601c0040026eb4c004c02c0148c0480045261365632533300c3370e90000008991919192999809980b0010a4c2c6eb4c050004c050008dd6980900098050020b180500199299980599b87480000044c8c94ccc040c04c00852616375c602200260120082c60120066eb8004dd7000918029baa001230033754002ae6955ceaab9e5573eae815d0aba201", - "hash": "90cc4e54e154a227c5ade01fb84badf5d9cbb2cbc5b92fadc21feb8d" - }, - { - "title": "param.authm", - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/param~1AuthAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "58cf0100003232323232323223222325333007323232533300a3370e9001001099800980198048028038998009801980480280391199119198008008019129998090008a501323253330113371e00400a29444cc010010004c054008dd718098009bac300f30103010301030103010301030103010300a002001375a6002600e0084601800229309b2b19299980399b87480000044c8c8c8c94ccc038c04000852616375a601c002601c0046eb4c030004c01800c58c01cdd50011bae001230043754002ae6955ceaab9e5573eae855d11", - "hash": "c1dab3c19731fab8507aba1ca16fc4a1fc48572d98620747a8249432" - }, - { - "title": "param.plock", - "datum": { - "title": "_d", - "schema": { - "$ref": "#/definitions/Data" - } - }, - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/param~1LockingAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - }, - { - "title": "cs", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "58d50100003232323232323223223222232533300a323232533300d3370e90010010998009801980600280509980098019806002805111991191980080080191299980a8008a501323253330143371e00400a29444cc010010004c060008dd7180b0009bac301230133013301330133013301330133013300d002001375a600260140084601e00229309b2b19299980519b87480000044c8c8c8c94ccc044c04c00852616375a602200260220046eb4c03c004c02400c58c028dd50011bae001375c002460086ea80055cd2ab9d5573caae7d5d0aba201", - "hash": "e168ff4ba1550d41c1f3da33c411b36acb439712dc9cc3620f0c00ec" - }, - { - "title": "param.pmint", - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/param~1MintAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "5905300100003232323232323232322322232533300832323232533300c3370e9000180580089919191919191919191919191919299980e981000109919191919299980f9991199119198008008019129998140008a501323253330273371e00400a29444cc010010004c0b0008dd718150009bac302630273027302730273027302730273027301f0020013001301d01901b13232323232323253330263370e9001003899299981399b8748000c0980044c8c8c8c8c8c94ccc0b4cdc3a4008605800226464646464a66606466002042464a66606866e1d200430330011323253330363375e6030606800866e9520003303a3374a90011981d180c181a00425eb80cc0e9300103d87a80004bd70099b8733300637566022606800805203890010a50303a001303200116300f3031001153330323300102123370e6660066eacc038c0c400409805cdd6980718188170991919299981aa99981aa99981a99b8701a480084cdc380c1bad3010303303014a02004294040045281980900c19809801240046602203266024002900018079bae300e303002d161622323300100100322533303800114a026464a66606e600a00429444cc010010004c0f0008c0e8004888c8cc88c94ccc0dccdc3a4004002200426eb4c0f0c0d400cc0d4008c94ccc0d4cdc3a40040022980103d87a8000132323300100100222533303b00114c103d87a8000132323232533303c3371e014004266e95200033040375000297ae0133006006003375a607a0066eb8c0ec008c0fc008c0f4004dd5981d18198011819800a40006603c00600464a66606066e1d20000011323253330353038002149858dd7181b00098170010b1817000981980098158008b18041815000981800098180009813800981680098128008b1929998150008a60103d87a800013374a9000198159816000a5eb80dd61800981200e89919192999814a999814a99981499b8700e480044cdc380619b8148000dd6980218138120a50100214a020022940cc018030cc01c00920023300500d3300600148000c00cdd718011812010918159816000918151815981580091919199800800a5eb850544000643b000810544001bc2800000111129998158010a5eb804c8c94ccc0b400c52f5c026605c6ea4cdc50011bae302f0033330050050013030003302f003375c605a004660506ea4004cc0a0dd4800a5eb80894ccc090cdc3a40006046002266e3c008dd7181498110008b180080091129998130010a6103d87a80001323253330253370e0069000099ba548000cc0a4dd480125eb804ccc014014004cdc0801a400460540066eb8c0a0008dd69800980e80d0b118120009bad301f004375c603a0066eb4c074010dd7180d8018b180f000980f001180e00099199119299980d19b874800800440084dd5980f980c001980c0011980100080525eb7bdb180c8cc00400400c894ccc06c00452f5bded8c0264646464a66603866e3d2201000021003133020337606ea4008dd3000998030030019bab301d003375c6036004603e004603a00244646600200200644a6660380022980103d87a8000132323232533301d3371e00e004266e95200033021374c00297ae01330060060033756603c0066eb8c070008c080008c078004dd5980c800980c800980c0011bac301600130160013015001300c005375c602400260140022c60200026020004601c002600c00429309b2b19299980419b87480000044c8c8c8c8c8c94ccc044c05000852616375c602400260240046eb4c040004c040008dd6980700098030018b18030011bae001230053754002460066ea80055cd2ab9d5573caae7d5d02ba15745", - "hash": "002f92bb0728fd7cf69cb888da1dbcb47b2f3c1646be76860b431583" - }, - { - "title": "param.pvest", - "datum": { - "title": "d", - "schema": { - "$ref": "#/definitions/param~1VestingDatum" - } - }, - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/param~1VestingAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "5903fb0100003232323232323232322322223232533300a3232533300c3370e90010008991919191999191919191119299980c19b8748000c05c0044c8c8cdc39980300200099b813300600500148008dd7180f000980b0008b19299980d8008a60103d87a800013374a90001980e180e800a5eb80c018c8cc00400400c894ccc07000452f5bded8c0264646464a66603a66e3d221000021003133021337606ea4008dd3000998030030019bab301e003375c60380046040004603c0024464a66602e66e1d200030160011375a6038602a0022c64a6660340022980103d87a800013374a90001980d980e000a5eb80c00ccc88c94ccc064cdc3a4004002200426eacc078c05c00cc05c008c8cc00400400c894ccc06c0045300103d87a8000132323232533301c3371e00e004266e95200033020374c00297ae01330060060033756603a0066eb8c06c008c07c008c0740052f5bded8c0600200244a66602e002297ae01330183016301900133002002301a001300100122533301500114bd7009980b1809980b80099801001180c0009bab3004300e00137566008601c004600401066464646464464a66602a66e1cc018cc014dd61802180998059809801180180124004264a66602c66e1d200030150011301b30140011632533301900114c103d87a800013374a90001980d180d800a5eb80cc014dd618021809980598098010008b180100091919299980a99b8748008c0500044dd7180d18098008b180518091805180900098030009180b980c180c00091191980080080191299980b8008a5eb804c8c94ccc058c8c94ccc060cdc3a4004002266e3c01cdd7180e980b0010a503016001300c3014300c301400213301a00233004004001133004004001301b002301900130010012253330130011480004cdc02400466004004602c00200e46464a66602066e1d2000300f00113232323007301100230100013016001300e001163322323300100100322533301600114c103d87a80001323253330153375e6016602600400a266e952000330190024bd70099802002000980d001180c0009bac3005300d3005300d00200132533300f3370e900118070008980a18068008b18011806000918091809800899911991191980080080191299980a8008a501323253330143371e00400a29444cc010010004c064008dd7180b8009bac301330143014301430143014301430143014300c0020013002300a005008375a6002601200a4602000229309b2b19299980519b87480000044c8c8c8c94ccc044c05000852616375a602400260240046eb4c040004c02001058c02000cc94ccc024cdc3a400000226464a66601c60220042930b1bad300f0013007004163007003375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae89", - "hash": "46e5fb9d32f75a527812759e378769f59f0db3e6020622ec4f0539e4" - } - ], - "definitions": { - "ByteArray": { - "dataType": "bytes" - }, - "Data": { - "title": "Data", - "description": "Any Plutus data." - }, - "Int": { - "dataType": "integer" - }, - "param/AuthAction": { - "title": "AuthAction", - "anyOf": [ - { - "title": "AuthAction", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "a", - "$ref": "#/definitions/Int" - }, - { - "title": "b", - "$ref": "#/definitions/Int" - } - ] - } - ] - }, - "param/AuthDatum": { - "title": "AuthDatum", - "anyOf": [ - { - "title": "AuthDatum", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "a", - "$ref": "#/definitions/ByteArray" - } - ] - } - ] - }, - "param/LockingAction": { - "title": "LockingAction", - "anyOf": [ - { - "title": "LockingAction", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "a", - "$ref": "#/definitions/Int" - }, - { - "title": "b", - "$ref": "#/definitions/Int" - } - ] - } - ] - }, - "param/MintAction": { - "title": "MintAction", - "anyOf": [ - { - "title": "MintAction", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "a", - "$ref": "#/definitions/Int" - }, - { - "title": "b", - "$ref": "#/definitions/Int" - }, - { - "title": "tn", - "$ref": "#/definitions/ByteArray" - } - ] - } - ] - }, - "param/VestingAction": { - "title": "VestingAction", - "anyOf": [ - { - "title": "VestingAction", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "a", - "$ref": "#/definitions/Int" - }, - { - "title": "b", - "$ref": "#/definitions/Int" - } - ] - } - ] - }, - "param/VestingDatum": { - "title": "VestingDatum", - "anyOf": [ - { - "title": "VestingDatum", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "v", - "$ref": "#/definitions/Int" - } - ] - } - ] - } - } -} \ No newline at end of file diff --git a/plutus1.json b/plutus1.json deleted file mode 100644 index f16c96a..0000000 --- a/plutus1.json +++ /dev/null @@ -1,303 +0,0 @@ -{ - "preamble": { - "title": "rhystmorgan/okapi-aiken", - "description": "Aiken contracts for project 'rhystmorgan/okapi-aiken'", - "version": "0.0.0", - "plutusVersion": "v2", - "compiler": { - "name": "Aiken", - "version": "v1.0.20-alpha+unknown" - }, - "license": "Apache-2.0" - }, - "validators": [ - { - "title": "inc.mint", - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/inc~1Action" - } - }, - "compiledCode": "5902b60100003232323232323232322232533300632323232533300a3370e9000180480089919191919191919191919191919299980d980f00109919191919299980e99b874800000454ccc074c8c8c94ccc080cc0040448cdc39998019bab3004301f001016009480084cc0040448cdc39998019bab3004301f001016007480085281119198008008019129998130008a50132325333025300500214a22660080080026054004605000244464664464a66604a66e1d200200110021375a60546046006604600464a66604666e1d200200114c0103d87a8000132323300100100222533302900114c103d87a8000132323232533302a3371e014004266e9520003302e375000297ae0133006006003375a60560066eb8c0a4008c0b4008c0ac004dd5981418108011810800a40006601c0060044604660480022a66603a66e1c011200213370e00490010a50161533301d3370e0089000899b8700248004528180d80c9bad301d004375c60360066eb4c06c010dd7180c8018b180e000980e001180d00099199119299980c19b874800800440084dd5980e980b001980b0011980100080525eb7bdb180c8cc00400400c894ccc06400452f5bded8c0264646464a66603466e3d22100002100313301e337606ea4008dd3000998030030019bab301b003375c6032004603a004603600244646600200200644a6660340022980103d87a8000132323232533301b3371e00e004266e9520003301f374c00297ae0133006006003375660380066eb8c068008c078008c070004dd5980b800980b800980b0011bac301400130140013013001300a005375c602000260100022c601c002601c0046018002600800429309b2b19299980319b874800000454ccc024c01000c52616153330063370e90010008a99980498020018a4c2c2c60080044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", - "hash": "2d0ca9e77cff20b7ff4dd1e8984a8d091bdab9181c84d77f1e11c6c5" - }, - { - "title": "inc.mint1", - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/inc~1Action" - } - }, - "compiledCode": "59036c0100003232323232323232322232533300632323232533300a3370e9000180480089919191919191919191919191919299980d980f00109919191919299980e99b87480000044c8c8c94ccc080cc0040448cdc39998019bab3004301f0010160094800854ccc080cc0040448cdc39998019bab3004301f001016007480084c8c8c8c8c8c94ccc0994ccc0994ccc098cdc3806a4004266e1c02d200214a02004294040045281980100599801802a40046600201866004008900011299981299b8748000c0900044cdc78011bae302a3023001163001001222533302700214c103d87a80001323253330263370e0069000099ba548000cc0a8dd480125eb804ccc014014004cdc0801a400460560066eb8c0a4008cc88cc098dd499801244103313030000013302637526600491103323232000014bd701119b8a00200148908496e63546573743400161622323300100100322533302600114a026464a66604a600a00429444cc010010004c0a8008c0a0004888c8cc88c94ccc094cdc3a4004002200426eb4c0a8c08c00cc08c008c94ccc08ccdc3a4004002298103d87a8000132323300100100222533302900114c103d87a8000132323232533302a3371e014004266e9520003302e375000297ae0133006006003375a60560066eb8c0a4008c0b4008c0ac004dd5981418108011810800a40006601c0060044604660480022a66603a66e1c011200113370e00490008a50301b019375a603a0086eb8c06c00cdd6980d8021bae301900316301c001301c002301a0013233223253330183370e9001000880109bab301d301600330160023300200100a4bd6f7b630191980080080191299980c8008a5eb7bdb1804c8c8c8c94ccc068cdc7a4500002100313301e337606ea4008dd3000998030030019bab301b003375c6032004603a004603600244646600200200644a6660340022980103d87a8000132323232533301b3371e00e004266e9520003301f374c00297ae0133006006003375660380066eb8c068008c078008c070004dd5980b800980b800980b0011bac301400130140013013001300a005375c602000260100022c601c002601c0046018002600800429309b2b19299980319b874800000454ccc024c01000c52616153330063370e90010008a99980498020018a4c2c2c60080044600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", - "hash": "804d94b206da4c80652cdc3fc7095b552ee640755f7824c323b64777" - }, - { - "title": "soundrig.metadata_validator", - "datum": { - "title": "dat", - "schema": { - "$ref": "#/definitions/soundrig~1TokenDatum" - } - }, - "redeemer": { - "title": "red", - "schema": { - "$ref": "#/definitions/soundrig~1MetadataAction" - } - }, - "parameters": [ - { - "title": "cs", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "590513010000323232323232323232232222323232533300b32323232533300f3370e9001180700089919191919191919191919191919191919299981019b8748000c07c0044c8c8c8c8c8c8c94ccc09ccdc3a4004604c002264646464a66605666e1d2000302a0011323232323232323253330333370e900218190008991919191919191919191919191919299982119b874800000c4c8c8c8c8c94ccc11d4ccc11d4ccc11d4ccc11c030402c52808050a50100914a020022940cc014dd61803182201d0009bae304a001304a0023048001304003c1323232533304500a100114a0660066eb0c010c1080e0004dd71824000982001e1119198008008019129998240008a501323253330473371e00400a29444cc010010004c130008dd718250009182318239823982398239823982398239823800981f01c991919baf3300137566044607c0189000198009bab3022303e03b48000c0040048894ccc110008530103d87a80001323253330433370e0069000099ba548000cc11cdd399823982200119823982280125eb812f5c0266600a00a00266e0400d200230480033046002323371260026eacc064c0f0c064c0f0074c004dd5980c981e009119199119299982119b874800800440084dd698239820001982000119299982019b8748008004530103d87a8000132323300100100222533304600114c103d87a800013232323253330473371e9110000213374a9000198259ba80014bd700998030030019bad3048003375c608c004609400460900026eacc114c0f8008c0f80052000330080014881003375e6e9cc008cc014dd5980b981d00801c261039f01ff003375e6e9cc004cc010dd5980b181c980b181c80d01ba61039f01ff0023002001300100122533303d00114bd7009981f181e181f80099801001182000091199119299981e19b874800800440084dd59820981d001981d00119801801000a5eb7bdb18088c8cc00400400c894ccc0f4004530103d87a8000132323232533303e3371e00e004266e95200033042374c00297ae01330060060033756607e0066eb8c0f4008c104008c0fc004c0b4004c0e4004c0c400458c024c0c0018c0d8004c0d8008dd5981a000981a0009815800981880098148008b191929998178008a6103d87a800013374a9000198181818800a5eb80c8cc004004008894ccc0c000452f5c026464a66605e6464a66606266e1d200200113371e0126eb8c0d8c0bc0085281817800980898169808981680109981980119802002000899802002000981a00118190009bac3001302801e2302f30303030001375c605a002604a0022c60106048601060486002604800a460566058002605200260520026040002604c002603c0022c64646600200200444a66604a0022980103d87a80001323253330243375e600c6044004028266e952000330280024bd70099802002000981480118138009bac3001301d0132302400137586044002604400260420026040002603e0046eacc074004c074004c070008dd6180d000980d000980c8011bac3017001300f0053015001300d00116301300130130023011001300900414984d958c94ccc02ccdc3a4000002264646464a666024602a0042930b1bae30130013013002301100130090051533300b3370e900100089919299980818098010a4c2c6eb8c044004c02401458c024010c0040108c94ccc028cdc3a4000002264646464a66602260280042930b1bad3012001301200230100013008002163008001375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", - "hash": "f27e0278ef548c67861f68c711ef69253054a0e98d7d8e9e314f8d82" - }, - { - "title": "soundrig.mint68", - "redeemer": { - "title": "r", - "schema": { - "$ref": "#/definitions/soundrig~1MintAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "5905bd0100003232323232323232322322232533300832323232533300c3370e90001805800899191919191919191919191919191919191919299980f99b8748000c0780044c8c8c8c8c8c8c94ccc098cdc3a4008604a00226464646464646464a66606260680042646464646464a66606866e1d2000303300113232323232323232533303c3370e9002181d800899191919299982019b87480000044c8c94ccc108c8cc0040040c0894ccc11c0045280991929998232999823299982319b8f376660286088602860880046eb8c050c11007c4cdc399991119199119299982699b874800800440084dd698291825801982580119299982599b8748008004530103d87a8000132323300100100222533305100114c103d87a800013232323253330523371e014004266e95200033056375000297ae0133006006003375a60a60066eb8c144008c154008c14c004dd5982818248011824800a4000660400060046eacc0a4c1100080e4061200214a0266e3cdd9980a18220049bb3374c6466446609a66ec1300105446e616d650037526e60020cc134cdd826010645696d6167650037526e60008cc134cdd826010a496d65646961547970650037526e600052f5bded8c060029110a697066732f2f31323334003001488109696d6167652f706e670023732002294052889980200200098258011824800899191919191929998242999824299982419b87019480084cdc380ba40042940400852808008a50330020173300300548008cc004060cc00801120002253330473370e90001823000899b8f002375c6098608a0022c6002002444a666092004298103d87a80001323253330483370e0069000099ba548000cc130dd480125eb804ccc014014004cdc0801a4004609a0066eb8c12c008cc8c88cc124dd499801a4410331303000300200133049375266006911033232320030020014bd7011b9800122337140040020022c6e64dd71823000981f01d89919299982119b87013480044cdc3808a40022940dcc9bae3046001303e03b303e03a32533303f3370e9000000899191919299982318248010a4c2c6eb4c11c004c11c008c114004c0f400858c0f4004c108004c0e800458c05cc0e4018c0fc004c0fc008dd5981e800981e800981a000981d00098190008b19180c19191980080080191299981d0008a5eb804c8c94ccc0e4c8c94ccc0eccdc3a4004002266e3c01cdd71820181c8010a503039001300730373007303700213303d00233004004001133004004001303e002303c001375c6004606401a6eb0c03cc0c40a88c0e0004dd698198021bae3031003375a60620086eb8c0bc00c58c0c8004c0c8008c0c0004c8cc88c94ccc0b8cdc3a4004002200426eacc0ccc0b000cc0b0008cc0080040792f5bded8c0646600200202a44a66605e002297adef6c6013232323253330303371e911000021003133034337606ea4008dd3000998030030019bab3031003375c605e0046066004606200244646600200200644a6660600022980103d87a800013232323253330313371e00e004266e95200033035374c00297ae0133006006003375660640066eb8c0c0008c0d0008c0c8004c94ccc0a4cdc3a4000002264646464a66606060660042930b1bae30310013031002375c605e002604e0042c604e002605800260480022c60026046004460546056605600260500026050002603e002604a002603a0022c60046eb0c004c0700548c08cc09000494ccc080004530103d87a800013374a9000198109811000a5eb80dd618100009810000980f800980f000980e8011bab301b001301b001301a0023758603000260300046eb0c058004c058008dd6180a00098060029bae3012001300a0011630100013010002300e001300600214984d958c94ccc020cdc3a400000226464a66601a60200042930b1b99375c601c002600c0062a66601066e1d200200113232533300d3010002149858dcc9bae300e0013006003163006002375c0024600a6ea80048c00cdd5000ab9a5573aaae7955cfaba05742ae881", - "hash": "b3538e93156eb3d2ebd9caa14cbb506b31706ef8f2fb307338918922" - }, - { - "title": "soundrig.reference_mint", - "redeemer": { - "title": "red", - "schema": { - "$ref": "#/definitions/soundrig~1RefMintAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "5903e20100003232323232323232322322232533300832323232533300c3370e90001805800899191919191919191919191919191919191919299981118128010991919299981119b87480000044c8c8c8c8c8c8c94ccc0a4cdc3a4000605000226464646464646464a66606266e1d2004303000113232325333034323300100102222533303900114a026464a666070a666070a66607066e3cdd99808981b1808981b00100a899b8733322232332232533303f3370e9001000880109bad3044303d003303d00232533303d3370e90010008a60103d87a8000132323300100100222533304300114c103d87a800013232323253330443371e014004266e95200033048375000297ae0133006006003375a608a0066eb8c10c008c11c008c114004dd59821181d801181d800a40006603e0060046eacc0f4c0f8c0d80080ac065200214a0266ebc018cdd2a4000660786ea404ccc0f0dd4815a5eb805280a51133004004001303d002303b00113370e02890010b19299981a19b87480000044c8c8c8c94ccc0ecc0f800852616375c607800260780046eb8c0e8004c0c800858c0c8004c0dc004c0bc00458c028c0b8018c0d0004c0d0008dd5981900098190009814800981780098138008b191929998168008a60103d87a800013374a9000198171817800a5eb80c8cc004004008894ccc0b800452f5c026464a66605a6464a66605e66e1d200200113371e0186eb8c0d0c0b40085281816800980318159803181580109981880119802002000899802002000981900118180009bac3002302601f2302d0012302c302d302d001375c605400260540046eb8c0a0004c0800744cdc38012400260400386eb4c088008dd718100008b181180099199119299981099b874800800440084dd59813180f801980f80119801000808a5eb7bdb180c8cc004004020894ccc08800452f5bded8c0264646464a66604666e3d221000021003133027337606ea4008dd3000998030030019bab3024003375c6044004604c004604800244646600200200644a6660460022980103d87a800013232323253330243371e00e004266e95200033028374c00297ae01330060060033756604a0066eb8c08c008c09c008c094004dd618100009810000980f800980f000980e8011bab301b001301b001301a0023758603000260300046eb0c058004c058008dd6180a00098060029bae3012001300a0011630100013010002300e001300600214984d958c94ccc020cdc3a4000002264646464a66601e60240042930b1bae30100013010002375c601c002600c0062a66601066e1d20020011533300b300600314985858c018008dd7000918029baa001230033754002ae6955ceaab9e5573eae815d0aba21", - "hash": "15d2d5993019003e80ddd991bb236828c59a8d2f5f81697ee512d6e7" - }, - { - "title": "soundrig.reference_validator", - "datum": { - "title": "dat", - "schema": { - "$ref": "#/definitions/soundrig~1ReferenceDatum" - } - }, - "redeemer": { - "title": "red", - "schema": { - "$ref": "#/definitions/soundrig~1ReferenceAction" - } - }, - "parameters": [ - { - "title": "owner", - "schema": { - "$ref": "#/definitions/ByteArray" - } - } - ], - "compiledCode": "59049b010000323232323232323232232222323232533300b32323232533300f3370e90011807000899191919191919191919191919191919299980f99b8748000c0780044c8c8c8c8c8c8c94ccc098cdc3a4004604a002264646464a66605466e1d200030290011323232323232323253330323370e9002181880089919191919191919191919191919299982019b87480000044c8c8c94ccc10d4ccc10d4ccc10d4ccc10d4ccc10c018401452808008a50100b14a0201a2940403052819b8f375c604a608001e0026eb8c118004c0f80e854ccc1000084024528181f01c99baf374e60046600a6eacc068c0f004cdd7180d181e01ca601039f01ff003375e6e9cc004cc010dd5980c981d980c981d80e9bae3019303b0384c1039f01ff0023002001300100122533303f00114bd70099820181f182080099801001182100091199119299981f19b874800800440084dd59821981e001981e00119803001000a5eb7bdb180cdc79bae30143036005375c6028606c0666644646600200200644a66607c00229404c8c94ccc0f4cdc78010028a511330040040013042002375c60800026eb0c0f0c0f4c0f4c0f4c0f4c0f4c0f4c0f4c0f4c0d40ac0ccc8cdc498009bab3013303530133035017300137566026606a018464664464a66607666e1d200200110021375a60806072006607200464a66607266e1d200200114c103d87a8000132323300100100222533303f00114c103d87a800013232323253330403371e9110000213374a9000198221ba80014bd700998030030019bad3041003375c607e004608600460820026eacc0f8c0dc008c0dc00520003300200148810022323300100100322533303c00114c0103d87a8000132323232533303d3371e00e004266e95200033041374c00297ae01330060060033756607c0066eb8c0f0008c100008c0f8004c0b0004c0e0004c0c000458c024c0bc018c0d4004c0d4008dd5981980098198009815000981800098140008b191929998170008a6103d87a800013374a9000198179818000a5eb80c8cc004004008894ccc0bc00452f5c026464a66605c6464a66606066e1d200200113371e0126eb8c0d4c0b80085281817000980898161808981600109981900119802002000899802002000981980118188009bac3001302701d2302e302f302f001375c605800260480022c60106046601060466002604600a46054605600260500026050002603e002604a002603a0022c64646600200200444a6660480022980103d87a80001323253330233375e600c6042004026266e952000330270024bd70099802002000981400118130009bac3001301c012230230013758604200260420026040002603e002603c002603a00260380046eb0c068004c068004c064008dd6180b8009807802980a80098068008b18098009809801180880098048020a4c26cac64a66601666e1d20000011323253330103013002149858dd7180880098048028a99980599b874800800454ccc038c024014526161630090043001004232533300a3370e90000008991919192999808980a0010a4c2c6eb8c048004c048008dd7180800098040010b18040009bae001230053754002460066ea80055cd2ab9d5573caae7d5d02ba15745", - "hash": "9c487a18b48339305206abbc85a177c8d5248090b32a9642a9bdbe1b" - } - ], - "definitions": { - "ByteArray": { - "dataType": "bytes" - }, - "Data": { - "title": "Data", - "description": "Any Plutus data." - }, - "Int": { - "dataType": "integer" - }, - "String": { - "dataType": "#string" - }, - "inc/Action": { - "title": "Action", - "anyOf": [ - { - "title": "AMint", - "dataType": "constructor", - "index": 0, - "fields": [] - }, - { - "title": "ABurn", - "dataType": "constructor", - "index": 1, - "fields": [] - } - ] - }, - "soundrig/MetadataAction": { - "title": "MetadataAction", - "anyOf": [ - { - "title": "Update", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "metadata", - "$ref": "#/definitions/Data" - }, - { - "title": "user", - "$ref": "#/definitions/ByteArray" - } - ] - }, - { - "title": "Remove", - "dataType": "constructor", - "index": 1, - "fields": [ - { - "title": "owner", - "$ref": "#/definitions/ByteArray" - } - ] - } - ] - }, - "soundrig/MintAction": { - "title": "MintAction", - "anyOf": [ - { - "title": "Mint", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "tn", - "$ref": "#/definitions/String" - } - ] - }, - { - "title": "Burn", - "dataType": "constructor", - "index": 1, - "fields": [ - { - "title": "tn", - "$ref": "#/definitions/String" - } - ] - } - ] - }, - "soundrig/RefMintAction": { - "title": "RefMintAction", - "anyOf": [ - { - "title": "MintRef", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "script_hash", - "$ref": "#/definitions/ByteArray" - }, - { - "title": "metadata_script_hash", - "$ref": "#/definitions/ByteArray" - } - ] - }, - { - "title": "BurnRef", - "dataType": "constructor", - "index": 1, - "fields": [] - } - ] - }, - "soundrig/ReferenceAction": { - "title": "ReferenceAction", - "anyOf": [ - { - "title": "UpdateRef", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "metadata_script_hash", - "$ref": "#/definitions/ByteArray" - } - ] - }, - { - "title": "RemoveRef", - "dataType": "constructor", - "index": 1, - "fields": [] - } - ] - }, - "soundrig/ReferenceDatum": { - "title": "ReferenceDatum", - "anyOf": [ - { - "title": "ReferenceDatum", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "metadata_script_hash", - "$ref": "#/definitions/ByteArray" - }, - { - "title": "refCS", - "$ref": "#/definitions/ByteArray" - } - ] - } - ] - }, - "soundrig/TokenDatum": { - "title": "TokenDatum", - "anyOf": [ - { - "title": "TokenDatum", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "metadata", - "$ref": "#/definitions/Data" - }, - { - "title": "version", - "$ref": "#/definitions/Int" - } - ] - } - ] - } - } -} \ No newline at end of file diff --git a/routes/_404.tsx b/routes/_404.tsx deleted file mode 100644 index c63ae2e..0000000 --- a/routes/_404.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { Head } from "$fresh/runtime.ts"; - -export default function Error404() { - return ( - <> - - 404 - Page not found - -
-
- the Fresh logo: a sliced lemon dripping with juice -

404 - Page not found

-

- The page you were looking for doesn't exist. -

- Go back home -
-
- - ); -} diff --git a/routes/_app.tsx b/routes/_app.tsx deleted file mode 100644 index a884cb2..0000000 --- a/routes/_app.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { AppProps } from "$fresh/server.ts"; - -export default function App({ Component }: AppProps) { - return ( - - - - - okapi-aiken - - - - - - ); -} diff --git a/routes/greet/[name].tsx b/routes/greet/[name].tsx deleted file mode 100644 index 9c06827..0000000 --- a/routes/greet/[name].tsx +++ /dev/null @@ -1,5 +0,0 @@ -import { PageProps } from "$fresh/server.ts"; - -export default function Greet(props: PageProps) { - return
Hello {props.params.name}
; -} diff --git a/routes/index.tsx b/routes/index.tsx deleted file mode 100644 index 714faa9..0000000 --- a/routes/index.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { Head } from "$fresh/runtime.ts"; -import { Handlers, PageProps } from "$fresh/server.ts"; - -import Oneshot from "~/islands/Oneshot.tsx"; - -import { readValidators, Validators } from "~/utils.ts"; - -interface Data { - validators: Validators; -} - -export const handler: Handlers = { - GET(_req, ctx) { - const validators = readValidators(); - - return ctx.render({ validators }); - }, -}; - -export default function Home({ data }: PageProps) { - const { validators } = data; - - return ( - <> - - One Shot - - -
-
-

- Make a one shot minting and lock contract -

- -

Redeem

-
-            {validators.redeem.script}
-          
- -

Gift Card

-
-            {validators.giftCard.script}
-          
-
- - -
- - ); -} \ No newline at end of file diff --git a/static/favicon.ico b/static/favicon.ico deleted file mode 100644 index 1cfaaa2..0000000 Binary files a/static/favicon.ico and /dev/null differ diff --git a/static/logo.svg b/static/logo.svg deleted file mode 100644 index ef2fbe4..0000000 --- a/static/logo.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/twind.config.ts b/twind.config.ts deleted file mode 100644 index 2a7ac27..0000000 --- a/twind.config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Options } from "$fresh/plugins/twind.ts"; - -export default { - selfURL: import.meta.url, -} as Options; diff --git a/utils.ts b/utils.ts deleted file mode 100644 index 6f2a84a..0000000 --- a/utils.ts +++ /dev/null @@ -1,156 +0,0 @@ -import { - applyDoubleCborEncoding, - applyParamsToScript, - Constr, - fromText, - Lucid, - MintingPolicy, - OutRef, - SpendingValidator, - PaymentCredential, - Address, - CurrencySymbol, - ScriptHash -} from "lucid/mod.ts"; - -import blueprint from "~/plutus.json" assert { type: "json" }; - -export type Validators = { - lock: SpendingValidator; - mint: MintingPolicy; - refscript: SpendingValidator; - refmint: MintingPolicy; -}; - -export function readValidators(): Validators { - const lock = blueprint.validators.find((v) => v.title === "soundrig.metadata_validator"); - - if (!lock) { - throw new Error("Locking validator not found"); - } - - const mint = blueprint.validators.find( - (v) => v.title === "soundrig.mint68" - ); - - if (!mint) { - throw new Error("minting policy not found"); - } - - const refscript = blueprint.validators.find((v) => v.title === "soundrig.reference_validator"); - - if (!refscript) { - throw new Error("Ref validator not found"); - } - - const refmint = blueprint.validators.find((v) => v.title === "soundrig.reference_mint"); - - if (!refmint) { - throw new Error("Ref mint not found"); - } - - return { - lock: { - type: "PlutusV2", - script: lock.compiledCode, - }, - mint: { - type: "PlutusV2", - script: mint.compiledCode, - }, - refscript: { - type: "PlutusV2", - script: refscript.compiledCode, - }, - refmint: { - type: "PlutusV2", - script: refmint.compiledCode, - }, - }; -} - -// export type AppliedValidators = { -// redeem: SpendingValidator; -// giftCard: MintingPolicy; -// policyId: string; -// lockAddress: string; -// }; - -export type AppliedValidators = { - lock: SpendingValidator; - mint: MintingPolicy; - refscript: SpendingValidator; - refmint: MintingPolicy; - policyId: CurrencySymbol; - refpolicyId: CurrencySymbol; - lockAddress: Address; - lockHash: ScriptHash; - refAddress: Address; - refHash: ScriptHash; -}; - -export function applyParams( - owner: PaymentCredential.hash, - validators: Validators, - lucid: Lucid -): AppliedValidators { - - const mint = applyParamsToScript(validators.mint.script, [ - owner, - ]); - - const policyId = lucid.utils.validatorToScriptHash({ - type: "PlutusV2", - script: mint, - }); - - const lock = applyParamsToScript(validators.lock.script, [ - policyId, - ]); - - const lockAddress = lucid.utils.validatorToAddress({ - type: "PlutusV2", - script: lock, - }); - - const lockHash = lucid.utils.validatorToScriptHash({ - type: "PlutusV2", - script: lock - }) - - const refscript = applyParamsToScript(validators.refscript.script, [ - owner, - ]); - - const refAddress = lucid.utils.validatorToAddress({ - type: "PlutusV2", - script: refscript - }) - - const refHash = lucid.utils.validatorToScriptHash({ - type: "PlutusV2", - script: refscript - }) - - const refmint = applyParamsToScript(validators.refmint.script, [ - owner, - ]); - - const refpolicyId = lucid.utils.validatorToScriptHash({ - type: "PlutusV2", - script: refmint, - }); - - return { - lock: { type: "PlutusV2", script: applyDoubleCborEncoding(lock) }, - mint: { type: "PlutusV2", script: applyDoubleCborEncoding(mint) }, - refscript: { type: "PlutusV2", script: applyDoubleCborEncoding(refscript) }, - refmint: { type: "PlutusV2", script: applyDoubleCborEncoding(refmint) }, - policyId, - refpolicyId, - lockAddress, - lockHash, - refAddress, - refHash, - }; -} \ No newline at end of file diff --git a/validators/oktest.ak b/validators/oktest.ak index 8b13789..f2a0a3b 100644 --- a/validators/oktest.ak +++ b/validators/oktest.ak @@ -1 +1,12 @@ - +// validator template +// use aiken/bytearray as b +// use aiken/hash as h +// use aiken/list as l +// use aiken/transaction as t +// use aiken/transaction/credential as c +// use aiken/transaction/value as v +// okapi lib +// use okapi_aiken/okapi as ok +// // +// Validators // +// // diff --git a/vesting-lock.ts b/vesting-lock.ts deleted file mode 100644 index b75e004..0000000 --- a/vesting-lock.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { - Blockfrost, - C, - Data, - Lucid, - SpendingValidator, - TxHash, - fromHex, - toHex, -} from "https://deno.land/x/lucid@0.8.3/mod.ts"; -import * as cbor from "https://deno.land/x/cbor@v1.4.1/index.js"; - -// deno run --allow-net --allow-read --allow-env vesting_lock.ts - -// assumes vesting validator is [0] if validators list - -const lucid = await Lucid.new( - new Blockfrost( - "https://cardano-preview.blockfrost.io/api/v0", - Deno.env.get("BLOCKFROST_API_KEY"), - ), - "Preview", -); - -lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./owner.sk")); - -const validator = await readValidator(); - -// --- Supporting functions - -async function readValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0]; - return { - type: "PlutusV2", - script: toHex(cbor.encode(fromHex(validator.compiledCode))), - }; -} - -const ownerPublicKeyHash = lucid.utils.getAddressDetails( - await lucid.wallet.address() -).paymentCredential.hash; - -const beneficiaryPublicKeyHash = - lucid.utils.getAddressDetails(await Deno.readTextFile("beneficiary.addr")) - .paymentCredential.hash; - -const Datum = Data.Object({ - lock_until: Data.BigInt, // this is POSIX time, you can check and set it here: https://www.unixtimestamp.com - owner: Data.String, // we can pass owner's verification key hash as byte array but also as a string - beneficiary: Data.String, // we can beneficiary's hash as byte array but also as a string -}); - -type Datum = Data.Static; - -const datum = Data.to( - { - lock_until: 1672843961000n, // Wed Jan 04 2023 14:52:41 GMT+0000 - owner: ownerPublicKeyHash, // our own wallet verification key hash - beneficiary: beneficiaryPublicKeyHash, - }, - Datum -); - -const txLock = await lock(1000000, { into: validator, datum: datum }); - -await lucid.awaitTx(txLock); - -console.log(`1 tADA locked into the contract - Tx ID: ${txLock} - Datum: ${datum} -`); - -// --- Supporting functions - -async function lock(lovelace, { into, datum }): Promise { - const contractAddress = lucid.utils.validatorToAddress(into); - - const tx = await lucid - .newTx() - .payToContract(contractAddress, { inline: datum }, { lovelace }) - .complete(); - - const signedTx = await tx.sign().complete(); - - return signedTx.submit(); -} \ No newline at end of file diff --git a/vesting-unlock.ts b/vesting-unlock.ts deleted file mode 100644 index 77398f6..0000000 --- a/vesting-unlock.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { - Blockfrost, - C, - Data, - Lucid, - SpendingValidator, - TxHash, - fromHex, - toHex, -} from "https://deno.land/x/lucid@0.8.3/mod.ts"; -import * as cbor from "https://deno.land/x/cbor@v1.4.1/index.js"; - -// deno run --allow-net --allow-read --allow-env vesting_unlock.ts - -// assumes validator is [0] of validators - -const lucid = await Lucid.new( - new Blockfrost( - "https://cardano-preview.blockfrost.io/api/v0", - Deno.env.get("BLOCKFROST_API_KEY"), - ), - "Preview", -); - -lucid.selectWalletFromPrivateKey(await Deno.readTextFile("./beneficiary.sk")); - -const beneficiaryPublicKeyHash = lucid.utils.getAddressDetails( - await lucid.wallet.address() -).paymentCredential.hash; - -const validator = await readValidator(); - -// --- Supporting functions - -async function readValidator(): Promise { - const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0]; - return { - type: "PlutusV2", - script: toHex(cbor.encode(fromHex(validator.compiledCode))), - }; -} - -// ^^^ Code above is unchanged. ^^^ - -const scriptAddress = lucid.utils.validatorToAddress(validator); - -// we get all the UTXOs sitting at the script address -const scriptUtxos = await lucid.utxosAt(scriptAddress); - -const Datum = Data.Object({ - lock_until: Data.BigInt, // this is POSIX time, you can check and set it here: https://www.unixtimestamp.com - owner: Data.String, // we can pass owner's verification key hash as byte array but also as a string - beneficiary: Data.String, // we can beneficiary's hash as byte array but also as a string -}); - -type Datum = Data.Static; - -const currentTime = new Date().getTime(); - -// we filter out all the UTXOs by beneficiary and lock_until -const utxos = scriptUtxos.filter((utxo) => { - let datum = Data.from( - utxo.datum, - Datum, - ); - - return datum.beneficiary === beneficiaryPublicKeyHash && - datum.lock_until <= currentTime; -}); - -if (utxos.length === 0) { - console.log("No redeemable utxo found. You need to wait a little longer..."); - Deno.exit(1); -} - -// we don't have any redeemer in our contract but it needs to be empty -const redeemer = Data.empty(); - -const txUnlock = await unlock(utxos, currentTime, { from: validator, using: redeemer }); - -await lucid.awaitTx(txUnlock); - -console.log(`1 tADA recovered from the contract - Tx ID: ${txUnlock} - Redeemer: ${redeemer} -`); - -// --- Supporting functions - -async function unlock(utxos, currentTime, { from, using }): Promise { - const laterTime = new Date(currentTime + 2 * 60 * 60 * 1000).getTime(); // add two hours (TTL: time to live) - - const tx = await lucid - .newTx() - .collectFrom(utxos, using) - .addSigner(await lucid.wallet.address()) // this should be beneficiary address - .validFrom(currentTime) - .validTo(laterTime) - .attachSpendingValidator(from) - .complete(); - - const signedTx = await tx - .sign() - .complete(); - - return signedTx.submit(); -} \ No newline at end of file