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

Balance type refactoring #386

Merged
merged 68 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6d27234
Added Eth-connector comments and renamde some constants
mrLSD Nov 22, 2021
88d6ae2
Changed eth-connector contract init instance and comments
mrLSD Nov 23, 2021
c5e3d7f
Analized code and added TODO's for next changes. Changes for Trasfer …
mrLSD Nov 23, 2021
5b7e98e
Fix ft_transaction
mrLSD Nov 24, 2021
d8d2038
Introduce Fee type
mrLSD Nov 25, 2021
ee9c2c2
Added Fee type, and change everywhere. Added changes for deposit_even…
mrLSD Nov 25, 2021
4013225
Fix all Fee type dependency. Modified logic: prepare_message_for_on_t…
mrLSD Nov 25, 2021
fb6d780
Fix eth-connecotr tests
mrLSD Nov 25, 2021
2894a28
Changes for Balance type
mrLSD Nov 26, 2021
61e0743
Cleanup imports
mrLSD Nov 26, 2021
c87c17b
Fix standalone/mocks tests
mrLSD Nov 26, 2021
8ba55ed
Added earlt verification to deposit_event for TokenMessageData
mrLSD Nov 26, 2021
cb89024
Extend comments. FungibleToken - cleanup and introduce new type
mrLSD Nov 26, 2021
819a541
Reorgonize TODO's
mrLSD Nov 26, 2021
7f3266d
Changed functions: get_recipient, init_contract
mrLSD Nov 30, 2021
3056329
deposit_event - check u128 overflow
mrLSD Nov 30, 2021
29326b0
parse OnTrasfer: changed Fee to 32 bytes
mrLSD Nov 30, 2021
9b678d5
Change balance types dependency
mrLSD Nov 30, 2021
3fffee6
Fix test_deposit_with_0x_prefix
mrLSD Dec 1, 2021
ca790c5
deposit_event refactoring
mrLSD Dec 1, 2021
9945d35
engine-types: reorgonize types
mrLSD Dec 1, 2021
5aec1e5
Rename OnTransferMessageData -> FtTransferMessageData
mrLSD Dec 2, 2021
7e32715
Wei types - added try_into_u128
mrLSD Dec 2, 2021
a6425b4
Extend Result types for try_into_u128
mrLSD Dec 2, 2021
fb85325
Remove redundant Result types for Engine and try_into_u128 - just cha…
mrLSD Dec 2, 2021
f347f35
Merge branch 'feat/connector-cleanup' of github.com:aurora-is-near/au…
mrLSD Dec 3, 2021
def83bf
Simplify BalanceOverflowError, remove From<Fee> for u128
mrLSD Dec 3, 2021
7361b93
Update engine/src/connector.rs
mrLSD Dec 3, 2021
cf997bf
Update engine/src/fungible_token.rs
mrLSD Dec 3, 2021
a31ec8f
Remove redundant Add<Fee> u128 implementations
mrLSD Dec 3, 2021
7a0f163
Merge branch 'feat/connector-cleanup' of github.com:aurora-is-near/au…
mrLSD Dec 3, 2021
a891f96
Merge branch 'feat/connector-cleanup' of github.com:aurora-is-near/au…
mrLSD Dec 6, 2021
5c9aec9
Fix Balance type for fungible_token and extend Wei type
mrLSD Dec 6, 2021
fe29bc7
Change balance dependencies
mrLSD Dec 7, 2021
ed9de03
Changed Balance for deposit_event
mrLSD Dec 7, 2021
e13616c
Fix engine parameters Balance types
mrLSD Dec 7, 2021
721dcf2
Merge branch 'develop' of github.com:aurora-is-near/aurora-engine int…
mrLSD Dec 7, 2021
605fd3d
Changed Balance type for eth-connector
mrLSD Dec 7, 2021
1da1340
Fix tests for Balance type
mrLSD Dec 7, 2021
fd0003e
Merge branch 'feat/connector-cleanup' of github.com:aurora-is-near/au…
mrLSD Dec 7, 2021
23df001
Fix Wei import
mrLSD Dec 7, 2021
1a608f7
Changed precompiles/native Balance invoke
mrLSD Dec 7, 2021
216aa08
Balance - remove Div method
mrLSD Dec 7, 2021
4e0bd24
Remove Balance Mul
mrLSD Dec 7, 2021
44e7c60
Merge branch 'develop' of github.com:aurora-is-near/aurora-engine int…
mrLSD Dec 8, 2021
cc7a32d
Introduce NEP141Wei, Yocto types. Changes Promises call args types an…
mrLSD Dec 9, 2021
be83db6
Fix tests
mrLSD Dec 9, 2021
97a3053
Merge branch 'develop' of github.com:aurora-is-near/aurora-engine int…
mrLSD Dec 10, 2021
d5ca01e
Feat(standalone): Add debug tracing of remaining gas values (#391)
birchmd Dec 9, 2021
c579fc8
Release 2.3.0. (#392)
joshuajbouw Dec 10, 2021
5009dee
Update engine-types/src/types/balance.rs
mrLSD Dec 13, 2021
01f711c
Update engine-types/src/types/balance.rs
mrLSD Dec 13, 2021
aefaa19
Update engine-types/src/types/wei.rs
mrLSD Dec 13, 2021
005f213
Added Balance chages
mrLSD Dec 13, 2021
2a07840
Merge branch 'feat/balance' of github.com:aurora-is-near/aurora-engin…
mrLSD Dec 13, 2021
fb11973
Remove depends
mrLSD Dec 13, 2021
0a4d3d3
Changed balances for Connector
mrLSD Dec 13, 2021
eff4bb7
Fungible Tokens - changed Balance types
mrLSD Dec 13, 2021
fff8b60
Changed tests
mrLSD Dec 13, 2021
cd716de
Added wei serializer test
mrLSD Dec 13, 2021
980da52
Fungible token - fix types for storage
mrLSD Dec 13, 2021
b4b7549
Cleanup balance
mrLSD Dec 13, 2021
7148fd3
Rename into_u128 -> as_u128
mrLSD Dec 14, 2021
cada6e0
Merge branch 'master' into develop
joshuajbouw Dec 14, 2021
1f180df
Merge branch 'feat/balance' of github.com:aurora-is-near/aurora-engin…
mrLSD Dec 14, 2021
b73bf0b
Minor changes. Remove Borsh for Wei
mrLSD Dec 14, 2021
3d44f9e
Changed Fee type declaration
mrLSD Dec 14, 2021
5df02a2
Changed Promise amount type to Yocto
mrLSD Dec 14, 2021
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
42 changes: 40 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.0] - 2021-12-10

### Added

- A precompile which exposes NEAR's random number generator was added by [@mfornet] as requested by
[@birchmd]. ([#368] [#297])
- London hard fork support was added by [@birchmd]. ([#244])

### Changes

- The gas limit for `deposit` and `ft_on_transfer` were changed as they were not attaching enough
gas, as changed by [@mrLSD]. ([#389])

### Fixes

- There was an issue with the original storage not actually being stored. Unfortunately, previous
transactions can't be updated with this change. This has been fixed by [@birchmd]. ([#390])
- Call arguments were intended to have a value attached to them to make it equivalent to an ETH
call. This was fixed in a backwards compatible manner by [@andrcmdr], as reported by [@birchmd].
([#351] [#309])

### Removed

- Betanet support was dropped and will no longer be supported by [@joshuajbouw]. ([#388])

[#390]: https://github.com/aurora-is-near/aurora-engine/pull/390
[#389]: https://github.com/aurora-is-near/aurora-engine/pull/389
[#388]: https://github.com/aurora-is-near/aurora-engine/pull/388
[#368]: https://github.com/aurora-is-near/aurora-engine/pull/368
[#351]: https://github.com/aurora-is-near/aurora-engine/pull/351
[#311]: https://github.com/aurora-is-near/aurora-engine/pull/311
[#309]: https://github.com/aurora-is-near/aurora-engine/issues/309
[#297]: https://github.com/aurora-is-near/aurora-engine/issues/297
[#244]: https://github.com/aurora-is-near/aurora-engine/pull/244

## [2.2.0] - 2021-11-09

### Added
Expand Down Expand Up @@ -145,7 +180,8 @@ struct SubmitResult {

## [1.0.0] - 2021-05-12

[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/2.2.0...master
[Unreleased]: https://github.com/aurora-is-near/aurora-engine/compare/2.3.0...master
[2.3.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.2.0...2.3.0
[2.2.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/aurora-is-near/aurora-engine/compare/2.0.2...2.1.0
[2.0.2]: https://github.com/aurora-is-near/aurora-engine/compare/2.0.1...2.0.2
Expand All @@ -167,7 +203,9 @@ struct SubmitResult {
[1.1.0]: https://github.com/aurora-is-near/aurora-engine/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/aurora-is-near/aurora-engine/tree/1.0.0

[@mrLSD]: https://github.com/mrLSD
[@andrcmdr]: https://github.com/andrcmdr
[@birchmd]: https://github.com/birchmd
[@joshuajbouw]: https://github.com/joshuajbouw
[@mfornet]: https://github.com/mfornet
[@mrLSD]: https://github.com/mrLSD
[@sept-en]: https://github.com/sept-en
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ documentation.
Network | Contract ID | Chain ID | Version
------- | ------------------- | ---------- | ------
Mainnet | [`aurora`][Mainnet] | 1313161554 | 2.2.0
Testnet | [`aurora`][Testnet] | 1313161555 | 2.2.0
Local | `aurora.test.near` | 1313161556 | 2.2.0
Testnet | [`aurora`][Testnet] | 1313161555 | 2.3.0
Local | `aurora.test.near` | 1313161556 | 2.3.0

[Mainnet]: https://explorer.near.org/accounts/aurora
[Testnet]: https://explorer.testnet.near.org/accounts/aurora
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.0
2.3.0
2 changes: 1 addition & 1 deletion engine-precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl From<PrecompileOutput> for evm::executor::PrecompileOutput {
fn from(output: PrecompileOutput) -> Self {
evm::executor::PrecompileOutput {
exit_status: ExitSucceed::Returned,
cost: output.cost.into_u64(),
cost: output.cost.as_u64(),
output: output.output,
logs: output.logs,
}
Expand Down
24 changes: 13 additions & 11 deletions engine-precompiles/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::prelude::{
parameters::{PromiseArgs, PromiseCreateArgs, WithdrawCallArgs},
sdk,
storage::{bytes_to_key, KeyPrefix},
types::Yocto,
vec, BorshSerialize, Cow, String, ToString, TryFrom, TryInto, Vec, H160, U256,
};
#[cfg(all(feature = "error_refund", feature = "contract"))]
Expand All @@ -24,7 +25,7 @@ use evm::{Context, ExitError};
const ERR_TARGET_TOKEN_NOT_FOUND: &str = "Target token not found";

mod costs {
use crate::prelude::types::EthGas;
use crate::prelude::types::{EthGas, NearGas};

// TODO(#51): Determine the correct amount of gas
pub(super) const EXIT_TO_NEAR_GAS: EthGas = EthGas::new(0);
Expand All @@ -33,14 +34,14 @@ mod costs {
pub(super) const EXIT_TO_ETHEREUM_GAS: EthGas = EthGas::new(0);

// TODO(#332): Determine the correct amount of gas
pub(super) const FT_TRANSFER_GAS: EthGas = EthGas::new(100_000_000_000_000);
pub(super) const FT_TRANSFER_GAS: NearGas = NearGas::new(100_000_000_000_000);

// TODO(#332): Determine the correct amount of gas
#[cfg(feature = "error_refund")]
pub(super) const REFUND_ON_ERROR_GAS: EthGas = EthGas::new(60_000_000_000_000);
pub(super) const REFUND_ON_ERROR_GAS: NearGas = NearGas::new(60_000_000_000_000);

// TODO(#332): Determine the correct amount of gas
pub(super) const WITHDRAWAL_GAS: EthGas = EthGas::new(100_000_000_000_000);
pub(super) const WITHDRAWAL_GAS: NearGas = NearGas::new(100_000_000_000_000);
}

pub mod events {
Expand Down Expand Up @@ -377,15 +378,15 @@ impl Precompile for ExitToNear {
target_account_id: refund_on_error_target,
method: "refund_on_error".to_string(),
args: refund_args.try_to_vec().unwrap(),
attached_balance: 0,
attached_gas: costs::REFUND_ON_ERROR_GAS.into_u64(),
attached_balance: Yocto::new(0),
attached_gas: costs::REFUND_ON_ERROR_GAS,
};
let transfer_promise = PromiseCreateArgs {
target_account_id: nep141_address,
method: "ft_transfer".to_string(),
args: args.as_bytes().to_vec(),
attached_balance: 1,
attached_gas: costs::FT_TRANSFER_GAS.into_u64(),
attached_balance: Yocto::new(1),
attached_gas: costs::FT_TRANSFER_GAS,
};

#[cfg(feature = "error_refund")]
Expand Down Expand Up @@ -463,6 +464,7 @@ impl Precompile for ExitToEthereum {
context: &Context,
is_static: bool,
) -> EvmPrecompileResult {
use crate::prelude::types::NEP141Wei;
if let Some(target_gas) = target_gas {
if Self::required_gas(input)? > target_gas {
return Err(ExitError::OutOfGas);
Expand Down Expand Up @@ -496,7 +498,7 @@ impl Precompile for ExitToEthereum {
// as decimal and hexadecimal respectively.
WithdrawCallArgs {
recipient_address,
amount: context.apparent_value.as_u128(),
amount: NEP141Wei::new(context.apparent_value.as_u128()),
}
.try_to_vec()
.map_err(|_| ExitError::Other(Cow::from("ERR_INVALID_AMOUNT")))?,
Expand Down Expand Up @@ -569,8 +571,8 @@ impl Precompile for ExitToEthereum {
target_account_id: nep141_address,
method: "withdraw".to_string(),
args: serialized_args,
attached_balance: 1,
attached_gas: costs::WITHDRAWAL_GAS.into_u64(),
attached_balance: Yocto::new(1),
attached_gas: costs::WITHDRAWAL_GAS,
};

let promise = PromiseArgs::Create(withdraw_promise).try_to_vec().unwrap();
Expand Down
16 changes: 8 additions & 8 deletions engine-sdk/src/near_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Runtime {
b"state_migration",
&[],
0,
Self::GAS_FOR_STATE_MIGRATION.into_u64(),
Self::GAS_FOR_STATE_MIGRATION.as_u64(),
)
}
}
Expand Down Expand Up @@ -266,8 +266,8 @@ impl crate::promise::PromiseHandler for Runtime {
let account_id = args.target_account_id.as_bytes();
let method_name = args.method.as_bytes();
let arguments = args.args.as_slice();
let amount = args.attached_balance;
let gas = args.attached_gas;
let amount = args.attached_balance.as_u128();
let gas = args.attached_gas.as_u64();

let id = unsafe {
exports::promise_create(
Expand All @@ -292,8 +292,8 @@ impl crate::promise::PromiseHandler for Runtime {
let account_id = callback.target_account_id.as_bytes();
let method_name = callback.method.as_bytes();
let arguments = callback.args.as_slice();
let amount = callback.attached_balance;
let gas = callback.attached_gas;
let amount = callback.attached_balance.as_u128();
let gas = callback.attached_gas.as_u64();

let id = unsafe {
exports::promise_then(
Expand Down Expand Up @@ -322,7 +322,7 @@ impl crate::promise::PromiseHandler for Runtime {
for action in args.actions.iter() {
match action {
PromiseAction::Transfer { amount } => unsafe {
let amount = *amount;
let amount = amount.as_u128();
exports::promise_batch_action_transfer(id, &amount as *const u128 as _);
},
PromiseAction::DeployConotract { code } => unsafe {
Expand All @@ -341,15 +341,15 @@ impl crate::promise::PromiseHandler for Runtime {
} => unsafe {
let method_name = name.as_bytes();
let arguments = args.as_slice();
let amount = *attached_yocto;
let amount = attached_yocto.as_u128();
exports::promise_batch_action_function_call(
id,
method_name.len() as _,
method_name.as_ptr() as _,
arguments.len() as _,
arguments.as_ptr() as _,
&amount as *const u128 as _,
*gas,
gas.as_u64(),
)
},
}
Expand Down
6 changes: 3 additions & 3 deletions engine-standalone/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ impl From<TraceLog> for CTraceLog {
Self {
depth: log.depth.into_u32(),
error,
gas: log.gas.into_u64(),
gas_cost: log.gas_cost.into_u64(),
gas: log.gas.as_u64(),
gas_cost: log.gas_cost.as_u64(),
memory_ptr,
memory_len,
opcode: log.opcode.as_u8(),
Expand Down Expand Up @@ -108,7 +108,7 @@ impl From<TransactionTrace> for CTransactionTrace {
};

Self {
gas: trace.gas().into_u64(),
gas: trace.gas().as_u64(),
result: CString::new(trace.result()).expect("CString::new failed"),
logs_ptr,
logs_len,
Expand Down
4 changes: 3 additions & 1 deletion engine-tests/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use aurora_engine_types::account_id::AccountId;
use aurora_engine_types::types::NEP141Wei;
use borsh::{BorshDeserialize, BorshSerialize};
use near_primitives_core::config::VMConfig;
use near_primitives_core::contract::ContractCode;
Expand Down Expand Up @@ -270,7 +271,8 @@ impl AuroraRunner {
.get(&ft_key)
.map(|bytes| FungibleToken::try_from_slice(&bytes).unwrap())
.unwrap_or_default();
current_ft.total_eth_supply_on_near += init_balance.raw().as_u128();
current_ft.total_eth_supply_on_near =
current_ft.total_eth_supply_on_near + NEP141Wei::new(init_balance.raw().as_u128());
current_ft
};

Expand Down
7 changes: 3 additions & 4 deletions engine-tests/src/test_utils/standalone/mocks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::test_utils;
use aurora_engine::engine;
use aurora_engine::fungible_token::FungibleTokenMetadata;
use aurora_engine::parameters::{FinishDepositCallArgs, InitCallArgs, NewCallArgs};
use aurora_engine_sdk::env::{Env, DEFAULT_PREPAID_GAS};
use aurora_engine_sdk::io::IO;
use aurora_engine_types::types::NearGas;
use aurora_engine_types::types::{NEP141Wei, NearGas};
use aurora_engine_types::{account_id::AccountId, types::Wei, Address, H256, U256};
use engine_standalone_storage::{BlockMetadata, Storage};
use near_sdk_sim::DEFAULT_GAS;

use crate::test_utils;

pub mod block;
pub mod promise;
pub mod storage;
Expand Down Expand Up @@ -101,7 +100,7 @@ pub fn mint_evm_account<I: IO + Copy, E: Env>(

let deposit_args = FinishDepositCallArgs {
new_owner_id: aurora_account_id.clone(),
amount: balance.raw().low_u128(),
amount: NEP141Wei::new(balance.raw().as_u128()),
proof_key: String::new(),
relayer_id: aurora_account_id.clone(),
fee: 0.into(),
Expand Down
10 changes: 5 additions & 5 deletions engine-tests/src/tests/erc20_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn test_ft_on_transfer() {
let nep141 = "tt.testnet".to_string();
let alice = "alice".to_string();
let token = runner.deploy_erc20_token(&nep141);
let amount = 10;
let amount = Balance::new(10);
let recipient = runner.create_account().address;

let balance = runner.balance_of(token, recipient, origin());
Expand All @@ -278,15 +278,15 @@ fn test_ft_on_transfer() {
assert_eq!(res, "\"0\"");

let balance = runner.balance_of(token, recipient, origin());
assert_eq!(balance, U256::from(amount));
assert_eq!(balance, U256::from(amount.as_u128()));
}

#[test]
fn test_ft_on_transfer_fail() {
let mut runner = AuroraRunner::new();
let nep141 = "tt.testnet".to_string();
let alice = "alice".to_string();
let amount = 10;
let amount = Balance::new(10);

let recipient = runner.create_account().address;

Expand All @@ -301,7 +301,7 @@ fn test_relayer_charge_fee() {
let mut runner = AuroraRunner::new();
// Standalone runner presently does not support ft_on_transfer
runner.standalone_runner = None;
let amount = 10;
let amount = Balance::new(10);
let fee = 51;
let nep141 = "tt.testnet".to_string();
let alice = "alice".to_string();
Expand Down Expand Up @@ -339,7 +339,7 @@ fn test_relayer_charge_fee() {
assert_eq!(relayer_balance, Wei::new_u64(fee));

let balance = runner.balance_of(token, recipient, origin());
assert_eq!(balance, U256::from(amount));
assert_eq!(balance, U256::from(amount.as_u128()));
}

#[test]
Expand Down
Loading