Gnosis Developer Portal Conditional Tokens

Gnosis Developer Portal Conditional Tokens

  • Introduction
  • Use Case
  • Documentation
  • Tutorials
  • Support

›How to set up a prediction market in 30min

How to set up a prediction market in 30min

  • Introduction
  • Prediction Market use case
  • Setting up the development environment
  • Preparing a condition
  • Tying in the market maker
  • Enabling trading
  • Resolving the market
  • Redeeming positions

Redeeming positions

Before redeeming your positions in the market is possible, the oracle must report the correct answer to the contract.

In the ConditionalTokensRepo.ts file it is defined the function that calls the contract to redeem the positions of the trader:

redeemPositions = async (
  collateralAddress: string,
  parentCollectionId: string,
  marketConditionId: string,
  indexSets: number[],
  from: string,
) => {
  return this.conditionalTokens.redeemPositions(
    collateralAddress,
    parentCollectionId,
    marketConditionId,
    indexSets,
    { from },
  )
}

The function redeemPositions is defined in the ConditionalTokens contract and it has two parameters:

function redeemPositions(IERC20 collateralToken, bytes32 parentCollectionId, bytes32 conditionId, uint[] calldata indexSets) external
  • collateralToken: ERC20 token which exists on the same chain as the ConditionalTokens instance and is used as collateral to back positions.
  • parentCollectionId: Collection ID of the parent outcome collection, or bytes32(0) if there's no parent.
  • conditionId: It may be derived from other parameters via keccak256(abi.encodePacked(oracle, questionId, outcomeSlotCount)).
  • indexSets: Is a bit array where the 0th index corresponds with the 0th outcome slot and also whether or not the 1st place (1 << 0) is set in the value of indexSets. Similarly, the 1st index corresponds with the 1st outcome slot and is whether or not the 2nd place (1 << 1) is set. It is supposed to represent a "union" of outcome slots. So like a value of 3 (0b11) would represent a position that pays out when either outcome slots [0] or [1] occur.

If the function succeeds, the following event will be emitted.

event PayoutRedemption(
  address indexed redeemer,
  IERC20 indexed collateralToken,
  bytes32 indexed parentCollectionId,
  bytes32 conditionId,
  uint[] indexSets,
  uint payout
);

The function to redeem positions is defined in Market.ts:

const redeem = async () => {
  const collateral = await marketMakersRepo.getCollateralToken()

  const indexSets = Array.from({ length: marketInfo.outcomes.length }, (v, i) =>
    i === 0 ? 1 : parseInt(Math.pow(10, i).toString(), 2),
  )

  const tx = await conditionalTokensRepo.redeemPositions(
    collateral.address,
    `0x${'0'.repeat(64)}`,
    marketInfo.conditionId,
    indexSets,
    account,
  )
}
← Resolving the market
Gnosis Ltd.
ImprintCopyright
© 2020 Gnosis LTD
Privacy Policy
Copyright © 2025 Gnosis LTD