Skip to content

Commit

Permalink
fix: reduce the gas usage
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Oct 17, 2024
1 parent 5381627 commit 441f004
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions eth-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl EthConnectorContract {

// Register user and calculate counter
fn register_if_not_exists(&mut self, account: &AccountId) {
if !self.ft.accounts.contains_key(account) {
if self.ft.account_storage_usage == 0 && !self.ft.accounts.contains_key(account) {
self.ft.internal_register_account(account);
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ impl FungibleTokenCore for EthConnectorContract {
#[payable]
#[pause(except(roles(Role::DAO)))]
fn ft_transfer(&mut self, receiver_id: AccountId, amount: U128, memo: Option<String>) {
self.ft.storage_deposit(Some(receiver_id.clone()), None);
self.register_if_not_exists(&receiver_id);
self.ft.ft_transfer(receiver_id, amount, memo);
}

Expand All @@ -358,7 +358,7 @@ impl FungibleTokenCore for EthConnectorContract {
"More gas is required"
);
let sender_id = env::predecessor_account_id();
self.ft.storage_deposit(Some(receiver_id.clone()), None);
self.register_if_not_exists(&receiver_id);
self.internal_ft_transfer_call(sender_id, receiver_id, amount, memo, msg)
}

Expand Down Expand Up @@ -388,7 +388,7 @@ impl EngineFungibleToken for EthConnectorContract {
memo: Option<String>,
) {
self.assert_aurora_engine_access_right();
self.ft.storage_deposit(Some(receiver_id.clone()), None);
self.register_if_not_exists(&receiver_id);

assert_one_yocto();
let amount: Balance = amount.into();
Expand All @@ -413,7 +413,7 @@ impl EngineFungibleToken for EthConnectorContract {
env::prepaid_gas() > GAS_FOR_FT_TRANSFER_CALL,
"More gas is required"
);
self.ft.storage_deposit(Some(receiver_id.clone()), None);
self.register_if_not_exists(&receiver_id);
self.internal_ft_transfer_call(sender_id, receiver_id, amount, memo, msg)
}
}
Expand Down
Binary file modified res/aurora-eth-connector-mainnet-migration.wasm
Binary file not shown.
Binary file modified res/aurora-eth-connector-mainnet.wasm
Binary file not shown.

0 comments on commit 441f004

Please sign in to comment.