Skip to content

Commit

Permalink
Merge pull request #231 from multiversx/fix-safe-upgrade
Browse files Browse the repository at this point in the history
Added the proxy contract on the upgrade function in ESD safe contract
  • Loading branch information
iulianpascalau authored Oct 17, 2024
2 parents 385ba23 + 0136d1d commit c38aeb7
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 101 deletions.
7 changes: 5 additions & 2 deletions bridge-proxy/src/esdt_safe_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ where
pub fn upgrade<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<BigUint<Env::Api>>,
Arg2: ProxyArg<ManagedAddress<Env::Api>>,
Arg3: ProxyArg<BigUint<Env::Api>>,
>(
self,
fee_estimator_contract_address: Arg0,
multi_transfer_contract_address: Arg1,
eth_tx_gas_limit: Arg2,
bridge_proxy_contract_address: Arg2,
eth_tx_gas_limit: Arg3,
) -> TxTypedUpgrade<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_upgrade()
.argument(&fee_estimator_contract_address)
.argument(&multi_transfer_contract_address)
.argument(&bridge_proxy_contract_address)
.argument(&eth_tx_gas_limit)
.original_result()
}
Expand Down
7 changes: 5 additions & 2 deletions bridged-tokens-wrapper/src/esdt_safe_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ where
pub fn upgrade<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<BigUint<Env::Api>>,
Arg2: ProxyArg<ManagedAddress<Env::Api>>,
Arg3: ProxyArg<BigUint<Env::Api>>,
>(
self,
fee_estimator_contract_address: Arg0,
multi_transfer_contract_address: Arg1,
eth_tx_gas_limit: Arg2,
bridge_proxy_contract_address: Arg2,
eth_tx_gas_limit: Arg3,
) -> TxTypedUpgrade<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_upgrade()
.argument(&fee_estimator_contract_address)
.argument(&multi_transfer_contract_address)
.argument(&bridge_proxy_contract_address)
.argument(&eth_tx_gas_limit)
.original_result()
}
Expand Down
3 changes: 3 additions & 0 deletions esdt-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@ pub trait EsdtSafe:
&self,
fee_estimator_contract_address: ManagedAddress,
multi_transfer_contract_address: ManagedAddress,
bridge_proxy_contract_address: ManagedAddress,
eth_tx_gas_limit: BigUint,
) {
self.fee_estimator_contract_address()
.set(&fee_estimator_contract_address);
self.multi_transfer_contract_address()
.set(&multi_transfer_contract_address);
self.bridge_proxy_contract_address().
set(&bridge_proxy_contract_address);

self.eth_tx_gas_limit().set(&eth_tx_gas_limit);

Expand Down
8 changes: 2 additions & 6 deletions multi-transfer-esdt/src/bridge_proxy_contract_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,12 @@ where
.original_result()
}

pub fn cancel<
Arg0: ProxyArg<usize>,
>(
pub fn update_lowest_tx_id(
self,
tx_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("cancel")
.argument(&tx_id)
.raw_call("updateLowestTxId")
.original_result()
}

Expand Down
7 changes: 5 additions & 2 deletions multi-transfer-esdt/src/esdt_safe_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ where
pub fn upgrade<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<BigUint<Env::Api>>,
Arg2: ProxyArg<ManagedAddress<Env::Api>>,
Arg3: ProxyArg<BigUint<Env::Api>>,
>(
self,
fee_estimator_contract_address: Arg0,
multi_transfer_contract_address: Arg1,
eth_tx_gas_limit: Arg2,
bridge_proxy_contract_address: Arg2,
eth_tx_gas_limit: Arg3,
) -> TxTypedUpgrade<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_upgrade()
.argument(&fee_estimator_contract_address)
.argument(&multi_transfer_contract_address)
.argument(&bridge_proxy_contract_address)
.argument(&eth_tx_gas_limit)
.original_result()
}
Expand Down
1 change: 1 addition & 0 deletions multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl MultiTransferTestState {
.upgrade(
ManagedAddress::zero(),
MULTI_TRANSFER_ADDRESS.to_address(),
BRIDGE_PROXY_ADDRESS.to_address(),
ESDT_SAFE_ETH_TX_GAS_LIMIT,
)
.code(ESDT_SAFE_CODE_PATH)
Expand Down
30 changes: 24 additions & 6 deletions multisig/interaction/config/menu_functions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ source $SCRIPTPATH/config/multisig-snippets.sh
source $SCRIPTPATH/config/multitransfer-snippets.sh
source $SCRIPTPATH/config/proxy-snippets.sh
source $SCRIPTPATH/config/relayers-snippets.sh
source $SCRIPTPATH/config/upgrade-snippets.sh
source $SCRIPTPATH/config/wrapped-snippets.sh
source $SCRIPTPATH/config/safe-snippets.sh
source $SCRIPTPATH/config/testing.sh

CHECK_VARIABLES ALICE PROXY CHAIN_ID

function upgrade-wrapper {
wrapper-upgrade
}

function upgrade-wrapper-universal-token {
wrapper-updateWrappedToken
}
Expand Down Expand Up @@ -54,9 +49,9 @@ function deploy-bridge-contracts {
confirmation-with-skip setEsdtSafeOnSCProxy

confirmation-with-skip setEsdtSafeOnWrapper
confirmation-with-skip setSCProxyOnWrapper

confirmation-with-skip setBridgedTokensWrapperOnEsdtSafe
confirmation-with-skip setSCProxyOnEsdtSafe

confirmation-with-skip changeChildContractsOwnershipSafe
confirmation-with-skip changeChildContractsOwnershipMultiTransfer
Expand Down Expand Up @@ -182,6 +177,29 @@ function upgrade-aggregator {
aggregator-upgrade
}

function upgrade-wrapper {
wrapper-upgrade
}

function upgrade-safe {
confirmation-with-skip deploySafeForUpgrade
confirmation-with-skip upgradeSafeContract
}

function upgrade-multi-transfer {
confirmation-with-skip deployMultiTransferForUpgrade
confirmation-with-skip upgradeMultiTransferContract
}

function upgrade-proxy {
confirmation-with-skip deployBridgeProxyForUpgrade
confirmation-with-skip upgradeBridgeProxyContract
}

function upgrade-multisig {
confirmation-with-skip upgradeMultisig
}

function faucet-deposit {
confirmation-with-skip deployFaucet
echo -e
Expand Down
15 changes: 15 additions & 0 deletions multisig/interaction/config/multisig-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,18 @@ initSupplyMintBurn() {
--arguments str:${CHAIN_SPECIFIC_TOKEN} ${MINT} ${BURN} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}

upgradeMultisig() {
CHECK_VARIABLES SAFE MULTI_TRANSFER BRIDGE_PROXY MULTISIG_WASM

mxpy --verbose contract upgrade ${MULTISIG} --bytecode=${MULTISIG_WASM} --recall-nonce --pem=${ALICE} \
--gas-limit=100000000 --send \
--arguments ${SAFE} ${MULTI_TRANSFER} ${BRIDGE_PROXY} \
--outfile="upgrade-multisig-child-sc.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return

TRANSACTION=$(mxpy data parse --file="./upgrade-multisig-child-sc.json" --expression="data['emitted_tx']['hash']")
ADDRESS=$(mxpy data parse --file="./upgrade-multisig-child-sc.json" --expression="data['contractAddress']")

echo ""
echo "Multisig contract updated: ${ADDRESS}"
}
25 changes: 24 additions & 1 deletion multisig/interaction/config/multitransfer-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,27 @@ setBridgedTokensWrapperOnMultiTransfer() {
--gas-limit=60000000 --function="setWrappingContractAddress" \
--arguments ${BRIDGED_TOKENS_WRAPPER} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}
}

deployMultiTransferForUpgrade() {
CHECK_VARIABLES MULTI_TRANSFER_WASM

mxpy --verbose contract deploy --bytecode=${MULTI_TRANSFER_WASM} --recall-nonce --pem=${ALICE} \
--gas-limit=100000000 --metadata-payable \
--send --outfile="deploy-multitransfer-upgrade.interaction.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return

TRANSACTION=$(mxpy data parse --file="./deploy-multitransfer-upgrade.interaction.json" --expression="data['emittedTransactionHash']")
ADDRESS=$(mxpy data parse --file="./deploy-multitransfer-upgrade.interaction.json" --expression="data['contractAddress']")

echo ""
echo "New multi transfer contract address: ${ADDRESS}"
}

upgradeMultiTransferContract() {
local NEW_MULTI_TRANSFER_ADDR=$(mxpy data parse --file="./deploy-multitransfer-upgrade.interaction.json" --expression="data['contractAddress']")

mxpy --verbose contract call ${MULTISIG} --recall-nonce --pem=${ALICE} \
--gas-limit=400000000 --function="upgradeChildContractFromSource" \
--arguments ${MULTI_TRANSFER} ${NEW_MULTI_TRANSFER_ADDR} 0x00 \
--send --outfile="upgrade-multitransfer-child-sc.json" --proxy=${PROXY} --chain=${CHAIN_ID}
}
24 changes: 24 additions & 0 deletions multisig/interaction/config/proxy-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,27 @@ setEsdtSafeOnSCProxy() {
--arguments ${SAFE} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}

deployBridgeProxyForUpgrade() {
CHECK_VARIABLES PROXY_WASM MULTI_TRANSFER

mxpy --verbose contract deploy --bytecode=${PROXY_WASM} --recall-nonce --pem=${ALICE} \
--gas-limit=200000000 \
--arguments ${MULTI_TRANSFER} \
--send --outfile="deploy-proxy-upgrade.interaction.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return

TRANSACTION=$(mxpy data parse --file="./deploy-proxy-upgrade.interaction.json" --expression="data['emittedTransactionHash']")
ADDRESS=$(mxpy data parse --file="./deploy-proxy-upgrade.interaction.json" --expression="data['contractAddress']")

echo ""
echo "New proxy contract address: ${ADDRESS}"
}

upgradeBridgeProxyContract() {
local NEW_BRIDGE_PROXY_ADDR=$(mxpy data parse --file="./deploy-proxy-upgrade.interaction.json" --expression="data['contractAddress']")

mxpy --verbose contract call ${MULTISIG} --recall-nonce --pem=${ALICE} \
--gas-limit=400000000 --function="upgradeChildContractFromSource" \
--arguments ${BRIDGE_PROXY} ${NEW_BRIDGE_PROXY_ADDR} 0x00 \
--send --outfile="upgrade-proxy-child-sc.json" --proxy=${PROXY} --chain=${CHAIN_ID}
}
34 changes: 34 additions & 0 deletions multisig/interaction/config/safe-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,37 @@ setBridgedTokensWrapperOnEsdtSafe() {
--arguments ${BRIDGED_TOKENS_WRAPPER} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}

setSCProxyOnEsdtSafe() {
CHECK_VARIABLES SAFE BRIDGE_PROXY

mxpy --verbose contract call ${SAFE} --recall-nonce --pem=${ALICE} \
--gas-limit=60000000 --function="setBridgeProxyContractAddress" \
--arguments ${BRIDGE_PROXY} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}

deploySafeForUpgrade() {
CHECK_VARIABLES SAFE_WASM MULTI_TRANSFER AGGREGATOR BRIDGE_PROXY

mxpy --verbose contract deploy --bytecode=${SAFE_WASM} --recall-nonce --pem=${ALICE} \
--gas-limit=150000000 \
--arguments ${AGGREGATOR} ${MULTI_TRANSFER} 1 \
--send --outfile="deploy-safe-upgrade.interaction.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return

TRANSACTION=$(mxpy data parse --file="./deploy-safe-upgrade.interaction.json" --expression="data['emittedTransactionHash']")
ADDRESS=$(mxpy data parse --file="./deploy-safe-upgrade.interaction.json" --expression="data['contractAddress']")

echo ""
echo "New safe contract address: ${ADDRESS}"
}

upgradeSafeContract() {
local NEW_SAFE_ADDR=$(mxpy data parse --file="./deploy-safe-upgrade.interaction.json" --expression="data['contractAddress']")

mxpy --verbose contract call ${MULTISIG} --recall-nonce --pem=${ALICE} \
--gas-limit=400000000 --function="upgradeChildContractFromSource" \
--arguments ${SAFE} ${NEW_SAFE_ADDR} 0x00 \
${AGGREGATOR} ${MULTI_TRANSFER} ${BRIDGE_PROXY} 1 \
--send --outfile="upgrade-safe-child-sc.json" --proxy=${PROXY} --chain=${CHAIN_ID}
}
60 changes: 0 additions & 60 deletions multisig/interaction/config/upgrade-snippets.sh

This file was deleted.

9 changes: 0 additions & 9 deletions multisig/interaction/config/wrapped-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,3 @@ setEsdtSafeOnWrapper() {
--arguments ${SAFE} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}

setSCProxyOnWrapper() {
CHECK_VARIABLES BRIDGED_TOKENS_WRAPPER BRIDGE_PROXY

mxpy --verbose contract call ${BRIDGED_TOKENS_WRAPPER} --recall-nonce --pem=${ALICE} \
--gas-limit=60000000 --function="setBridgeProxyContractAddress" \
--arguments ${BRIDGE_PROXY} \
--send --proxy=${PROXY} --chain=${CHAIN_ID}
}
Loading

0 comments on commit c38aeb7

Please sign in to comment.