generated from bgd-labs/bgd-forge-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
GetExchangeRatesTest.t.sol
283 lines (235 loc) · 9.93 KB
/
GetExchangeRatesTest.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import 'forge-std/Test.sol';
import {IERC4626} from 'forge-std/interfaces/IERC4626.sol';
import {AaveV3EthereumAssets} from 'aave-address-book/AaveV3Ethereum.sol';
import {AaveV2EthereumAssets} from 'aave-address-book/AaveV2Ethereum.sol';
import {AaveV3AvalancheAssets} from 'aave-address-book/AaveV3Avalanche.sol';
import {AaveV3GnosisAssets} from 'aave-address-book/AaveV3Gnosis.sol';
import {MiscEthereum} from 'aave-address-book/MiscEthereum.sol';
import {MiscArbitrum} from 'aave-address-book/MiscArbitrum.sol';
import {MiscBase} from 'aave-address-book/MiscBase.sol';
import {MiscGnosis} from 'aave-address-book/MiscGnosis.sol';
import {MiscOptimism} from 'aave-address-book/MiscOptimism.sol';
import {MiscPolygon} from 'aave-address-book/MiscPolygon.sol';
import {ICbEthRateProvider} from 'cl-synchronicity-price-adapter/interfaces/ICbEthRateProvider.sol';
import {IrETH} from 'cl-synchronicity-price-adapter/interfaces/IrETH.sol';
import {IPot} from 'cl-synchronicity-price-adapter/interfaces/IPot.sol';
import {IStETH} from 'cl-synchronicity-price-adapter/interfaces/IStETH.sol';
import {IMaticRateProvider} from 'cl-synchronicity-price-adapter/interfaces/IMaticRateProvider.sol';
import {IERC4626} from 'forge-std/interfaces/IERC4626.sol';
import {IChainlinkAggregator} from 'cl-synchronicity-price-adapter/interfaces/IChainlinkAggregator.sol';
import {ISAvax} from '../../src/interfaces/ISAvax.sol';
import {IStEUR} from '../../src/interfaces/IStEUR.sol';
import {IWeEth} from '../../src/interfaces/IWeEth.sol';
import {IOsTokenVaultController} from '../../src/interfaces/IOsTokenVaultController.sol';
import {IEthX} from '../../src/interfaces/IEthX.sol';
import {IEzETHRestakeManager, IEzEthToken} from '../../src/interfaces/IEzETH.sol';
import {IRsETH} from '../../src/interfaces/IRsETH.sol';
import {IBNBx} from '../../src/interfaces/IBNBx.sol';
import {CapAdaptersCodeEthereum} from '../../scripts/DeployEthereum.s.sol';
import {CapAdaptersCodeArbitrum} from '../../scripts/DeployArbitrumWeEth.s.sol';
import {CapAdaptersCodeBase} from '../../scripts/DeployBase.s.sol';
import {CapAdaptersCodeScroll} from '../../scripts/DeployScroll.s.sol';
import {CapAdaptersCodeBNB} from '../../scripts/DeployBnb.s.sol';
import {CapAdaptersCodeZkSync} from '../../scripts/DeployZkSync.s.sol';
contract ExchangeRatesEth is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('mainnet'), 21010101); // Oct-20-2024
}
function test_getExchangeRate() public view {
uint256 cbEthRate = ICbEthRateProvider(AaveV3EthereumAssets.cbETH_UNDERLYING).exchangeRate();
uint256 rEthRate = IrETH(AaveV3EthereumAssets.rETH_UNDERLYING).getExchangeRate();
uint256 sDaiRate = IPot(MiscEthereum.sDAI_POT).chi();
uint256 wstEthRate = IStETH(AaveV2EthereumAssets.stETH_UNDERLYING).getPooledEthByShares(
10 ** 18
);
uint256 stEurRate = IStEUR(MiscEthereum.stEUR).convertToAssets(10 ** 18);
uint256 weEthRate = IWeEth(CapAdaptersCodeEthereum.weETH).getRate();
uint256 osEthRate = IOsTokenVaultController(CapAdaptersCodeEthereum.osETH_VAULT_CONTROLLER)
.convertToAssets(10 ** 18);
uint256 ethXRate = IEthX(CapAdaptersCodeEthereum.STADER_STAKE_POOLS_MANAGER).getExchangeRate();
uint256 sUSDeRate = IERC4626(CapAdaptersCodeEthereum.sUSDe).convertToAssets(10 ** 18);
uint256 sUSDSRate = IERC4626(CapAdaptersCodeEthereum.sUSDS).convertToAssets(10 ** 18);
(, , uint256 totalTVL) = IEzETHRestakeManager(CapAdaptersCodeEthereum.ezETH_RESTAKE_MANAGER)
.calculateTVLs();
uint256 ezETHRate = ((totalTVL * 1 ether) /
IEzETHRestakeManager(CapAdaptersCodeEthereum.ezETH_RESTAKE_MANAGER).ezETH().totalSupply());
uint256 rsETHRate = IRsETH(CapAdaptersCodeEthereum.rsETH_LRT_ORACLE).rsETHPrice();
console.log('cbEthRate', cbEthRate);
console.log('rEthRate', rEthRate);
console.log('sDaiRate', sDaiRate);
console.log('wstEthRate', wstEthRate);
console.log('stEurRate', stEurRate);
console.log('weEthRate', weEthRate);
console.log('osEthRate', osEthRate);
console.log('ethXRate', ethXRate);
console.log('sUSDe', sUSDeRate);
console.log('sUSDS', sUSDSRate);
console.log('ezETHRate', ezETHRate);
console.log('rsETHRate', rsETHRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesArbitrum is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('arbitrum'), 194797824); // 27th of March
}
function test_getExchangeRate() public view {
uint256 rEthRate = uint256(
IChainlinkAggregator(MiscArbitrum.rETH_ETH_AGGREGATOR).latestAnswer()
);
uint256 wstEthRate = uint256(
IChainlinkAggregator(MiscArbitrum.wstETH_stETH_AGGREGATOR).latestAnswer()
);
uint256 weEthRate = uint256(
IChainlinkAggregator(CapAdaptersCodeArbitrum.weETH_eETH_AGGREGATOR).latestAnswer()
);
console.log('Arbitrum');
console.log('rEthRate', rEthRate);
console.log('wstEthRate', wstEthRate);
console.log('weEthRate', weEthRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesAvax is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('avalanche'), 41384761); // 7th of February
}
function test_getExchangeRate() public view {
uint256 sAvaxRate = ISAvax(AaveV3AvalancheAssets.sAVAX_UNDERLYING).getPooledAvaxByShares(
10 ** 18
);
console.log('Avalanche');
console.log('sAvaxRate', sAvaxRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesBase is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('base'), 14415412); // may 13
}
function test_getExchangeRate() public view {
uint256 cbEthRate = uint256(IChainlinkAggregator(MiscBase.cbETH_ETH_AGGREGATOR).latestAnswer());
uint256 wstEthRate = uint256(
IChainlinkAggregator(MiscBase.wstETH_stETH_AGGREGATOR).latestAnswer()
);
uint256 weEthRate = uint256(
IChainlinkAggregator(CapAdaptersCodeBase.weETH_eETH_AGGREGATOR).latestAnswer()
);
console.log('Base');
console.log('cbEthRate', cbEthRate);
console.log('wstEthRate', wstEthRate);
console.log('weEthRate', weEthRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesGnosis is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('gnosis'), 36600000); // Oct-20-2024
}
function test_getExchangeRate() public view {
uint256 sDaiRate = IERC4626(AaveV3GnosisAssets.sDAI_UNDERLYING).convertToAssets(10 ** 18);
uint256 wstEthRate = uint256(
IChainlinkAggregator(MiscGnosis.wstETH_stETH_AGGREGATOR).latestAnswer()
);
console.log('Gnosis');
console.log('sDaiRate', sDaiRate);
console.log('wstEthRate', wstEthRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesOptimism is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('optimism'), 116196954); // 15th of February
}
function test_getExchangeRate() public view {
uint256 rEthRate = uint256(
IChainlinkAggregator(MiscOptimism.rETH_ETH_AGGREGATOR).latestAnswer()
);
uint256 wstEthRate = uint256(
IChainlinkAggregator(MiscOptimism.wstETH_stETH_AGGREGATOR).latestAnswer()
);
console.log('Optimism');
console.log('rEthRate', rEthRate);
console.log('wstEthRate', wstEthRate);
console.log(block.timestamp);
}
}
contract ExchangeRates7Polygon is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('polygon'), 53527296); // 15th of February days ago
}
function test_getExchangeRate() public view {
uint256 wstEthRate = uint256(
IChainlinkAggregator(MiscPolygon.wstETH_stETH_AGGREGATOR).latestAnswer()
);
console.log('Polygon 7');
console.log('wstEthRate', wstEthRate);
console.log(block.timestamp);
}
}
contract ExchangeRates14Polygon is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('polygon'), 53252303); // 8th of February days ago
}
function test_getExchangeRate() public view {
uint256 stMaticRate = IMaticRateProvider(MiscPolygon.stMATIC_RATE_PROVIDER).getRate();
uint256 maticXRate = IMaticRateProvider(MiscPolygon.MaticX_RATE_PROVIDER).getRate();
console.log('Polygon 14');
console.log('stMaticRate', stMaticRate);
console.log('maticXRate', maticXRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesScroll is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('scroll'), 7740000); // July 24th
}
function test_getExchangeRate() public view {
uint256 wstEthRate = uint256(
IChainlinkAggregator(0xE61Da4C909F7d86797a0D06Db63c34f76c9bCBDC).latestAnswer()
);
uint256 weEthRate = uint256(
IChainlinkAggregator(CapAdaptersCodeScroll.weETH_eETH_AGGREGATOR).latestAnswer()
);
console.log('Scroll');
console.log('wstEthRate', wstEthRate);
console.log('weEthRate', weEthRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesBNB is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('bnb'), 42938803); // Oct-08-2024
}
function test_getExchangeRate() public view {
uint256 wstEthRate = uint256(
IChainlinkAggregator(CapAdaptersCodeBNB.wstETH_stETH_AGGREGATOR).latestAnswer()
);
uint256 bnbxRate = uint256(
IBNBx(CapAdaptersCodeBNB.BNBx_STAKE_MANAGER_V2).convertBnbXToBnb(10 ** 18)
);
console.log('BNB');
console.log('wstEthRate', wstEthRate);
console.log('bnbxRate', bnbxRate);
console.log(block.timestamp);
}
}
contract ExchangeRatesZKSync is Test {
function setUp() public {
vm.createSelectFork(vm.rpcUrl('zksync'), 48189193); // Nov-05-2024
}
function test_getExchangeRate() public view {
uint256 weETHRate = uint256(
IChainlinkAggregator(CapAdaptersCodeZkSync.weETH_eETH_AGGREGATOR).latestAnswer()
);
uint256 sUSDeRate = uint256(
IChainlinkAggregator(CapAdaptersCodeZkSync.sUSDe_USDe_AGGREGATOR).latestAnswer()
);
console.log('ZkSync');
console.log('weETHRate', weETHRate);
console.log('sUSDeRate', sUSDeRate);
console.log(block.timestamp);
}
}