Vaults
Vaults can be used to deposit and mint tokens without participating in the debt pool.
#
Structure of VaultData describing a vault is stored inside a Vault struct. Its address is generated from addresses of tokens it uses. It is structured as following:
- halted - vault can be halted independently of rest of exchange (but halt of exchange affects it too)
- synthetic - address of the synthetic token
- collateral - address of the token used as collateral
- debt_interest_rate - yearly interest rate (charged minutely)
- collateral_ratio - ratio of collateral to synthetic token that can be borrowed using it
- liquidation_threshold - ratio of debt to the value of collateral defining when an account can be liquidated
- liquidation_ratio - maximum percentage of user's collateral that can be liquidated at once
- liquidation_penalty_liquidator - percentage of additional collateral going to a liquidator
- liquidation_penalty_exchange - percentage of liquidation that goes to liquidation fund as a penalty
- accumulated_interest - interest rate of minted tokens. Can be withdrawn by admin
- accumulated_interest_rate - compounded interest rate. Can be used instead of compounding amount by the interest rate for every user
- collateral_reserve - address of the account to which tokens are deposited (different than reserve for deposit to staking)
- mint_amount - the amount already minted (both amount borrowed and interest)
- collateral_amount - the amount of deposited collateral in reserve
- max_borrow - limit of total synthetic that can be borrowed
- last_update - timestamp since the last update of interest rate
- bump - seed used to ensure the generated address doesn't collide with any other existing one
#
Vault entryVault entry is created for every user using a vault and it stores data for it.
- owner - pubkey belonging to the owner of an entry
- vault - address of vault which is used
- last_accumulated_interest_rate - the value of accumulated_interest_rate when it was last charged to the user
- synthetic_amount - the amount of minted synthetic, is increased by interest rate
- collateral_amount - the amount of deposited collateral token
- bump - seed used to ensure the generated address doesn't collide with any other existing one
#
Creation of Vault EntryVault entry is created here, takes bump (u8) and a following context:
- state - account with data of the program
- vault_entry - user account in vault
- owner - pubkey belonging to the owner of the account
- vault - vault for which entry is created
- assets_list - list of assets, structured like this
- synthetic - address of synthetic token used as a seed for entry
- collateral - address of collateral token also used as seed
- rent - a data structure relating to rent, needed to create an account
- system_program - Solana's System Program needed to create an account
#
DepositMethod depositing tokens is defined here, takes amount (u64) and a context structured like this:
- state - account with data of the program
- vault_entry - user account in vault
- vault - account storing data for particular pair
- synthetic - address of asset used as synthetic in the used vault
- collateral - address of the deposited token
- reserve_address - address of the account to which tokens are deposited (different than reserve for deposit to staking)
- user_collateral_account - account from which tokens are transferred
- token_program - address of Solana's Token Program
- assets_list - list of assets, structured like this
- owner - the owner of collateral account and vault entry
- exchange_authority - pubkey belonging to the exchange
#
BorrowBorrow is the counterpart of minting in Vault. It allows user to borrow synthetic asset up to collateral_amount * collateral_ratio. It is defined here, takes amount (u64) and a context:
- state - account with data of the program
- vault_entry - user account in vault
- vault - account storing data for particular pair
- synthetic - address of the borrowed token
- collateral - address of token used as a collateral token
- assets_list - list of assets, structured like this
- to - account to which borrowed tokens will be transferred (does not have to be owned by signer)
- token_program - address of Solana's Token Program
- owner - signer, owner of vault entry
- exchange_authority - pubkey belonging to the exchange
#
WithdrawMethod responsible for withdrawal is defined here. It withdraws users collateral up to when value of collateral * collateral_ratio are equal to borrowed synthetic. It takes amount (u64, when equal to u64::MAX maximum amount will be withdrawn) and a following context:
- state - account with data of the program
- vault_entry - user account in vault (this one)
- vault - account storing data for particular pair
- synthetic - address of token used as a synthetic
- collateral - address of token used as collateral
- reserve_address - address of the account from which tokens are withdrawn (same as in the corresponding vault)
- user_collateral_account - account to which tokens will be transferred
- token_program - address of Solana's Token Program
- assets_list - list of assets, structured like this
- owner - signer, owner of VaultEntry, signer of the transaction
- exchange_authority - pubkey of the exchange program
#
RepayRepay method allows user to burn borrowed tokens, and free its collateral. It is defined here, takes amount (u64) and a following context:
- state - account with data of the program
- vault_entry - user account in vault (this one)
- vault - account storing data for particular pair
- synthetic - address of token used as a synthetic
- collateral - address of token used as collateral
- assets_list - list of assets, structured like this
- user_token_account_repay - account from with tokens will be repaid
- owner - the owner of VaultEntry and collateral amount, signer of a transaction
- exchange_authority - pubkey of the exchange program
#
LiquidationFunction responsible for liquidation is defined here. It checks if user can be liquidated, and if amount is valid. Liquidated amount is not greater than difference between borrow limit and current debt and below liquidation_ratio of collateral (or sets is at maximum valid value if amount is equal to u64::MAX). Method takes amount (u64) and this context:
- state - account with data of the program
- vault_entry - user account in vault (this one)
- vault - account storing data for particular pair
- synthetic - address of token used as a synthetic
- collateral - address of token used as collateral
- assets_list - list of assets, structured like this
- collateral_reserve - address of account where deposited tokens are kept
- liquidator_synthetic_account - account from which synthetic tokens will be repaid
- liquidator_collateral_account - account to which collateral tokens will be transferred
- liquidation_fund - the account where liquidation_penalty_exchange will be transferred (same as in Collateral struct)
- token_program - address of Solana's Token Program
- owner - the owner of vault_entry, needed to check the address of it
- liquidator - signer, owner of accounts with synthetics and collateral tokens
- exchange_authority - pubkey of the exchange program