Skip to content

Commit

Permalink
Remove eth-connector fee logic (#882)
Browse files Browse the repository at this point in the history
<!--
Thanks for submitting a pull request! Here are some helpful tips:

* Always create branches on and target the `develop` branch.
* Run all the tests locally and ensure that they are passing.
* Run `make format` to ensure that the code is formatted.
* Run `make check` to ensure that all checks passed successfully.
* Small commits and contributions that attempt one single goal is
preferable.
* If the idea changes or adds anything functional which will affect
users, an
AIP discussion is required first on the Aurora forum: 

https://forum.aurora.dev/discussions/AIPs%20(Aurora%20Improvement%20Proposals).
* Avoid breaking the public API (namely in engine/src/lib.rs) unless
required.
* If your PR is a WIP, ensure that you enable "draft" mode.
* Your first PRs won't use the CI automatically unless a maintainer
starts.
If this is not your first PR, please do NOT abuse the CI resources.

Checklist:
- [ ] I have performed a self-review of my code
- [ ] I have documented my code, particularly in the hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests to prove my fix or new feature is effective and
works
- [ ] Any dependent changes have been merged
- [ ] The PR is targeting the `develop` branch and not `master`
- [ ] I have pre-squashed my commits into a single commit and rebased.
-->

## Description
Remove unused and redundant `Fee` logic of the eth-connector.
The primary purpose of this change is to unify the message format for
transferring ERC20 and native base tokens.
These changes should simplify the interactions with silo contracts,
especially when the base token is an ERC20 token.

## Performance / NEAR gas cost considerations
Slight reduction in gas
<!--
Performance regressions are not ideal, though we welcome performance 
improvements. Any PR must be completely mindful of any gas cost
increases. The
CI will fail if the gas costs change at all. Do update these tests to 
accommodate for the new gas changes. It is good to explain 
this change, if necessary.
-->

## Testing
Added unit and workspace tests
<!--
Please describe the tests that you ran to verify your changes.
-->

## How should this be reviewed
Verify the `ft_on_transfer` logic for both internal and external
connectors.
This change should be backward compatible, not breaking any internal or
external components/services.
<!--
Include any recommendations of areas to be careful of to ensure that the
reviewers use extra attention.
-->

## Additional information
N/A
<!--
Include any additional information which you think should be in this PR,
such
as prior arts, future extensions, unresolved problems, or a TODO list
which
should be followed up.
-->

---------

Co-authored-by: Oleksandr Anyshchenko <[email protected]>
  • Loading branch information
karim-en and aleksuss committed Feb 6, 2024
1 parent d24ada1 commit 4f708f8
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 105 deletions.
61 changes: 59 additions & 2 deletions engine-tests-connector/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,64 @@ async fn test_ft_transfer_call_eth() -> anyhow::Result<()> {
Ok(())
}

#[tokio::test]
async fn test_ft_transfer_call_without_fee() -> anyhow::Result<()> {
let contract = TestContract::new().await?;
contract.call_deposit_eth_to_near().await?;

let user_acc = contract
.create_sub_account(DEPOSITED_RECIPIENT_NAME)
.await?;
assert_eq!(
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
DEPOSITED_AMOUNT,
);
assert_eq!(
contract
.get_eth_on_near_balance(contract.engine_contract.id())
.await?
.0,
0,
);

let transfer_amount: U128 = 50.into();
let message = RECIPIENT_ETH_ADDRESS;
let memo: Option<String> = None;
let res = user_acc
.call(contract.engine_contract.id(), "ft_transfer_call")
.args_json(json!({
"receiver_id": contract.engine_contract.id(),
"amount": transfer_amount,
"memo": memo,
"msg": message,
}))
.gas(DEFAULT_GAS)
.deposit(ONE_YOCTO)
.transact()
.await?;
assert!(res.is_success());

assert_eq!(
contract.get_eth_on_near_balance(user_acc.id()).await?.0,
DEPOSITED_AMOUNT - transfer_amount.0,
);
assert_eq!(
contract
.get_eth_on_near_balance(contract.engine_contract.id())
.await?
.0,
transfer_amount.0,
);
assert_eq!(
contract
.get_eth_balance(&validate_eth_address(RECIPIENT_ETH_ADDRESS),)
.await?,
transfer_amount.0,
);
assert_eq!(contract.total_supply().await?, DEPOSITED_AMOUNT);
Ok(())
}

#[tokio::test]
async fn test_ft_transfer_call_without_message() -> anyhow::Result<()> {
let contract = TestContract::new().await?;
Expand Down Expand Up @@ -438,8 +496,7 @@ async fn test_deposit_with_0x_prefix() -> anyhow::Result<()> {
let message = [CONTRACT_ACC, ":", "0x", &recipient_address_encoded].concat();
let fee: Fee = Fee::new(NEP141Wei::new(0));
let token_message_data =
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee)
.unwrap();
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message).unwrap();

let deposit_event = DepositedEvent {
eth_custodian_address,
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,7 @@ pub mod workspace {
let message = recipient_id.to_string();
let fee: Fee = Fee::new(NEP141Wei::new(0));
let token_message_data =
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee)
.unwrap();
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message).unwrap();

let deposit_event = DepositedEvent {
eth_custodian_address,
Expand Down
3 changes: 1 addition & 2 deletions engine-tests/src/tests/standalone/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ fn mock_proof(recipient_address: Address, deposit_amount: Wei) -> aurora_engine:
let fee = Fee::new(NEP141Wei::new(0));
let message = ["aurora", ":", recipient_address.encode().as_str()].concat();
let token_message_data: TokenMessageData =
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message, fee)
.unwrap();
TokenMessageData::parse_event_message_and_prepare_token_message_data(&message).unwrap();

let deposit_event = DepositedEvent {
eth_custodian_address,
Expand Down
14 changes: 3 additions & 11 deletions engine-tests/src/utils/standalone/mocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use aurora_engine::engine;
use aurora_engine::engine::Engine;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine::parameters::InitCallArgs;
#[cfg(not(feature = "ext-connector"))]
use aurora_engine_modexp::ModExpAlgorithm;
use aurora_engine_sdk::env::{Env, DEFAULT_PREPAID_GAS};
use aurora_engine_sdk::io::IO;
#[cfg(not(feature = "ext-connector"))]
Expand Down Expand Up @@ -114,19 +112,13 @@ pub fn mint_evm_account<I: IO + Copy, E: Env>(
};

#[cfg(not(feature = "ext-connector"))]
deposit(io, &engine, &env.current_account_id(), address, balance);
deposit(io, &env.current_account_id(), address, balance);

engine.apply(std::iter::once(state_change), std::iter::empty(), false);
}

#[cfg(not(feature = "ext-connector"))]
fn deposit<I: IO + Copy, E: Env, M: ModExpAlgorithm>(
mut io: I,
engine: &Engine<I, E, M>,
aurora_account_id: &AccountId,
address: Address,
balance: Wei,
) {
fn deposit<I: IO + Copy>(mut io: I, aurora_account_id: &AccountId, address: Address, balance: Wei) {
const DEFAULT_GAS: u64 = 300_000_000_000_000;
let deposit_args = aurora_engine_types::parameters::connector::FinishDepositCallArgs {
new_owner_id: aurora_account_id.clone(),
Expand Down Expand Up @@ -165,7 +157,7 @@ fn deposit<I: IO + Copy, E: Env, M: ModExpAlgorithm>(
hex::encode(address.as_bytes())
),
};
connector.ft_on_transfer(engine, &transfer_args).unwrap();
connector.ft_on_transfer(&transfer_args).unwrap();
}

#[cfg(not(feature = "ext-connector"))]
Expand Down
Loading

0 comments on commit 4f708f8

Please sign in to comment.