Skip to content

TRADE-Stable Token Smart Contract (ERC-20) ​

Overview ​

The TRADE-S is an ERC-20 token implementation using OpenZeppelin's ERC20PresetMinterPauser preset, deployed on the public EVM network. It serves as the collateral token for the SecureTrade platform, provided by the platform admin to users' Clearing Accounts. These tokens are used as collateral backing for PayPledges and are locked in individual user Collateral Vaults.

This contract interacts with:

  • Platform Admin, who mints TRADE-S tokens to users' Clearing Accounts.
  • Buyers, who receive TRADE-S tokens in their Clearing Account and deposit them into their Collateral Vaults.
  • Treasury Service, which monitors Collateral Vault deposits/withdrawals and triggers TRADE-P operations on the private network.
  • Collateral Vault contract, which holds TRADE-S tokens in individual user vaults.

Key Functionalities ​

1. ERC-20 Compliance ​

  • Standard ERC-20 token implementation with full compliance features.
  • Supports standard ERC-20 functions (transfer, approve, transferFrom).
  • Includes additional features from ERC20PresetMinterPauser.

2. Minting and Distribution ​

  • Platform Admin can mint TRADE-S tokens to users' Clearing Accounts.
  • Tokens are distributed to users as collateral backing for PayPledge operations.
  • Total supply is controlled by the Platform Admin.

3. Pausable Functionality ​

  • Platform Admin can pause token transfers in emergency situations.
  • Provides additional security and control over token operations.

4. Role-Based Access Control ​

  • Implements role-based access control for minting, pausing, and administrative functions.
  • Ensures only authorized parties can perform critical operations.

5. Token Metadata ​

  • Maintains metadata: Name "Trade Stable", symbol "TRADE-S", and decimals: 18.

Roles ​

  • Platform Admin (DEFAULT_ADMIN_ROLE): Has full administrative control over the contract.
  • Minter (MINTER_ROLE): Can mint new TRADE-S tokens to user addresses.
  • Pauser (PAUSER_ROLE): Can pause and unpause token transfers.
  • Buyers: Receive TRADE-S tokens in Clearing Account and deposit them into Collateral Vaults.
  • Treasury Service: Monitors Collateral Vault operations for cross-chain token bridging.

Events ​

Standard ERC-20 Events ​

  • Transfer(address indexed from, address indexed to, uint256 value): Emitted when tokens are transferred.
  • Approval(address indexed owner, address indexed spender, uint256 value): Emitted when spending allowance is set.

Additional Events from ERC20PresetMinterPauser ​

  • RoleGranted(bytes32 indexed role, address indexed account, address indexed sender): Emitted when a role is granted.
  • RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender): Emitted when a role is revoked.
  • Paused(address account): Emitted when the contract is paused.
  • Unpaused(address account): Emitted when the contract is unpaused.

Contract Structure ​

State Variables ​

  • string public name: "Trade Stable"
  • string public symbol: "TRADE-S"
  • uint8 public decimals: 18
  • uint256 public totalSupply: Total TRADE-S tokens
  • mapping(address => uint256) public balanceOf: Token balances
  • mapping(address => mapping(address => uint256)) public allowance: Spender allowances
  • bool public paused: Pause state of the contract

Roles ​

  • bytes32 public constant DEFAULT_ADMIN_ROLE: Administrative role
  • bytes32 public constant MINTER_ROLE: Minting role
  • bytes32 public constant PAUSER_ROLE: Pausing role

Functions ​

Standard ERC-20 Functions ​

  • transfer(address to, uint256 amount) external returns (bool): Transfers tokens to another address.
  • approve(address spender, uint256 amount) external returns (bool): Approves spending allowance.
  • transferFrom(address from, address to, uint256 amount) external returns (bool): Transfers tokens via allowance.

Minting Functions ​

  • mint(address to, uint256 amount): Mints new TRADE-S tokens to the specified address. Only callable by addresses with MINTER_ROLE.

Pausing Functions ​

  • pause(): Pauses all token transfers. Only callable by addresses with PAUSER_ROLE.
  • unpause(): Unpauses token transfers. Only callable by addresses with PAUSER_ROLE.

Role Management Functions ​

  • grantRole(bytes32 role, address account): Grants a role to an account. Only callable by addresses with DEFAULT_ADMIN_ROLE.
  • revokeRole(bytes32 role, address account): Revokes a role from an account. Only callable by addresses with DEFAULT_ADMIN_ROLE.
  • hasRole(bytes32 role, address account) external view returns (bool): Checks if an account has a specific role.

View Functions ​

  • name() external view returns (string memory): Returns the token name.
  • symbol() external view returns (string memory): Returns the token symbol.
  • decimals() external view returns (uint8): Returns the token decimals.
  • totalSupply() external view returns (uint256): Returns the total token supply.
  • balanceOf(address account) external view returns (uint256): Returns the balance of an account.
  • allowance(address owner, address spender) external view returns (uint256): Returns the allowance of a spender.

Security Considerations ​

  • Access Control: Role-based access control ensures only authorized parties can mint, pause, or perform administrative functions.
  • Pausable Functionality: Emergency pause mechanism provides additional security in case of critical issues.
  • Standard Compliance: Full ERC-20 compliance ensures compatibility with wallets, exchanges, and other DeFi protocols.
  • Reentrancy Protection: Built-in protection against reentrancy attacks through OpenZeppelin's secure implementations.

Dependencies ​

  • OpenZeppelin Contracts v4.9.6:
    • ERC20PresetMinterPauser: Main contract implementation
    • AccessControl: Role-based access control
    • ERC20: Standard ERC-20 token functionality
    • ERC20Pausable: Pausable token functionality
    • ERC20Burnable: Burnable token functionality

Deployment ​

  • Network: Public EVM network
  • Implementation: Uses OpenZeppelin's ERC20PresetMinterPauser preset
  • Initial Setup:
    • Deployer automatically receives DEFAULT_ADMIN_ROLE
    • Deployer can grant MINTER_ROLE and PAUSER_ROLE to appropriate addresses
    • Initial supply is 0 (tokens are minted as needed by Platform Admin)

Usage Flow ​

  1. Token Distribution: Platform Admin mints TRADE-S tokens to users' Clearing Accounts
  2. Collateral Deposit: Users deposit TRADE-S tokens from Clearing Account to their Collateral Vault
  3. TRADE-P Supply Management: Treasury Service monitors Collateral Vault deposits and triggers TRADE-P minting on private network
  4. PayPledge Operations: TRADE-P tokens are used for PayPledge Credit and Escrow operations on private network
  5. Settlement: When PayPledges settle, TRADE-P tokens are burned and TRADE-S tokens are released from Collateral Vaults