@defisaver/positions-sdk 0.0.164 → 0.0.166-dev
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +69 -69
- package/cjs/eulerV2/index.js +10 -4
- package/cjs/helpers/eulerHelpers/index.d.ts +2 -1
- package/cjs/helpers/eulerHelpers/index.js +11 -8
- package/cjs/types/euler.d.ts +1 -0
- package/esm/eulerV2/index.js +11 -5
- package/esm/helpers/eulerHelpers/index.d.ts +2 -1
- package/esm/helpers/eulerHelpers/index.js +9 -7
- package/esm/types/euler.d.ts +1 -0
- package/package.json +44 -44
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +590 -590
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +281 -281
- package/src/config/contracts.js +1040 -1040
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +130 -130
- package/src/curveUsd/index.ts +229 -229
- package/src/eulerV2/index.ts +285 -273
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +194 -194
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +246 -246
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +230 -228
- package/src/helpers/index.ts +8 -8
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +115 -115
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +48 -48
- package/src/liquity/index.ts +116 -116
- package/src/llamaLend/index.ts +275 -275
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +152 -152
- package/src/markets/aave/marketAssets.ts +46 -46
- package/src/markets/compound/index.ts +173 -173
- package/src/markets/compound/marketsAssets.ts +64 -64
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +37 -37
- package/src/markets/index.ts +23 -23
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +691 -691
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +630 -630
- package/src/morphoBlue/index.ts +171 -171
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +56 -56
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +424 -424
- package/src/staking/staking.ts +189 -189
- package/src/types/aave.ts +262 -262
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +129 -129
- package/src/types/curveUsd.ts +118 -118
- package/src/types/euler.ts +170 -169
- package/src/types/index.ts +9 -9
- package/src/types/liquity.ts +30 -30
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +144 -144
- package/src/types/spark.ts +127 -127
package/.mocharc.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"require": "ts-node/register",
|
|
3
|
-
"extension": ["ts"]
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"require": "ts-node/register",
|
|
3
|
+
"extension": ["ts"]
|
|
4
|
+
}
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v20.17.0
|
|
1
|
+
v20.17.0
|
package/README.md
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
# DeFi Saver Positions SDK
|
|
2
|
-
|
|
3
|
-
Supported protocols:
|
|
4
|
-
- [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
|
|
5
|
-
- [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
|
|
6
|
-
- [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
|
|
7
|
-
- [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
|
|
8
|
-
- [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
|
|
9
|
-
- [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
|
|
10
|
-
- [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
|
|
11
|
-
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
12
|
-
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
13
|
-
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
14
|
-
- [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
|
|
15
|
-
|
|
16
|
-
## Setup
|
|
17
|
-
Supported Node version is v10.
|
|
18
|
-
|
|
19
|
-
- run `npm install` (first time)
|
|
20
|
-
- run `npm run build`
|
|
21
|
-
|
|
22
|
-
`build` command will generate contracts and build ejs and esm folders
|
|
23
|
-
|
|
24
|
-
## How to use
|
|
25
|
-
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
26
|
-
|
|
27
|
-
This is a Compound V3 example, and every other protocol is similar
|
|
28
|
-
```js
|
|
29
|
-
import Web3 from 'web3';
|
|
30
|
-
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// every protocol has market data and user data getters
|
|
34
|
-
const {
|
|
35
|
-
getCompoundV3MarketsData,
|
|
36
|
-
getCompoundV3AccountData,
|
|
37
|
-
} = compoundV3;
|
|
38
|
-
|
|
39
|
-
const provider = 'Your RPC provider';
|
|
40
|
-
const web3 = new Web3(provider);
|
|
41
|
-
|
|
42
|
-
const user = '0x123...';
|
|
43
|
-
|
|
44
|
-
const { assetsData } = await getCompoundV3MarketsData(
|
|
45
|
-
web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
46
|
-
1, // network
|
|
47
|
-
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
48
|
-
web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const userData = await getCompoundV3AccountData(
|
|
52
|
-
web3,
|
|
53
|
-
1, // network
|
|
54
|
-
userAddress, // EOA or DSProxy
|
|
55
|
-
'', // proxy address of the user, or just empty string if checking for EOA
|
|
56
|
-
{
|
|
57
|
-
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
58
|
-
assetsData,
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
64
|
-
|
|
65
|
-
## Testing
|
|
66
|
-
|
|
67
|
-
`npm run test` - Run all tests
|
|
68
|
-
|
|
69
|
-
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
|
1
|
+
# DeFi Saver Positions SDK
|
|
2
|
+
|
|
3
|
+
Supported protocols:
|
|
4
|
+
- [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
|
|
5
|
+
- [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
|
|
6
|
+
- [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
|
|
7
|
+
- [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
|
|
8
|
+
- [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
|
|
9
|
+
- [Morpho Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV2)
|
|
10
|
+
- [Morpho Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/morphoAaveV3)
|
|
11
|
+
- [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
|
|
12
|
+
- [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
|
|
13
|
+
- [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
|
|
14
|
+
- [Chicken Bonds](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/chickenBonds)
|
|
15
|
+
|
|
16
|
+
## Setup
|
|
17
|
+
Supported Node version is v10.
|
|
18
|
+
|
|
19
|
+
- run `npm install` (first time)
|
|
20
|
+
- run `npm run build`
|
|
21
|
+
|
|
22
|
+
`build` command will generate contracts and build ejs and esm folders
|
|
23
|
+
|
|
24
|
+
## How to use
|
|
25
|
+
[All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
|
|
26
|
+
|
|
27
|
+
This is a Compound V3 example, and every other protocol is similar
|
|
28
|
+
```js
|
|
29
|
+
import Web3 from 'web3';
|
|
30
|
+
import { compoundV3 } from '@defisaver/positions-sdk';
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// every protocol has market data and user data getters
|
|
34
|
+
const {
|
|
35
|
+
getCompoundV3MarketsData,
|
|
36
|
+
getCompoundV3AccountData,
|
|
37
|
+
} = compoundV3;
|
|
38
|
+
|
|
39
|
+
const provider = 'Your RPC provider';
|
|
40
|
+
const web3 = new Web3(provider);
|
|
41
|
+
|
|
42
|
+
const user = '0x123...';
|
|
43
|
+
|
|
44
|
+
const { assetsData } = await getCompoundV3MarketsData(
|
|
45
|
+
web3, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
|
|
46
|
+
1, // network
|
|
47
|
+
selectedMarket, // market object like in /src/markets/compound/index.ts
|
|
48
|
+
web3, // this must be mainnet rpc - used for getting prices onchain and calculating apys
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const userData = await getCompoundV3AccountData(
|
|
52
|
+
web3,
|
|
53
|
+
1, // network
|
|
54
|
+
userAddress, // EOA or DSProxy
|
|
55
|
+
'', // proxy address of the user, or just empty string if checking for EOA
|
|
56
|
+
{
|
|
57
|
+
selectedMarket, // market object as in /src/markets/compound/index.ts
|
|
58
|
+
assetsData,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
|
|
64
|
+
|
|
65
|
+
## Testing
|
|
66
|
+
|
|
67
|
+
`npm run test` - Run all tests
|
|
68
|
+
|
|
69
|
+
`npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
|
package/cjs/eulerV2/index.js
CHANGED
|
@@ -43,6 +43,9 @@ const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3) => __
|
|
|
43
43
|
const colls = data.collaterals.map((collateral) => {
|
|
44
44
|
const decimals = collateral.decimals;
|
|
45
45
|
const assetInfo = (0, tokens_1.getAssetInfoByAddress)(collateral.assetAddr);
|
|
46
|
+
const borrowRate = (0, eulerHelpers_1.getEulerV2BorrowRate)(collateral.interestRate);
|
|
47
|
+
const utilizationRate = (0, eulerHelpers_1.getUtilizationRate)(collateral.totalBorrows, new decimal_js_1.default(collateral.totalBorrows).plus(collateral.cash).toString());
|
|
48
|
+
const supplyRate = (0, eulerHelpers_1.getEulerV2SupplyRate)(borrowRate, utilizationRate, collateral.interestFee);
|
|
46
49
|
return ({
|
|
47
50
|
vaultAddress: collateral.vaultAddr,
|
|
48
51
|
assetAddress: collateral.assetAddr,
|
|
@@ -58,8 +61,9 @@ const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3) => __
|
|
|
58
61
|
price: isInUSD ? (0, tokens_1.assetAmountInEth)(collateral.assetPriceInUnit) : new decimal_js_1.default((0, tokens_1.assetAmountInEth)(collateral.assetPriceInUnit)).mul(usdPrice).toString(),
|
|
59
62
|
canBeBorrowed: false,
|
|
60
63
|
canBeSupplied: true,
|
|
61
|
-
borrowRate
|
|
62
|
-
supplyRate
|
|
64
|
+
borrowRate,
|
|
65
|
+
supplyRate,
|
|
66
|
+
utilization: new decimal_js_1.default(utilizationRate).mul(100).toString(),
|
|
63
67
|
});
|
|
64
68
|
});
|
|
65
69
|
for (const coll of colls) {
|
|
@@ -75,7 +79,8 @@ const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3) => __
|
|
|
75
79
|
// (1 + SPY/10**27) ** secondsPerYear - 1
|
|
76
80
|
const interestRate = data.interestRate;
|
|
77
81
|
const borrowRate = (0, eulerHelpers_1.getEulerV2BorrowRate)(interestRate);
|
|
78
|
-
const
|
|
82
|
+
const utilizationRate = (0, eulerHelpers_1.getUtilizationRate)(data.totalBorrows, data.totalAssets);
|
|
83
|
+
const supplyRate = (0, eulerHelpers_1.getEulerV2SupplyRate)(borrowRate, utilizationRate, data.interestFee);
|
|
79
84
|
const marketAsset = {
|
|
80
85
|
assetAddress: data.assetAddr,
|
|
81
86
|
vaultAddress: data.vaultAddr,
|
|
@@ -94,6 +99,7 @@ const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3) => __
|
|
|
94
99
|
supplyRate,
|
|
95
100
|
collateralFactor: '0',
|
|
96
101
|
liquidationRatio: '0',
|
|
102
|
+
utilization: new decimal_js_1.default(utilizationRate).mul(100).toString(),
|
|
97
103
|
};
|
|
98
104
|
const assetsData = {
|
|
99
105
|
[data.vaultAddr.toLowerCase()]: marketAsset,
|
|
@@ -191,7 +197,7 @@ const getEulerV2AccountData = (web3, network, address, extractedState) => __awai
|
|
|
191
197
|
const suppliedInUnit = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInUnit, parsingDecimals);
|
|
192
198
|
const suppliedInAsset = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInAsset, collInfo.decimals);
|
|
193
199
|
const collateralAmountInUSD = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInUSD, 18);
|
|
194
|
-
usedAssets[key] = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { collateral:
|
|
200
|
+
usedAssets[key] = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { collateral: true, isSupplied: true, supplied: suppliedInAsset, suppliedUsd: collateralAmountInUSD, vaultAddress: collateral.collateralVault, symbol: collInfo.symbol });
|
|
195
201
|
});
|
|
196
202
|
payload = Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), (0, eulerHelpers_1.getEulerV2AggregatedData)({
|
|
197
203
|
usedAssets, assetsData, network,
|
|
@@ -17,7 +17,8 @@ export declare const getEulerV2AggregatedData: ({ usedAssets, assetsData, networ
|
|
|
17
17
|
network: NetworkNumber;
|
|
18
18
|
}) => EulerV2AggregatedPositionData;
|
|
19
19
|
export declare const getEulerV2BorrowRate: (interestRate: string) => string;
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const getUtilizationRate: (totalBorrows: string, totalAssets: string) => string;
|
|
21
|
+
export declare const getEulerV2SupplyRate: (borrowRate: string, utilizationRate: string, _interestFee: string) => string;
|
|
21
22
|
export declare const getApyAfterValuesEstimationEulerV2: (actions: {
|
|
22
23
|
action: string;
|
|
23
24
|
amount: string;
|
|
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getApyAfterValuesEstimationEulerV2 = exports.getEulerV2SupplyRate = exports.getEulerV2BorrowRate = exports.getEulerV2AggregatedData = exports.calculateNetApy = exports.isLeveragedPos = void 0;
|
|
26
|
+
exports.getApyAfterValuesEstimationEulerV2 = exports.getEulerV2SupplyRate = exports.getUtilizationRate = exports.getEulerV2BorrowRate = exports.getEulerV2AggregatedData = exports.calculateNetApy = exports.isLeveragedPos = void 0;
|
|
27
27
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
28
28
|
const tokens_1 = require("@defisaver/tokens");
|
|
29
29
|
const moneymarket_1 = require("../../moneymarket");
|
|
@@ -155,14 +155,16 @@ const getEulerV2AggregatedData = (_a) => {
|
|
|
155
155
|
};
|
|
156
156
|
exports.getEulerV2AggregatedData = getEulerV2AggregatedData;
|
|
157
157
|
const getEulerV2BorrowRate = (interestRate) => {
|
|
158
|
-
const _interestRate = new decimal_js_1.default(interestRate).div(1e27);
|
|
158
|
+
const _interestRate = new decimal_js_1.default(interestRate).div(1e27).toString();
|
|
159
159
|
const secondsPerYear = 31556953;
|
|
160
|
-
|
|
160
|
+
const a = new decimal_js_1.default(1).plus(_interestRate).pow(secondsPerYear - 1).toString();
|
|
161
|
+
return new decimal_js_1.default(new decimal_js_1.default(a).minus(1)).mul(100).toString();
|
|
161
162
|
};
|
|
162
163
|
exports.getEulerV2BorrowRate = getEulerV2BorrowRate;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
const getUtilizationRate = (totalBorrows, totalAssets) => new decimal_js_1.default(totalBorrows).div(totalAssets).toString();
|
|
165
|
+
exports.getUtilizationRate = getUtilizationRate;
|
|
166
|
+
const getEulerV2SupplyRate = (borrowRate, utilizationRate, _interestFee) => {
|
|
167
|
+
const interestFee = new decimal_js_1.default(_interestFee).div(10000);
|
|
166
168
|
const fee = new decimal_js_1.default(1).minus(interestFee);
|
|
167
169
|
return new decimal_js_1.default(borrowRate).mul(utilizationRate).mul(fee).toString();
|
|
168
170
|
};
|
|
@@ -213,15 +215,16 @@ const getApyAfterValuesEstimationEulerV2 = (actions, web3, network) => __awaiter
|
|
|
213
215
|
const vaultInfo = multicallRes[i][0];
|
|
214
216
|
const decimals = vaultInfo.decimals;
|
|
215
217
|
const borrowRate = (0, exports.getEulerV2BorrowRate)(_interestRate);
|
|
216
|
-
const amount =
|
|
218
|
+
const amount = new decimal_js_1.default(actions[i].amount).mul(Math.pow(10, decimals)).toString();
|
|
217
219
|
const action = actions[i].action;
|
|
218
220
|
const isBorrowOperation = constants_1.borrowOperations.includes(action);
|
|
219
221
|
const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amount, isBorrowOperation);
|
|
220
222
|
const totalBorrows = new decimal_js_1.default(vaultInfo.totalBorrows).add(isBorrowOperation ? liquidityRemoved : '0').sub(isBorrowOperation ? liquidityAdded : '0').toString();
|
|
221
223
|
const totalAssets = new decimal_js_1.default(vaultInfo.totalAssets).add(isBorrowOperation ? '0' : liquidityAdded).sub(isBorrowOperation ? '0' : liquidityRemoved).toString();
|
|
224
|
+
const utilizationRate = (0, exports.getUtilizationRate)(totalBorrows, totalAssets);
|
|
222
225
|
data[vaultInfo.vaultAddr.toLowerCase()] = {
|
|
223
226
|
borrowRate,
|
|
224
|
-
supplyRate: (0, exports.getEulerV2SupplyRate)(borrowRate,
|
|
227
|
+
supplyRate: (0, exports.getEulerV2SupplyRate)(borrowRate, utilizationRate, vaultInfo.interestFee),
|
|
225
228
|
};
|
|
226
229
|
}
|
|
227
230
|
return data;
|
package/cjs/types/euler.d.ts
CHANGED
package/esm/eulerV2/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
|
12
12
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
13
13
|
import { compareAddresses, getEthAmountForDecimals, isMaxuint } from '../services/utils';
|
|
14
14
|
import { EulerV2VaultType, } from '../types';
|
|
15
|
-
import { getEulerV2AggregatedData, getEulerV2BorrowRate, getEulerV2SupplyRate } from '../helpers/eulerHelpers';
|
|
15
|
+
import { getEulerV2AggregatedData, getEulerV2BorrowRate, getEulerV2SupplyRate, getUtilizationRate, } from '../helpers/eulerHelpers';
|
|
16
16
|
import { ZERO_ADDRESS } from '../constants';
|
|
17
17
|
import { EulerV2ViewContract } from '../contracts';
|
|
18
18
|
export const EMPTY_USED_ASSET = {
|
|
@@ -37,6 +37,9 @@ export const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3
|
|
|
37
37
|
const colls = data.collaterals.map((collateral) => {
|
|
38
38
|
const decimals = collateral.decimals;
|
|
39
39
|
const assetInfo = getAssetInfoByAddress(collateral.assetAddr);
|
|
40
|
+
const borrowRate = getEulerV2BorrowRate(collateral.interestRate);
|
|
41
|
+
const utilizationRate = getUtilizationRate(collateral.totalBorrows, new Dec(collateral.totalBorrows).plus(collateral.cash).toString());
|
|
42
|
+
const supplyRate = getEulerV2SupplyRate(borrowRate, utilizationRate, collateral.interestFee);
|
|
40
43
|
return ({
|
|
41
44
|
vaultAddress: collateral.vaultAddr,
|
|
42
45
|
assetAddress: collateral.assetAddr,
|
|
@@ -52,8 +55,9 @@ export const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3
|
|
|
52
55
|
price: isInUSD ? assetAmountInEth(collateral.assetPriceInUnit) : new Dec(assetAmountInEth(collateral.assetPriceInUnit)).mul(usdPrice).toString(),
|
|
53
56
|
canBeBorrowed: false,
|
|
54
57
|
canBeSupplied: true,
|
|
55
|
-
borrowRate
|
|
56
|
-
supplyRate
|
|
58
|
+
borrowRate,
|
|
59
|
+
supplyRate,
|
|
60
|
+
utilization: new Dec(utilizationRate).mul(100).toString(),
|
|
57
61
|
});
|
|
58
62
|
});
|
|
59
63
|
for (const coll of colls) {
|
|
@@ -69,7 +73,8 @@ export const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3
|
|
|
69
73
|
// (1 + SPY/10**27) ** secondsPerYear - 1
|
|
70
74
|
const interestRate = data.interestRate;
|
|
71
75
|
const borrowRate = getEulerV2BorrowRate(interestRate);
|
|
72
|
-
const
|
|
76
|
+
const utilizationRate = getUtilizationRate(data.totalBorrows, data.totalAssets);
|
|
77
|
+
const supplyRate = getEulerV2SupplyRate(borrowRate, utilizationRate, data.interestFee);
|
|
73
78
|
const marketAsset = {
|
|
74
79
|
assetAddress: data.assetAddr,
|
|
75
80
|
vaultAddress: data.vaultAddr,
|
|
@@ -88,6 +93,7 @@ export const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3
|
|
|
88
93
|
supplyRate,
|
|
89
94
|
collateralFactor: '0',
|
|
90
95
|
liquidationRatio: '0',
|
|
96
|
+
utilization: new Dec(utilizationRate).mul(100).toString(),
|
|
91
97
|
};
|
|
92
98
|
const assetsData = {
|
|
93
99
|
[data.vaultAddr.toLowerCase()]: marketAsset,
|
|
@@ -184,7 +190,7 @@ export const getEulerV2AccountData = (web3, network, address, extractedState) =>
|
|
|
184
190
|
const suppliedInUnit = getEthAmountForDecimals(collateral.collateralAmountInUnit, parsingDecimals);
|
|
185
191
|
const suppliedInAsset = getEthAmountForDecimals(collateral.collateralAmountInAsset, collInfo.decimals);
|
|
186
192
|
const collateralAmountInUSD = getEthAmountForDecimals(collateral.collateralAmountInUSD, 18);
|
|
187
|
-
usedAssets[key] = Object.assign(Object.assign({}, EMPTY_USED_ASSET), { collateral:
|
|
193
|
+
usedAssets[key] = Object.assign(Object.assign({}, EMPTY_USED_ASSET), { collateral: true, isSupplied: true, supplied: suppliedInAsset, suppliedUsd: collateralAmountInUSD, vaultAddress: collateral.collateralVault, symbol: collInfo.symbol });
|
|
188
194
|
});
|
|
189
195
|
payload = Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), getEulerV2AggregatedData({
|
|
190
196
|
usedAssets, assetsData, network,
|
|
@@ -17,7 +17,8 @@ export declare const getEulerV2AggregatedData: ({ usedAssets, assetsData, networ
|
|
|
17
17
|
network: NetworkNumber;
|
|
18
18
|
}) => EulerV2AggregatedPositionData;
|
|
19
19
|
export declare const getEulerV2BorrowRate: (interestRate: string) => string;
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const getUtilizationRate: (totalBorrows: string, totalAssets: string) => string;
|
|
21
|
+
export declare const getEulerV2SupplyRate: (borrowRate: string, utilizationRate: string, _interestFee: string) => string;
|
|
21
22
|
export declare const getApyAfterValuesEstimationEulerV2: (actions: {
|
|
22
23
|
action: string;
|
|
23
24
|
amount: string;
|
|
@@ -146,13 +146,14 @@ export const getEulerV2AggregatedData = (_a) => {
|
|
|
146
146
|
return payload;
|
|
147
147
|
};
|
|
148
148
|
export const getEulerV2BorrowRate = (interestRate) => {
|
|
149
|
-
const _interestRate = new Dec(interestRate).div(1e27);
|
|
149
|
+
const _interestRate = new Dec(interestRate).div(1e27).toString();
|
|
150
150
|
const secondsPerYear = 31556953;
|
|
151
|
-
|
|
151
|
+
const a = new Dec(1).plus(_interestRate).pow(secondsPerYear - 1).toString();
|
|
152
|
+
return new Dec(new Dec(a).minus(1)).mul(100).toString();
|
|
152
153
|
};
|
|
153
|
-
export const
|
|
154
|
-
|
|
155
|
-
const interestFee = new Dec(_interestFee).div(
|
|
154
|
+
export const getUtilizationRate = (totalBorrows, totalAssets) => new Dec(totalBorrows).div(totalAssets).toString();
|
|
155
|
+
export const getEulerV2SupplyRate = (borrowRate, utilizationRate, _interestFee) => {
|
|
156
|
+
const interestFee = new Dec(_interestFee).div(10000);
|
|
156
157
|
const fee = new Dec(1).minus(interestFee);
|
|
157
158
|
return new Dec(borrowRate).mul(utilizationRate).mul(fee).toString();
|
|
158
159
|
};
|
|
@@ -202,15 +203,16 @@ export const getApyAfterValuesEstimationEulerV2 = (actions, web3, network) => __
|
|
|
202
203
|
const vaultInfo = multicallRes[i][0];
|
|
203
204
|
const decimals = vaultInfo.decimals;
|
|
204
205
|
const borrowRate = getEulerV2BorrowRate(_interestRate);
|
|
205
|
-
const amount =
|
|
206
|
+
const amount = new Dec(actions[i].amount).mul(Math.pow(10, decimals)).toString();
|
|
206
207
|
const action = actions[i].action;
|
|
207
208
|
const isBorrowOperation = borrowOperations.includes(action);
|
|
208
209
|
const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amount, isBorrowOperation);
|
|
209
210
|
const totalBorrows = new Dec(vaultInfo.totalBorrows).add(isBorrowOperation ? liquidityRemoved : '0').sub(isBorrowOperation ? liquidityAdded : '0').toString();
|
|
210
211
|
const totalAssets = new Dec(vaultInfo.totalAssets).add(isBorrowOperation ? '0' : liquidityAdded).sub(isBorrowOperation ? '0' : liquidityRemoved).toString();
|
|
212
|
+
const utilizationRate = getUtilizationRate(totalBorrows, totalAssets);
|
|
211
213
|
data[vaultInfo.vaultAddr.toLowerCase()] = {
|
|
212
214
|
borrowRate,
|
|
213
|
-
supplyRate: getEulerV2SupplyRate(borrowRate,
|
|
215
|
+
supplyRate: getEulerV2SupplyRate(borrowRate, utilizationRate, vaultInfo.interestFee),
|
|
214
216
|
};
|
|
215
217
|
}
|
|
216
218
|
return data;
|
package/esm/types/euler.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./cjs/index.js",
|
|
6
|
-
"module": "./esm/index.js",
|
|
7
|
-
"types": "./esm/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.json",
|
|
11
|
-
"build": "npm run lint && npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
-
"dev": "npm run generate-contracts && tsc -p tsconfig.json --watch",
|
|
13
|
-
"lint": "eslint src/ --fix",
|
|
14
|
-
"lint-check": "eslint src/",
|
|
15
|
-
"generate-contracts": "node scripts/generateContracts.js",
|
|
16
|
-
"test": "mocha tests/*",
|
|
17
|
-
"test-single": "mocha ./tests/$npm_config_name.js",
|
|
18
|
-
"test:debugger": "mocha --inspect-brk tests/*",
|
|
19
|
-
"build-test": "npm run build && npm run test"
|
|
20
|
-
},
|
|
21
|
-
"keywords": [],
|
|
22
|
-
"author": "",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@defisaver/tokens": "^1.5.37",
|
|
26
|
-
"@ethersproject/bignumber": "^5.7.0",
|
|
27
|
-
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
28
|
-
"decimal.js": "^10.4.3"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
32
|
-
"chai": "^4.3.8",
|
|
33
|
-
"dotenv": "^16.3.1",
|
|
34
|
-
"eslint": "^8.49.0",
|
|
35
|
-
"mocha": "^10.2.0",
|
|
36
|
-
"ts-node": "^10.9.2",
|
|
37
|
-
"typechain": "^8.3.1",
|
|
38
|
-
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
39
|
-
"typescript": "^5.2.2"
|
|
40
|
-
},
|
|
41
|
-
"peerDependencies": {
|
|
42
|
-
"web3": "^1.10.2"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@defisaver/positions-sdk",
|
|
3
|
+
"version": "0.0.166-dev",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"types": "./esm/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.esm.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.json",
|
|
11
|
+
"build": "npm run lint && npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
+
"dev": "npm run generate-contracts && tsc -p tsconfig.json --watch",
|
|
13
|
+
"lint": "eslint src/ --fix",
|
|
14
|
+
"lint-check": "eslint src/",
|
|
15
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
16
|
+
"test": "mocha tests/*",
|
|
17
|
+
"test-single": "mocha ./tests/$npm_config_name.js",
|
|
18
|
+
"test:debugger": "mocha --inspect-brk tests/*",
|
|
19
|
+
"build-test": "npm run build && npm run test"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [],
|
|
22
|
+
"author": "",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@defisaver/tokens": "^1.5.37",
|
|
26
|
+
"@ethersproject/bignumber": "^5.7.0",
|
|
27
|
+
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
28
|
+
"decimal.js": "^10.4.3"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
32
|
+
"chai": "^4.3.8",
|
|
33
|
+
"dotenv": "^16.3.1",
|
|
34
|
+
"eslint": "^8.49.0",
|
|
35
|
+
"mocha": "^10.2.0",
|
|
36
|
+
"ts-node": "^10.9.2",
|
|
37
|
+
"typechain": "^8.3.1",
|
|
38
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
39
|
+
"typescript": "^5.2.2"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"web3": "^1.10.2"
|
|
43
|
+
}
|
|
44
|
+
}
|