-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port assets-erc20 precompile from Moonbeam (#27)
* port assets-erc20 precompile * update Cargo.lock * fix rust tests * pr suggestions * move pallet-balances to dev deps
- Loading branch information
Showing
9 changed files
with
3,127 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
[package] | ||
name = "pallet-evm-precompileset-assets-erc20" | ||
authors = { workspace = true } | ||
description = "A Precompile to expose Assets pallet through an ERC20-compliant interface." | ||
edition = "2021" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
paste = { workspace = true } | ||
|
||
# Moonbeam | ||
precompile-utils = { workspace = true } | ||
|
||
# Substrate | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
pallet-assets = { workspace = true } | ||
pallet-timestamp = { workspace = true } | ||
parity-scale-codec = { workspace = true, features = [ "max-encoded-len" ] } | ||
scale-info = { workspace = true, features = [ "derive" ] } | ||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
# Frontier | ||
fp-evm = { workspace = true } | ||
pallet-evm = { workspace = true, features = [ "forbid-evm-reentrancy" ] } | ||
|
||
[dev-dependencies] | ||
hex-literal = { workspace = true } | ||
libsecp256k1 = { workspace = true } | ||
sha3 = { workspace = true } | ||
|
||
# Moonbeam | ||
precompile-utils = { workspace = true, features = [ "std", "testing" ] } | ||
|
||
pallet-balances = { workspace = true, features = [ "insecure_zero_ed" ] } | ||
pallet-timestamp = { workspace = true, features = [ "std" ] } | ||
parity-scale-codec = { workspace = true, features = [ "max-encoded-len", "std" ] } | ||
scale-info = { workspace = true, features = [ "derive" ] } | ||
sp-runtime = { workspace = true, features = [ "std" ] } | ||
|
||
[features] | ||
default = [ "std" ] | ||
std = [ | ||
"fp-evm/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"pallet-assets/std", | ||
"pallet-balances/std", | ||
"pallet-evm/std", | ||
"pallet-timestamp/std", | ||
"parity-scale-codec/std", | ||
"precompile-utils/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.3; | ||
|
||
/// @author The Moonbeam Team | ||
/// @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. | ||
/// @custom:selector 06fdde03 | ||
function name() external view returns (string memory); | ||
|
||
/// @dev Returns the symbol of the token. | ||
/// @custom:selector 95d89b41 | ||
function symbol() external view returns (string memory); | ||
|
||
/// @dev Returns the decimals places of the token. | ||
/// @custom:selector 313ce567 | ||
function decimals() external view returns (uint8); | ||
|
||
/// @dev Total number of tokens in existence | ||
/// @custom:selector 18160ddd | ||
function totalSupply() external view returns (uint256); | ||
|
||
/// @dev Gets the balance of the specified address. | ||
/// @custom: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. | ||
/// @custom: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 | ||
/// @custom: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 | ||
/// @custom: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 | ||
/// @custom: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. | ||
/// @custom: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. | ||
/// @custom: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 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.3; | ||
|
||
/// @author The Moonbeam Team | ||
/// @title Extension of the ERC20 interface that allows users to | ||
/// sign permit messages to interact with contracts without needing to | ||
/// make a first approve transaction. | ||
interface Permit { | ||
/// @dev Consumes an approval permit. | ||
/// Anyone can call this function for a permit. | ||
/// @custom:selector d505accf | ||
/// @param owner Owner of the tokens issuing the permit | ||
/// @param spender Address whose allowance will be increased. | ||
/// @param value Allowed value. | ||
/// @param deadline Timestamp after which the permit will no longer be valid. | ||
/// @param v V component of the signature. | ||
/// @param r R component of the signature. | ||
/// @param s S component of the signature. | ||
function permit( | ||
address owner, | ||
address spender, | ||
uint256 value, | ||
uint256 deadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external; | ||
|
||
/// @dev Returns the current nonce for given owner. | ||
/// A permit must have this nonce to be consumed, which will | ||
/// increase the nonce by one. | ||
/// @custom:selector 7ecebe00 | ||
function nonces(address owner) external view returns (uint256); | ||
|
||
/// @dev Returns the EIP712 domain separator. It is used to avoid replay | ||
/// attacks accross assets or other similar EIP712 message structures. | ||
/// @custom:selector 3644e515 | ||
function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity >=0.8.3; | ||
|
||
/// @author The Moonbeam Team | ||
/// @title ERC20 interface Asset Roles | ||
/// @dev Extension of the ERC20 interface that allows users to get the account capable of fulfilling different asset roles | ||
/// @custom:address 0xFFFFFFFE + hex(assetId) | ||
interface Roles { | ||
/// @dev Function to check the owner of the asset | ||
/// @custom:selector 8da5cb5b | ||
/// @return the address of the owner. | ||
function owner() | ||
external | ||
view | ||
returns (address); | ||
|
||
/// @dev Function to check the freezer of the asset | ||
/// @dev Freezer: the account that can freeze an asset | ||
/// @custom:selector 92716054 | ||
/// @return the address of the freezer. | ||
function freezer() | ||
external | ||
view | ||
returns (address); | ||
|
||
/// @dev Function to check the issuer of the asset | ||
/// @dev Issuer: the account that can issue tokens for an asset | ||
/// @custom:selector 1d143848 | ||
/// @return the address of the issuer. | ||
function issuer() | ||
external | ||
view | ||
returns (address); | ||
|
||
/// @dev Function to check the admin of the asset | ||
/// @dev Admin: the account that can unfreeze and force transfer | ||
/// @custom:selector f851a440 | ||
/// @return the address of the admin. | ||
function admin() | ||
external | ||
view | ||
returns (address); | ||
} |
Oops, something went wrong.