-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInstanceTest.t.sol.jinja
More file actions
159 lines (144 loc) · 7.14 KB
/
InstanceTest.t.sol.jinja
File metadata and controls
159 lines (144 loc) · 7.14 KB
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
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.22;
import { {{ name.capitalized }}HyperdriveCoreDeployer } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}HyperdriveCoreDeployer.sol";
import { {{ name.capitalized }}HyperdriveDeployerCoordinator } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}HyperdriveDeployerCoordinator.sol";
import { {{ name.capitalized }}Target0Deployer } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}Target0Deployer.sol";
import { {{ name.capitalized }}Target1Deployer } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}Target1Deployer.sol";
import { {{ name.capitalized }}Target2Deployer } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}Target2Deployer.sol";
import { {{ name.capitalized }}Target3Deployer } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}Target3Deployer.sol";
import { {{ name.capitalized }}Target4Deployer } from "../../../contracts/src/deployers/{{ name.lowercase }}/{{ name.capitalized }}Target4Deployer.sol";
import { {{ name.capitalized }}Conversions } from "../../../contracts/src/instances/{{ name.lowercase }}/{{ name.capitalized }}Conversions.sol";
import { IERC20 } from "../../../contracts/src/interfaces/IERC20.sol";
import { I{{ name.capitalized }} } from "../../../contracts/src/interfaces/I{{ name.capitalized }}.sol";
import { IHyperdrive } from "../../../contracts/src/interfaces/IHyperdrive.sol";
import { ERC20ForwarderFactory } from "../../../contracts/src/token/ERC20ForwarderFactory.sol";
import { FixedPointMath } from "../../../contracts/src/libraries/FixedPointMath.sol";
import { ERC20ForwarderFactory } from "../../../contracts/src/token/ERC20ForwarderFactory.sol";
import { InstanceTest } from "../../utils/InstanceTest.sol";
import { HyperdriveUtils } from "../../utils/HyperdriveUtils.sol";
import { Lib } from "../../utils/Lib.sol";
abstract contract {{ name.capitalized }}InstanceTest is InstanceTest {
using FixedPointMath for uint256;
using HyperdriveUtils for IHyperdrive;
using Lib for *;
/// Overrides ///
/// @dev Gets the extra data used to deploy Hyperdrive instances.
/// @return The extra data.
function getExtraData() internal pure override returns (bytes memory) {
return new bytes(0);
}
/// @dev Converts base amount to the equivalent about in shares.
/// @param baseAmount The base amount.
/// @return The converted share amount.
function convertToShares(
uint256 baseAmount
) internal view override returns (uint256) {
// FIXME: add the correct conversion
return
{{ name.capitalized }}Conversions.convertToShares(
config.vaultSharesToken,
baseAmount
);
}
/// @dev Converts share amount to the equivalent amount in base.
/// @param shareAmount The share amount.
/// @return The converted base amount.
function convertToBase(
uint256 shareAmount
) internal view override returns (uint256) {
// FIXME: add the correct conversion
return
{{ name.capitalized }}Conversions.convertToBase(
config.vaultSharesToken,
shareAmount
);
}
/// @dev Deploys the rsETH Linea deployer coordinator contract.
/// @param _factory The address of the Hyperdrive factory.
/// @return The coordinator address.
function deployCoordinator(
address _factory
) internal override returns (address) {
vm.startPrank(alice);
return
address(
new {{ name.capitalized }}HyperdriveDeployerCoordinator(
string.concat(config.name, "DeployerCoordinator"),
_factory,
address(new {{ name.capitalized }}HyperdriveCoreDeployer()),
address(new {{ name.capitalized }}Target0Deployer()),
address(new {{ name.capitalized }}Target1Deployer()),
address(new {{ name.capitalized }}Target2Deployer()),
address(new {{ name.capitalized }}Target3Deployer()),
address(new {{ name.capitalized }}Target4Deployer())
)
);
}
/// @dev Fetches the total supply of the base and share tokens.
/// @return The total supply of base.
/// @return The total supply of vault shares.
function getSupply()
internal
view
virtual
override
returns (uint256, uint256)
{
return (
I{{ name.capitalized }}(address(config.vaultSharesToken)).totalAssets(),
I{{ name.capitalized }}(address(config.vaultSharesToken)).totalSupply()
);
}
/// @dev Fetches the token balance information of an account.
/// @param account The account to query.
/// @return The balance of base.
/// @return The balance of vault shares.
function getTokenBalances(
address account
) internal view override returns (uint256, uint256) {
return (
config.baseToken.balanceOf(account),
config.vaultSharesToken.balanceOf(account)
);
}
/// Getters ///
/// @dev Test for the additional getters. In the case of the {{ name.capitalized }}Hyperdrive
/// instance, there are no additional getter and we just test the
/// `totalShares` implementation.
function test_getters() external view {
// FIXME: add t.ests for additional getters here
(, uint256 totalShares) = getTokenBalances(address(hyperdrive));
assertEq(hyperdrive.totalShares(), totalShares);
}
/// Price Per Share ///
/// @dev Fuzz test that verifies that the vault share price is the price
/// that dictates the conversion between base and shares.
/// @param basePaid the fuzz parameter for the base paid.
function test__pricePerVaultShare(uint256 basePaid) external virtual {
// FIXME: add test for the price per vaul share here. {{ name.capitalized }} example
// is provided.
// Ensure that the share price is the expected value.
(uint256 totalBase, uint256 totalSupply) = getSupply();
uint256 vaultSharePrice = hyperdrive.getPoolInfo().vaultSharePrice;
assertApproxEqAbs(vaultSharePrice, totalBase.divDown(totalSupply), 1);
// Ensure that the share price accurately predicts the amount of shares
// that will be minted for depositing a given amount of shares. This will
// be an approximation.
basePaid = basePaid.normalizeToRange(
2 * hyperdrive.getPoolConfig().minimumTransactionAmount,
hyperdrive.calculateMaxLong()
);
(, uint256 hyperdriveSharesBefore) = getTokenBalances(
address(hyperdrive)
);
openLong(bob, basePaid);
(, uint256 hyperdriveSharesAfter) = getTokenBalances(
address(hyperdrive)
);
assertApproxEqAbs(
hyperdriveSharesAfter,
hyperdriveSharesBefore + basePaid.divDown(vaultSharePrice),
config.shareTolerance
);
}
}