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

Update deploy scripts #75

Merged
merged 5 commits into from
Nov 20, 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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions cpp/scripts/.env.example
Original file line number Diff line number Diff line change
@@ -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=
4 changes: 4 additions & 0 deletions cpp/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cpp/scripts/adapter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cpp/scripts/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
67 changes: 67 additions & 0 deletions cpp/scripts/deploy-xtoken.sh
Original file line number Diff line number Diff line change
@@ -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"
envin3 marked this conversation as resolved.
Show resolved Hide resolved

# 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!"
10 changes: 5 additions & 5 deletions cpp/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand Down
9 changes: 5 additions & 4 deletions cpp/scripts/eosio.token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
envin3 marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
9 changes: 5 additions & 4 deletions cpp/scripts/feesmanager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions cpp/scripts/lockbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cpp/scripts/push-action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
}

Expand Down
19 changes: 9 additions & 10 deletions cpp/scripts/start-testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!"
9 changes: 5 additions & 4 deletions cpp/scripts/xerc20.token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion solidity/scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract Deploy is Script, DeployHelper {
string memory name,
string memory symbol,
bool local,
bool isNative,
bool freezing
) public {
vm.startBroadcast();
Expand All @@ -44,6 +45,7 @@ contract Deploy is Script, DeployHelper {
Adapter adapter = new Adapter(
address(xerc20),
erc20,
isNative,
address(feesManager),
address(pam)
);
Expand Down Expand Up @@ -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);
}
}
12 changes: 12 additions & 0 deletions solidity/scripts/PAM.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down