Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract review 1 #7

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Use the `complete_build.sh` script to build the contracts using the data from `c

## Headless Interaction

Use the `scripts` folder to interact with the dapp using the cardano-cli.
Use the `headless` folder to interact with the dapp using the cardano-cli.

## CIP30 Frontend Interaction

Expand Down
9 changes: 5 additions & 4 deletions complete_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ rm -fr build/ || true
echo -e "\033[1;34m Building Contracts \033[0m"

# remove all traces for production
aiken build --trace-level silent --filter-traces user-defined
# aiken build --trace-level silent --filter-traces user-defined

# partial traces
aiken build --trace-level compact --filter-traces user-defined

# keep the traces for testing
# aiken build --trace-level verbose --filter-traces all
Expand Down Expand Up @@ -96,8 +99,6 @@ echo -e "\033[1;33m Thread Contract Hash: $(cat hashes/thread_contract.hash) \03

thread_vkh=$(cat hashes/thread_contract.hash)

###############################################################################
############## DATUM AND REDEEMER STUFF #######################################
###############################################################################

jq \
Expand All @@ -110,7 +111,7 @@ jq \
.fields[2].bytes=$cvkh |
.fields[3].bytes=$tvkh
' \
./scripts/data/reference/reference-datum.json | sponge ./scripts/data/reference/reference-datum.json
./headless/data/reference/reference-datum.json | sponge ./headless/data/reference/reference-datum.json

# end of build
echo -e "\033[1;32m\nBuilding Complete! \033[0m"
6 changes: 4 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"__comment1__": "Genesis UTxO From Starter Wallet",
"genesis_tx_id": "64a77e920056af16040e372df803980dc96f045dc10f6133c604a0e60d99ea57",
"genesis_tx_id": "d235ed02346839c6ae5f07191d6b5da2850c2adcef55a3fa435134add0135823",
"genesis_tx_idx": 0,
"__comment2__": "Random String For Data Reference",
"random_string": "08"
"random_string": "16",
"__comment3__": "Change address for reference and genesis",
"change_address": "addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp"
}
48 changes: 45 additions & 3 deletions headless/00_createScriptReferences.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ ${cli} query protocol-parameters ${network} --out-file ./tmp/protocol.json
# Addresses
reference_address=$(cat ./wallets/reference-wallet/payment.addr)

# address to send the leftover ada too
change_address=$(jq -r '.change_address' ../config.json)

# perma lock the script references to the reference contract
reference_script_path="../contracts/reference_contract.plutus"
script_reference_address=$(${cli} address build --payment-script-file ${reference_script_path} ${network})
Expand Down Expand Up @@ -62,7 +65,7 @@ do
--tx-out-reference-script-file ${contract} \
--fee 900000

FEE=$(cardano-cli transaction calculate-min-fee \
FEE=$(${cli} transaction calculate-min-fee \
--tx-body-file ./tmp/tx.draft \
${network} \
--protocol-params-file ./tmp/protocol.json \
Expand Down Expand Up @@ -90,12 +93,47 @@ do
--out-file ./tmp/utxo-${file_name}.signed \
${network}

ref_tx_in=$(${cli} transaction txid --tx-body-file ./tmp/tx.draft)#0
tx_id=$(${cli} transaction txid --tx-body-file ./tmp/tx.draft)
ref_tx_in=${tx_id}#0
echo
echo -e "\033[0;36mNext UTxO: $ref_tx_in \033[0m"
echo -e "\033[0;36m$file_name: $tx_id#1 \033[0m"

done

${cli} transaction build-raw \
--babbage-era \
--protocol-params-file ./tmp/protocol.json \
--out-file ./tmp/tx.draft \
--tx-in ${ref_tx_in} \
--tx-out="${change_address} + ${changeAmount}" \
--fee 900000

FEE=$(${cli} transaction calculate-min-fee \
--tx-body-file ./tmp/tx.draft \
${network} \
--protocol-params-file ./tmp/protocol.json \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1)
echo -e "\033[0;35mFEE: ${FEE} \033[0m"
fee=$(echo $FEE | rev | cut -c 9- | rev)

changeAmount=$((${changeAmount} - ${fee}))

${cli} transaction build-raw \
--babbage-era \
--protocol-params-file ./tmp/protocol.json \
--out-file ./tmp/tx.draft \
--tx-in ${ref_tx_in} \
--tx-out="${change_address} + ${changeAmount}" \
--fee ${fee}

${cli} transaction sign \
--signing-key-file ./wallets/reference-wallet/payment.skey \
--tx-body-file ./tmp/tx.draft \
--out-file ./tmp/change-tx.signed \
${network}

echo -e "\033[1;37m --------------------------------------------------------------------------------\033[0m"
# now submit them in that order
for contract in $(ls "../contracts"/* | sort -V)
Expand All @@ -108,4 +146,8 @@ do
--tx-file ./tmp/utxo-${file_name}.signed
done

${cli} transaction submit \
${network} \
--tx-file ./tmp/change-tx.signed

echo -e "\033[0;32m\nDone!\033[0m"
13 changes: 2 additions & 11 deletions headless/01_genesisMint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ reference_script_address=$(${cli} address build --payment-script-file ${referenc
genesis_script_path="../contracts/genesis_contract.plutus"
genesis_policy_id=$(cat ../hashes/genesis_contract.hash)

# fraction estate wallet
# starter wallet
starter_address=$(cat wallets/starter-wallet/payment.addr)
starter_pkh=$(${cli} address key-hash --payment-verification-key-file wallets/starter-wallet/payment.vkey)

change_address="addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp"
change_address=$(jq -r '.change_address' ../config.json)

# collat wallet
collat_address=$(cat wallets/collat-wallet/payment.addr)
collat_pkh=$(${cli} address key-hash --payment-verification-key-file wallets/collat-wallet/payment.vkey)


echo -e "\033[0;36m Gathering Starter UTxO Information \033[0m"
${cli} query utxo \
${network} \
Expand Down Expand Up @@ -53,7 +52,6 @@ genesis_tkn="${full_genesis_tkn:0:64}"
mint_genesis_asset="1 ${genesis_policy_id}.${genesis_tkn}"
echo -e "\033[1;36m\nGenesis Token: ${mint_genesis_asset} \033[0m"


# mint 1 genesis token and burn 100M old fet
mint_asset="${mint_genesis_asset}"

Expand Down Expand Up @@ -82,17 +80,10 @@ collat_utxo=$(jq -r 'keys[0]' tmp/collat_utxo.json)

genesis_ref_utxo=$(${cli} transaction txid --tx-file tmp/utxo-genesis_contract.plutus.signed )

# slot contraints
slot=$(${cli} query tip ${network} | jq .slot)
current_slot=$(($slot - 1))
final_slot=$(($slot + 2500))

echo -e "\033[0;36m Building Tx \033[0m"
FEE=$(${cli} transaction build \
--babbage-era \
--out-file tmp/tx.draft \
--invalid-before ${current_slot} \
--invalid-hereafter ${final_slot} \
--change-address ${change_address} \
--tx-in-collateral="${collat_utxo}" \
--tx-in ${starter_tx_in} \
Expand Down
1 change: 0 additions & 1 deletion headless/cogno/01_createCogno.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ UTXO_VALUE=$(${cli} transaction calculate-min-required-utxo \
--tx-out="${cogno_script_address} + 5000000 + ${MINT_ASSET}" | tr -dc '0-9')
cogno_address_out="${cogno_script_address} + ${UTXO_VALUE} + ${MINT_ASSET}"


echo "Cogno OUTPUT:" ${cogno_address_out}
#
# exit
Expand Down
14 changes: 14 additions & 0 deletions headless/data/cogno/cogno-datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
"bytes": ""
}
]
},
{
"constructor": 0,
"fields": [
{
"list": []
},
{
"list": []
},
{
"list": []
}
]
}
]
}
2 changes: 1 addition & 1 deletion headless/data/cogno/token.name
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cafebabe00ac8e5e2f504e19d70a15539d99f863bb0bebc3f5c445fa9b42a566
cafebabe00198bc57f19a5ef202e916693db2f0aa39379ca337e1fa06531fb72
14 changes: 14 additions & 0 deletions headless/data/cogno/updated-cogno-datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
"bytes": ""
}
]
},
{
"constructor": 0,
"fields": [
{
"list": []
},
{
"list": []
},
{
"list": []
}
]
}
]
}
8 changes: 4 additions & 4 deletions headless/data/reference/reference-datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"constructor": 0,
"fields": [
{
"bytes": "bb551e2b69f617a629c30ea72e136cea8a43ce3959a2c35eed93b943"
"bytes": "4387279867defd6ca72708ff601a1c1c218985cfad4a3a00bf39841d"
},
{
"bytes": "e1fe41795990685656635438f6427b6e5870a1e692260a5336d62ee9"
"bytes": "c85f8a7a6dc3bc8c541aa2c3350e0c1c996a666c627f8910d56f1d46"
},
{
"bytes": "8dfffee833c1f5f5a88382c5d19154517acfe5539296e1a2f4f8fac4"
"bytes": "1e7ced4cd5054b9a5ede4b1f5cf0452092874c81be30bd029878dd6a"
},
{
"bytes": "72c824ef52141a930fea10963bfcb73f6d114c8cafc1d6721c717e5e"
"bytes": "cee32b83349938116d94e1a550ec6c85d703cbb949c78dbcab25731b"
}
]
}
2 changes: 1 addition & 1 deletion headless/data/thread/thread-datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
},
{
"bytes": "cafebabe00ac8e5e2f504e19d70a15539d99f863bb0bebc3f5c445fa9b42a566"
"bytes": "cafebabe0035b6040bb1810776a1bea50e956e754fffd48f95bb53f01558c945"
}
]
}
2 changes: 1 addition & 1 deletion headless/data/thread/token.name
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1abe11ed007c7a9687a042efabf5acecce82030b010ce630e87c264981e183b2
1abe11ed00bc76a2013c2b81ac62a6cf0ae1b1338cae024eb6375b5658f3e452
2 changes: 1 addition & 1 deletion headless/data/thread/updated-thread-datum.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
},
{
"bytes": "cafebabe00ac8e5e2f504e19d70a15539d99f863bb0bebc3f5c445fa9b42a566"
"bytes": "cafebabe0035b6040bb1810776a1bea50e956e754fffd48f95bb53f01558c945"
}
]
}
4 changes: 2 additions & 2 deletions headless/trade_token.sh → headless/send_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ rm ./tmp/tx.signed || true
${cli} query protocol-parameters ${network} --out-file ./tmp/protocol.json

# Sender Address
sender_path="wallets/user-1-wallet/"
sender_path="wallets/reference-wallet/"
sender_address=$(cat ${sender_path}payment.addr)

# Receiver Address
# receiver_address=$(cat ${sender_path}payment.addr)
receiver_address="addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp"
receiver_address=$(jq -r '.change_address' ../config.json)
#
# exit
#
Expand Down
11 changes: 11 additions & 0 deletions lib/cogno_v2/types/cogno.ak
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aiken/transaction/value.{AssetName}
use assist/types/wallet.{Wallet}

pub type Profile {
Expand All @@ -6,9 +7,19 @@ pub type Profile {
details: ByteArray,
}

pub type Moderation {
// show posts from these users
friendly_user_list: List<AssetName>,
// do not show posts from these users
restricted_user_list: List<AssetName>,
// do not show these threads
restricted_thread_list: List<AssetName>,
}

pub type CognoDatum {
owner: Wallet,
profile: Profile,
moderation: Moderation,
}

pub type CognoRedeemer {
Expand Down
2 changes: 1 addition & 1 deletion lib/cogno_v2/types/thread.ak
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub type ThreadDatum {
category: ByteArray,
// a list of comments, can be strings or images
comments: List<ByteArray>,
// the tkn of the owner
// the cafebabe tkn of the owner
tkn: AssetName,
}

Expand Down
5 changes: 4 additions & 1 deletion validators/cogno.ak
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ validator(
|> value.from_minted_value()
|> value.flatten()
//
//
// Remove a cogno by burning the cafebabe token if it exists. This
// transaction is valid if and only if there exists a valid signature.
// If the cafebabe token doesn't exist then it is still removeable.
//
and {
// owner must sign
Expand All @@ -66,6 +68,7 @@ validator(
)?,
// must burn cafebabe token if it exists
or {
// if cogno exists then burn it
and {
values.prove_nft(
this_input.output.value,
Expand Down
5 changes: 3 additions & 2 deletions validators/cogno_minter.ak
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ validator(
extra_signatories,
..
} = context.transaction
// get tx info
// get first tx info
let index: Int = find.first_input_index(inputs)
let tx_hash: TxHash = find.first_input_txid(inputs)
// get reference data stuff
let ref_addr: Address = credential.from_script(data_ref_hash)
let ref_input: Input = find.input_by_addr(reference_inputs, ref_addr)
expect ref_datum: ReferenceDatum = data.input_datum(ref_input)
// generate the cafebabe token name
let token_name: AssetName = util.token_name(tx_hash, index, #"cafebabe")
// what is being minted in this transaction
let mint_list: List<(PolicyId, AssetName, Int)> =
Expand Down Expand Up @@ -73,7 +74,7 @@ validator(
value.from_asset(currency_symbol, token_name, 1),
outputs,
)?,
// can not spend anything from cogno address
// single output going to the cogno address
count.outputs_by_addr(outputs, cogno_addr, 1)?,
}
}
Expand Down
2 changes: 1 addition & 1 deletion validators/thread.ak
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ validator(
// transaction then it can be removed from the contract.
//
and {
// owner must sign
// owner must sign by referenced cogno
signing.verify_sig(extra_signatories, cogno_datum.owner.pkh)?,
// single script input, no script output
count.inputs_by_addr(inputs, this_addr, 1)?,
Expand Down
3 changes: 2 additions & 1 deletion validators/thread_minter.ak
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ validator(
MintToken -> {
let Transaction { inputs, reference_inputs, outputs, mint, .. } =
context.transaction
// get tx info
// get the first tx info
let index: Int = find.first_input_index(inputs)
let tx_hash: TxHash = find.first_input_txid(inputs)
// get reference data stuff
let ref_addr: Address = credential.from_script(data_ref_hash)
let ref_input: Input = find.input_by_addr(reference_inputs, ref_addr)
expect ref_datum: ReferenceDatum = data.input_datum(ref_input)
// generate the 1abe11ed token name
let token_name: AssetName = util.token_name(tx_hash, index, #"1abe11ed")
// what is being minted in this transaction
let mint_list: List<(PolicyId, AssetName, Int)> =
Expand Down