@defisaver/positions-sdk 0.0.66 → 0.0.68

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.
Files changed (70) hide show
  1. package/README.md +63 -63
  2. package/cjs/markets/aave/marketAssets.js +1 -1
  3. package/cjs/markets/llamaLend/index.js +1 -1
  4. package/cjs/staking/staking.js +9 -1
  5. package/cjs/types/llamaLend.js +2 -2
  6. package/esm/markets/aave/marketAssets.js +1 -1
  7. package/esm/markets/llamaLend/index.js +1 -1
  8. package/esm/staking/staking.js +9 -1
  9. package/esm/types/llamaLend.js +2 -2
  10. package/package.json +41 -40
  11. package/src/aaveV2/index.ts +227 -227
  12. package/src/aaveV3/index.ts +562 -562
  13. package/src/assets/index.ts +60 -60
  14. package/src/chickenBonds/index.ts +123 -123
  15. package/src/compoundV2/index.ts +219 -219
  16. package/src/compoundV3/index.ts +273 -273
  17. package/src/config/contracts.js +845 -845
  18. package/src/constants/index.ts +5 -5
  19. package/src/contracts.ts +128 -128
  20. package/src/curveUsd/index.ts +229 -229
  21. package/src/exchange/index.ts +17 -17
  22. package/src/helpers/aaveHelpers/index.ts +134 -134
  23. package/src/helpers/chickenBondsHelpers/index.ts +23 -23
  24. package/src/helpers/compoundHelpers/index.ts +181 -181
  25. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  26. package/src/helpers/index.ts +7 -7
  27. package/src/helpers/llamaLendHelpers/index.ts +45 -45
  28. package/src/helpers/makerHelpers/index.ts +94 -94
  29. package/src/helpers/morphoBlueHelpers/index.ts +56 -56
  30. package/src/helpers/sparkHelpers/index.ts +106 -106
  31. package/src/index.ts +46 -46
  32. package/src/liquity/index.ts +116 -116
  33. package/src/llamaLend/index.ts +268 -268
  34. package/src/maker/index.ts +117 -117
  35. package/src/markets/aave/index.ts +80 -80
  36. package/src/markets/aave/marketAssets.ts +25 -25
  37. package/src/markets/compound/index.ts +142 -142
  38. package/src/markets/compound/marketsAssets.ts +50 -50
  39. package/src/markets/curveUsd/index.ts +69 -69
  40. package/src/markets/index.ts +5 -5
  41. package/src/markets/llamaLend/contractAddresses.ts +95 -95
  42. package/src/markets/llamaLend/index.ts +150 -150
  43. package/src/markets/morphoBlue/index.ts +262 -262
  44. package/src/markets/spark/index.ts +29 -29
  45. package/src/markets/spark/marketAssets.ts +10 -10
  46. package/src/moneymarket/moneymarketCommonService.ts +75 -75
  47. package/src/morphoAaveV2/index.ts +256 -256
  48. package/src/morphoAaveV3/index.ts +619 -619
  49. package/src/morphoBlue/index.ts +177 -178
  50. package/src/multicall/index.ts +22 -22
  51. package/src/services/dsrService.ts +15 -15
  52. package/src/services/priceService.ts +21 -21
  53. package/src/services/utils.ts +51 -51
  54. package/src/setup.ts +8 -8
  55. package/src/spark/index.ts +422 -422
  56. package/src/staking/staking.ts +199 -190
  57. package/src/types/aave.ts +256 -256
  58. package/src/types/chickenBonds.ts +45 -45
  59. package/src/types/common.ts +84 -84
  60. package/src/types/compound.ts +128 -128
  61. package/src/types/curveUsd.ts +118 -118
  62. package/src/types/index.ts +8 -8
  63. package/src/types/liquity.ts +30 -30
  64. package/src/types/llamaLend.ts +143 -143
  65. package/src/types/maker.ts +50 -50
  66. package/src/types/morphoBlue.ts +107 -107
  67. package/src/types/spark.ts +106 -106
  68. package/.yarn/releases/yarn-1.22.1.cjs +0 -147386
  69. package/.yarn/releases/yarn-1.22.1.js +0 -147386
  70. package/.yarnrc.yml +0 -1
@@ -1,190 +1,199 @@
1
- import Dec from 'decimal.js';
2
- import Web3 from 'web3';
3
- import {
4
- CbEthContract, LidoContract, PotContract, REthContract, wstETHContract,
5
- } from '../contracts';
6
- import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
7
- import { ContractEventLog } from '../types/contracts/generated/types';
8
- import { BLOCKS_IN_A_YEAR, SECONDS_PER_YEAR, AVG_BLOCK_TIME } from '../constants';
9
- import { multicall } from '../multicall';
10
-
11
- export const getStETHApr = async (web3: Web3, fromBlock = 17900000, blockNumber: 'latest' | number = 'latest') => {
12
- try {
13
- const tokenRebasedEvents: ContractEventLog<{ [key: string]: any }>[] = await LidoContract(web3, NetworkNumber.Eth).getPastEvents('TokenRebased', { fromBlock, toBlock: blockNumber });
14
- tokenRebasedEvents.sort((a, b) => b.blockNumber - a.blockNumber); // sort from highest to lowest block number
15
- const movingAverage = 7;
16
- const aprs = tokenRebasedEvents.slice(0, movingAverage).map(({ returnValues: event }) => {
17
- const preShareRate = new Dec(event.preTotalEther.toString()).div(event.preTotalShares.toString());
18
- const postShareRate = new Dec(event.postTotalEther.toString()).div(event.postTotalShares.toString());
19
- return new Dec(SECONDS_PER_YEAR).mul(new Dec(postShareRate).sub(preShareRate).div(preShareRate))
20
- .div(event.timeElapsed.toString()).mul(100)
21
- .toNumber();
22
- });
23
- return aprs.reduce((a, b) => a + b, 0) / aprs.length;
24
- } catch (e) {
25
- console.warn('Failed to fetch stETH APY from events, falling back to Lido API');
26
- const res = await fetch('https://eth-api.lido.fi/v1/protocol/steth/apr/sma');
27
- const data = await res.json();
28
- return data.data.smaApr;
29
- }
30
- };
31
-
32
-
33
- export const getCbETHApr = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
34
- let currentBlock = blockNumber;
35
- if (blockNumber === 'latest') currentBlock = await web3.eth.getBlockNumber();
36
- const blockDiff = 6 * 24 * 60 * 60 / AVG_BLOCK_TIME;
37
- const pastBlock = (currentBlock as number) - blockDiff;
38
- const contract = CbEthContract(web3, NetworkNumber.Eth);
39
- const [pastRate, currentRate] = await Promise.all([
40
- contract.methods.exchangeRate().call({}, pastBlock),
41
- contract.methods.exchangeRate().call({}, currentBlock),
42
- ]);
43
- const apr = new Dec(currentRate.toString()).sub(pastRate.toString()).div(currentRate.toString())
44
- .mul(BLOCKS_IN_A_YEAR / blockDiff)
45
- .mul(100)
46
- .toString();
47
- return apr;
48
- };
49
-
50
-
51
- export const getREthApr = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
52
- let currentBlock = blockNumber;
53
- if (blockNumber === 'latest') currentBlock = await web3.eth.getBlockNumber();
54
- const blockDiff = 8 * 24 * 60 * 60 / AVG_BLOCK_TIME;
55
- const pastBlock = (currentBlock as number) - blockDiff;
56
- const contract = REthContract(web3, NetworkNumber.Eth);
57
- const [pastRate, currentRate] = await Promise.all([
58
- contract.methods.getExchangeRate().call({}, pastBlock),
59
- contract.methods.getExchangeRate().call({}, currentBlock),
60
- ]);
61
- const apr = new Dec(currentRate.toString()).sub(pastRate.toString()).div(currentRate.toString())
62
- .mul(BLOCKS_IN_A_YEAR / blockDiff)
63
- .mul(100)
64
- .toString();
65
-
66
- return apr;
67
- };
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
-
79
- export const getSUSDeApy = async () => {
80
- const res = await fetch('https://app.defisaver.com/api/staking/apy?asset=sUSDe');
81
- const data = await res.json();
82
- return data.apy;
83
- };
84
-
85
- const getWeEthApr = async () => {
86
- const res = await fetch('https://www.etherfi.bid/api/etherfi/apr');
87
- const data = await res.json();
88
- const total = (data.latest_aprs as string[]).reduce((acc,apr) => new Dec(acc).add(apr).toString());
89
- return new Dec(total).div(data.latest_aprs.length).div(100).toString();
90
- }
91
-
92
- export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI','weETH'];
93
-
94
- export const getStakingApy = (asset: string, web3: Web3, blockNumber: 'latest' | number = 'latest', fromBlock: number | undefined = undefined) => {
95
- try {
96
- if (asset === 'stETH' || asset === 'wstETH') return getStETHApr(web3, fromBlock, blockNumber);
97
- if (asset === 'cbETH') return getCbETHApr(web3, blockNumber);
98
- if (asset === 'rETH') return getREthApr(web3, blockNumber);
99
- if (asset === 'sDAI') return getDsrApy(web3);
100
- if (asset === 'sUSDe') return getSUSDeApy();
101
- if (asset === 'weETH') return getWeEthApr();
102
- } catch (e) {
103
- console.error(`Failed to fetch APY for ${asset}`);
104
- return '0';
105
- }
106
- };
107
-
108
- export const calculateInterestEarned = (principal: string, interest: string, type: string, apy = false) => {
109
- let interval = 1;
110
-
111
- if (+interest === 0) return 0;
112
-
113
- if (type === 'month') interval = 1 / 12;
114
- if (type === 'week') interval = 1 / 52.1429;
115
-
116
- if (apy) {
117
- // interest rate already compounded
118
- return (+principal * (1 + (+interest / 100 * interval))) - +principal;
119
- }
120
-
121
- return (+principal * (((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)) ** (BLOCKS_IN_A_YEAR * interval))) - +principal; // eslint-disable-line
122
- };
123
-
124
- export const calculateNetApy = (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho = false) => {
125
- const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
126
- const acc = { ..._acc };
127
- const assetData = assetsData[usedAsset.symbol];
128
-
129
- if (usedAsset.isSupplied) {
130
- const amount = usedAsset.suppliedUsd;
131
- acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
132
- const rate = isMorpho
133
- ? usedAsset.supplyRate === '0' ? assetData.supplyRateP2P : usedAsset.supplyRate
134
- : assetData.supplyRate;
135
- const supplyInterest = calculateInterestEarned(amount, rate as string, 'year', true);
136
- acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
137
- if (assetData.incentiveSupplyApy) {
138
- // take COMP/AAVE yield into account
139
- const incentiveInterest = calculateInterestEarned(amount, assetData.incentiveSupplyApy, 'year', true);
140
- acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
141
- }
142
- }
143
-
144
- if (usedAsset.isBorrowed) {
145
- const amount = usedAsset.borrowedUsd;
146
- acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
147
- const rate = isMorpho
148
- ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
149
- : usedAsset.symbol === 'GHO'
150
- ? usedAsset.discountedBorrowRate
151
- : (usedAsset?.interestMode === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
152
- const borrowInterest = calculateInterestEarned(amount, rate as string, 'year', true);
153
- acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
154
- if (assetData.incentiveBorrowApy) {
155
- // take COMP/AAVE yield into account
156
- const incentiveInterest = calculateInterestEarned(amount, assetData.incentiveBorrowApy, 'year', true);
157
- acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
158
- }
159
- }
160
-
161
- return acc;
162
- }, {
163
- borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
164
- });
165
-
166
- const {
167
- borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd,
168
- } = sumValues;
169
-
170
- const totalInterestUsd = new Dec(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
171
- const balance = new Dec(suppliedUsd).sub(borrowedUsd);
172
- const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
173
-
174
- return { netApy, totalInterestUsd, incentiveUsd };
175
- };
176
-
177
- export const getWstETHByStETH = async (stETHAmount: string | number, web3: Web3) => wstETHContract(web3, NetworkNumber.Eth).methods.getWstETHByStETH(stETHAmount).call();
178
-
179
- export const getStETHByWstETH = async (wstETHAmount: string | number, web3: Web3) => wstETHContract(web3, NetworkNumber.Eth).methods.getStETHByWstETH(wstETHAmount).call();
180
-
181
- export const getStETHByWstETHMultiple = async (wstEthAmounts: string[] | number[], web3: Web3) => {
182
- const contract = wstETHContract(web3, NetworkNumber.Eth);
183
- const calls = wstEthAmounts.map((amount) => ({
184
- target: contract.options.address,
185
- abiItem: contract.options.jsonInterface.find((i) => i.name === 'getStETHByWstETH'),
186
- params: [amount],
187
- }));
188
- const stEthAmounts = await multicall(calls, web3);
189
- return stEthAmounts.map((arr) => arr[0]);
190
- };
1
+ import Dec from 'decimal.js';
2
+ import Web3 from 'web3';
3
+ import { StakeWiseSDK, Network } from '@stakewise/v3-sdk';
4
+ import {
5
+ CbEthContract, LidoContract, PotContract, REthContract, wstETHContract,
6
+ } from '../contracts';
7
+ import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
8
+ import { ContractEventLog } from '../types/contracts/generated/types';
9
+ import { BLOCKS_IN_A_YEAR, SECONDS_PER_YEAR, AVG_BLOCK_TIME } from '../constants';
10
+ import { multicall } from '../multicall';
11
+
12
+
13
+ export const getStETHApr = async (web3: Web3, fromBlock = 17900000, blockNumber: 'latest' | number = 'latest') => {
14
+ try {
15
+ const tokenRebasedEvents: ContractEventLog<{ [key: string]: any }>[] = await LidoContract(web3, NetworkNumber.Eth).getPastEvents('TokenRebased', { fromBlock, toBlock: blockNumber });
16
+ tokenRebasedEvents.sort((a, b) => b.blockNumber - a.blockNumber); // sort from highest to lowest block number
17
+ const movingAverage = 7;
18
+ const aprs = tokenRebasedEvents.slice(0, movingAverage).map(({ returnValues: event }) => {
19
+ const preShareRate = new Dec(event.preTotalEther.toString()).div(event.preTotalShares.toString());
20
+ const postShareRate = new Dec(event.postTotalEther.toString()).div(event.postTotalShares.toString());
21
+ return new Dec(SECONDS_PER_YEAR).mul(new Dec(postShareRate).sub(preShareRate).div(preShareRate))
22
+ .div(event.timeElapsed.toString()).mul(100)
23
+ .toNumber();
24
+ });
25
+ return aprs.reduce((a, b) => a + b, 0) / aprs.length;
26
+ } catch (e) {
27
+ console.warn('Failed to fetch stETH APY from events, falling back to Lido API');
28
+ const res = await fetch('https://eth-api.lido.fi/v1/protocol/steth/apr/sma');
29
+ const data = await res.json();
30
+ return data.data.smaApr;
31
+ }
32
+ };
33
+
34
+
35
+ export const getCbETHApr = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
36
+ let currentBlock = blockNumber;
37
+ if (blockNumber === 'latest') currentBlock = await web3.eth.getBlockNumber();
38
+ const blockDiff = 6 * 24 * 60 * 60 / AVG_BLOCK_TIME;
39
+ const pastBlock = (currentBlock as number) - blockDiff;
40
+ const contract = CbEthContract(web3, NetworkNumber.Eth);
41
+ const [pastRate, currentRate] = await Promise.all([
42
+ contract.methods.exchangeRate().call({}, pastBlock),
43
+ contract.methods.exchangeRate().call({}, currentBlock),
44
+ ]);
45
+ const apr = new Dec(currentRate.toString()).sub(pastRate.toString()).div(currentRate.toString())
46
+ .mul(BLOCKS_IN_A_YEAR / blockDiff)
47
+ .mul(100)
48
+ .toString();
49
+ return apr;
50
+ };
51
+
52
+
53
+ export const getREthApr = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
54
+ let currentBlock = blockNumber;
55
+ if (blockNumber === 'latest') currentBlock = await web3.eth.getBlockNumber();
56
+ const blockDiff = 8 * 24 * 60 * 60 / AVG_BLOCK_TIME;
57
+ const pastBlock = (currentBlock as number) - blockDiff;
58
+ const contract = REthContract(web3, NetworkNumber.Eth);
59
+ const [pastRate, currentRate] = await Promise.all([
60
+ contract.methods.getExchangeRate().call({}, pastBlock),
61
+ contract.methods.getExchangeRate().call({}, currentBlock),
62
+ ]);
63
+ const apr = new Dec(currentRate.toString()).sub(pastRate.toString()).div(currentRate.toString())
64
+ .mul(BLOCKS_IN_A_YEAR / blockDiff)
65
+ .mul(100)
66
+ .toString();
67
+
68
+ return apr;
69
+ };
70
+
71
+ export const getDsrApy = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
72
+ const potContract = PotContract(web3, NetworkNumber.Eth);
73
+ return new Dec(await potContract.methods.dsr().call())
74
+ .div(new Dec(1e27))
75
+ .pow(SECONDS_PER_YEAR)
76
+ .sub(1)
77
+ .mul(100)
78
+ .toString();
79
+ };
80
+
81
+ export const getSUSDeApy = async () => {
82
+ const res = await fetch('https://app.defisaver.com/api/staking/apy?asset=sUSDe');
83
+ const data = await res.json();
84
+ return data.apy;
85
+ };
86
+
87
+ const getWeEthApr = async () => {
88
+ const res = await fetch('https://www.etherfi.bid/api/etherfi/apr');
89
+ const data = await res.json();
90
+ const total = (data.latest_aprs as string[]).reduce((acc, apr) => new Dec(acc).add(apr).toString());
91
+ return new Dec(total).div(data.latest_aprs.length).div(100).toString();
92
+ };
93
+
94
+ const getOsETHApy = async () => {
95
+ const sdk = new StakeWiseSDK({ network: Network.Mainnet });
96
+ const apy = await sdk.osToken.getAPY();
97
+ return apy;
98
+ };
99
+
100
+ export const STAKING_ASSETS = ['cbETH', 'wstETH', 'cbETH', 'rETH', 'sDAI', 'weETH', 'sUSDe', 'osETH'];
101
+
102
+ export const getStakingApy = (asset: string, web3: Web3, blockNumber: 'latest' | number = 'latest', fromBlock: number | undefined = undefined) => {
103
+ try {
104
+ if (asset === 'stETH' || asset === 'wstETH') return getStETHApr(web3, fromBlock, blockNumber);
105
+ if (asset === 'cbETH') return getCbETHApr(web3, blockNumber);
106
+ if (asset === 'rETH') return getREthApr(web3, blockNumber);
107
+ if (asset === 'sDAI') return getDsrApy(web3);
108
+ if (asset === 'sUSDe') return getSUSDeApy();
109
+ if (asset === 'weETH') return getWeEthApr();
110
+ if (asset === 'osETH') return getOsETHApy();
111
+ } catch (e) {
112
+ console.error(`Failed to fetch APY for ${asset}`);
113
+ return '0';
114
+ }
115
+ };
116
+
117
+ export const calculateInterestEarned = (principal: string, interest: string, type: string, apy = false) => {
118
+ let interval = 1;
119
+
120
+ if (+interest === 0) return 0;
121
+
122
+ if (type === 'month') interval = 1 / 12;
123
+ if (type === 'week') interval = 1 / 52.1429;
124
+
125
+ if (apy) {
126
+ // interest rate already compounded
127
+ return (+principal * (1 + (+interest / 100 * interval))) - +principal;
128
+ }
129
+
130
+ return (+principal * (((1 + (+interest / 100) / BLOCKS_IN_A_YEAR)) ** (BLOCKS_IN_A_YEAR * interval))) - +principal; // eslint-disable-line
131
+ };
132
+
133
+ export const calculateNetApy = (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho = false) => {
134
+ const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
135
+ const acc = { ..._acc };
136
+ const assetData = assetsData[usedAsset.symbol];
137
+
138
+ if (usedAsset.isSupplied) {
139
+ const amount = usedAsset.suppliedUsd;
140
+ acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
141
+ const rate = isMorpho
142
+ ? usedAsset.supplyRate === '0' ? assetData.supplyRateP2P : usedAsset.supplyRate
143
+ : assetData.supplyRate;
144
+ const supplyInterest = calculateInterestEarned(amount, rate as string, 'year', true);
145
+ acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
146
+ if (assetData.incentiveSupplyApy) {
147
+ // take COMP/AAVE yield into account
148
+ const incentiveInterest = calculateInterestEarned(amount, assetData.incentiveSupplyApy, 'year', true);
149
+ acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
150
+ }
151
+ }
152
+
153
+ if (usedAsset.isBorrowed) {
154
+ const amount = usedAsset.borrowedUsd;
155
+ acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
156
+ const rate = isMorpho
157
+ ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
158
+ : usedAsset.symbol === 'GHO'
159
+ ? usedAsset.discountedBorrowRate
160
+ : (usedAsset?.interestMode === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
161
+ const borrowInterest = calculateInterestEarned(amount, rate as string, 'year', true);
162
+ acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
163
+ if (assetData.incentiveBorrowApy) {
164
+ // take COMP/AAVE yield into account
165
+ const incentiveInterest = calculateInterestEarned(amount, assetData.incentiveBorrowApy, 'year', true);
166
+ acc.incentiveUsd = new Dec(acc.incentiveUsd).add(incentiveInterest).toString();
167
+ }
168
+ }
169
+
170
+ return acc;
171
+ }, {
172
+ borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
173
+ });
174
+
175
+ const {
176
+ borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd,
177
+ } = sumValues;
178
+
179
+ const totalInterestUsd = new Dec(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
180
+ const balance = new Dec(suppliedUsd).sub(borrowedUsd);
181
+ const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
182
+
183
+ return { netApy, totalInterestUsd, incentiveUsd };
184
+ };
185
+
186
+ export const getWstETHByStETH = async (stETHAmount: string | number, web3: Web3) => wstETHContract(web3, NetworkNumber.Eth).methods.getWstETHByStETH(stETHAmount).call();
187
+
188
+ export const getStETHByWstETH = async (wstETHAmount: string | number, web3: Web3) => wstETHContract(web3, NetworkNumber.Eth).methods.getStETHByWstETH(wstETHAmount).call();
189
+
190
+ export const getStETHByWstETHMultiple = async (wstEthAmounts: string[] | number[], web3: Web3) => {
191
+ const contract = wstETHContract(web3, NetworkNumber.Eth);
192
+ const calls = wstEthAmounts.map((amount) => ({
193
+ target: contract.options.address,
194
+ abiItem: contract.options.jsonInterface.find((i) => i.name === 'getStETHByWstETH'),
195
+ params: [amount],
196
+ }));
197
+ const stEthAmounts = await multicall(calls, web3);
198
+ return stEthAmounts.map((arr) => arr[0]);
199
+ };