@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,4 +1,9 @@
|
|
|
1
|
+
import Web3 from 'web3';
|
|
1
2
|
import { AaveHelperCommon, AaveMarketInfo, AaveV3AggregatedPositionData, AaveV3AssetsData, AaveV3UsedAssets } from '../../types';
|
|
3
|
+
import { NetworkNumber } from '../../types/common';
|
|
4
|
+
export declare const isAaveV2: ({ selectedMarket }: {
|
|
5
|
+
selectedMarket: Partial<AaveMarketInfo>;
|
|
6
|
+
}) => boolean;
|
|
2
7
|
export declare const isAaveV3: ({ selectedMarket }: {
|
|
3
8
|
selectedMarket: Partial<AaveMarketInfo>;
|
|
4
9
|
}) => boolean;
|
|
@@ -35,3 +40,13 @@ export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, assetsData,
|
|
|
35
40
|
collateralFactor: any;
|
|
36
41
|
};
|
|
37
42
|
export declare const aaveAnyGetAggregatedPositionData: ({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network, ...rest }: AaveHelperCommon) => AaveV3AggregatedPositionData;
|
|
43
|
+
export declare const getApyAfterValuesEstimation: (selectedMarket: AaveMarketInfo, actions: [{
|
|
44
|
+
action: string;
|
|
45
|
+
amount: string;
|
|
46
|
+
asset: string;
|
|
47
|
+
}], web3: Web3, network: NetworkNumber) => Promise<{
|
|
48
|
+
[key: string]: {
|
|
49
|
+
supplyRate: string;
|
|
50
|
+
borrowRate: string;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
11
|
var t = {};
|
|
3
12
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -10,10 +19,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
19
|
return t;
|
|
11
20
|
};
|
|
12
21
|
import Dec from 'decimal.js';
|
|
22
|
+
import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
13
23
|
import { AaveVersions, } from '../../types';
|
|
14
|
-
import { wethToEth } from '../../services/utils';
|
|
15
|
-
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
24
|
+
import { ethToWeth, wethToEth } from '../../services/utils';
|
|
25
|
+
import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos, } from '../../moneymarket';
|
|
16
26
|
import { calculateNetApy } from '../../staking';
|
|
27
|
+
import { borrowOperations } from '../../constants';
|
|
28
|
+
import { AaveLoanInfoV2Contract, AaveV3ViewContract } from '../../contracts';
|
|
29
|
+
export const isAaveV2 = ({ selectedMarket }) => selectedMarket.value === AaveVersions.AaveV2;
|
|
17
30
|
export const isAaveV3 = ({ selectedMarket }) => selectedMarket.value === AaveVersions.AaveV3;
|
|
18
31
|
export const isMorphoAaveV2 = ({ selectedMarket }) => selectedMarket.value === AaveVersions.MorphoAaveV2;
|
|
19
32
|
export const isMorphoAaveV3 = ({ selectedMarket }) => selectedMarket.value === AaveVersions.MorphoAaveV3Eth;
|
|
@@ -100,3 +113,45 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
100
113
|
}
|
|
101
114
|
return payload;
|
|
102
115
|
};
|
|
116
|
+
const getApyAfterValuesEstimationInner = (selectedMarket, actions, viewContract, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
const params = actions.map(({ action, asset, amount }) => {
|
|
118
|
+
const isDebtAsset = borrowOperations.includes(action);
|
|
119
|
+
const amountInWei = assetAmountInWei(amount, asset);
|
|
120
|
+
const assetInfo = getAssetInfo(ethToWeth(asset), network);
|
|
121
|
+
let liquidityAdded;
|
|
122
|
+
let liquidityTaken;
|
|
123
|
+
if (isDebtAsset) {
|
|
124
|
+
liquidityAdded = action === 'payback' ? amountInWei : '0';
|
|
125
|
+
liquidityTaken = action === 'borrow' ? amountInWei : '0';
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
liquidityAdded = action === 'collateral' ? amountInWei : '0';
|
|
129
|
+
liquidityTaken = action === 'withdraw' ? amountInWei : '0';
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
reserveAddress: assetInfo.address,
|
|
133
|
+
liquidityAdded,
|
|
134
|
+
liquidityTaken,
|
|
135
|
+
isDebtAsset,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const data = yield viewContract.methods.getApyAfterValuesEstimation(selectedMarket.providerAddress, params).call();
|
|
139
|
+
const rates = {};
|
|
140
|
+
data.forEach((d) => {
|
|
141
|
+
const asset = wethToEth(getAssetInfoByAddress(d.reserveAddress, network).symbol);
|
|
142
|
+
rates[asset] = {
|
|
143
|
+
supplyRate: aprToApy(new Dec(d.supplyRate.toString()).div(1e25).toString()),
|
|
144
|
+
borrowRate: aprToApy(new Dec(d.variableBorrowRate.toString()).div(1e25).toString()),
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
return rates;
|
|
148
|
+
});
|
|
149
|
+
export const getApyAfterValuesEstimation = (selectedMarket, actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
150
|
+
if (isAaveV2({ selectedMarket })) {
|
|
151
|
+
return getApyAfterValuesEstimationInner(selectedMarket, actions, AaveLoanInfoV2Contract(web3, network), network);
|
|
152
|
+
}
|
|
153
|
+
if (isAaveV3({ selectedMarket })) {
|
|
154
|
+
return getApyAfterValuesEstimationInner(selectedMarket, actions, AaveV3ViewContract(web3, network), network);
|
|
155
|
+
}
|
|
156
|
+
return {};
|
|
157
|
+
});
|
|
@@ -10,6 +10,37 @@ export interface EventOptions {
|
|
|
10
10
|
topics?: string[];
|
|
11
11
|
}
|
|
12
12
|
export declare namespace AaveView {
|
|
13
|
+
type LiquidityChangeParamsStruct = [string, number | string | BN, number | string | BN, boolean] | {
|
|
14
|
+
reserveAddress: string;
|
|
15
|
+
liquidityAdded: number | string | BN;
|
|
16
|
+
liquidityTaken: number | string | BN;
|
|
17
|
+
isDebtAsset: boolean;
|
|
18
|
+
};
|
|
19
|
+
type LiquidityChangeParamsStructOutputArray = [
|
|
20
|
+
string,
|
|
21
|
+
string,
|
|
22
|
+
string,
|
|
23
|
+
boolean
|
|
24
|
+
];
|
|
25
|
+
type LiquidityChangeParamsStructOutputStruct = {
|
|
26
|
+
reserveAddress: string;
|
|
27
|
+
liquidityAdded: string;
|
|
28
|
+
liquidityTaken: string;
|
|
29
|
+
isDebtAsset: boolean;
|
|
30
|
+
};
|
|
31
|
+
type LiquidityChangeParamsStructOutput = LiquidityChangeParamsStructOutputArray & LiquidityChangeParamsStructOutputStruct;
|
|
32
|
+
type EstimatedRatesStruct = [string, number | string | BN, number | string | BN] | {
|
|
33
|
+
reserveAddress: string;
|
|
34
|
+
supplyRate: number | string | BN;
|
|
35
|
+
variableBorrowRate: number | string | BN;
|
|
36
|
+
};
|
|
37
|
+
type EstimatedRatesStructOutputArray = [string, string, string];
|
|
38
|
+
type EstimatedRatesStructOutputStruct = {
|
|
39
|
+
reserveAddress: string;
|
|
40
|
+
supplyRate: string;
|
|
41
|
+
variableBorrowRate: string;
|
|
42
|
+
};
|
|
43
|
+
type EstimatedRatesStructOutput = EstimatedRatesStructOutputArray & EstimatedRatesStructOutputStruct;
|
|
13
44
|
type TokenInfoFullStruct = [
|
|
14
45
|
string,
|
|
15
46
|
string,
|
|
@@ -90,6 +121,46 @@ export declare namespace AaveView {
|
|
|
90
121
|
stableBorrowRateEnabled: boolean;
|
|
91
122
|
};
|
|
92
123
|
type TokenInfoFullStructOutput = TokenInfoFullStructOutputArray & TokenInfoFullStructOutputStruct;
|
|
124
|
+
type LoanDataStruct = [
|
|
125
|
+
string,
|
|
126
|
+
number | string | BN,
|
|
127
|
+
string[],
|
|
128
|
+
boolean[],
|
|
129
|
+
string[],
|
|
130
|
+
number | string | BN[],
|
|
131
|
+
number | string | BN[],
|
|
132
|
+
number | string | BN[]
|
|
133
|
+
] | {
|
|
134
|
+
user: string;
|
|
135
|
+
ratio: number | string | BN;
|
|
136
|
+
collAddr: string[];
|
|
137
|
+
enabledAsColl: boolean[];
|
|
138
|
+
borrowAddr: string[];
|
|
139
|
+
collAmounts: number | string | BN[];
|
|
140
|
+
borrowStableAmounts: number | string | BN[];
|
|
141
|
+
borrowVariableAmounts: number | string | BN[];
|
|
142
|
+
};
|
|
143
|
+
type LoanDataStructOutputArray = [
|
|
144
|
+
string,
|
|
145
|
+
string,
|
|
146
|
+
string[],
|
|
147
|
+
boolean[],
|
|
148
|
+
string[],
|
|
149
|
+
string[],
|
|
150
|
+
string[],
|
|
151
|
+
string[]
|
|
152
|
+
];
|
|
153
|
+
type LoanDataStructOutputStruct = {
|
|
154
|
+
user: string;
|
|
155
|
+
ratio: string;
|
|
156
|
+
collAddr: string[];
|
|
157
|
+
enabledAsColl: boolean[];
|
|
158
|
+
borrowAddr: string[];
|
|
159
|
+
collAmounts: string[];
|
|
160
|
+
borrowStableAmounts: string[];
|
|
161
|
+
borrowVariableAmounts: string[];
|
|
162
|
+
};
|
|
163
|
+
type LoanDataStructOutput = LoanDataStructOutputArray & LoanDataStructOutputStruct;
|
|
93
164
|
type UserTokenStruct = [
|
|
94
165
|
string,
|
|
95
166
|
number | string | BN,
|
|
@@ -122,14 +193,46 @@ export declare namespace AaveView {
|
|
|
122
193
|
enabledAsCollateral: boolean;
|
|
123
194
|
};
|
|
124
195
|
type UserTokenStructOutput = UserTokenStructOutputArray & UserTokenStructOutputStruct;
|
|
196
|
+
type TokenInfoStruct = [string, string, number | string | BN, number | string | BN] | {
|
|
197
|
+
aTokenAddress: string;
|
|
198
|
+
underlyingTokenAddress: string;
|
|
199
|
+
collateralFactor: number | string | BN;
|
|
200
|
+
price: number | string | BN;
|
|
201
|
+
};
|
|
202
|
+
type TokenInfoStructOutputArray = [string, string, string, string];
|
|
203
|
+
type TokenInfoStructOutputStruct = {
|
|
204
|
+
aTokenAddress: string;
|
|
205
|
+
underlyingTokenAddress: string;
|
|
206
|
+
collateralFactor: string;
|
|
207
|
+
price: string;
|
|
208
|
+
};
|
|
209
|
+
type TokenInfoStructOutput = TokenInfoStructOutputArray & TokenInfoStructOutputStruct;
|
|
125
210
|
}
|
|
126
211
|
export interface AaveLoanInfoV2 extends BaseContract {
|
|
127
212
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): AaveLoanInfoV2;
|
|
128
213
|
clone(): AaveLoanInfoV2;
|
|
129
214
|
methods: {
|
|
215
|
+
AAVE_REFERRAL_CODE(): NonPayableTransactionObject<string>;
|
|
216
|
+
AaveIncentivesController(): NonPayableTransactionObject<string>;
|
|
217
|
+
DATA_PROVIDER_ID(): NonPayableTransactionObject<string>;
|
|
218
|
+
StakedToken(): NonPayableTransactionObject<string>;
|
|
219
|
+
enableAsCollateral(_market: string, _tokenAddr: string, _useAsCollateral: boolean): NonPayableTransactionObject<void>;
|
|
220
|
+
getApyAfterValuesEstimation(_market: string, _reserveParams: AaveView.LiquidityChangeParamsStruct[]): NonPayableTransactionObject<AaveView.EstimatedRatesStructOutput[]>;
|
|
221
|
+
getCollFactors(_market: string, _tokens: string[]): NonPayableTransactionObject<string[]>;
|
|
130
222
|
getFullTokensInfo(_market: string, _tokenAddresses: string[]): NonPayableTransactionObject<AaveView.TokenInfoFullStructOutput[]>;
|
|
223
|
+
getIncentivesRewardsBalance(_assets: string[], _user: string): NonPayableTransactionObject<string>;
|
|
224
|
+
getLoanData(_market: string, _user: string): NonPayableTransactionObject<AaveView.LoanDataStructOutput>;
|
|
225
|
+
getLoanDataArr(_market: string, _users: string[]): NonPayableTransactionObject<AaveView.LoanDataStructOutput[]>;
|
|
131
226
|
getPrices(_market: string, _tokens: string[]): NonPayableTransactionObject<string[]>;
|
|
227
|
+
getRatio(_market: string, _user: string): NonPayableTransactionObject<string>;
|
|
228
|
+
getRatios(_market: string, _users: string[]): NonPayableTransactionObject<string[]>;
|
|
229
|
+
getSafetyRatio(_market: string, _user: string): NonPayableTransactionObject<string>;
|
|
230
|
+
getStakingRewardsBalance(_staker: string): NonPayableTransactionObject<string>;
|
|
132
231
|
getTokenBalances(_market: string, _user: string, _tokens: string[]): NonPayableTransactionObject<AaveView.UserTokenStructOutput[]>;
|
|
232
|
+
getTokenInfoFull(_dataProvider: string, _priceOracleAddress: string, _token: string): NonPayableTransactionObject<AaveView.TokenInfoFullStructOutput>;
|
|
233
|
+
getTokensInfo(_market: string, _tokenAddresses: string[]): NonPayableTransactionObject<AaveView.TokenInfoStructOutput[]>;
|
|
234
|
+
getUserUnclaimedRewards(_user: string): NonPayableTransactionObject<string>;
|
|
235
|
+
switchRateMode(_market: string, _tokenAddr: string, _rateMode: number | string | BN): NonPayableTransactionObject<void>;
|
|
133
236
|
};
|
|
134
237
|
events: {
|
|
135
238
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
|
@@ -10,16 +10,23 @@ export interface EventOptions {
|
|
|
10
10
|
topics?: string[];
|
|
11
11
|
}
|
|
12
12
|
export declare namespace AaveV3View {
|
|
13
|
-
type LiquidityChangeParamsStruct = [string, number | string | BN, number | string | BN] | {
|
|
13
|
+
type LiquidityChangeParamsStruct = [string, number | string | BN, number | string | BN, boolean] | {
|
|
14
14
|
reserveAddress: string;
|
|
15
15
|
liquidityAdded: number | string | BN;
|
|
16
16
|
liquidityTaken: number | string | BN;
|
|
17
|
+
isDebtAsset: boolean;
|
|
17
18
|
};
|
|
18
|
-
type LiquidityChangeParamsStructOutputArray = [
|
|
19
|
+
type LiquidityChangeParamsStructOutputArray = [
|
|
20
|
+
string,
|
|
21
|
+
string,
|
|
22
|
+
string,
|
|
23
|
+
boolean
|
|
24
|
+
];
|
|
19
25
|
type LiquidityChangeParamsStructOutputStruct = {
|
|
20
26
|
reserveAddress: string;
|
|
21
27
|
liquidityAdded: string;
|
|
22
28
|
liquidityTaken: string;
|
|
29
|
+
isDebtAsset: boolean;
|
|
23
30
|
};
|
|
24
31
|
type LiquidityChangeParamsStructOutput = LiquidityChangeParamsStructOutputArray & LiquidityChangeParamsStructOutputStruct;
|
|
25
32
|
type EstimatedRatesStruct = [string, number | string | BN, number | string | BN] | {
|