Appearance
Solidity API
TradeToken
This contract is based on OpenZeppelin's ERC20 implementation and includes security features like ownership and reentrancy protection.
_Implements an advanced and customizable ERC20 token with wrapping and unwrapping capabilities, wrap ratios and secure transfer handling.
The contract supports two types of tokens:
- Mintable: New tokens can be created by the owner
- Wrappable: Tokens that can be wrapped into other TradeToken
Security features:
- Reentrancy protection on all state-modifying functions
- Ownership controls for sensitive operations
- Transfer acceptance checks for contract recipients
- Twin contract verification for wrapping operations_
TradeTokenType
Defines the type of TradeToken
solidity
enum TradeTokenType {
Mintable,
Wrappable
}
tradeTokenType
solidity
enum TradeToken.TradeTokenType tradeTokenType
The type of this TradeToken instance
attachments
solidity
mapping(string => address) attachments
Mapping to track IPFS Content Identifiers (CIDs) and their submitters Maps CID strings to the address that submitted them
AttachmentAdded
solidity
event AttachmentAdded(string cid, address submitter)
Emitted when a new attachment is added to the contract
Parameters
Name | Type | Description |
---|---|---|
cid | string | IPFS Content Identifier of the attachment |
submitter | address | Address that submitted the attachment |
WrapRatioAdded
solidity
event WrapRatioAdded(address childTradeTokenAddress, uint256 ratio)
Emitted when a new wrap ratio is added for a child Trade Token
Parameters
Name | Type | Description |
---|---|---|
childTradeTokenAddress | address | Address of the child Trade Token |
ratio | uint256 | The wrap ratio scaled by 10^18 |
WrapRatioReceived
solidity
event WrapRatioReceived(address tradeTokenAddress, uint256 ratio)
Emitted when a wrap ratio is received from another Trade Token
Parameters
Name | Type | Description |
---|---|---|
tradeTokenAddress | address | Address of the Trade Token setting the ratio |
ratio | uint256 | The received wrap ratio |
TradeTokenMintingNotAllowed
solidity
error TradeTokenMintingNotAllowed()
TradeTokenUnauthorizedTradeTokenOwner
solidity
error TradeTokenUnauthorizedTradeTokenOwner()
TradeTokenInvalidTwinContract
solidity
error TradeTokenInvalidTwinContract(address target)
TradeTokenWrapRatioNotRegistered
solidity
error TradeTokenWrapRatioNotRegistered(address target)
TradeTokenWrapRatioAlreadyExists
solidity
error TradeTokenWrapRatioAlreadyExists(address target)
TradeTokenInsufficientBalanceForWrap
solidity
error TradeTokenInsufficientBalanceForWrap(uint256 available, uint256 required)
TradeTokenTransferFailed
solidity
error TradeTokenTransferFailed(address to, uint256 value)
TradeTokenAttachmentAlreadyAdded
solidity
error TradeTokenAttachmentAlreadyAdded(string cid)
TradeTokenNonZeroInitialSupplyForWrappable
solidity
error TradeTokenNonZeroInitialSupplyForWrappable()
constructor
solidity
constructor(address _initialOwner, string _tokenName, string _tokenSymbol, uint256 _initialSupply, enum TradeToken.TradeTokenType _tradeTokenType) public
Sets up the Trade Token with initial parameters
Parameters
Name | Type | Description |
---|---|---|
_initialOwner | address | Address of the initial owner |
_tokenName | string | Name of the token |
_tokenSymbol | string | Symbol of the token |
_initialSupply | uint256 | Initial supply to mint |
_tradeTokenType | enum TradeToken.TradeTokenType | Type of the Trade Token (Mintable or Wrappable) |
mint
solidity
function mint(address _account, uint256 _value) external
Creates new tokens and assigns them to the specified account
Parameters
Name | Type | Description |
---|---|---|
_account | address | Address to receive the minted tokens |
_value | uint256 | Amount of tokens to mint Requirements: - Caller must be the contract owner - Token must be of Mintable type |
burn
solidity
function burn(uint256 _value) external
Burns sender's owned tokens
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | Amount of tokens to be burnt Requirements: - Caller must own atleast value amount of tokens |
wrap
solidity
function wrap(uint256 _value, address _wrapperTradeToken, address _to) external
Wraps tokens into another TradeToken at the predefined ratio
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | Amount of tokens to wrap |
_wrapperTradeToken | address | Address of the target TradeToken to wrap into |
_to | address | Address to receive the wrapped tokens Requirements: - Wrap ratio must be registered for the target TradeToken - Caller must have sufficient balance - Contract must not be reentrant |
unwrap
solidity
function unwrap(uint256 _value, address _wrappedTradeToken, address _to) external
Unwraps tokens back to their original form
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | Amount of wrapped tokens to unwrap |
_wrappedTradeToken | address | Address of the TradeToken containing the original tokens |
_to | address | Address to receive the unwrapped tokens Requirements: - Caller must be the contract owner - Wrap ratio must be registered - Contract must not be reentrant |
onReceiveWrappedTokens
solidity
function onReceiveWrappedTokens(uint256 _value, address _to) external
Callback function for receiving wrapped tokens
Parameters
Name | Type | Description |
---|---|---|
_value | uint256 | Amount of tokens to mint |
_to | address | Address to receive the minted tokens Requirements: - Caller must be a verified twin contract - The call must not be reentrant |
setWrapRatio
solidity
function setWrapRatio(address _childTradeTokenAddress, uint256 _ratio) external
Sets the wrap ratio for a child TradeToken
Parameters
Name | Type | Description |
---|---|---|
_childTradeTokenAddress | address | Address of the child TradeToken |
_ratio | uint256 | Wrap ratio scaled by 10^18 Requirements: - Child TradeToken must be a verified twin contract - Caller must be the owner of the child TradeToken - Contract must not be reentrant - Wrap ratio must not already be set for the child TradeToken |
getWrapRatio
solidity
function getWrapRatio(address _tradeTokenAddress) external view returns (uint256)
Returns the wrap ratio for a given TradeToken address
Parameters
Name | Type | Description |
---|---|---|
_tradeTokenAddress | address | Address of the TradeToken to query |
Return Values
Name | Type | Description |
---|---|---|
[0] | uint256 | The wrap ratio scaled by 10^18 |
onReceiveWrapRatio
solidity
function onReceiveWrapRatio(uint256 _ratio) external
Callback function when receiving a wrap ratio from another TradeToken
Parameters
Name | Type | Description |
---|---|---|
_ratio | uint256 | The received wrap ratio Requirements: - Caller must be another TradeToken contract with the same deployed bytecode |
transfer
solidity
function transfer(address _to, uint256 _value) public virtual returns (bool)
Overrides ERC20 transfer function with additional security checks
Parameters
Name | Type | Description |
---|---|---|
_to | address | Address to transfer tokens to |
_value | uint256 | Amount of tokens to transfer |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | bool indicating success Requirements: - Contract must not be reentrant - Recipient contract must properly implement onReceiveERC20 if it's a contract |
transferFrom
solidity
function transferFrom(address _from, address _to, uint256 _value) public virtual returns (bool)
Overrides ERC20 transferFrom function with additional security checks
Parameters
Name | Type | Description |
---|---|---|
_from | address | Address to transfer tokens from |
_to | address | Address to transfer tokens to |
_value | uint256 | Amount of tokens to transfer |
Return Values
Name | Type | Description |
---|---|---|
[0] | bool | bool indicating success Requirements: - Contract must not be reentrant - Recipient contract must properly implement onReceiveERC20 if it's a contract |
addAttachment
solidity
function addAttachment(string _cid) external
Adds a new IPFS attachment to the contract
Parameters
Name | Type | Description |
---|---|---|
_cid | string | IPFS Content Identifier for the attachment Requirements: - Caller must be the contract owner - CID must not already be registered |
_verifyTwinContractBytecode
solidity
function _verifyTwinContractBytecode(address _target) internal view
Verifies that the target contract has identical bytecode
Parameters
Name | Type | Description |
---|---|---|
_target | address | Address of the contract to verify |