Settling by token price

The following is an example of a settlement contract which determines the outcome of an Ante based on an asset price fetched from a Chainlink oracle.

The settle function takes some data that is decoded to a Chainlink oracle address (can be found herearrow-up-right) and a price threshold. You need to make sure the threshold value takes into account the asset decimals.

 function settle(bytes memory data) external view returns (WinningSide) {
        (address feedAddr, int priceThreshold) = abi.decode(data, (address, int));

This data value passed as a parameter when you create the Ante. This value doesn't get changed after creation and the AnteMetaPool smart contract will use it to call the settlement contract when the time comes.

// Extracted from AnteMetaPool.settle function
address settler = commitment.settler;
bytes memory settlerData = commitment.settlerData;
...
ParticipantSide winningSide = ParticipantSide(uint8(IAnteSettlement(settler).settle(settlerData)));

If the fetched price is equal to the set threshold, the Ante will be marked as having no winner. At this point both parties can withdraw their initial stake.

If the fetched price is greater than the set threshold, A side is considered the winner.

If the fetched price is less than the set threshold, B side is considered the winner.

if (price == priceThreshold) {
    return WinningSide.NONE;
} else if (price > priceThreshold) {
    return WinningSide.A;
} else {
    return WinningSide.B;
}

IMPORTANT! If you are the Ante author, you will automatically be assigned to side A. In order to stake behind a claim saying that an asset will be under a threshold, you will have to update the condition block accordingly.

link to repo

Full contract code

Last updated