From 109dee28a735319f12aea16f5df01f9252f6b788 Mon Sep 17 00:00:00 2001 From: Mark Paul Date: Thu, 4 Apr 2024 23:44:29 +1100 Subject: [PATCH 1/2] wip: some lcoal updates --- README.md | 2 +- interaction/devnet.snippets.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4e0d684..80f8f1c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ See `devnet.snippets.sh` for list of available endpoints for user testing. ### Setting up dev environment (project development bootstrap) + how to build (and upgrade) -- Uses `multiversx-sc-* 0.47.5` (In v1.0.0, we used 0.47.5) SDK libs (see Cargo.toml) +- Uses `multiversx-sc-* 0.47.8` (In v1.0.0, we used 0.47.8) SDK libs (see Cargo.toml) - Building requires minimum **mxpy 9.5.1** (In v1.0.0, we used mxpy 9.5.1). Check version using `mxpy --version` - To build the project, requires minimum Rust version `1.78.0-nightly` (In v1.0.0, we used 1.78.0-nightly). Check your Rust version by running `rustc --version`. To update your Rust, run `rustup update`. To set to nightly run `rustup default nightly`. Note that `mxpy deps install rust --overwrite` also brings in it's own compatible rust version so running `rustup default nightly` might have a higher rust version than what is used via `mxpy deps install rust --overwrite`. - After you make sure you have the minimum Rust version you can then begin development. After you clone repo and before you run build, deploy or run the tests - follow these steps (most likely only needed the 1st time) diff --git a/interaction/devnet.snippets.sh b/interaction/devnet.snippets.sh index cf311af..e44f690 100644 --- a/interaction/devnet.snippets.sh +++ b/interaction/devnet.snippets.sh @@ -60,7 +60,7 @@ restoreDeployData() { # after we upgraded to mxpy 8.1.2, mxpy data parse seems to load the ADDRESS correctly but it breaks when used below with a weird "Bad address" error # so, we just hardcode the ADDRESS here. Just make sure you use the "data['contractAddress'] from the latest deploy-devnet.interaction.json file - ADDRESS="erd1qqqqqqqqqqqqqpgq4xqxlq8p8zenrq4f0htgcwjzdlwmrhwdfsxsmavcuq" + ADDRESS="erd1qqqqqqqqqqqqqpgqhlyaj872kyh620zsfew64l2k4djerw2tfsxsmrxlan" } setAdministrator(){ From 3bc0613a1fb49c680dd5d4811bf12686659b8b4a Mon Sep 17 00:00:00 2001 From: Mark Paul Date: Fri, 3 May 2024 18:16:20 +1000 Subject: [PATCH 2/2] feature: updated snippets after final mainnet deployment --- interaction/devnet.snippets.sh | 23 ++- interaction/mainnet.snippets.sh | 310 ++++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+), 2 deletions(-) create mode 100644 interaction/mainnet.snippets.sh diff --git a/interaction/devnet.snippets.sh b/interaction/devnet.snippets.sh index e44f690..9a1f9cf 100644 --- a/interaction/devnet.snippets.sh +++ b/interaction/devnet.snippets.sh @@ -42,9 +42,9 @@ deploy(){ # in below code example we added --metadata-payable to add PAYABLE to the prop of the SC and removed --metadata-not-readable to make it READABLE upgrade(){ mxpy --verbose contract upgrade ${ADDRESS} \ - --bytecode output/core-mx-life-bonding-sc.wasm \ + --bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \ + --metadata-not-readable \ --metadata-payable-by-sc \ - --metadata-payable \ --pem ${WALLET} \ --proxy ${PROXY} \ --chain ${CHAIN_ID} \ @@ -275,3 +275,22 @@ renewWithNewLockPeriod(){ --chain ${CHAIN_ID} \ --send || return } + +initiateBond() { + # $1 = the address for who the bond is initiated + # $2 = token identifier + # $3 = nonce + + address="0x$(mxpy wallet bech32 --decode ${1})" + token_identifier="0x$(echo -n ${2} | xxd -p -u | tr -d '\n')" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --pem=${WALLET} \ + --gas-limit=20000000 \ + --function "initiateBond" \ + --arguments $address $token_identifier $3 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --send || return +} diff --git a/interaction/mainnet.snippets.sh b/interaction/mainnet.snippets.sh new file mode 100644 index 0000000..8cc7c66 --- /dev/null +++ b/interaction/mainnet.snippets.sh @@ -0,0 +1,310 @@ +PROXY=https://gateway.multiversx.com +CHAIN_ID="1" + +ADDRESS=$(mxpy data load --key=address-mainnet) +DEPLOY_TRANSACTION=$(mxpy data load --key=deployTransaction-mainnet) + +TOKEN="ITHEUM-df6f26" +TOKEN_HEX="0x$(echo -n ${TOKEN} | xxd -p -u | tr -d '\n')" + +# to deploy from last reprodubible build, we need to change or vice versa +# --bytecode output/core-mx-life-bonding-sc.wasm \ +# to +# --bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \ +deployLedgerMainnet(){ + mxpy --verbose contract deploy \ + --bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \ + --outfile deployOutput \ + --metadata-not-readable \ + --metadata-payable-by-sc \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --gas-limit 150000000 \ + --send \ + --recall-nonce \ + --ledger \ + --ledger-address-index 0 \ + --outfile="./interaction/deploy-mainnet.interaction.json" || return + + TRANSACTION=$(mxpy data parse --file="./interaction/deploy-mainnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="./interaction/deploy-mainnet.interaction.json" --expression="data['contractAddress']") + + mxpy data store --key=address-mainnet --value=${ADDRESS} + mxpy data store --key=deployTransaction-mainnet --value=${TRANSACTION} +} + +# any change to code or property requires a full upgrade +# always check if you are deploy via a reprodubible build and that the code hash is the same before and after upgrade (that is if you are only changing props and not code.. for code, the RB will be different) +# if only changing props, you can't just "append" new props. you have to add the old ones again and then add a new prop you need. i.e. it's not append, it's a whole reset +# for upgrade, --outfile deployOutput is not needed +# in below code example we added --metadata-payable to add PAYABLE to the prop of the SC and removed --metadata-not-readable to make it READABLE +upgrade(){ + mxpy --verbose contract upgrade ${ADDRESS} \ + --bytecode output-docker/core-mx-life-bonding-sc/core-mx-life-bonding-sc.wasm \ + --metadata-payable-by-sc \ + --metadata-payable \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --gas-limit 150000000 \ + --recall-nonce \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +# if you interact without calling deploy(), then you need to 1st run this to restore the vars from data +restoreDeployDataLedgerMainnet(){ + TRANSACTION=$(mxpy data parse --file="./interaction/deploy-mainnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="./interaction/deploy-mainnet.interaction.json" --expression="data['contractAddress']") + + # after we upgraded to mxpy 8.1.2, mxpy data parse seems to load the ADDRESS correctly but it breaks when used below with a weird "Bad address" error + # so, we just hardcode the ADDRESS here. Just make sure you use the "data['contractAddress'] from the latest deploy-devnet.interaction.json file + ADDRESS="erd1qqqqqqqqqqqqqpgq9yfa4vcmtmn55z0e5n84zphf2uuuxxw9c77qgqqwkn" +} + +setAdministratorMainnet(){ + # $1 = address + + address="0x$(mxpy wallet bech32 --decode ${1})" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setAdministrator" \ + --arguments $address \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setContractStateActiveMainnet(){ + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setContractStateActive" \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setContractStateInactiveMainnet(){ + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setContractStateInactive" \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setAcceptedCallersMainnet(){ + # $1 = address + + address="0x$(mxpy wallet bech32 --decode ${1})" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setAcceptedCallers" \ + --arguments $address \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setBondTokenMainnet(){ + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setBondToken" \ + --arguments $TOKEN_HEX \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setPeriodsBondsMainnet(){ + # $1 = lockPeriod + # $2 = bond + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setPeriodsBonds" \ + --arguments $1 $2 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setMinimumPenaltyMainnet(){ + # $1 = minimumPenalty + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setMinimumPenalty" \ + --arguments $1 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setMaximumPenaltyMainnet(){ + # $1 = maximumPenalty + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setMaximumPenalty" \ + --arguments $1 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +setWithdrawPenaltyMainnet(){ + # $1 = withdrawPenalty + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "setWithdrawPenalty" \ + --arguments $1 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +sanctionMainnet(){ + # $1 = token identifier + # $2 = nonce + # $3 = penalty (0=minimum, 1=custom, 2=maximum) + # $4 = custom penalty (if $3=1) + + token_identifier="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')" + penalty=$3 + custom_penalty=$4 + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "sanction" \ + --arguments $token_identifier $2 $penalty $custom_penalty \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +modifyBondMainnet(){ + # $1 = token identifier + # $2 = nonce + + token_identifier="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "modifyBond" \ + --arguments $token_identifier $2 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +withdrawMainnet(){ + # $1 = token identifier + # $2 = nonce + + token_identifier="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=20000000 \ + --function "withdraw" \ + --arguments $token_identifier $2 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +renewMainnet(){ + # $1 = token identifier + # $2 = nonce + + token_identifier="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "renew" \ + --arguments $token_identifier $2 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +renewWithNewLockPeriodMainnet(){ + # $1 = token identifier + # $2 = nonce + # $3 = lockPeriod + + token_identifier="0x$(echo -n ${1} | xxd -p -u | tr -d '\n')" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=6000000 \ + --function "renew" \ + --arguments $token_identifier $2 $3 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +} + +initiateBondMainnet() { + # $1 = the address for who the bond is initiated + # $2 = token identifier + # $3 = nonce + + address="0x$(mxpy wallet bech32 --decode ${1})" + token_identifier="0x$(echo -n ${2} | xxd -p -u | tr -d '\n')" + + mxpy --verbose contract call ${ADDRESS} \ + --recall-nonce \ + --gas-limit=20000000 \ + --function "initiateBond" \ + --arguments $address $token_identifier $3 \ + --proxy ${PROXY} \ + --chain ${CHAIN_ID} \ + --ledger \ + --ledger-address-index 0 \ + --send || return +}