@1delta/margin-fetcher 0.0.8 → 0.0.10
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.
- package/dist/abis/aave/AaveOracle.d.ts +10 -0
- package/dist/abis/aave/AaveOracle.d.ts.map +1 -1
- package/dist/abis/aave/AaveOracle.js +13 -0
- package/dist/abis/morpho/blue.d.ts +76 -0
- package/dist/abis/morpho/blue.d.ts.map +1 -0
- package/dist/abis/morpho/blue.js +99 -0
- package/dist/abis/morpho/lens.d.ts +16 -0
- package/dist/abis/morpho/lens.d.ts.map +1 -0
- package/dist/abis/morpho/lens.js +31 -0
- package/dist/abis/oracle/AaveOracle.d.ts +10 -0
- package/dist/abis/oracle/AaveOracle.d.ts.map +1 -1
- package/dist/abis/oracle/AaveOracle.js +13 -0
- package/dist/assets/index.d.ts +4 -4
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +7 -7
- package/dist/assets/liquidityThresholds.d.ts +29 -0
- package/dist/assets/liquidityThresholds.d.ts.map +1 -0
- package/dist/assets/liquidityThresholds.js +51 -0
- package/dist/flash-liquidity/index.d.ts +1 -0
- package/dist/flash-liquidity/index.d.ts.map +1 -1
- package/dist/flash-liquidity/index.js +1 -0
- package/dist/flash-liquidity/utils.d.ts +11 -0
- package/dist/flash-liquidity/utils.d.ts.map +1 -0
- package/dist/flash-liquidity/utils.js +17 -0
- package/dist/lending/aave-v2-type/publicCallParse.d.ts +2 -1
- package/dist/lending/aave-v2-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v2-type/publicCallParse.js +10 -7
- package/dist/lending/aave-v3-type/publicCallParse.d.ts +3 -2
- package/dist/lending/aave-v3-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v3-type/publicCallParse.js +11 -8
- package/dist/lending/aave-v3-type/types.d.ts +2 -0
- package/dist/lending/aave-v3-type/types.d.ts.map +1 -1
- package/dist/lending/addresses/compoundV3.d.ts +1 -1
- package/dist/lending/addresses/compoundV3.d.ts.map +1 -1
- package/dist/lending/addresses/compoundV3.js +8 -7
- package/dist/lending/compound-v3/publicCallParse.d.ts +2 -1
- package/dist/lending/compound-v3/publicCallParse.d.ts.map +1 -1
- package/dist/lending/compound-v3/publicCallParse.js +3 -2
- package/dist/lending/compound-v3/types.d.ts +2 -0
- package/dist/lending/compound-v3/types.d.ts.map +1 -1
- package/dist/lending/fetchLender.d.ts +2 -1
- package/dist/lending/fetchLender.d.ts.map +1 -1
- package/dist/lending/fetchLender.js +12 -8
- package/dist/lending/fetchLenderAll.d.ts +8 -0
- package/dist/lending/fetchLenderAll.d.ts.map +1 -0
- package/dist/lending/fetchLenderAll.js +12 -0
- package/dist/lending/fetchLenderExt.d.ts +8 -0
- package/dist/lending/fetchLenderExt.d.ts.map +1 -0
- package/dist/lending/fetchLenderExt.js +28 -0
- package/dist/lending/index.d.ts +1 -0
- package/dist/lending/index.d.ts.map +1 -1
- package/dist/lending/index.js +1 -0
- package/dist/lending/init/publicCallParse.d.ts +2 -1
- package/dist/lending/init/publicCallParse.d.ts.map +1 -1
- package/dist/lending/init/publicCallParse.js +3 -2
- package/dist/lending/init/types.d.ts +2 -0
- package/dist/lending/init/types.d.ts.map +1 -1
- package/dist/lending/morpho/convertPublic.d.ts +9 -0
- package/dist/lending/morpho/convertPublic.d.ts.map +1 -0
- package/dist/lending/morpho/convertPublic.js +115 -0
- package/dist/lending/morpho/fetchPublic.d.ts +3 -0
- package/dist/lending/morpho/fetchPublic.d.ts.map +1 -0
- package/dist/lending/morpho/fetchPublic.js +72 -0
- package/dist/lending/morpho/publicCallBuild.d.ts +8 -0
- package/dist/lending/morpho/publicCallBuild.d.ts.map +1 -0
- package/dist/lending/morpho/publicCallBuild.js +6 -0
- package/dist/lending/morpho/types.d.ts +106 -0
- package/dist/lending/morpho/types.d.ts.map +1 -0
- package/dist/lending/morpho/types.js +1 -0
- package/dist/lending/types/index.d.ts +18 -0
- package/dist/lending/types/index.d.ts.map +1 -0
- package/dist/lending/types/index.js +1 -0
- package/dist/lending/user-data/aave-v2-type/userCallBuild.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v2-type/userCallBuild.js +4 -23
- package/dist/lending/user-data/aave-v2-type/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v2-type/userCallParse.js +24 -11
- package/dist/lending/user-data/aave-v3-type/userCallBuild.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v3-type/userCallBuild.js +1 -16
- package/dist/lending/user-data/aave-v3-type/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v3-type/userCallParse.js +13 -6
- package/dist/lending/user-data/aave-v3-type/userCallParseYldr.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v3-type/userCallParseYldr.js +12 -6
- package/dist/lending/user-data/compound-v3/addresses.d.ts.map +1 -1
- package/dist/lending/user-data/compound-v3/addresses.js +8 -7
- package/dist/lending/user-data/compound-v3/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/compound-v3/userCallParse.js +2 -0
- package/dist/lending/user-data/morpho/decoder.d.ts +21 -0
- package/dist/lending/user-data/morpho/decoder.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/decoder.js +52 -0
- package/dist/lending/user-data/morpho/morphoLib.d.ts +5 -0
- package/dist/lending/user-data/morpho/morphoLib.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/morphoLib.js +21 -0
- package/dist/lending/user-data/morpho/types.d.ts +12 -0
- package/dist/lending/user-data/morpho/types.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/types.js +13 -0
- package/dist/lending/user-data/morpho/userCallBuild.d.ts +6 -0
- package/dist/lending/user-data/morpho/userCallBuild.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/userCallBuild.js +36 -0
- package/dist/lending/user-data/morpho/userCallParse.d.ts +11 -0
- package/dist/lending/user-data/morpho/userCallParse.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/userCallParse.js +99 -0
- package/dist/lending/user-data/morpho/userCallParseNoDeploy.d.ts +11 -0
- package/dist/lending/user-data/morpho/userCallParseNoDeploy.d.ts.map +1 -0
- package/dist/lending/user-data/morpho/userCallParseNoDeploy.js +112 -0
- package/dist/lending-pairs/computeLendingPairs.d.ts +13 -0
- package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
- package/dist/lending-pairs/computeLendingPairs.js +129 -23
- package/dist/prices/main-prices/fetchOracleData.d.ts +1 -2
- package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
- package/dist/prices/main-prices/fetchOracleData.js +95 -55
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +41 -16
- package/dist/utils/parsing.d.ts.map +1 -1
- package/dist/utils/parsing.js +4 -2
- package/package.json +2 -2
- package/src/abis/aave/AaveOracle.ts +13 -0
- package/src/abis/oracle/AaveOracle.ts +13 -0
- package/src/assets/index.ts +70 -51
- package/src/assets/liquidityThresholds.ts +83 -0
- package/src/flash-liquidity/index.ts +2 -1
- package/src/flash-liquidity/utils.ts +22 -0
- package/src/lending/aave-v2-type/publicCallParse.ts +12 -7
- package/src/lending/aave-v3-type/publicCallParse.ts +13 -8
- package/src/lending/aave-v3-type/types.ts +2 -0
- package/src/lending/addresses/compoundV3.ts +29 -15
- package/src/lending/compound-v3/publicCallParse.ts +5 -2
- package/src/lending/compound-v3/types.ts +2 -0
- package/src/lending/fetchLender.ts +23 -17
- package/src/lending/index.ts +2 -1
- package/src/lending/init/publicCallParse.ts +5 -2
- package/src/lending/init/types.ts +3 -0
- package/src/lending/types/index.ts +16 -0
- package/src/lending/user-data/aave-v2-type/userCallBuild.ts +1 -25
- package/src/lending/user-data/aave-v2-type/userCallParse.ts +24 -11
- package/src/lending/user-data/aave-v3-type/userCallBuild.ts +1 -16
- package/src/lending/user-data/aave-v3-type/userCallParse.ts +15 -6
- package/src/lending/user-data/aave-v3-type/userCallParseYldr.ts +14 -6
- package/src/lending/user-data/compound-v3/addresses.ts +58 -39
- package/src/lending/user-data/compound-v3/userCallParse.ts +2 -2
- package/src/lending-pairs/computeLendingPairs.ts +421 -189
- package/src/prices/main-prices/fetchOracleData.ts +197 -107
- package/src/utils/index.ts +90 -58
- package/src/utils/parsing.ts +51 -51
- package/test/index.test.ts +15 -7
- package/test/userdata.test.ts +5 -5
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { getAssetMeta, toGenericPriceKey, toOracleKey } from "../assets";
|
|
2
|
+
import { getLiquidityThresholds, meetsLiquidityThresholds, } from "../assets/liquidityThresholds";
|
|
2
3
|
import { isAaveV3Type, isInit } from "../utils";
|
|
3
|
-
const isEMode = (longData, shortData) => Boolean(longData.eMode)
|
|
4
|
-
Number(longData.eMode?.category) > 0 &&
|
|
4
|
+
const isEMode = (longData, shortData) => Boolean(longData.eMode)
|
|
5
|
+
? Number(longData.eMode?.category) > 0 &&
|
|
6
|
+
Number(longData.eMode?.category) === shortData.eMode?.category
|
|
7
|
+
: false;
|
|
5
8
|
const intersection = (a0, a1) => {
|
|
6
|
-
return a0.filter(a => a1.includes(a));
|
|
9
|
+
return a0.filter((a) => a1.includes(a));
|
|
7
10
|
};
|
|
8
11
|
const LENDER_MODE_NO_MODE = 0;
|
|
9
12
|
// calculate the maximum leverage for a given pair
|
|
10
13
|
const getMaxLeverage = (lender, longData, shortData) => {
|
|
11
14
|
// for Aave V3 we check for eModes
|
|
12
15
|
if (isAaveV3Type(lender)) {
|
|
13
|
-
const cf = isEMode(longData, shortData)
|
|
14
|
-
longData.config[longData.eMode?.category ?? 0]?.borrowCollateralFactor
|
|
15
|
-
longData.config[LENDER_MODE_NO_MODE]?.borrowCollateralFactor;
|
|
16
|
+
const cf = isEMode(longData, shortData)
|
|
17
|
+
? longData.config[longData.eMode?.category ?? 0]?.borrowCollateralFactor
|
|
18
|
+
: longData.config[LENDER_MODE_NO_MODE]?.borrowCollateralFactor;
|
|
16
19
|
return 1 / (1 - cf);
|
|
17
20
|
}
|
|
18
21
|
// for init, we match the modes and find the one with the highest collatearal factor
|
|
@@ -20,11 +23,13 @@ const getMaxLeverage = (lender, longData, shortData) => {
|
|
|
20
23
|
const modeIntersect = intersection(Object.values(longData.config).map((c) => c.category), Object.values(shortData.config).map((c) => c.category));
|
|
21
24
|
if (modeIntersect.length === 0)
|
|
22
25
|
return 1;
|
|
23
|
-
const configId = Object.values(longData.config)
|
|
26
|
+
const configId = Object.values(longData.config)
|
|
27
|
+
.filter((c) => modeIntersect.includes(c.category))
|
|
28
|
+
.sort((c, d) => c.borrowCollateralFactor < d.borrowCollateralFactor ? 1 : -1)[0].category;
|
|
24
29
|
// we have to use the adjusted formula with the borrowFactor here
|
|
25
30
|
const cf = longData.config[configId]?.borrowCollateralFactor;
|
|
26
31
|
const bf = shortData.config[configId]?.borrowFactor;
|
|
27
|
-
return 1 / (1 -
|
|
32
|
+
return 1 / (1 - cf / bf);
|
|
28
33
|
}
|
|
29
34
|
// all other cases use the default mode no_mode without borrowFactor
|
|
30
35
|
const cf = longData?.config?.[LENDER_MODE_NO_MODE]?.borrowCollateralFactor ?? 0.8;
|
|
@@ -35,17 +40,19 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
35
40
|
const pairs = [];
|
|
36
41
|
for (const chainId in lenderData) {
|
|
37
42
|
const chainEntry = lenderData[chainId];
|
|
38
|
-
const lenderToData =
|
|
43
|
+
const lenderToData = chainEntry.data ?? chainEntry;
|
|
39
44
|
for (const lender in lenderToData) {
|
|
40
45
|
const lenderEntry = lenderToData[lender];
|
|
41
46
|
// protect agaist error data
|
|
42
|
-
|
|
43
|
-
let pools = Object.values(lenderEntry?.data ?? lenderEntry ?? {}).map(a => a?.data ? a.data : a);
|
|
47
|
+
let pools = Object.values(lenderEntry?.data ?? lenderEntry ?? {}).map((a) => (a?.data ? a.data : a));
|
|
44
48
|
// sometimes error messages are included
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
const hasErrorMessages = pools.some((p) => typeof p === "string" &&
|
|
50
|
+
(p.includes("No lenders available") || p.includes("Failed to fetch")));
|
|
51
|
+
if (hasErrorMessages)
|
|
47
52
|
continue;
|
|
48
|
-
|
|
53
|
+
// cast to poolData
|
|
54
|
+
const validPools = pools.filter((p) => typeof p === "object" && p !== null);
|
|
55
|
+
const poolArray = validPools.filter((p) => !p?.isFrozen);
|
|
49
56
|
// Loop through all ordered pairs of pools
|
|
50
57
|
for (let i = 0; i < poolArray.length; i++) {
|
|
51
58
|
for (let j = 0; j < poolArray.length; j++) {
|
|
@@ -59,7 +66,7 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
59
66
|
if (long.underlying === short.underlying)
|
|
60
67
|
continue;
|
|
61
68
|
const maxDepositLeverage = getMaxLeverage(lender, long, short);
|
|
62
|
-
const borrowLeverage =
|
|
69
|
+
const borrowLeverage = maxDepositLeverage - 1;
|
|
63
70
|
const depositLeverage = borrowLeverage + 1;
|
|
64
71
|
let collateralRewards = 0;
|
|
65
72
|
let borrowRewards = 0;
|
|
@@ -77,7 +84,8 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
77
84
|
: baseYields.variableBorrowRate;
|
|
78
85
|
borrowRewards += borrowRate;
|
|
79
86
|
if (borrowRate != 0)
|
|
80
|
-
rewards[rewardId] =
|
|
87
|
+
rewards[rewardId] =
|
|
88
|
+
(rewards[rewardId] ?? 0) + borrowRate * borrowLeverage;
|
|
81
89
|
}
|
|
82
90
|
const depositApr = long.depositRate + long.stakingYield;
|
|
83
91
|
const borrowApr = short.variableBorrowRate + short.stakingYield;
|
|
@@ -89,6 +97,13 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
89
97
|
const price24hShort = histPrices[keyShort] ?? priceShort;
|
|
90
98
|
const price = priceShort !== 0 ? priceLong / priceShort : 0;
|
|
91
99
|
const price24h = price24hShort !== 0 ? price24hLong / price24hShort : 0;
|
|
100
|
+
// only base apr
|
|
101
|
+
const baseApr = depositApr * depositLeverage - borrowApr * borrowLeverage;
|
|
102
|
+
// only rewards apr
|
|
103
|
+
const rewardApr = collateralRewards * depositLeverage +
|
|
104
|
+
borrowRewards * borrowLeverage;
|
|
105
|
+
// total apr
|
|
106
|
+
const totalApr = baseApr + rewardApr;
|
|
92
107
|
pairs.push({
|
|
93
108
|
chainId,
|
|
94
109
|
lender,
|
|
@@ -100,8 +115,21 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
100
115
|
assetGroupShort,
|
|
101
116
|
priceChange: price24h === 0 ? 0 : (price - price24h) / price24h,
|
|
102
117
|
maxLeverage: maxDepositLeverage,
|
|
103
|
-
apr:
|
|
104
|
-
|
|
118
|
+
apr: totalApr,
|
|
119
|
+
baseApr,
|
|
120
|
+
rewardApr,
|
|
121
|
+
eMode: long.eMode?.category ?? 0,
|
|
122
|
+
longTotalDepositsUSD: long.totalDepositsUSD,
|
|
123
|
+
longTotalDebtUSD: long.totalDebtUSD,
|
|
124
|
+
longTotalLiquidityUSD: long.totalLiquidityUSD,
|
|
125
|
+
shortTotalDepositsUSD: short.totalDepositsUSD,
|
|
126
|
+
shortTotalDebtUSD: short.totalDebtUSD,
|
|
127
|
+
shortTotalLiquidityUSD: short.totalLiquidityUSD,
|
|
128
|
+
longIsActive: long.isActive,
|
|
129
|
+
longIsFrozen: long.isFrozen,
|
|
130
|
+
shortIsActive: short.isActive,
|
|
131
|
+
shortIsFrozen: short.isFrozen,
|
|
132
|
+
shortBorrowingEnabled: short.borrowingEnabled,
|
|
105
133
|
});
|
|
106
134
|
}
|
|
107
135
|
}
|
|
@@ -111,13 +139,56 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
111
139
|
}
|
|
112
140
|
function getPriceKey(asset, chainId) {
|
|
113
141
|
const assetGroup = getAssetMeta(chainId, asset)?.assetGroup;
|
|
114
|
-
return [
|
|
142
|
+
return [
|
|
143
|
+
assetGroup,
|
|
144
|
+
toOracleKey(assetGroup) ?? toGenericPriceKey(asset, chainId),
|
|
145
|
+
];
|
|
115
146
|
}
|
|
116
147
|
const MAX_ENTRIES = 10;
|
|
148
|
+
function filterPairsByCategory(pairs, longFilter, shortFilter) {
|
|
149
|
+
return pairs
|
|
150
|
+
.filter((p) => {
|
|
151
|
+
if (!longFilter(p.assetGroupLong) || !shortFilter(p.assetGroupShort)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (p.assetGroupShort?.includes("PT-") ||
|
|
155
|
+
p.assetGroupLong?.includes("PT-")) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (!p.longIsActive ||
|
|
159
|
+
p.longIsFrozen ||
|
|
160
|
+
!p.shortIsActive ||
|
|
161
|
+
p.shortIsFrozen) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
if (!p.shortBorrowingEnabled) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
// apply liquidity thresholds
|
|
168
|
+
const longThresholds = getLiquidityThresholds(p.chainId, p.assetLong, p.assetGroupLong);
|
|
169
|
+
const shortThresholds = getLiquidityThresholds(p.chainId, p.assetShort, p.assetGroupShort);
|
|
170
|
+
const longMeetsThresholds = meetsLiquidityThresholds({
|
|
171
|
+
totalDepositsUSD: p.longTotalDepositsUSD,
|
|
172
|
+
totalDebtUSD: p.longTotalDebtUSD,
|
|
173
|
+
totalLiquidityUSD: p.longTotalLiquidityUSD,
|
|
174
|
+
}, longThresholds);
|
|
175
|
+
const shortMeetsThresholds = meetsLiquidityThresholds({
|
|
176
|
+
totalDepositsUSD: p.shortTotalDepositsUSD,
|
|
177
|
+
totalDebtUSD: p.shortTotalDebtUSD,
|
|
178
|
+
totalLiquidityUSD: p.shortTotalLiquidityUSD,
|
|
179
|
+
}, shortThresholds);
|
|
180
|
+
if (!longMeetsThresholds || !shortMeetsThresholds) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
return true;
|
|
184
|
+
})
|
|
185
|
+
.sort((a, b) => b.apr - a.apr)
|
|
186
|
+
.slice(0, MAX_ENTRIES);
|
|
187
|
+
}
|
|
117
188
|
export function getTopPairs(pairs) {
|
|
118
|
-
const stables = pairs
|
|
119
|
-
const btcLst = pairs
|
|
120
|
-
const ethLst = pairs
|
|
189
|
+
const stables = filterPairsByCategory(pairs, (group) => group?.includes("USD") ?? false, (group) => group?.includes("USD") ?? false);
|
|
190
|
+
const btcLst = filterPairsByCategory(pairs, (group) => group?.includes("BTC") ?? false, (group) => group?.includes("BTC") ?? false);
|
|
191
|
+
const ethLst = filterPairsByCategory(pairs, (group) => group?.includes("ETH") ?? false, (group) => group?.includes("ETH") ?? false);
|
|
121
192
|
return {
|
|
122
193
|
stables,
|
|
123
194
|
btcLst,
|
|
@@ -129,7 +200,42 @@ function isStable(assetGroup) {
|
|
|
129
200
|
return assetGroup.includes("USD");
|
|
130
201
|
}
|
|
131
202
|
export function getDistinctPairsByShortAsset(pairs) {
|
|
132
|
-
const
|
|
203
|
+
const qualityPairs = pairs.filter((p) => {
|
|
204
|
+
if (!isFinite(p.apr) || !isFinite(p.priceChange)) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
if (!p.longIsActive ||
|
|
208
|
+
p.longIsFrozen ||
|
|
209
|
+
!p.shortIsActive ||
|
|
210
|
+
p.shortIsFrozen) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
if (!p.shortBorrowingEnabled) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
// Apply liquidity thresholds
|
|
217
|
+
const longThresholds = getLiquidityThresholds(p.chainId, p.assetLong, p.assetGroupLong);
|
|
218
|
+
const shortThresholds = getLiquidityThresholds(p.chainId, p.assetShort, p.assetGroupShort);
|
|
219
|
+
const longMeetsThresholds = meetsLiquidityThresholds({
|
|
220
|
+
totalDepositsUSD: p.longTotalDepositsUSD,
|
|
221
|
+
totalDebtUSD: p.longTotalDebtUSD,
|
|
222
|
+
totalLiquidityUSD: p.longTotalLiquidityUSD,
|
|
223
|
+
}, longThresholds);
|
|
224
|
+
const shortMeetsThresholds = meetsLiquidityThresholds({
|
|
225
|
+
totalDepositsUSD: p.shortTotalDepositsUSD,
|
|
226
|
+
totalDebtUSD: p.shortTotalDebtUSD,
|
|
227
|
+
totalLiquidityUSD: p.shortTotalLiquidityUSD,
|
|
228
|
+
}, shortThresholds);
|
|
229
|
+
if (!longMeetsThresholds || !shortMeetsThresholds) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (p.assetGroupShort?.includes("PT-") ||
|
|
233
|
+
p.assetGroupLong?.includes("PT-")) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
});
|
|
238
|
+
const sorted = [...qualityPairs].sort((a, b) => b.priceChange - a.priceChange);
|
|
133
239
|
const blacklist = new Set();
|
|
134
240
|
const blacklistLong = new Set();
|
|
135
241
|
const result = [];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GetEvmClientFunction } from '../../types';
|
|
2
|
-
export declare const formatAavePrice: (price: string,
|
|
3
|
-
export declare const parseRawAmount: (answer?: string, decimals?: number) => number;
|
|
2
|
+
export declare const formatAavePrice: (price: string, isV2?: boolean) => number;
|
|
4
3
|
interface OracleData {
|
|
5
4
|
[key: string]: number;
|
|
6
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchOracleData.d.ts","sourceRoot":"","sources":["../../../src/prices/main-prices/fetchOracleData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchOracleData.d.ts","sourceRoot":"","sources":["../../../src/prices/main-prices/fetchOracleData.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGlD,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,cAAY,KAAG,MAQ7D,CAAA;AAOD,UAAU,UAAU;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB;AAID;;GAEG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,MAAM,EAAE,EAClB,cAAc,oBAAoB,KACjC,OAAO,CAAC,UAAU,CA8GpB,CAAA"}
|
|
@@ -5,27 +5,18 @@ import { Api3OracleAbi } from '../../abis/oracle/Api3Oracle';
|
|
|
5
5
|
import { RWADynamicOracleAbi } from '../../abis/oracle/RWADynamicOracle';
|
|
6
6
|
import { api3OracleAddresses } from './addresses/api3';
|
|
7
7
|
import { AAVE_V2_LENDERS, ASSET_META, Chain } from '@1delta/asset-registry';
|
|
8
|
-
import { formatEther
|
|
8
|
+
import { formatEther } from 'viem';
|
|
9
9
|
import { getAaveAssets } from '../../assets';
|
|
10
|
-
import { chainlinkOracles, getChainLinkKeys, ChainlinkAggregatorIndexes } from './addresses/chainlink';
|
|
10
|
+
import { chainlinkOracles, getChainLinkKeys, ChainlinkAggregatorIndexes, } from './addresses/chainlink';
|
|
11
11
|
import { fetchDefillamaData } from '../defillama';
|
|
12
12
|
import { multicallViemAbiArray } from '../../utils/multicall';
|
|
13
13
|
import { AAVE_STYLE_ORACLES } from './addresses/aaveOracles';
|
|
14
14
|
import { AAVES_PER_CHAIN } from '../../utils';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export const parseRawAmount = (answer, decimals = 18) => {
|
|
21
|
-
if (!answer || answer === "0x")
|
|
22
|
-
return 0;
|
|
23
|
-
try {
|
|
24
|
-
return Number(formatUnits(BigInt(answer ?? '0'), decimals ?? 18));
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
return 0;
|
|
28
|
-
}
|
|
15
|
+
import { parseRawAmount } from '../../utils/parsing';
|
|
16
|
+
export const formatAavePrice = (price, isV2 = false) => {
|
|
17
|
+
return Number(formatEther(BigInt(price ?? '0') *
|
|
18
|
+
// 10^(18 - decimals)
|
|
19
|
+
10n ** (isV2 ? 0n : 10n)));
|
|
29
20
|
};
|
|
30
21
|
const LENDLE_PAIR_MANTLE = '0x4c57BE599d0e0414785943569E9B6A66dA79Aa6b';
|
|
31
22
|
const AU_PAIR_MANTLE = '0x709503fbb50b10f921e812c48fbd5c5522a0b20c';
|
|
@@ -35,16 +26,20 @@ const RWA_DYNAMIC_ORACLE = '0xA96abbe61AfEdEB0D14a20440Ae7100D9aB4882f';
|
|
|
35
26
|
* Fetches Aave and uniswap V2 oracle data
|
|
36
27
|
*/
|
|
37
28
|
export const fetchMainPrices = async (chainIds, getEvmClient) => {
|
|
38
|
-
let promises = chainIds.map(chainId => {
|
|
29
|
+
let promises = chainIds.map((chainId) => {
|
|
39
30
|
const aaveForks = AAVES_PER_CHAIN[chainId];
|
|
40
|
-
let reservesToQuery = aaveForks.map(a => ({ fork: a, assets: getAaveAssets(chainId, a) }));
|
|
31
|
+
let reservesToQuery = aaveForks.map((a) => ({ fork: a, assets: getAaveAssets(chainId, a) }));
|
|
41
32
|
let handled = [];
|
|
42
33
|
let queries = [];
|
|
43
|
-
reservesToQuery.forEach(e => {
|
|
44
|
-
const newOnes = e.assets.filter(a => !handled.includes(a));
|
|
34
|
+
reservesToQuery.forEach((e) => {
|
|
35
|
+
const newOnes = e.assets.filter((a) => !handled.includes(a));
|
|
45
36
|
if (newOnes.length > 0) {
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
queries.push({
|
|
38
|
+
assets: newOnes,
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
oracle: AAVE_STYLE_ORACLES[e.fork][chainId],
|
|
41
|
+
fork: e.fork,
|
|
42
|
+
});
|
|
48
43
|
handled = [...handled, ...newOnes];
|
|
49
44
|
}
|
|
50
45
|
});
|
|
@@ -53,25 +48,53 @@ export const fetchMainPrices = async (chainIds, getEvmClient) => {
|
|
|
53
48
|
const uniswapV2Calls = getUniswapV2Calls(chainId);
|
|
54
49
|
const [api3Calls, api3Names] = getApi3Calls(chainId);
|
|
55
50
|
const [rwaCalls, rwaNames] = getRWADynamicOracleCalls(chainId);
|
|
56
|
-
return multicallViemAbiArray(chainId, [
|
|
51
|
+
return multicallViemAbiArray(chainId, [
|
|
52
|
+
...ChainLinkAggregatorAbi,
|
|
53
|
+
...UniswapV2PairAbi,
|
|
54
|
+
...AaveOracleAbi,
|
|
55
|
+
...Api3OracleAbi,
|
|
56
|
+
...RWADynamicOracleAbi,
|
|
57
|
+
], [
|
|
58
|
+
...callsChainLink,
|
|
59
|
+
...callAave,
|
|
60
|
+
...uniswapV2Calls,
|
|
61
|
+
...api3Calls,
|
|
62
|
+
...rwaCalls,
|
|
63
|
+
], getEvmClient).then((multicallResult) => {
|
|
57
64
|
const chainLinkResults = multicallResult.slice(0, callsChainLink.length);
|
|
58
65
|
const aaveResult = multicallResult.slice(callsChainLink.length, callsChainLink.length + callAave.length);
|
|
59
66
|
const chainLinkData = parseChainLinkResults(chainId, chainLinkResults, chainLinkNames);
|
|
60
67
|
// @ts-ignore
|
|
61
68
|
const aaveData = parseAaveResults(chainId, aaveResult, queries);
|
|
62
69
|
const uniswapResult = multicallResult.slice(callsChainLink.length + callAave.length, callsChainLink.length + callAave.length + uniswapV2Calls.length);
|
|
63
|
-
const api3Result = multicallResult.slice(callsChainLink.length + callAave.length + uniswapV2Calls.length, callsChainLink.length +
|
|
70
|
+
const api3Result = multicallResult.slice(callsChainLink.length + callAave.length + uniswapV2Calls.length, callsChainLink.length +
|
|
71
|
+
callAave.length +
|
|
72
|
+
uniswapV2Calls.length +
|
|
73
|
+
api3Calls.length);
|
|
64
74
|
const uniswapData = parseUniswapV2results(uniswapResult, chainId);
|
|
65
75
|
const api3Data = parseApi3Results(chainId, api3Result, api3Names);
|
|
66
|
-
const rwaResult = multicallResult.slice(callsChainLink.length +
|
|
76
|
+
const rwaResult = multicallResult.slice(callsChainLink.length +
|
|
77
|
+
callAave.length +
|
|
78
|
+
uniswapV2Calls.length +
|
|
79
|
+
api3Calls.length, callsChainLink.length +
|
|
80
|
+
callAave.length +
|
|
81
|
+
uniswapV2Calls.length +
|
|
82
|
+
api3Calls.length +
|
|
83
|
+
rwaCalls.length);
|
|
67
84
|
const rwaData = parseRWADynamicOracleResults(chainId, rwaResult, rwaNames);
|
|
68
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
...uniswapData,
|
|
87
|
+
...aaveData,
|
|
88
|
+
...chainLinkData,
|
|
89
|
+
...api3Data,
|
|
90
|
+
...rwaData,
|
|
91
|
+
};
|
|
69
92
|
});
|
|
70
93
|
});
|
|
71
94
|
promises.push(fetchDefillamaData());
|
|
72
95
|
const result = await Promise.all(promises);
|
|
73
96
|
let data = {};
|
|
74
|
-
result.forEach(r => {
|
|
97
|
+
result.forEach((r) => {
|
|
75
98
|
data = { ...data, ...r };
|
|
76
99
|
});
|
|
77
100
|
return data;
|
|
@@ -88,17 +111,17 @@ const getUniswapV2Calls = (chainId) => {
|
|
|
88
111
|
{
|
|
89
112
|
address: WMNT_USDT_PAIR,
|
|
90
113
|
name: 'getReserves',
|
|
91
|
-
params: []
|
|
114
|
+
params: [],
|
|
92
115
|
},
|
|
93
116
|
{
|
|
94
117
|
address: LENDLE_PAIR_MANTLE,
|
|
95
118
|
name: 'getReserves',
|
|
96
|
-
params: []
|
|
119
|
+
params: [],
|
|
97
120
|
},
|
|
98
121
|
{
|
|
99
122
|
address: AU_PAIR_MANTLE,
|
|
100
123
|
name: 'getReserves',
|
|
101
|
-
params: []
|
|
124
|
+
params: [],
|
|
102
125
|
},
|
|
103
126
|
];
|
|
104
127
|
default:
|
|
@@ -114,11 +137,13 @@ const getUniswapV2Calls = (chainId) => {
|
|
|
114
137
|
const getAaveCalls = (query) => {
|
|
115
138
|
if (query.length === 0)
|
|
116
139
|
return [];
|
|
117
|
-
return query
|
|
140
|
+
return query
|
|
141
|
+
.map(({ oracle, assets }) => ({
|
|
118
142
|
address: oracle,
|
|
119
143
|
name: 'getAssetsPrices',
|
|
120
144
|
params: [assets],
|
|
121
|
-
}))
|
|
145
|
+
}))
|
|
146
|
+
.flat();
|
|
122
147
|
};
|
|
123
148
|
/**
|
|
124
149
|
* Create calldata for chainLink oracles
|
|
@@ -131,7 +156,7 @@ const getChainLinkCalls = (chainId) => {
|
|
|
131
156
|
case Chain.MANTLE:
|
|
132
157
|
return [[], []];
|
|
133
158
|
default: {
|
|
134
|
-
const keys = getChainLinkKeys(chainId).filter(k => k.split('-')[1] === 'USD');
|
|
159
|
+
const keys = getChainLinkKeys(chainId).filter((k) => k.split('-')[1] === 'USD');
|
|
135
160
|
// @ts-ignore
|
|
136
161
|
const addresses = keys.map((k) => chainlinkOracles[k][chainId]);
|
|
137
162
|
return [
|
|
@@ -142,7 +167,7 @@ const getChainLinkCalls = (chainId) => {
|
|
|
142
167
|
params: [],
|
|
143
168
|
};
|
|
144
169
|
}),
|
|
145
|
-
keys.map(k => k.split('-')[0])
|
|
170
|
+
keys.map((k) => k.split('-')[0]),
|
|
146
171
|
];
|
|
147
172
|
}
|
|
148
173
|
}
|
|
@@ -160,16 +185,16 @@ const parseUniswapV2results = (data, chainId) => {
|
|
|
160
185
|
if (data.length > 0) {
|
|
161
186
|
const reserves = data[1];
|
|
162
187
|
// lendle and wmnt are respective token0s
|
|
163
|
-
const lendleReserve = parseRawAmount(reserves[0].toString(), 18);
|
|
164
|
-
const wmntReserve = parseRawAmount(reserves[1].toString(), 18);
|
|
188
|
+
const lendleReserve = Number(parseRawAmount(reserves[0].toString(), 18));
|
|
189
|
+
const wmntReserve = Number(parseRawAmount(reserves[1].toString(), 18));
|
|
165
190
|
const auReserves = data[2];
|
|
166
|
-
const auReserve = parseRawAmount(auReserves[1].toString(), 18);
|
|
167
|
-
const wmntReserve_au = parseRawAmount(auReserves[0].toString(), 18);
|
|
191
|
+
const auReserve = Number(parseRawAmount(auReserves[1].toString(), 18));
|
|
192
|
+
const wmntReserve_au = Number(parseRawAmount(auReserves[0].toString(), 18));
|
|
168
193
|
const reservesWmntUsdt = data[0];
|
|
169
|
-
const usdtReserve = parseRawAmount(reservesWmntUsdt[0].toString(), 6);
|
|
170
|
-
const wmnt2Reserve = parseRawAmount(reservesWmntUsdt[1].toString(), 18);
|
|
171
|
-
const lendPrice = wmntReserve / lendleReserve / wmnt2Reserve * usdtReserve;
|
|
172
|
-
const auPrice = wmntReserve_au / auReserve / wmnt2Reserve * usdtReserve;
|
|
194
|
+
const usdtReserve = Number(parseRawAmount(reservesWmntUsdt[0].toString(), 6));
|
|
195
|
+
const wmnt2Reserve = Number(parseRawAmount(reservesWmntUsdt[1].toString(), 18));
|
|
196
|
+
const lendPrice = (wmntReserve / lendleReserve / wmnt2Reserve) * usdtReserve;
|
|
197
|
+
const auPrice = (wmntReserve_au / auReserve / wmnt2Reserve) * usdtReserve;
|
|
173
198
|
uniswapData['LEND'] = lendPrice;
|
|
174
199
|
uniswapData['AU'] = auPrice;
|
|
175
200
|
}
|
|
@@ -179,6 +204,14 @@ const parseUniswapV2results = (data, chainId) => {
|
|
|
179
204
|
return {};
|
|
180
205
|
}
|
|
181
206
|
};
|
|
207
|
+
function lowDecimalOracle(chainId, fork) {
|
|
208
|
+
// some chains only have high decimal oracles
|
|
209
|
+
if (chainId === Chain.AVALANCHE_C_CHAIN || chainId === Chain.MODE) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
// otherwise, it depends on whether it is aave V3
|
|
213
|
+
return AAVE_V2_LENDERS.includes(fork);
|
|
214
|
+
}
|
|
182
215
|
/**
|
|
183
216
|
* Parser for aave results in ulticall slice
|
|
184
217
|
* @param chainId network
|
|
@@ -191,8 +224,10 @@ const parseAaveResults = (chainId, data, queries) => {
|
|
|
191
224
|
data.forEach((d, i) => {
|
|
192
225
|
const details = queries[i];
|
|
193
226
|
details.assets.forEach((a, j) => {
|
|
194
|
-
const oracleId = ASSET_META[chainId][a]?.assetGroup ??
|
|
195
|
-
|
|
227
|
+
const oracleId = ASSET_META[chainId][a]?.assetGroup ??
|
|
228
|
+
ASSET_META[chainId]?.[a]?.symbol ??
|
|
229
|
+
chainId + '-' + a;
|
|
230
|
+
prices[oracleId] = formatAavePrice(d[j].toString(), lowDecimalOracle(chainId, details.fork));
|
|
196
231
|
});
|
|
197
232
|
});
|
|
198
233
|
return prices;
|
|
@@ -209,7 +244,7 @@ const parseChainLinkResults = (chainId, data, assetName) => {
|
|
|
209
244
|
default: {
|
|
210
245
|
return Object.assign({}, ...data.map((entry, index) => {
|
|
211
246
|
return {
|
|
212
|
-
[assetName[index]]: parseRawAmount(entry?.[ChainlinkAggregatorIndexes.answer]?.toString() ?? '0', 8)
|
|
247
|
+
[assetName[index]]: Number(parseRawAmount(entry?.[ChainlinkAggregatorIndexes.answer]?.toString() ?? '0', 8)),
|
|
213
248
|
};
|
|
214
249
|
}));
|
|
215
250
|
}
|
|
@@ -223,7 +258,7 @@ const parseChainLinkResults = (chainId, data, assetName) => {
|
|
|
223
258
|
const getApi3Calls = (chainId) => {
|
|
224
259
|
switch (chainId) {
|
|
225
260
|
case Chain.MANTLE: {
|
|
226
|
-
const keys = [
|
|
261
|
+
const keys = ['WETH', 'METH', 'FBTC', 'CMETH'];
|
|
227
262
|
const addresses = keys.map((k) => api3OracleAddresses[chainId][k]);
|
|
228
263
|
return [
|
|
229
264
|
addresses.map((tk) => {
|
|
@@ -233,7 +268,7 @@ const getApi3Calls = (chainId) => {
|
|
|
233
268
|
params: [],
|
|
234
269
|
};
|
|
235
270
|
}),
|
|
236
|
-
keys
|
|
271
|
+
keys,
|
|
237
272
|
];
|
|
238
273
|
}
|
|
239
274
|
default:
|
|
@@ -252,12 +287,12 @@ const parseApi3Results = (chainId, data, assetName) => {
|
|
|
252
287
|
case Chain.MANTLE: {
|
|
253
288
|
let prices = Object.assign({}, ...data.map((entry, index) => {
|
|
254
289
|
return {
|
|
255
|
-
[assetName[index]]: parseRawAmount(entry?.[0]?.toString() ?? '0', 18)
|
|
290
|
+
[assetName[index]]: Number(parseRawAmount(entry?.[0]?.toString() ?? '0', 18)),
|
|
256
291
|
};
|
|
257
292
|
}));
|
|
258
|
-
// METH is given in mETH/WETH
|
|
259
|
-
prices[
|
|
260
|
-
prices[
|
|
293
|
+
// METH is given in mETH/WETH
|
|
294
|
+
prices['METH'] = prices['METH'] * prices['WETH'];
|
|
295
|
+
prices['CMETH'] = prices['CMETH'] * prices['METH'];
|
|
261
296
|
return prices;
|
|
262
297
|
}
|
|
263
298
|
default: {
|
|
@@ -273,12 +308,17 @@ const parseApi3Results = (chainId, data, assetName) => {
|
|
|
273
308
|
const getRWADynamicOracleCalls = (chainId) => {
|
|
274
309
|
switch (chainId) {
|
|
275
310
|
case Chain.MANTLE: {
|
|
276
|
-
const keys = [
|
|
277
|
-
return [
|
|
311
|
+
const keys = ['USDY_MUSD'];
|
|
312
|
+
return [
|
|
313
|
+
[
|
|
314
|
+
{
|
|
278
315
|
address: RWA_DYNAMIC_ORACLE,
|
|
279
316
|
name: 'getPrice',
|
|
280
317
|
params: [],
|
|
281
|
-
}
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
keys,
|
|
321
|
+
];
|
|
282
322
|
}
|
|
283
323
|
default:
|
|
284
324
|
return [[], []];
|
|
@@ -296,7 +336,7 @@ const parseRWADynamicOracleResults = (chainId, data, assetName) => {
|
|
|
296
336
|
case Chain.MANTLE: {
|
|
297
337
|
let prices = Object.assign({}, ...data.map((entry, index) => {
|
|
298
338
|
return {
|
|
299
|
-
[assetName[index]]: parseRawAmount(entry?.toString() ?? '0', 18)
|
|
339
|
+
[assetName[index]]: Number(parseRawAmount(entry?.toString() ?? '0', 18)),
|
|
300
340
|
};
|
|
301
341
|
}));
|
|
302
342
|
return prices;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare function isCompoundV3Type(lender: string): boolean;
|
|
|
11
11
|
export declare function isInit(lender: string): lender is Lender.INIT;
|
|
12
12
|
export declare function isSwaylend(lender: string): boolean;
|
|
13
13
|
export declare const getLendersForChain: (c: string) => string[];
|
|
14
|
+
/** Filter lenders by protocol list */
|
|
15
|
+
export declare const filterLendersByProtocol: (allLenders: string[], protocolList?: string[]) => string[];
|
|
14
16
|
/** All aave protocols per chain */
|
|
15
17
|
export declare const AAVES_PER_CHAIN: {
|
|
16
18
|
[c: string]: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EAGP,MAAM,wBAAwB,CAAA;AAQ/B,eAAO,MAAM,mBAAmB,UAAkE,CAAA;AAElG,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAE1C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAE9C;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAE1C;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,yBAEpC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,WAE3C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,WAExC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,WAE1C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,WAE9C;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,yBAEpC;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,WAExC;AAED,eAAO,MAAM,kBAAkB,GAAI,GAAG,MAAM,aAqB3C,CAAA;AAED,sCAAsC;AACtC,eAAO,MAAM,uBAAuB,GAAI,YAAY,MAAM,EAAE,EAAE,eAAe,MAAM,EAAE,KAAG,MAAM,EAQ7F,CAAA;AAaD,mCAAmC;AACnC,eAAO,MAAM,eAAe;;CAAqB,CAAA;AAEjD,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MAEpD,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,wBAAgC,KAAG,MAAM,EAO9G,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,24 +1,40 @@
|
|
|
1
|
-
import { AAVE_FORK_POOL_DATA, AAVE_STYLE_RESERVE_ASSETS, AAVE_V2_LENDERS, AAVE_V3_LENDERS, COMPOUND_BASE_TOKENS, COMPOUND_STYLE_RESERVE_ASSETS, INIT_STYLE_RESERVE_ASSETS, Lender, SWAYLEND_RESERVE_ASSETS, INIT_CONFIG_DATA } from "@1delta/asset-registry";
|
|
1
|
+
import { AAVE_FORK_POOL_DATA, AAVE_STYLE_RESERVE_ASSETS, AAVE_V2_LENDERS, AAVE_V3_LENDERS, COMPOUND_BASE_TOKENS, COMPOUND_STYLE_RESERVE_ASSETS, INIT_STYLE_RESERVE_ASSETS, Lender, SWAYLEND_RESERVE_ASSETS, INIT_CONFIG_DATA, } from "@1delta/asset-registry";
|
|
2
2
|
import { uniq } from "lodash";
|
|
3
3
|
import { COMPOSERS } from "./constants";
|
|
4
|
-
export const AAVE_V3_2_PROTOCOLS = [
|
|
5
|
-
Lender.AAVE_V3,
|
|
6
|
-
Lender.AAVE_V3_ETHER_FI,
|
|
7
|
-
Lender.AAVE_V3_PRIME,
|
|
8
|
-
];
|
|
9
|
-
export function isAaveV3Type(lender) { return AAVE_V3_LENDERS.includes(lender); }
|
|
10
4
|
const AAVE_V3_KEY = "AAVE_V3";
|
|
11
|
-
export function isAaveV3Original(lender) { return lender.startsWith(AAVE_V3_KEY); }
|
|
12
|
-
export function isAaveV2Type(lender) { return AAVE_V2_LENDERS.includes(lender); }
|
|
13
|
-
export function isYLDR(lender) { return lender === Lender.YLDR; }
|
|
14
|
-
export function isAaveV32Type(lender) { return AAVE_V3_2_PROTOCOLS.includes(lender); }
|
|
15
|
-
export function isAaveType(lender) { return [...AAVE_V3_LENDERS, ...AAVE_V2_LENDERS].includes(lender); }
|
|
16
5
|
const COMPOUND_V3_KEY = "COMPOUND_V3";
|
|
17
|
-
export function isCompoundV3(lender) { return lender.startsWith(COMPOUND_V3_KEY); }
|
|
18
|
-
export function isCompoundV3Type(lender) { return lender.startsWith(COMPOUND_V3_KEY); }
|
|
19
|
-
export function isInit(lender) { return lender === Lender.INIT; }
|
|
20
6
|
const SWAYLEND_KEY = "SWAYLEND";
|
|
21
|
-
export
|
|
7
|
+
export const AAVE_V3_2_PROTOCOLS = [Lender.AAVE_V3, Lender.AAVE_V3_ETHER_FI, Lender.AAVE_V3_PRIME];
|
|
8
|
+
export function isAaveV3Type(lender) {
|
|
9
|
+
return AAVE_V3_LENDERS.includes(lender);
|
|
10
|
+
}
|
|
11
|
+
export function isAaveV3Original(lender) {
|
|
12
|
+
return lender.startsWith(AAVE_V3_KEY);
|
|
13
|
+
}
|
|
14
|
+
export function isAaveV2Type(lender) {
|
|
15
|
+
return AAVE_V2_LENDERS.includes(lender);
|
|
16
|
+
}
|
|
17
|
+
export function isYLDR(lender) {
|
|
18
|
+
return lender === Lender.YLDR;
|
|
19
|
+
}
|
|
20
|
+
export function isAaveV32Type(lender) {
|
|
21
|
+
return AAVE_V3_2_PROTOCOLS.includes(lender);
|
|
22
|
+
}
|
|
23
|
+
export function isAaveType(lender) {
|
|
24
|
+
return [...AAVE_V3_LENDERS, ...AAVE_V2_LENDERS].includes(lender);
|
|
25
|
+
}
|
|
26
|
+
export function isCompoundV3(lender) {
|
|
27
|
+
return lender.startsWith(COMPOUND_V3_KEY);
|
|
28
|
+
}
|
|
29
|
+
export function isCompoundV3Type(lender) {
|
|
30
|
+
return lender.startsWith(COMPOUND_V3_KEY);
|
|
31
|
+
}
|
|
32
|
+
export function isInit(lender) {
|
|
33
|
+
return lender === Lender.INIT;
|
|
34
|
+
}
|
|
35
|
+
export function isSwaylend(lender) {
|
|
36
|
+
return lender.startsWith(SWAYLEND_KEY);
|
|
37
|
+
}
|
|
22
38
|
export const getLendersForChain = (c) => {
|
|
23
39
|
let lenders = [];
|
|
24
40
|
// aaves
|
|
@@ -41,6 +57,15 @@ export const getLendersForChain = (c) => {
|
|
|
41
57
|
});
|
|
42
58
|
return lenders;
|
|
43
59
|
};
|
|
60
|
+
/** Filter lenders by protocol list */
|
|
61
|
+
export const filterLendersByProtocol = (allLenders, protocolList) => {
|
|
62
|
+
// return all lenders if no filter is provided
|
|
63
|
+
if (!protocolList || protocolList.length === 0) {
|
|
64
|
+
return allLenders;
|
|
65
|
+
}
|
|
66
|
+
// Filter lenders based on protocol list
|
|
67
|
+
return allLenders.filter((lender) => protocolList.includes(lender));
|
|
68
|
+
};
|
|
44
69
|
const getAavesForChain = () => {
|
|
45
70
|
let lenders = {};
|
|
46
71
|
Object.entries(AAVE_FORK_POOL_DATA).forEach(([l, data]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/utils/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"parsing.d.ts","sourceRoot":"","sources":["../../src/utils/parsing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIvD,eAAO,MAAM,GAAG,QAAQ,CAAC;AAEzB,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,iBAAa,KAAG,MAO/D,CAAC;AAEF,oBAAY,SAAS;IACnB,KAAK,IAAA;IACL,EAAE,IAAA;CACH;AAYD,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,WAEnC,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,WAEnC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,IAAI,MAAM,GAAG,MAAM,KAAG,MAG7D,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,GAAG,MAAM,EACT,SAAS,MAAM,EACf,eAAiC,KAChC,MAgBF,CAAC;AACF,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,WAGrE,CAAC;AAGF,eAAO,MAAM,gBAAgB,GAAI,eAAe,MAAM,GAAG,MAAM,WAI9D,CAAC"}
|