@defisaver/positions-sdk 0.0.113 → 0.0.115
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/cjs/config/contracts.d.ts +276 -2
- package/cjs/config/contracts.js +28 -12
- package/cjs/helpers/aaveHelpers/index.d.ts +15 -0
- package/cjs/helpers/aaveHelpers/index.js +58 -1
- package/cjs/types/contracts/generated/AaveLoanInfoV2.d.ts +103 -0
- package/cjs/types/contracts/generated/AaveV3View.d.ts +9 -2
- package/esm/config/contracts.d.ts +276 -2
- package/esm/config/contracts.js +28 -12
- package/esm/helpers/aaveHelpers/index.d.ts +15 -0
- package/esm/helpers/aaveHelpers/index.js +57 -2
- package/esm/types/contracts/generated/AaveLoanInfoV2.d.ts +103 -0
- package/esm/types/contracts/generated/AaveV3View.d.ts +9 -2
- package/package.json +1 -1
- package/src/config/contracts.js +28 -12
- package/src/helpers/aaveHelpers/index.ts +58 -2
- package/src/types/contracts/generated/AaveLoanInfoV2.ts +183 -0
- package/src/types/contracts/generated/AaveV3View.ts +9 -2
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
+
import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
+
import Web3 from 'web3';
|
|
2
4
|
import {
|
|
3
5
|
AaveAssetData, AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAssets, AaveVersions,
|
|
4
6
|
} from '../../types';
|
|
5
|
-
import { wethToEth } from '../../services/utils';
|
|
6
|
-
import {
|
|
7
|
+
import { ethToWeth, wethToEth } from '../../services/utils';
|
|
8
|
+
import {
|
|
9
|
+
aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos,
|
|
10
|
+
} from '../../moneymarket';
|
|
7
11
|
import { calculateNetApy } from '../../staking';
|
|
12
|
+
import { borrowOperations } from '../../constants';
|
|
13
|
+
import { EthAddress, NetworkNumber } from '../../types/common';
|
|
14
|
+
import { AaveLoanInfoV2Contract, AaveV3ViewContract } from '../../contracts';
|
|
15
|
+
import { BaseContract } from '../../types/contracts/generated/types';
|
|
8
16
|
|
|
17
|
+
export const isAaveV2 = ({ selectedMarket }: { selectedMarket: Partial<AaveMarketInfo> }) => selectedMarket.value === AaveVersions.AaveV2;
|
|
9
18
|
export const isAaveV3 = ({ selectedMarket }: { selectedMarket: Partial<AaveMarketInfo> }) => selectedMarket.value === AaveVersions.AaveV3;
|
|
10
19
|
export const isMorphoAaveV2 = ({ selectedMarket }: { selectedMarket: Partial<AaveMarketInfo> }) => selectedMarket.value === AaveVersions.MorphoAaveV2;
|
|
11
20
|
export const isMorphoAaveV3 = ({ selectedMarket }: { selectedMarket: Partial<AaveMarketInfo> }) => selectedMarket.value === AaveVersions.MorphoAaveV3Eth;
|
|
@@ -132,4 +141,51 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
132
141
|
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
133
142
|
}
|
|
134
143
|
return payload;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const getApyAfterValuesEstimationInner = async (selectedMarket: AaveMarketInfo, actions: [{ action: string, amount: string, asset: string }], viewContract: BaseContract, network: NetworkNumber) => {
|
|
147
|
+
const params = actions.map(({ action, asset, amount }) => {
|
|
148
|
+
const isDebtAsset = borrowOperations.includes(action);
|
|
149
|
+
const amountInWei = assetAmountInWei(amount, asset);
|
|
150
|
+
const assetInfo = getAssetInfo(ethToWeth(asset), network);
|
|
151
|
+
let liquidityAdded;
|
|
152
|
+
let liquidityTaken;
|
|
153
|
+
if (isDebtAsset) {
|
|
154
|
+
liquidityAdded = action === 'payback' ? amountInWei : '0';
|
|
155
|
+
liquidityTaken = action === 'borrow' ? amountInWei : '0';
|
|
156
|
+
} else {
|
|
157
|
+
liquidityAdded = action === 'collateral' ? amountInWei : '0';
|
|
158
|
+
liquidityTaken = action === 'withdraw' ? amountInWei : '0';
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
reserveAddress: assetInfo.address,
|
|
162
|
+
liquidityAdded,
|
|
163
|
+
liquidityTaken,
|
|
164
|
+
isDebtAsset,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
const data = await viewContract.methods.getApyAfterValuesEstimation(
|
|
168
|
+
selectedMarket.providerAddress,
|
|
169
|
+
params,
|
|
170
|
+
).call();
|
|
171
|
+
const rates: { [key: string]: { supplyRate: string, borrowRate: string } } = {};
|
|
172
|
+
data.forEach((d: { reserveAddress: EthAddress, supplyRate: string, variableBorrowRate: string }) => {
|
|
173
|
+
const asset = wethToEth(getAssetInfoByAddress(d.reserveAddress, network).symbol);
|
|
174
|
+
rates[asset] = {
|
|
175
|
+
supplyRate: aprToApy(new Dec(d.supplyRate.toString()).div(1e25).toString()),
|
|
176
|
+
borrowRate: aprToApy(new Dec(d.variableBorrowRate.toString()).div(1e25).toString()),
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
return rates;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const getApyAfterValuesEstimation = async (selectedMarket: AaveMarketInfo, actions: [{ action: string, amount: string, asset: string }], web3: Web3, network: NetworkNumber) => {
|
|
183
|
+
if (isAaveV2({ selectedMarket })) {
|
|
184
|
+
return getApyAfterValuesEstimationInner(selectedMarket, actions, AaveLoanInfoV2Contract(web3, network), network);
|
|
185
|
+
}
|
|
186
|
+
if (isAaveV3({ selectedMarket })) {
|
|
187
|
+
return getApyAfterValuesEstimationInner(selectedMarket, actions, AaveV3ViewContract(web3, network), network);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return {};
|
|
135
191
|
};
|
|
@@ -22,6 +22,48 @@ export interface EventOptions {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export declare namespace AaveView {
|
|
25
|
+
export type LiquidityChangeParamsStruct =
|
|
26
|
+
| [string, number | string | BN, number | string | BN, boolean]
|
|
27
|
+
| {
|
|
28
|
+
reserveAddress: string;
|
|
29
|
+
liquidityAdded: number | string | BN;
|
|
30
|
+
liquidityTaken: number | string | BN;
|
|
31
|
+
isDebtAsset: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type LiquidityChangeParamsStructOutputArray = [
|
|
35
|
+
string,
|
|
36
|
+
string,
|
|
37
|
+
string,
|
|
38
|
+
boolean
|
|
39
|
+
];
|
|
40
|
+
export type LiquidityChangeParamsStructOutputStruct = {
|
|
41
|
+
reserveAddress: string;
|
|
42
|
+
liquidityAdded: string;
|
|
43
|
+
liquidityTaken: string;
|
|
44
|
+
isDebtAsset: boolean;
|
|
45
|
+
};
|
|
46
|
+
export type LiquidityChangeParamsStructOutput =
|
|
47
|
+
LiquidityChangeParamsStructOutputArray &
|
|
48
|
+
LiquidityChangeParamsStructOutputStruct;
|
|
49
|
+
|
|
50
|
+
export type EstimatedRatesStruct =
|
|
51
|
+
| [string, number | string | BN, number | string | BN]
|
|
52
|
+
| {
|
|
53
|
+
reserveAddress: string;
|
|
54
|
+
supplyRate: number | string | BN;
|
|
55
|
+
variableBorrowRate: number | string | BN;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type EstimatedRatesStructOutputArray = [string, string, string];
|
|
59
|
+
export type EstimatedRatesStructOutputStruct = {
|
|
60
|
+
reserveAddress: string;
|
|
61
|
+
supplyRate: string;
|
|
62
|
+
variableBorrowRate: string;
|
|
63
|
+
};
|
|
64
|
+
export type EstimatedRatesStructOutput = EstimatedRatesStructOutputArray &
|
|
65
|
+
EstimatedRatesStructOutputStruct;
|
|
66
|
+
|
|
25
67
|
export type TokenInfoFullStruct =
|
|
26
68
|
| [
|
|
27
69
|
string,
|
|
@@ -107,6 +149,51 @@ export declare namespace AaveView {
|
|
|
107
149
|
export type TokenInfoFullStructOutput = TokenInfoFullStructOutputArray &
|
|
108
150
|
TokenInfoFullStructOutputStruct;
|
|
109
151
|
|
|
152
|
+
export type LoanDataStruct =
|
|
153
|
+
| [
|
|
154
|
+
string,
|
|
155
|
+
number | string | BN,
|
|
156
|
+
string[],
|
|
157
|
+
boolean[],
|
|
158
|
+
string[],
|
|
159
|
+
number | string | BN[],
|
|
160
|
+
number | string | BN[],
|
|
161
|
+
number | string | BN[]
|
|
162
|
+
]
|
|
163
|
+
| {
|
|
164
|
+
user: string;
|
|
165
|
+
ratio: number | string | BN;
|
|
166
|
+
collAddr: string[];
|
|
167
|
+
enabledAsColl: boolean[];
|
|
168
|
+
borrowAddr: string[];
|
|
169
|
+
collAmounts: number | string | BN[];
|
|
170
|
+
borrowStableAmounts: number | string | BN[];
|
|
171
|
+
borrowVariableAmounts: number | string | BN[];
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export type LoanDataStructOutputArray = [
|
|
175
|
+
string,
|
|
176
|
+
string,
|
|
177
|
+
string[],
|
|
178
|
+
boolean[],
|
|
179
|
+
string[],
|
|
180
|
+
string[],
|
|
181
|
+
string[],
|
|
182
|
+
string[]
|
|
183
|
+
];
|
|
184
|
+
export type LoanDataStructOutputStruct = {
|
|
185
|
+
user: string;
|
|
186
|
+
ratio: string;
|
|
187
|
+
collAddr: string[];
|
|
188
|
+
enabledAsColl: boolean[];
|
|
189
|
+
borrowAddr: string[];
|
|
190
|
+
collAmounts: string[];
|
|
191
|
+
borrowStableAmounts: string[];
|
|
192
|
+
borrowVariableAmounts: string[];
|
|
193
|
+
};
|
|
194
|
+
export type LoanDataStructOutput = LoanDataStructOutputArray &
|
|
195
|
+
LoanDataStructOutputStruct;
|
|
196
|
+
|
|
110
197
|
export type UserTokenStruct =
|
|
111
198
|
| [
|
|
112
199
|
string,
|
|
@@ -143,6 +230,25 @@ export declare namespace AaveView {
|
|
|
143
230
|
};
|
|
144
231
|
export type UserTokenStructOutput = UserTokenStructOutputArray &
|
|
145
232
|
UserTokenStructOutputStruct;
|
|
233
|
+
|
|
234
|
+
export type TokenInfoStruct =
|
|
235
|
+
| [string, string, number | string | BN, number | string | BN]
|
|
236
|
+
| {
|
|
237
|
+
aTokenAddress: string;
|
|
238
|
+
underlyingTokenAddress: string;
|
|
239
|
+
collateralFactor: number | string | BN;
|
|
240
|
+
price: number | string | BN;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export type TokenInfoStructOutputArray = [string, string, string, string];
|
|
244
|
+
export type TokenInfoStructOutputStruct = {
|
|
245
|
+
aTokenAddress: string;
|
|
246
|
+
underlyingTokenAddress: string;
|
|
247
|
+
collateralFactor: string;
|
|
248
|
+
price: string;
|
|
249
|
+
};
|
|
250
|
+
export type TokenInfoStructOutput = TokenInfoStructOutputArray &
|
|
251
|
+
TokenInfoStructOutputStruct;
|
|
146
252
|
}
|
|
147
253
|
|
|
148
254
|
export interface AaveLoanInfoV2 extends BaseContract {
|
|
@@ -153,21 +259,98 @@ export interface AaveLoanInfoV2 extends BaseContract {
|
|
|
153
259
|
): AaveLoanInfoV2;
|
|
154
260
|
clone(): AaveLoanInfoV2;
|
|
155
261
|
methods: {
|
|
262
|
+
AAVE_REFERRAL_CODE(): NonPayableTransactionObject<string>;
|
|
263
|
+
|
|
264
|
+
AaveIncentivesController(): NonPayableTransactionObject<string>;
|
|
265
|
+
|
|
266
|
+
DATA_PROVIDER_ID(): NonPayableTransactionObject<string>;
|
|
267
|
+
|
|
268
|
+
StakedToken(): NonPayableTransactionObject<string>;
|
|
269
|
+
|
|
270
|
+
enableAsCollateral(
|
|
271
|
+
_market: string,
|
|
272
|
+
_tokenAddr: string,
|
|
273
|
+
_useAsCollateral: boolean
|
|
274
|
+
): NonPayableTransactionObject<void>;
|
|
275
|
+
|
|
276
|
+
getApyAfterValuesEstimation(
|
|
277
|
+
_market: string,
|
|
278
|
+
_reserveParams: AaveView.LiquidityChangeParamsStruct[]
|
|
279
|
+
): NonPayableTransactionObject<AaveView.EstimatedRatesStructOutput[]>;
|
|
280
|
+
|
|
281
|
+
getCollFactors(
|
|
282
|
+
_market: string,
|
|
283
|
+
_tokens: string[]
|
|
284
|
+
): NonPayableTransactionObject<string[]>;
|
|
285
|
+
|
|
156
286
|
getFullTokensInfo(
|
|
157
287
|
_market: string,
|
|
158
288
|
_tokenAddresses: string[]
|
|
159
289
|
): NonPayableTransactionObject<AaveView.TokenInfoFullStructOutput[]>;
|
|
160
290
|
|
|
291
|
+
getIncentivesRewardsBalance(
|
|
292
|
+
_assets: string[],
|
|
293
|
+
_user: string
|
|
294
|
+
): NonPayableTransactionObject<string>;
|
|
295
|
+
|
|
296
|
+
getLoanData(
|
|
297
|
+
_market: string,
|
|
298
|
+
_user: string
|
|
299
|
+
): NonPayableTransactionObject<AaveView.LoanDataStructOutput>;
|
|
300
|
+
|
|
301
|
+
getLoanDataArr(
|
|
302
|
+
_market: string,
|
|
303
|
+
_users: string[]
|
|
304
|
+
): NonPayableTransactionObject<AaveView.LoanDataStructOutput[]>;
|
|
305
|
+
|
|
161
306
|
getPrices(
|
|
162
307
|
_market: string,
|
|
163
308
|
_tokens: string[]
|
|
164
309
|
): NonPayableTransactionObject<string[]>;
|
|
165
310
|
|
|
311
|
+
getRatio(
|
|
312
|
+
_market: string,
|
|
313
|
+
_user: string
|
|
314
|
+
): NonPayableTransactionObject<string>;
|
|
315
|
+
|
|
316
|
+
getRatios(
|
|
317
|
+
_market: string,
|
|
318
|
+
_users: string[]
|
|
319
|
+
): NonPayableTransactionObject<string[]>;
|
|
320
|
+
|
|
321
|
+
getSafetyRatio(
|
|
322
|
+
_market: string,
|
|
323
|
+
_user: string
|
|
324
|
+
): NonPayableTransactionObject<string>;
|
|
325
|
+
|
|
326
|
+
getStakingRewardsBalance(
|
|
327
|
+
_staker: string
|
|
328
|
+
): NonPayableTransactionObject<string>;
|
|
329
|
+
|
|
166
330
|
getTokenBalances(
|
|
167
331
|
_market: string,
|
|
168
332
|
_user: string,
|
|
169
333
|
_tokens: string[]
|
|
170
334
|
): NonPayableTransactionObject<AaveView.UserTokenStructOutput[]>;
|
|
335
|
+
|
|
336
|
+
getTokenInfoFull(
|
|
337
|
+
_dataProvider: string,
|
|
338
|
+
_priceOracleAddress: string,
|
|
339
|
+
_token: string
|
|
340
|
+
): NonPayableTransactionObject<AaveView.TokenInfoFullStructOutput>;
|
|
341
|
+
|
|
342
|
+
getTokensInfo(
|
|
343
|
+
_market: string,
|
|
344
|
+
_tokenAddresses: string[]
|
|
345
|
+
): NonPayableTransactionObject<AaveView.TokenInfoStructOutput[]>;
|
|
346
|
+
|
|
347
|
+
getUserUnclaimedRewards(_user: string): NonPayableTransactionObject<string>;
|
|
348
|
+
|
|
349
|
+
switchRateMode(
|
|
350
|
+
_market: string,
|
|
351
|
+
_tokenAddr: string,
|
|
352
|
+
_rateMode: number | string | BN
|
|
353
|
+
): NonPayableTransactionObject<void>;
|
|
171
354
|
};
|
|
172
355
|
events: {
|
|
173
356
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -23,18 +23,25 @@ export interface EventOptions {
|
|
|
23
23
|
|
|
24
24
|
export declare namespace AaveV3View {
|
|
25
25
|
export type LiquidityChangeParamsStruct =
|
|
26
|
-
| [string, number | string | BN, number | string | BN]
|
|
26
|
+
| [string, number | string | BN, number | string | BN, boolean]
|
|
27
27
|
| {
|
|
28
28
|
reserveAddress: string;
|
|
29
29
|
liquidityAdded: number | string | BN;
|
|
30
30
|
liquidityTaken: number | string | BN;
|
|
31
|
+
isDebtAsset: boolean;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
export type LiquidityChangeParamsStructOutputArray = [
|
|
34
|
+
export type LiquidityChangeParamsStructOutputArray = [
|
|
35
|
+
string,
|
|
36
|
+
string,
|
|
37
|
+
string,
|
|
38
|
+
boolean
|
|
39
|
+
];
|
|
34
40
|
export type LiquidityChangeParamsStructOutputStruct = {
|
|
35
41
|
reserveAddress: string;
|
|
36
42
|
liquidityAdded: string;
|
|
37
43
|
liquidityTaken: string;
|
|
44
|
+
isDebtAsset: boolean;
|
|
38
45
|
};
|
|
39
46
|
export type LiquidityChangeParamsStructOutput =
|
|
40
47
|
LiquidityChangeParamsStructOutputArray &
|