Skip to content
Open
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
4 changes: 2 additions & 2 deletions bridge-proxy/src/bridge-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub trait BridgeProxyContract:
let caller = self.blockchain().get_caller();
let payment = self.call_value().single_esdt();
require!(
caller == self.get_multi_transfer_address(),
"Only MultiTransfer can do deposits"
caller == self.get_esdt_safe_address(),
"Only EsdtSafe can do deposits"
);
let next_tx_id = self.get_next_tx_id();
self.pending_transactions().insert(next_tx_id, eth_tx);
Expand Down
30 changes: 15 additions & 15 deletions bridge-proxy/tests/bridge_proxy_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ impl BridgeProxyTestState {
.nonce(1)
.esdt_balance(TokenIdentifier::from(BRIDGE_TOKEN_ID), INITIAL_BALANCE)
.account(MULTI_TRANSFER_ADDRESS)
.esdt_balance(TokenIdentifier::from(WBRIDGE_TOKEN_ID), INITIAL_BALANCE)
.esdt_balance(TokenIdentifier::from(BRIDGE_TOKEN_ID), INITIAL_BALANCE)
.code(multi_transfer_code)
.account(ESDT_SAFE_ADDRESS)
.esdt_balance(TokenIdentifier::from(WBRIDGE_TOKEN_ID), INITIAL_BALANCE)
.esdt_balance(TokenIdentifier::from(BRIDGE_TOKEN_ID), INITIAL_BALANCE)
.code(esdt_safe_code);

let roles = vec![
Expand Down Expand Up @@ -312,7 +312,7 @@ fn bridge_proxy_execute_crowdfunding_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -391,7 +391,7 @@ fn multiple_deposit_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx1, 1u64)
Expand All @@ -404,7 +404,7 @@ fn multiple_deposit_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx2, 1u64)
Expand Down Expand Up @@ -512,7 +512,7 @@ fn test_highest_tx_id() {
for tx in &transactions {
test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(tx, 1u64)
Expand Down Expand Up @@ -570,7 +570,7 @@ fn bridge_proxy_wrong_formatting_sc_call_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -649,7 +649,7 @@ fn bridge_proxy_wrong_endpoint_sc_call_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -730,7 +730,7 @@ fn bridge_proxy_wrong_args_sc_call_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -811,7 +811,7 @@ fn bridge_proxy_too_small_gas_sc_call_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -886,7 +886,7 @@ fn bridge_proxy_empty_endpoint_with_args_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -963,7 +963,7 @@ fn bridge_proxy_empty_endpoint_with_gas_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -1041,7 +1041,7 @@ fn bridge_proxy_refund_tx_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -1140,7 +1140,7 @@ fn bridge_proxy_double_execute_same_tx_test() {

test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down Expand Up @@ -1221,7 +1221,7 @@ fn bridge_proxy_execute_1000_even_tx_test() {
for _ in 1..101 {
test.world
.tx()
.from(MULTI_TRANSFER_ADDRESS)
.from(ESDT_SAFE_ADDRESS)
.to(BRIDGE_PROXY_ADDRESS)
.typed(bridge_proxy_contract_proxy::BridgeProxyContractProxy)
.deposit(&eth_tx, 1u64)
Expand Down
52 changes: 52 additions & 0 deletions bridged-tokens-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,58 @@ pub trait BridgedTokensWrapper:
new_payments
}

/// Will wrap what it can, and send back the rest unchanged
#[payable("*")]
#[endpoint(wrapToken)]
fn wrap_token(&self) -> EsdtTokenPayment<Self::Api> {
require!(self.not_paused(), "Contract is paused");
let payment = self.call_value().single_esdt().clone();
if payment.amount == 0 {
return payment.clone();
}

let payment_to_return = payment.clone();
require!(
payment.token_nonce == 0,
"Only fungible tokens accepted for wrapping"
);
let universal_token_id_mapper =
self.chain_specific_to_universal_mapping(&payment.token_identifier);

// if there is chain specific -> universal mapping, then the token is whitelisted
if universal_token_id_mapper.is_empty() {
self.tx()
.to(ToCaller)
.esdt(payment_to_return.clone())
.transfer();
return payment_to_return.clone();
}

let universal_token_id = universal_token_id_mapper.get();
self.require_tokens_have_set_decimals_num(&universal_token_id, &payment.token_identifier);
self.token_liquidity(&payment.token_identifier)
.update(|value| *value += &payment.amount.clone());
let converted_amount = self.get_converted_amount(
&payment.token_identifier,
&universal_token_id,
payment.amount.clone(),
);

self.send()
.esdt_local_mint(&universal_token_id, 0, &converted_amount);

let payment_to_return =
EsdtTokenPayment::new(universal_token_id.clone(), 0, converted_amount.clone());
self.tx()
.to(ToCaller)
.esdt(payment_to_return.clone())
.transfer();

self.wrap_tokens_event(universal_token_id, converted_amount);

payment_to_return
}

#[payable("*")]
#[endpoint(unwrapToken)]
fn unwrap_token(&self, requested_token: TokenIdentifier) {
Expand Down
5 changes: 3 additions & 2 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: 16
// Endpoints: 17
// Async Callback (empty): 1
// Total number of exported functions: 19
// Total number of exported functions: 20

#![no_std]

Expand All @@ -27,6 +27,7 @@ multiversx_sc_wasm_adapter::endpoints! {
blacklistToken => blacklist_token
depositLiquidity => deposit_liquidity
wrapTokens => wrap_tokens
wrapToken => wrap_token
unwrapToken => unwrap_token
unwrapTokenCreateTransaction => unwrap_token_create_transaction
getUniversalBridgedTokenIds => universal_bridged_token_ids
Expand Down
9 changes: 9 additions & 0 deletions common/sc-proxies/src/bridged_tokens_wrapper_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ where
.original_result()
}

/// Will wrap what it can, and send back the rest unchanged
pub fn wrap_token(
self,
) -> TxTypedCall<Env, From, To, (), Gas, EsdtTokenPayment<Env::Api>> {
self.wrapped_tx
.raw_call("wrapToken")
.original_result()
}

pub fn unwrap_token<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
>(
Expand Down
32 changes: 16 additions & 16 deletions common/sc-proxies/src/esdt_safe_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ where
.original_result()
}

pub fn get_tokens<
Arg0: ProxyArg<transaction::EthTransaction<Env::Api>>,
Arg1: ProxyArg<u64>,
>(
self,
eth_tx: Arg0,
batch_id: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getTokens")
.argument(&eth_tx)
.argument(&batch_id)
.original_result()
}

pub fn withdraw_refund_fees_for_ethereum<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Expand Down Expand Up @@ -450,22 +466,6 @@ where
.original_result()
}

pub fn get_tokens<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<BigUint<Env::Api>>,
>(
self,
token_id: Arg0,
amount: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, bool> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getTokens")
.argument(&token_id)
.argument(&amount)
.original_result()
}

pub fn init_supply<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<BigUint<Env::Api>>,
Expand Down
50 changes: 0 additions & 50 deletions common/token-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,56 +162,6 @@ pub trait TokenModule:
self.token_whitelist().swap_remove(&token_id);
}

#[endpoint(getTokens)]
fn get_tokens(&self, token_id: &TokenIdentifier, amount: &BigUint) -> bool {
let caller = self.blockchain().get_caller();
require!(
caller == self.get_multi_transfer_address(),
"Only MultiTransfer can get tokens"
);

if !self.mint_burn_token(token_id).get() {
let total_balances_mapper = self.total_balances(token_id);
if &total_balances_mapper.get() >= amount {
total_balances_mapper.update(|total| {
*total -= amount;
});
self.tx()
.to(ToCaller)
.single_esdt(token_id, 0, amount)
.transfer();

return true;
} else {
return false;
}
}

let burn_balances_mapper = self.burn_balances(token_id);
let mint_balances_mapper = self.mint_balances(token_id);
if self.native_token(token_id).get() {
require!(
burn_balances_mapper.get() >= &mint_balances_mapper.get() + amount,
"Not enough burned tokens!"
);
}

let mint_executed = self.internal_mint(token_id, amount);
if !mint_executed {
return false;
}
self.tx()
.to(ToCaller)
.single_esdt(token_id, 0, amount)
.transfer();

mint_balances_mapper.update(|minted| {
*minted += amount;
});

true
}

#[only_owner]
#[payable("*")]
#[endpoint(initSupply)]
Expand Down
Loading
Loading