Skip to content

Commit

Permalink
Merge pull request #11 from DripDropz/desugar-transaction
Browse files Browse the repository at this point in the history
Desugar transaction
  • Loading branch information
logicalmechanism authored May 6, 2024
2 parents 52b02bf + 6eaa698 commit 7757ff0
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 195 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ docs/
aiken.lock
.github/
contracts/
hashes/
hashes/
plutus.json
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand Down Expand Up @@ -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:

Expand All @@ -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.
2 changes: 1 addition & 1 deletion aiken.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
18 changes: 10 additions & 8 deletions complete_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 </dev/urandom | head -c 32)
random_cbor=$(python3 -c "import cbor2;hex_string='${random_string}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())")
# random_string1=$(LC_ALL=C tr -dc a-f0-9 </dev/urandom | head -c 32)
random_string1=$(jq -r '.randomString1' config.json)
random_cbor=$(python3 -c "import cbor2;hex_string='${random_string1}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())")

echo Random String 1: ${random_string}
echo Random String 1: ${random_string1}

echo -e "\033[1;33m Convert Perma Lock FT Contract \033[0m"

Expand All @@ -57,10 +58,11 @@ aiken blueprint convert -v perma_lock_ft.params > 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 </dev/urandom | head -c 32)
random_cbor=$(python3 -c "import cbor2;hex_string='${random_string}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())")
# random_string=$(LC_ALL=C tr -dc a-f0-9 </dev/urandom | head -c 32)
random_string2=$(jq -r '.randomString2' config.json)
random_cbor=$(python3 -c "import cbor2;hex_string='${random_string2}';data = bytes.fromhex(hex_string);encoded = cbor2.dumps(data);print(encoded.hex())")

echo Random String 2: ${random_string}
echo Random String 2: ${random_string2}

echo -e "\033[1;33m Convert Perma Lock NFT Contract \033[0m"

Expand Down
8 changes: 5 additions & 3 deletions start_info.json → config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"__comment1__": "This is the ft to lock for the perma lock ft contract",
"__comment1__": "The FT compile information",
"lockingPid": "d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf",
"lockingTkn": "546869735f49735f415f566572795f4c6f6e675f537472696e675f5f5f5f5f5f",
"__comment2__": "This is maximum amount of the ft in existence.",
"maxTokenAmt": 9223372036854775807,
"__comment3__": "Place a static stake key here",
"randomString1": "acab",
"__comment2__": "The NFT compile information",
"randomString2": "acab",
"__comment3__": "Place a static stake key here for testing",
"stakeKey": "stake_test1uzl65wzu364hh0wxex94qsf5xkeaq2mnmc7xgnsnsjuqr4qruvxwu"
}
99 changes: 0 additions & 99 deletions plutus.json

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/all_balances.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cli=$(cat ./data/path_to_cli.sh)
testnet_magic=$(cat ./data/testnet.magic)

# stake key
stake_key=$(jq -r '.stakeKey' ../start_info.json)
stake_key=$(jq -r '.stakeKey' ../config.json)

# perma lock ft contract
perma_lock_ft_script_path="../contracts/perma_lock_ft_contract.plutus"
Expand Down
8 changes: 4 additions & 4 deletions scripts/lock_ft/01_createPermaLockFTUTxO.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cli=$(cat ../data/path_to_cli.sh)
testnet_magic=$(cat ../data/testnet.magic)

# stake key
stake_key=$(jq -r '.stakeKey' ../../start_info.json)
stake_key=$(jq -r '.stakeKey' ../../config.json)

# perma lock contract
perma_lock_ft_script_path="../../contracts/perma_lock_ft_contract.plutus"
Expand All @@ -18,9 +18,9 @@ user_address=$(cat ../wallets/${user_path}/payment.addr)
user_pkh=$(${cli} address key-hash --payment-verification-key-file ../wallets/${user_path}/payment.vkey)

# this is the maximum amount of tokens that could possible exist
locking_pid=$(jq -r '.lockingPid' ../../start_info.json)
locking_tkn=$(jq -r '.lockingTkn' ../../start_info.json)
max_tkn_amt=$(jq -r '.maxTokenAmt' ../../start_info.json)
locking_pid=$(jq -r '.lockingPid' ../../config.json)
locking_tkn=$(jq -r '.lockingTkn' ../../config.json)
max_tkn_amt=$(jq -r '.maxTokenAmt' ../../config.json)
worst_case_value="${max_tkn_amt} ${locking_pid}.${locking_tkn}"

# calc the min ada required for the worst case value and datum
Expand Down
6 changes: 3 additions & 3 deletions scripts/lock_ft/02_permaLockFT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ python -c "import json; data=json.load(open('../data/add-ft-redeemer.json', 'r')
# python -c "import json; data=json.load(open('../data/add-ft-redeemer.json', 'r')); data['fields'][0]['int'] = $token_amt; json.dump(data, open('../data/add-ft-redeemer.json', 'w'), indent=2)"

# stake key
stake_key=$(jq -r '.stakeKey' ../../start_info.json)
stake_key=$(jq -r '.stakeKey' ../../config.json)

# perma lock contract
perma_lock_ft_script_path="../../contracts/perma_lock_ft_contract.plutus"
Expand Down Expand Up @@ -53,8 +53,8 @@ TXIN=$(jq -r --arg alltxin "" 'keys[] | . + $alltxin + " --tx-in"' ../tmp/script
script_tx_in=${TXIN::-8}


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)
# this should work for the min lovelace
script_lovelace=$(jq '[.[] | .value.lovelace] | add' ../tmp/script_utxo.json)
# get the current token amount but account for numbers below 2^63 -1
Expand Down
2 changes: 1 addition & 1 deletion scripts/lock_nft/01_createPermaLockNFTUTxO.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cli=$(cat ../data/path_to_cli.sh)
testnet_magic=$(cat ../data/testnet.magic)

# stake key
stake_key=$(jq -r '.stakeKey' ../../start_info.json)
stake_key=$(jq -r '.stakeKey' ../../config.json)

# perma lock contract
perma_lock_nft_script_path="../../contracts/perma_lock_nft_contract.plutus"
Expand Down
2 changes: 1 addition & 1 deletion scripts/lock_nft/02_permaLockNFT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ user_tx_in=${TXIN::-8}
python ../py/tokens.py

# stake key
stake_key=$(jq -r '.stakeKey' ../../start_info.json)
stake_key=$(jq -r '.stakeKey' ../../config.json)

# perma lock contract
perma_lock_nft_script_path="../../contracts/perma_lock_nft_contract.plutus"
Expand Down
2 changes: 1 addition & 1 deletion scripts/lock_nft/30_testMaxUTxOSize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ json.dump(data, open('../data/add-nft-redeemer.json', 'w'), indent=2)
"

# stake key
stake_key=$(jq -r '.stakeKey' ../../start_info.json)
stake_key=$(jq -r '.stakeKey' ../../config.json)

# perma lock contract
perma_lock_nft_script_path="../../contracts/perma_lock_nft_contract.plutus"
Expand Down
2 changes: 1 addition & 1 deletion scripts/lock_nft/31_testMaxTokensPerTx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ user_token_string=$(cat ../data/token_string.txt)
echo $user_token_string

# stake key
stake_key=$(jq -r '.stakeKey' ../../start_info.json)
stake_key=$(jq -r '.stakeKey' ../../config.json)

# perma lock contract
perma_lock_nft_script_path="../../contracts/perma_lock_nft_contract.plutus"
Expand Down
4 changes: 2 additions & 2 deletions scripts/trade_token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ sender_path="./wallets/user-wallet/"
sender_address=$(cat ${sender_path}payment.addr)
receiver_address="addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp"

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)

echo -e "\033[0;36m Gathering UTxO Information \033[0m"
${cli} query utxo \
Expand Down
Loading

0 comments on commit 7757ff0

Please sign in to comment.