Overview
TheAssetOperations mixin provides core functionality for handling CTF (Conditional Token Framework) and collateral assets. It implements balance fetching, transfers, and CTF-specific operations like minting (splitting) and merging positions.
Source: src/exchange/mixins/AssetOperations.sol
Constants
parentCollectionId
Functions
_getBalance
Parameters
tokenId(uint256):0for collateral (ERC20) balance- Any other value for the ERC1155 CTF token balance
Returns
uint256: The token balance
_transfer
_transferCollateral or _transferCTF based on the token ID.
Parameters
from(address): The account to transfer assets fromto(address): The account to transfer assets toid(uint256):0for collateral (ERC20)- Any other value for CTF tokens (ERC1155)
value(uint256): The amount of assets to transfer
_transferCollateral
TransferHelper library. Uses either transfer or transferFrom depending on whether the from address is the contract itself.
Parameters
from(address): The account to transfer tokens fromto(address): The account to transfer tokens tovalue(uint256): The amount of ERC20 tokens to transfer
_transferCTF
TransferHelper library.
Parameters
from(address): The account to transfer tokens fromto(address): The account to transfer tokens toid(uint256): The ERC1155 token IDvalue(uint256): The amount of tokens to transfer
_mint
splitPosition on the CTF contract. This converts X units of collateral (ERC20) into X units of each complementary outcome token (ERC1155).
For binary outcomes, this creates equal amounts of both outcome tokens (e.g., YES and NO tokens).
Parameters
conditionId(bytes32): The ID of the condition to split onamount(uint256): The quantity of collateral to split (note: collateral and minted conditional tokens use the same number of decimals)
Implementation Details
- Uses
parentCollectionIdof zero (bytes32(0)) - Uses a binary partition [1, 2] for the two outcome tokens
- Calls
IConditionalTokens.splitPosition()on the CTF contract
Learn more about Gnosis Conditional Tokens in the official documentation.
_merge
mergePositions on the CTF contract. This converts X units of each complementary outcome token (ERC1155) into X units of collateral (ERC20).
For binary outcomes, this requires equal amounts of both outcome tokens (e.g., YES and NO tokens).
Parameters
conditionId(bytes32): The ID of the condition to merge onamount(uint256): The quantity of complete sets to burn for their underlying collateral
Implementation Details
- Uses
parentCollectionIdof zero (bytes32(0)) - Uses a binary partition [1, 2] for the two outcome tokens
- Calls
IConditionalTokens.mergePositions()on the CTF contract
Learn more about Gnosis Conditional Tokens in the official documentation.
Usage in Binary Matching
The_mint and _merge functions are critical for binary matching:
- Mint: When matching buy orders for complementary tokens (A and A’), the exchange mints a full set from collateral, then transfers token A to one buyer and token A’ to the other.
- Merge: When matching sell orders for complementary tokens (A and A’), the exchange receives both tokens from the sellers, merges them back into collateral, and pays out the sellers in collateral.