datahaven/operator/precompiles/erc20-balances/Permit.sol
Ahmad Kaouk b5a6406470
feat: Add ERC20 Balances precompile (#150)
## Summary
- Introduces an ERC20-compatible precompile backed by `pallet_balances`,
including approvals and EIP-2612 permit.
- Wires the precompile into Mainnet, Testnet, and Stagenet at address
`0x0000000000000000000000000000000000000802` (u64: 2050).
- Adds comprehensive unit tests and a mock runtime.

## Motivation
- Allow EVM contracts and tooling to interact with Substrate balances
via a familiar ERC20 interface.
- Support off-chain approvals via EIP-2612 for gasless approvals and
improved UX.

## Key Changes
- New crate: `operator/precompiles/erc20-balances`
  - Core logic: `src/lib.rs`
  - EIP-2612 helpers and validation: `src/eip2612.rs`
  - Tests + mock runtime: `src/tests.rs`, `src/mock.rs`
- Runtime wiring (all networks): add `Erc20BalancesPrecompile` at
`AddressU64<2050>`
  - `operator/runtime/{mainnet,stagenet,testnet}/src/precompiles.rs`
- Workspace plumbing: include `pallet-evm-precompile-balances-erc20` in
`operator/Cargo.toml`

## Interface
- ERC20: `totalSupply`, `balanceOf`, `allowance`, `approve`, `transfer`,
`transferFrom`, `name`, `symbol`, `decimals`
- Native-only flows: `deposit()` (fallback/payable) and
`withdraw(uint256)`
- EIP-2612: `permit(owner,spender,value,deadline,v,r,s)`,
`nonces(owner)`, `DOMAIN_SEPARATOR()`
- Events: `Transfer`, `Approval`, `Deposit`, `Withdrawal`
- Storage:
- Approvals via `ApprovesStorage` (double map: owner → spender → amount)
  - EIP-2612 nonces via `NoncesStorage` keyed by `H160`
- Instance-aware prefixes to support multiple `pallet_balances`
instances
2025-09-12 08:57:44 +00:00

39 lines
No EOL
1.5 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.3;
/// @author The DataHaven Team
/// @title Extension of the ERC20 interface that allows users to
/// @dev 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);
}