Skip to main content
The FutarchyRouter contract replicates the main Conditional Tokens functions, but allowing to work with ERC20 outcomes instead of the ERC1155.

Variables

conditionalTokens

Conditional Tokens contract.

wrapped1155Factory

Wrapped1155Factory contract.

Functions

constructor

Constructor. Parameters

splitPosition

Transfers the collateral to the FutarchyRouter, splits the position and sends the ERC20 outcome tokens back to the user. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory. Collateral tokens are deposited only if we are not splitting a deep position (proposal.parentCollectionId is bytes32(0)). Parameters Pre-condition
  1. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory.
  2. The caller must have <amount> collateral tokens or ERC20 parent outcome tokens (in the case proposal.parentCollectionId is not null).
Logic When proposal.parentCollectionId is null:
  1. Transfer <amount> collateral from the user to FutarchyRouter.
  2. Call conditionalTokens.splitPosition to transfer <amount> collateral from FutarchyRouterto ConditionalTokens, while minting corresponding ERC1155 outcome tokens to FutarchyRouter.
When proposal.parentCollectionId is not null:
  1. Unwrap ERC20 parent outcome tokens back to ERC1155 tokens.
  2. Call conditionalTokens.splitPosition to transfer ERC1155 parent outcome tokens from FutarchyRouterto ConditionalTokens, burning them while minting corresponding conditional outcome tokens to FutarchyRouter.
Step 3 is the same in both cases:
  1. Transfer ERC1155 outcome tokens from FutarchyRouter to Wrapped1155Factory contract. There is a callback function in Wrapped1155Factory that will wrap the tokens into ERC20 tokens, then transfer the wrapped tokens back to the original user.

_splitPosition

Splits a position and sends the ERC20 outcome tokens to the user. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory. Parameters

mergePositions

Merges positions and sends the collateral tokens to the user. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory. Collateral tokens are withdrawn only if we are not merging a deep position (market.parentCollectionId is bytes32(0)). Parameters Pre-condition
  1. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory.
  2. The caller must have <amount> ERC20 tokens of all the outcomes of a proposal.
Logic Merging positions does precisely the opposite of what splitting a position does.
  1. Unwraps ERC20 outcome tokens (which will burn these tokens and transfer corresponding ERC1155 outcome tokens back to the FutarchyRouter contract).
  2. Call conditionalTokens.mergePositions to burn ERC1155 outcome tokens. Then:
When market.parentCollectionId is null:
  1. Return collateral to FutarchyRouter , which will then be sent to the user.
When proposal.parentCollectionId is not null:
  1. conditionalTokens will mint ERC1155 parent outcome tokens and send to FutarchyRouter . FutarchyRouter will wrap these tokens to ERC20 and send to the user.

_mergePositions

Merges positions and receives the collateral tokens. Callers to this function must send the collateral to the user. Parameters

redeemPositions

Redeems positions and sends the collateral tokens to the user. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory. Collateral tokens are withdrawn only if we are not redeeming a deep position (parentCollectionId is bytes32(0)). Parameters Pre-condition
  1. The ERC20 associated to each outcome must be previously created on the wrapped1155Factory.
  2. The caller must have ERC20 tokens of the outcome they want to redeem.
  3. conditionalTokens.reportPayouts has been called by an oracle.
Logic
  1. Unwraps ERC20 outcome tokens (which will burn these tokens and transfer corresponding ERC1155 outcome tokens back to the Router contract).
  2. Call conditionalTokens.redeemPositions to burn ERC1155 outcome tokens. Then:
When proposal.parentCollectionId is null:
  1. Return collateral to FutarchyRouter . The return amount is in proportion to the ConditionalTokens payouts. FutarchyRouter will calculate the collateral difference before and after redeeming and transfer the difference to the user.
When proposal.parentCollectionId is not null:
  1. conditionalTokens will mint ERC1155 parent outcome tokens and send to FutarchyRouter . The amount is in proportion to the ConditionalTokens payouts. FutarchyRouter will calculate the ERC1155 outcome tokens difference before and after redeeming, wrap the difference to ERC20 and send to the user.

_redeemPositions

Redeems positions and sends the collateral tokens to the user. Callers to this function must send the collateral to the user. Parameters

redeemProposal

Redeems positions and receives the collateral tokens. It’s a wrapper around redeemPositions that allows to redeem one or two collateral at the same time. Parameters

getTokenId

Constructs a tokenId from a collateral token and an outcome collection. Parameters Return Values

getWinningOutcomes

Helper function used to know the redeemable outcomes associated to a conditionId. Parameters Return Values