Split, Merge and Redeem
The Router
contract is a wrapper around ConditionalTokens
contract, allowing users to split, merge and redeems outcome tokens using an ERC20 collateral token. Note that in order to call Router
functions, a prediction market (as well as its outcome tokens) must be created beforehand (see Create a market).
Split position
Step-by-step, the function will:
Transfer <amount> collateral from the user to
Router
.Call
conditionalTokens.splitPosition
to transfer <amount> collateral fromRouter
toConditionalTokens
, while minting corresponding ERC1155 outcome tokens toRouter
.Transfer outcome tokens from
Router
toWrapped1155Factory
contract. There is a callback function inWrapped1155Factory
that will wrap the ERC1155 tokens into ERC20 tokens, then transfer the wrapped tokens back to the original user.
Merge positions
Merging positions does precisely the opposite of what splitting a position does. First, it unwraps ERC20 outcome tokens (which will burn these tokens and transfer corresponding ERC1155 outcome tokens to the Router
contract). The function will then call conditionalTokens.mergePositions
to burn ERC1155 outcome tokens and return collateral to Router
. Finally, collateral will be sent to the user.
Redeem positions
A user can only redeem their positions after conditionalTokens.reportPayouts
has been called by an oracle. Router
will try to redeem based on the provided outcomeIndexes and amounts for collateral (or parent outcome tokens in conditional markets), then transfer back to the user.
Conditional markets
In the case of conditional markets, we will work with parent outcome tokens instead of collateral tokens.
When splitting a position, we will split from a parent position to deeper conditional positions. The opposite is true in the case of merging. For redeeming, you will redeem for parent outcome tokens instead of collateral. There will be an example in the later section.
GnosisRouter and MainnetRouter
GnosisRouter
is a Router
implementation to use on Gnosis chain, using Savings xDai as its collateral token. Users must have available xDai tokens to call splitFromBase
.
MainnetRouter
is similar to GnosisRouter
, but is used on Ethereum mainnet. Users must have available Dai tokens to call splitFromDai
.
Last updated