Skip to content

Commit aecfda8

Browse files
checkpoint: organization, clean up TODO's
Signed-off-by: Elliot <[email protected]>
1 parent 50648e6 commit aecfda8

File tree

13 files changed

+212
-150
lines changed

13 files changed

+212
-150
lines changed

src/exercises/00/SIP00.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {Addresses} from
77
"@forge-proposal-simulator/addresses/Addresses.sol";
88

99
import {Vault} from "src/exercises/00/Vault00.sol";
10-
import {MockToken} from "@mocks/MockToken.sol";
1110
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";
1211

1312
/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/00/SIP00.sol:SIP00 -vvvv
@@ -50,20 +49,20 @@ contract SIP00 is GovernorBravoProposal {
5049
}
5150

5251
function deploy() public override {
53-
if (!addresses.isAddressSet("V1_VAULT")) {
52+
if (!addresses.isAddressSet("V0_VAULT")) {
5453
address[] memory tokens = new address[](3);
5554
tokens[0] = addresses.getAddress("USDC");
5655
tokens[1] = addresses.getAddress("DAI");
5756
tokens[2] = addresses.getAddress("USDT");
5857

5958
Vault vault = new Vault(tokens);
6059

61-
addresses.addAddress("V1_VAULT", address(vault), true);
60+
addresses.addAddress("V0_VAULT", address(vault), true);
6261
}
6362
}
6463

6564
function validate() public view override {
66-
Vault vault = Vault(addresses.getAddress("V1_VAULT"));
65+
Vault vault = Vault(addresses.getAddress("V0_VAULT"));
6766

6867
assertEq(
6968
vault.authorizedToken(addresses.getAddress("USDC")),

src/exercises/01/SIP01.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {Addresses} from
77
"@forge-proposal-simulator/addresses/Addresses.sol";
88

99
import {Vault} from "src/exercises/01/Vault01.sol";
10-
import {MockToken} from "@mocks/MockToken.sol";
1110
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";
1211

1312
/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/01/SIP01.sol:SIP01 -vvvv

src/exercises/02/SIP02.sol

Lines changed: 7 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import {GovernorBravoProposal} from
55
"@forge-proposal-simulator/src/proposals/GovernorBravoProposal.sol";
66
import {Addresses} from
77
"@forge-proposal-simulator/addresses/Addresses.sol";
8-
9-
import {Vault03} from "src/exercises/03/Vault.sol";
10-
import {Vault04} from "src/exercises/04/Vault04.sol";
11-
import {MockToken} from "@mocks/MockToken.sol";
12-
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";
138
import {
149
ProxyAdmin,
1510
TransparentUpgradeableProxy,
@@ -20,6 +15,9 @@ import {ERC1967Utils} from
2015
"@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
2116
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
2217

18+
import {Vault} from "src/exercises/02/Vault02.sol";
19+
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";
20+
2321
/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/02/SIP02.sol:SIP02 -vvvv
2422
contract SIP02 is GovernorBravoProposal {
2523
using ForkSelector for uint256;
@@ -60,64 +58,21 @@ contract SIP02 is GovernorBravoProposal {
6058
}
6159

6260
function deploy() public override {
63-
address vaultProxy;
64-
if (!addresses.isAddressSet("V3_VAULT_IMPLEMENTATION")) {
65-
address vaultImpl = address(new Vault03());
66-
addresses.addAddress(
67-
"V3_VAULT_IMPLEMENTATION", vaultImpl, true
68-
);
69-
61+
if (!addresses.isAddressSet("V2_VAULT")) {
7062
address[] memory tokens = new address[](3);
7163
tokens[0] = addresses.getAddress("USDC");
7264
tokens[1] = addresses.getAddress("DAI");
7365
tokens[2] = addresses.getAddress("USDT");
7466

7567
address owner = addresses.getAddress("DEPLOYER_EOA");
7668

77-
// Generate calldata for initialize function of vault
78-
bytes memory data = abi.encodeWithSignature(
79-
"initialize(address[],address)", tokens, owner
80-
);
81-
82-
vaultProxy = address(
83-
new TransparentUpgradeableProxy(
84-
vaultImpl, owner, data
85-
)
86-
);
87-
addresses.addAddress("VAULT_PROXY", vaultProxy, true);
88-
}
89-
90-
if (!addresses.isAddressSet("V4_VAULT_IMPLEMENTATION")) {
91-
address vaultImpl = address(new Vault04());
92-
addresses.addAddress(
93-
"V4_VAULT_IMPLEMENTATION", vaultImpl, true
94-
);
69+
address vaultImpl = address(new Vault(tokens, owner));
70+
addresses.addAddress("V2_VAULT", vaultImpl, true);
9571
}
9672
}
9773

98-
function build()
99-
public
100-
override
101-
buildModifier(addresses.getAddress("COMPOUND_TIMELOCK_BRAVO"))
102-
{
103-
address vaultProxy = addresses.getAddress("VAULT_PROXY");
104-
bytes32 adminSlot =
105-
vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT);
106-
107-
address proxyAdmin = address(uint160(uint256(adminSlot)));
108-
109-
// upgrade to new implementation
110-
ProxyAdmin(proxyAdmin).upgradeAndCall(
111-
ITransparentUpgradeableProxy(vaultProxy),
112-
addresses.getAddress("V4_VAULT_IMPLEMENTATION"),
113-
""
114-
);
115-
116-
Vault04(vaultProxy).setMaxSupply(1_000_000e18);
117-
}
118-
11974
function validate() public view override {
120-
Vault04 vault = Vault04(addresses.getAddress("VAULT_PROXY"));
75+
Vault vault = Vault(addresses.getAddress("V2_VAULT"));
12176

12277
assertEq(
12378
vault.authorizedToken(addresses.getAddress("USDC")),
@@ -134,16 +89,5 @@ contract SIP02 is GovernorBravoProposal {
13489
true,
13590
"USDT should be authorized"
13691
);
137-
138-
assertEq(
139-
vault.maxSupply(),
140-
1_000_000e18,
141-
"Max supply should be 1,000,000 USDC"
142-
);
143-
assertEq(
144-
vault.totalSupplied(),
145-
1_000e18,
146-
"Total supplied should be 1000 USDC"
147-
);
14892
}
14993
}

src/exercises/03/REQUIREMENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Overview
2+
3+
Make the contract upgradeable while preserving all previous functionality. Users can migrate to this contract via opt-in by removing their liquidity from the previous contract and depositing here.

src/exercises/03/SIP04.sol renamed to src/exercises/03/SIP03.sol

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import {GovernorBravoProposal} from
66
import {Addresses} from
77
"@forge-proposal-simulator/addresses/Addresses.sol";
88

9-
import {Vault04} from "src/exercises/04/Vault04.sol";
10-
import {MockToken} from "@mocks/MockToken.sol";
11-
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";
129
import {
1310
ProxyAdmin,
1411
TransparentUpgradeableProxy,
@@ -19,8 +16,11 @@ import {ERC1967Utils} from
1916
"@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
2017
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
2118

22-
/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/SIP04.sol:SIP04 -vvvv
23-
contract SIP04 is GovernorBravoProposal {
19+
import {Vault} from "src/exercises/03/Vault03.sol";
20+
import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol";
21+
22+
/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/03/SIP03.sol:SIP03 -vvvv
23+
contract SIP03 is GovernorBravoProposal {
2424
using ForkSelector for uint256;
2525

2626
constructor() {
@@ -38,7 +38,7 @@ contract SIP04 is GovernorBravoProposal {
3838
}
3939

4040
function name() public pure override returns (string memory) {
41-
return "SIP-04 Upgrade";
41+
return "SIP-03 Upgrade";
4242
}
4343

4444
function description()
@@ -59,45 +59,45 @@ contract SIP04 is GovernorBravoProposal {
5959
}
6060

6161
function deploy() public override {
62-
if (!addresses.isAddressSet("PROXY_ADMIN")) {
63-
ProxyAdmin proxyAdmin = new ProxyAdmin();
64-
proxyAdmin.transferOwnership(
65-
addresses.getAddress("COMPOUND_TIMELOCK_BRAVO")
66-
);
67-
68-
addresses.addAddress("PROXY_ADMIN", address(proxyAdmin), true);
69-
}
70-
7162
address vaultProxy;
72-
if (!addresses.isAddressSet("V4_VAULT_IMPLEMENTATION")) {
73-
address vaultImpl = address(new Vault04());
74-
addresses.addAddress(
75-
"V4_VAULT_IMPLEMENTATION", vaultImpl, true
76-
);
63+
if (!addresses.isAddressSet("V3_VAULT_IMPL")) {
64+
address vaultImpl = address(new Vault());
65+
addresses.addAddress("V3_VAULT_IMPL", vaultImpl, true);
7766

7867
address[] memory tokens = new address[](3);
7968
tokens[0] = addresses.getAddress("USDC");
8069
tokens[1] = addresses.getAddress("DAI");
8170
tokens[2] = addresses.getAddress("USDT");
8271

83-
address owner = addresses.getAddress("COMPOUND_TIMELOCK_BRAVO");
72+
address owner =
73+
addresses.getAddress("COMPOUND_TIMELOCK_BRAVO");
8474

8575
// Generate calldata for initialize function of vault
8676
bytes memory data = abi.encodeWithSignature(
8777
"initialize(address[],address)", tokens, owner
8878
);
8979

80+
/// proxy admin contract is created by the Transparent Upgradeable Proxy
9081
vaultProxy = address(
9182
new TransparentUpgradeableProxy(
9283
vaultImpl, owner, data
9384
)
9485
);
9586
addresses.addAddress("VAULT_PROXY", vaultProxy, true);
87+
88+
address proxyAdmin = address(
89+
uint160(
90+
uint256(
91+
vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT)
92+
)
93+
)
94+
);
95+
addresses.addAddress("PROXY_ADMIN", proxyAdmin, true);
9696
}
9797
}
9898

9999
function validate() public view override {
100-
Vault04 vault = Vault04(addresses.getAddress("VAULT_PROXY"));
100+
Vault vault = Vault(addresses.getAddress("VAULT_PROXY"));
101101

102102
assertEq(
103103
vault.authorizedToken(addresses.getAddress("USDC")),
@@ -120,5 +120,11 @@ contract SIP04 is GovernorBravoProposal {
120120
vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT);
121121

122122
address proxyAdmin = address(uint160(uint256(adminSlot)));
123+
124+
assertEq(
125+
ProxyAdmin(proxyAdmin).owner(),
126+
addresses.getAddress("COMPOUND_TIMELOCK_BRAVO"),
127+
"owner not set"
128+
);
123129
}
124130
}

src/exercises/04/Vault05.sol renamed to src/exercises/03/Vault03.sol

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@ import {IERC20Metadata} from
44
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
55
import {SafeERC20} from
66
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7-
import {OwnableUpgradeable} from
8-
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
97
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
108

11-
import {VaultStoragePausable} from
12-
"src/exercises/storage/VaultStoragePausable.sol";
9+
import {VaultStorageOwnable} from
10+
"src/exercises/storage/VaultStorageOwnable.sol";
1311

1412
/// @notice Add maxsupply to the vault and update getNormalizedAmount logic
15-
/// TODO make pauseable
16-
/// make totalSupplied offsets the same
17-
/// inherit pausable to mess up the storage slot offsets
18-
/// add governance proposal that deploys and ugprades the existing vault from
19-
/// proposal 03
2013
/// deploy Vault 03 to mainnet
2114
/// add integration tests
22-
contract Vault05 is VaultStoragePausable {
15+
contract Vault is VaultStorageOwnable {
2316
using SafeERC20 for IERC20;
2417

2518
/// @notice Deposit event
@@ -116,10 +109,7 @@ contract Vault05 is VaultStoragePausable {
116109
/// @notice Deposit tokens into the vault
117110
/// @param token The token to deposit, only authorized tokens allowed
118111
/// @param amount The amount to deposit
119-
function deposit(address token, uint256 amount)
120-
external
121-
whenNotPaused
122-
{
112+
function deposit(address token, uint256 amount) external {
123113
require(authorizedToken[token], "Vault: token not authorized");
124114

125115
uint256 normalizedAmount = getNormalizedAmount(token, amount);

src/exercises/03/Vault04Storage.sol

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/exercises/04/REQUIREMENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Overview
2+
3+
Make the contract pauseable, while preserving all previous functionality. Users should not be able to deposit when the contract is paused. Users should be able to withdraw their liquidity when the contract is paused. Only the owner can pause and unpause the contract.
4+
5+
Then upgrade the existing contract's implementation to this new contract. This migration is forced, and users not wishing to stay for this new contract upgrade must withdraw their liquidity.

0 commit comments

Comments
 (0)