Skip to content

Commit

Permalink
Add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Aug 6, 2023
1 parent 10d1ab3 commit 0e6d363
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions eth-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,19 @@ impl Withdraw for EthConnectorContract {
// Burn tokens to recipient
self.ft.internal_withdraw(&sender_id, amount);

let fee_amount =
self.calculate_fee_amount(amount.into(), FeeType::Withdraw, Some(sender_id));
let fee_amount = self
.calculate_fee_amount(amount.into(), FeeType::Withdraw, Some(sender_id))
.0;
// Mint fee
self.mint_eth_on_near(&env::current_account_id(), fee_amount.0);
self.mint_eth_on_near(&env::current_account_id(), fee_amount);

let withdraw_amount = amount.checked_sub(fee_amount).sdk_unwrap();

let withdraw_amount = amount.checked_sub(fee_amount.0).sdk_unwrap();
near_sdk::log!(
"withdraw_amount: {}, fee_amount: {}",
withdraw_amount,
fee_amount
);
WithdrawResult {
amount: withdraw_amount,
recipient_id: recipient_address,
Expand Down Expand Up @@ -561,12 +568,19 @@ impl EngineConnectorWithdraw for EthConnectorContract {
// Burn tokens to recipient
self.ft.internal_withdraw(&sender_id, amount);

let fee_amount =
self.calculate_fee_amount(amount.into(), FeeType::Withdraw, Some(sender_id));
let fee_amount = self
.calculate_fee_amount(amount.into(), FeeType::Withdraw, Some(sender_id))
.0;
// Mint fee
self.mint_eth_on_near(&env::current_account_id(), fee_amount.0);
self.mint_eth_on_near(&env::current_account_id(), fee_amount);

let withdraw_amount = amount.checked_sub(fee_amount).sdk_unwrap();

let withdraw_amount = amount.checked_sub(fee_amount.0).sdk_unwrap();
near_sdk::log!(
"withdraw_amount: {}, fee_amount: {}",
withdraw_amount,
fee_amount
);
WithdrawResult {
amount: withdraw_amount,
recipient_id: recipient_address,
Expand Down Expand Up @@ -691,14 +705,23 @@ impl FundsFinish for EthConnectorContract {
.map_err(|_| crate::errors::ERR_BORSH_DESERIALIZE)
.sdk_unwrap();

let fee_amount = self.calculate_fee_amount(
deposit_call.amount.into(),
FeeType::Deposit,
Some(args.receiver_id.clone()),
let fee_amount = self
.calculate_fee_amount(
deposit_call.amount.into(),
FeeType::Deposit,
Some(args.receiver_id.clone()),
)
.0;
let amount_to_transfer = deposit_call.amount.checked_sub(fee_amount).sdk_unwrap();

near_sdk::log!(
"deposit_amount: {}, fee_amount: {}",
amount_to_transfer,
fee_amount
);
let amount_to_transfer = deposit_call.amount.checked_sub(fee_amount.0).sdk_unwrap();

// Early return if the fee is higher than the transferred amount
if amount_to_transfer == 0 && fee_amount.0 != 0 {
if amount_to_transfer == 0 && fee_amount != 0 {
return PromiseOrValue::Value(Some(U128(0)));
}

Expand All @@ -714,12 +737,19 @@ impl FundsFinish for EthConnectorContract {
PromiseOrValue::Value(v) => PromiseOrValue::Value(Some(v)),
}
} else {
let fee_amount =
self.calculate_fee_amount(deposit_call.amount.into(), FeeType::Deposit, None);
let deposit_amount = deposit_call.amount.checked_sub(fee_amount.0).sdk_unwrap();
let fee_amount = self
.calculate_fee_amount(deposit_call.amount.into(), FeeType::Deposit, None)
.0;
let deposit_amount = deposit_call.amount.checked_sub(fee_amount).sdk_unwrap();

near_sdk::log!(
"deposit_amount: {}, fee_amount: {}",
deposit_amount,
fee_amount
);

// Mint - calculate new balances
self.mint_eth_on_near(&env::current_account_id(), fee_amount.0);
self.mint_eth_on_near(&env::current_account_id(), fee_amount);

self.mint_eth_on_near(&deposit_call.new_owner_id, deposit_amount);

Expand Down

0 comments on commit 0e6d363

Please sign in to comment.