@1delta/margin-fetcher 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/abis/aave/AaveOracle.d.ts +10 -0
  2. package/dist/abis/aave/AaveOracle.d.ts.map +1 -1
  3. package/dist/abis/aave/AaveOracle.js +13 -0
  4. package/dist/abis/oracle/AaveOracle.d.ts +10 -0
  5. package/dist/abis/oracle/AaveOracle.d.ts.map +1 -1
  6. package/dist/abis/oracle/AaveOracle.js +13 -0
  7. package/dist/assets/index.d.ts +4 -4
  8. package/dist/assets/index.d.ts.map +1 -1
  9. package/dist/assets/index.js +7 -7
  10. package/dist/assets/liquidityThresholds.d.ts +29 -0
  11. package/dist/assets/liquidityThresholds.d.ts.map +1 -0
  12. package/dist/assets/liquidityThresholds.js +51 -0
  13. package/dist/lending/aave-v2-type/publicCallParse.js +3 -3
  14. package/dist/lending/addresses/compoundV3.d.ts +1 -1
  15. package/dist/lending/addresses/compoundV3.d.ts.map +1 -1
  16. package/dist/lending/addresses/compoundV3.js +8 -7
  17. package/dist/lending/user-data/aave-v2-type/userCallBuild.d.ts.map +1 -1
  18. package/dist/lending/user-data/aave-v2-type/userCallBuild.js +4 -23
  19. package/dist/lending/user-data/aave-v2-type/userCallParse.d.ts.map +1 -1
  20. package/dist/lending/user-data/aave-v2-type/userCallParse.js +23 -10
  21. package/dist/lending/user-data/aave-v3-type/userCallBuild.d.ts.map +1 -1
  22. package/dist/lending/user-data/aave-v3-type/userCallBuild.js +1 -16
  23. package/dist/lending/user-data/aave-v3-type/userCallParse.d.ts.map +1 -1
  24. package/dist/lending/user-data/aave-v3-type/userCallParse.js +13 -6
  25. package/dist/lending/user-data/aave-v3-type/userCallParseYldr.d.ts.map +1 -1
  26. package/dist/lending/user-data/aave-v3-type/userCallParseYldr.js +12 -6
  27. package/dist/lending/user-data/compound-v3/addresses.d.ts.map +1 -1
  28. package/dist/lending/user-data/compound-v3/addresses.js +8 -7
  29. package/dist/lending/user-data/compound-v3/userCallParse.d.ts.map +1 -1
  30. package/dist/lending/user-data/compound-v3/userCallParse.js +2 -0
  31. package/dist/lending-pairs/computeLendingPairs.d.ts +11 -0
  32. package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
  33. package/dist/lending-pairs/computeLendingPairs.js +84 -5
  34. package/dist/prices/main-prices/fetchOracleData.d.ts +1 -1
  35. package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
  36. package/dist/prices/main-prices/fetchOracleData.js +11 -2
  37. package/dist/utils/parsing.d.ts.map +1 -1
  38. package/dist/utils/parsing.js +4 -2
  39. package/package.json +2 -2
  40. package/src/abis/aave/AaveOracle.ts +13 -0
  41. package/src/abis/oracle/AaveOracle.ts +13 -0
  42. package/src/assets/index.ts +70 -51
  43. package/src/assets/liquidityThresholds.ts +83 -0
  44. package/src/lending/aave-v2-type/publicCallParse.ts +3 -3
  45. package/src/lending/addresses/compoundV3.ts +29 -15
  46. package/src/lending/user-data/aave-v2-type/userCallBuild.ts +1 -25
  47. package/src/lending/user-data/aave-v2-type/userCallParse.ts +23 -10
  48. package/src/lending/user-data/aave-v3-type/userCallBuild.ts +1 -16
  49. package/src/lending/user-data/aave-v3-type/userCallParse.ts +15 -6
  50. package/src/lending/user-data/aave-v3-type/userCallParseYldr.ts +14 -6
  51. package/src/lending/user-data/compound-v3/addresses.ts +58 -39
  52. package/src/lending/user-data/compound-v3/userCallParse.ts +2 -2
  53. package/src/lending-pairs/computeLendingPairs.ts +135 -5
  54. package/src/prices/main-prices/fetchOracleData.ts +14 -2
  55. package/src/utils/parsing.ts +51 -51
  56. package/test/userdata.test.ts +5 -5
@@ -1,42 +1,56 @@
1
- import { Chain, COMETS_PER_CHAIN_MAP, COMPOUND_BASE_TOKENS, Lender, SWAYLEND_BASE_TOKENS } from '@1delta/asset-registry'
1
+ import {
2
+ Chain,
3
+ COMETS_PER_CHAIN_MAP,
4
+ COMPOUND_BASE_TOKENS,
5
+ Lender,
6
+ SWAYLEND_BASE_TOKENS,
7
+ } from "@1delta/asset-registry";
2
8
 
3
- export function getCompoundV3CometAddress(chainId: string, lender = Lender.COMPOUND_V3_USDCE): string | undefined {
4
- return COMETS_PER_CHAIN_MAP[chainId]?.[lender]
9
+ export function getCompoundV3CometAddress(
10
+ chainId: string,
11
+ lender = Lender.COMPOUND_V3_USDCE
12
+ ): string | undefined {
13
+ return COMETS_PER_CHAIN_MAP[chainId]?.[lender];
5
14
  }
6
15
 
7
16
  export function getCompoundV3CometRewardsAddress(chainId: string) {
8
17
  // @ts-ignore
9
- return addressesCompoundV3.cometRewards[chainId]
18
+ return addressesCompoundV3.cometRewards[chainId];
10
19
  }
11
20
 
12
21
  export function getCompoundV3CometIRGetterAddress(chainId: string) {
13
22
  // @ts-ignore
14
- return addressesCompoundV3.lens[chainId]
23
+ return addressesCompoundV3.lens[chainId];
15
24
  }
16
25
 
17
26
  export function getCompoundV3CometLens(chainId: string) {
18
27
  // @ts-ignore
19
- return addressesCompoundV3.lens[chainId]
28
+ return addressesCompoundV3.lens[chainId];
20
29
  }
21
30
 
22
31
  const addressesCompoundV3 = {
23
32
  lens: {
24
- [Chain.POLYGON_MAINNET]: '0x4eDA401658c5286d16c4d342884F32280B4E8b1b',
25
- [Chain.MANTLE]: '0x32B31A066c8dd3F7b77283Ba1d89Ddaf6DA0a8aE',
26
- [Chain.ARBITRUM_ONE]: '0x13D9c35f4901491Ac4FFebd3100238BBfFBD7181',
33
+ [Chain.POLYGON_MAINNET]: "0x4eDA401658c5286d16c4d342884F32280B4E8b1b",
34
+ [Chain.MANTLE]: "0x32B31A066c8dd3F7b77283Ba1d89Ddaf6DA0a8aE",
35
+ [Chain.ARBITRUM_ONE]: "0x13D9c35f4901491Ac4FFebd3100238BBfFBD7181",
27
36
  [Chain.BASE]: "0x7e2D250E4FD0EeD6BD2cB3DC525A2b9f12508152",
28
37
  [Chain.OP_MAINNET]: "0xA453ba397c61B0c292EA3959A858821145B2707F",
29
38
  },
30
39
  cometRewards: {
31
40
  [Chain.POLYGON_MAINNET]: "0x45939657d1CA34A8FA39A924B71D28Fe8431e581",
32
41
  [Chain.MANTLE]: "0xCd83CbBFCE149d141A5171C3D6a0F0fCCeE225Ab",
33
- [Chain.ARBITRUM_ONE]: '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae',
42
+ [Chain.ARBITRUM_ONE]: "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae",
34
43
  [Chain.BASE]: "0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1",
35
44
  [Chain.OP_MAINNET]: "0x443EA0340cb75a160F31A440722dec7b5bc3C2E9",
36
- }
37
- }
45
+ },
46
+ };
38
47
 
39
- export function getCompoundV3BaseAsset(lender: Lender | string, chainId: string) {
40
- return COMPOUND_BASE_TOKENS[lender]?.[chainId] ?? SWAYLEND_BASE_TOKENS[lender]?.[chainId]
48
+ export function getCompoundV3BaseAsset(
49
+ lender: Lender | string,
50
+ chainId: string
51
+ ) {
52
+ return (
53
+ COMPOUND_BASE_TOKENS[lender]?.[chainId] ??
54
+ SWAYLEND_BASE_TOKENS[lender]?.[chainId]
55
+ );
41
56
  }
42
-
@@ -2,39 +2,19 @@ import { Call } from "../../../utils/multicall"
2
2
  import { Lender } from "@1delta/asset-registry"
3
3
  import { getAaveAssets, getAaveStyleProtocolTokenMap, getAaveTypePoolDataProviderAddress } from "../../../assets"
4
4
  import { getAaveTypeIncentivesControllerAddress, getAaveTypeMultiFeeDistribution } from "../../addresses"
5
- import { getComposerAddress } from "../../../utils"
6
-
7
- const fallbackDebtToken = '0x52A1CeB68Ee6b7B5D13E0376A1E0E4423A8cE26e'
8
5
 
9
6
  const getBaseAaveV2Calls = (
10
7
  chainId: string,
11
8
  account: string,
12
9
  lender: Lender,
13
10
  assetsToQuery: string[],
14
- aaveTokenMap: any
15
11
  ) => {
16
- const broker = getComposerAddress(chainId)
17
12
  return assetsToQuery.flatMap((tk) => [
18
13
  {
19
14
  address: getAaveTypePoolDataProviderAddress(chainId, lender),
20
15
  name: 'getUserReserveData',
21
16
  params: [tk, account],
22
17
  },
23
- {
24
- address: aaveTokenMap[tk].aToken,
25
- name: 'allowance',
26
- params: [account, broker],
27
- },
28
- {
29
- address: aaveTokenMap[tk].vToken ?? fallbackDebtToken,
30
- name: 'borrowAllowance',
31
- params: [account, broker],
32
- },
33
- {
34
- address: aaveTokenMap[tk].sToken ?? fallbackDebtToken,
35
- name: 'borrowAllowance',
36
- params: [account, broker],
37
- },
38
18
  ])
39
19
  }
40
20
 
@@ -55,7 +35,6 @@ export const buildAaveV2UserCall = (chainId: string, lender: Lender, account: st
55
35
  account,
56
36
  lender,
57
37
  assetsToQuery,
58
- aaveTokenMap
59
38
  ),
60
39
  {
61
40
  address: rewarder,
@@ -120,8 +99,7 @@ export const buildAaveV2UserCall = (chainId: string, lender: Lender, account: st
120
99
  chainId,
121
100
  account,
122
101
  lender,
123
- assetsToQuery,
124
- aaveTokenMap
102
+ assetsToQuery
125
103
  ),
126
104
  rewardsBalance,
127
105
  unclaimedRewards
@@ -129,13 +107,11 @@ export const buildAaveV2UserCall = (chainId: string, lender: Lender, account: st
129
107
  }
130
108
  default: {
131
109
  const assetsToQuery = getAaveAssets(chainId, lender)
132
- const aaveTokenMap = getAaveStyleProtocolTokenMap(chainId, lender)
133
110
  return getBaseAaveV2Calls(
134
111
  chainId,
135
112
  account,
136
113
  lender,
137
114
  assetsToQuery,
138
- aaveTokenMap
139
115
  )
140
116
  }
141
117
  }
@@ -19,7 +19,7 @@ export const getAaveV2UserDataConverter = (
19
19
  switch (lender) {
20
20
  case Lender.AURELIUS: {
21
21
  const assetsToQuery = getAaveAssets(chainId, lender)
22
- const expectedNumberOfCalls = assetsToQuery.length * 4 + 1
22
+ const expectedNumberOfCalls = assetsToQuery.length + 1
23
23
  return [
24
24
  (data: any[]) => {
25
25
  if (data.length !== expectedNumberOfCalls) {
@@ -46,12 +46,14 @@ export const getAaveV2UserDataConverter = (
46
46
  pricesHist,
47
47
  0,
48
48
  )
49
+ if(!dataForAsset) continue;
50
+
49
51
  totalDebt24h += addedDebt
50
52
  totalDeposits24h += addedDeposits
51
53
  lendingPositions[asset] = dataForAsset
52
54
  }
53
55
 
54
- const startIndex = assetsToQuery.length * 4
56
+ const startIndex = assetsToQuery.length
55
57
  const rewardMapping = Object.fromEntries(data[startIndex][0].map((key: string, index: number) => [key.toLowerCase(), data[startIndex][1][index]]))
56
58
  const rewards: UserRewardEntry = {}
57
59
  for (let i = 0; i < AURELIUS_REWARD_ASSETS.length; i++) {
@@ -81,7 +83,7 @@ export const getAaveV2UserDataConverter = (
81
83
  }
82
84
  case Lender.LENDLE: {
83
85
  const assetsToQuery = getAaveAssets(chainId, lender)
84
- const expectedNumberOfCalls = assetsToQuery.length * 4 + 2
86
+ const expectedNumberOfCalls = assetsToQuery.length + 2
85
87
 
86
88
  return [
87
89
  (data: any[]) => {
@@ -123,6 +125,7 @@ export const getAaveV2UserDataConverter = (
123
125
  pricesHist,
124
126
  mappedClaimableRewardsToTokens[i][asset],
125
127
  )
128
+ if(!dataForAsset) continue;
126
129
  totalDebt24h += addedDebt
127
130
  totalDeposits24h += addedDeposits
128
131
  lendingPositions[asset] = dataForAsset
@@ -153,7 +156,7 @@ export const getAaveV2UserDataConverter = (
153
156
  }
154
157
  case Lender.MERIDIAN: {
155
158
  const assetsToQuery = getLenderAssets(chainId, lender)
156
- const expectedNumberOfCalls = assetsToQuery.length * 4 + 2
159
+ const expectedNumberOfCalls = assetsToQuery.length + 2
157
160
 
158
161
  return [
159
162
  (data: any[]) => {
@@ -200,6 +203,7 @@ export const getAaveV2UserDataConverter = (
200
203
  pricesHist,
201
204
  assetClaimableRewards,
202
205
  )
206
+ if(!dataForAsset) continue;
203
207
  totalDebt24h += addedDebt
204
208
  totalDeposits24h += addedDeposits
205
209
  lendingPositions[asset] = dataForAsset
@@ -229,7 +233,7 @@ export const getAaveV2UserDataConverter = (
229
233
  }
230
234
  default: {
231
235
  const assetsToQuery = getLenderAssets(chainId, lender)
232
- const expectedNumberOfCalls = assetsToQuery.length * 4
236
+ const expectedNumberOfCalls = assetsToQuery.length
233
237
  return [
234
238
  (data: any[]) => {
235
239
  if (data.length !== expectedNumberOfCalls) {
@@ -255,6 +259,7 @@ export const getAaveV2UserDataConverter = (
255
259
  pricesHist,
256
260
  0,
257
261
  )
262
+ if(!dataForAsset) continue;
258
263
  totalDebt24h += addedDebt
259
264
  totalDeposits24h += addedDeposits
260
265
  lendingPositions[asset] = dataForAsset
@@ -288,10 +293,22 @@ function createAaveV2Entry(
288
293
  pricesHist: any,
289
294
  claimableRewards: any,
290
295
  ) {
291
- const reserveData = data[i * 4]
296
+ const reserveData = data[i]
292
297
  const currentATokenBalanceRaw = reserveData[AaveV2TypeGetUserReserveData.currentATokenBalance]?.toString()
293
298
  const currentStableDebtRaw = reserveData[AaveV2TypeGetUserReserveData.currentStableDebt]?.toString()
294
299
  const currentVariableDebtRaw = reserveData[AaveV2TypeGetUserReserveData.currentVariableDebt]?.toString()
300
+
301
+ if (
302
+ currentATokenBalanceRaw === "0" &&
303
+ currentStableDebtRaw === "0" &&
304
+ currentVariableDebtRaw === "0") {
305
+ return {
306
+ dataForAsset: undefined,
307
+ addedDeposits: 0,
308
+ addedDebt: 0
309
+ }
310
+ }
311
+
295
312
  const assetMeta = getAssetMeta(chainId, asset)
296
313
  const decimals = assetMeta?.decimals ?? 18
297
314
  const currentATokenBalance = parseRawAmount(currentATokenBalanceRaw, decimals)
@@ -316,10 +333,6 @@ function createAaveV2Entry(
316
333
  collateralActive: Boolean(reserveData[AaveV2TypeGetUserReserveData.usageAsCollateralEnabled]),
317
334
  claimableRewards,
318
335
 
319
- // allowances
320
- allowanceWithdrawal: data[i * 4 + 1]?.toString(),
321
- allowanceBorrowingVariable: data[i * 4 + 2]?.toString(),
322
- allowanceBorrowingStable: data[i * 4 + 3]?.toString(),
323
336
  }
324
337
 
325
338
  return {
@@ -18,22 +18,7 @@ const getBaseAaveV3Calls = (
18
18
  address: getAaveTypePoolDataProviderAddress(chainId, lender),
19
19
  name: 'getUserReserveData',
20
20
  params: [tk, account],
21
- },
22
- {
23
- address: aaveTokenMap[tk].aToken,
24
- name: 'allowance',
25
- params: [account, broker],
26
- },
27
- {
28
- address: aaveTokenMap[tk].vToken ?? fallbackDebtToken,
29
- name: 'borrowAllowance',
30
- params: [account, broker],
31
- },
32
- {
33
- address: aaveTokenMap[tk].sToken ?? fallbackDebtToken,
34
- name: 'borrowAllowance',
35
- params: [account, broker],
36
- },
21
+ }
37
22
  ])
38
23
  }
39
24
 
@@ -15,7 +15,7 @@ export const getAaveV3UserDataConverter = (
15
15
  ): [(data: any[]) => AaveV3UserReserveResponse | undefined, number] => {
16
16
 
17
17
  const assetsToQuery = getAaveAssets(chainId, lender)
18
- const expectedNumberOfCalls = assetsToQuery.length * 4 + 1
18
+ const expectedNumberOfCalls = assetsToQuery.length + 1
19
19
  return [
20
20
  (data: any[]) => {
21
21
  if (data.length !== expectedNumberOfCalls) {
@@ -41,6 +41,8 @@ export const getAaveV3UserDataConverter = (
41
41
  prices,
42
42
  pricesHist,
43
43
  )
44
+ if (!dataForAsset) continue;
45
+
44
46
  totalDebt24h += addedDebt
45
47
  totalDeposits24h += addedDeposits
46
48
  lendingPositions[asset] = dataForAsset
@@ -71,12 +73,23 @@ function createAaveV3Entry(
71
73
  prices: any,
72
74
  pricesHist: any,
73
75
  ) {
74
- const reserveData = data[i * 4]
76
+ const reserveData = data[i]
75
77
 
76
78
  const currentATokenBalanceRaw = reserveData[AaveTypeGetUserReserveIndexes.currentATokenBalance]?.toString()
77
79
  const currentStableDebtRaw = reserveData[AaveTypeGetUserReserveIndexes.currentStableDebt]?.toString()
78
80
  const currentVariableDebtRaw = reserveData[AaveTypeGetUserReserveIndexes.currentVariableDebt]?.toString()
79
81
 
82
+ if (
83
+ currentATokenBalanceRaw === "0" &&
84
+ currentStableDebtRaw === "0" &&
85
+ currentVariableDebtRaw === "0") {
86
+ return {
87
+ dataForAsset: undefined,
88
+ addedDeposits: 0,
89
+ addedDebt: 0
90
+ }
91
+ }
92
+
80
93
  const assetMeta = getAssetMeta(chainId, asset)
81
94
  const decimals = assetMeta?.decimals ?? 18
82
95
 
@@ -103,10 +116,6 @@ function createAaveV3Entry(
103
116
  stableBorrowRate: reserveData[AaveTypeGetUserReserveIndexes.stableBorrowRate]?.toString() ?? "0",
104
117
  collateralActive: Boolean(reserveData[AaveTypeGetUserReserveIndexes.usageAsCollateralEnabled]),
105
118
  claimableRewards: 0,
106
- // allowances
107
- allowanceWithdrawal: data[i * 4 + 1]?.toString(),
108
- allowanceBorrowingVariable: data[i * 4 + 2]?.toString(),
109
- allowanceBorrowingStable: data[i * 4 + 3]?.toString(),
110
119
  }
111
120
 
112
121
  return {
@@ -16,7 +16,7 @@ export const getYldrUserDataConverter = (
16
16
  ): [(data: any[]) => AaveV3UserReserveResponse | undefined, number] => {
17
17
 
18
18
  const assetsToQuery = getAaveAssets(chainId, lender)
19
- const expectedNumberOfCalls = assetsToQuery.length * 4
19
+ const expectedNumberOfCalls = assetsToQuery.length
20
20
  return [
21
21
  (data: any[]) => {
22
22
  if (data.length !== expectedNumberOfCalls) {
@@ -41,6 +41,7 @@ export const getYldrUserDataConverter = (
41
41
  prices,
42
42
  pricesHist,
43
43
  )
44
+ if (!dataForAsset) continue;
44
45
  totalDebt24h += addedDebt
45
46
  totalDeposits24h += addedDeposits
46
47
  lendingPositions[asset] = dataForAsset
@@ -72,11 +73,22 @@ function createAaveV3Entry(
72
73
  prices: any,
73
74
  pricesHist: any,
74
75
  ) {
75
- const reserveData = data[i * 4]
76
+ const reserveData = data[i]
76
77
 
77
78
  const currentATokenBalanceRaw = reserveData[YldrTypeGetUserReserveIndexes.currentYTokenBalance]?.toString()
78
79
  const currentVariableDebtRaw = reserveData[YldrTypeGetUserReserveIndexes.currentVariableDebt]?.toString()
79
80
 
81
+
82
+ if (
83
+ currentATokenBalanceRaw === "0" &&
84
+ currentVariableDebtRaw === "0") {
85
+ return {
86
+ dataForAsset: undefined,
87
+ addedDeposits: 0,
88
+ addedDebt: 0
89
+ }
90
+ }
91
+
80
92
  const assetMeta = getAssetMeta(chainId, asset)
81
93
  const decimals = assetMeta?.decimals ?? 18
82
94
 
@@ -102,10 +114,6 @@ function createAaveV3Entry(
102
114
  stableBorrowRate: 0,
103
115
  collateralActive: Boolean(reserveData[YldrTypeGetUserReserveIndexes.usageAsCollateralEnabled]),
104
116
  claimableRewards: 0,
105
- // allowances
106
- allowanceWithdrawal: data[i * 4 + 1]?.toString(),
107
- allowanceBorrowingVariable: "0",
108
- allowanceBorrowingStable: data[i * 4 + 3]?.toString(),
109
117
  }
110
118
 
111
119
  return {
@@ -1,40 +1,59 @@
1
- import { Chain, COMETS_PER_CHAIN_MAP, COMPOUND_BASE_TOKENS, Lender, SWAYLEND_BASE_TOKENS } from "@1delta/asset-registry"
1
+ import {
2
+ Chain,
3
+ COMETS_PER_CHAIN_MAP,
4
+ COMPOUND_BASE_TOKENS,
5
+ Lender,
6
+ SWAYLEND_BASE_TOKENS,
7
+ } from "@1delta/asset-registry";
2
8
 
3
- export function getCompoundV3CometAddress(chainId: string, lender = Lender.COMPOUND_V3_USDCE): string | undefined {
4
- return COMETS_PER_CHAIN_MAP[chainId]?.[lender]
5
- }
6
-
7
- export function getCompoundV3CometRewardsAddress(chainId: string) {
8
- return addressesCompoundV3.cometRewards[chainId as keyof typeof addressesCompoundV3.cometRewards]
9
- }
10
-
11
- export function getCompoundV3CometIRGetterAddress(chainId: string) {
12
- return addressesCompoundV3.lens[chainId as keyof typeof addressesCompoundV3.lens]
13
- }
14
-
15
- export function getCompoundV3CometLens(chainId: string) {
16
- return addressesCompoundV3.lens[chainId as keyof typeof addressesCompoundV3.lens]
17
- }
18
-
19
- const addressesCompoundV3 = {
20
- lens: {
21
- [Chain.POLYGON_MAINNET]: '0x4eDA401658c5286d16c4d342884F32280B4E8b1b',
22
- [Chain.MANTLE]: '0x32B31A066c8dd3F7b77283Ba1d89Ddaf6DA0a8aE',
23
- [Chain.ARBITRUM_ONE]: '0x13D9c35f4901491Ac4FFebd3100238BBfFBD7181',
24
- [Chain.BASE]: "0x7e2D250E4FD0EeD6BD2cB3DC525A2b9f12508152",
25
- [Chain.OP_MAINNET]: "0xA453ba397c61B0c292EA3959A858821145B2707F",
26
- },
27
- cometRewards: {
28
- [Chain.POLYGON_MAINNET]: "0x45939657d1CA34A8FA39A924B71D28Fe8431e581",
29
- [Chain.MANTLE]: "0xCd83CbBFCE149d141A5171C3D6a0F0fCCeE225Ab",
30
- [Chain.ARBITRUM_ONE]: '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae',
31
- [Chain.BASE]: "0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1",
32
- [Chain.OP_MAINNET]: "0x443EA0340cb75a160F31A440722dec7b5bc3C2E9",
33
- }
34
- }
35
-
36
- export function getCompoundV3BaseAsset(lender: Lender | string, chainId: string) {
37
- return COMPOUND_BASE_TOKENS[lender]?.[chainId] ?? SWAYLEND_BASE_TOKENS[lender]?.[chainId]
38
- }
39
-
40
-
9
+ export function getCompoundV3CometAddress(
10
+ chainId: string,
11
+ lender = Lender.COMPOUND_V3_USDCE
12
+ ): string | undefined {
13
+ return COMETS_PER_CHAIN_MAP[chainId]?.[lender];
14
+ }
15
+
16
+ export function getCompoundV3CometRewardsAddress(chainId: string) {
17
+ return addressesCompoundV3.cometRewards[
18
+ chainId as keyof typeof addressesCompoundV3.cometRewards
19
+ ];
20
+ }
21
+
22
+ export function getCompoundV3CometIRGetterAddress(chainId: string) {
23
+ return addressesCompoundV3.lens[
24
+ chainId as keyof typeof addressesCompoundV3.lens
25
+ ];
26
+ }
27
+
28
+ export function getCompoundV3CometLens(chainId: string) {
29
+ return addressesCompoundV3.lens[
30
+ chainId as keyof typeof addressesCompoundV3.lens
31
+ ];
32
+ }
33
+
34
+ const addressesCompoundV3 = {
35
+ lens: {
36
+ [Chain.POLYGON_MAINNET]: "0x4eDA401658c5286d16c4d342884F32280B4E8b1b",
37
+ [Chain.MANTLE]: "0x32B31A066c8dd3F7b77283Ba1d89Ddaf6DA0a8aE",
38
+ [Chain.ARBITRUM_ONE]: "0x13D9c35f4901491Ac4FFebd3100238BBfFBD7181",
39
+ [Chain.BASE]: "0x7e2D250E4FD0EeD6BD2cB3DC525A2b9f12508152",
40
+ [Chain.OP_MAINNET]: "0xA453ba397c61B0c292EA3959A858821145B2707F",
41
+ },
42
+ cometRewards: {
43
+ [Chain.POLYGON_MAINNET]: "0x45939657d1CA34A8FA39A924B71D28Fe8431e581",
44
+ [Chain.MANTLE]: "0xCd83CbBFCE149d141A5171C3D6a0F0fCCeE225Ab",
45
+ [Chain.ARBITRUM_ONE]: "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae",
46
+ [Chain.BASE]: "0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1",
47
+ [Chain.OP_MAINNET]: "0x443EA0340cb75a160F31A440722dec7b5bc3C2E9",
48
+ },
49
+ };
50
+
51
+ export function getCompoundV3BaseAsset(
52
+ lender: Lender | string,
53
+ chainId: string
54
+ ) {
55
+ return (
56
+ COMPOUND_BASE_TOKENS[lender]?.[chainId] ??
57
+ SWAYLEND_BASE_TOKENS[lender]?.[chainId]
58
+ );
59
+ }
@@ -1,6 +1,5 @@
1
1
  import { Lender } from "@1delta/asset-registry"
2
- import { formatUnits } from "viem"
3
- import { CompoundV3UserReserveResponse, UserLendingPosition, UserRewardEntry } from "../types"
2
+ import { CompoundV3UserReserveResponse } from "../types"
4
3
  import { getAssetMeta, getCompoundV3Assets, toGenericPriceKey, toOracleKey } from "../../../assets"
5
4
  import { getCompoundV3BaseAsset } from "./addresses"
6
5
  import { parseRawAmount } from "../../../utils/parsing"
@@ -37,6 +36,7 @@ export const getCompoundV3UserDataConverter = (
37
36
  const assetMeta = getAssetMeta(chainId, asset)
38
37
  const decimals = assetMeta?.decimals ?? 18
39
38
  const depositsRaw = data[i][0]?.toString()
39
+ if(depositsRaw === "0") continue;
40
40
  const deposits = parseRawAmount(depositsRaw, decimals)
41
41
  const key = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(asset, chainId)
42
42
  const price = prices[key] ?? 1
@@ -1,4 +1,5 @@
1
1
  import { getAssetMeta, toGenericPriceKey, toOracleKey } from "../assets"
2
+ import { getLiquidityThresholds, meetsLiquidityThresholds } from "../assets/liquidityThresholds"
2
3
  import { ConfigEntry, LenderData, PoolData } from "../types"
3
4
  import { isAaveV3Type, isInit } from "../utils"
4
5
 
@@ -24,6 +25,21 @@ export interface LendingPair {
24
25
  apr: number
25
26
  tags?: string[]
26
27
  eMode?: number
28
+
29
+ // liquidity data
30
+ longTotalDepositsUSD: number
31
+ longTotalDebtUSD: number
32
+ longTotalLiquidityUSD: number
33
+ shortTotalDepositsUSD: number
34
+ shortTotalDebtUSD: number
35
+ shortTotalLiquidityUSD: number
36
+
37
+ // status flags
38
+ longIsActive: boolean
39
+ longIsFrozen: boolean
40
+ shortIsActive: boolean
41
+ shortIsFrozen: boolean
42
+ shortBorrowingEnabled: boolean
27
43
  }
28
44
 
29
45
  const isEMode = (longData: PoolData, shortData: PoolData) => Boolean(longData.eMode) ?
@@ -145,7 +161,18 @@ export function generateLendingPairs(lenderData: LenderData, prices: { [k: strin
145
161
  priceChange: price24h === 0 ? 0 : (price - price24h) / price24h,
146
162
  maxLeverage: maxDepositLeverage,
147
163
  apr: (depositApr + collateralRewards) * depositLeverage + (borrowRewards - borrowApr) * borrowLeverage,
148
- eMode: long.eMode?.category ?? 0
164
+ eMode: long.eMode?.category ?? 0,
165
+ longTotalDepositsUSD: long.totalDepositsUSD,
166
+ longTotalDebtUSD: long.totalDebtUSD,
167
+ longTotalLiquidityUSD: long.totalLiquidityUSD,
168
+ shortTotalDepositsUSD: short.totalDepositsUSD,
169
+ shortTotalDebtUSD: short.totalDebtUSD,
170
+ shortTotalLiquidityUSD: short.totalLiquidityUSD,
171
+ longIsActive: long.isActive,
172
+ longIsFrozen: long.isFrozen,
173
+ shortIsActive: short.isActive,
174
+ shortIsFrozen: short.isFrozen,
175
+ shortBorrowingEnabled: short.borrowingEnabled
149
176
  });
150
177
  }
151
178
  }
@@ -162,10 +189,73 @@ function getPriceKey(asset: string, chainId: string): [string, string] {
162
189
 
163
190
  const MAX_ENTRIES = 10
164
191
 
192
+ function filterPairsByCategory(
193
+ pairs: LendingPair[],
194
+ longFilter: (group: string) => boolean,
195
+ shortFilter: (group: string) => boolean
196
+ ): LendingPair[] {
197
+ return pairs
198
+ .filter(p => {
199
+ if (!longFilter(p.assetGroupLong) || !shortFilter(p.assetGroupShort)) {
200
+ return false;
201
+ }
202
+
203
+ if (p.assetGroupShort?.includes("PT-") || p.assetGroupLong?.includes("PT-")) {
204
+ return false;
205
+ }
206
+
207
+ if (!p.longIsActive || p.longIsFrozen || !p.shortIsActive || p.shortIsFrozen) {
208
+ return false;
209
+ }
210
+
211
+ if (!p.shortBorrowingEnabled) {
212
+ return false;
213
+ }
214
+
215
+ // apply liquidity thresholds
216
+ const longThresholds = getLiquidityThresholds(p.chainId, p.assetLong, p.assetGroupLong);
217
+ const shortThresholds = getLiquidityThresholds(p.chainId, p.assetShort, p.assetGroupShort);
218
+
219
+ const longMeetsThresholds = meetsLiquidityThresholds({
220
+ totalDepositsUSD: p.longTotalDepositsUSD,
221
+ totalDebtUSD: p.longTotalDebtUSD,
222
+ totalLiquidityUSD: p.longTotalLiquidityUSD
223
+ }, longThresholds);
224
+
225
+ const shortMeetsThresholds = meetsLiquidityThresholds({
226
+ totalDepositsUSD: p.shortTotalDepositsUSD,
227
+ totalDebtUSD: p.shortTotalDebtUSD,
228
+ totalLiquidityUSD: p.shortTotalLiquidityUSD
229
+ }, shortThresholds);
230
+
231
+ if (!longMeetsThresholds || !shortMeetsThresholds) {
232
+ return false;
233
+ }
234
+
235
+ return true;
236
+ })
237
+ .sort((a, b) => b.apr - a.apr)
238
+ .slice(0, MAX_ENTRIES);
239
+ }
240
+
165
241
  export function getTopPairs(pairs: LendingPair[]) {
166
- const stables = pairs.filter(p => p.assetGroupLong?.includes("USD") && p.assetGroupShort?.includes("USD") && !p.assetGroupShort?.includes("PT-")).sort((a, b) => a.apr > b.apr ? -1 : 1).slice(0, MAX_ENTRIES)
167
- const btcLst = pairs.filter(p => p.assetGroupLong?.includes("BTC") && p.assetGroupShort?.includes("BTC") && !p.assetGroupShort?.includes("PT-")).sort((a, b) => a.apr > b.apr ? -1 : 1).slice(0, MAX_ENTRIES)
168
- const ethLst = pairs.filter(p => p.assetGroupLong?.includes("ETH") && p.assetGroupShort?.includes("ETH") && !p.assetGroupShort?.includes("PT-")).sort((a, b) => a.apr > b.apr ? -1 : 1).slice(0, MAX_ENTRIES)
242
+ const stables = filterPairsByCategory(
243
+ pairs,
244
+ (group) => group?.includes("USD") ?? false,
245
+ (group) => group?.includes("USD") ?? false
246
+ );
247
+
248
+ const btcLst = filterPairsByCategory(
249
+ pairs,
250
+ (group) => group?.includes("BTC") ?? false,
251
+ (group) => group?.includes("BTC") ?? false
252
+ );
253
+
254
+ const ethLst = filterPairsByCategory(
255
+ pairs,
256
+ (group) => group?.includes("ETH") ?? false,
257
+ (group) => group?.includes("ETH") ?? false
258
+ );
169
259
 
170
260
  return {
171
261
  stables,
@@ -182,7 +272,47 @@ function isStable(assetGroup: string): boolean {
182
272
  export function getDistinctPairsByShortAsset(
183
273
  pairs: LendingPair[],
184
274
  ): LendingPair[] {
185
- const sorted = [...pairs].sort((a, b) =>
275
+ const qualityPairs = pairs.filter(p => {
276
+ if (!isFinite(p.apr) || !isFinite(p.priceChange)) {
277
+ return false;
278
+ }
279
+
280
+ if (!p.longIsActive || p.longIsFrozen || !p.shortIsActive || p.shortIsFrozen) {
281
+ return false;
282
+ }
283
+
284
+ if (!p.shortBorrowingEnabled) {
285
+ return false;
286
+ }
287
+
288
+ // Apply liquidity thresholds
289
+ const longThresholds = getLiquidityThresholds(p.chainId, p.assetLong, p.assetGroupLong);
290
+ const shortThresholds = getLiquidityThresholds(p.chainId, p.assetShort, p.assetGroupShort);
291
+
292
+ const longMeetsThresholds = meetsLiquidityThresholds({
293
+ totalDepositsUSD: p.longTotalDepositsUSD,
294
+ totalDebtUSD: p.longTotalDebtUSD,
295
+ totalLiquidityUSD: p.longTotalLiquidityUSD
296
+ }, longThresholds);
297
+
298
+ const shortMeetsThresholds = meetsLiquidityThresholds({
299
+ totalDepositsUSD: p.shortTotalDepositsUSD,
300
+ totalDebtUSD: p.shortTotalDebtUSD,
301
+ totalLiquidityUSD: p.shortTotalLiquidityUSD
302
+ }, shortThresholds);
303
+
304
+ if (!longMeetsThresholds || !shortMeetsThresholds) {
305
+ return false;
306
+ }
307
+
308
+ if (p.assetGroupShort?.includes("PT-") || p.assetGroupLong?.includes("PT-")) {
309
+ return false;
310
+ }
311
+
312
+ return true;
313
+ });
314
+
315
+ const sorted = [...qualityPairs].sort((a, b) =>
186
316
  b.priceChange - a.priceChange
187
317
  );
188
318