Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Feature xcmp assets #35

Merged
merged 7 commits into from Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.toml
Expand Up @@ -3,7 +3,14 @@ members = [
"frame/block-reward",
"frame/custom-signatures",
"frame/dapps-staking",
"precompiles/assets-erc20",
"precompiles/dapps-staking",
"precompiles/sr25519",
"precompiles/utils",
]

[patch.crates-io]
ethereum = { git = "https://github.com/AstarNetwork/ethereum", branch = "polkadot-v0.9.17" }
evm = { git = "https://github.com/AstarNetwork/evm", branch = "polkadot-v0.9.17" }
evm-gasometer = { git = "https://github.com/AstarNetwork/evm", branch = "polkadot-v0.9.17" }
evm-runtime = { git = "https://github.com/AstarNetwork/evm", branch = "polkadot-v0.9.17" }
55 changes: 55 additions & 0 deletions precompiles/assets-erc20/Cargo.toml
@@ -0,0 +1,55 @@
[package]
name = "pallet-evm-precompile-assets-erc20"
authors = [ "Stake Technologies", "PureStake" ]
description = "A Precompile to expose a Assets pallet through an ERC20-compliant interface."
edition = "2018"
version = "0.2.0"

[dependencies]
log = "0.4"
num_enum = { version = "0.5.3", default-features = false }
slices = "0.2.0"

# Moonbeam
precompile-utils = { path = "../utils", default-features = false }

# Substrate
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "max-encoded-len" ] }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false }

# Frontier
fp-evm = { git = "https://github.com/AstarNetwork/frontier", branch = "polkadot-v0.9.17", default-features = false }
pallet-evm = { git = "https://github.com/AstarNetwork/frontier", branch = "polkadot-v0.9.17", default-features = false }

[dev-dependencies]
derive_more = { version = "0.99" }
serde = { version = "1.0.100" }
sha3 = "0.8"

codec = { package = "parity-scale-codec", version = "2.0.0", features = [ "max-encoded-len" ] }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17" }
scale-info = { version = "1.0", default-features = false, features = [ "derive" ] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17" }

[features]
default = [ "std" ]
std = [
"codec/std",
"fp-evm/std",
"frame-support/std",
"frame-system/std",
"pallet-assets/std",
"pallet-evm/std",
"precompile-utils/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]
111 changes: 111 additions & 0 deletions precompiles/assets-erc20/ERC20.sol
@@ -0,0 +1,111 @@
pragma solidity ^0.8.0;

/**
* @title ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
* @dev copied from https://github.com/OpenZeppelin/openzeppelin-contracts
*/
interface IERC20 {

/**
* @dev Returns the name of the token.
* Selector: 06fdde03
*/
function name() external view returns (string memory);

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

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

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

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

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

/**
* @dev Transfer token for a specified address
* Selector: a9059cbb
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) external returns (bool);

/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf
* of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may
* use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to
* mitigate this race condition is to first reduce the spender's allowance to 0 and set
* the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* Selector: 095ea7b3
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value)
external returns (bool);

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

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

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