@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.
- package/cjs/aaveV3/index.js +3 -3
- package/cjs/config/contracts.d.ts +3 -0
- package/cjs/config/contracts.js +3 -0
- package/cjs/helpers/aaveHelpers/index.js +0 -1
- package/cjs/staking/staking.d.ts +2 -3
- package/cjs/staking/staking.js +2 -2
- package/esm/aaveV3/index.js +4 -4
- package/esm/config/contracts.d.ts +3 -0
- package/esm/config/contracts.js +3 -0
- package/esm/helpers/aaveHelpers/index.js +0 -1
- package/esm/staking/staking.d.ts +2 -3
- package/esm/staking/staking.js +2 -2
- package/package.json +1 -1
- package/src/aaveV3/index.ts +4 -8
- package/src/config/contracts.js +3 -0
- package/src/helpers/aaveHelpers/index.ts +0 -1
- package/src/staking/staking.ts +2 -4
package/cjs/aaveV3/index.js
CHANGED
|
@@ -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)) {
|
package/cjs/config/contracts.js
CHANGED
package/cjs/staking/staking.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { MMAssetsData, MMUsedAssets
|
|
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
|
|
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;
|
package/cjs/staking/staking.js
CHANGED
|
@@ -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
|
|
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' &&
|
|
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);
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -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
|
|
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)) {
|
package/esm/config/contracts.js
CHANGED
package/esm/staking/staking.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { MMAssetsData, MMUsedAssets
|
|
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
|
|
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;
|
package/esm/staking/staking.js
CHANGED
|
@@ -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
|
|
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' &&
|
|
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
package/src/aaveV3/index.ts
CHANGED
|
@@ -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();
|
package/src/config/contracts.js
CHANGED
package/src/staking/staking.ts
CHANGED
|
@@ -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' &&
|
|
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);
|