Skip to content

Commit

Permalink
Merge pull request #250 from multiversx/remove-safe-storage-from-wrapper
Browse files Browse the repository at this point in the history
remove safe storage from wrapper
  • Loading branch information
iulianpascalau authored Nov 7, 2024
2 parents ad2178e + 5fa13e9 commit 5868e9c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 183 deletions.
17 changes: 0 additions & 17 deletions bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,6 @@
"status": "0"
}
},
{
"step": "scCall",
"id": "",
"tx": {
"from": "address:owner",
"to": "sc:bridged-tokens-wrapper",
"function": "setEsdtSafeContractAddress",
"arguments": [
"0x00000000000000000500657364742d736166655f5f5f5f5f5f5f5f5f5f5f5f5f"
],
"gasLimit": "5,000,000"
},
"expect": {
"out": [],
"status": "0"
}
},
{
"step": "scCall",
"id": "",
Expand Down
29 changes: 5 additions & 24 deletions bridge-proxy/src/bridged_tokens_wrapper_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,22 @@ where

pub fn unwrap_token_create_transaction<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<eth_address::EthAddress<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<eth_address::EthAddress<Env::Api>>,
>(
self,
requested_token: Arg0,
to: Arg1,
safe_address: Arg1,
to: Arg2,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("unwrapTokenCreateTransaction")
.argument(&requested_token)
.argument(&safe_address)
.argument(&to)
.original_result()
}

pub fn set_esdt_safe_contract_address<
Arg0: ProxyArg<OptionalValue<ManagedAddress<Env::Api>>>,
>(
self,
opt_new_address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("setEsdtSafeContractAddress")
.argument(&opt_new_address)
.original_result()
}

pub fn universal_bridged_token_ids(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, TokenIdentifier<Env::Api>>> {
Expand Down Expand Up @@ -279,15 +269,6 @@ where
.original_result()
}

pub fn esdt_safe_contract_address(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedAddress<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getEsdtSafeContractAddress")
.original_result()
}

pub fn pause_endpoint(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
Expand Down
7 changes: 0 additions & 7 deletions bridge-proxy/tests/bridge_proxy_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,6 @@ impl BridgeProxyTestState {
)
.run();

self.world
.tx()
.from(OWNER_ADDRESS)
.to(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.set_esdt_safe_contract_address(OptionalValue::Some(ESDT_SAFE_ADDRESS))
.run();
self
}
}
Expand Down
18 changes: 2 additions & 16 deletions bridged-tokens-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,14 @@ pub trait BridgedTokensWrapper:
fn unwrap_token_create_transaction(
&self,
requested_token: TokenIdentifier,
safe_address: ManagedAddress<Self::Api>,
to: EthAddress<Self::Api>,
) {
let converted_amount = self.unwrap_token_common(&requested_token);

let caller = self.blockchain().get_caller();
self.tx()
.to(self.esdt_safe_contract_address().get())
.to(safe_address)
.typed(esdt_safe_proxy::EsdtSafeProxy)
.create_transaction(
to,
Expand Down Expand Up @@ -302,17 +303,6 @@ pub trait BridgedTokensWrapper:
);
}

#[only_owner]
#[endpoint(setEsdtSafeContractAddress)]
fn set_esdt_safe_contract_address(&self, opt_new_address: OptionalValue<ManagedAddress>) {
match opt_new_address {
OptionalValue::Some(sc_addr) => {
self.esdt_safe_contract_address().set(&sc_addr);
}
OptionalValue::None => self.esdt_safe_contract_address().clear(),
}
}

#[view(getUniversalBridgedTokenIds)]
#[storage_mapper("universalBridgedTokenIds")]
fn universal_bridged_token_ids(&self) -> UnorderedSetMapper<TokenIdentifier>;
Expand All @@ -337,8 +327,4 @@ pub trait BridgedTokensWrapper:

#[storage_mapper("token_decimals_num")]
fn token_decimals_num(&self, token: &TokenIdentifier) -> SingleValueMapper<u32>;

#[view(getEsdtSafeContractAddress)]
#[storage_mapper("esdtSafeContractAddress")]
fn esdt_safe_contract_address(&self) -> SingleValueMapper<ManagedAddress>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,43 +131,6 @@ fn test_require_tokens_have_set_decimals_num_should_work() {
);
}

#[test]
fn test_set_esdt_safe_contract_address_should_work() {
let mut world = setup();
let bridged_tokens_wrapper = WhiteboxContract::new(
BRIDGE_TOKENS_WRAPPER_ADDRESS_EXPR,
bridged_tokens_wrapper::contract_obj,
);

let esdt_address_expr = "address:from".to_string();
let esdt_address = AddressValue::from(esdt_address_expr.as_str());

world.whitebox_call(
&bridged_tokens_wrapper,
ScCallStep::new().from(OWNER_ADDRESS_EXPR),
|sc| {
sc.set_esdt_safe_contract_address(OptionalValue::Some(managed_address!(
&esdt_address.to_address()
)));
},
);

world.whitebox_query(&bridged_tokens_wrapper, |sc| {
let result = sc.esdt_safe_contract_address().get();
assert_eq!(result, managed_address!(&esdt_address.to_address()));
});

world.whitebox_call(
&bridged_tokens_wrapper,
ScCallStep::new().from(OWNER_ADDRESS_EXPR),
|sc| {
sc.set_esdt_safe_contract_address(OptionalValue::None);
let result = sc.esdt_safe_contract_address().is_empty();
assert!(result);
},
);
}

#[test]
fn test_require_mint_and_burn_roles_should_fail() {
let mut world = setup();
Expand Down Expand Up @@ -424,13 +387,13 @@ fn test_unwrap_token_create_transaction_should_fail_case_1() {
.expect(TxExpect::user_error("str:Contract is paused")),
|sc| {
sc.set_paused(true);
sc.set_esdt_safe_contract_address(OptionalValue::Some(ManagedAddress::new_from_bytes(
b"0102030405060708090a0b0c0d0e0f10",
)));

let address = convert_to_eth_address(ETH_ADDRESS);
sc.unwrap_token_create_transaction(
managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER),
ManagedAddress::new_from_bytes(
b"0102030405060708090a0b0c0d0e0f10",
),
address,
);
},
Expand Down Expand Up @@ -468,6 +431,9 @@ fn test_unwrap_token_create_transaction_should_fail_case_2() {
let address = convert_to_eth_address(ETH_ADDRESS);
sc.unwrap_token_create_transaction(
managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER),
ManagedAddress::new_from_bytes(
b"0102030405060708090a0b0c0d0e0f10",
),
address,
);
},
Expand Down Expand Up @@ -505,6 +471,7 @@ fn test_unwrap_token_create_transaction_should_fail_case_3() {
let address = convert_to_eth_address(ETH_ADDRESS);
sc.unwrap_token_create_transaction(
managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER),
ManagedAddress::zero(),
address,
);
},
Expand Down Expand Up @@ -577,6 +544,7 @@ fn test_unwrap_token_create_transaction_should_fail_case_4() {
let address = convert_to_eth_address(ETH_ADDRESS);
sc.unwrap_token_create_transaction(
managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER),
ManagedAddress::zero(),
address,
);
},
Expand Down Expand Up @@ -621,11 +589,6 @@ fn test_unwrap_token_create_transaction_should_work() {
sc.deposit_liquidity();
sc.chain_specific_to_universal_mapping(&managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER))
.set(managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER));
let esdt_address_expr = "sc:esdt_safe".to_string();
let esdt_address = AddressValue::from(esdt_address_expr.as_str());
sc.set_esdt_safe_contract_address(OptionalValue::Some(managed_address!(
&esdt_address.to_address()
)));
},
);
}
Expand Down
6 changes: 2 additions & 4 deletions bridged-tokens-wrapper/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 19
// Endpoints: 17
// Async Callback (empty): 1
// Total number of exported functions: 22
// Total number of exported functions: 20

#![no_std]

Expand All @@ -30,12 +30,10 @@ multiversx_sc_wasm_adapter::endpoints! {
wrapTokens => wrap_tokens
unwrapToken => unwrap_token
unwrapTokenCreateTransaction => unwrap_token_create_transaction
setEsdtSafeContractAddress => set_esdt_safe_contract_address
getUniversalBridgedTokenIds => universal_bridged_token_ids
getTokenLiquidity => token_liquidity
getChainSpecificToUniversalMapping => chain_specific_to_universal_mapping
getchainSpecificTokenIds => chain_specific_token_ids
getEsdtSafeContractAddress => esdt_safe_contract_address
pause => pause_endpoint
unpause => unpause_endpoint
isPaused => paused_status
Expand Down
29 changes: 5 additions & 24 deletions multi-transfer-esdt/src/bridged_tokens_wrapper_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,22 @@ where

pub fn unwrap_token_create_transaction<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<eth_address::EthAddress<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<eth_address::EthAddress<Env::Api>>,
>(
self,
requested_token: Arg0,
to: Arg1,
safe_address: Arg1,
to: Arg2,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("unwrapTokenCreateTransaction")
.argument(&requested_token)
.argument(&safe_address)
.argument(&to)
.original_result()
}

pub fn set_esdt_safe_contract_address<
Arg0: ProxyArg<OptionalValue<ManagedAddress<Env::Api>>>,
>(
self,
opt_new_address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("setEsdtSafeContractAddress")
.argument(&opt_new_address)
.original_result()
}

pub fn universal_bridged_token_ids(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, TokenIdentifier<Env::Api>>> {
Expand Down Expand Up @@ -279,15 +269,6 @@ where
.original_result()
}

pub fn esdt_safe_contract_address(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ManagedAddress<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getEsdtSafeContractAddress")
.original_result()
}

pub fn pause_endpoint(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
Expand Down
15 changes: 5 additions & 10 deletions multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,6 @@ impl MultiTransferTestState {
}

fn config_bridged_tokens_wrapper(&mut self) {
self.world
.tx()
.from(OWNER_ADDRESS)
.to(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.set_esdt_safe_contract_address(OptionalValue::Some(ESDT_SAFE_ADDRESS.to_address()))
.run();

self.world
.tx()
Expand Down Expand Up @@ -809,6 +802,7 @@ fn test_unwrap_token_create_transaction_paused() {
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.unwrap_token_create_transaction(
TokenIdentifier::from(UNIVERSAL_TOKEN_IDENTIFIER),
ESDT_SAFE_ADDRESS.to_address(),
EthAddress::zero(),
)
.egld_or_single_esdt(
Expand Down Expand Up @@ -860,7 +854,7 @@ fn test_unwrap_token_create_transaction_insufficient_liquidity() {
.from(USER1_ADDRESS)
.to(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero())
.unwrap_token_create_transaction(WRAPPED_TOKEN_ID, ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero())
.egld_or_single_esdt(
&EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER),
0u64,
Expand Down Expand Up @@ -919,7 +913,7 @@ fn test_unwrap_token_create_transaction_should_work() {
.from(USER1_ADDRESS)
.to(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero())
.unwrap_token_create_transaction(WRAPPED_TOKEN_ID, ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero())
.egld_or_single_esdt(
&EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER),
0u64,
Expand Down Expand Up @@ -963,7 +957,7 @@ fn test_unwrap_token_create_transaction_should_fail() {
.from(USER1_ADDRESS)
.to(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero())
.unwrap_token_create_transaction(WRAPPED_TOKEN_ID, ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero())
.egld_or_single_esdt(
&EgldOrEsdtTokenIdentifier::esdt(TOKEN_ID),
0u64,
Expand All @@ -989,6 +983,7 @@ fn test_unwrap_token_create_transaction_amount_zero() {
.typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy)
.unwrap_token_create_transaction(
TokenIdentifier::from(WRAPPED_TOKEN_ID),
ESDT_SAFE_ADDRESS.to_address(),
EthAddress::zero(),
)
.egld_or_single_esdt(
Expand Down
3 changes: 0 additions & 3 deletions multisig/interaction/config/menu_functions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ function deploy-bridge-contracts {
confirmation-with-skip setMultiTransferOnSCProxy
confirmation-with-skip setEsdtSafeOnSCProxy

confirmation-with-skip setEsdtSafeOnWrapper

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

Expand Down Expand Up @@ -179,7 +177,6 @@ function upgrade-aggregator {

function upgrade-wrapper {
wrapper-upgrade
confirmation-with-skip setEsdtSafeOnWrapper
}

function upgrade-safe {
Expand Down
9 changes: 0 additions & 9 deletions multisig/interaction/config/wrapped-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,3 @@ wrapper-upgrade() {
--gas-limit=50000000 --send \
--outfile="upgrade-bridged-tokens-wrapper.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return
}

setEsdtSafeOnWrapper() {
CHECK_VARIABLES BRIDGED_TOKENS_WRAPPER SAFE

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

0 comments on commit 5868e9c

Please sign in to comment.