Split, Merge and Redeem
Last updated
Last updated
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 ).
Step-by-step, the function will:
Transfer <amount> collateral from the user to Router
.
Call conditionalTokens.splitPosition
to transfer <amount> collateral from Router
to ConditionalTokens
, while minting corresponding ERC1155 outcome tokens to Router
.
Transfer outcome tokens from Router
to Wrapped1155Factory
contract. There is a callback function in Wrapped1155Factory
that will wrap the ERC1155 tokens into ERC20 tokens, then transfer the wrapped tokens back to the original user.
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.
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.
In the case of conditional markets, we will work with parent outcome tokens instead of collateral tokens.
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
.
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 .