@defisaver/positions-sdk 0.0.182 → 0.0.183

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.
@@ -104,7 +104,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
104
104
  params: [],
105
105
  },
106
106
  {
107
- target: (0, tokens_1.getAssetInfo)('GHO').address,
107
+ target: (0, tokens_1.getAssetInfo)('GHO', network).address,
108
108
  abiItem: (0, utils_1.getAbiItem)(GhoTokenAbi, 'getFacilitatorsList'),
109
109
  params: [],
110
110
  },
@@ -148,7 +148,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
148
148
  const assetsData = yield Promise.all(loanInfo
149
149
  .map((tokenMarket, i) => __awaiter(this, void 0, void 0, function* () {
150
150
  const symbol = market.assets[i];
151
- const nativeAsset = symbol === 'GHO';
151
+ const nativeAsset = symbol === 'GHO' && network === common_1.NetworkNumber.Eth;
152
152
  // eslint-disable-next-line guard-for-in
153
153
  for (const eModeIndex in eModeCategoriesData) {
154
154
  if ((0, utils_1.isEnabledOnBitmap)(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
@@ -423,7 +423,7 @@ const getAaveV3AccountData = (web3, network, address, extractedState) => __await
423
423
  }
424
424
  if (!usedAssets[asset])
425
425
  usedAssets[asset] = {};
426
- const nativeAsset = asset === 'GHO';
426
+ const nativeAsset = asset === 'GHO' && network === common_1.NetworkNumber.Eth;
427
427
  let discountRateOnBorrow = '0';
428
428
  const borrowed = new decimal_js_1.default(borrowedStable).add(borrowedVariable).toString();
429
429
  if (nativeAsset && new decimal_js_1.default(borrowed).gt(0) && new decimal_js_1.default(stkAaveBalance).gt(0)) {
@@ -2280,6 +2280,9 @@ export namespace GHO {
2280
2280
  "1": {
2281
2281
  address: string;
2282
2282
  };
2283
+ "42161": {
2284
+ address: string;
2285
+ };
2283
2286
  };
2284
2287
  export { networks_15 as networks };
2285
2288
  }
@@ -312,6 +312,9 @@ module.exports = {
312
312
  "networks": {
313
313
  "1": {
314
314
  "address": "0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f"
315
+ },
316
+ "42161": {
317
+ "address": "0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33"
315
318
  }
316
319
  }
317
320
  },
@@ -115,7 +115,6 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
115
115
  usedAssets,
116
116
  assetsData,
117
117
  isMorpho: (0, exports.isMorphoAave)({ selectedMarket }),
118
- network,
119
118
  });
120
119
  payload.netApy = netApy;
121
120
  payload.incentiveUsd = incentiveUsd;
@@ -1,5 +1,5 @@
1
1
  import Web3 from 'web3';
2
- import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
2
+ import { MMAssetsData, MMUsedAssets } from '../types/common';
3
3
  export declare const getStETHApy: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<string>;
4
4
  export declare const getCbETHApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
5
5
  export declare const getREthApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
@@ -8,11 +8,10 @@ export declare const getSsrApy: () => Promise<string>;
8
8
  export declare const STAKING_ASSETS: string[];
9
9
  export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => "0" | Promise<any> | undefined;
10
10
  export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
11
- export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho, network, }: {
11
+ export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho }: {
12
12
  usedAssets: MMUsedAssets;
13
13
  assetsData: MMAssetsData;
14
14
  isMorpho?: boolean | undefined;
15
- network?: NetworkNumber | undefined;
16
15
  }) => {
17
16
  netApy: string;
18
17
  totalInterestUsd: string;
@@ -170,7 +170,7 @@ const calculateInterestEarned = (principal, interest, type, apy = false) => {
170
170
  return (+principal * (Math.pow(((1 + (+interest / 100) / constants_1.BLOCKS_IN_A_YEAR)), (constants_1.BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
171
171
  };
172
172
  exports.calculateInterestEarned = calculateInterestEarned;
173
- const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, network = 1, }) => {
173
+ const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false }) => {
174
174
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
175
175
  const acc = Object.assign({}, _acc);
176
176
  const assetData = assetsData[usedAsset.symbol];
@@ -193,7 +193,7 @@ const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, network = 1
193
193
  acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
194
194
  const rate = isMorpho
195
195
  ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
196
- : (usedAsset.symbol === 'GHO' && network === common_1.NetworkNumber.Eth)
196
+ : (usedAsset.symbol === 'GHO' && assetsData.nativeAsset)
197
197
  ? usedAsset.discountedBorrowRate
198
198
  : ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
199
199
  const borrowInterest = (0, exports.calculateInterestEarned)(amount, rate, 'year', true);
@@ -16,7 +16,7 @@ import { getStakingApy, STAKING_ASSETS } from '../staking';
16
16
  import { multicall } from '../multicall';
17
17
  import { getAssetsBalances } from '../assets';
18
18
  import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
19
- import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode, } from '../helpers/aaveHelpers';
19
+ import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
20
20
  import { AAVE_V3 } from '../markets/aave';
21
21
  export const test = (web3, network) => {
22
22
  const contract = AaveV3ViewContract(web3, 1);
@@ -95,7 +95,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
95
95
  params: [],
96
96
  },
97
97
  {
98
- target: getAssetInfo('GHO').address,
98
+ target: getAssetInfo('GHO', network).address,
99
99
  abiItem: getAbiItem(GhoTokenAbi, 'getFacilitatorsList'),
100
100
  params: [],
101
101
  },
@@ -139,7 +139,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
139
139
  const assetsData = yield Promise.all(loanInfo
140
140
  .map((tokenMarket, i) => __awaiter(this, void 0, void 0, function* () {
141
141
  const symbol = market.assets[i];
142
- const nativeAsset = symbol === 'GHO';
142
+ const nativeAsset = symbol === 'GHO' && network === NetworkNumber.Eth;
143
143
  // eslint-disable-next-line guard-for-in
144
144
  for (const eModeIndex in eModeCategoriesData) {
145
145
  if (isEnabledOnBitmap(Number(eModeCategoriesData[eModeIndex].collateralBitmap), Number(tokenMarket.assetId)))
@@ -412,7 +412,7 @@ export const getAaveV3AccountData = (web3, network, address, extractedState) =>
412
412
  }
413
413
  if (!usedAssets[asset])
414
414
  usedAssets[asset] = {};
415
- const nativeAsset = asset === 'GHO';
415
+ const nativeAsset = asset === 'GHO' && network === NetworkNumber.Eth;
416
416
  let discountRateOnBorrow = '0';
417
417
  const borrowed = new Dec(borrowedStable).add(borrowedVariable).toString();
418
418
  if (nativeAsset && new Dec(borrowed).gt(0) && new Dec(stkAaveBalance).gt(0)) {
@@ -2280,6 +2280,9 @@ export namespace GHO {
2280
2280
  "1": {
2281
2281
  address: string;
2282
2282
  };
2283
+ "42161": {
2284
+ address: string;
2285
+ };
2283
2286
  };
2284
2287
  export { networks_15 as networks };
2285
2288
  }
@@ -311,6 +311,9 @@ module.exports = {
311
311
  "networks": {
312
312
  "1": {
313
313
  "address": "0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f"
314
+ },
315
+ "42161": {
316
+ "address": "0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33"
314
317
  }
315
318
  }
316
319
  },
@@ -98,7 +98,6 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
98
98
  usedAssets,
99
99
  assetsData,
100
100
  isMorpho: isMorphoAave({ selectedMarket }),
101
- network,
102
101
  });
103
102
  payload.netApy = netApy;
104
103
  payload.incentiveUsd = incentiveUsd;
@@ -1,5 +1,5 @@
1
1
  import Web3 from 'web3';
2
- import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
2
+ import { MMAssetsData, MMUsedAssets } from '../types/common';
3
3
  export declare const getStETHApy: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<string>;
4
4
  export declare const getCbETHApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
5
5
  export declare const getREthApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
@@ -8,11 +8,10 @@ export declare const getSsrApy: () => Promise<string>;
8
8
  export declare const STAKING_ASSETS: string[];
9
9
  export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => "0" | Promise<any> | undefined;
10
10
  export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
11
- export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho, network, }: {
11
+ export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho }: {
12
12
  usedAssets: MMUsedAssets;
13
13
  assetsData: MMAssetsData;
14
14
  isMorpho?: boolean | undefined;
15
- network?: NetworkNumber | undefined;
16
15
  }) => {
17
16
  netApy: string;
18
17
  totalInterestUsd: string;
@@ -157,7 +157,7 @@ export const calculateInterestEarned = (principal, interest, type, apy = false)
157
157
  }
158
158
  return (+principal * (Math.pow(((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)), (BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
159
159
  };
160
- export const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, network = 1, }) => {
160
+ export const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false }) => {
161
161
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
162
162
  const acc = Object.assign({}, _acc);
163
163
  const assetData = assetsData[usedAsset.symbol];
@@ -180,7 +180,7 @@ export const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, netw
180
180
  acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
181
181
  const rate = isMorpho
182
182
  ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
183
- : (usedAsset.symbol === 'GHO' && network === NetworkNumber.Eth)
183
+ : (usedAsset.symbol === 'GHO' && assetsData.nativeAsset)
184
184
  ? usedAsset.discountedBorrowRate
185
185
  : ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
186
186
  const borrowInterest = calculateInterestEarned(amount, rate, 'year', true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.182",
3
+ "version": "0.0.183",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -34,11 +34,7 @@ import { multicall } from '../multicall';
34
34
  import { IUiIncentiveDataProviderV3 } from '../types/contracts/generated/AaveUiIncentiveDataProviderV3';
35
35
  import { getAssetsBalances } from '../assets';
36
36
  import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
37
- import {
38
- aaveAnyGetAggregatedPositionData,
39
- aaveV3IsInIsolationMode,
40
- aaveV3IsInSiloedMode,
41
- } from '../helpers/aaveHelpers';
37
+ import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
42
38
  import { AAVE_V3 } from '../markets/aave';
43
39
 
44
40
  export const test = (web3: Web3, network: NetworkNumber) => {
@@ -137,7 +133,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
137
133
  params: [],
138
134
  },
139
135
  {
140
- target: getAssetInfo('GHO').address,
136
+ target: getAssetInfo('GHO', network).address,
141
137
  abiItem: getAbiItem(GhoTokenAbi, 'getFacilitatorsList'),
142
138
  params: [],
143
139
  },
@@ -191,7 +187,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
191
187
  const assetsData: AaveV3AssetData[] = await Promise.all(loanInfo
192
188
  .map(async (tokenMarket, i) => {
193
189
  const symbol = market.assets[i];
194
- const nativeAsset = symbol === 'GHO';
190
+ const nativeAsset = symbol === 'GHO' && network === NetworkNumber.Eth;
195
191
 
196
192
  // eslint-disable-next-line guard-for-in
197
193
  for (const eModeIndex in eModeCategoriesData) {
@@ -547,7 +543,7 @@ export const getAaveV3AccountData = async (web3: Web3, network: NetworkNumber, a
547
543
  interestMode = 'both';
548
544
  }
549
545
  if (!usedAssets[asset]) usedAssets[asset] = {} as AaveV3UsedAsset;
550
- const nativeAsset = asset === 'GHO';
546
+ const nativeAsset = asset === 'GHO' && network === NetworkNumber.Eth;
551
547
 
552
548
  let discountRateOnBorrow = '0';
553
549
  const borrowed = new Dec(borrowedStable).add(borrowedVariable).toString();
@@ -312,6 +312,9 @@ module.exports = {
312
312
  "networks": {
313
313
  "1": {
314
314
  "address": "0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f"
315
+ },
316
+ "42161": {
317
+ "address": "0x7dfF72693f6A4149b17e7C6314655f6A9F7c8B33"
315
318
  }
316
319
  }
317
320
  },
@@ -129,7 +129,6 @@ export const aaveAnyGetAggregatedPositionData = ({
129
129
  usedAssets,
130
130
  assetsData,
131
131
  isMorpho: isMorphoAave({ selectedMarket }),
132
- network,
133
132
  });
134
133
  payload.netApy = netApy;
135
134
  payload.incentiveUsd = incentiveUsd;
@@ -151,9 +151,7 @@ export const calculateInterestEarned = (principal: string, interest: string, typ
151
151
  return (+principal * (((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)) ** (BLOCKS_IN_A_YEAR * interval))) - +principal; // eslint-disable-line
152
152
  };
153
153
 
154
- export const calculateNetApy = ({
155
- usedAssets, assetsData, isMorpho = false, network = 1,
156
- }: { usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean, network?: NetworkNumber }) => {
154
+ export const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false }: { usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean }) => {
157
155
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
158
156
  const acc = { ..._acc };
159
157
  const assetData = assetsData[usedAsset.symbol];
@@ -178,7 +176,7 @@ export const calculateNetApy = ({
178
176
  acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
179
177
  const rate = isMorpho
180
178
  ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
181
- : (usedAsset.symbol === 'GHO' && network === NetworkNumber.Eth)
179
+ : (usedAsset.symbol === 'GHO' && assetsData.nativeAsset)
182
180
  ? usedAsset.discountedBorrowRate
183
181
  : (usedAsset?.interestMode === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
184
182
  const borrowInterest = calculateInterestEarned(amount, rate as string, 'year', true);