Epochs
Last updated
Last updated
The app has a "heartbeat". It aligns with a weekly or monthly cycle that contains a number of different phases (trade, intra-epoch, settlement & claim activation - see image below).
The Phases of the ERKO Monthly Epoch
The variable epoch-expiry
in the epoch-info
map holds the UNIX timestamp of the current epoch's expiry and acts as the contract's internal clock.
Here is how a monthly epoch plays out:
Phase 1: Trade
During the 72 block (~12 hours) registration-window
the trader
has the ability to register-trades
to an interested buyer. The price of the option is determined off-chain and passed to the core
contract by the trader.
Once a trade has been registered with the counterparty, the trader has 12 blocks (~2 hours) to confirm the trade by calling confirm-trade
which then transfers the BTC premium to the counterparty from the vault
contract. The options have a 1 week/month expiry (Fridays at 16:00 GMT) and the strike-call
, strike-put
, barrier-up
and barrier-down
are set by the trader by calling start-new-epoch
.
Phase 2: Intra-epoch
During this period users queue-deposit
which transfers their funds to the vault
contract, creates a claim
entry for their token
representing their deposit, and queues their funds for activation in the next epoch. Users who have already claimed their tokens can call queue-withdrawal
which transfers their tokens to the vault and creates a claim
entry for the underlying
funds representing the funds they are entitled to receive after the next epoch settles.
Users that have claims
corresponding to settled epochs can call the claim
function to receive their token
or underlying
funds.
Phase 3a: Settlement
Once the option has expired, the contract calculates the option's value (unit-pnl
). This value is either positive (in-the-money) or zero (out-of-the-money).
In-the-money scenario: If the option is in-the-money, the contract executes payment-requester
which writes amount-requested
to the counterparty-info
map. The counterparty then has 144 blocks (~24 hours) to call make-payment
and transfer the requested amount to the vault
contract.
Out-of-the-money scenario: If the option expires worthless, no settlement transactions are executed.
Phase 3b: Claim Activation
Intra-epoch deposits and withdrawals are kept separate from the vault's total-underlying-active
and are tracked in the total-pending-deposits
variable and the token
balance of the vault (total-pending-withdrawals
).
Independently from the value of the options, the core
contract will activate-pending-deposit/withdrawal-claims
and reserve the corresponding values of token
and underlying
for the outstanding claims.
The underlying-per-token
at the end of the epoch (after settle
) is stored in the epoch-info
map as underlying-per-token-settled
and serves as the reference rate when processing claims.
Please Note: Deposits and withdrawals send on-chain transfers immediately when requested by the user. But the claims corresponding to the intra-epoch deposits and withdrawals only become active at the end of every epoch.