Skip to content

Commit

Permalink
fix backword compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos-rebegea committed Feb 29, 2024
1 parent 7acf6fc commit 6f5a615
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
29 changes: 17 additions & 12 deletions common/token-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigUint>,
) {
self.token_ticker(&token_id).set(&ticker);
Expand All @@ -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]
Expand All @@ -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)]
Expand All @@ -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);
}

Expand Down Expand Up @@ -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<TokenIdentifier>;

#[view(getAllNativeTokens)]
#[storage_mapper("nativeTokens")]
fn token_native(&self) -> UnorderedSetMapper<TokenIdentifier>;

#[view(isMintBurnAllowed)]
#[storage_mapper("mintBurnAllowed")]
fn mint_burn_allowed(&self, token: &TokenIdentifier) -> SingleValueMapper<bool>;
Expand Down
21 changes: 17 additions & 4 deletions esdt-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion esdt-safe/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions multisig/interaction/config/configs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions multisig/interaction/config/multisig-snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
18 changes: 18 additions & 0 deletions multisig/interaction/config/proxy-snippets.sh
Original file line number Diff line number Diff line change
@@ -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}
}

0 comments on commit 6f5a615

Please sign in to comment.