Skip to content

add liquidation tracking#6175

Draft
RohanNero wants to merge 6 commits intoDefiLlama:masterfrom
RohanNero:liquidations
Draft

add liquidation tracking#6175
RohanNero wants to merge 6 commits intoDefiLlama:masterfrom
RohanNero:liquidations

Conversation

@RohanNero
Copy link
Contributor

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 81dced3a-f292-40f0-bacb-ff2ff29c294e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.


type Config = Record<string, { pools: string[]; start: string }>;

const configs: Record<string, Config> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, why not export aaveProtocolConfigs from helper/aave and use it here instead of duplicating the same config, this way, when a new pool/protocol gets added there, you automatically get support


type LiquidationConfig = Record<string, { comptroller: string; start: string }>;

const liquidationConfigs: Record<string, LiquidationConfig> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as aave, can keep only the missing protocols here

const AbsorbCollateralEvent = 'event AbsorbCollateral(address indexed absorber, address indexed borrower, address indexed asset, uint256 collateralAbsorbed, uint256 usdValue)'
const AbsorbDebtEvent = 'event AbsorbDebt(address indexed absorber, address indexed borrower, uint256 basePaidOut, uint256 usdValue)'

const config: { [chain: string]: { comets: string[]; start: string } } = {
Copy link
Member

@g1nt0ki g1nt0ki Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be pulled from compound v3 fees adapter, this way, any change there is reflected here

Copy link
Member

@g1nt0ki g1nt0ki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also track liquidations in perp dexes, I think gmx forks emit liquidation event, and might need to look for events/rely on their api in some cases

@noateden noateden self-assigned this Mar 17, 2026
const collateralUnderlying = underlyingMap[collateralCToken]
const exchangeRate = exchangeRateMap[collateralCToken]
if (collateralUnderlying && exchangeRate) {
const underlyingAmount = (BigInt(event.seizeTokens) * exchangeRate) / BigInt(1e18)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update the conversion here, this is from Compound docs:

oneCTokenInUnderlying = exchangeRateCurrent / (1 * 10 ^ (18 + underlyingDecimals - cTokenDecimals))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current formula is also correct since we add to balances in raw units, we keep the extra decimals (like adding 1e18 to ETH bal instead of 1 wei). Using this tx hash as an example, if we use the current formula we get 63.4 LINK seized (cLINK underlying), if we add underlyingDecimals - cTokenDecimals, it would show 0.000000006 LINK seized, and if we follow the docs and calculate underlyingAmount in two steps then we get 63.4 LINK seized (same output):

const txHash = '0x14f738e13b596d61bb66adfe86f6a1250948c0983111a460976546ba2bb281b7'
const seizeTokensRaw = 315071765737n
const exchangeRateStored = 201264676862259987086714351n
const cTokenDecimals = 8n
const underlyingDecimals = 18n

// current method
const oneStepUnderlyingRaw = (seizeTokensRaw * exchangeRateStored) / (10n ** 18n)

// compound docs: https://docs.compound.finance/v2/#protocol-math
const oneCTokenInUnderlyingScaled = (exchangeRateStored * (10n ** 18n)) / (10n ** (18n + underlyingDecimals - cTokenDecimals))
const twoStepUnderlyingRaw = (seizeTokensRaw * oneCTokenInUnderlyingScaled * (10n ** underlyingDecimals)) / ((10n ** cTokenDecimals) * (10n ** 18n))

console.log('oneStepUnderlyingRaw:', oneStepUnderlyingRaw.toString()) // 63412817119478982867
console.log('twoStepUnderlyingRaw:', twoStepUnderlyingRaw.toString()) // 63412817119478980634
console.log('underlyingHuman:', Number(oneStepUnderlyingRaw) / 1e18) // 63.41281711947898

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check cases of liquidated USDC, USDT? they have 6 decimals and make sure the calculation is correct to them

// LIQUIDATIONS
export type FetchResultLiquidations = FetchResultBase & {
dailyLiquidations?: FetchResponseValue
dailyLiquidatedDebt?: FetchResponseValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally, I would prefer dailyLiquidationRepaidDebt, because debt is repaid, not liquidated

@noateden
Copy link
Contributor

can you also track liquidations in perp dexes, I think gmx forks emit liquidation event, and might need to look for events/rely on their api in some cases

our HL indexer is tracking liquidation volume on Hyperliquid too

@llamabutler
Copy link

The aave-v3.ts adapter exports:

> adapters@1.0.0 test
> ts-node --transpile-only cli/testAdapter.ts fees aave-v3.ts

🦙 Running AAVE-V3.TS adapter 🦙
---------------------------------------------------
Start Date:	Wed, 18 Mar 2026 15:00:00 GMT
End Date:	Thu, 19 Mar 2026 15:00:00 GMT
---------------------------------------------------

Token transfers: Failed to use indexer, falling back to logs optimism Llama Indexer URL/api key is not set
Token transfers: Failed to use indexer, falling back to logs polygon Llama Indexer URL/api key is not set
Token transfers: Failed to use indexer, falling back to logs sonic Llama Indexer URL/api key is not set
Token transfers: Failed to use indexer, falling back to logs sonic Llama Indexer URL/api key is not set
Token transfers: Failed to use indexer, falling back to logs xdai Llama Indexer URL/api key is not set
Token transfers: Failed to use indexer, falling back to logs arbitrum Llama Indexer URL/api key is not set
Token transfers: Failed to use indexer, falling back to logs optimism Llama Indexer URL/api key is not set
------ ERROR ------

Promise pool failed! 
 Error: Llama RPC error! method: call 
- host: https://bsc-dataseed.binance.org error: missing trie node
- host: https://bsc-dataseed.bnbchain.org error: missing trie node
- host: https://bsc-dataseed2.defibit.io error: missing trie node
- host: https://bsc-dataseed4.defibit.io error: missing trie node
- host: https://bsc.api.pocket.network error: state at block #87335777 is pruned
- host: https://bsc.blockrazor.xyz error: not supported
- host: https://bsc-dataseed1.ninicoin.io error: missing trie node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants