diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e196eb5..bc202994 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: - name: 'Install Foundry' uses: foundry-rs/foundry-toolchain@v1 with: - version: nightly + version: nightly-e649e62f125244a3ef116be25dfdc81a2afbaf2a - name: 'Setup Node.js' uses: actions/setup-node@v4 diff --git a/cpp/scripts/.env.example b/cpp/scripts/.env.example new file mode 100644 index 00000000..0133b9f7 --- /dev/null +++ b/cpp/scripts/.env.example @@ -0,0 +1,32 @@ +#chain endpoint +NODEOSURL=http://127.0.0.1:8888 + +# accounts +OWNER_NAME= +OWNER_PK_O= +OWNER_PK_A= +XTOKEN_NAME= +XTOKEN_PK_O= +XTOKEN_PK_A= +ADAPTER_NAME= +ADAPTER_PK_O= +ADAPTER_PK_A= +LOCKBOX_NAME= +LOCKBOX_PK_O= +LOCKBOX_PK_A= +FEESMANAGER_NAME= +FEESMANAGER_PK_O= +FEESMANAGER_PK_A= + + +# Underlying token info +IS_LOCAL= # true if underlying token is ANTELOPE type +UNDERLYING_NAME= +UNDERLYING_SYMBOL= +SYMBOL_BYTES= + +# xtoken info +MAX_SUPPLY= +BURN_LIMIT= +MINT_LIMIT= +MIN_FEE= \ No newline at end of file diff --git a/cpp/scripts/README.md b/cpp/scripts/README.md index 0a90e663..7bd4fe65 100644 --- a/cpp/scripts/README.md +++ b/cpp/scripts/README.md @@ -42,6 +42,10 @@ key of the first pair generated when the wallet was created. - Create an account through the `create-account.sh` script. This will create an account assigning the public key relative to the specified wallet. +## Deploy + +* `deploy-xtoken` can deploy an xtoken to testnet or mainnet given a list of accounts names and their pk. The list of account and token/xtoken infos must be passed through a `.env` file. + **Example:** ```bash diff --git a/cpp/scripts/adapter.sh b/cpp/scripts/adapter.sh index d7b788e5..456027dd 100755 --- a/cpp/scripts/adapter.sh +++ b/cpp/scripts/adapter.sh @@ -149,19 +149,20 @@ function adapter { local action local permission local shifting_pos - local contract + local contract_name local json - contract="${FUNCNAME[0]}" + contract_name="$1" + shift - contract_script_init action permission shifting_pos "$contract" "$@" + contract_script_init action permission shifting_pos "$contract_name" "$@" shift "$shifting_pos" adapter.get_json_params json "$action" "$@" # We call the action - push_action "$contract" "$action" "$json" "--permission" "$permission" + push_action "$contract_name" "$action" "$json" "--permission" "$permission" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/cpp/scripts/constants.sh b/cpp/scripts/constants.sh index 676ea477..ed4b5485 100644 --- a/cpp/scripts/constants.sh +++ b/cpp/scripts/constants.sh @@ -6,6 +6,10 @@ export FILE_ENV="$dir_name/../.env" source "$FILE_ENV" +# Endpoint +shopt -s expand_aliases +alias cleos="cleos -u \$NODEOSURL" + # Constants export FOLDER_EOS_DATA=eosio-data-dir export DIR_DATA="$dir_name/$FOLDER_EOS_DATA" diff --git a/cpp/scripts/deploy-xtoken.sh b/cpp/scripts/deploy-xtoken.sh new file mode 100755 index 00000000..776833b9 --- /dev/null +++ b/cpp/scripts/deploy-xtoken.sh @@ -0,0 +1,67 @@ +#!/bin/bash +dir_name=$(dirname "$(realpath "${BASH_SOURCE[0]}")") + +source "$dir_name/constants.sh" +source "$dir_name/utils.sh" +source "$dir_name/deploy.sh" +source "$dir_name/start-nodeos.sh" +source "$dir_name/create-wallet.sh" +source "$dir_name/create-account.sh" +source "$dir_name/eosio.token.sh" +source "$dir_name/xerc20.token.sh" +source "$dir_name/adapter.sh" +source "$dir_name/lockbox.sh" +source "$dir_name/feesmanager.sh" +source "$dir_name/add-code-permissions.sh" +source "$dir_name/activate-protocol-features.sh" + +set -e + +# creat local wallets and import accounts +echo "Creating owner wallet" +cleos wallet create -n "owner" --to-console +echo "Importing xtoken account" +cleos wallet import -n "owner" --private-key "$XTOKEN_PK_A" +echo "Importing adapter account" +cleos wallet import -n "owner" --private-key "$ADAPTER_PK_A" +echo "Importing lockbox account" +cleos wallet import -n "owner" --private-key "$LOCKBOX_PK_A" +echo "Creating feesmanager wallet" +cleos wallet create -n "feesmanager" --to-console +echo "Importing feesmanager account" +cleos wallet import -n "feesmanager" --private-key "$FEESMANAGER_PK_A" + +# deploy contracts +echo "Deploying adapter using --$ADAPTER_NAME-- account ..." +deploy adapter "$ADAPTER_NAME" +add_code_permissions "$ADAPTER_NAME" +if $IS_LOCAL; then + echo "Deploying lockbox using --$LOCKBOX_NAME-- account ..." + deploy lockbox "$LOCKBOX_NAME" + add_code_permissions "$LOCKBOX_NAME" +fi +echo "Deploying feesmanager using --$FEESMANAGER_NAME-- account ..." +deploy feesmanager "$FEESMANAGER_NAME" +echo "Deploying xtoken using --$XTOKEN_NAME-- account ..." +deploy xerc20.token "$XTOKEN_NAME" + +echo "Setup xtoken parameters" +XSYMBOL="X$UNDERLYING_SYMBOL" +MINTING_LIMIT="$MINT_LIMIT $XSYMBOL" +BURNING_LIMIT="$BURN_LIMIT $XSYMBOL" +MIN_FEE="$MIN_FEE $XSYMBOL" + +# setup the bridge +xerc20.token "$XTOKEN_NAME" "$XTOKEN_NAME"@action create "$OWNER_NAME" "$MAX_SUPPLY $XSYMBOL" +xerc20.token "$XTOKEN_NAME" setlimits "$ADAPTER_NAME" "$MINTING_LIMIT" "$BURNING_LIMIT" + +if $IS_LOCAL; then + xerc20.token "$XTOKEN_NAME" setlockbox "$LOCKBOX_NAME" + lockbox "$LOCKBOX_NAME" create "$XTOKEN_NAME" "4,$XSYMBOL" "$UNDERLYING_NAME" "4,$UNDERLYING_SYMBOL" + adapter "$ADAPTER_NAME" create "$XTOKEN_NAME" "4,$XSYMBOL" "$UNDERLYING_NAME" "4,$UNDERLYING_SYMBOL" "$SYMBOL_BYTES" "$MIN_FEE" +fi + +adapter "$ADAPTER_NAME" create "$XTOKEN_NAME" "4,$XSYMBOL" "$UNDERLYING_NAME" "4,$UNDERLYING_SYMBOL" "$SYMBOL_BYTES" "$MIN_FEE" +adapter "$ADAPTER_NAME" setfeemanagr "$FEESMANAGER_NAME" + +echo "Done!" \ No newline at end of file diff --git a/cpp/scripts/deploy.sh b/cpp/scripts/deploy.sh index 75cf84d8..b520909d 100755 --- a/cpp/scripts/deploy.sh +++ b/cpp/scripts/deploy.sh @@ -50,16 +50,16 @@ function usage { } function deploy { - local contract + local contract_name local account - contract="$1" + contract_name="$1" - exit_if_empty "$contract" "Contract name is required" + exit_if_empty "$contract_name" "Contract name is required" - account="${2:-$contract}" + account="${2:-$contract_name}" - cleos set contract "$account" "$FOLDER_BUILD" "$contract.wasm" "$contract.abi" -p "$account@active" + cleos set contract "$account" "$FOLDER_BUILD" "$contract_name.wasm" "$contract_name.abi" -p "$account@active" } diff --git a/cpp/scripts/eosio.token.sh b/cpp/scripts/eosio.token.sh index 0a969764..de504031 100755 --- a/cpp/scripts/eosio.token.sh +++ b/cpp/scripts/eosio.token.sh @@ -99,19 +99,20 @@ function eosio.token { local action local permission local shifting_pos - local contract + local contract_name local json - contract="${FUNCNAME[0]}" + contract_name="${1}" + shift - contract_script_init action permission shifting_pos "$contract" "$@" + contract_script_init action permission shifting_pos "$contract_name" "$@" shift "$shifting_pos" eosio.token.get_json_params json "$action" "$@" # We call the action - push_action "$contract" "$action" "$json" "--permission" "$permission" + push_action "$contract_name" "$action" "$json" "--permission" "$permission" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/cpp/scripts/feesmanager.sh b/cpp/scripts/feesmanager.sh index 2a583dcc..a2f629da 100755 --- a/cpp/scripts/feesmanager.sh +++ b/cpp/scripts/feesmanager.sh @@ -81,19 +81,20 @@ function feesmanager { local action local permission local shifting_pos - local contract + local contract_name local json - contract="${FUNCNAME[0]}" + contract_name="$1" + shift - contract_script_init action permission shifting_pos "$contract" "$@" + contract_script_init action permission shifting_pos "$contract_name" "$@" shift "$shifting_pos" feesmanager.get_json_params json "$action" "$@" # We call the action - push_action "$contract" "$action" "$json" "--permission" "$permission" + push_action "$contract_name" "$action" "$json" "--permission" "$permission" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/cpp/scripts/lockbox.sh b/cpp/scripts/lockbox.sh index 2056a26e..adaca06e 100755 --- a/cpp/scripts/lockbox.sh +++ b/cpp/scripts/lockbox.sh @@ -58,19 +58,20 @@ function lockbox { local action local permission local shifting_pos - local contract + local contract_name local json - contract="${FUNCNAME[0]}" + contract_name="$1" + shift - contract_script_init action permission shifting_pos "$contract" "$@" + contract_script_init action permission shifting_pos "$contract_name" "$@" shift "$shifting_pos" lockbox.get_json_params json "$action" "$@" # We call the action - push_action "$contract" "$action" "$json" "--permission" "$permission" + push_action "$contract_name" "$action" "$json" "--permission" "$permission" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/cpp/scripts/push-action.sh b/cpp/scripts/push-action.sh index 132addc0..b3c2733e 100644 --- a/cpp/scripts/push-action.sh +++ b/cpp/scripts/push-action.sh @@ -5,7 +5,7 @@ dir_name=$(dirname "$(realpath "${BASH_SOURCE[0]}")") source "$dir_name/constants.sh" function push_action { - echo "cleos push action $*" + echo "cleos -u $NODEOSURL push action $*" cleos push action "$@" } diff --git a/cpp/scripts/start-testnet.sh b/cpp/scripts/start-testnet.sh index f60c43ce..1e5ffe85 100755 --- a/cpp/scripts/start-testnet.sh +++ b/cpp/scripts/start-testnet.sh @@ -59,7 +59,6 @@ add_code_permissions adapter deploy lockbox lockbox add_code_permissions lockbox deploy feesmanager feesmanager -deploy feesmanager feesmanager deploy xerc20.token xtoken SYMBOL=WRAM @@ -71,17 +70,17 @@ BURNING_LIMIT="1500.0000 $XSYMBOL" MIN_FEE="0.0000 $XSYMBOL" # ... and the bridge -eosio.token create owner "$MAX_SUPPLY $SYMBOL" +eosio.token eosio.token create owner "$MAX_SUPPLY $SYMBOL" -xerc20.token xtoken@active create owner "$MAX_SUPPLY $XSYMBOL" -xerc20.token setlockbox lockbox -xerc20.token setlimits adapter "$MINTING_LIMIT" "$BURNING_LIMIT" +xerc20.token xtoken xtoken@active create owner "$MAX_SUPPLY $XSYMBOL" +xerc20.token xtoken setlockbox lockbox +xerc20.token xtoken setlimits adapter "$MINTING_LIMIT" "$BURNING_LIMIT" -lockbox create "xtoken" "4,$XSYMBOL" "eosio.token" "4,$SYMBOL" -adapter create "xtoken" "4,$XSYMBOL" "eosio.token" "4,$SYMBOL" "$SYMBOL_BYTES" "$MIN_FEE" -adapter setfeemanagr "feesmanager" +lockbox lockbox create "xtoken" "4,$XSYMBOL" "eosio.token" "4,$SYMBOL" +adapter adapter create "xtoken" "4,$XSYMBOL" "eosio.token" "4,$SYMBOL" "$SYMBOL_BYTES" "$MIN_FEE" +adapter adapter setfeemanagr "feesmanager" -eosio.token owner@active issue owner "100.0000 WRAM" -eosio.token owner@active transfer owner user "10.0000 WRAM" +eosio.token eosio.token owner@active issue owner "100.0000 WRAM" +eosio.token eosio.token owner@active transfer owner user "10.0000 WRAM" echo "Done!" \ No newline at end of file diff --git a/cpp/scripts/xerc20.token.sh b/cpp/scripts/xerc20.token.sh index 6389a0ef..51e06413 100755 --- a/cpp/scripts/xerc20.token.sh +++ b/cpp/scripts/xerc20.token.sh @@ -76,19 +76,20 @@ function xerc20.token { local action local permission local shifting_pos - local contract + local contract_name local json - contract=xtoken + contract_name=$1 + shift - contract_script_init action permission shifting_pos "$contract" "$@" + contract_script_init action permission shifting_pos "$contract_name" "$@" shift "$shifting_pos" xerc20.token.get_json_params json "$action" "$@" # We call the action - push_action "$contract" "$action" "$json" "--permission" "$permission" + push_action "$contract_name" "$action" "$json" "--permission" "$permission" } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/solidity/scripts/Deploy.s.sol b/solidity/scripts/Deploy.s.sol index b01c298e..d75d694f 100644 --- a/solidity/scripts/Deploy.s.sol +++ b/solidity/scripts/Deploy.s.sol @@ -27,6 +27,7 @@ contract Deploy is Script, DeployHelper { string memory name, string memory symbol, bool local, + bool isNative, bool freezing ) public { vm.startBroadcast(); @@ -44,6 +45,7 @@ contract Deploy is Script, DeployHelper { Adapter adapter = new Adapter( address(xerc20), erc20, + isNative, address(feesManager), address(pam) ); @@ -72,8 +74,9 @@ contract Deploy is Script, DeployHelper { string memory name, string memory symbol, bool local, + bool isNative, bool freezing ) public { - run(address(0), erc20, name, symbol, local, freezing); + run(address(0), erc20, name, symbol, local, isNative, freezing); } } diff --git a/solidity/scripts/PAM.s.sol b/solidity/scripts/PAM.s.sol index c96e33cc..adcb7f6b 100644 --- a/solidity/scripts/PAM.s.sol +++ b/solidity/scripts/PAM.s.sol @@ -16,6 +16,18 @@ contract PAMScript is Script { vm.stopBroadcast(); } + // Call if emitter is not in a EVM chain + function setEmitter( + address pam, + uint256 chainid, + bytes32 emitter + ) external { + vm.startBroadcast(); + PAM(pam).setEmitter(bytes32(chainid), emitter); + vm.stopBroadcast(); + } + + // Call if emitter is in a EVM chain function setEmitter( address pam, uint256 chainid,