@defisaver/positions-sdk 0.0.2 → 0.0.4
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 +1 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +1 -1
- package/cjs/helpers/aaveHelpers/index.js +3 -14
- package/cjs/helpers/sparkHelpers/index.d.ts +1 -1
- package/cjs/helpers/sparkHelpers/index.js +3 -9
- package/cjs/staking/staking.d.ts +1 -0
- package/cjs/staking/staking.js +13 -1
- package/esm/aaveV3/index.js +1 -1
- package/esm/helpers/aaveHelpers/index.d.ts +1 -1
- package/esm/helpers/aaveHelpers/index.js +3 -14
- package/esm/helpers/sparkHelpers/index.d.ts +1 -1
- package/esm/helpers/sparkHelpers/index.js +3 -9
- package/esm/staking/staking.d.ts +1 -0
- package/esm/staking/staking.js +12 -1
- package/package.json +3 -3
- package/src/aaveV3/index.ts +1 -1
- package/src/helpers/aaveHelpers/index.ts +3 -20
- package/src/helpers/sparkHelpers/index.ts +2 -14
- package/src/staking/staking.ts +12 -1
- package/yarn-error.log +64 -0
package/cjs/aaveV3/index.js
CHANGED
|
@@ -168,7 +168,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
168
168
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
169
169
|
/* eslint-disable no-param-reassign */
|
|
170
170
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
171
|
-
if (['wstETH', 'cbETH', 'rETH'].includes(_market.symbol)) {
|
|
171
|
+
if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
|
|
172
172
|
if (!(0, utils_1.isLayer2Network)(network) && _market.symbol === 'cbETH')
|
|
173
173
|
return;
|
|
174
174
|
_market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(_market.symbol, defaultWeb3);
|
|
@@ -30,7 +30,7 @@ export declare const aaveAnyGetSuppliableAsCollAssets: ({ usedAssets, eModeCateg
|
|
|
30
30
|
symbol: string;
|
|
31
31
|
canBeCollateral: boolean;
|
|
32
32
|
}[];
|
|
33
|
-
export declare const aaveAnyGetEmodeMutableProps: ({
|
|
33
|
+
export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, assetsData, }: AaveHelperCommon, _asset: string) => {
|
|
34
34
|
liquidationRatio: any;
|
|
35
35
|
collateralFactor: any;
|
|
36
36
|
};
|
|
@@ -57,24 +57,13 @@ const aaveAnyGetSuppliableAsCollAssets = (_a) => {
|
|
|
57
57
|
return (0, exports.aaveAnyGetSuppliableAssets)(Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
58
58
|
};
|
|
59
59
|
exports.aaveAnyGetSuppliableAsCollAssets = aaveAnyGetSuppliableAsCollAssets;
|
|
60
|
-
const aaveAnyGetEmodeMutableProps = (
|
|
61
|
-
var
|
|
62
|
-
var { usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategories", "assetsData", "selectedMarket", "network"]);
|
|
63
|
-
const data = Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest);
|
|
60
|
+
const aaveAnyGetEmodeMutableProps = ({ eModeCategory, assetsData, }, _asset) => {
|
|
61
|
+
var _a;
|
|
64
62
|
const asset = (0, utils_1.wethToEth)(_asset);
|
|
65
|
-
const canSupplyAsColl = (0, exports.aaveAnyGetSuppliableAsCollAssets)(data).some(({ symbol }) => symbol === asset);
|
|
66
|
-
// TODO remove dirty fix for Morpho V2
|
|
67
|
-
if ((0, exports.isMorphoAaveV2)({ selectedMarket }) && !canSupplyAsColl) {
|
|
68
|
-
const { liquidationRatio, collateralFactor } = assetsData[asset];
|
|
69
|
-
return ({ liquidationRatio, collateralFactor });
|
|
70
|
-
}
|
|
71
|
-
if (!canSupplyAsColl) {
|
|
72
|
-
return ({ liquidationRatio: '0', collateralFactor: '0' });
|
|
73
|
-
}
|
|
74
63
|
const assetData = assetsData[asset];
|
|
75
64
|
if (eModeCategory === 0
|
|
76
65
|
|| assetData.eModeCategory !== eModeCategory
|
|
77
|
-
|| new decimal_js_1.default(((
|
|
66
|
+
|| new decimal_js_1.default(((_a = assetData === null || assetData === void 0 ? void 0 : assetData.eModeCategoryData) === null || _a === void 0 ? void 0 : _a.collateralFactor) || 0).eq(0)) {
|
|
78
67
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
79
68
|
return ({ liquidationRatio, collateralFactor });
|
|
80
69
|
}
|
|
@@ -14,7 +14,7 @@ export declare const sparkGetSuppliableAsCollAssets: ({ usedAssets, eModeCategor
|
|
|
14
14
|
symbol: string;
|
|
15
15
|
canBeCollateral: boolean;
|
|
16
16
|
}[];
|
|
17
|
-
export declare const sparkGetEmodeMutableProps: ({
|
|
17
|
+
export declare const sparkGetEmodeMutableProps: ({ eModeCategory, assetsData, }: SparkHelperCommon, _asset: string) => {
|
|
18
18
|
liquidationRatio: string;
|
|
19
19
|
collateralFactor: string;
|
|
20
20
|
};
|
|
@@ -40,19 +40,13 @@ const sparkGetSuppliableAsCollAssets = (_a) => {
|
|
|
40
40
|
return (0, exports.sparkGetSuppliableAssets)(Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
41
41
|
};
|
|
42
42
|
exports.sparkGetSuppliableAsCollAssets = sparkGetSuppliableAsCollAssets;
|
|
43
|
-
const sparkGetEmodeMutableProps = (
|
|
44
|
-
var
|
|
45
|
-
var { usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategories", "assetsData", "selectedMarket", "network"]);
|
|
46
|
-
const data = Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest);
|
|
43
|
+
const sparkGetEmodeMutableProps = ({ eModeCategory, assetsData, }, _asset) => {
|
|
44
|
+
var _a;
|
|
47
45
|
const asset = (0, utils_1.wethToEth)(_asset);
|
|
48
|
-
const canSupplyAsColl = (0, exports.sparkGetSuppliableAsCollAssets)(data).some(({ symbol }) => symbol === asset);
|
|
49
|
-
if (!canSupplyAsColl) {
|
|
50
|
-
return ({ liquidationRatio: '0', collateralFactor: '0' });
|
|
51
|
-
}
|
|
52
46
|
const assetData = assetsData[asset];
|
|
53
47
|
if (eModeCategory === 0
|
|
54
48
|
|| assetData.eModeCategory !== eModeCategory
|
|
55
|
-
|| new decimal_js_1.default(((
|
|
49
|
+
|| new decimal_js_1.default(((_a = assetData === null || assetData === void 0 ? void 0 : assetData.eModeCategoryData) === null || _a === void 0 ? void 0 : _a.collateralFactor) || 0).eq(0)) {
|
|
56
50
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
57
51
|
return ({ liquidationRatio, collateralFactor });
|
|
58
52
|
}
|
package/cjs/staking/staking.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
|
|
|
3
3
|
export declare const getStETHApr: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<any>;
|
|
4
4
|
export declare const getCbETHApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
5
5
|
export declare const getREthApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
|
+
export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
7
|
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> | undefined;
|
|
7
8
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
8
9
|
export declare const calculateNetApy: (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean) => {
|
package/cjs/staking/staking.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.getREthApr = exports.getCbETHApr = exports.getStETHApr = void 0;
|
|
15
|
+
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.getDsrApy = exports.getREthApr = exports.getCbETHApr = exports.getStETHApr = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const contracts_1 = require("../contracts");
|
|
18
18
|
const common_1 = require("../types/common");
|
|
@@ -76,6 +76,16 @@ const getREthApr = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, v
|
|
|
76
76
|
return apr;
|
|
77
77
|
});
|
|
78
78
|
exports.getREthApr = getREthApr;
|
|
79
|
+
const getDsrApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const potContract = (0, contracts_1.PotContract)(web3, common_1.NetworkNumber.Eth);
|
|
81
|
+
return new decimal_js_1.default(yield potContract.methods.dsr().call())
|
|
82
|
+
.div(new decimal_js_1.default(1e27))
|
|
83
|
+
.pow(constants_1.SECONDS_PER_YEAR)
|
|
84
|
+
.sub(1)
|
|
85
|
+
.mul(100)
|
|
86
|
+
.toString();
|
|
87
|
+
});
|
|
88
|
+
exports.getDsrApy = getDsrApy;
|
|
79
89
|
const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
80
90
|
if (asset === 'stETH' || asset === 'wstETH')
|
|
81
91
|
return (0, exports.getStETHApr)(web3, fromBlock, blockNumber);
|
|
@@ -83,6 +93,8 @@ const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefine
|
|
|
83
93
|
return (0, exports.getCbETHApr)(web3, blockNumber);
|
|
84
94
|
if (asset === 'rETH')
|
|
85
95
|
return (0, exports.getREthApr)(web3, blockNumber);
|
|
96
|
+
if (asset === 'sDAI')
|
|
97
|
+
return (0, exports.getDsrApy)(web3);
|
|
86
98
|
};
|
|
87
99
|
exports.getStakingApy = getStakingApy;
|
|
88
100
|
const calculateInterestEarned = (principal, interest, type, apy = false) => {
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -159,7 +159,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
159
159
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
160
160
|
/* eslint-disable no-param-reassign */
|
|
161
161
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
162
|
-
if (['wstETH', 'cbETH', 'rETH'].includes(_market.symbol)) {
|
|
162
|
+
if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
|
|
163
163
|
if (!isLayer2Network(network) && _market.symbol === 'cbETH')
|
|
164
164
|
return;
|
|
165
165
|
_market.incentiveSupplyApy = yield getStakingApy(_market.symbol, defaultWeb3);
|
|
@@ -30,7 +30,7 @@ export declare const aaveAnyGetSuppliableAsCollAssets: ({ usedAssets, eModeCateg
|
|
|
30
30
|
symbol: string;
|
|
31
31
|
canBeCollateral: boolean;
|
|
32
32
|
}[];
|
|
33
|
-
export declare const aaveAnyGetEmodeMutableProps: ({
|
|
33
|
+
export declare const aaveAnyGetEmodeMutableProps: ({ eModeCategory, assetsData, }: AaveHelperCommon, _asset: string) => {
|
|
34
34
|
liquidationRatio: any;
|
|
35
35
|
collateralFactor: any;
|
|
36
36
|
};
|
|
@@ -42,24 +42,13 @@ export const aaveAnyGetSuppliableAsCollAssets = (_a) => {
|
|
|
42
42
|
var { usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategories", "assetsData", "selectedMarket", "network"]);
|
|
43
43
|
return aaveAnyGetSuppliableAssets(Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
44
44
|
};
|
|
45
|
-
export const aaveAnyGetEmodeMutableProps = (
|
|
46
|
-
var
|
|
47
|
-
var { usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategories", "assetsData", "selectedMarket", "network"]);
|
|
48
|
-
const data = Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest);
|
|
45
|
+
export const aaveAnyGetEmodeMutableProps = ({ eModeCategory, assetsData, }, _asset) => {
|
|
46
|
+
var _a;
|
|
49
47
|
const asset = wethToEth(_asset);
|
|
50
|
-
const canSupplyAsColl = aaveAnyGetSuppliableAsCollAssets(data).some(({ symbol }) => symbol === asset);
|
|
51
|
-
// TODO remove dirty fix for Morpho V2
|
|
52
|
-
if (isMorphoAaveV2({ selectedMarket }) && !canSupplyAsColl) {
|
|
53
|
-
const { liquidationRatio, collateralFactor } = assetsData[asset];
|
|
54
|
-
return ({ liquidationRatio, collateralFactor });
|
|
55
|
-
}
|
|
56
|
-
if (!canSupplyAsColl) {
|
|
57
|
-
return ({ liquidationRatio: '0', collateralFactor: '0' });
|
|
58
|
-
}
|
|
59
48
|
const assetData = assetsData[asset];
|
|
60
49
|
if (eModeCategory === 0
|
|
61
50
|
|| assetData.eModeCategory !== eModeCategory
|
|
62
|
-
|| new Dec(((
|
|
51
|
+
|| new Dec(((_a = assetData === null || assetData === void 0 ? void 0 : assetData.eModeCategoryData) === null || _a === void 0 ? void 0 : _a.collateralFactor) || 0).eq(0)) {
|
|
63
52
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
64
53
|
return ({ liquidationRatio, collateralFactor });
|
|
65
54
|
}
|
|
@@ -14,7 +14,7 @@ export declare const sparkGetSuppliableAsCollAssets: ({ usedAssets, eModeCategor
|
|
|
14
14
|
symbol: string;
|
|
15
15
|
canBeCollateral: boolean;
|
|
16
16
|
}[];
|
|
17
|
-
export declare const sparkGetEmodeMutableProps: ({
|
|
17
|
+
export declare const sparkGetEmodeMutableProps: ({ eModeCategory, assetsData, }: SparkHelperCommon, _asset: string) => {
|
|
18
18
|
liquidationRatio: string;
|
|
19
19
|
collateralFactor: string;
|
|
20
20
|
};
|
|
@@ -30,19 +30,13 @@ export const sparkGetSuppliableAsCollAssets = (_a) => {
|
|
|
30
30
|
var { usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategories", "assetsData", "selectedMarket", "network"]);
|
|
31
31
|
return sparkGetSuppliableAssets(Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest)).filter(({ canBeCollateral }) => canBeCollateral);
|
|
32
32
|
};
|
|
33
|
-
export const sparkGetEmodeMutableProps = (
|
|
34
|
-
var
|
|
35
|
-
var { usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network } = _a, rest = __rest(_a, ["usedAssets", "eModeCategory", "eModeCategories", "assetsData", "selectedMarket", "network"]);
|
|
36
|
-
const data = Object.assign({ usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network }, rest);
|
|
33
|
+
export const sparkGetEmodeMutableProps = ({ eModeCategory, assetsData, }, _asset) => {
|
|
34
|
+
var _a;
|
|
37
35
|
const asset = wethToEth(_asset);
|
|
38
|
-
const canSupplyAsColl = sparkGetSuppliableAsCollAssets(data).some(({ symbol }) => symbol === asset);
|
|
39
|
-
if (!canSupplyAsColl) {
|
|
40
|
-
return ({ liquidationRatio: '0', collateralFactor: '0' });
|
|
41
|
-
}
|
|
42
36
|
const assetData = assetsData[asset];
|
|
43
37
|
if (eModeCategory === 0
|
|
44
38
|
|| assetData.eModeCategory !== eModeCategory
|
|
45
|
-
|| new Dec(((
|
|
39
|
+
|| new Dec(((_a = assetData === null || assetData === void 0 ? void 0 : assetData.eModeCategoryData) === null || _a === void 0 ? void 0 : _a.collateralFactor) || 0).eq(0)) {
|
|
46
40
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
47
41
|
return ({ liquidationRatio, collateralFactor });
|
|
48
42
|
}
|
package/esm/staking/staking.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
|
|
|
3
3
|
export declare const getStETHApr: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<any>;
|
|
4
4
|
export declare const getCbETHApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
5
5
|
export declare const getREthApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
|
+
export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
7
|
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> | undefined;
|
|
7
8
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
8
9
|
export declare const calculateNetApy: (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean) => {
|
package/esm/staking/staking.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
|
-
import { CbEthContract, LidoContract, REthContract, wstETHContract, } from '../contracts';
|
|
11
|
+
import { CbEthContract, LidoContract, PotContract, REthContract, wstETHContract, } from '../contracts';
|
|
12
12
|
import { NetworkNumber } from '../types/common';
|
|
13
13
|
import { BLOCKS_IN_A_YEAR, SECONDS_PER_YEAR, AVG_BLOCK_TIME } from '../constants';
|
|
14
14
|
import { multicall } from '../multicall';
|
|
@@ -67,6 +67,15 @@ export const getREthApr = (web3, blockNumber = 'latest') => __awaiter(void 0, vo
|
|
|
67
67
|
.toString();
|
|
68
68
|
return apr;
|
|
69
69
|
});
|
|
70
|
+
export const getDsrApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
const potContract = PotContract(web3, NetworkNumber.Eth);
|
|
72
|
+
return new Dec(yield potContract.methods.dsr().call())
|
|
73
|
+
.div(new Dec(1e27))
|
|
74
|
+
.pow(SECONDS_PER_YEAR)
|
|
75
|
+
.sub(1)
|
|
76
|
+
.mul(100)
|
|
77
|
+
.toString();
|
|
78
|
+
});
|
|
70
79
|
export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
71
80
|
if (asset === 'stETH' || asset === 'wstETH')
|
|
72
81
|
return getStETHApr(web3, fromBlock, blockNumber);
|
|
@@ -74,6 +83,8 @@ export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = u
|
|
|
74
83
|
return getCbETHApr(web3, blockNumber);
|
|
75
84
|
if (asset === 'rETH')
|
|
76
85
|
return getREthApr(web3, blockNumber);
|
|
86
|
+
if (asset === 'sDAI')
|
|
87
|
+
return getDsrApy(web3);
|
|
77
88
|
};
|
|
78
89
|
export const calculateInterestEarned = (principal, interest, type, apy = false) => {
|
|
79
90
|
let interval = 1;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
|
-
"module": "./esm/
|
|
7
|
-
"types": "./esm/
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"types": "./esm/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
10
10
|
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -244,7 +244,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
244
244
|
await Promise.all(assetsData.map(async (_market: AaveV3AssetData) => {
|
|
245
245
|
/* eslint-disable no-param-reassign */
|
|
246
246
|
const rewardForMarket: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput | undefined = rewardInfo?.[_market.underlyingTokenAddress as any];
|
|
247
|
-
if (['wstETH', 'cbETH', 'rETH'].includes(_market.symbol)) {
|
|
247
|
+
if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
|
|
248
248
|
if (!isLayer2Network(network) && _market.symbol === 'cbETH') return;
|
|
249
249
|
_market.incentiveSupplyApy = await getStakingApy(_market.symbol, defaultWeb3);
|
|
250
250
|
_market.incentiveSupplyToken = _market.symbol;
|
|
@@ -50,34 +50,17 @@ export const aaveAnyGetSuppliableAsCollAssets = ({
|
|
|
50
50
|
|
|
51
51
|
export const aaveAnyGetEmodeMutableProps = (
|
|
52
52
|
{
|
|
53
|
-
usedAssets,
|
|
54
53
|
eModeCategory,
|
|
55
|
-
eModeCategories,
|
|
56
54
|
assetsData,
|
|
57
|
-
selectedMarket,
|
|
58
|
-
network,
|
|
59
|
-
...rest
|
|
60
55
|
}: AaveHelperCommon, _asset: string) => {
|
|
61
|
-
const data = {
|
|
62
|
-
usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network, ...rest,
|
|
63
|
-
};
|
|
64
56
|
const asset = wethToEth(_asset);
|
|
65
|
-
const canSupplyAsColl = aaveAnyGetSuppliableAsCollAssets(data).some(({ symbol }: { symbol: string }) => symbol === asset);
|
|
66
57
|
|
|
67
|
-
// TODO remove dirty fix for Morpho V2
|
|
68
|
-
if (isMorphoAaveV2({ selectedMarket }) && !canSupplyAsColl) {
|
|
69
|
-
const { liquidationRatio, collateralFactor } = assetsData[asset];
|
|
70
|
-
return ({ liquidationRatio, collateralFactor });
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!canSupplyAsColl) {
|
|
74
|
-
return ({ liquidationRatio: '0', collateralFactor: '0' });
|
|
75
|
-
}
|
|
76
58
|
const assetData = assetsData[asset];
|
|
59
|
+
|
|
77
60
|
if (
|
|
78
61
|
eModeCategory === 0
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
|| assetData.eModeCategory !== eModeCategory
|
|
63
|
+
|| new Dec(assetData?.eModeCategoryData?.collateralFactor || 0).eq(0)
|
|
81
64
|
) {
|
|
82
65
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
83
66
|
return ({ liquidationRatio, collateralFactor });
|
|
@@ -36,29 +36,17 @@ export const sparkGetSuppliableAsCollAssets = ({
|
|
|
36
36
|
}).filter(({ canBeCollateral }) => canBeCollateral);
|
|
37
37
|
|
|
38
38
|
export const sparkGetEmodeMutableProps = ({
|
|
39
|
-
usedAssets,
|
|
40
39
|
eModeCategory,
|
|
41
|
-
eModeCategories,
|
|
42
40
|
assetsData,
|
|
43
|
-
selectedMarket,
|
|
44
|
-
network,
|
|
45
|
-
...rest
|
|
46
41
|
}: SparkHelperCommon,
|
|
47
42
|
_asset: string) => {
|
|
48
|
-
const data = {
|
|
49
|
-
usedAssets, eModeCategory, eModeCategories, assetsData, selectedMarket, network, ...rest,
|
|
50
|
-
};
|
|
51
43
|
const asset = wethToEth(_asset);
|
|
52
|
-
const canSupplyAsColl = sparkGetSuppliableAsCollAssets(data).some(({ symbol }) => symbol === asset);
|
|
53
44
|
|
|
54
|
-
if (!canSupplyAsColl) {
|
|
55
|
-
return ({ liquidationRatio: '0', collateralFactor: '0' });
|
|
56
|
-
}
|
|
57
45
|
const assetData = assetsData[asset];
|
|
58
46
|
if (
|
|
59
47
|
eModeCategory === 0
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
|| assetData.eModeCategory !== eModeCategory
|
|
49
|
+
|| new Dec(assetData?.eModeCategoryData?.collateralFactor || 0).eq(0)
|
|
62
50
|
) {
|
|
63
51
|
const { liquidationRatio, collateralFactor } = assetData;
|
|
64
52
|
return ({ liquidationRatio, collateralFactor });
|
package/src/staking/staking.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import Web3 from 'web3';
|
|
3
3
|
import {
|
|
4
|
-
CbEthContract, LidoContract, REthContract, wstETHContract,
|
|
4
|
+
CbEthContract, LidoContract, PotContract, REthContract, wstETHContract,
|
|
5
5
|
} from '../contracts';
|
|
6
6
|
import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
|
|
7
7
|
import { ContractEventLog } from '../types/contracts/generated/types';
|
|
@@ -66,10 +66,21 @@ export const getREthApr = async (web3: Web3, blockNumber: 'latest' | number = 'l
|
|
|
66
66
|
return apr;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
export const getDsrApy = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
|
|
70
|
+
const potContract = PotContract(web3, NetworkNumber.Eth);
|
|
71
|
+
return new Dec(await potContract.methods.dsr().call())
|
|
72
|
+
.div(new Dec(1e27))
|
|
73
|
+
.pow(SECONDS_PER_YEAR)
|
|
74
|
+
.sub(1)
|
|
75
|
+
.mul(100)
|
|
76
|
+
.toString();
|
|
77
|
+
};
|
|
78
|
+
|
|
69
79
|
export const getStakingApy = (asset: string, web3: Web3, blockNumber: 'latest' | number = 'latest', fromBlock: number | undefined = undefined) => {
|
|
70
80
|
if (asset === 'stETH' || asset === 'wstETH') return getStETHApr(web3, fromBlock, blockNumber);
|
|
71
81
|
if (asset === 'cbETH') return getCbETHApr(web3, blockNumber);
|
|
72
82
|
if (asset === 'rETH') return getREthApr(web3, blockNumber);
|
|
83
|
+
if (asset === 'sDAI') return getDsrApy(web3);
|
|
73
84
|
};
|
|
74
85
|
|
|
75
86
|
export const calculateInterestEarned = (principal: string, interest: string, type: string, apy = false) => {
|
package/yarn-error.log
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Arguments:
|
|
2
|
+
/Users/stefan/.nvm/versions/node/v14.19.0/bin/node /usr/local/Cellar/yarn/1.22.19/libexec/bin/yarn.js
|
|
3
|
+
|
|
4
|
+
PATH:
|
|
5
|
+
/Users/stefan/.nvm/versions/node/v14.19.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/go/bin:/Users/stefan/WebstormProjects/defisaver-positions-sdk/node_modules/.bin:/usr/local/go
|
|
6
|
+
|
|
7
|
+
Yarn version:
|
|
8
|
+
1.22.19
|
|
9
|
+
|
|
10
|
+
Node version:
|
|
11
|
+
14.19.0
|
|
12
|
+
|
|
13
|
+
Platform:
|
|
14
|
+
darwin x64
|
|
15
|
+
|
|
16
|
+
Trace:
|
|
17
|
+
Error: incorrect data check
|
|
18
|
+
at Zlib.zlibOnError [as onerror] (zlib.js:187:17)
|
|
19
|
+
|
|
20
|
+
npm manifest:
|
|
21
|
+
{
|
|
22
|
+
"name": "defisaver-positions-sdk",
|
|
23
|
+
"version": "0.0.1",
|
|
24
|
+
"description": "",
|
|
25
|
+
"main": "./cjs/index.js",
|
|
26
|
+
"module": "./esm/src/index.js",
|
|
27
|
+
"types": "./esm/src/index.d.ts",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
30
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
31
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
32
|
+
"dev": "tsc -p tsconfig.cjs.json --watch",
|
|
33
|
+
"lint": "eslint src/ --fix",
|
|
34
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
35
|
+
"test": "mocha tests/*",
|
|
36
|
+
"build-test": "npm run build && mocha tests/*"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [],
|
|
39
|
+
"author": "",
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@defisaver/tokens": "^1.4.56",
|
|
43
|
+
"decimal.js": "^10.4.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
47
|
+
"chai": "^4.3.8",
|
|
48
|
+
"dotenv": "^16.3.1",
|
|
49
|
+
"eslint": "^8.49.0",
|
|
50
|
+
"mocha": "^10.2.0",
|
|
51
|
+
"typechain": "^8.3.1",
|
|
52
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
53
|
+
"typescript": "^5.2.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"web3": "^1.10.2"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
yarn manifest:
|
|
61
|
+
No manifest
|
|
62
|
+
|
|
63
|
+
Lockfile:
|
|
64
|
+
No lockfile
|