Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
20f7188
Add basic implementation for total_supply and balance_of calls
dmitrylavrenov Aug 24, 2023
95481c1
Integrate initial precompile-evm-balances-erc20 implementation into h…
dmitrylavrenov Aug 24, 2023
abd9a18
Add metadata erc20 methods
dmitrylavrenov Aug 24, 2023
a24707d
Add approvals related logic
dmitrylavrenov Aug 24, 2023
5d3fa58
Add transfer related method
dmitrylavrenov Aug 24, 2023
d53e157
Add transferFrom related method
dmitrylavrenov Aug 24, 2023
34325d7
Add event logs
dmitrylavrenov Aug 24, 2023
440d8d0
Add docs to interface actions
dmitrylavrenov Aug 24, 2023
448bd57
Fix some clippy
dmitrylavrenov Aug 24, 2023
7c1e371
Add docs for approves logic
dmitrylavrenov Aug 24, 2023
b06c562
Fix typos
dmitrylavrenov Aug 24, 2023
5faec0f
Remove unnecesary docs
dmitrylavrenov Aug 25, 2023
64a9610
Introduce helper functions to simplify code
dmitrylavrenov Aug 25, 2023
70d0b08
Some refactoring
dmitrylavrenov Aug 25, 2023
5f81c84
Update features snapshot
dmitrylavrenov Aug 25, 2023
0d5b4d6
Fix docs
dmitrylavrenov Aug 25, 2023
41be202
Add ERC20 solidity interface
dmitrylavrenov Aug 25, 2023
6785a6e
Rename erc20 metadata at frontier precompiles
dmitrylavrenov Aug 25, 2023
c055a1a
Add mocked environment
dmitrylavrenov Aug 25, 2023
68de669
Add metadata related tests
dmitrylavrenov Aug 25, 2023
c7c1c34
Add balance_of_works and total_supply_works tests
dmitrylavrenov Aug 25, 2023
115acc3
Add approve_works test
dmitrylavrenov Aug 25, 2023
88b2356
Rename some tests
dmitrylavrenov Aug 25, 2023
8147024
Add transfer_works test
dmitrylavrenov Aug 25, 2023
e6a33ea
Add transfer_from_works test
dmitrylavrenov Aug 25, 2023
890f6a7
Rename symbol
dmitrylavrenov Aug 28, 2023
2992d29
Edit name erc20 metadata
dmitrylavrenov Aug 28, 2023
99d30dc
Introduce pallet-erc20 to store approvals data
dmitrylavrenov Aug 28, 2023
f0a31c8
Use approvals logic from pallet-erc20 at precompile
dmitrylavrenov Aug 28, 2023
9736378
Use currency config instead of pallet-evm-balances config
dmitrylavrenov Aug 28, 2023
350d670
Add erc20 related logic into pallet-erc20
dmitrylavrenov Aug 29, 2023
be70bdd
Add utility aliases
dmitrylavrenov Aug 30, 2023
aadf8b2
Integrate pallet-erc20 logic into precompile
dmitrylavrenov Aug 30, 2023
60f43cc
Fix mock at pallet-erc20
dmitrylavrenov Aug 30, 2023
c7421e3
Fix mock at precompile
dmitrylavrenov Aug 30, 2023
1fdbb26
Remove redundant dependency
dmitrylavrenov Aug 30, 2023
4b9a3e1
Rename pallet-erc20 to pallet-token-wrapper
dmitrylavrenov Aug 30, 2023
3aa99bd
Rename precompile-evm-balances-erc20 into precompile-token-wrapper
dmitrylavrenov Aug 30, 2023
9e5460e
Integrate introduced changes into humanode-runtime
dmitrylavrenov Aug 30, 2023
922f15f
Use wrapped-token instead for token-wrapper
dmitrylavrenov Aug 30, 2023
14883e3
Merge branch 'master' into precompile-balances-erc20
dmitrylavrenov Sep 4, 2023
9275197
Rename EvmBalancesErc20 into WrappedEvmBalances
dmitrylavrenov Sep 4, 2023
c52f822
Add total_supply_works test to pallet-wrapped-token
dmitrylavrenov Sep 4, 2023
9af708f
Improve approvals related test at pallet-wrapped-token
dmitrylavrenov Sep 4, 2023
03d9703
Add transfer_works test
dmitrylavrenov Sep 4, 2023
2a547f0
Add transfer_from_works test
dmitrylavrenov Sep 4, 2023
85a6c63
Add fails tests for transfer from logic
dmitrylavrenov Sep 4, 2023
2c1e87a
Add with_storage_layer usage at pallet-wrapped-token
dmitrylavrenov Sep 4, 2023
2a4ee15
Fix features
dmitrylavrenov Sep 6, 2023
654dc65
Use approvals aliases
dmitrylavrenov Sep 8, 2023
0f21930
Merge branch 'master' into precompile-balances-erc20
dmitrylavrenov Sep 8, 2023
cec5068
Rename pallet-wrapped-token into pallet-erc20-support
dmitrylavrenov Sep 8, 2023
87d81ff
Merge branch 'master' into precompile-balances-erc20
dmitrylavrenov Sep 11, 2023
38f68c2
Some renaming and docs improvements
dmitrylavrenov Sep 12, 2023
93be731
Update features snapshot
dmitrylavrenov Sep 12, 2023
0fdc379
Add comments for tests at pallet-erc20-support
dmitrylavrenov Sep 12, 2023
6e9c7db
Improve dispatch error handling
dmitrylavrenov Sep 12, 2023
7a6f1b5
Add more tests at precompile-erc20-support
dmitrylavrenov Sep 12, 2023
ad08491
Merge branch 'master' into precompile-balances-erc20
dmitrylavrenov Sep 14, 2023
38966f0
Merge branch 'master' into precompile-balances-erc20
dmitrylavrenov Sep 14, 2023
d66cddf
Rename precompile-erc20-support into precompile-native-currency
dmitrylavrenov Sep 14, 2023
78b3097
Rename Erc20EvmBalancesMetadata into EvmBalancesErc20Metadata
dmitrylavrenov Sep 14, 2023
974d188
Rename Erc20EvmBalances into EvmBalancesErc20Support
dmitrylavrenov Sep 14, 2023
66f9c50
Revert "Use approvals aliases"
dmitrylavrenov Sep 14, 2023
b293aad
Merge branch 'master' into precompile-balances-erc20
dmitrylavrenov Sep 14, 2023
276d52f
Properly handle transferFrom logic
dmitrylavrenov Sep 18, 2023
e600842
Improve dispatch error handling
dmitrylavrenov Sep 18, 2023
1354e9e
Add approve_overwrite_works test
dmitrylavrenov Sep 18, 2023
a7944d6
Fix transfer
dmitrylavrenov Sep 18, 2023
ebed3b0
Add tests to check approve logic with sending full approved balance
dmitrylavrenov Sep 18, 2023
00e1d79
Add approve_approval_value_more_than_balance_works test
dmitrylavrenov Sep 18, 2023
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
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pallet-vesting = { path = "../pallet-vesting", default-features = false }
precompile-bioauth = { path = "../precompile-bioauth", default-features = false }
precompile-currency-swap = { path = "../precompile-currency-swap", default-features = false }
precompile-evm-accounts-mapping = { path = "../precompile-evm-accounts-mapping", default-features = false }
precompile-evm-balances-erc20 = { path = "../precompile-evm-balances-erc20", default-features = false }
precompile-utils = { path = "../precompile-utils", default-features = false }
primitives-auth-ticket = { path = "../primitives-auth-ticket", default-features = false }
primitives-currency-swap-proxy = { path = "../primitives-currency-swap-proxy", default-features = false }
Expand Down Expand Up @@ -190,6 +191,7 @@ std = [
"precompile-bioauth/std",
"precompile-currency-swap/std",
"precompile-evm-accounts-mapping/std",
"precompile-evm-balances-erc20/std",
"precompile-utils/std",
"primitives-auth-ticket/std",
"primitives-currency-swap-proxy/std",
Expand Down
29 changes: 27 additions & 2 deletions crates/humanode-runtime/src/frontier_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripe
use precompile_bioauth::Bioauth;
use precompile_currency_swap::CurrencySwap;
use precompile_evm_accounts_mapping::EvmAccountsMapping;
use sp_core::H160;
use precompile_evm_balances_erc20::EvmBalancesErc20;
use sp_core::{H160, U256};
use sp_std::marker::PhantomData;

use crate::{currency_swap, AccountId, ConstU64, EvmAccountId};
Expand All @@ -23,7 +24,7 @@ where
R: pallet_evm::Config,
{
pub fn used_addresses() -> sp_std::vec::Vec<H160> {
sp_std::vec![1_u64, 2, 3, 4, 5, 1024, 1025, 2048, 2049, 2304]
sp_std::vec![1_u64, 2, 3, 4, 5, 1024, 1025, 2048, 2049, 2050, 2304]
.into_iter()
.map(hash)
.collect()
Expand All @@ -35,6 +36,9 @@ where
R: pallet_evm::Config,
R: pallet_bioauth::Config,
R: pallet_evm_accounts_mapping::Config,
R: pallet_evm_balances::Config,
<R as pallet_evm_balances::Config>::Balance: Into<U256> + TryFrom<U256>,
<R as pallet_evm_balances::Config>::AccountId: From<H160>,
R::ValidatorPublicKey: for<'a> TryFrom<&'a [u8]> + Eq,
{
fn execute(&self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
Expand All @@ -51,6 +55,11 @@ where
// Humanode precompiles:
a if a == hash(2048) => Some(Bioauth::<R>::execute(handle)),
a if a == hash(2049) => Some(EvmAccountsMapping::<R>::execute(handle)),
a if a == hash(2050) => {
Some(
EvmBalancesErc20::<R, EvmBalancesErc20Metadata, ConstU64<200>>::execute(handle),
)
}
a if a == hash(2304) => Some(CurrencySwap::<
currency_swap::EvmToNativeOneToOne,
EvmAccountId,
Expand All @@ -71,3 +80,19 @@ where
fn hash(a: u64) -> H160 {
H160::from_low_u64_be(a)
}

pub struct EvmBalancesErc20Metadata;

impl precompile_evm_balances_erc20::Erc20Metadata for EvmBalancesErc20Metadata {
fn name() -> &'static str {
"Ethereum humanode token"
}

fn symbol() -> &'static str {
"eHMND"
}

fn decimals() -> u8 {
18
}
}
47 changes: 47 additions & 0 deletions crates/precompile-evm-balances-erc20/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "precompile-evm-balances-erc20"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
precompile-utils = { path = "../precompile-utils", default-features = false }
primitives-currency-swap = { path = "../primitives-currency-swap", default-features = false }

codec = { workspace = true, package = "parity-scale-codec", features = ["derive"] }
fp-evm = { workspace = true }
frame-support = { workspace = true }
num_enum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-balances = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
sp-core = { workspace = true }

[dev-dependencies]
precompile-utils = { path = "../precompile-utils", features = ["testing"] }

frame-system = { workspace = true }
hex-literal = { workspace = true }
pallet-balances = { workspace = true, features = ["default"] }
pallet-evm = { workspace = true }
pallet-evm-system = { workspace = true, features = ["default"] }
pallet-timestamp = { workspace = true, features = ["default"] }

[features]
default = ["std"]
std = [
"codec/std",
"fp-evm/std",
"frame-support/std",
"frame-system/std",
"num_enum/std",
"pallet-balances/std",
"pallet-evm-balances/std",
"pallet-evm-system/std",
"pallet-evm/std",
"pallet-timestamp/std",
"precompile-utils/std",
"primitives-currency-swap/std",
"scale-info/std",
"sp-core/std",
]
117 changes: 117 additions & 0 deletions crates/precompile-evm-balances-erc20/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity >=0.7.0 <0.9.0;

/**
* @title ERC20 Interface
*
* An interface exposing native eHMND tokens as ERC20 tokens.
*
* Address: 0x0000000000000000000000000000000000000802
*/
interface IERC20 {
/**
* Returns the name of the token.
* Selector: 06fdde03
*/
function name() external view returns (string memory);

/**
* Returns the symbol of the token.
* Selector: 95d89b41
*/
function symbol() external view returns (string memory);

/**
* Returns the decimals places of the token.
* Selector: 313ce567
*/
function decimals() external view returns (uint8);

/**
* Total number of tokens in existence.
* Selector: 18160ddd
*/
function totalSupply() external view returns (uint256);

/**
* Gets the balance of the specified address.
* Selector: 70a08231
*
* @param owner The address to query the balance of.
* @return uint256 The amount owned by the passed address.
*/
function balanceOf(address owner) external view returns (uint256);

/**
* Function to check the amount of tokens that an owner allowed to a spender.
* Selector: dd62ed3e
*
* @param owner The address which owns the funds.
* @param spender The address which will spend the funds.
* @return uint256 The amount of tokens still available for the spender.
*/
function allowance(
address owner,
address spender
) external view returns (uint256);

/**
* Transfer token for a specified address.
* Selector: a9059cbb
*
* @param to The address to transfer tokens to.
* @param value The amount to be transferred.
* @return true if the transfer was succesful, revert otherwise.
*/
function transfer(address to, uint256 value) external returns (bool);

/**
* Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Selector: 095ea7b3
*
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return true, this cannot fail.
*/
function approve(address spender, uint256 value) external returns (bool);

/**
* Transfer tokens from one address to another.
* Selector: 23b872dd
*
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return true if the transfer was succesful, revert otherwise.
*/
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);

/**
* Event emited when a transfer has been performed.
* Selector: ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
*
* @param from The address sending the tokens
* @param to The address receiving the tokens.
* @param value The amount of tokens transfered.
*/
event Transfer(address indexed from, address indexed to, uint256 value);

/**
* Event emited when an approval has been registered.
* Selector: 8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925
*
* @param owner The owner address of the tokens.
* @param spender The allowed spender address.
* @param value The amount of tokens approved.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
Loading