From ad31bcfa266d5166aa66b7e587f5eb73e5fd5903 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Thu, 2 May 2024 15:56:09 -0700 Subject: [PATCH 1/2] adding plutus.json to git ignore --- .gitignore | 3 +- plutus.json | 99 ----------------------------------------------------- 2 files changed, 2 insertions(+), 100 deletions(-) delete mode 100644 plutus.json diff --git a/.gitignore b/.gitignore index 04b8077..7cee509 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ docs/ aiken.lock .github/ contracts/ -hashes/ \ No newline at end of file +hashes/ +plutus.json \ No newline at end of file diff --git a/plutus.json b/plutus.json deleted file mode 100644 index b3ecb49..0000000 --- a/plutus.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "preamble": { - "title": "dripdropz/perma-lock", - "description": "Perma Lock Contract For Dripdropz", - "version": "1.1.2", - "plutusVersion": "v2", - "compiler": { - "name": "Aiken", - "version": "v1.0.26-alpha+fdbe811" - }, - "license": "GPL-3.0-or-later" - }, - "validators": [ - { - "title": "perma_lock_ft.params", - "datum": { - "title": "_datum", - "schema": { - "$ref": "#/definitions/Void" - } - }, - "redeemer": { - "title": "add_amt", - "schema": { - "$ref": "#/definitions/Int" - } - }, - "compiledCode": "5905ba01000033332323232323232323232323223223223223232232253330103232533233013300130153754004264646464646464a666034a6660346010646660020026eb0c020c078dd5003a4000444a6660420042002264a66603c66ebcc02cc084dd5180718109baa30240030081333004004001337000049001099980200200080118120010a51153301b491064c35313b31310014a02a666034a6660346010646660020026eb0c00cc078dd5003a4000444a6660420042002264a66603c66ebcc02cc084dd51812001804099980200200099b80002480084ccc010010004008c0900085288a9980da49064c35333b31310014a02a666034a66603466e21200000c14a22a660369201064c35353b31310014a02a66603464660020026eb0c00cc078dd50039129998100008a5013232533301e533301e3375e601660426ea80080204cdd7980718109baa002374c00e2940528899802002000981200118110008a51153301b491064c35373b31310014a029405280a503253333330220011533301a300f301c37540022a66603c603a6ea8004526153301b01716153301b01716153301b01716153301b01716153301b01716153301b0171632533301a3370e9002180e1baa00113020301d37540022a66036921064c39363b313000163001301c375464660020026eb0c008c074dd500311299980f8008a9980e249074c3136323b3131001613232533301d3375e601460406ea800801c40084cc010010004c08c008c0840048c07cc080c080004cc894ccc064c03802c40044c8c8cc00400400c894ccc0800044cc084cdd81ba9017374c00697adef6c6013232323253330203375e6601203600498103d8798000133025337606ea406cdd30038028a99981019b8f01b002132533302130163023375400226604c66ec0dd480e181398121baa0010041004325333021533302500114a229405300103d87a800013374a9000198131ba60014bd70191980080080111299981300089981399bb037520366ea00512f5bded8c0264646464a66604c66ebccc03c07c00930103d879800013302b337606ea407cdd400c0028a99981319b8f01f0021325333027301c3029375400226605866ec0dd4810181698151baa0010041004325333027301c00114c103d87a800013374a9000198161ba80014bd7019b8000101813302b337606ea4008dd4000998030030019bad3028003375c604c0046054004605000226604a66ec0dd48011ba600133006006003375660440066eb8c080008c090008c088004c8c8008c8cc004004008894ccc080004526132533302100114984c8c94ccc07cc050c084dd5198041bae30213025004375c604200426600a00a660480040022a66040921074c3433313b313400163025002302300130230013301e337606ea4048dd4005a5eb7bdb180894ccc064cdc80010008a6103d8798000153330193371e0040022980103d87a800014c103d87b80003756600e60346ea8c01cc068dd50011801980c9baa3006301937540026644646600200200644a66603a0022a66034921064c38393b3131001613232533301b3375e6010603c6ea800801440084cc010010004c084008c07c004dd61801180c1baa001301b301837540086002602e6ea80148c068004dc3a40042940c004c050dd50011180b980c0008a4c26caca66666602c0022a6601e0182c2a6601e0182c2a6601e0182c26eb400454cc03c030594cccccc05000854ccc030c004c038dd50010a99980818079baa002149854cc03402c5854cc03402c5854cc03402c5854cc03402c5854cc03402c5854cc03402c58dc3a40006eb8004dd70009bae001491054c34343b39004901064c33303b3237004901064c33303b3133005734ae7155ceaab9e5573eae815d0aba257489811e581cd441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf004c01225820546869735f49735f415f566572795f4c6f6e675f537472696e675f5f5f5f5f5f004c01115089b3b38df75610f1524fddae74841ccd0001", - "hash": "b04e2520272e96d947c68390ddaf8d3b1d18b3ab2137f330d5362448" - }, - { - "title": "perma_lock_nft.params", - "datum": { - "title": "_datum", - "schema": { - "$ref": "#/definitions/Void" - } - }, - "redeemer": { - "title": "assets", - "schema": { - "$ref": "#/definitions/List$assist~1types~1token~1Token" - } - }, - "compiledCode": "59082a010000332323232323232323232323223223232232322533300d323253323301030013012375400426464646464646464a666030a6660306012646660020026eb0c024c070dd500424000444a66603e0042002264a66603866ebcc030c07cdd51807980f9baa30220030091333004004001337000049001099980200200080118110010a511533019491064c34323b31310014a02a666030a6660306012646660020026eb0c014c070dd500424000444a66603e0042002264a66603866ebcc030c07cdd51811001804899980200200099b80002480084ccc010010004008c0880085288a9980ca49064c34343b31310014a02a666030a66603064660020026eb0c014c070dd500411299980f0008a5013232533301c533301c3375e6018603e6ea80080244c8c8cc004004c8cc004004024894ccc09000452f5c0264666444646600200200644a6660540022006264660586e9ccc0b0dd4803198161ba9375c6052002660586ea0dd69815000a5eb80cc00c00cc0b8008c0b0004dd718118009bab3024001330030033028002302600122533302300114a22646464a66604466e24dd6981418148009991192999812980b18139baa0011480004dd6981598141baa001325333025301630273754002298103d87a8000132330010013756605860526ea8008894ccc0ac004530103d87a80001323232533302a3371e00e6eb8c0b000c4c054cc0bcdd4000a5eb804cc014014008dd698160011817801181680099198008008049129998150008a6103d87a8000132323253330293371e00e6eb8c0ac00c4c050cc0b8dd3000a5eb804cc014014008dd59815801181700118160009bae3028003375c605000226600a00a0042940c0a0008c09c008dd618128009bab300f301f37540042940528899802002000981100118100008a5115330194901064c34363b31310014a02a666030664600200244a66603c00229444c94ccc06ccdc4240006eb4c01cc078dd518108010998018018008a50302100100e14a22a660329201064c34383b31310014a029405280a50325333333020001153330183011301a37540022a66603860366ea80045261533019015161533019015161533019015161533019015161533019015161533019015163253330183370e9002180d1baa0011301e301b37540022a66032921064c39363b313000163003301a375464660020026eb0c010c06cdd500391299980e8008a9980d249074c3136323b3131001613232533301b3375e6016603c6ea800802040084cc010010004c084008c07c004ccc8c8c0040048894ccc07800440084ccc00c00cc8ccc8894ccc078c05c00440184c8c8cc004004020894ccc0940044cc098cdd81ba9006374c00697adef6c6013232323253330253375e6601e01400498103d879800013302a337606ea4028dd30038028a99981299b8f00a0021325333026301f3028375400226605666ec0dd4805981618149baa0010041004325333026533302a00114a229405300103d87a8000130113302b374c00297ae0323300100100222533302b00113302c337606ea402cdd400525eb7bdb1804c8c8c8c94ccc0accdd79980a80780126103d8798000133030337606ea403cdd40070028a99981599b8f00f002132533302c3025302e375400226606266ec0dd4808181918179baa001004100432533302c302500114c103d87a80001301733031375000297ae03370000201c26606066ec0dd48011ba800133006006003375a605a0066eb8c0ac008c0bc008c0b40044cc0a8cdd81ba9002374c0026600c00c0066eacc09c00cdd7181280118148011813800991900119198008008011129998128008a4c264a66604c002293099192999812180e98131baa3300e375c604c60540086eb8c0980084cc014014cc0a400800454cc0952401074c3433313b31340016302a0023028001302800133023337606ea4008dd4000a5eb7bdb180dd71805980f1baa001375c601c603c6ea8004dd69803980f1baa0013020001302100122533301833720004002298103d8798000153330183371e0040022980103d87a800014c103d87b80003756601260326ea8c024c064dd50020061ba5480008c06cc070c070004c00cc058dd51803180b1baa0013322323300100100322533301a00115330174901064c38393b313100161323253330183375e601060366ea800801440084cc010010004c078008c070004dd61801180a9baa001301830153754008600260286ea80148c05c004dc3a40042940c004c044dd50011180a180a8008a4c26cac646600200200444a66602200229309919801801980a80119192999807980418089baa0011325333014001153301100e161323253330160011533013010161323253330180011533015012161325333019301c002149854cc05804c58c94cccccc07400454cc05804c5854cc05804c5854cc05804c584dd68008a9980b0098b180d000980d00119299999980d8008a9980a0088b0a9980a0088b0a9980a0088b0a9980a0088b09bae00130180013018002325333333019001153301200f16153301200f16153301200f16153301200f161375c002602c00260246ea800454cc040034594cccccc058004400454cc03c0305854cc03c0305854cc03c0305854cc03c03058c04c0054cccccc04800454cc02c0205854cc02c020584dd60008a998058040b0a998058040b29999998080010a999804180098051baa0021533300c300b37540042930a998048038b0a998048038b0a998048038b0a998048038b0a998048038b0a998048038b1b8748000dd7000a49054c33363b39004901064c32323b3237004901064c32323b3133005734ae7155ceaab9e5573eae815d0aba2574898111501aa0e79ca441d5e8619135497bdcbd640001", - "hash": "17f9ef7685d1937878f5370ba87457057cd34317762efea290535682" - } - ], - "definitions": { - "ByteArray": { - "dataType": "bytes" - }, - "Int": { - "dataType": "integer" - }, - "List$assist/types/token/Token": { - "dataType": "list", - "items": { - "$ref": "#/definitions/assist~1types~1token~1Token" - } - }, - "Void": { - "title": "Unit", - "description": "The nullary constructor.", - "anyOf": [ - { - "dataType": "constructor", - "index": 0, - "fields": [] - } - ] - }, - "assist/types/token/Token": { - "title": "Token", - "description": "A token type for a safe single policy id and asset name value.", - "anyOf": [ - { - "title": "Token", - "dataType": "constructor", - "index": 0, - "fields": [ - { - "title": "pid", - "$ref": "#/definitions/ByteArray" - }, - { - "title": "tkn", - "$ref": "#/definitions/ByteArray" - }, - { - "title": "amt", - "$ref": "#/definitions/Int" - } - ] - } - ] - } - } -} \ No newline at end of file From 6eaa6981ad268997840b060a19d67a63f532e1c3 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Thu, 2 May 2024 16:16:19 -0700 Subject: [PATCH 2/2] desugared the transaction, start_info is now config, and random strings are in config --- README.md | 20 ++++--- aiken.toml | 2 +- complete_build.sh | 18 +++--- start_info.json => config.json | 8 ++- scripts/all_balances.sh | 2 +- scripts/lock_ft/01_createPermaLockFTUTxO.sh | 8 +-- scripts/lock_ft/02_permaLockFT.sh | 6 +- scripts/lock_nft/01_createPermaLockNFTUTxO.sh | 2 +- scripts/lock_nft/02_permaLockNFT.sh | 2 +- scripts/lock_nft/30_testMaxUTxOSize.sh | 2 +- scripts/lock_nft/31_testMaxTokensPerTx.sh | 2 +- scripts/trade_token.sh | 4 +- validators/perma_lock_ft.ak | 58 +++++++++---------- validators/perma_lock_nft.ak | 56 +++++++++--------- 14 files changed, 95 insertions(+), 95 deletions(-) rename start_info.json => config.json (56%) diff --git a/README.md b/README.md index 42554ac..cdc4580 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,19 @@ The `Perma Lock NFT` contract is designed to permanently lock various types of t ## **Configuration** -Configuring the `Perma Lock FT` contract begins by specifying the token details inside `start_info.json`: +Configuring the `Perma Lock FT` contract begins by specifying the required compile information inside `config.json`: ```json { - "__comment1__": "This is the ft to lock for the perma lock ft contract", - "lockingPid": "954fe5769e9eb8dad54c99f8d62015c813c24f229a4d98dbf05c28b9", - "lockingNFT": "546869735f49735f415f566572795f4c6f6e675f537472696e675f5f5f5f5f5f", - "__comment2__": "This is maximum amount of the ft in existence.", - "maxTokenAmt": 9223372036854775807 + "__comment1__": "The FT compile information", + "lockingPid": "d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf", + "lockingTkn": "546869735f49735f415f566572795f4c6f6e675f537472696e675f5f5f5f5f5f", + "maxTokenAmt": 9223372036854775807, + "randomString1": "acab", + "__comment2__": "The NFT compile information", + "randomString2": "cafe", + "__comment3__": "Place a static stake key here for testing", + "stakeKey": "stake_test1uzl65wzu364hh0wxex94qsf5xkeaq2mnmc7xgnsnsjuqr4qruvxwu" } ``` @@ -65,7 +69,7 @@ To add tokens to the `Perma Lock FT` contract: ./02_permaLockFT.sh 123456789 ``` -The command above locks 123,456,789 tokens into the contract, as specified in the `start_info.json`. +The command above locks 123,456,789 tokens into the contract, as specified in the `config.json`. To add tokens to the `Perma Lock NFT` contract: @@ -81,6 +85,6 @@ The command above locks some amount of tokens into the contract, as specified by Worst case for the nft lock is 64 unique policy ids. On pre-production, the UTxO `2981fdc49509b9cfc1c122b0dfc2563f29e49c2a07337ad55da3e2017a561124#0` is currently maxed out. -Worst case for the nft lock per transaction is 36. On pre-production, the UTxO `ff9b410414a5a5c0a2f63e9358b7299d296bb304ae579360dccf008357149809` shows the maximum amount of tokens for a single transaction. +Worst case for the nft lock per transaction is 36. On pre-production, the transaction `ff9b410414a5a5c0a2f63e9358b7299d296bb304ae579360dccf008357149809` shows the maximum amount of tokens for a single transaction. The max memory parameter would have to be increased at the protocol level to account for more unique policy ids on the UTxO. \ No newline at end of file diff --git a/aiken.toml b/aiken.toml index 8956355..e5d3379 100644 --- a/aiken.toml +++ b/aiken.toml @@ -1,5 +1,5 @@ name = "dripdropz/perma-lock" -version = "1.1.2" +version = "1.1.3" license = "GPL-3.0-or-later" description = "Perma Lock Contract For Dripdropz" diff --git a/complete_build.sh b/complete_build.sh index b8222b0..c03a828 100755 --- a/complete_build.sh +++ b/complete_build.sh @@ -27,18 +27,19 @@ aiken build --trace-level compact --filter-traces all echo -e "\033[1;34m\nBuilding FT Contract \033[0m" # the locking token information -locking_pid=$(jq -r '.lockingPid' start_info.json) -locking_tkn=$(jq -r '.lockingTkn' start_info.json) +locking_pid=$(jq -r '.lockingPid' config.json) +locking_tkn=$(jq -r '.lockingTkn' config.json) # convert token info into proper cbor locking_pid_cbor=$(python3 -c "import cbor2;hex_string='${locking_pid}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())") locking_tkn_cbor=$(python3 -c "import cbor2;hex_string='${locking_tkn}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())") # randomly generate a length 32 hex string -random_string=$(LC_ALL=C tr -dc a-f0-9 contracts/perma_lock_ft_contra echo -e "\033[1;34m\nBuilding NFT Contract \033[0m" # randomly generate a length 32 hex string -random_string=$(LC_ALL=C tr -dc a-f0-9 Bool { - when context.purpose is { - // spend only - Spend(out_ref) -> { - // the entire transaction - let tx: Transaction = context.transaction - // this input being validated - let this_input: Input = find.input_by_ref(tx.inputs, out_ref) - // this address being spent from - let this_addr: Address = this_input.output.address - // calculate that value returning to this address - let that_value: Value = - this_input.output.value |> value.add(lock_pid, lock_tkn, add_amt) - // this silent fails for anything coming back that isn't the Void type - expect _: Void = find.output_datum_by_addr(tx.outputs, this_addr) - // - // Add `amt lock_pid.lock_tkn` to this value and send that value back - // to this address. - // - and { - // single script input - count.inputs_by_addr(tx.inputs, this_addr, 1)?, - // single script output - count.outputs_by_addr(tx.outputs, this_addr, 1)?, - // add tokens only - (add_amt > 0)?, - // send exactly that value back to this address - payout.exact(this_addr, that_value, tx.outputs)?, - } - } - // anything else fails - _ -> False + // must be spending + expect Spend(out_ref) = context.purpose + // the transaction being validated + let Transaction { inputs, outputs, .. } = context.transaction + // this input being validated + let this_input: Input = find.input_by_ref(inputs, out_ref) + // this address being spent from + let this_addr: Address = this_input.output.address + // calculate that value returning to this address + let that_value: Value = + this_input.output.value |> value.add(lock_pid, lock_tkn, add_amt) + // this silent fails for anything coming back that isn't the Void type + expect _: Void = find.output_datum_by_addr(outputs, this_addr) + // + // Add `add_amt lock_pid.lock_tkn` to this value and send that value back + // to this address. The add amount must be positive and the value being + // sent back must be exact. + // + and { + // single script input + count.inputs_by_addr(inputs, this_addr, 1)?, + // single script output + count.outputs_by_addr(outputs, this_addr, 1)?, + // can only add an amount of token + (add_amt > 0)?, + // send exactly that value back to this address + payout.exact(this_addr, that_value, outputs)?, } } } diff --git a/validators/perma_lock_nft.ak b/validators/perma_lock_nft.ak index 28b7bd8..413ee50 100644 --- a/validators/perma_lock_nft.ak +++ b/validators/perma_lock_nft.ak @@ -20,36 +20,32 @@ validator( _random_string: ByteArray, ) { fn params(_datum: Void, assets: Tokens, context: ScriptContext) -> Bool { - when context.purpose is { - // spend only - Spend(out_ref) -> { - // the entire transaction - let tx: Transaction = context.transaction - // this input being validated - let this_input: Input = find.input_by_ref(tx.inputs, out_ref) - // this address being spent from - let this_addr: Address = this_input.output.address - // calculate that value returning to this address - let that_value: Value = - this_input.output.value |> token.add_tokens_to_value(assets) - // this silent fails for anything coming back that isn't the Void type - expect _: Void = find.output_datum_by_addr(tx.outputs, this_addr) - // - // Add a list of tokens to this value and send that value back to this address. - // - and { - // single script input - count.inputs_by_addr(tx.inputs, this_addr, 1)?, - // single script output - count.outputs_by_addr(tx.outputs, this_addr, 1)?, - // send at least that value back to this address - payout.at_least(this_addr, that_value, tx.outputs)?, - // add tokens only - token.addition_only(assets)?, - } - } - // anything else fails - _ -> False + // must be spending + expect Spend(out_ref) = context.purpose + // the transaction being validated + let Transaction { inputs, outputs, .. } = context.transaction + // this input being validated + let this_input: Input = find.input_by_ref(inputs, out_ref) + // this address being spent from + let this_addr: Address = this_input.output.address + // calculate that value returning to this address + let that_value: Value = + this_input.output.value |> token.add_tokens_to_value(assets) + // this silent fails for anything coming back that isn't the Void type + expect _: Void = find.output_datum_by_addr(outputs, this_addr) + // + // Add tokens to this value and send at least that value back to this + // address. All tokens being added to that value must be positive. + // + and { + // single script input + count.inputs_by_addr(inputs, this_addr, 1)?, + // single script output + count.outputs_by_addr(outputs, this_addr, 1)?, + // send at least that value back to this address + payout.at_least(this_addr, that_value, outputs)?, + // can only add tokens + token.addition_only(assets)?, } } }