Liquidation Contract
The Liquidation Contract enables users to submit Terra stablecoin bids for a Cw20-compliant token. Bidders can specify the rate of premium they will receive on bid execution, and the maximum premium rate is set at 30%.
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). The oracle contract is responsible for providing the relevant Cw20 token prices.
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.
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
owner
CanonicalAddr
Address of contract owner that can update config
oracle_contract
CanonicalAddr
Contract address of Oracle
stable_denom
String
Native token denomination for bids
safe_ratio
Decimal256
A liability / borrow limit ratio of a loan deemed safe
bid_fee
Decimal256
Fee rate applied to all executed bids
max_premium_rate
Decimal256
Maximum rate of commission given to bidder of an executed bid
liquidation_threshold
Uint256
Threshold collateral value for partial collateral liquidations
price_timeframe
u64
Window of time before oracle price data is considered outdated [seconds]

InstantiateMsg

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct InstantiateMsg {
3
pub owner: String,
4
pub oracle_contract: String,
5
pub stable_denom: String,
6
pub safe_ratio: Decimal256,
7
pub bid_fee: Decimal256,
8
pub max_premium_rate: Decimal256,
9
pub liquidation_threshold: Uint256,
10
pub price_timeframe: u64,
11
}
Copied!
1
{
2
"owner": "terra1..",
3
"oracle_contract": "terra1...",
4
"stable_denom": "uusd",
5
"safe_ratio": "0.8",
6
"bid_fee": "0.01",
7
"max_premium_rate": "0.05",
8
"liquidation_threshold": "500",
9
"price_timeframe": 60
10
}
Copied!
Key
Type
Description
owner
String
Address of contract owner that can update config
oracle_contract
String
Contract address of Oracle
stable_denom
String
Native token denomination for bids
safe_ratio
Decimal256
A liability / borrow limit ratio of a loan deemed safe
bid_fee
Decimal256
Fee rate applied to executed bids
max_premium_rate
Decimal256
Maximum rate of commission given to the bidder of an executed bid
liquidation_threshold
Uint256
Threshold collateral value for triggering partial collateral liquidations
price_timeframe
u64
Window of time before oracle price data is considered outdated [seconds]

ExecuteMsg

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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
Receive {
5
sender: String,
6
amount: Uint128,
7
msg: Binary,
8
}
9
}
Copied!
1
{
2
"receive": {
3
"sender": "terra1...",
4
"amount": "10000000",
5
"msg": "eyAiZXhlY3V0ZV9tc2ciOiAiYmluYXJ5IiB9"
6
}
7
}
Copied!
Key
Type
Description
sender
String
Sender of the token transfer
amount
Uint128
Amount of tokens received
msg
Binary
Base64-encoded string of JSON of Receive Hook

UpdateConfig

Updates the Liquidation Contract's configuration. Can only be issued by the owner.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
UpdateConfig {
5
owner: Option<String>,
6
oracle_contract: Option<String>,
7
stable_denom: Option<String>,
8
safe_ratio: Option<Decimal256>,
9
bid_fee: Option<Decimal256>,
10
max_premium_rate: Option<Decimal256>,
11
liquidation_threshold: Option<Uint256>,
12
price_timeframe: Option<u64>,
13
}
14
}
Copied!
1
{
2
"update_config": {
3
"owner": "terra1...",
4
"oracle_contract": "terra1...",
5
"stable_denom": "uusd",
6
"safe_ratio": "0.8",
7
"bid_fee": "0.01",
8
"max_premium_rate": "0.05",
9
"liquidation_threshold": "200000000",
10
"price_timeframe": 60
11
}
12
}
Copied!
Key
Type
Description
owner*
String
Address of new owner
oracle_contract*
String
New oracle contract address
stable_denom*
String
New native token denomination for bids
safe_ratio*
Decimal256
New liability / borrow limit of a loan deemed safe
bid_fee*
Decimal256
New fee rate applied to executed bids
max_premium_rate*
Decimal256
New maximum rate of commission given to the bidder of an executed bid
liquidation_threshold*
Uint256
New threshold collateral value for triggering partial collateral liquidations
price_timeframe*
u64
New window of time before price data is considered outdated [seconds]
* = optional

SubmitBid

Submits a new bid for the specified Cw20 collateral with the specified premium rate. Requires Terra stablecoins to be sent beforehand.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
SubmitBid {
5
collateral_token: String,
6
premium_rate: Decimal256,
7
}
8
}
Copied!
1
{
2
"submit_bid": {
3
"collateral_token": "terra1...",
4
"premium_rate": "0.03"
5
}
6
}
Copied!
Key
Type
Description
collateral_token
String
Cw20 token contract address of bidding collateral
premium_rate
Decimal256
Rate of commission on executing this bid

RetractBid

Withdraws specified amount of stablecoins from the bid for the specified collateral. Withdraws the entire bid for the specified collateral if the amount field is not filled.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum ExecuteMsg {
4
RetractBid {
5
collateral_token: String,
6
amount: Option<Uint256>,
7
}
8
}
Copied!
1
{
2
"retract_bid": {
3
"collateral_token": "terra1...",
4
"amount": "100000000"
5
}
6
}
Copied!
Key
Type
Description
collateral_token
String
Cw20 token contract address of bidding collateral
amount*
Uint256
Amount of stablecoins remove from bid
* = optional

Receive Hooks

ExecuteBid

Liquidates collateral by executing an existing bid for the received collateral. Requires the liquidator to have an existing bid. For Usage in Anchor, 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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum Cw20HookMsg {
4
ExecuteBid {
5
liquidator: String,
6
fee_address: Option<String>, // Filled as Overseer contract's address
7
repay_address: Option<String>, // Filled as Market contract's address
8
}
9
}
Copied!
1
{
2
"execute_bid": {
3
"liquidator": "terra1...",
4
"fee_address": "terra1...", // Filled as Overseer contract's address
5
"repay_address": "terra1..." // Filled as Market contract's address
6
}
7
}
Copied!
Key
Type
Description
liquidator
String
Address of collateral liquidator
fee_address*
String
Address to receive bid_fee from liquidation
repay_address*
String
Address to receive bid stablecoins from liquidation
* = optional

QueryMsg

Config

Gets the Liquidation Contract's configuration.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Config {}
5
}
Copied!
1
{
2
"config": {}
3
}
Copied!
Key
Type
Description

ConfigResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct ConfigResponse {
3
pub owner: String,
4
pub oracle_contract: String,
5
pub stable_denom: String,
6
pub safe_ratio: Decimal256,
7
pub bid_fee: Decimal256,
8
pub max_premium_rate: Decimal256,
9
pub liquidation_threshold: Uint256,
10
pub price_timeframe: u64,
11
}
Copied!
1
{
2
"owner": "terra1...",
3
"oracle_contract": "terra1...",
4
"stable_denom": "uusd",
5
"safe_ratio": "0.8",
6
"bid_fee": "0.01",
7
"max_premium_rate": "0.05",
8
"liquidation_threshold": "200000000",
9
"price_timeframe": 60
10
}
Copied!
Key
Type
Description
owner
String
Address of contract owner that can update config
oracle_contract
String
Contract address of Oracle
stable_denom
String
Native token denomination for bids
safe_ratio
Decimal256
A liability / borrow limit ratio of a loan deemed safe
bid_fee
Decimal256
Fee rate applied to all executed bids
max_premium_rate
Decimal256
Maximum rate of commission given to bidder of an executed bid
liquidation_threshold
Uint256
Threshold collateral value for partial collateral liquidations
price_timeframe
u64
Window of time before price data is considered outdated [seconds]

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.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
LiquidationAmount {
5
borrow_amount: Uint256,
6
borrow_limit: Uint256,
7
collaterals: TokensHuman,
8
collateral_prices: Vec<Decimal>,
9
}
10
}
11
12
pub type TokensHuman = Vec<(String, Uint256)>;
Copied!
1
{
2
"liquidation_amount": {
3
"borrow_amount": "10000000",
4
"borrow_limit": "10000000",
5
"collaterals": [
6
["terra1...", "100000000"], // (Cw20 contract address, Locked amount)
7
["terra1...", "100000000"]
8
],
9
"collateral_prices": [
10
"123.456789", // Price of collateral
11
"123.456789"
12
]
13
}
14
}
Copied!
Key
Type
Description
borrow_amount
Uint256
Liability of borrower
borrow_limit
Uint256
Borrow limit of borrower
collaterals
TokensHuman
Held collaterals and locked amounts
collateral_prices
Vec<Decimal>
Vector of collateral prices
Key
Type
Description
TokensHuman
Vec<(String, Uint256)>
Vector of (Collateral's token address, Amount of collateral locked by borrower)

LiquidationAmountResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct LiquidationAmountResponse {
3
pub collaterals: TokensHuman,
4
}
5
6
pub type TokensHuman = Vec<(String, Uint256)>;
Copied!
1
{
2
"collaterals": [
3
["terra1...", "100000000"], // (Cw20 Token address, Required liquidation amount to reach safe_ratio)
4
["terra1...", "100000000"]
5
]
6
}
Copied!
Key
Type
Description
collaterals
TokensHuman
Calculated amount of collaterals to liquidate
Key
Type
Description
TokensHuman
Vec<(String, Uint256)>
Vector of (Collateral's token address, Amount that has to be liquidated)

Bid

Gets information about the specified bidder's bid for the specified collateral.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
Bid {
5
collateral_token: String,
6
bidder: String,
7
}
8
}
Copied!
1
{
2
"bid": {
3
"collateral_token": "terra1...",
4
"bidder": "terra1..."
5
}
6
}
Copied!
Key
Type
Description
collateral_token
String
Token contract address of bidding collateral
bidder
String
Address of bidder

BidResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct BidResponse {
3
pub collateral_token: String,
4
pub bidder: String,
5
pub amount: Uint256,
6
pub premium_rate: Decimal256,
7
}
Copied!
1
{
2
"collateral_token": "terra1...",
3
"bidder": "terra1...",
4
"amount": "100000000",
5
"premium_rate": "0.03"
6
}
Copied!
Key
Type
Description
collateral_token
String
Token contract address of bidding collateral
bidder
String
Address of bidder
amount
Uint256
Amount of stablecoins put up in bid
premium_rate
Decimal256
Rate of commission taken by bidder upon bid execution

BidsByUser

Gets information for all bids submitted by the specified bidder
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
BidsByUser {
5
bidder: String,
6
start_after: Option<String>,
7
limit: Option<u32>,
8
}
9
}
Copied!
1
{
2
"bids_by_user": {
3
"bidder": "terra1...",
4
"start_after": "terra1...",
5
"limit": 8
6
}
7
}
Copied!
Key
Type
Description
bidder
String
Address of bidder
start_after*
String
Token contract address of collateral to start query
limit*
u32
Maximum number of query entries

BidsByUserResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct BidsResponse {
3
pub bids: Vec<BidResponse>,
4
}
5
6
pub struct BidResponse {
7
pub collateral_token: String,
8
pub bidder: String,
9
pub amount: Uint256,
10
pub premium_rate: Decimal256,
11
}
Copied!
1
{
2
"bids": [
3
{
4
"collateral_token": "terra1...",
5
"bidder": "terra1...",
6
"amount": "100000000",
7
"premium_rate": "0.03"
8
},
9
{
10
"collateral_token": "terra1...",
11
"bidder": "terra1...",
12
"amount": "100000000",
13
"premium_rate": "0.03"
14
}
15
]
16
}
Copied!
Key
Type
Description
bids
Vec<BidResponse>
Vector of user's bid information
Key
Type
Description
collateral_token
String
Token contract address of bidding collateral
bidder
String
Address of bidder
amount
Uint256
Amount of stablecoins put up in bid
premium_rate
Decimal256
Rate of commission taken by bidder upon bid execution

BidsByCollateral

Gets bid information for all bids submitted for the specified collateral.
Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
#[serde(rename_all = "snake_case")]
3
pub enum QueryMsg {
4
BidsByCollateral {
5
collateral_token: String,
6
start_after: Option<String>,
7
limit: Option<u32>,
8
}
9
}
Copied!
1
{
2
"bids_by_collateral": {
3
"collateral_token": "terra1...",
4
"start_after": "terra1...",
5
"limit": 10
6
}
7
}
Copied!
Key
Type
Description
collateral_token
String
Token contract address of collateral
start_after*
String
Token contract address of collateral to start query
limit*
u32
Maximum number of query entries
* = optional

BidsByCollateralResponse

Rust
JSON
1
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
2
pub struct BidsResponse {
3
pub bids: Vec<BidResponse>,
4
}
5
6
pub struct BidResponse {
7
pub collateral_token: String,
8
pub bidder: String,
9
pub amount: Uint256,
10
pub premium_rate: Decimal256,
11
}
Copied!
1
{
2
"bids": [
3
{
4
"collateral_token": "terra1...",
5
"bidder": "terra1...",
6
"amount": "100000000",
7
"premium_rate": "0.03"
8
},
9
{
10
"collateral_token": "terra1...",
11
"bidder": "terra1...",
12
"amount": "100000000",
13
"premium_rate": "0.03"
14
}
15
]
16
}
Copied!
Key
Type
Description
bids
Vec<BidResponse>
Vector of user's bid information
Key
Type
Description
collateral_token
String
Token contract address of bidding collateral
bidder
String
Address of bidder
amount
Uint256
Amount of stablecoins put up in bid
premium_rate
Decimal256
Rate of commission taken by bidder upon bid execution
Last modified 17d ago