Comment on page
How the FP Contract works
This contract assumes there is a working oracle service and an oracle contract which commits on a data set of
<asset, value>pairs on different times.
The Fixed Payout contract can issue Bull and Bear positions on one of the tickers on which the oracle commits for a future event, and provides the winner with the collateral payed by the issuer.
First - the issuer issues position tokens for both positions, derived from the public key of the oracle service, the contract ID of the oracle contract, the name of the forex ticker, the time frame in which the event will take place, the price on which the positions diverge, and the position name.
The contract issues two position tokens, according to the possible positions:
- 1.Bull - which believes the price will be above or equal to the specified price during the specified time frame.
- 2.Bear - which believes the price will be below the specified price during the specified time frame.
Both of the tokens (issued by the same amount as the collateral) are sent to the issuer at the time of the issuing.
The issuer will hold the position they believe in and sell the other tokens, the buyers will hold the opposite position, then they will both wait until the event date will occur.
Once the event for which the position was issued has occurred, and the oracle has committed on the event data, the rightful redeemers must ask the oracle service to provide the proof data (which contains the timestamp, the value of the asset at the time of the commitment, the root of the Merkle tree of the committed data set, the audit path of the
<asset, value>pair within the Merkle tree, the index of the
<asset, value>within the leaves array of the Merkle tree, and the parameters of the Merkle tree), and the oracle contract has to attest for the global proof data (the timestamp, the root of the Merkle tree, and the oracle service public key), which would send the Fixed Payout contract an attestation token which will give the redeemer the right for the collateral when found in the wallet of the Fixed Payout contract, since the attestation token is the embodiment of the attestation of the oracle on the occurrence and details of the event.
If the specified redemption data fits both the given attestation token (which guarantees the occurrence of the event) and the position of the given position token (which guarantees the right of the redeemer for the collateral) - the contract will send the redeemer a portion of the collateral equal to the number of winning position tokens provided.
The Fixed Payout contract accepts 3 commands:
To issue new position tokens - execute the contract with the
"Issue"command while providing it with a dictionary in the message body which contains the following data:
The contract will lock to itself all the collateral tokens (of the asset defined in the
"Collateral"field in the message body) which were provided to it in the TX by the issuer, and will mint and lock to the issuer the same amount of position tokens of both kinds (so if the issuer supplies the contract with
mcollateral tokens - the contract will mint and lock to the issuer
mBear tokens and
mBull tokens based on the event).
Diagrammatically it looks like this:
To redeem a position token - execute the contract with the
"Redeem"command while providing it with a dictionary in the message body which contains the following data:
You'll have to ensure the Fixed Payout contract has an attestation token from the oracle contract specified in
"OracleContractId"which commits to the data specified in
You'll also have to provide the contract with the position tokens according to the position specified in
"Position"- to redeem a Bull position provide the contract with Bull tokens, and make sure the attested value is above the price specified in
"Price"or equal to it; to redeem a Bear position provide the contract with Bear tokens, and make sure the attested value is below the price specified in
For both positions you'll also have to make sure that all of the following conditions hold:
- 1.The specified
"Timestamp"is within the time bounds specified in
- 2.The specified
"AuditPath"is valid for the Merkle root specified in
"Root"for the leaf given by the
"Ticker"key with the specified
"Value"in the specified
- 3.The data hashed in the position tokens is according to the specified
When all of the conditions hold (including the conditions which are specific for the position) the contract will destroy the provided tokens and will lock to the redeemer collateral tokens of the same amount as the provided position tokens of the specified position.
Diagrammatically it looks like this:
The only way for the resulting transaction to be valid is if:
[[event data ; position]]
To cancel some or all of the issued position tokens you execute the contract with the
"Cancel"command and send the contract an equal amount of both position tokens, the same amount of collateral will be sent back to you and the given position tokens will be destroyed.
You'll also need to put in the message body the exact same data that was given at the issuance of the given tokens.
As you can see this is the exact dual situation to the
If the time frame is too narrow there's a chance the oracle will not commit on the event during that time frame; if the time frame is too wide there's a chance the oracle will commit and attest for both the Bull and the Bear positions, so the collateral will go to whoever redeems it first ("the early bird gets the worm").
Generated by the Oracle contract.
[[[ [[ root ; timestamp ]] ; oraclePublicKey ]]]
Generated by the Fixed Payout contract.
[[ oracleContractId ; ticker ; price ; start ; expiry ; collateral ; position ]]