Liquidation Queue Contract
The Liquidation contract enables users to submit Terra stablecoin bids for a Cw20-compliant token. Bidders can submit a bid to one of the bid pools; each of the pools deposited funds are used to buy the liquidated collateral at different discount rates. There are 31 slots per collateral, from 0% to 30%; users can bid on one or more slots.
Upon execution of a bid, Cw20 tokens are sent to the bidder, while the bidder's Terra stablecoins are sent to the repay address (if not specified, sent to message sender). A portion of the collateral value liquidated will be given to the address triggering the liquidation (liquidator_fee
).
Bids are consumed from the bid pools in increasing order of premium rate (e.g 2% bids are only consumed after 0% and 1% pools are emptied). The liquidated collateral is then distributed to the bidders in the affected pools in proportion to their bid amount. The respective collateral should be claimed by the bidders.
To prevent bots from sniping loans, submitted bids can only be activated after wait_period
has expired, unless the total bid amount falls under the bid_threshold
, in which case bids will be directly activated upon submission.
Additionally, the Liquidation contract serves as the point of calculation for partial collateral liquidations, where a loan position is liquidated until it reaches a safe borrow_amount / borrow_limit
ratio. The required liquidation amount for each collateral is calculated based on the fed-in loan position's attributes and the state of the bid pools.
The oracle contract is responsible for providing the relevant Cw20 token prices. Price data from the Oracle contract are only valid for 60 seconds (price_timeframe
). The Liquidation contract disables bid executions until new price data is fed in to the Oracle contract.
Config
Key | Type | Description |
---|---|---|
| CanonicalAddr | Address of contract owner that can update config |
| CanonicalAddr | Contract address of Oracle |
| String | Native token denomination for bids |
| Decimal256 | A liability / borrow limit ratio of a loan deemed safe |
| Decimal256 | Fee rate given to the executor |
| Decimal256 | Fee rate applied to all executed liquidations |
| Uint256 | Threshold collateral value for partial collateral liquidations |
| u64 | Window of time before oracle price data is considered outdated [seconds] |
| u64 | Time after submitted bids can be activated [seconds] |
| CanonicalAddr | Contract address of Overseer |
InstantiateMsg
Key | Type | Description |
---|---|---|
| String | Address of contract owner that can update config |
| String | Contract address of Oracle |
| String | Native token denomination for bids |
| Decimal256 | A liability / borrow limit ratio of a loan deemed safe |
| Decimal256 | Fee rate applied to executed bids |
| Decimal256 | Fee rate given to the executor |
| Uint256 | Threshold collateral value for triggering partial collateral liquidations |
| u64 | Window of time before oracle price data is considered outdated [seconds] |
| u64 | Time after submitted bids can be activated [seconds] |
| String | Contract address of Overseer |
ExecuteMsg
Receive
Receive
Can be called during a CW20 token transfer when the Liquidation contract is the recipient. Allows the token transfer to execute a Receive Hook as a subsequent action within the same transaction.
Key | Type | Description |
---|---|---|
| String | Sender of the token transfer |
| Uint128 | Amount of tokens received |
| Binary | Base64-encoded string of JSON of Receive Hook |
UpdateConfig
UpdateConfig
Updates the Liquidation contract's configuration. Can only be issued by the owner.
Key | Type | Description |
---|---|---|
| String | Address of new owner |
| String | New oracle contract address |
| Decimal256 | New liability / borrow limit of a loan deemed safe |
| Decimal256 | New fee rate applied to executed bids |
| Decimal256 | Fee rate given to the executor |
| Uint256 | New threshold collateral value for triggering partial collateral liquidations |
| u64 | New window of time before price data is considered outdated [seconds] |
| u64 | Time after submitted bids can be activated [seconds] |
| String | Contract address of Overseer |
* = optional
WhitelistCollateral
WhitelistCollateral
Whitelist a new collateral token. Can only be issued by the owner.
Key | Type | Description |
---|---|---|
| String | Address of the collateral token to whitelist |
| Uint256 | Bid amount threshold under which bids will be activated upon submission |
| u8 | Maximum premium slot |
| Decimal256 | Premium rate increase for each slot |
UpdateCollateralInfo
UpdateCollateralInfo
Update a whitelisted collateral configuration. Can only be issued by the owner.
Key | Type | Description |
---|---|---|
| String | Address of the collateral token to whitelist |
| Uint256 | Bid amount threshold under which bids will be activated upon submission |
| u8 | Maximum premium slot |
* = optional
SubmitBid
SubmitBid
Submits a new bid for the specified Cw20 collateral to the specified premium slot. Requires Terra stablecoins to be sent beforehand. The premium rate on each slot can be calculated using the whitelisted collateral configuration (premium_slot * premium_rate_per_slot
).
Key | Type | Description |
---|---|---|
| String | Cw20 token contract address of bidding collateral |
| u8 | Premium rate slot to which the bid will be submitted to |
ActivateBids
ActivateBids
Activates the list of bids_idx
for the specified collateral_token
. Activates all bids with expired waiting_period
of the bid_idx
field is not filled.
Key | Type | Description |
---|---|---|
| String | Cw20 token contract address of bidding collateral |
| Vec<Uint128> | List of bid unique identifiers |
* = optional
RetractBid
RetractBid
Withdraws specified amount of stablecoins from the specified bid_idx
. Withdraws the entire remaining bid if the amount
field is not filled.
Key | Type | Description |
---|---|---|
| Uint128 | Bid unique identifier |
| Uint256 | Amount of stablecoins to remove from bid |
* = optional
ClaimLiquidations
ClaimLiquidations
Claim the liquidated collateral accrued by the specified list of bids_idx
. Claims all the pending collateral from user submitted bids if the bids_idx
field is not filled.
Key | Type | Description |
---|---|---|
| String | Cw20 token contract address of bidding collateral |
| Vec<Uint128> | List of bid unique identifiers |
* = optional
Receive Hooks
ExecuteBid
ExecuteBid
Liquidates the sent collateral using the active bids on the bid pools, consuming bids with lower premium rates first. Can only be executed by a whitelisted collateral's Custody
contract. Custody
issues this message with fee_address
as Overseer
's contract address and repay_address
as Market
's contract address, where stablecoins from the bid is sent to the Market contract to repay a borrower's loan and fees are sent to the Overseer contract to be added to the interest buffer. The liquidator_fee
is sent to the liquidator
address that originally triggered the liquidation.
Key | Type | Description |
---|---|---|
| String | Address of collateral liquidator to receive |
| String | Address to receive |
| String | Address to receive bid stablecoins from liquidation |
* = optional
QueryMsg
Config
Config
Gets the Liquidation Contract's configuration.
ConfigResponse
ConfigResponse
Key | Type | Description |
---|---|---|
| String | Address of contract owner that can update config |
| String | Contract address of Oracle |
| String | Native token denomination for bids |
| Decimal256 | A liability / borrow limit ratio of a loan deemed safe |
| Decimal256 | Fee rate applied to all executed bids |
| Decimal256 | Fee rate given to the executor |
| Uint256 | Threshold collateral value for partial collateral liquidations |
| u64 | Window of time before price data is considered outdated [seconds] |
| u64 | Time after submitted bids can be activated [seconds] |
| String | Contract address of Overseer |
CollateralInfo
CollateralInfo
Gets collateral specific configuration.
Key | Type | Description |
---|---|---|
| String | Token contract address |
CollateralInfoResponse
CollateralInfoResponse
Key | Type | Description |
---|---|---|
| String | Address of the collateral token whitelisted |
| Uint256 | Bid amount threshold under which bids will be activated upon submission |
| u8 | Maximum premium slot |
| Decimal256 | Premium rate increase for each slot |
LiquidationAmount
LiquidationAmount
Gets the amount of collaterals that needs to be liquidated in order for the borrower's loan to reach safe_ratio
, based on the fed in borrower's status and the state of all bid pools.
Key | Type | Description |
---|---|---|
| Uint256 | Liability of borrower |
| Uint256 | Borrow limit of borrower |
| TokensHuman | Held collaterals and locked amounts |
| Vec<Decimal> | Vector of collateral prices |
Key | Type | Description |
---|---|---|
| Vec<(String, Uint256)> | Vector of (Collateral's token address, Amount of collateral locked by borrower) |
LiquidationAmountResponse
LiquidationAmountResponse
Key | Type | Description |
---|---|---|
| TokensHuman | Calculated amount of collaterals to liquidate |
Key | Type | Description |
---|---|---|
| Vec<(String, Uint256)> | Vector of (Collateral's token address, Amount that has to be liquidated) |
Bid
Bid
Gets information about the specified bid_idx
.
Key | Type | Description |
---|---|---|
| Uint128 | Bid unique identifier |
BidResponse
BidResponse
Key | Type | Description |
---|---|---|
| Uint128 | Bid unique identifier |
| String | Token contract address of bidding collateral |
| u8 | Premium rate slot to which the bid is submitted to |
| String | Address of bidder |
| Uint256 | Amount of stablecoins put up in bid |
| Decimal256 | Snapshot of the bid pool's product at the time of activation |
| Decimal256 | Snapshot of the bid pool's sum at the time of activation |
| Uint256 | Amount of claimable collateral |
| u64 | Timestamp (seconds) when bid can be activated, empty if already active |
| Uint128 | Snapshot of the bid pool epoch at the time of activation |
| Uint128 | Snapshot of the bid pool scale at the time of activation |
BidsByUser
BidsByUser
Gets information for all bids submitted by the specified bidder and collateral.
Key | Type | Description |
---|---|---|
| String | Address of bidder |
| Uint128 | User bid idx to start the query after |
| u8 | Maximum number of query entries (capped at 31) |
BidsByUserResponse
BidsByUserResponse
Key | Type | Description |
---|---|---|
| Vec<BidResponse> | Vector of user's bid information |
Key | Type | Description |
---|---|---|
| Uint128 | Bid unique identifier |
| String | Token contract address of bidding collateral |
| u8 | Premium rate slot to which the bid is submitted to |
| String | Address of bidder |
| Uint256 | Amount of stablecoins put up in bid |
| Decimal256 | Snapshot of the bid pool's product at the time of activation |
| Decimal256 | Snapshot of the bid pool's sum at the time of activation |
| Uint256 | Amount of claimable collateral |
| u64 | Timestamp (seconds) when bid can be activated, empty if already active |
| Uint128 | Snapshot of the bid pool epoch at the time of activation |
| Uint128 | Snapshot of the bid pool scale at the time of activation |
BidPool
BidPool
Gets information about the bid pool for the specified collateral_token
and bid_slot
.
Key | Type | Description |
---|---|---|
| String | Token contract address of bidding collateral |
| u8 | Premium rate slot |
BidPoolResponse
BidPoolResponse
Key | Type | Description |
---|---|---|
| Decimal256 | Internal parameter that represents amount of collateral liquidated to be distributed |
| Decimal256 | Internal parameter that represents rate at which bids are consumed |
| Uint256 | Total remaining bid amount for this pool |
| Decimal256 | Discount rate at which the bid pool buys liquidated collateral |
| Uint128 | Increases every time all bids in the bid pool are totally consumed |
| Uint128 | Increases every time |
BidPoolsByCollateral
BidPoolsByCollateral
Gets information about all bid pools for the specified collateral.
Key | Type | Description |
---|---|---|
| String | Token contract address of collateral |
| u8 | Premium slot to start the query after |
| u32 | Maximum number of query entries (capped at 31) |
* = optional
BidPoolsByCollateralResponse
BidPoolsByCollateralResponse
Key | Type | Description |
---|---|---|
| Vec<BidPoolResponse> | Vector of bid pools information |
Key | Type | Description |
---|---|---|
| Decimal256 | Internal parameter that represents amount of collateral liquidated to be distributed |
| Decimal256 | Internal parameter that represents rate at which bids are consumed |
| Uint256 | Total remaining bid amount for this pool |
| Decimal256 | Discount rate at which the bid pool buys liquidated collateral |
| Uint128 | Increases every time all bids in the bid pool are totally consumed |
| Uint128 | Increases every time |
Last updated