@1delta/margin-fetcher 0.0.39 → 0.0.41
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/lending/aave-v2-type/publicCallBuild.d.ts +2 -2
- package/dist/lending/aave-v2-type/publicCallBuild.d.ts.map +1 -1
- package/dist/lending/aave-v2-type/publicCallBuild.js +1 -81
- package/dist/lending/aave-v2-type/publicCallParse.d.ts.map +1 -1
- package/dist/lending/aave-v2-type/publicCallParse.js +2 -196
- package/dist/lending/addresses/compoundV3.d.ts.map +1 -1
- package/dist/lending/addresses/compoundV3.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 +1 -67
- package/dist/lending/user-data/aave-v2-type/userCallParse.d.ts.map +1 -1
- package/dist/lending/user-data/aave-v2-type/userCallParse.js +0 -158
- package/package.json +2 -2
- package/src/lending/aave-v2-type/publicCallBuild.ts +0 -86
- package/src/lending/aave-v2-type/publicCallParse.ts +0 -357
- package/src/lending/addresses/compoundV3.ts +1 -0
- package/src/lending/user-data/aave-v2-type/userCallBuild.ts +0 -77
- package/src/lending/user-data/aave-v2-type/userCallParse.ts +0 -262
- package/test/lenderData.test.ts +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Lender } from '@1delta/lender-registry';
|
|
2
2
|
export declare const buildAaveV2StyleLenderReserveCall: (chainId: string, lender: Lender) => {
|
|
3
|
-
address:
|
|
3
|
+
address: string;
|
|
4
4
|
name: string;
|
|
5
|
-
params:
|
|
5
|
+
params: string[];
|
|
6
6
|
}[];
|
|
7
7
|
//# sourceMappingURL=publicCallBuild.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicCallBuild.d.ts","sourceRoot":"","sources":["../../../src/lending/aave-v2-type/publicCallBuild.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publicCallBuild.d.ts","sourceRoot":"","sources":["../../../src/lending/aave-v2-type/publicCallBuild.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,eAAO,MAAM,iCAAiC,GAC5C,SAAS,MAAM,EACf,QAAQ,MAAM;;;;GAqBf,CAAA"}
|
|
@@ -1,88 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getAaveAssets, getAaveStyleProtocolTokenMap, getAaveTypePoolDataProviderAddress, } from '../../assets';
|
|
3
|
-
import { Lender } from '@1delta/lender-registry';
|
|
4
|
-
import { getAaveTypeIncentivesControllerAddress } from '../addresses';
|
|
1
|
+
import { getAaveAssets, getAaveTypePoolDataProviderAddress, } from '../../assets';
|
|
5
2
|
export const buildAaveV2StyleLenderReserveCall = (chainId, lender) => {
|
|
6
3
|
const providerAddress = getAaveTypePoolDataProviderAddress(chainId, lender);
|
|
7
4
|
const underlyingTokensArray = getAaveAssets(chainId, lender);
|
|
8
5
|
switch (lender) {
|
|
9
|
-
case Lender.AURELIUS: {
|
|
10
|
-
const aaveprotocolTokens = getAaveStyleProtocolTokenMap(chainId, lender);
|
|
11
|
-
const incentivesController = getAaveTypeIncentivesControllerAddress(chainId, lender);
|
|
12
|
-
const [reward0, reward1] = AURELIUS_REWARD_ASSETS.map((t) => t.address);
|
|
13
|
-
return [
|
|
14
|
-
...underlyingTokensArray.flatMap((asset) => [
|
|
15
|
-
{
|
|
16
|
-
address: providerAddress,
|
|
17
|
-
name: 'getReserveData',
|
|
18
|
-
params: [asset],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
address: providerAddress,
|
|
22
|
-
name: 'getReserveConfigurationData',
|
|
23
|
-
params: [asset],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
address: incentivesController,
|
|
27
|
-
name: 'getRewardsData',
|
|
28
|
-
params: [aaveprotocolTokens[asset].aToken, reward0],
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
address: incentivesController,
|
|
32
|
-
name: 'getRewardsData',
|
|
33
|
-
params: [aaveprotocolTokens[asset].aToken, reward1],
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
address: incentivesController,
|
|
37
|
-
name: 'getRewardsData',
|
|
38
|
-
params: [aaveprotocolTokens[asset].vToken, reward0],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
address: incentivesController,
|
|
42
|
-
name: 'getRewardsData',
|
|
43
|
-
params: [aaveprotocolTokens[asset].vToken, reward1],
|
|
44
|
-
},
|
|
45
|
-
]),
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
case Lender.LENDLE: {
|
|
49
|
-
const incentivesController = getAaveTypeIncentivesControllerAddress(chainId, lender);
|
|
50
|
-
const aaveprotocolTokens = getAaveStyleProtocolTokenMap(chainId, lender);
|
|
51
|
-
return [
|
|
52
|
-
...underlyingTokensArray.flatMap((asset) => [
|
|
53
|
-
{
|
|
54
|
-
address: providerAddress,
|
|
55
|
-
name: 'getReserveData',
|
|
56
|
-
params: [asset],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
address: providerAddress,
|
|
60
|
-
name: 'getReserveConfigurationData',
|
|
61
|
-
params: [asset],
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
address: incentivesController,
|
|
65
|
-
name: 'poolInfo',
|
|
66
|
-
params: [aaveprotocolTokens[asset].aToken],
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
address: incentivesController,
|
|
70
|
-
name: 'poolInfo',
|
|
71
|
-
params: [aaveprotocolTokens[asset].vToken],
|
|
72
|
-
},
|
|
73
|
-
]),
|
|
74
|
-
{
|
|
75
|
-
address: incentivesController,
|
|
76
|
-
name: 'rewardsPerSecond',
|
|
77
|
-
params: [],
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
address: incentivesController,
|
|
81
|
-
name: 'totalAllocPoint',
|
|
82
|
-
params: [],
|
|
83
|
-
},
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
6
|
default:
|
|
87
7
|
return [
|
|
88
8
|
...underlyingTokensArray.flatMap((tk) => [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicCallParse.d.ts","sourceRoot":"","sources":["../../../src/lending/aave-v2-type/publicCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"publicCallParse.d.ts","sourceRoot":"","sources":["../../../src/lending/aave-v2-type/publicCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAYhD,OAAO,EACL,2BAA2B,EAG5B,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAG3C,eAAO,MAAM,8BAA8B,GACzC,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,QAAQ;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACnC,kBAAkB,gBAAgB,EAClC,YAAW,gBAAqB,KAC/B,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,2BAA2B,GAAG,SAAS,EAAE,MAAM,CAkKnE,CAAA"}
|
|
@@ -1,204 +1,10 @@
|
|
|
1
1
|
import { Lender } from '@1delta/lender-registry';
|
|
2
2
|
import { getAaveAssets, LENDER_MODE_NO_MODE, toGenericPriceKey, toOracleKey, } from '../../assets';
|
|
3
|
-
import { BPS,
|
|
4
|
-
import { AaveV2TypeGetReserveConfigurationData, AaveV2TypeGetReserveDataIndexes,
|
|
3
|
+
import { BPS, formatAaveRawApyToApr, parseRawAmount, } from '../../utils/parsing';
|
|
4
|
+
import { AaveV2TypeGetReserveConfigurationData, AaveV2TypeGetReserveDataIndexes, } from './types';
|
|
5
5
|
import { Chain } from '@1delta/chain-registry';
|
|
6
6
|
export const getAaveV2ReservesDataConverter = (lender, chainId, prices, additionalYields, tokenList = {}) => {
|
|
7
7
|
switch (lender) {
|
|
8
|
-
case Lender.AURELIUS: {
|
|
9
|
-
const assetsToQuery = getAaveAssets(chainId, lender);
|
|
10
|
-
const expectedNumberOfCalls = assetsToQuery.length * 6;
|
|
11
|
-
return [
|
|
12
|
-
(data) => {
|
|
13
|
-
if (data.length !== expectedNumberOfCalls) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
const resultReserves = {};
|
|
17
|
-
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
18
|
-
const asset = assetsToQuery[i];
|
|
19
|
-
const reserveData = data[i * 6];
|
|
20
|
-
const configData = data[i * 6 + 1];
|
|
21
|
-
const [, emission0PerSecondCollateral, ,] = data[i * 6 + 2];
|
|
22
|
-
const [, emission1PerSecondCollateral, ,] = data[i * 6 + 3];
|
|
23
|
-
const [, emission0PerSecondDebt, ,] = data[i * 6 + 4];
|
|
24
|
-
const [, emission1PerSecondDebt, ,] = data[i * 6 + 5];
|
|
25
|
-
const assetMeta = tokenList[asset];
|
|
26
|
-
const decimals = assetMeta?.decimals ?? 18;
|
|
27
|
-
const totalStableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalStableDebt]?.toString(), decimals);
|
|
28
|
-
const totalVariableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalVariableDebt]?.toString(), decimals);
|
|
29
|
-
const liquidity = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals);
|
|
30
|
-
const totalAToken = Number(liquidity) +
|
|
31
|
-
Number(totalStableDebt) +
|
|
32
|
-
Number(totalVariableDebt);
|
|
33
|
-
const oracleKey = toOracleKey(assetMeta?.assetGroup) ??
|
|
34
|
-
toGenericPriceKey(asset, chainId);
|
|
35
|
-
const price = prices[oracleKey] ?? 1;
|
|
36
|
-
const totalDepositsUSD = totalAToken * price;
|
|
37
|
-
const totalDebtUSD = Number(totalVariableDebt) * price;
|
|
38
|
-
resultReserves[asset] = {
|
|
39
|
-
poolId: asset,
|
|
40
|
-
underlying: asset,
|
|
41
|
-
asset: assetMeta,
|
|
42
|
-
// token amounts
|
|
43
|
-
totalDeposits: totalAToken,
|
|
44
|
-
totalDebtStable: totalStableDebt,
|
|
45
|
-
totalDebt: totalVariableDebt,
|
|
46
|
-
totalLiquidity: liquidity,
|
|
47
|
-
// USD amounts
|
|
48
|
-
totalDepositsUSD,
|
|
49
|
-
totalDebtStableUSD: Number(totalStableDebt) * price,
|
|
50
|
-
totalDebtUSD,
|
|
51
|
-
totalLiquidityUSD: Number(liquidity) * price,
|
|
52
|
-
// rates
|
|
53
|
-
depositRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.liquidityRate]?.toString()),
|
|
54
|
-
variableBorrowRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.variableBorrowRate]?.toString()),
|
|
55
|
-
stableBorrowRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.stableBorrowRate]?.toString()),
|
|
56
|
-
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
57
|
-
// rewards
|
|
58
|
-
rewards: {
|
|
59
|
-
WMNT: {
|
|
60
|
-
depositRate: (convertRateToApr(parseRawAmount(emission0PerSecondCollateral)) /
|
|
61
|
-
totalDepositsUSD) *
|
|
62
|
-
prices['WMNT'],
|
|
63
|
-
variableBorrowRate: (convertRateToApr(parseRawAmount(emission0PerSecondDebt)) /
|
|
64
|
-
totalDebtUSD) *
|
|
65
|
-
prices['WMNT'],
|
|
66
|
-
stableBorrowRate: 0,
|
|
67
|
-
},
|
|
68
|
-
// oAU allows for a 50% discount to pruchase AU, hence the price is the price of AU divided by 2
|
|
69
|
-
OAU: {
|
|
70
|
-
depositRate: ((convertRateToApr(parseRawAmount(emission1PerSecondCollateral)) /
|
|
71
|
-
totalDepositsUSD) *
|
|
72
|
-
(prices['AU'] ?? 0)) /
|
|
73
|
-
2,
|
|
74
|
-
variableBorrowRate: ((convertRateToApr(parseRawAmount(emission1PerSecondDebt)) /
|
|
75
|
-
totalDebtUSD) *
|
|
76
|
-
(prices['AU'] ?? 0)) /
|
|
77
|
-
2,
|
|
78
|
-
stableBorrowRate: 0,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
decimals: Number(configData?.[AaveV2TypeGetReserveConfigurationData.decimals]),
|
|
82
|
-
config: {
|
|
83
|
-
[LENDER_MODE_NO_MODE]: {
|
|
84
|
-
category: LENDER_MODE_NO_MODE,
|
|
85
|
-
// collateral factors
|
|
86
|
-
borrowCollateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData.ltv].toString()) / BPS,
|
|
87
|
-
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
88
|
-
.liquidationThreshold].toString()) / BPS,
|
|
89
|
-
borrowFactor: 1,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
liquidationBonus: Number(configData?.[AaveV2TypeGetReserveConfigurationData.liquidationBonus].toString()) / BPS,
|
|
93
|
-
// flags
|
|
94
|
-
collateralActive: configData?.[AaveV2TypeGetReserveConfigurationData.usageAsCollateralEnabled],
|
|
95
|
-
borrowingEnabled: configData?.[AaveV2TypeGetReserveConfigurationData.borrowingEnabled],
|
|
96
|
-
hasStable: configData?.[AaveV2TypeGetReserveConfigurationData.stableBorrowRateEnabled],
|
|
97
|
-
isActive: configData?.[AaveV2TypeGetReserveConfigurationData.isActive],
|
|
98
|
-
isFrozen: configData?.[AaveV2TypeGetReserveConfigurationData.isFrozen],
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
data: resultReserves,
|
|
103
|
-
chainId,
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
expectedNumberOfCalls,
|
|
107
|
-
];
|
|
108
|
-
}
|
|
109
|
-
case Lender.LENDLE: {
|
|
110
|
-
const assetsToQuery = getAaveAssets(chainId, lender);
|
|
111
|
-
const expectedNumberOfCalls = assetsToQuery.length * 4 + 2;
|
|
112
|
-
return [
|
|
113
|
-
(data) => {
|
|
114
|
-
if (data.length !== expectedNumberOfCalls) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
const rewardsPerSecond = Number(parseRawAmount(data[expectedNumberOfCalls - 2].toString(), 18));
|
|
118
|
-
const totalAllocPoint = Number(data[expectedNumberOfCalls - 1].toString());
|
|
119
|
-
const resultReserves = {};
|
|
120
|
-
const lendPrice = prices['LEND'];
|
|
121
|
-
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
122
|
-
const asset = assetsToQuery[i];
|
|
123
|
-
const reserveData = data[i * 4];
|
|
124
|
-
const configData = data[i * 4 + 1];
|
|
125
|
-
const collateralRewardIndex = i * 4 + 2;
|
|
126
|
-
const borrowRewardIndex = i * 4 + 3;
|
|
127
|
-
const collateralRewards = (Number(data?.[collateralRewardIndex]?.[AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint].toString()) /
|
|
128
|
-
totalAllocPoint) *
|
|
129
|
-
rewardsPerSecond;
|
|
130
|
-
const borrowRewards = (Number(data?.[borrowRewardIndex]?.[AaveV2TypeIncentivesControllerPoolInfoIndexes.allocPoint].toString()) /
|
|
131
|
-
totalAllocPoint) *
|
|
132
|
-
rewardsPerSecond;
|
|
133
|
-
const assetMeta = tokenList[asset];
|
|
134
|
-
const decimals = assetMeta?.decimals ?? 18;
|
|
135
|
-
const totalStableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalStableDebt]?.toString(), decimals);
|
|
136
|
-
const totalVariableDebt = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.totalVariableDebt]?.toString(), decimals);
|
|
137
|
-
const liquidity = parseRawAmount(reserveData?.[AaveV2TypeGetReserveDataIndexes.availableLiquidity]?.toString(), decimals);
|
|
138
|
-
const totalAToken = Number(liquidity) +
|
|
139
|
-
Number(totalStableDebt) +
|
|
140
|
-
Number(totalVariableDebt);
|
|
141
|
-
const oracleKey = toOracleKey(assetMeta?.assetGroup) ??
|
|
142
|
-
toGenericPriceKey(asset, chainId);
|
|
143
|
-
const price = prices?.[oracleKey] ?? 1;
|
|
144
|
-
const totalDepositsUSD = totalAToken * price;
|
|
145
|
-
const totalDebtUSD = Number(totalVariableDebt) * price;
|
|
146
|
-
resultReserves[asset] = {
|
|
147
|
-
poolId: asset,
|
|
148
|
-
underlying: asset,
|
|
149
|
-
asset: assetMeta,
|
|
150
|
-
// token amounts
|
|
151
|
-
totalDeposits: totalAToken,
|
|
152
|
-
totalDebtStable: totalStableDebt,
|
|
153
|
-
totalDebt: totalVariableDebt,
|
|
154
|
-
totalLiquidity: liquidity,
|
|
155
|
-
// USD amounts
|
|
156
|
-
totalDepositsUSD,
|
|
157
|
-
totalDebtStableUSD: Number(totalStableDebt) * price,
|
|
158
|
-
totalDebtUSD,
|
|
159
|
-
totalLiquidityUSD: Number(liquidity) * price,
|
|
160
|
-
// rates
|
|
161
|
-
depositRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.liquidityRate]?.toString()),
|
|
162
|
-
variableBorrowRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.variableBorrowRate]?.toString()),
|
|
163
|
-
stableBorrowRate: formatAaveRawApyToApr(reserveData?.[AaveV2TypeGetReserveDataIndexes.stableBorrowRate]?.toString()),
|
|
164
|
-
stakingYield: additionalYields.intrinsicYields[oracleKey] ?? 0,
|
|
165
|
-
// rewards
|
|
166
|
-
rewards: {
|
|
167
|
-
LEND: {
|
|
168
|
-
depositRate: convertRateToApr(collateralRewards / totalDepositsUSD) *
|
|
169
|
-
lendPrice,
|
|
170
|
-
variableBorrowRate: convertRateToApr(totalDebtUSD > 0 ? borrowRewards / totalDebtUSD : 0) * lendPrice,
|
|
171
|
-
stableBorrowRate: 0,
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
decimals: Number(configData?.[AaveV2TypeGetReserveConfigurationData.decimals]),
|
|
175
|
-
config: {
|
|
176
|
-
[LENDER_MODE_NO_MODE]: {
|
|
177
|
-
category: LENDER_MODE_NO_MODE,
|
|
178
|
-
// collateral factors
|
|
179
|
-
borrowCollateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData.ltv].toString()) / BPS,
|
|
180
|
-
collateralFactor: Number(configData?.[AaveV2TypeGetReserveConfigurationData
|
|
181
|
-
.liquidationThreshold].toString()) / BPS,
|
|
182
|
-
borrowFactor: 1,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
liquidationBonus: Number(configData?.[AaveV2TypeGetReserveConfigurationData.liquidationBonus].toString()) / BPS,
|
|
186
|
-
// flags
|
|
187
|
-
collateralActive: configData?.[AaveV2TypeGetReserveConfigurationData.usageAsCollateralEnabled],
|
|
188
|
-
borrowingEnabled: configData?.[AaveV2TypeGetReserveConfigurationData.borrowingEnabled],
|
|
189
|
-
hasStable: configData?.[AaveV2TypeGetReserveConfigurationData.stableBorrowRateEnabled],
|
|
190
|
-
isActive: configData?.[AaveV2TypeGetReserveConfigurationData.isActive],
|
|
191
|
-
isFrozen: configData?.[AaveV2TypeGetReserveConfigurationData.isFrozen],
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
data: resultReserves,
|
|
196
|
-
chainId,
|
|
197
|
-
};
|
|
198
|
-
},
|
|
199
|
-
expectedNumberOfCalls,
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
8
|
/** AAVE V2 style with rewards from state */
|
|
203
9
|
default: {
|
|
204
10
|
const assetsToQuery = getAaveAssets(chainId, lender);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compoundV3.d.ts","sourceRoot":"","sources":["../../../src/lending/addresses/compoundV3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGhD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,MAAM,SAA2B,GAChC,MAAM,GAAG,SAAS,CAEpB;AAED,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,MAAM,OAG/D;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,OAGrD;
|
|
1
|
+
{"version":3,"file":"compoundV3.d.ts","sourceRoot":"","sources":["../../../src/lending/addresses/compoundV3.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGhD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,MAAM,SAA2B,GAChC,MAAM,GAAG,SAAS,CAEpB;AAED,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,MAAM,OAG/D;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,OAGrD;AA0BD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,OAAO,EAAE,MAAM;;;EAGhB"}
|
|
@@ -22,6 +22,7 @@ const addressesCompoundV3 = {
|
|
|
22
22
|
[Chain.ETHEREUM_MAINNET]: '0xCe434378adacC51d54312c872113D687Ac19B516',
|
|
23
23
|
[Chain.UNICHAIN]: '0x0bd7473CbBf81d9dD936c61117eD230d95006CA2',
|
|
24
24
|
[Chain.LINEA]: '0x7a59ddbB76521E8982Fa3A08598C9a83b14A6C07',
|
|
25
|
+
[Chain.SCROLL]: '0x32198Ee619fAd24169fa94A149Cb5205701C6AB1',
|
|
25
26
|
},
|
|
26
27
|
cometRewards: {
|
|
27
28
|
[Chain.POLYGON_MAINNET]: '0x45939657d1CA34A8FA39A924B71D28Fe8431e581',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userCallBuild.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/aave-v2-type/userCallBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"userCallBuild.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/aave-v2-type/userCallBuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAqBhD,eAAO,MAAM,mBAAmB,GAC9B,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,SAAS,MAAM,EAAE,KAChB,IAAI,EAON,CAAA"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getAaveAssets, getAaveStyleProtocolTokenMap, getAaveTypePoolDataProviderAddress, } from '../../../assets';
|
|
3
|
-
import { getAaveTypeIncentivesControllerAddress, getAaveTypeMultiFeeDistribution, } from '../../addresses';
|
|
1
|
+
import { getAaveAssets, getAaveTypePoolDataProviderAddress, } from '../../../assets';
|
|
4
2
|
const getBaseAaveV2Calls = (chainId, account, lender, assetsToQuery) => {
|
|
5
3
|
return assetsToQuery.flatMap((tk) => [
|
|
6
4
|
{
|
|
@@ -12,70 +10,6 @@ const getBaseAaveV2Calls = (chainId, account, lender, assetsToQuery) => {
|
|
|
12
10
|
};
|
|
13
11
|
export const buildAaveV2UserCall = (chainId, lender, account, assets) => {
|
|
14
12
|
switch (lender) {
|
|
15
|
-
case Lender.AURELIUS: {
|
|
16
|
-
const rewarder = getAaveTypeIncentivesControllerAddress(chainId, lender);
|
|
17
|
-
const assetsToQuery = assets ?? getAaveAssets(chainId, lender);
|
|
18
|
-
const aaveTokenMap = getAaveStyleProtocolTokenMap(chainId, lender);
|
|
19
|
-
const aTokens = Object.values(aaveTokenMap).map((a) => a.aToken);
|
|
20
|
-
const vTokens = Object.values(aaveTokenMap).map((a) => a.vToken);
|
|
21
|
-
return [
|
|
22
|
-
...getBaseAaveV2Calls(chainId, account, lender, assetsToQuery),
|
|
23
|
-
{
|
|
24
|
-
address: rewarder,
|
|
25
|
-
name: 'getAllUserRewardsBalance',
|
|
26
|
-
params: [
|
|
27
|
-
[...Object.values(aTokens), ...Object.values(vTokens)],
|
|
28
|
-
account,
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
case Lender.MERIDIAN:
|
|
34
|
-
case Lender.LENDLE: {
|
|
35
|
-
const rewarder = getAaveTypeIncentivesControllerAddress(chainId, lender);
|
|
36
|
-
const assetsToQuery = getAaveAssets(chainId, lender);
|
|
37
|
-
const aaveTokenMap = getAaveStyleProtocolTokenMap(chainId, lender);
|
|
38
|
-
let lAndVTokensAddresses = [];
|
|
39
|
-
const aTokens = Object.values(aaveTokenMap).map((a) => a.aToken);
|
|
40
|
-
const vTokens = Object.values(aaveTokenMap).map((a) => a.vToken);
|
|
41
|
-
// rewards are accrued for both l and v tokens
|
|
42
|
-
assetsToQuery.forEach((_, i) => {
|
|
43
|
-
lAndVTokensAddresses.push(aTokens[i], vTokens[i]);
|
|
44
|
-
});
|
|
45
|
-
let rewardsBalance;
|
|
46
|
-
let unclaimedRewards;
|
|
47
|
-
if (lender === Lender.MERIDIAN) {
|
|
48
|
-
rewardsBalance = {
|
|
49
|
-
address: rewarder,
|
|
50
|
-
name: 'getRewardsBalance',
|
|
51
|
-
params: [lAndVTokensAddresses, account],
|
|
52
|
-
};
|
|
53
|
-
// total vested LEND rewards
|
|
54
|
-
unclaimedRewards = {
|
|
55
|
-
address: rewarder,
|
|
56
|
-
name: 'getUserUnclaimedRewards',
|
|
57
|
-
params: [account],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
rewardsBalance = {
|
|
62
|
-
address: rewarder,
|
|
63
|
-
name: 'claimableReward',
|
|
64
|
-
params: [account, lAndVTokensAddresses],
|
|
65
|
-
};
|
|
66
|
-
// total vested TAIKo rewards
|
|
67
|
-
unclaimedRewards = {
|
|
68
|
-
address: getAaveTypeMultiFeeDistribution(chainId, lender),
|
|
69
|
-
name: 'earnedBalances',
|
|
70
|
-
params: [account],
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return [
|
|
74
|
-
...getBaseAaveV2Calls(chainId, account, lender, assetsToQuery),
|
|
75
|
-
rewardsBalance,
|
|
76
|
-
unclaimedRewards,
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
13
|
default: {
|
|
80
14
|
const assetsToQuery = getAaveAssets(chainId, lender);
|
|
81
15
|
return getBaseAaveV2Calls(chainId, account, lender, assetsToQuery);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userCallParse.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/aave-v2-type/userCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAEL,yBAAyB,
|
|
1
|
+
{"version":3,"file":"userCallParse.d.ts","sourceRoot":"","sources":["../../../../src/lending/user-data/aave-v2-type/userCallParse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAEL,yBAAyB,EAC1B,MAAM,UAAU,CAAA;AAKjB,eAAO,MAAM,0BAA0B,GACrC,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,yBAAyB,GAAG,SAAS,EAAE,MAAM,CAsDjE,CAAA"}
|
|
@@ -1,167 +1,9 @@
|
|
|
1
|
-
import { Lender } from '@1delta/lender-registry';
|
|
2
1
|
import { toGenericPriceKey, toOracleKey } from '../../../assets';
|
|
3
2
|
import { AaveV2TypeGetUserReserveData, } from '../types';
|
|
4
|
-
import { AURELIUS_REWARD_ASSETS } from '../../aave-v2-type/misc';
|
|
5
3
|
import { createBaseTypeUserState } from '../utils';
|
|
6
4
|
import { parseRawAmount } from '../../../utils/parsing';
|
|
7
5
|
export const getAaveV2UserDataConverter = (lender, chainId, account, prices, pricesHist, lenderData) => {
|
|
8
6
|
switch (lender) {
|
|
9
|
-
case Lender.AURELIUS: {
|
|
10
|
-
const assetsToQuery = Object.keys(lenderData);
|
|
11
|
-
const expectedNumberOfCalls = assetsToQuery.length + 1;
|
|
12
|
-
return [
|
|
13
|
-
(data) => {
|
|
14
|
-
if (data.length !== expectedNumberOfCalls) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
const lendingPositions = {};
|
|
18
|
-
let totalDebt24h = 0;
|
|
19
|
-
let totalDeposits24h = 0;
|
|
20
|
-
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
21
|
-
const asset = assetsToQuery[i];
|
|
22
|
-
const { dataForAsset, addedDebt, addedDeposits } = createAaveV2Entry(i, data, chainId, lenderData[asset].asset, prices, pricesHist, 0);
|
|
23
|
-
if (!dataForAsset)
|
|
24
|
-
continue;
|
|
25
|
-
totalDebt24h += addedDebt;
|
|
26
|
-
totalDeposits24h += addedDeposits;
|
|
27
|
-
lendingPositions[asset] = dataForAsset;
|
|
28
|
-
}
|
|
29
|
-
const startIndex = assetsToQuery.length;
|
|
30
|
-
const rewardMapping = Object.fromEntries(data[startIndex][0].map((key, index) => [
|
|
31
|
-
key.toLowerCase(),
|
|
32
|
-
data[startIndex][1][index],
|
|
33
|
-
]));
|
|
34
|
-
const rewards = {};
|
|
35
|
-
for (let i = 0; i < AURELIUS_REWARD_ASSETS.length; i++) {
|
|
36
|
-
const asset = AURELIUS_REWARD_ASSETS[i];
|
|
37
|
-
const reward = Number(parseRawAmount(rewardMapping[asset.address.toLowerCase()].toString(), asset.decimals));
|
|
38
|
-
rewards[asset.symbol] = {
|
|
39
|
-
totalRewards: reward,
|
|
40
|
-
claimableRewards: reward,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
const payload = {
|
|
44
|
-
chainId,
|
|
45
|
-
account,
|
|
46
|
-
lendingPositions: { '0': lendingPositions },
|
|
47
|
-
rewards,
|
|
48
|
-
};
|
|
49
|
-
const userData = createBaseTypeUserState(payload, lenderData, totalDeposits24h, totalDebt24h);
|
|
50
|
-
return {
|
|
51
|
-
...payload,
|
|
52
|
-
...userData,
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
expectedNumberOfCalls,
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
case Lender.LENDLE: {
|
|
59
|
-
const assetsToQuery = Object.keys(lenderData);
|
|
60
|
-
const expectedNumberOfCalls = assetsToQuery.length + 2;
|
|
61
|
-
return [
|
|
62
|
-
(data) => {
|
|
63
|
-
if (data.length !== expectedNumberOfCalls) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
const claimableRewards = data[expectedNumberOfCalls - 2];
|
|
67
|
-
// map claimable rewards to tokens
|
|
68
|
-
// foreach asset, we sum the l and v token rewards
|
|
69
|
-
const mappedClaimableRewardsToTokens = assetsToQuery.map((name, index) => {
|
|
70
|
-
return {
|
|
71
|
-
[name]: Number(parseRawAmount(claimableRewards?.[index * 2]?.toString(), 18)) +
|
|
72
|
-
Number(parseRawAmount(claimableRewards?.[index * 2 + 1]?.toString(), 18)),
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
const lendingPositions = {};
|
|
76
|
-
let totalClaimableLend = 0;
|
|
77
|
-
let totalDebt24h = 0;
|
|
78
|
-
let totalDeposits24h = 0;
|
|
79
|
-
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
80
|
-
const asset = assetsToQuery[i];
|
|
81
|
-
totalClaimableLend += mappedClaimableRewardsToTokens[i][asset];
|
|
82
|
-
const { dataForAsset, addedDebt, addedDeposits } = createAaveV2Entry(i, data, chainId, lenderData[asset].asset, prices, pricesHist, mappedClaimableRewardsToTokens[i][asset]);
|
|
83
|
-
if (!dataForAsset)
|
|
84
|
-
continue;
|
|
85
|
-
totalDebt24h += addedDebt;
|
|
86
|
-
totalDeposits24h += addedDeposits;
|
|
87
|
-
lendingPositions[asset] = dataForAsset;
|
|
88
|
-
}
|
|
89
|
-
const rewards = {};
|
|
90
|
-
const earnedBalances = data[expectedNumberOfCalls - 1];
|
|
91
|
-
const lendRewards = Number(parseRawAmount(earnedBalances[0].toString(), 18));
|
|
92
|
-
rewards['LEND'] = {
|
|
93
|
-
totalRewards: lendRewards + totalClaimableLend,
|
|
94
|
-
claimableRewards: totalClaimableLend,
|
|
95
|
-
};
|
|
96
|
-
const payload = {
|
|
97
|
-
chainId,
|
|
98
|
-
account,
|
|
99
|
-
lendingPositions: { '0': lendingPositions },
|
|
100
|
-
rewards,
|
|
101
|
-
};
|
|
102
|
-
const userData = createBaseTypeUserState(payload, lenderData, totalDeposits24h, totalDebt24h);
|
|
103
|
-
return {
|
|
104
|
-
...payload,
|
|
105
|
-
...userData,
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
expectedNumberOfCalls,
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
case Lender.MERIDIAN: {
|
|
112
|
-
const assetsToQuery = Object.keys(lenderData);
|
|
113
|
-
const expectedNumberOfCalls = assetsToQuery.length + 2;
|
|
114
|
-
return [
|
|
115
|
-
(data) => {
|
|
116
|
-
if (data.length !== expectedNumberOfCalls) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
const rewardsBalanceArray = data[expectedNumberOfCalls - 2];
|
|
120
|
-
const totalUnclaimedRewards = data[expectedNumberOfCalls - 1];
|
|
121
|
-
const totalRewards = Number(parseRawAmount(totalUnclaimedRewards.toString(), 18));
|
|
122
|
-
// map claimable rewards to tokens
|
|
123
|
-
// foreach asset, we sum the l and v token rewards from the rewards balance array
|
|
124
|
-
const mappedClaimableRewardsToTokens = assetsToQuery.map((name, index) => {
|
|
125
|
-
return {
|
|
126
|
-
[name]: Number(parseRawAmount(rewardsBalanceArray[index * 2]?.toString() || '0', 18)) +
|
|
127
|
-
Number(parseRawAmount(rewardsBalanceArray[index * 2 + 1]?.toString() || '0', 18)),
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
const lendingPositions = {};
|
|
131
|
-
let totalDebt24h = 0;
|
|
132
|
-
let totalDeposits24h = 0;
|
|
133
|
-
let totalClaimableRewards = 0;
|
|
134
|
-
for (let i = 0; i < assetsToQuery.length; i++) {
|
|
135
|
-
const asset = assetsToQuery[i];
|
|
136
|
-
const assetClaimableRewards = mappedClaimableRewardsToTokens[i][asset];
|
|
137
|
-
totalClaimableRewards += assetClaimableRewards;
|
|
138
|
-
const { dataForAsset, addedDebt, addedDeposits } = createAaveV2Entry(i, data, chainId, lenderData[asset].asset, prices, pricesHist, assetClaimableRewards);
|
|
139
|
-
if (!dataForAsset)
|
|
140
|
-
continue;
|
|
141
|
-
totalDebt24h += addedDebt;
|
|
142
|
-
totalDeposits24h += addedDeposits;
|
|
143
|
-
lendingPositions[asset] = dataForAsset;
|
|
144
|
-
}
|
|
145
|
-
const rewards = {};
|
|
146
|
-
rewards['TAIKO'] = {
|
|
147
|
-
totalRewards,
|
|
148
|
-
claimableRewards: totalClaimableRewards,
|
|
149
|
-
};
|
|
150
|
-
const payload = {
|
|
151
|
-
chainId,
|
|
152
|
-
account,
|
|
153
|
-
lendingPositions: { '0': lendingPositions },
|
|
154
|
-
rewards,
|
|
155
|
-
};
|
|
156
|
-
const userData = createBaseTypeUserState(payload, lenderData, totalDeposits24h, totalDebt24h);
|
|
157
|
-
return {
|
|
158
|
-
...payload,
|
|
159
|
-
...userData,
|
|
160
|
-
};
|
|
161
|
-
},
|
|
162
|
-
expectedNumberOfCalls,
|
|
163
|
-
];
|
|
164
|
-
}
|
|
165
7
|
default: {
|
|
166
8
|
const assetsToQuery = Object.keys(lenderData);
|
|
167
9
|
const expectedNumberOfCalls = assetsToQuery.length;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1delta/margin-fetcher",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"@types/async-retry": "^1.4.9",
|
|
18
18
|
"async-retry": "^1.3.3",
|
|
19
19
|
"typescript": "^5.9.2",
|
|
20
|
-
"@1delta/providers": "0.0.
|
|
20
|
+
"@1delta/providers": "0.0.15"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc",
|