@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.
- 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/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/lending/aave-v2-type/publicCallParse.js +3 -3
- 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/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 +23 -10
- 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-pairs/computeLendingPairs.d.ts +11 -0
- package/dist/lending-pairs/computeLendingPairs.d.ts.map +1 -1
- package/dist/lending-pairs/computeLendingPairs.js +84 -5
- package/dist/prices/main-prices/fetchOracleData.d.ts +1 -1
- package/dist/prices/main-prices/fetchOracleData.d.ts.map +1 -1
- package/dist/prices/main-prices/fetchOracleData.js +11 -2
- 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/lending/aave-v2-type/publicCallParse.ts +3 -3
- package/src/lending/addresses/compoundV3.ts +29 -15
- package/src/lending/user-data/aave-v2-type/userCallBuild.ts +1 -25
- package/src/lending/user-data/aave-v2-type/userCallParse.ts +23 -10
- 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 +135 -5
- package/src/prices/main-prices/fetchOracleData.ts +14 -2
- package/src/utils/parsing.ts +51 -51
- package/test/userdata.test.ts +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Chain, COMETS_PER_CHAIN_MAP, COMPOUND_BASE_TOKENS, Lender, SWAYLEND_BASE_TOKENS } from "@1delta/asset-registry";
|
|
1
|
+
import { Chain, COMETS_PER_CHAIN_MAP, COMPOUND_BASE_TOKENS, Lender, SWAYLEND_BASE_TOKENS, } from "@1delta/asset-registry";
|
|
2
2
|
export function getCompoundV3CometAddress(chainId, lender = Lender.COMPOUND_V3_USDCE) {
|
|
3
3
|
return COMETS_PER_CHAIN_MAP[chainId]?.[lender];
|
|
4
4
|
}
|
|
@@ -13,20 +13,21 @@ export function getCompoundV3CometLens(chainId) {
|
|
|
13
13
|
}
|
|
14
14
|
const addressesCompoundV3 = {
|
|
15
15
|
lens: {
|
|
16
|
-
[Chain.POLYGON_MAINNET]:
|
|
17
|
-
[Chain.MANTLE]:
|
|
18
|
-
[Chain.ARBITRUM_ONE]:
|
|
16
|
+
[Chain.POLYGON_MAINNET]: "0x4eDA401658c5286d16c4d342884F32280B4E8b1b",
|
|
17
|
+
[Chain.MANTLE]: "0x32B31A066c8dd3F7b77283Ba1d89Ddaf6DA0a8aE",
|
|
18
|
+
[Chain.ARBITRUM_ONE]: "0x13D9c35f4901491Ac4FFebd3100238BBfFBD7181",
|
|
19
19
|
[Chain.BASE]: "0x7e2D250E4FD0EeD6BD2cB3DC525A2b9f12508152",
|
|
20
20
|
[Chain.OP_MAINNET]: "0xA453ba397c61B0c292EA3959A858821145B2707F",
|
|
21
21
|
},
|
|
22
22
|
cometRewards: {
|
|
23
23
|
[Chain.POLYGON_MAINNET]: "0x45939657d1CA34A8FA39A924B71D28Fe8431e581",
|
|
24
24
|
[Chain.MANTLE]: "0xCd83CbBFCE149d141A5171C3D6a0F0fCCeE225Ab",
|
|
25
|
-
[Chain.ARBITRUM_ONE]:
|
|
25
|
+
[Chain.ARBITRUM_ONE]: "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae",
|
|
26
26
|
[Chain.BASE]: "0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1",
|
|
27
27
|
[Chain.OP_MAINNET]: "0x443EA0340cb75a160F31A440722dec7b5bc3C2E9",
|
|
28
|
-
}
|
|
28
|
+
},
|
|
29
29
|
};
|
|
30
30
|
export function getCompoundV3BaseAsset(lender, chainId) {
|
|
31
|
-
return COMPOUND_BASE_TOKENS[lender]?.[chainId] ??
|
|
31
|
+
return (COMPOUND_BASE_TOKENS[lender]?.[chainId] ??
|
|
32
|
+
SWAYLEND_BASE_TOKENS[lender]?.[chainId]);
|
|
32
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userCallParse.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/compound-v3/userCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"userCallParse.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/compound-v3/userCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAOxD,eAAO,MAAM,8BAA8B,GACzC,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,SAAS,MAAM,EACf,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,YAAY;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACvC,YAAY,GAAG,KACd,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,6BAA6B,GAAG,SAAS,EAAE,MAAM,CA6GrE,CAAA"}
|
|
@@ -22,6 +22,8 @@ export const getCompoundV3UserDataConverter = (lender, chainId, account, prices,
|
|
|
22
22
|
const assetMeta = getAssetMeta(chainId, asset);
|
|
23
23
|
const decimals = assetMeta?.decimals ?? 18;
|
|
24
24
|
const depositsRaw = data[i][0]?.toString();
|
|
25
|
+
if (depositsRaw === "0")
|
|
26
|
+
continue;
|
|
25
27
|
const deposits = parseRawAmount(depositsRaw, decimals);
|
|
26
28
|
const key = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(asset, chainId);
|
|
27
29
|
const price = prices[key] ?? 1;
|
|
@@ -13,6 +13,17 @@ export interface LendingPair {
|
|
|
13
13
|
apr: number;
|
|
14
14
|
tags?: string[];
|
|
15
15
|
eMode?: number;
|
|
16
|
+
longTotalDepositsUSD: number;
|
|
17
|
+
longTotalDebtUSD: number;
|
|
18
|
+
longTotalLiquidityUSD: number;
|
|
19
|
+
shortTotalDepositsUSD: number;
|
|
20
|
+
shortTotalDebtUSD: number;
|
|
21
|
+
shortTotalLiquidityUSD: number;
|
|
22
|
+
longIsActive: boolean;
|
|
23
|
+
longIsFrozen: boolean;
|
|
24
|
+
shortIsActive: boolean;
|
|
25
|
+
shortIsFrozen: boolean;
|
|
26
|
+
shortBorrowingEnabled: boolean;
|
|
16
27
|
}
|
|
17
28
|
/** create array of pairs for given lender data */
|
|
18
29
|
export declare function generateLendingPairs(lenderData: LenderData, prices: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeLendingPairs.d.ts","sourceRoot":"","sources":["../../src/lending-pairs/computeLendingPairs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computeLendingPairs.d.ts","sourceRoot":"","sources":["../../src/lending-pairs/computeLendingPairs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,UAAU,EAAY,MAAM,UAAU,CAAA;AAG5D,MAAM,WAAW,WAAW;IAExB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IAEd,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAGlB,cAAc,EAAE,MAAM,CAAA;IAEtB,eAAe,EAAE,MAAM,CAAA;IAEvB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IAGnB,WAAW,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IAGd,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;IACxB,qBAAqB,EAAE,MAAM,CAAA;IAC7B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,iBAAiB,EAAE,MAAM,CAAA;IACzB,sBAAsB,EAAE,MAAM,CAAA;IAG9B,YAAY,EAAE,OAAO,CAAA;IACrB,YAAY,EAAE,OAAO,CAAA;IACrB,aAAa,EAAE,OAAO,CAAA;IACtB,aAAa,EAAE,OAAO,CAAA;IACtB,qBAAqB,EAAE,OAAO,CAAA;CACjC;AAwCD,kDAAkD;AAClD,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EAAE,UAAU,EAAE;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,WAAW,EAAE,CAmGhJ;AA0DD,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE;;;;;EAyB/C;AAMD,wBAAgB,4BAA4B,CACxC,KAAK,EAAE,WAAW,EAAE,GACrB,WAAW,EAAE,CAqEf"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getAssetMeta, toGenericPriceKey, toOracleKey } from "../assets";
|
|
2
|
+
import { getLiquidityThresholds, meetsLiquidityThresholds } from "../assets/liquidityThresholds";
|
|
2
3
|
import { isAaveV3Type, isInit } from "../utils";
|
|
3
4
|
const isEMode = (longData, shortData) => Boolean(longData.eMode) ?
|
|
4
5
|
Number(longData.eMode?.category) > 0 && Number(longData.eMode?.category) === shortData.eMode?.category : false;
|
|
@@ -101,7 +102,18 @@ export function generateLendingPairs(lenderData, prices, histPrices) {
|
|
|
101
102
|
priceChange: price24h === 0 ? 0 : (price - price24h) / price24h,
|
|
102
103
|
maxLeverage: maxDepositLeverage,
|
|
103
104
|
apr: (depositApr + collateralRewards) * depositLeverage + (borrowRewards - borrowApr) * borrowLeverage,
|
|
104
|
-
eMode: long.eMode?.category ?? 0
|
|
105
|
+
eMode: long.eMode?.category ?? 0,
|
|
106
|
+
longTotalDepositsUSD: long.totalDepositsUSD,
|
|
107
|
+
longTotalDebtUSD: long.totalDebtUSD,
|
|
108
|
+
longTotalLiquidityUSD: long.totalLiquidityUSD,
|
|
109
|
+
shortTotalDepositsUSD: short.totalDepositsUSD,
|
|
110
|
+
shortTotalDebtUSD: short.totalDebtUSD,
|
|
111
|
+
shortTotalLiquidityUSD: short.totalLiquidityUSD,
|
|
112
|
+
longIsActive: long.isActive,
|
|
113
|
+
longIsFrozen: long.isFrozen,
|
|
114
|
+
shortIsActive: short.isActive,
|
|
115
|
+
shortIsFrozen: short.isFrozen,
|
|
116
|
+
shortBorrowingEnabled: short.borrowingEnabled
|
|
105
117
|
});
|
|
106
118
|
}
|
|
107
119
|
}
|
|
@@ -114,10 +126,46 @@ function getPriceKey(asset, chainId) {
|
|
|
114
126
|
return [assetGroup, toOracleKey(assetGroup) ?? toGenericPriceKey(asset, chainId)];
|
|
115
127
|
}
|
|
116
128
|
const MAX_ENTRIES = 10;
|
|
129
|
+
function filterPairsByCategory(pairs, longFilter, shortFilter) {
|
|
130
|
+
return pairs
|
|
131
|
+
.filter(p => {
|
|
132
|
+
if (!longFilter(p.assetGroupLong) || !shortFilter(p.assetGroupShort)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (p.assetGroupShort?.includes("PT-") || p.assetGroupLong?.includes("PT-")) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
if (!p.longIsActive || p.longIsFrozen || !p.shortIsActive || p.shortIsFrozen) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (!p.shortBorrowingEnabled) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
// apply liquidity thresholds
|
|
145
|
+
const longThresholds = getLiquidityThresholds(p.chainId, p.assetLong, p.assetGroupLong);
|
|
146
|
+
const shortThresholds = getLiquidityThresholds(p.chainId, p.assetShort, p.assetGroupShort);
|
|
147
|
+
const longMeetsThresholds = meetsLiquidityThresholds({
|
|
148
|
+
totalDepositsUSD: p.longTotalDepositsUSD,
|
|
149
|
+
totalDebtUSD: p.longTotalDebtUSD,
|
|
150
|
+
totalLiquidityUSD: p.longTotalLiquidityUSD
|
|
151
|
+
}, longThresholds);
|
|
152
|
+
const shortMeetsThresholds = meetsLiquidityThresholds({
|
|
153
|
+
totalDepositsUSD: p.shortTotalDepositsUSD,
|
|
154
|
+
totalDebtUSD: p.shortTotalDebtUSD,
|
|
155
|
+
totalLiquidityUSD: p.shortTotalLiquidityUSD
|
|
156
|
+
}, shortThresholds);
|
|
157
|
+
if (!longMeetsThresholds || !shortMeetsThresholds) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
})
|
|
162
|
+
.sort((a, b) => b.apr - a.apr)
|
|
163
|
+
.slice(0, MAX_ENTRIES);
|
|
164
|
+
}
|
|
117
165
|
export function getTopPairs(pairs) {
|
|
118
|
-
const stables = pairs
|
|
119
|
-
const btcLst = pairs
|
|
120
|
-
const ethLst = pairs
|
|
166
|
+
const stables = filterPairsByCategory(pairs, (group) => group?.includes("USD") ?? false, (group) => group?.includes("USD") ?? false);
|
|
167
|
+
const btcLst = filterPairsByCategory(pairs, (group) => group?.includes("BTC") ?? false, (group) => group?.includes("BTC") ?? false);
|
|
168
|
+
const ethLst = filterPairsByCategory(pairs, (group) => group?.includes("ETH") ?? false, (group) => group?.includes("ETH") ?? false);
|
|
121
169
|
return {
|
|
122
170
|
stables,
|
|
123
171
|
btcLst,
|
|
@@ -129,7 +177,38 @@ function isStable(assetGroup) {
|
|
|
129
177
|
return assetGroup.includes("USD");
|
|
130
178
|
}
|
|
131
179
|
export function getDistinctPairsByShortAsset(pairs) {
|
|
132
|
-
const
|
|
180
|
+
const qualityPairs = pairs.filter(p => {
|
|
181
|
+
if (!isFinite(p.apr) || !isFinite(p.priceChange)) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (!p.longIsActive || p.longIsFrozen || !p.shortIsActive || p.shortIsFrozen) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (!p.shortBorrowingEnabled) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
// Apply liquidity thresholds
|
|
191
|
+
const longThresholds = getLiquidityThresholds(p.chainId, p.assetLong, p.assetGroupLong);
|
|
192
|
+
const shortThresholds = getLiquidityThresholds(p.chainId, p.assetShort, p.assetGroupShort);
|
|
193
|
+
const longMeetsThresholds = meetsLiquidityThresholds({
|
|
194
|
+
totalDepositsUSD: p.longTotalDepositsUSD,
|
|
195
|
+
totalDebtUSD: p.longTotalDebtUSD,
|
|
196
|
+
totalLiquidityUSD: p.longTotalLiquidityUSD
|
|
197
|
+
}, longThresholds);
|
|
198
|
+
const shortMeetsThresholds = meetsLiquidityThresholds({
|
|
199
|
+
totalDepositsUSD: p.shortTotalDepositsUSD,
|
|
200
|
+
totalDebtUSD: p.shortTotalDebtUSD,
|
|
201
|
+
totalLiquidityUSD: p.shortTotalLiquidityUSD
|
|
202
|
+
}, shortThresholds);
|
|
203
|
+
if (!longMeetsThresholds || !shortMeetsThresholds) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (p.assetGroupShort?.includes("PT-") || p.assetGroupLong?.includes("PT-")) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
});
|
|
211
|
+
const sorted = [...qualityPairs].sort((a, b) => b.priceChange - a.priceChange);
|
|
133
212
|
const blacklist = new Set();
|
|
134
213
|
const blacklistLong = new Set();
|
|
135
214
|
const result = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GetEvmClientFunction } from '../../types';
|
|
2
|
-
export declare const formatAavePrice: (price: string,
|
|
2
|
+
export declare const formatAavePrice: (price: string, isV2?: boolean) => number;
|
|
3
3
|
export declare const parseRawAmount: (answer?: string, decimals?: number) => number;
|
|
4
4
|
interface OracleData {
|
|
5
5
|
[key: string]: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchOracleData.d.ts","sourceRoot":"","sources":["../../../src/prices/main-prices/fetchOracleData.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"fetchOracleData.d.ts","sourceRoot":"","sources":["../../../src/prices/main-prices/fetchOracleData.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,cAAY,KAAG,MAK7D,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,iBAAa,KAAG,MAO/D,CAAA;AAOD,UAAU,UAAU;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB;AAID;;GAEG;AACH,eAAO,MAAM,eAAe,GAAU,UAAU,MAAM,EAAE,EAAE,cAAc,oBAAoB,KAAG,OAAO,CAAC,UAAU,CA8EhH,CAAA"}
|
|
@@ -12,7 +12,7 @@ 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
|
-
export const formatAavePrice = (price,
|
|
15
|
+
export const formatAavePrice = (price, isV2 = false) => {
|
|
16
16
|
return Number(formatEther(BigInt(price ?? '0') * (
|
|
17
17
|
// 10^(18 - decimals)
|
|
18
18
|
10n ** (isV2 ? 0n : 10n))));
|
|
@@ -179,6 +179,15 @@ const parseUniswapV2results = (data, chainId) => {
|
|
|
179
179
|
return {};
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
+
function lowDecimalOracle(chainId, fork) {
|
|
183
|
+
// some chains only have high decimal oracles
|
|
184
|
+
if (chainId === Chain.AVALANCHE_C_CHAIN ||
|
|
185
|
+
chainId === Chain.MODE) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
// otherwise, it depends on whether it is aave V3
|
|
189
|
+
return AAVE_V2_LENDERS.includes(fork);
|
|
190
|
+
}
|
|
182
191
|
/**
|
|
183
192
|
* Parser for aave results in ulticall slice
|
|
184
193
|
* @param chainId network
|
|
@@ -192,7 +201,7 @@ const parseAaveResults = (chainId, data, queries) => {
|
|
|
192
201
|
const details = queries[i];
|
|
193
202
|
details.assets.forEach((a, j) => {
|
|
194
203
|
const oracleId = ASSET_META[chainId][a]?.assetGroup ?? ASSET_META[chainId]?.[a]?.symbol ?? chainId + "-" + a;
|
|
195
|
-
prices[oracleId] = formatAavePrice(d[j].toString(), chainId,
|
|
204
|
+
prices[oracleId] = formatAavePrice(d[j].toString(), lowDecimalOracle(chainId, details.fork));
|
|
196
205
|
});
|
|
197
206
|
});
|
|
198
207
|
return prices;
|
|
@@ -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"}
|
package/dist/utils/parsing.js
CHANGED
|
@@ -6,7 +6,7 @@ export const parseRawAmount = (answer, decimals = 18) => {
|
|
|
6
6
|
if (!answer || answer === "0x")
|
|
7
7
|
return "0";
|
|
8
8
|
try {
|
|
9
|
-
return
|
|
9
|
+
return formatUnits(BigInt(answer ?? "0"), decimals ?? 18);
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
12
|
return "0";
|
|
@@ -45,7 +45,9 @@ export const calculateRateForCompound = (n, chainId, lender = Lender.COMPOUND_V3
|
|
|
45
45
|
}
|
|
46
46
|
const rate = Number(formatEther(BigInt(n)));
|
|
47
47
|
if (scale === TimeScale.BLOCK)
|
|
48
|
-
return (Math.pow((rate * 60 * 60 * 24) / (BLOCK_TIMES[chainId] ?? 1) + 1, 365) -
|
|
48
|
+
return ((Math.pow((rate * 60 * 60 * 24) / (BLOCK_TIMES[chainId] ?? 1) + 1, 365) -
|
|
49
|
+
1) *
|
|
50
|
+
100);
|
|
49
51
|
return (Math.pow(rate * 60 * 60 * 24 + 1, 365) - 1) * 100;
|
|
50
52
|
};
|
|
51
53
|
export const formatAaveRawApyToApr = (raw) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1delta/margin-fetcher",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/async-retry": "^1.4.9",
|
|
21
21
|
"async-retry": "^1.3.3",
|
|
22
22
|
"typescript": "^5.8.3",
|
|
23
|
-
"@1delta/providers": "0.0.
|
|
23
|
+
"@1delta/providers": "0.0.3"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "tsc",
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
export const AaveOracleAbi = [
|
|
2
|
+
{
|
|
3
|
+
"inputs": [],
|
|
4
|
+
"name": "BASE_CURRENCY_UNIT",
|
|
5
|
+
"outputs": [
|
|
6
|
+
{
|
|
7
|
+
"internalType": "uint256",
|
|
8
|
+
"name": "",
|
|
9
|
+
"type": "uint256"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"stateMutability": "view",
|
|
13
|
+
"type": "function"
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"inputs": [
|
|
4
17
|
{
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
export const AaveOracleAbi = [
|
|
2
|
+
{
|
|
3
|
+
"inputs": [],
|
|
4
|
+
"name": "BASE_CURRENCY_UNIT",
|
|
5
|
+
"outputs": [
|
|
6
|
+
{
|
|
7
|
+
"internalType": "uint256",
|
|
8
|
+
"name": "",
|
|
9
|
+
"type": "uint256"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"stateMutability": "view",
|
|
13
|
+
"type": "function"
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"inputs": [
|
|
4
17
|
{
|
package/src/assets/index.ts
CHANGED
|
@@ -1,82 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AAVE_FORK_POOL_DATA,
|
|
3
|
+
AAVE_STYLE_RESERVE_ASSETS,
|
|
4
|
+
AAVE_STYLE_TOKENS,
|
|
5
|
+
ASSET_META,
|
|
6
|
+
COMPOUND_STYLE_RESERVE_ASSETS,
|
|
7
|
+
COMPOUND_V2_STYLE_RESERVE_ASSETS,
|
|
8
|
+
INIT_STYLE_RESERVE_ASSETS,
|
|
9
|
+
Lender,
|
|
10
|
+
SWAYLEND_RESERVE_ASSETS,
|
|
11
|
+
} from "@1delta/asset-registry";
|
|
12
|
+
import { isAaveType, isCompoundV3, isInit, isSwaylend } from "../utils";
|
|
3
13
|
|
|
4
14
|
/** No specific configuration */
|
|
5
|
-
export const LENDER_MODE_NO_MODE = 0
|
|
6
|
-
|
|
15
|
+
export const LENDER_MODE_NO_MODE = 0;
|
|
7
16
|
|
|
8
17
|
export function getAaveStyleProtocolTokenMap(chainId: string, lender: string) {
|
|
9
|
-
|
|
18
|
+
return AAVE_STYLE_TOKENS[lender]?.[chainId] as any;
|
|
10
19
|
}
|
|
11
20
|
|
|
12
|
-
|
|
13
21
|
export const getAaveAssets = (
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
chainId: string | undefined,
|
|
23
|
+
lendingProtocol: string = Lender.AAVE_V3
|
|
16
24
|
): string[] => {
|
|
17
|
-
|
|
18
|
-
return []
|
|
19
|
-
|
|
25
|
+
if (isAaveType(lendingProtocol))
|
|
26
|
+
return AAVE_STYLE_RESERVE_ASSETS[lendingProtocol]?.[chainId ?? "0"] ?? [];
|
|
27
|
+
return [];
|
|
28
|
+
};
|
|
20
29
|
|
|
21
30
|
export const getInitAssets = (
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
chainId: string | undefined,
|
|
32
|
+
lendingProtocol = Lender.INIT
|
|
24
33
|
): string[] => {
|
|
25
|
-
|
|
26
|
-
return []
|
|
27
|
-
|
|
34
|
+
if (isInit(lendingProtocol))
|
|
35
|
+
return INIT_STYLE_RESERVE_ASSETS[lendingProtocol]?.[chainId ?? "0"] ?? [];
|
|
36
|
+
return [];
|
|
37
|
+
};
|
|
28
38
|
|
|
29
39
|
export const getCompoundV3Assets = (
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
chainId: string | undefined,
|
|
41
|
+
lendingProtocol = Lender.COMPOUND_V3_USDCE
|
|
32
42
|
): string[] => {
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
|
|
43
|
+
if (isCompoundV3(lendingProtocol))
|
|
44
|
+
return (
|
|
45
|
+
COMPOUND_STYLE_RESERVE_ASSETS[lendingProtocol]?.[chainId ?? "0"] ?? []
|
|
46
|
+
);
|
|
47
|
+
return [];
|
|
48
|
+
};
|
|
36
49
|
|
|
37
50
|
export const getCompoundV2Assets = (
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
chainId: string | undefined,
|
|
52
|
+
lendingProtocol = Lender.VENUS
|
|
40
53
|
): string[] => {
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
if (isCompoundV3(lendingProtocol))
|
|
55
|
+
return (
|
|
56
|
+
COMPOUND_V2_STYLE_RESERVE_ASSETS[lendingProtocol]?.[chainId ?? "0"] ?? []
|
|
57
|
+
);
|
|
58
|
+
return [];
|
|
59
|
+
};
|
|
45
60
|
|
|
46
61
|
export const getSwaylendAssets = (
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
chainId: string | undefined,
|
|
63
|
+
lendingProtocol = Lender.SWAYLEND_USDC
|
|
49
64
|
): string[] => {
|
|
50
|
-
|
|
51
|
-
return []
|
|
65
|
+
if (isSwaylend(lendingProtocol))
|
|
66
|
+
return SWAYLEND_RESERVE_ASSETS[lendingProtocol]?.[chainId ?? "0"] ?? [];
|
|
67
|
+
return [];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export function getAaveTypePoolDataProviderAddress(
|
|
71
|
+
chainId: string,
|
|
72
|
+
lender: string
|
|
73
|
+
) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
return AAVE_FORK_POOL_DATA[lender]?.[chainId]?.protocolDataProvider;
|
|
52
76
|
}
|
|
53
77
|
|
|
54
|
-
export function
|
|
55
|
-
|
|
56
|
-
|
|
78
|
+
export function getAaveTypePoolAddress(
|
|
79
|
+
chainId: string,
|
|
80
|
+
lender: string
|
|
81
|
+
): string {
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
return AAVE_FORK_POOL_DATA[lender]?.[chainId]?.pool;
|
|
57
84
|
}
|
|
58
85
|
|
|
59
|
-
|
|
60
|
-
export function getAaveTypePoolAddress(chainId: string, lender: string): string {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
return AAVE_FORK_POOL_DATA[lender]?.[chainId]?.pool
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
86
|
export function getAssetMeta(chainId: string, asset: string | undefined) {
|
|
67
|
-
|
|
87
|
+
return ASSET_META[chainId ?? "0"]?.[asset?.toLowerCase() ?? ""] as any;
|
|
68
88
|
}
|
|
69
89
|
|
|
70
|
-
|
|
71
90
|
/**
|
|
72
|
-
* Convert a string (asset symbol) to a Supported asset, considering also naming conflicts
|
|
73
|
-
* @param a string
|
|
74
|
-
* @returns SupportedAsset
|
|
75
|
-
*/
|
|
91
|
+
* Convert a string (asset symbol) to a Supported asset, considering also naming conflicts
|
|
92
|
+
* @param a string
|
|
93
|
+
* @returns SupportedAsset
|
|
94
|
+
*/
|
|
76
95
|
export const toOracleKey = (a: string) => {
|
|
77
|
-
|
|
78
|
-
}
|
|
96
|
+
return a;
|
|
97
|
+
};
|
|
79
98
|
|
|
80
99
|
export const toGenericPriceKey = (assetAddress: string, chainId: string) => {
|
|
81
|
-
|
|
82
|
-
}
|
|
100
|
+
return chainId + "-" + assetAddress;
|
|
101
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Chain } from "@1delta/asset-registry";
|
|
2
|
+
|
|
3
|
+
export interface LiquidityThresholds {
|
|
4
|
+
/** Minimum total deposits in USD */
|
|
5
|
+
minDepositsUSD: number;
|
|
6
|
+
/** Minimum total debt/borrows in USD */
|
|
7
|
+
minDebtUSD: number;
|
|
8
|
+
/** Minimum total liquidity in USD */
|
|
9
|
+
minLiquidityUSD: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_LIQUIDITY_THRESHOLDS: LiquidityThresholds = {
|
|
13
|
+
minDepositsUSD: 50_000,
|
|
14
|
+
minDebtUSD: 10_000,
|
|
15
|
+
minLiquidityUSD: 25_000,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const ASSET_GROUP_LIQUIDITY_THRESHOLDS: { [assetGroup: string]: LiquidityThresholds } = {
|
|
19
|
+
'USDC': {
|
|
20
|
+
minDepositsUSD: 25_000,
|
|
21
|
+
minDebtUSD: 5_000,
|
|
22
|
+
minLiquidityUSD: 15_000,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const CHAIN_THRESHOLD_MULTIPLIERS: { [chainId: string]: number } = {
|
|
27
|
+
[Chain.POLYGON_MAINNET]: 1.0,
|
|
28
|
+
[Chain.ARBITRUM_ONE]: 1.0,
|
|
29
|
+
[Chain.OP_MAINNET]: 1.0,
|
|
30
|
+
[Chain.BASE]: 1.0,
|
|
31
|
+
[Chain.MANTLE]: 0.8,
|
|
32
|
+
[Chain.LINEA]: 0.8,
|
|
33
|
+
[Chain.ZKSYNC_MAINNET]: 0.8,
|
|
34
|
+
[Chain.SCROLL]: 0.8,
|
|
35
|
+
[Chain.TAIKO_ALETHIA]: 0.6,
|
|
36
|
+
[Chain.HEMI_NETWORK]: 0.6,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Asset based overrides (per chain)
|
|
41
|
+
* assetKey format: "chainId-assetAddress" (lowercase)
|
|
42
|
+
*/
|
|
43
|
+
export const ASSET_SPECIFIC_THRESHOLDS: { [assetKey: string]: LiquidityThresholds } = {
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
export function getLiquidityThresholds(
|
|
51
|
+
chainId: string,
|
|
52
|
+
assetAddress: string,
|
|
53
|
+
assetGroup?:string,
|
|
54
|
+
): LiquidityThresholds {
|
|
55
|
+
// Check for asset overrides
|
|
56
|
+
const assetKey = `${chainId}-${assetAddress.toLowerCase()}`;
|
|
57
|
+
if (ASSET_SPECIFIC_THRESHOLDS[assetKey]) {
|
|
58
|
+
return ASSET_SPECIFIC_THRESHOLDS[assetKey];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let baseThresholds = assetGroup && ASSET_GROUP_LIQUIDITY_THRESHOLDS[assetGroup]
|
|
62
|
+
? ASSET_GROUP_LIQUIDITY_THRESHOLDS[assetGroup]
|
|
63
|
+
: DEFAULT_LIQUIDITY_THRESHOLDS;
|
|
64
|
+
|
|
65
|
+
const chainMultiplier = CHAIN_THRESHOLD_MULTIPLIERS[chainId] ?? 1.0;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
minDepositsUSD: Math.floor(baseThresholds.minDepositsUSD * chainMultiplier),
|
|
69
|
+
minDebtUSD: Math.floor(baseThresholds.minDebtUSD * chainMultiplier),
|
|
70
|
+
minLiquidityUSD: Math.floor(baseThresholds.minLiquidityUSD * chainMultiplier),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function meetsLiquidityThresholds(
|
|
75
|
+
pool: { totalDepositsUSD: number; totalDebtUSD: number; totalLiquidityUSD: number },
|
|
76
|
+
thresholds: LiquidityThresholds
|
|
77
|
+
): boolean {
|
|
78
|
+
return (
|
|
79
|
+
pool.totalDepositsUSD >= thresholds.minDepositsUSD &&
|
|
80
|
+
pool.totalDebtUSD >= thresholds.minDebtUSD &&
|
|
81
|
+
pool.totalLiquidityUSD >= thresholds.minLiquidityUSD
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -46,7 +46,7 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
46
46
|
const liquidity = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals)
|
|
47
47
|
const totalAToken = Number(liquidity) + Number(totalStableDebt) + Number(totalVariableDebt)
|
|
48
48
|
|
|
49
|
-
const oracleKey = toOracleKey(assetMeta?.
|
|
49
|
+
const oracleKey = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(asset, chainId)
|
|
50
50
|
const price = prices[oracleKey] ?? 1
|
|
51
51
|
|
|
52
52
|
const totalDepositsUSD = totalAToken * price
|
|
@@ -148,7 +148,7 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
148
148
|
const totalVariableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalVariableDebt]?.toString(), decimals)
|
|
149
149
|
const liquidity = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals)
|
|
150
150
|
const totalAToken = Number(liquidity) + Number(totalStableDebt) + Number(totalVariableDebt)
|
|
151
|
-
const oracleKey = toOracleKey(assetMeta?.
|
|
151
|
+
const oracleKey = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(asset, chainId)
|
|
152
152
|
const price = prices?.[oracleKey] ?? 1
|
|
153
153
|
|
|
154
154
|
const totalDepositsUSD = totalAToken * price
|
|
@@ -235,7 +235,7 @@ export const getAaveV2ReservesDataConverter = (
|
|
|
235
235
|
const liquidity = Number(parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals))
|
|
236
236
|
const totalAToken = liquidity + Number(totalStableDebt) + Number(totalVariableDebt)
|
|
237
237
|
|
|
238
|
-
const oracleKey = toOracleKey(assetMeta?.
|
|
238
|
+
const oracleKey = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(asset, chainId)
|
|
239
239
|
const price = prices[oracleKey] ?? 1
|
|
240
240
|
|
|
241
241
|
const totalDepositsUSD = Number(totalAToken) * price
|