@defisaver/positions-sdk 0.0.70 → 0.0.71

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