Liquidations On Anchor
Understanding how the Anchor Liquidation Contract is being utilized.
Method
To understand how the liquidation contract is being utilized, we analyze anchor liquidations over the past 90 days.
The Anchor Liquidation Contract is deployed at terra1w9ky73v4g7v98zzdqpqgf3kjmusnx4d4mvnac6
. The first step is to query the contract's messages over the past 90 days.
The results are fed into queries that use the terra.msg_events
to get the number of liquidations, the number of addresses liquidated, and the total amount of liquidations in bLuna.
Here's how the final query looks like:
WITH liquidation_tx AS (
SELECT DISTINCT(tx_id)
FROM terra.msgs
WHERE msg_value:contract::string = 'terra1w9ky73v4g7v98zzdqpqgf3kjmusnx4d4mvnac6'
AND block_timestamp >= CURRENT_DATE - 90 AND tx_status = 'SUCCEEDED'
AND msg_value:execute_msg:submit_bid:collateral_token =
'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp'
),
liquidations AS (
SELECT COUNT(DISTINCT(e.tx_id)) AS no_of_liquidations
FROM terra.msg_events AS e
JOIN liquidation_tx AS l ON l.tx_id = e.tx_id
WHERE event_attributes:"1_sender"::string = 'terra1w9ky73v4g7v98zzdqpqgf3kjmusnx4d4mvnac6'
),
addresses AS (
SELECT COUNT(DISTINCT(event_attributes:"1_recipient"::string)) AS liquidated_addresses
FROM terra.msg_events AS e
JOIN liquidation_tx AS l ON l.tx_id = e.tx_id
WHERE event_attributes:"1_sender"::string = 'terra1w9ky73v4g7v98zzdqpqgf3kjmusnx4d4mvnac6'
),
liquidation_amount AS (
SELECT (SUM(event_attributes:"1_amount"[0].amount)/POW(10,6))*7.0 AS amount_bluna
FROM terra.msg_events AS e
JOIN liquidation_tx AS l ON l.tx_id = e.tx_id
WHERE event_attributes:"1_sender" = 'terra1w9ky73v4g7v98zzdqpqgf3kjmusnx4d4mvnac6'
)
SELECT *
FROM liquidations
LEFT JOIN addresses
LEFT JOIN liquidation_amount
NB: The price of bLUNA was calculated using LUNA as proxy at 7.0
The result is displayed below: