Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat 3.5 implementation #196

Merged
merged 33 commits into from
Sep 12, 2024
Merged
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
572773d
first-commit
evelinemolnar Aug 21, 2024
729523d
first-commit
evelinemolnar Aug 21, 2024
ba5677f
quick renane
evelinemolnar Aug 21, 2024
5b0fcc4
first-commit
evelinemolnar Aug 21, 2024
76e620e
Merge pull request #193 from multiversx/CII-49-create-common-transaction
dragos-rebegea Aug 22, 2024
0a4312a
Merge pull request #194 from multiversx/CII-50-event-sc-call
dragos-rebegea Aug 22, 2024
0ddb6a1
Merge branch 'feat-3.5-implementation' into CII-51-update-endpoint
dragos-rebegea Aug 22, 2024
f4b38bc
Merge pull request #195 from multiversx/CII-51-update-endpoint
dragos-rebegea Aug 22, 2024
aa16150
99%
evelinemolnar Aug 29, 2024
8dc7429
small-fix
evelinemolnar Aug 29, 2024
4d0776d
.
evelinemolnar Aug 29, 2024
7e924dd
.
evelinemolnar Aug 29, 2024
684183a
.
evelinemolnar Aug 29, 2024
7361cc0
.
evelinemolnar Aug 29, 2024
c20ded0
white-box
evelinemolnar Aug 30, 2024
e9838c5
multi-contract
evelinemolnar Aug 30, 2024
4084fc0
Merge pull request #201 from multiversx/remove-onlyownerv1
evelinemolnar Aug 30, 2024
bfcce64
.
evelinemolnar Aug 30, 2024
a0ebf2a
.
evelinemolnar Sep 2, 2024
6b209f4
change upgrade to init
evelinemolnar Sep 3, 2024
d8d7916
refactor - moved some tests in multitransafer blackbox
evelinemolnar Sep 8, 2024
3f02da5
forgot to include a proxy file
evelinemolnar Sep 9, 2024
0de0579
fix case
evelinemolnar Sep 9, 2024
d814e66
last-updates
evelinemolnar Sep 10, 2024
883ac77
.
evelinemolnar Sep 10, 2024
a96cf44
.
evelinemolnar Sep 10, 2024
715cb14
remove-duplicate-code
evelinemolnar Sep 10, 2024
e5daccb
Merge pull request #198 from multiversx/CII-52
dragos-rebegea Sep 11, 2024
b36d232
clippy fixes
evelinemolnar Sep 11, 2024
2b58348
Merge remote-tracking branch 'origin/feat/v3.5' into feat-3.5-impleme…
dragos-rebegea Sep 11, 2024
e3e6fdc
fix proxy after merge
dragos-rebegea Sep 11, 2024
8b86567
fix clippy
dragos-rebegea Sep 11, 2024
1ca0e7d
fix clippy
dragos-rebegea Sep 11, 2024
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
103 changes: 86 additions & 17 deletions esdt-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ const DEFAULT_MAX_TX_BATCH_BLOCK_DURATION: u64 = 100; // ~10 minutes

pub type PaymentsVec<M> = ManagedVec<M, EsdtTokenPayment<M>>;

pub struct TransactionDetails<Api: ManagedTypeApi> {
pub batch_id: u64,
pub tx_nonce: u64,
pub payment_token: TokenIdentifier<Api>,
pub actual_bridged_amount: BigUint<Api>,
pub required_fee: BigUint<Api>,
pub to_address: ManagedBuffer<Api>,
pub caller_address: ManagedBuffer<Api>,
}

#[multiversx_sc::contract]
pub trait EsdtSafe:
fee_estimator_module::FeeEstimatorModule
Expand Down Expand Up @@ -218,29 +228,19 @@ pub trait EsdtSafe:
}
}

// endpoints

/// Create an MultiversX -> Ethereum transaction. Only fungible tokens are accepted.
///
/// Every transfer will have a part of the tokens subtracted as fees.
/// The fee amount depends on the global eth_tx_gas_limit
/// and the current GWEI price, respective to the bridged token
///
/// fee_amount = price_per_gas_unit * eth_tx_gas_limit
#[payable("*")]
#[endpoint(createTransaction)]
fn create_transaction(&self, to: EthAddress<Self::Api>) {
fn create_transaction_common(
&self,
to: EthAddress<Self::Api>,
) -> TransactionDetails<Self::Api> {
require!(self.not_paused(), "Cannot create transaction while paused");

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

let required_fee = self.calculate_required_fee(&payment_token);
require!(
required_fee < payment_amount,
"Transaction fees cost more than the entire bridged amount"
);

self.require_below_max_amount(&payment_token, &payment_amount);

self.accumulated_transaction_fees(&payment_token)
Expand Down Expand Up @@ -280,14 +280,70 @@ pub trait EsdtSafe:
*burned += &actual_bridged_amount;
});
}
self.create_transaction_event(
TransactionDetails {
batch_id,
tx_nonce,
payment_token,
actual_bridged_amount,
required_fee,
tx.to,
tx.from,
to_address: to.as_managed_buffer().clone(),
caller_address: caller.as_managed_buffer().clone(),
}
}

// endpoints

/// Create an MultiversX -> Ethereum transaction. Only fungible tokens are accepted.
///
/// Every transfer will have a part of the tokens subtracted as fees.
/// The fee amount depends on the global eth_tx_gas_limit
/// and the current GWEI price, respective to the bridged token
///
/// fee_amount = price_per_gas_unit * eth_tx_gas_limit
#[payable("*")]
#[endpoint(createTransaction)]
fn create_transaction(&self, to: EthAddress<Self::Api>) {
let transaction_details = self.create_transaction_common(to);
let token_nonce = self.call_value().single_esdt().token_nonce;
dragos-rebegea marked this conversation as resolved.
Show resolved Hide resolved
require!(
token_nonce == 0,
"Only fungible tokens are accepted for this transaction"
);

self.create_transaction_event(
transaction_details.batch_id,
transaction_details.tx_nonce,
transaction_details.payment_token,
transaction_details.actual_bridged_amount,
transaction_details.required_fee,
transaction_details.to_address,
transaction_details.caller_address,
);
}

#[payable("*")]
#[endpoint(createTransactionSCCall)]
fn create_transaction_sc_call(
&self,
to: EthAddress<Self::Api>,
data: ManagedBuffer<Self::Api>,
) {
let transaction_details = self.create_transaction_common(to);
let token_nonce = self.call_value().single_esdt().token_nonce;
require!(
token_nonce == 0,
"Only fungible tokens are accepted for this transaction"
);

self.create_transaction_sc_call_event(
transaction_details.batch_id,
transaction_details.tx_nonce,
transaction_details.payment_token,
transaction_details.actual_bridged_amount,
transaction_details.required_fee,
transaction_details.to_address,
transaction_details.caller_address,
data,
);
}

Expand Down Expand Up @@ -451,6 +507,19 @@ pub trait EsdtSafe:
#[indexed] recipient: ManagedBuffer,
);

#[event("createTransactionScCallEvent")]
fn create_transaction_sc_call_event(
&self,
#[indexed] batch_id: u64,
#[indexed] tx_nonce: u64,
#[indexed] payment_token: TokenIdentifier,
#[indexed] amount: BigUint,
#[indexed] fee: BigUint,
#[indexed] to: ManagedBuffer,
#[indexed] from: ManagedBuffer,
#[indexed] data: ManagedBuffer,
Comment on lines +512 to +516
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[indexed] amount: BigUint,
#[indexed] fee: BigUint,
#[indexed] to: ManagedBuffer,
#[indexed] from: ManagedBuffer,
#[indexed] data: ManagedBuffer,
amount: BigUint,
fee: BigUint,
to: ManagedBuffer,
from: ManagedBuffer,
data: ManagedBuffer,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do the same for create_transaction_event

);

#[event("addRefundTransactionEvent")]
fn add_refund_transaction_event(
&self,
Expand Down
Loading