Skip to content

Commit

Permalink
add unwrap and create transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
dragos-rebegea committed Jul 18, 2024
1 parent d7f31ea commit 6ec7cd1
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions bridge-proxy/src/bridge-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use multiversx_sc::imports::*;

pub mod bridge_proxy_contract_proxy;
pub mod config;
pub mod esdt_safe_proxy;
pub mod bridged_tokens_wrapper;

Check failure on line 6 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

file not found for module `bridged_tokens_wrapper`

Check failure on line 6 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / Contracts / Test Coverage

file not found for module `bridged_tokens_wrapper`

Check failure on line 6 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

file not found for module `bridged_tokens_wrapper`

Check failure on line 6 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] bridge-proxy/src/bridge-proxy.rs#L6

error[E0583]: file not found for module `bridged_tokens_wrapper` --> bridge-proxy/src/bridge-proxy.rs:6:1 | 6 | pub mod bridged_tokens_wrapper; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: to create the module `bridged_tokens_wrapper`, create file "bridge-proxy/src/bridged_tokens_wrapper.rs" or "bridge-proxy/src/bridged_tokens_wrapper/mod.rs" = note: if there is a `mod bridged_tokens_wrapper` elsewhere in the crate already, import it with `use crate::...` instead
Raw output
bridge-proxy/src/bridge-proxy.rs:6:1:e:error[E0583]: file not found for module `bridged_tokens_wrapper`
 --> bridge-proxy/src/bridge-proxy.rs:6:1
  |
6 | pub mod bridged_tokens_wrapper;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: to create the module `bridged_tokens_wrapper`, create file "bridge-proxy/src/bridged_tokens_wrapper.rs" or "bridge-proxy/src/bridged_tokens_wrapper/mod.rs"
  = note: if there is a `mod bridged_tokens_wrapper` elsewhere in the crate already, import it with `use crate::...` instead


__END__

use transaction::EthTransaction;

Expand Down Expand Up @@ -72,11 +72,13 @@ pub trait BridgeProxyContract:
let tx = self.get_pending_transaction_by_id(tx_id);
let esdt_safe_addr = self.esdt_safe_address().get();

let (payment_token, payment_amount) = self.call_value().single_fungible_esdt();

self.tx()
.to(esdt_safe_addr)
.typed(esdt_safe_proxy::EsdtSafeProxy)
.create_transaction(tx.from)
.single_esdt(&tx.token_id, 0, &tx.amount)
.typed(bridged_tokens_wrapper::BridgedTokensWrapperProxy)

Check failure on line 79 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / Contracts / Rust tests

cannot find value `BridgedTokensWrapperProxy` in module `bridged_tokens_wrapper`

Check failure on line 79 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / Contracts / Test Coverage

cannot find value `BridgedTokensWrapperProxy` in module `bridged_tokens_wrapper`

Check failure on line 79 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / Contracts / Wasm tests

cannot find value `BridgedTokensWrapperProxy` in module `bridged_tokens_wrapper`

Check failure on line 79 in bridge-proxy/src/bridge-proxy.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] bridge-proxy/src/bridge-proxy.rs#L79

error[E0425]: cannot find value `BridgedTokensWrapperProxy` in module `bridged_tokens_wrapper` --> bridge-proxy/src/bridge-proxy.rs:79:44 | 79 | .typed(bridged_tokens_wrapper::BridgedTokensWrapperProxy) | ^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `bridged_tokens_wrapper`
Raw output
bridge-proxy/src/bridge-proxy.rs:79:44:e:error[E0425]: cannot find value `BridgedTokensWrapperProxy` in module `bridged_tokens_wrapper`
  --> bridge-proxy/src/bridge-proxy.rs:79:44
   |
79 |             .typed(bridged_tokens_wrapper::BridgedTokensWrapperProxy)
   |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `bridged_tokens_wrapper`


__END__
.unwrap_token_create_transaction(&tx.token_id, tx.from)
.single_esdt(&payment_token, 0, &payment_amount)
.sync_call();
}

Expand Down
9 changes: 9 additions & 0 deletions bridged-tokens-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ path = "src/lib.rs"
[dependencies.transaction]
path = "../common/transaction"

[dependencies.eth-address]
path = "../common/eth-address"

[dependencies.token-module]
path = "../common/token-module"

[dependencies.tx-batch-module]
path = "../common/tx-batch-module"

[dependencies.multiversx-sc]
version = "=0.51.1"

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bridged-tokens-wrapper/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pub trait EventsModule {
fn wrap_tokens_event(&self, #[indexed] token_id: TokenIdentifier, #[indexed] amount: BigUint);

#[event("unwrap_tokens")]
fn unwrap_tokens_event(&self, #[indexed] token_id: TokenIdentifier, #[indexed] amount: BigUint);
fn unwrap_tokens_event(&self, #[indexed] token_id: &TokenIdentifier, #[indexed] amount: BigUint);
}
26 changes: 22 additions & 4 deletions bridged-tokens-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

mod dfp_big_uint;
mod events;
mod esdt_safe_proxy;
use core::ops::Deref;

pub use dfp_big_uint::DFPBigUint;
use transaction::PaymentsVec;

use multiversx_sc::imports::*;
use eth_address::*;

impl<M: ManagedTypeApi> DFPBigUint<M> {}

Expand Down Expand Up @@ -194,6 +196,14 @@ pub trait BridgedTokensWrapper:
#[payable("*")]
#[endpoint(unwrapToken)]
fn unwrap_token(&self, requested_token: TokenIdentifier) {
let converted_amount = self.unwrap_token_common(&requested_token);
self.tx()
.to(ToCaller)
.single_esdt(&requested_token, 0, &converted_amount)
.transfer();
}

fn unwrap_token_common(&self, requested_token: &TokenIdentifier) -> BigUint {
require!(self.not_paused(), "Contract is paused");
let (payment_token, payment_amount) = self.call_value().single_fungible_esdt();
require!(payment_amount > 0u32, "Must pay more than 0 tokens!");
Expand Down Expand Up @@ -226,12 +236,20 @@ pub trait BridgedTokensWrapper:
self.send()
.esdt_local_burn(&universal_bridged_token_ids, 0, &payment_amount);

self.unwrap_tokens_event(chain_specific_token_id, converted_amount.clone());
converted_amount
}

#[payable("*")]
#[endpoint(unwrapTokenCreateTransaction)]
fn unwrap_token_create_transaction(&self, requested_token: TokenIdentifier, to: EthAddress<Self::Api>) {
let converted_amount = self.unwrap_token_common(&requested_token);
self.tx()
.to(ToCaller)
.single_esdt(chain_specific_token_id, 0, &converted_amount)
.transfer();

self.unwrap_tokens_event(chain_specific_token_id.clone(), converted_amount);
.typed(esdt_safe_proxy::EsdtSafeProxy)
.create_transaction(to)
.single_esdt(&requested_token, 0, &converted_amount)
.sync_call();
}

fn get_converted_amount(
Expand Down
26 changes: 26 additions & 0 deletions bridged-tokens-wrapper/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -29,6 +29,7 @@ multiversx_sc_wasm_adapter::endpoints! {
depositLiquidity => deposit_liquidity
wrapTokens => wrap_tokens
unwrapToken => unwrap_token
unwrapTokenCreateTransaction => unwrap_token_create_transaction
getUniversalBridgedTokenIds => universal_bridged_token_ids
getTokenLiquidity => token_liquidity
getChainSpecificToUniversalMapping => chain_specific_to_universal_mapping
Expand Down
15 changes: 15 additions & 0 deletions multi-transfer-esdt/src/bridged_tokens_wrapper_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ where
.original_result()
}

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

pub fn universal_bridged_token_ids(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, TokenIdentifier<Env::Api>>> {
Expand Down
3 changes: 3 additions & 0 deletions multi-transfer-esdt/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions multisig/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ec7cd1

Please sign in to comment.