State Transitions
This document describes the state transition operations pertaining to:
- Creating an insurance fund
- Underwriting an insurance fund
- Request a redemption from the insurance fund
- Automatic processing of matured redemption requests
Creating insurance fund
Params description
Sender field describes the creator of an insurance fund .
Ticker, QuoteDenom, OracleBase, OracleQuote, OracleType, Expiry fields describe the derivative market info
that the insurance fund associated to.
InitialDeposit field describes the initial deposit amount to be put on the insurance fund.
Steps
- Get
MarketIdfor the insurance fund - Note, market could be not available yet onexchangeand it's not an issue - Ensure if insurance fund associated to the
MarketIddoes not exist - Ensure if initial deposit amount is not zero
- Get
shareDenomthat is unique - it's incremented when share denom is requested for insurance fund creation or when underwriting insurance fund that has zero balance and non-zero total share denom supply. - Send coins from creator's account to insurance fund module account
- Create insurance fund object with
DefaultRedemptionNoticePeriodDurationand with the params provided - Set
Balanceof fund object to initial deposit amount - Mint
InsuranceFundInitialSupply(10^18)shareDenomtokens to creator account - Save insurance fund object to store
- Register newly created insurance fund
shareDenommetadata inside BankKeeper
Underwriting an insurance fund
Params description
Sender field describes the underwriter of an insurance fund .
MarketId field describes the derivative market id to the insurance fund.
Deposit field describes the deposit amount to be added on the insurance fund.
Steps
- Ensure if insurance fund associated to the
MarketIddoes exist - Send underwriting tokens from sender's account to module account
- Make actions based on the status of insurance fund associated to the
MarketId.- A. when
BalanceandShareDenomSupplyare zero- mint
InsuranceFundInitialSupply(10^18) to the sender. - set
Balanceto deposit amount - set
ShareDenomSupplytoInsuranceFundInitialSupply
- mint
- B. when
Balanceis zero andShareDenomSupplyis not zero- change
ShareDenomof the the insurance fund to start new insurance fund from beginning. - register newly created
ShareDenomin bank keeper - mint
InsuranceFundInitialSupply(10^18) to the sender. - set
Balanceto deposit amount - set
ShareDenomSupplytoInsuranceFundInitialSupply
- change
- C. when
Balanceis not zero andShareDenomSupplyis zero- mint
InsuranceFundInitialSupply(10^18) to the sender. - increase
Balanceby deposit amount - set
ShareDenomSupplytoInsuranceFundInitialSupply
- mint
- D. when both
BalanceandShareDenomSupplyare not zero - normal case- increase
Balanceby deposit amount - mint
prev_ShareDenomSupply * deposit_amount / prev_Balanceamount ofShareDenomto sender - increase
ShareDenomSupplywith mint amount
- increase
- A. when
- Save insurance fund object to store
Requesting a redemption from an insurance fund
Params description
Sender field describes the redemption requester of an insurance fund .
MarketId field describes the derivative market id associated to the insurance fund.
Amount field describes the share token amount to be redeemed.
Steps
- Ensure insurance fund associated to the
MarketIddoes exist - Send
ShareDenomto module account - Get new redemption schedule ID
- Calculate
ClaimTimefrom insurance fund's redemption notice period duration and current block time - Calculate key to store pending redemption (redemption schedule)
- Create redemption schedule object with details
- Store redemption schedule object to store
Insurance fund actions on liquidation events in derivative market
Steps
exchangemodule finds relative insurance fund from the insurance keeper.- if
missingFundis positive, it withdraws the amount from the insurance fund throughWithdrawFromInsuranceFund. - if
missingFundis negative, it deposits the amount into the insurance fund throughDepositIntoInsuranceFund.
Automatic processing of pending redemptions
Steps
Iterate all matured redemptions by sorted order by ClaimTime and perform the following actions:
- If
ClaimTimeis after current block time, break early - Ensure the insurance fund exist for matured redemption schedule
- Calculate redeem amount from share amount -
shareAmt * fund.Balance * fund.TotalShare - Send calculate redeem amount from module account to redeemer account
- Burn share tokens sent to the module account at the time of redemption schedule
- Delete redemption schedule object
- Reduce insurance fund's
Balanceby redeem amount - Store updated insurance object to store
Hooks
Other modules may register operations to execute when a certain event has occurred within insurance fund. These events
can be registered to execute either right Before or After the exchange event (as per the hook name). The following
hooks can registered with the exchange:
Note: Hooks are not available and exchange module calls insurance keeper function directly.
Steps When liquidation event happen in derivative market
exchangemodule finds relative insurance fund from the insurance keeper.- if
missingFundis positive, it withdraws the amount from the insurance fund throughWithdrawFromInsuranceFund. - if
missingFundis negative, it deposits the amount into the insurance fund throughDepositIntoInsuranceFund.