diff --git a/common/token-module/src/lib.rs b/common/token-module/src/lib.rs index 51af8595..900e14a2 100644 --- a/common/token-module/src/lib.rs +++ b/common/token-module/src/lib.rs @@ -68,6 +68,7 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { token_id: TokenIdentifier, ticker: ManagedBuffer, mint_burn_allowed: bool, + is_native_token: bool, opt_default_price_per_gas_unit: OptionalValue, ) { self.token_ticker(&token_id).set(&ticker); @@ -78,7 +79,10 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { } self.mint_burn_allowed(&token_id).set(mint_burn_allowed); - let _ = self.token_whitelist().insert(token_id); + let _ = self.token_whitelist().insert(token_id.clone()); + if is_native_token { + let _ = self.token_native().insert(token_id); + } } #[only_owner] @@ -89,6 +93,7 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { self.mint_burn_allowed(&token_id).clear(); self.token_whitelist().swap_remove(&token_id); + self.token_native().swap_remove(&token_id); } #[endpoint(mintToken)] @@ -108,11 +113,13 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { return EsdtTokenPayment::new(token_id.clone(), 0, BigUint::zero()); } - let accumulated_burned_tokens_mapper = self.accumulated_burned_tokens(token_id); - accumulated_burned_tokens_mapper.update(|burned| { - require!(*burned >= *amount, "Not enough accumulated burned tokens!"); - *burned -= amount; - }); + if !self.token_native().contains(token_id) { + let accumulated_burned_tokens_mapper = self.accumulated_burned_tokens(token_id); + accumulated_burned_tokens_mapper.update(|burned| { + require!(*burned >= *amount, "Not enough accumulated burned tokens!"); + *burned -= amount; + }); + } self.mint_esdt_token(token_id, amount); } @@ -168,18 +175,16 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule { } } - #[only_owner] - #[endpoint(setAccumulatedBurnedTokens)] - fn set_accumulated_burned_tokens(&self, token_id: &TokenIdentifier, value: BigUint) { - self.accumulated_burned_tokens(token_id).set_if_empty(value); - } - // storage #[view(getAllKnownTokens)] #[storage_mapper("tokenWhitelist")] fn token_whitelist(&self) -> UnorderedSetMapper; + #[view(getAllNativeTokens)] + #[storage_mapper("nativeTokens")] + fn token_native(&self) -> UnorderedSetMapper; + #[view(isMintBurnAllowed)] #[storage_mapper("mintBurnAllowed")] fn mint_burn_allowed(&self, token: &TokenIdentifier) -> SingleValueMapper; diff --git a/esdt-safe/src/lib.rs b/esdt-safe/src/lib.rs index 3adf6ae8..b8a6ffd6 100644 --- a/esdt-safe/src/lib.rs +++ b/esdt-safe/src/lib.rs @@ -225,13 +225,13 @@ pub trait EsdtSafe: nonce: tx_nonce, from: caller.as_managed_buffer().clone(), to: to.as_managed_buffer().clone(), - token_identifier: payment_token, - amount: actual_bridged_amount, + token_identifier: payment_token.clone(), + amount: actual_bridged_amount.clone(), is_refund_tx: false, }; let batch_id = self.add_to_batch(tx); - self.create_transaction_event(batch_id, tx_nonce); + self.create_transaction_event(batch_id, tx_nonce, payment_token, actual_bridged_amount); } /// Claim funds for failed Elrond -> Ethereum transactions. @@ -247,6 +247,7 @@ pub trait EsdtSafe: self.send() .direct_esdt(&caller, &token_id, 0, &refund_amount); + self.claim_refund_transaction_event(&token_id); EsdtTokenPayment::new(token_id, 0, refund_amount) } @@ -278,7 +279,13 @@ pub trait EsdtSafe: // events #[event("createTransactionEvent")] - fn create_transaction_event(&self, #[indexed] batch_id: u64, #[indexed] tx_id: u64); + fn create_transaction_event( + &self, + #[indexed] batch_id: u64, + #[indexed] tx_id: u64, + #[indexed] token_id: TokenIdentifier, + #[indexed] amount: BigUint, + ); #[event("addRefundTransactionEvent")] fn add_refund_transaction_event( @@ -288,6 +295,12 @@ pub trait EsdtSafe: #[indexed] original_tx_id: u64, ); + #[event("claimRefundTransactionEvent")] + fn claim_refund_transaction_event( + &self, + #[indexed] token_id: &TokenIdentifier, + ); + #[event("setStatusEvent")] fn set_status_event( &self, diff --git a/esdt-safe/wasm/src/lib.rs b/esdt-safe/wasm/src/lib.rs index b3bc1203..9cfa9d82 100644 --- a/esdt-safe/wasm/src/lib.rs +++ b/esdt-safe/wasm/src/lib.rs @@ -39,8 +39,8 @@ multiversx_sc_wasm_adapter::endpoints! { removeTokenFromWhitelist => remove_token_from_whitelist mintToken => mint_token setMultiTransferContractAddress => set_multi_transfer_contract_address - setAccumulatedBurnedTokens => set_accumulated_burned_tokens getAllKnownTokens => token_whitelist + getAllNativeTokens => token_native isMintBurnAllowed => mint_burn_allowed getMultiTransferContractAddress => multi_transfer_contract_address getAccumulatedTransactionFees => accumulated_transaction_fees diff --git a/multisig/interaction/config/configs.cfg b/multisig/interaction/config/configs.cfg index d72fa513..56ebaf71 100644 --- a/multisig/interaction/config/configs.cfg +++ b/multisig/interaction/config/configs.cfg @@ -43,6 +43,7 @@ UNIVERSAL_TOKEN= CHAIN_SPECIFIC_TOKEN=MEX-a659d0 ERC20_TOKEN=0x2E8e0BBe20Ecd819c721D164fb91F7c33BDFC756 MINTBURN_WHITELIST=true +NATIVE_TOKEN=true #============BRIDGE SETTINGS============== FEE_AMOUNT=50 # value without decimals diff --git a/multisig/interaction/config/multisig-snippets.sh b/multisig/interaction/config/multisig-snippets.sh index 2cc6db27..892085dd 100644 --- a/multisig/interaction/config/multisig-snippets.sh +++ b/multisig/interaction/config/multisig-snippets.sh @@ -68,11 +68,11 @@ addMapping() { } addTokenToWhitelist() { - CHECK_VARIABLES CHAIN_SPECIFIC_TOKEN CHAIN_SPECIFIC_TOKEN_TICKER MULTISIG MINTBURN_WHITELIST + CHECK_VARIABLES CHAIN_SPECIFIC_TOKEN CHAIN_SPECIFIC_TOKEN_TICKER MULTISIG MINTBURN_WHITELIST NATIVE_TOKEN mxpy --verbose contract call ${MULTISIG} --recall-nonce --pem=${ALICE} \ --gas-limit=60000000 --function="esdtSafeAddTokenToWhitelist" \ - --arguments str:${CHAIN_SPECIFIC_TOKEN} str:${CHAIN_SPECIFIC_TOKEN_TICKER} ${MINTBURN_WHITELIST} \ + --arguments str:${CHAIN_SPECIFIC_TOKEN} str:${CHAIN_SPECIFIC_TOKEN_TICKER} ${MINTBURN_WHITELIST} ${NATIVE_TOKEN} \ --send --proxy=${PROXY} --chain=${CHAIN_ID} } diff --git a/multisig/interaction/config/proxy-snippets.sh b/multisig/interaction/config/proxy-snippets.sh new file mode 100644 index 00000000..1e804186 --- /dev/null +++ b/multisig/interaction/config/proxy-snippets.sh @@ -0,0 +1,18 @@ +deployBridgeProxy() { + 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-testnet.interaction.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return + + TRANSACTION=$(mxpy data parse --file="./deploy-proxy-testnet.interaction.json" --expression="data['emitted_tx']['hash']") + ADDRESS=$(mxpy data parse --file="./deploy-proxy-testnet.interaction.json" --expression="data['contractAddress']") + + # mxpy data store --key=address-testnet-proxy --value=${ADDRESS} + # mxpy data store --key=deployTransaction-testnet --value=${TRANSACTION} + + echo "" + echo "Proxy contract address: ${ADDRESS}" + update-config BRIDGE_PROXY ${ADDRESS} +}