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

Split NEP-141 logic #607

Open
wants to merge 120 commits into
base: develop
Choose a base branch
from
Open

Split NEP-141 logic #607

wants to merge 120 commits into from

Conversation

mrLSD
Copy link
Member

@mrLSD mrLSD commented Sep 21, 2022

Split NEP-141

It is based on AIP: Split NEP-141 logic outside of Engine.

The main purpose is to isolate the NEP-141 Fungible Token logic into a separate contract and remove this logic from the Engine.

Aurora Eth Connector contract: https://github.com/aurora-is-near/aurora-eth-connector

Main goals

  • remove Eth Connector (NEP-141) logic
  • add cross-contract calls to aurora-eth-connector contract
  • modify eth-connector tests
  • add new tests that cover communications with aurora-eth-connector

Solution

  1. Removed fungible_token module
  2. Functions, related to NEP-141 are presented for Engine, as previously, as external public functions. Those, the public interface of the Engine contract has not changed. However, these functions now work differently. Inside them, there is a cross-contract call of the functions of another contract - aurora-eth-connector.
    • ft_transfer
    • ft_transfer_call
    • ft_total_supply
    • ft_balance_of
    • ft_metadata
    • deposit
    • withdraw
    • storage_deposit
    • storage_unregister
    • storage_balance_of
  3. ft_on_transfer is part of Engine, and responsible as call-back function for ft_transfer_call on aurora-eth-connector
  4. removed most of the functionality of the connector module
  5. added new tests coverage as a new sub-crate: engine-tests-connector, with deploying new aurora-eth-connector contract
  6. removed from engine-tests all tests related to eth-connector
  7. For new tests used the new framework: workspace.rs
  8. finish_deposit and other eth-connector specific functions now are part of aurora-eth-connector. This means that now we cannot receive events from there and process them since these functions are private.
  9. Added standalone-legacy-nep141 implementation (Feat: standalone nep141 legacy #669)

Gas costs

Not changed.

Breaking changes

The important change is that before the NEP-141 function call was direct, now it is a cross-contract call. This means that in the NEAR blockchain, this challenge is found as a recipe. This means that if the function had previously returned an error, the transaction was rolled back. Now the transaction will be successful if an error occurs in the receipt. This nuance must be taken into account.

CI flow

Github CI flow was changed. In particular, now the current version ofaurora-eth-connector is downloaded from the remote repository and a contract for tests is being assembled. The run-tests parameters have also been changed, and the number of threads that can be started is limited, which is caused by current restrictions workspace.rs issue 253.

@mrLSD mrLSD added the A-connector Area: Issues that relate to the connector. label Sep 21, 2022
@mrLSD mrLSD self-assigned this Sep 21, 2022
# Conflicts:
#	Cargo.lock
#	engine-standalone-storage/src/relayer_db/mod.rs
#	engine-standalone-storage/src/sync/mod.rs
#	engine-standalone-storage/src/sync/types.rs
#	engine-tests/src/tests/eth_connector.rs
#	engine-tests/src/tests/state_migration.rs
#	engine-tests/src/tests/xcc.rs
#	engine-types/src/storage.rs
#	engine-types/src/types/balance.rs
#	engine/src/admin_controlled.rs
#	engine/src/connector.rs
#	engine/src/lib.rs
#	engine/src/parameters.rs
Makefile.toml Show resolved Hide resolved
engine-precompiles/src/native.rs Show resolved Hide resolved
engine-standalone-nep141-legacy/src/legacy_connector.rs Outdated Show resolved Hide resolved
engine-standalone-nep141-legacy/src/legacy_connector.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

metadata is a more common name. I would use something more specific for that. E.g. ft_metadata?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, it shouldn't even exist. But before removing NEP-141, I think it's more efficient to keep it in Engine because it returns just const data. If we change it to a cross-contract call, we should attach gas. So really temporary solution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove some API but then keep others? It isn't the nETH contract anymore.

engine/src/metadata.rs Outdated Show resolved Hide resolved
engine/src/lib.rs Show resolved Hide resolved
Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
method: "engine_ft_transfer_call".to_string(),
args: data,
attached_balance: Yocto::new(1),
attached_gas: GAS_FOR_FT_TRANSFER_CALL,

Choose a reason for hiding this comment

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

It is unpredictable how much gas the ft_transfer_call cost because it depends on the ft_on_transfer function. But here we provide the constant gas amount and users don't have the opportunity to increase it.

What about using the trick from the standard realization: https://docs.rs/near-contract-standards/latest/src/near_contract_standards/fungible_token/core_impl.rs.html#146 ?

method: "ft_metadata".to_string(),
args: Vec::new(),
attached_balance: ZERO_ATTACHED_BALANCE,
attached_gas: GAS_FOR_FINISH_DEPOSIT,

Choose a reason for hiding this comment

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

Why GAS_FOR_FINISH_DEPOSIT?

method: "get_bridge_prover".to_string(),
args: Vec::new(),
attached_balance: ZERO_ATTACHED_BALANCE,
attached_gas: GAS_FOR_FINISH_DEPOSIT,

Choose a reason for hiding this comment

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

Why GAS_FOR_FINISH_DEPOSIT?

method: "get_accounts_counter".to_string(),
args: Vec::new(),
attached_balance: ZERO_ATTACHED_BALANCE,
attached_gas: GAS_FOR_FINISH_DEPOSIT,

Choose a reason for hiding this comment

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

Why GAS_FOR_FINISH_DEPOSIT?

# Conflicts:
#	.github/workflows/tests.yml
#	Cargo.lock
#	Cargo.toml
#	Makefile.toml
#	engine-standalone-nep141-legacy/src/fungible_token.rs
#	engine-standalone-storage/Cargo.toml
#	engine-standalone-storage/src/sync/mod.rs
#	engine-tests/Cargo.toml
#	engine-tests/src/tests/erc20_connector.rs
#	engine-tests/src/tests/eth_connector.rs
#	engine-tests/src/tests/mod.rs
#	engine-tests/src/tests/repro.rs
#	engine-tests/src/tests/sanity.rs
#	engine-tests/src/tests/state_migration.rs
#	engine-tests/src/tests/uniswap.rs
#	engine-tests/src/tests/xcc.rs
#	engine-tests/src/utils/mod.rs
#	engine-tests/src/utils/standalone/mocks/mod.rs
#	engine-types/src/parameters/mod.rs
#	engine/src/connector.rs
#	engine/src/lib.rs
#	engine/src/parameters.rs
joshuajbouw pushed a commit that referenced this pull request Aug 7, 2023
## Description

The PR is a clone of #607 but for SILO smart contract.

---------

Co-authored-by: Evgeny Ukhanov <evgeny@aurora.dev>
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector Area: Issues that relate to the connector. S-blocked Status: Blocked S-do-not-merge Status: Do not merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants