@defisaver/positions-sdk 0.0.65 → 0.0.67
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/README.md +63 -63
- package/cjs/aaveV3/index.js +1 -1
- package/cjs/markets/llamaLend/index.js +1 -1
- package/cjs/morphoBlue/index.js +1 -1
- package/cjs/staking/staking.d.ts +2 -1
- package/cjs/staking/staking.js +26 -11
- package/cjs/types/llamaLend.js +2 -2
- package/esm/aaveV3/index.js +2 -2
- package/esm/markets/llamaLend/index.js +1 -1
- package/esm/morphoBlue/index.js +2 -2
- package/esm/staking/staking.d.ts +2 -1
- package/esm/staking/staking.js +25 -10
- package/esm/types/llamaLend.js +2 -2
- package/package.json +40 -40
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +562 -562
- 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 +273 -273
- package/src/config/contracts.js +845 -845
- package/src/constants/index.ts +5 -5
- package/src/contracts.ts +128 -128
- package/src/curveUsd/index.ts +229 -229
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +134 -134
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +181 -181
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/index.ts +7 -7
- package/src/helpers/llamaLendHelpers/index.ts +45 -45
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +56 -56
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +46 -46
- package/src/liquity/index.ts +116 -116
- package/src/llamaLend/index.ts +268 -268
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +80 -80
- package/src/markets/aave/marketAssets.ts +25 -25
- package/src/markets/compound/index.ts +142 -142
- package/src/markets/compound/marketsAssets.ts +50 -50
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +5 -5
- package/src/markets/llamaLend/contractAddresses.ts +95 -95
- package/src/markets/llamaLend/index.ts +150 -150
- package/src/markets/morphoBlue/index.ts +262 -262
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +75 -75
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +619 -619
- package/src/morphoBlue/index.ts +177 -178
- 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 +51 -51
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +422 -422
- package/src/staking/staking.ts +190 -175
- package/src/types/aave.ts +256 -256
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +128 -128
- package/src/types/curveUsd.ts +118 -118
- package/src/types/index.ts +8 -8
- package/src/types/liquity.ts +30 -30
- package/src/types/llamaLend.ts +143 -143
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +107 -107
- package/src/types/spark.ts +106 -106
- package/yarn-error.log +0 -64
package/README.md
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
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)
|
|
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)
|
package/cjs/aaveV3/index.js
CHANGED
|
@@ -175,7 +175,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
175
175
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
176
176
|
/* eslint-disable no-param-reassign */
|
|
177
177
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
178
|
-
if (
|
|
178
|
+
if (staking_1.STAKING_ASSETS.includes(_market.symbol)) {
|
|
179
179
|
_market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(_market.symbol, defaultWeb3);
|
|
180
180
|
_market.incentiveSupplyToken = _market.symbol;
|
|
181
181
|
}
|
|
@@ -44,7 +44,7 @@ const getLlamaLendMarketData = (market, network = 1) => (0, exports.LlamaLendMar
|
|
|
44
44
|
exports.getLlamaLendMarketData = getLlamaLendMarketData;
|
|
45
45
|
const getLlamaLendMarketFromControllerAddress = (controllerAddress, network) => {
|
|
46
46
|
const markets = (0, exports.LlamaLendMarkets)(network);
|
|
47
|
-
const market = Object.values(markets).find((
|
|
47
|
+
const market = Object.values(markets).find((tempMarket) => tempMarket.controllerAddress === controllerAddress);
|
|
48
48
|
if (!market)
|
|
49
49
|
throw new Error('Market not found');
|
|
50
50
|
return market;
|
package/cjs/morphoBlue/index.js
CHANGED
|
@@ -102,7 +102,7 @@ function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
|
|
|
102
102
|
canBeSupplied: true,
|
|
103
103
|
canBeBorrowed: false,
|
|
104
104
|
};
|
|
105
|
-
if (
|
|
105
|
+
if (staking_1.STAKING_ASSETS.includes(collateralTokenInfo.symbol)) {
|
|
106
106
|
assetsData[collateralTokenInfo.symbol].incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collateralTokenInfo.symbol, mainnetWeb3);
|
|
107
107
|
assetsData[collateralTokenInfo.symbol].incentiveSupplyToken = collateralTokenInfo.symbol;
|
|
108
108
|
}
|
package/cjs/staking/staking.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export declare const getCbETHApr: (web3: Web3, blockNumber?: 'latest' | number)
|
|
|
5
5
|
export declare const getREthApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
6
|
export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
7
7
|
export declare const getSUSDeApy: () => Promise<any>;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const STAKING_ASSETS: string[];
|
|
9
|
+
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> | "0" | undefined;
|
|
9
10
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
10
11
|
export declare const calculateNetApy: (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean) => {
|
|
11
12
|
netApy: string;
|
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.getSUSDeApy = exports.getDsrApy = exports.getREthApr = exports.getCbETHApr = exports.getStETHApr = void 0;
|
|
15
|
+
exports.getStETHByWstETHMultiple = exports.getStETHByWstETH = exports.getWstETHByStETH = exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = exports.getSUSDeApy = 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");
|
|
@@ -92,17 +92,32 @@ const getSUSDeApy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
92
92
|
return data.apy;
|
|
93
93
|
});
|
|
94
94
|
exports.getSUSDeApy = getSUSDeApy;
|
|
95
|
+
const getWeEthApr = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
96
|
+
const res = yield fetch('https://www.etherfi.bid/api/etherfi/apr');
|
|
97
|
+
const data = yield res.json();
|
|
98
|
+
const total = data.latest_aprs.reduce((acc, apr) => new decimal_js_1.default(acc).add(apr).toString());
|
|
99
|
+
return new decimal_js_1.default(total).div(data.latest_aprs.length).div(100).toString();
|
|
100
|
+
});
|
|
101
|
+
exports.STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe'];
|
|
95
102
|
const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
try {
|
|
104
|
+
if (asset === 'stETH' || asset === 'wstETH')
|
|
105
|
+
return (0, exports.getStETHApr)(web3, fromBlock, blockNumber);
|
|
106
|
+
if (asset === 'cbETH')
|
|
107
|
+
return (0, exports.getCbETHApr)(web3, blockNumber);
|
|
108
|
+
if (asset === 'rETH')
|
|
109
|
+
return (0, exports.getREthApr)(web3, blockNumber);
|
|
110
|
+
if (asset === 'sDAI')
|
|
111
|
+
return (0, exports.getDsrApy)(web3);
|
|
112
|
+
if (asset === 'sUSDe')
|
|
113
|
+
return (0, exports.getSUSDeApy)();
|
|
114
|
+
if (asset === 'weETH')
|
|
115
|
+
return getWeEthApr();
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
console.error(`Failed to fetch APY for ${asset}`);
|
|
119
|
+
return '0';
|
|
120
|
+
}
|
|
106
121
|
};
|
|
107
122
|
exports.getStakingApy = getStakingApy;
|
|
108
123
|
const calculateInterestEarned = (principal, interest, type, apy = false) => {
|
package/cjs/types/llamaLend.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LlamaLendStatus = exports.LlamaLendVersions = exports.LLVersionsArb = exports.LLVersionsEth = void 0;
|
|
4
4
|
var LLVersionsEth;
|
|
5
5
|
(function (LLVersionsEth) {
|
|
6
|
-
//long only
|
|
6
|
+
// long only
|
|
7
7
|
LLVersionsEth["LLWstethCrvusd"] = "llamaLendwstETHcrvUSD";
|
|
8
8
|
LLVersionsEth["LLSusdeCrvusd"] = "llamaLendsUSDecrvUSD";
|
|
9
9
|
// long and short crv
|
|
@@ -18,7 +18,7 @@ var LLVersionsEth;
|
|
|
18
18
|
})(LLVersionsEth || (exports.LLVersionsEth = LLVersionsEth = {}));
|
|
19
19
|
var LLVersionsArb;
|
|
20
20
|
(function (LLVersionsArb) {
|
|
21
|
-
//long only
|
|
21
|
+
// long only
|
|
22
22
|
LLVersionsArb["LLArbCrvusd"] = "llamaLendArbcrvUSD";
|
|
23
23
|
LLVersionsArb["LLFxnCrvusd"] = "llamaLendFXNcrvUSD";
|
|
24
24
|
LLVersionsArb["LLWbtcCrvusd"] = "llamaLendWBTCcrvUSD";
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tok
|
|
|
12
12
|
import { AaveIncentiveDataProviderV3Contract, AaveV3ViewContract, createContractWrapper, getConfigContractAbi, getConfigContractAddress, GhoTokenContract, } from '../contracts';
|
|
13
13
|
import { addToObjectIf, ethToWeth, getAbiItem, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
|
|
14
14
|
import { NetworkNumber, } from '../types/common';
|
|
15
|
-
import { getStakingApy } from '../staking';
|
|
15
|
+
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { multicall } from '../multicall';
|
|
17
17
|
import { getAssetsBalances } from '../assets';
|
|
18
18
|
import { calculateBorrowingAssetLimit } from '../moneymarket';
|
|
@@ -166,7 +166,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
166
166
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
167
167
|
/* eslint-disable no-param-reassign */
|
|
168
168
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
169
|
-
if (
|
|
169
|
+
if (STAKING_ASSETS.includes(_market.symbol)) {
|
|
170
170
|
_market.incentiveSupplyApy = yield getStakingApy(_market.symbol, defaultWeb3);
|
|
171
171
|
_market.incentiveSupplyToken = _market.symbol;
|
|
172
172
|
}
|
|
@@ -28,7 +28,7 @@ export const LlamaLendMarkets = (networkId) => ({
|
|
|
28
28
|
export const getLlamaLendMarketData = (market, network = 1) => LlamaLendMarkets(network)[market];
|
|
29
29
|
export const getLlamaLendMarketFromControllerAddress = (controllerAddress, network) => {
|
|
30
30
|
const markets = LlamaLendMarkets(network);
|
|
31
|
-
const market = Object.values(markets).find((
|
|
31
|
+
const market = Object.values(markets).find((tempMarket) => tempMarket.controllerAddress === controllerAddress);
|
|
32
32
|
if (!market)
|
|
33
33
|
throw new Error('Market not found');
|
|
34
34
|
return market;
|
package/esm/morphoBlue/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import Dec from 'decimal.js';
|
|
|
11
11
|
import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
12
|
import { MorphoBlueViewContract, getConfigContractAbi, getConfigContractAddress, } from '../contracts';
|
|
13
13
|
import { WAD, SECONDS_PER_YEAR, USD_QUOTE } from '../constants';
|
|
14
|
-
import { getStakingApy } from '../staking';
|
|
14
|
+
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
15
15
|
import { getAbiItem, wethToEth } from '../services/utils';
|
|
16
16
|
import { multicall } from '../multicall';
|
|
17
17
|
import { getMorphoBlueAggregatedPositionData } from '../helpers/morphoBlueHelpers';
|
|
@@ -96,7 +96,7 @@ export function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWe
|
|
|
96
96
|
canBeSupplied: true,
|
|
97
97
|
canBeBorrowed: false,
|
|
98
98
|
};
|
|
99
|
-
if (
|
|
99
|
+
if (STAKING_ASSETS.includes(collateralTokenInfo.symbol)) {
|
|
100
100
|
assetsData[collateralTokenInfo.symbol].incentiveSupplyApy = yield getStakingApy(collateralTokenInfo.symbol, mainnetWeb3);
|
|
101
101
|
assetsData[collateralTokenInfo.symbol].incentiveSupplyToken = collateralTokenInfo.symbol;
|
|
102
102
|
}
|
package/esm/staking/staking.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export declare const getCbETHApr: (web3: Web3, blockNumber?: 'latest' | number)
|
|
|
5
5
|
export declare const getREthApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
6
6
|
export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
|
|
7
7
|
export declare const getSUSDeApy: () => Promise<any>;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const STAKING_ASSETS: string[];
|
|
9
|
+
export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> | "0" | undefined;
|
|
9
10
|
export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
|
|
10
11
|
export declare const calculateNetApy: (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean) => {
|
|
11
12
|
netApy: string;
|
package/esm/staking/staking.js
CHANGED
|
@@ -81,17 +81,32 @@ export const getSUSDeApy = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
81
81
|
const data = yield res.json();
|
|
82
82
|
return data.apy;
|
|
83
83
|
});
|
|
84
|
+
const getWeEthApr = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
const res = yield fetch('https://www.etherfi.bid/api/etherfi/apr');
|
|
86
|
+
const data = yield res.json();
|
|
87
|
+
const total = data.latest_aprs.reduce((acc, apr) => new Dec(acc).add(apr).toString());
|
|
88
|
+
return new Dec(total).div(data.latest_aprs.length).div(100).toString();
|
|
89
|
+
});
|
|
90
|
+
export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe'];
|
|
84
91
|
export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
try {
|
|
93
|
+
if (asset === 'stETH' || asset === 'wstETH')
|
|
94
|
+
return getStETHApr(web3, fromBlock, blockNumber);
|
|
95
|
+
if (asset === 'cbETH')
|
|
96
|
+
return getCbETHApr(web3, blockNumber);
|
|
97
|
+
if (asset === 'rETH')
|
|
98
|
+
return getREthApr(web3, blockNumber);
|
|
99
|
+
if (asset === 'sDAI')
|
|
100
|
+
return getDsrApy(web3);
|
|
101
|
+
if (asset === 'sUSDe')
|
|
102
|
+
return getSUSDeApy();
|
|
103
|
+
if (asset === 'weETH')
|
|
104
|
+
return getWeEthApr();
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
console.error(`Failed to fetch APY for ${asset}`);
|
|
108
|
+
return '0';
|
|
109
|
+
}
|
|
95
110
|
};
|
|
96
111
|
export const calculateInterestEarned = (principal, interest, type, apy = false) => {
|
|
97
112
|
let interval = 1;
|
package/esm/types/llamaLend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export var LLVersionsEth;
|
|
2
2
|
(function (LLVersionsEth) {
|
|
3
|
-
//long only
|
|
3
|
+
// long only
|
|
4
4
|
LLVersionsEth["LLWstethCrvusd"] = "llamaLendwstETHcrvUSD";
|
|
5
5
|
LLVersionsEth["LLSusdeCrvusd"] = "llamaLendsUSDecrvUSD";
|
|
6
6
|
// long and short crv
|
|
@@ -15,7 +15,7 @@ export var LLVersionsEth;
|
|
|
15
15
|
})(LLVersionsEth || (LLVersionsEth = {}));
|
|
16
16
|
export var LLVersionsArb;
|
|
17
17
|
(function (LLVersionsArb) {
|
|
18
|
-
//long only
|
|
18
|
+
// long only
|
|
19
19
|
LLVersionsArb["LLArbCrvusd"] = "llamaLendArbcrvUSD";
|
|
20
20
|
LLVersionsArb["LLFxnCrvusd"] = "llamaLendFXNcrvUSD";
|
|
21
21
|
LLVersionsArb["LLWbtcCrvusd"] = "llamaLendWBTCcrvUSD";
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
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.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
-
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
-
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
|
-
"lint": "eslint src/ --fix",
|
|
14
|
-
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
-
"test": "mocha tests/*",
|
|
16
|
-
"build-test": "npm run build && mocha tests/*"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [],
|
|
19
|
-
"author": "",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@defisaver/tokens": "^1.5.18",
|
|
23
|
-
"@ethersproject/bignumber": "^5.7.0",
|
|
24
|
-
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
|
-
"decimal.js": "^10.4.3"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
29
|
-
"chai": "^4.3.8",
|
|
30
|
-
"dotenv": "^16.3.1",
|
|
31
|
-
"eslint": "^8.49.0",
|
|
32
|
-
"mocha": "^10.2.0",
|
|
33
|
-
"typechain": "^8.3.1",
|
|
34
|
-
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
35
|
-
"typescript": "^5.2.2"
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"web3": "^1.10.2"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@defisaver/positions-sdk",
|
|
3
|
+
"version": "0.0.67",
|
|
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.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
+
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
+
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
|
+
"lint": "eslint src/ --fix",
|
|
14
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
+
"test": "mocha tests/*",
|
|
16
|
+
"build-test": "npm run build && mocha tests/*"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@defisaver/tokens": "^1.5.18",
|
|
23
|
+
"@ethersproject/bignumber": "^5.7.0",
|
|
24
|
+
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
|
+
"decimal.js": "^10.4.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
29
|
+
"chai": "^4.3.8",
|
|
30
|
+
"dotenv": "^16.3.1",
|
|
31
|
+
"eslint": "^8.49.0",
|
|
32
|
+
"mocha": "^10.2.0",
|
|
33
|
+
"typechain": "^8.3.1",
|
|
34
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
35
|
+
"typescript": "^5.2.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"web3": "^1.10.2"
|
|
39
|
+
}
|
|
40
|
+
}
|