@defisaver/positions-sdk 0.0.113 → 0.0.114

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.
@@ -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,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __rest = (this && this.__rest) || function (s, e) {
3
12
  var t = {};
4
13
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -14,12 +23,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
24
  };
16
25
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.aaveAnyGetAggregatedPositionData = exports.aaveAnyGetEmodeMutableProps = exports.aaveAnyGetSuppliableAsCollAssets = exports.aaveAnyGetSuppliableAssets = exports.aaveAnyGetCollSuppliedAssets = exports.aaveV3IsInSiloedMode = exports.aaveV3IsInIsolationMode = exports.isMorphoAave = exports.isMorphoAaveV3 = exports.isMorphoAaveV2 = exports.isAaveV3 = void 0;
26
+ exports.getApyAfterValuesEstimation = exports.aaveAnyGetAggregatedPositionData = exports.aaveAnyGetEmodeMutableProps = exports.aaveAnyGetSuppliableAsCollAssets = exports.aaveAnyGetSuppliableAssets = exports.aaveAnyGetCollSuppliedAssets = exports.aaveV3IsInSiloedMode = exports.aaveV3IsInIsolationMode = exports.isMorphoAave = exports.isMorphoAaveV3 = exports.isMorphoAaveV2 = exports.isAaveV3 = exports.isAaveV2 = void 0;
18
27
  const decimal_js_1 = __importDefault(require("decimal.js"));
28
+ const tokens_1 = require("@defisaver/tokens");
19
29
  const types_1 = require("../../types");
20
30
  const utils_1 = require("../../services/utils");
21
31
  const moneymarket_1 = require("../../moneymarket");
22
32
  const staking_1 = require("../../staking");
33
+ const constants_1 = require("../../constants");
34
+ const contracts_1 = require("../../contracts");
35
+ const isAaveV2 = ({ selectedMarket }) => selectedMarket.value === types_1.AaveVersions.AaveV2;
36
+ exports.isAaveV2 = isAaveV2;
23
37
  const isAaveV3 = ({ selectedMarket }) => selectedMarket.value === types_1.AaveVersions.AaveV3;
24
38
  exports.isAaveV3 = isAaveV3;
25
39
  const isMorphoAaveV2 = ({ selectedMarket }) => selectedMarket.value === types_1.AaveVersions.MorphoAaveV2;
@@ -117,3 +131,46 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
117
131
  return payload;
118
132
  };
119
133
  exports.aaveAnyGetAggregatedPositionData = aaveAnyGetAggregatedPositionData;
134
+ const getApyAfterValuesEstimationInner = (selectedMarket, actions, viewContract, network) => __awaiter(void 0, void 0, void 0, function* () {
135
+ const params = actions.map(({ action, asset, amount }) => {
136
+ const isDebtAsset = constants_1.borrowOperations.includes(action);
137
+ const amountInWei = (0, tokens_1.assetAmountInWei)(amount, asset);
138
+ const assetInfo = (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(asset), network);
139
+ let liquidityAdded;
140
+ let liquidityTaken;
141
+ if (isDebtAsset) {
142
+ liquidityAdded = action === 'payback' ? amountInWei : '0';
143
+ liquidityTaken = action === 'borrow' ? amountInWei : '0';
144
+ }
145
+ else {
146
+ liquidityAdded = action === 'collateral' ? amountInWei : '0';
147
+ liquidityTaken = action === 'withdraw' ? amountInWei : '0';
148
+ }
149
+ return {
150
+ reserveAddress: assetInfo.address,
151
+ liquidityAdded,
152
+ liquidityTaken,
153
+ isDebtAsset,
154
+ };
155
+ });
156
+ const data = yield viewContract.methods.getApyAfterValuesEstimation(selectedMarket.providerAddress, params).call();
157
+ const rates = {};
158
+ data.forEach((d) => {
159
+ const asset = (0, utils_1.wethToEth)((0, tokens_1.getAssetInfoByAddress)(d.reserveAddress, network).symbol);
160
+ rates[asset] = {
161
+ supplyRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(d.supplyRate.toString()).div(1e25).toString()),
162
+ borrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(d.variableBorrowRate.toString()).div(1e25).toString()),
163
+ };
164
+ });
165
+ return rates;
166
+ });
167
+ const getApyAfterValuesEstimation = (selectedMarket, actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
168
+ if ((0, exports.isAaveV2)({ selectedMarket })) {
169
+ return getApyAfterValuesEstimationInner(selectedMarket, actions, (0, contracts_1.AaveLoanInfoV2Contract)(web3, network), network);
170
+ }
171
+ if ((0, exports.isAaveV3)({ selectedMarket })) {
172
+ return getApyAfterValuesEstimationInner(selectedMarket, actions, (0, contracts_1.AaveV3ViewContract)(web3, network), network);
173
+ }
174
+ return {};
175
+ });
176
+ exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
@@ -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;
@@ -67,6 +67,72 @@ export namespace AaveV3View {
67
67
  address: string;
68
68
  createdBlock: number;
69
69
  oldVersions: {
70
+ "20218382": {
71
+ abi: ({
72
+ inputs: ({
73
+ internalType: string;
74
+ name: string;
75
+ type: string;
76
+ components?: undefined;
77
+ } | {
78
+ components: {
79
+ internalType: string;
80
+ name: string;
81
+ type: string;
82
+ }[];
83
+ internalType: string;
84
+ name: string;
85
+ type: string;
86
+ })[];
87
+ name: string;
88
+ outputs: {
89
+ components: {
90
+ internalType: string;
91
+ name: string;
92
+ type: string;
93
+ }[];
94
+ internalType: string;
95
+ name: string;
96
+ type: string;
97
+ }[];
98
+ stateMutability: string;
99
+ type: string;
100
+ } | {
101
+ inputs: {
102
+ internalType: string;
103
+ name: string;
104
+ type: string;
105
+ }[];
106
+ name: string;
107
+ outputs: {
108
+ internalType: string;
109
+ name: string;
110
+ type: string;
111
+ }[];
112
+ stateMutability: string;
113
+ type: string;
114
+ } | {
115
+ inputs: {
116
+ components: {
117
+ internalType: string;
118
+ name: string;
119
+ type: string;
120
+ }[];
121
+ internalType: string;
122
+ name: string;
123
+ type: string;
124
+ }[];
125
+ name: string;
126
+ outputs: {
127
+ internalType: string;
128
+ name: string;
129
+ type: string;
130
+ }[];
131
+ stateMutability: string;
132
+ type: string;
133
+ })[];
134
+ address: string;
135
+ };
70
136
  "17870436": {
71
137
  abi: ({
72
138
  inputs: {
@@ -175,6 +241,72 @@ export namespace AaveV3View {
175
241
  address: string;
176
242
  createdBlock: number;
177
243
  oldVersions: {
244
+ "122158666": {
245
+ abi: ({
246
+ inputs: ({
247
+ internalType: string;
248
+ name: string;
249
+ type: string;
250
+ components?: undefined;
251
+ } | {
252
+ components: {
253
+ internalType: string;
254
+ name: string;
255
+ type: string;
256
+ }[];
257
+ internalType: string;
258
+ name: string;
259
+ type: string;
260
+ })[];
261
+ name: string;
262
+ outputs: {
263
+ components: {
264
+ internalType: string;
265
+ name: string;
266
+ type: string;
267
+ }[];
268
+ internalType: string;
269
+ name: string;
270
+ type: string;
271
+ }[];
272
+ stateMutability: string;
273
+ type: string;
274
+ } | {
275
+ inputs: {
276
+ internalType: string;
277
+ name: string;
278
+ type: string;
279
+ }[];
280
+ name: string;
281
+ outputs: {
282
+ internalType: string;
283
+ name: string;
284
+ type: string;
285
+ }[];
286
+ stateMutability: string;
287
+ type: string;
288
+ } | {
289
+ inputs: {
290
+ components: {
291
+ internalType: string;
292
+ name: string;
293
+ type: string;
294
+ }[];
295
+ internalType: string;
296
+ name: string;
297
+ type: string;
298
+ }[];
299
+ name: string;
300
+ outputs: {
301
+ internalType: string;
302
+ name: string;
303
+ type: string;
304
+ }[];
305
+ stateMutability: string;
306
+ type: string;
307
+ })[];
308
+ address: string;
309
+ };
178
310
  "107950604": {
179
311
  address: string;
180
312
  abi: ({
@@ -421,6 +553,72 @@ export namespace AaveV3View {
421
553
  address: string;
422
554
  createdBlock: number;
423
555
  oldVersions: {
556
+ "227949246": {
557
+ abi: ({
558
+ inputs: ({
559
+ internalType: string;
560
+ name: string;
561
+ type: string;
562
+ components?: undefined;
563
+ } | {
564
+ components: {
565
+ internalType: string;
566
+ name: string;
567
+ type: string;
568
+ }[];
569
+ internalType: string;
570
+ name: string;
571
+ type: string;
572
+ })[];
573
+ name: string;
574
+ outputs: {
575
+ components: {
576
+ internalType: string;
577
+ name: string;
578
+ type: string;
579
+ }[];
580
+ internalType: string;
581
+ name: string;
582
+ type: string;
583
+ }[];
584
+ stateMutability: string;
585
+ type: string;
586
+ } | {
587
+ inputs: {
588
+ internalType: string;
589
+ name: string;
590
+ type: string;
591
+ }[];
592
+ name: string;
593
+ outputs: {
594
+ internalType: string;
595
+ name: string;
596
+ type: string;
597
+ }[];
598
+ stateMutability: string;
599
+ type: string;
600
+ } | {
601
+ inputs: {
602
+ components: {
603
+ internalType: string;
604
+ name: string;
605
+ type: string;
606
+ }[];
607
+ internalType: string;
608
+ name: string;
609
+ type: string;
610
+ }[];
611
+ name: string;
612
+ outputs: {
613
+ internalType: string;
614
+ name: string;
615
+ type: string;
616
+ }[];
617
+ stateMutability: string;
618
+ type: string;
619
+ })[];
620
+ address: string;
621
+ };
424
622
  "119382184": {
425
623
  address: string;
426
624
  abi: ({
@@ -644,6 +842,72 @@ export namespace AaveV3View {
644
842
  address: string;
645
843
  createdBlock: number;
646
844
  oldVersions: {
845
+ "16564098": {
846
+ abi: ({
847
+ inputs: ({
848
+ internalType: string;
849
+ name: string;
850
+ type: string;
851
+ components?: undefined;
852
+ } | {
853
+ components: {
854
+ internalType: string;
855
+ name: string;
856
+ type: string;
857
+ }[];
858
+ internalType: string;
859
+ name: string;
860
+ type: string;
861
+ })[];
862
+ name: string;
863
+ outputs: {
864
+ components: {
865
+ internalType: string;
866
+ name: string;
867
+ type: string;
868
+ }[];
869
+ internalType: string;
870
+ name: string;
871
+ type: string;
872
+ }[];
873
+ stateMutability: string;
874
+ type: string;
875
+ } | {
876
+ inputs: {
877
+ internalType: string;
878
+ name: string;
879
+ type: string;
880
+ }[];
881
+ name: string;
882
+ outputs: {
883
+ internalType: string;
884
+ name: string;
885
+ type: string;
886
+ }[];
887
+ stateMutability: string;
888
+ type: string;
889
+ } | {
890
+ inputs: {
891
+ components: {
892
+ internalType: string;
893
+ name: string;
894
+ type: string;
895
+ }[];
896
+ internalType: string;
897
+ name: string;
898
+ type: string;
899
+ }[];
900
+ name: string;
901
+ outputs: {
902
+ internalType: string;
903
+ name: string;
904
+ type: string;
905
+ }[];
906
+ stateMutability: string;
907
+ type: string;
908
+ })[];
909
+ address: string;
910
+ };
647
911
  "3907180": {
648
912
  address: string;
649
913
  abi: ({
@@ -2246,11 +2510,21 @@ export namespace wstETH {
2246
2510
  }
2247
2511
  export namespace AaveLoanInfoV2 {
2248
2512
  let abi_23: ({
2249
- inputs: {
2513
+ inputs: ({
2250
2514
  internalType: string;
2251
2515
  name: string;
2252
2516
  type: string;
2253
- }[];
2517
+ components?: undefined;
2518
+ } | {
2519
+ components: {
2520
+ internalType: string;
2521
+ name: string;
2522
+ type: string;
2523
+ }[];
2524
+ internalType: string;
2525
+ name: string;
2526
+ type: string;
2527
+ })[];
2254
2528
  name: string;
2255
2529
  outputs: {
2256
2530
  components: {