Skip to content

Commit

Permalink
Feat 3.5 implementation (#196)
Browse files Browse the repository at this point in the history
* first-commit

* first-commit

* quick renane

* first-commit

* 99%

* small-fix

* .

* .

* .

* .

* white-box

* multi-contract

* .

* .

* change upgrade to init

* refactor - moved some tests in multitransafer blackbox

* forgot to include a proxy file

* fix case

* last-updates

* .

* .

* remove-duplicate-code

* clippy fixes

* fix proxy after merge

* fix clippy

* fix clippy

---------

Co-authored-by: evelinemolnar <[email protected]>
Co-authored-by: Molnar Noemi Eveline <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent b88edf9 commit 4bdab8a
Show file tree
Hide file tree
Showing 14 changed files with 2,174 additions and 57 deletions.
679 changes: 679 additions & 0 deletions bridge-proxy/src/esdt_safe_proxy.rs

Large diffs are not rendered by default.

199 changes: 199 additions & 0 deletions bridged-tokens-wrapper/src/esdt_safe_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,72 @@ where
To: TxTo<Env>,
Gas: TxGas<Env>,
{
pub fn upgrade<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<BigUint<Env::Api>>,
>(
self,
fee_estimator_contract_address: Arg0,
multi_transfer_contract_address: Arg1,
eth_tx_gas_limit: Arg2,
) -> TxTypedUpgrade<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_upgrade()
.argument(&fee_estimator_contract_address)
.argument(&multi_transfer_contract_address)
.argument(&eth_tx_gas_limit)
.original_result()
}
}

#[rustfmt::skip]
impl<Env, From, To, Gas> EsdtSafeProxyMethods<Env, From, To, Gas>
where
Env: TxEnv,
Env::Api: VMApi,
From: TxFrom<Env>,
To: TxTo<Env>,
Gas: TxGas<Env>,
{
/// Sets the statuses for the transactions, after they were executed on the Ethereum side.
///
/// Only TransactionStatus::Executed (3) and TransactionStatus::Rejected (4) values are allowed.
/// Number of provided statuses must be equal to number of transactions in the batch.
pub fn set_transaction_batch_status<
Arg0: ProxyArg<u64>,
Arg1: ProxyArg<MultiValueEncoded<Env::Api, transaction::transaction_status::TransactionStatus>>,
>(
self,
batch_id: Arg0,
tx_statuses: Arg1,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("setTransactionBatchStatus")
.argument(&batch_id)
.argument(&tx_statuses)
.original_result()
}

/// Converts failed Ethereum -> MultiversX transactions to MultiversX -> Ethereum transaction.
/// This is done every now and then to refund the tokens.
///
/// As with normal MultiversX -> Ethereum transactions, a part of the tokens will be
/// subtracted to pay for the fees
pub fn add_refund_batch<
Arg0: ProxyArg<ManagedVec<Env::Api, transaction::Transaction<Env::Api>>>,
>(
self,
refund_transactions: Arg0,
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
self.wrapped_tx
.raw_call("addRefundBatch")
.argument(&refund_transactions)
.original_result()
}

/// Create an MultiversX -> Ethereum transaction. Only fungible tokens are accepted.
///
/// Every transfer will have a part of the tokens subtracted as fees.
Expand All @@ -62,4 +128,137 @@ where
.argument(&to)
.original_result()
}

/// Claim funds for failed MultiversX -> Ethereum transactions.
/// These are not sent automatically to prevent the contract getting stuck.
/// For example, if the receiver is a SC, a frozen account, etc.
pub fn claim_refund<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
>(
self,
token_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, EsdtTokenPayment<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("claimRefund")
.argument(&token_id)
.original_result()
}

/// Query function that lists all refund amounts for a user.
/// Useful for knowing which token IDs to pass to the claimRefund endpoint.
pub fn get_refund_amounts<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, MultiValue2<TokenIdentifier<Env::Api>, BigUint<Env::Api>>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getRefundAmounts")
.argument(&address)
.original_result()
}

pub fn add_token_to_whitelist<
Arg0: ProxyArg<TokenIdentifier<Env::Api>>,
Arg1: ProxyArg<ManagedBuffer<Env::Api>>,
Arg2: ProxyArg<bool>,
Arg3: ProxyArg<bool>,
Arg4: ProxyArg<OptionalValue<BigUint<Env::Api>>>,
>(
self,
token_id: Arg0,
ticker: Arg1,
mint_burn_token: Arg2,
native_token: Arg3,
opt_default_price_per_gas_unit: Arg4,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("addTokenToWhitelist")
.argument(&token_id)
.argument(&ticker)
.argument(&mint_burn_token)
.argument(&native_token)
.argument(&opt_default_price_per_gas_unit)
.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 set_multi_transfer_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("setMultiTransferContractAddress")
.argument(&opt_new_address)
.original_result()
}

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

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

pub fn get_batch_status<
Arg0: ProxyArg<u64>,
>(
self,
batch_id: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, tx_batch_module::batch_status::BatchStatus<Env::Api>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getBatchStatus")
.argument(&batch_id)
.original_result()
}

pub fn unpause_endpoint(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("unpause")
.original_result()
}
}
8 changes: 7 additions & 1 deletion common/token-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule {
}
}

#[only_owner]
#[endpoint(setTotalBalances)]
#[label("test-only")]
fn set_total_balances(&self, token_id: &TokenIdentifier, value: BigUint) {
self.total_balances(token_id).set_if_empty(value);
}

#[endpoint(setMintBalances)]
#[label("test-only")]
fn set_mint_balances(&self, token_id: &TokenIdentifier, value: BigUint) {
self.mint_balances(token_id).set_if_empty(value);
}

// storage

#[view(getAllKnownTokens)]
Expand Down
2 changes: 1 addition & 1 deletion common/tx-batch-module/src/batch_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use multiversx_sc::{api::ManagedTypeApi, types::ManagedVec};
use transaction::{BlockNonce, TxNonce};

#[type_abi]
#[derive(TopEncode, TopDecode)]
#[derive(TopEncode, TopDecode, Debug, PartialEq, Eq)]
pub enum BatchStatus<M: ManagedTypeApi> {
AlreadyProcessed,
Empty,
Expand Down
39 changes: 38 additions & 1 deletion esdt-safe/sc-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,27 @@ add-endpoints = [
"setMaxBridgedAmount",
]

[[proxy]]
path = "src/esdt_safe_proxy_test_only.rs"
add-unlabelled = false
add-labels = ["test-only"]

[[proxy]]
path = "../bridged-tokens-wrapper/src/esdt_safe_proxy.rs"
add-unlabelled = false
add-endpoints = [
"upgrade",
"unpause",
"setMultiTransferContractAddress",
"addTokenToWhitelist",
"getTokens",
"addRefundBatch",
"getAccumulatedTransactionFees",
"getTotalBalances",
"getBatchStatus",
"getRefundAmounts",
"claimRefund",
"setTransactionBatchStatus",
"createTransaction"
]

Expand All @@ -43,5 +60,25 @@ add-endpoints = [
"setMultiTransferContractAddress",
"addTokenToWhitelist",
"getTokens",
"addRefundBatch"
"addRefundBatch",
"getRefundAmounts",
"claimRefund",
"getBatchStatus",
"getTotalBalances",
"getAccumulatedTransactionFees",
"setTransactionBatchStatus",
"createTransaction"
]

[[proxy]]
path = "src/esdt_safe_proxy.rs"
add-unlabelled = false
add-endpoints = [
"init",
"initSupply",
"getTotalBalances",
"getBurnBalances",
"unpause",
"addTokenToWhitelist",
"setMultiTransferContractAddress",
]
Loading

0 comments on commit 4bdab8a

Please sign in to comment.