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