From aecfda8fd226f1056c115cdb7f9210a2764b2896 Mon Sep 17 00:00:00 2001 From: Elliot Date: Wed, 6 Nov 2024 13:30:20 +0700 Subject: [PATCH] checkpoint: organization, clean up TODO's Signed-off-by: Elliot --- src/exercises/00/SIP00.sol | 7 +- src/exercises/01/SIP01.sol | 1 - src/exercises/02/SIP02.sol | 70 +--------- src/exercises/03/REQUIREMENTS.md | 3 + src/exercises/03/{SIP04.sol => SIP03.sol} | 50 +++---- .../{04/Vault05.sol => 03/Vault03.sol} | 18 +-- src/exercises/03/Vault04Storage.sol | 21 --- src/exercises/04/REQUIREMENTS.md | 5 + src/exercises/04/SIP04.sol | 123 ++++++++++++++++++ src/exercises/{03 => 04}/Vault04.sol | 33 +++-- test/TestVault00.t.sol | 6 +- test/TestVault02.t.sol | 19 +-- test/TestVault04.t.sol | 6 +- 13 files changed, 212 insertions(+), 150 deletions(-) create mode 100644 src/exercises/03/REQUIREMENTS.md rename src/exercises/03/{SIP04.sol => SIP03.sol} (73%) rename src/exercises/{04/Vault05.sol => 03/Vault03.sol} (92%) delete mode 100644 src/exercises/03/Vault04Storage.sol create mode 100644 src/exercises/04/REQUIREMENTS.md create mode 100644 src/exercises/04/SIP04.sol rename src/exercises/{03 => 04}/Vault04.sol (89%) diff --git a/src/exercises/00/SIP00.sol b/src/exercises/00/SIP00.sol index 3dbca96..5156b9c 100644 --- a/src/exercises/00/SIP00.sol +++ b/src/exercises/00/SIP00.sol @@ -7,7 +7,6 @@ import {Addresses} from "@forge-proposal-simulator/addresses/Addresses.sol"; import {Vault} from "src/exercises/00/Vault00.sol"; -import {MockToken} from "@mocks/MockToken.sol"; import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; /// 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,7 +49,7 @@ contract SIP00 is GovernorBravoProposal { } function deploy() public override { - if (!addresses.isAddressSet("V1_VAULT")) { + if (!addresses.isAddressSet("V0_VAULT")) { address[] memory tokens = new address[](3); tokens[0] = addresses.getAddress("USDC"); tokens[1] = addresses.getAddress("DAI"); @@ -58,12 +57,12 @@ contract SIP00 is GovernorBravoProposal { Vault vault = new Vault(tokens); - addresses.addAddress("V1_VAULT", address(vault), true); + addresses.addAddress("V0_VAULT", address(vault), true); } } function validate() public view override { - Vault vault = Vault(addresses.getAddress("V1_VAULT")); + Vault vault = Vault(addresses.getAddress("V0_VAULT")); assertEq( vault.authorizedToken(addresses.getAddress("USDC")), diff --git a/src/exercises/01/SIP01.sol b/src/exercises/01/SIP01.sol index 5a6a8f3..3b695a8 100644 --- a/src/exercises/01/SIP01.sol +++ b/src/exercises/01/SIP01.sol @@ -7,7 +7,6 @@ import {Addresses} from "@forge-proposal-simulator/addresses/Addresses.sol"; import {Vault} from "src/exercises/01/Vault01.sol"; -import {MockToken} from "@mocks/MockToken.sol"; import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; /// 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 diff --git a/src/exercises/02/SIP02.sol b/src/exercises/02/SIP02.sol index 5bcae40..bda8de2 100644 --- a/src/exercises/02/SIP02.sol +++ b/src/exercises/02/SIP02.sol @@ -5,11 +5,6 @@ import {GovernorBravoProposal} from "@forge-proposal-simulator/src/proposals/GovernorBravoProposal.sol"; import {Addresses} from "@forge-proposal-simulator/addresses/Addresses.sol"; - -import {Vault03} from "src/exercises/03/Vault.sol"; -import {Vault04} from "src/exercises/04/Vault04.sol"; -import {MockToken} from "@mocks/MockToken.sol"; -import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; import { ProxyAdmin, TransparentUpgradeableProxy, @@ -20,6 +15,9 @@ import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import {Vault} from "src/exercises/02/Vault02.sol"; +import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; + /// 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 contract SIP02 is GovernorBravoProposal { using ForkSelector for uint256; @@ -60,13 +58,7 @@ contract SIP02 is GovernorBravoProposal { } function deploy() public override { - address vaultProxy; - if (!addresses.isAddressSet("V3_VAULT_IMPLEMENTATION")) { - address vaultImpl = address(new Vault03()); - addresses.addAddress( - "V3_VAULT_IMPLEMENTATION", vaultImpl, true - ); - + if (!addresses.isAddressSet("V2_VAULT")) { address[] memory tokens = new address[](3); tokens[0] = addresses.getAddress("USDC"); tokens[1] = addresses.getAddress("DAI"); @@ -74,50 +66,13 @@ contract SIP02 is GovernorBravoProposal { address owner = addresses.getAddress("DEPLOYER_EOA"); - // Generate calldata for initialize function of vault - bytes memory data = abi.encodeWithSignature( - "initialize(address[],address)", tokens, owner - ); - - vaultProxy = address( - new TransparentUpgradeableProxy( - vaultImpl, owner, data - ) - ); - addresses.addAddress("VAULT_PROXY", vaultProxy, true); - } - - if (!addresses.isAddressSet("V4_VAULT_IMPLEMENTATION")) { - address vaultImpl = address(new Vault04()); - addresses.addAddress( - "V4_VAULT_IMPLEMENTATION", vaultImpl, true - ); + address vaultImpl = address(new Vault(tokens, owner)); + addresses.addAddress("V2_VAULT", vaultImpl, true); } } - function build() - public - override - buildModifier(addresses.getAddress("COMPOUND_TIMELOCK_BRAVO")) - { - address vaultProxy = addresses.getAddress("VAULT_PROXY"); - bytes32 adminSlot = - vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT); - - address proxyAdmin = address(uint160(uint256(adminSlot))); - - // upgrade to new implementation - ProxyAdmin(proxyAdmin).upgradeAndCall( - ITransparentUpgradeableProxy(vaultProxy), - addresses.getAddress("V4_VAULT_IMPLEMENTATION"), - "" - ); - - Vault04(vaultProxy).setMaxSupply(1_000_000e18); - } - function validate() public view override { - Vault04 vault = Vault04(addresses.getAddress("VAULT_PROXY")); + Vault vault = Vault(addresses.getAddress("V2_VAULT")); assertEq( vault.authorizedToken(addresses.getAddress("USDC")), @@ -134,16 +89,5 @@ contract SIP02 is GovernorBravoProposal { true, "USDT should be authorized" ); - - assertEq( - vault.maxSupply(), - 1_000_000e18, - "Max supply should be 1,000,000 USDC" - ); - assertEq( - vault.totalSupplied(), - 1_000e18, - "Total supplied should be 1000 USDC" - ); } } diff --git a/src/exercises/03/REQUIREMENTS.md b/src/exercises/03/REQUIREMENTS.md new file mode 100644 index 0000000..e423ad2 --- /dev/null +++ b/src/exercises/03/REQUIREMENTS.md @@ -0,0 +1,3 @@ +# Overview + +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. \ No newline at end of file diff --git a/src/exercises/03/SIP04.sol b/src/exercises/03/SIP03.sol similarity index 73% rename from src/exercises/03/SIP04.sol rename to src/exercises/03/SIP03.sol index e3c46f3..0489a47 100644 --- a/src/exercises/03/SIP04.sol +++ b/src/exercises/03/SIP03.sol @@ -6,9 +6,6 @@ import {GovernorBravoProposal} from import {Addresses} from "@forge-proposal-simulator/addresses/Addresses.sol"; -import {Vault04} from "src/exercises/04/Vault04.sol"; -import {MockToken} from "@mocks/MockToken.sol"; -import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; import { ProxyAdmin, TransparentUpgradeableProxy, @@ -19,8 +16,11 @@ import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -/// 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 -contract SIP04 is GovernorBravoProposal { +import {Vault} from "src/exercises/03/Vault03.sol"; +import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; + +/// 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 +contract SIP03 is GovernorBravoProposal { using ForkSelector for uint256; constructor() { @@ -38,7 +38,7 @@ contract SIP04 is GovernorBravoProposal { } function name() public pure override returns (string memory) { - return "SIP-04 Upgrade"; + return "SIP-03 Upgrade"; } function description() @@ -59,45 +59,45 @@ contract SIP04 is GovernorBravoProposal { } function deploy() public override { - if (!addresses.isAddressSet("PROXY_ADMIN")) { - ProxyAdmin proxyAdmin = new ProxyAdmin(); - proxyAdmin.transferOwnership( - addresses.getAddress("COMPOUND_TIMELOCK_BRAVO") - ); - - addresses.addAddress("PROXY_ADMIN", address(proxyAdmin), true); - } - address vaultProxy; - if (!addresses.isAddressSet("V4_VAULT_IMPLEMENTATION")) { - address vaultImpl = address(new Vault04()); - addresses.addAddress( - "V4_VAULT_IMPLEMENTATION", vaultImpl, true - ); + if (!addresses.isAddressSet("V3_VAULT_IMPL")) { + address vaultImpl = address(new Vault()); + addresses.addAddress("V3_VAULT_IMPL", vaultImpl, true); address[] memory tokens = new address[](3); tokens[0] = addresses.getAddress("USDC"); tokens[1] = addresses.getAddress("DAI"); tokens[2] = addresses.getAddress("USDT"); - address owner = addresses.getAddress("COMPOUND_TIMELOCK_BRAVO"); + address owner = + addresses.getAddress("COMPOUND_TIMELOCK_BRAVO"); // Generate calldata for initialize function of vault bytes memory data = abi.encodeWithSignature( "initialize(address[],address)", tokens, owner ); + /// proxy admin contract is created by the Transparent Upgradeable Proxy vaultProxy = address( new TransparentUpgradeableProxy( vaultImpl, owner, data ) ); addresses.addAddress("VAULT_PROXY", vaultProxy, true); + + address proxyAdmin = address( + uint160( + uint256( + vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT) + ) + ) + ); + addresses.addAddress("PROXY_ADMIN", proxyAdmin, true); } } function validate() public view override { - Vault04 vault = Vault04(addresses.getAddress("VAULT_PROXY")); + Vault vault = Vault(addresses.getAddress("VAULT_PROXY")); assertEq( vault.authorizedToken(addresses.getAddress("USDC")), @@ -120,5 +120,11 @@ contract SIP04 is GovernorBravoProposal { vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT); address proxyAdmin = address(uint160(uint256(adminSlot))); + + assertEq( + ProxyAdmin(proxyAdmin).owner(), + addresses.getAddress("COMPOUND_TIMELOCK_BRAVO"), + "owner not set" + ); } } diff --git a/src/exercises/04/Vault05.sol b/src/exercises/03/Vault03.sol similarity index 92% rename from src/exercises/04/Vault05.sol rename to src/exercises/03/Vault03.sol index 3dfbb48..43d4aa5 100644 --- a/src/exercises/04/Vault05.sol +++ b/src/exercises/03/Vault03.sol @@ -4,22 +4,15 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import {OwnableUpgradeable} from - "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {VaultStoragePausable} from - "src/exercises/storage/VaultStoragePausable.sol"; +import {VaultStorageOwnable} from + "src/exercises/storage/VaultStorageOwnable.sol"; /// @notice Add maxsupply to the vault and update getNormalizedAmount logic -/// TODO make pauseable -/// make totalSupplied offsets the same -/// inherit pausable to mess up the storage slot offsets -/// add governance proposal that deploys and ugprades the existing vault from -/// proposal 03 /// deploy Vault 03 to mainnet /// add integration tests -contract Vault05 is VaultStoragePausable { +contract Vault is VaultStorageOwnable { using SafeERC20 for IERC20; /// @notice Deposit event @@ -116,10 +109,7 @@ contract Vault05 is VaultStoragePausable { /// @notice Deposit tokens into the vault /// @param token The token to deposit, only authorized tokens allowed /// @param amount The amount to deposit - function deposit(address token, uint256 amount) - external - whenNotPaused - { + function deposit(address token, uint256 amount) external { require(authorizedToken[token], "Vault: token not authorized"); uint256 normalizedAmount = getNormalizedAmount(token, amount); diff --git a/src/exercises/03/Vault04Storage.sol b/src/exercises/03/Vault04Storage.sol deleted file mode 100644 index 34a1c1a..0000000 --- a/src/exercises/03/Vault04Storage.sol +++ /dev/null @@ -1,21 +0,0 @@ -pragma solidity 0.8.25; - -/// inherit ownable, switch around the order o -contract Vault04Storage { - /// @notice Mapping of authorized tokens - mapping(address => bool) public authorizedToken; - - /// @notice User's balance of all tokens deposited in the vault - mapping(address => uint256) public balanceOf; - - /// @notice Maximum amount of tokens that can be supplied to the vault - uint256 public maxSupply; - - /// @notice Total amount of tokens supplied to the vault - /// - /// invariants: - /// totalSupplied = sum(balanceOf all users) - /// sum(balanceOf(vault) authorized tokens) >= totalSupplied - /// - uint256 public totalSupplied; -} diff --git a/src/exercises/04/REQUIREMENTS.md b/src/exercises/04/REQUIREMENTS.md new file mode 100644 index 0000000..c9b193b --- /dev/null +++ b/src/exercises/04/REQUIREMENTS.md @@ -0,0 +1,5 @@ +# Overview + +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. + +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. diff --git a/src/exercises/04/SIP04.sol b/src/exercises/04/SIP04.sol new file mode 100644 index 0000000..94cd5fa --- /dev/null +++ b/src/exercises/04/SIP04.sol @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +pragma solidity ^0.8.0; + +import {GovernorBravoProposal} from + "@forge-proposal-simulator/src/proposals/GovernorBravoProposal.sol"; +import {Addresses} from + "@forge-proposal-simulator/addresses/Addresses.sol"; +import { + ProxyAdmin, + TransparentUpgradeableProxy, + ITransparentUpgradeableProxy +} from + "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import {ERC1967Utils} from + "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol"; +import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +import {Vault} from "src/exercises/04/Vault04.sol"; +import {ForkSelector, ETHEREUM_FORK_ID} from "@test/utils/Forks.sol"; + +/// DO_RUN=false DO_BUILD=false DO_DEPLOY=true DO_SIMULATE=false DO_PRINT=false DO_VALIDATE=true forge script src/exercises/04/SIP04.sol:SIP04 -vvvv +contract SIP04 is GovernorBravoProposal { + using ForkSelector for uint256; + + constructor() { + primaryForkId = ETHEREUM_FORK_ID; + } + + function setupProposal() public { + ETHEREUM_FORK_ID.createForksAndSelect(); + + string memory addressesFolderPath = "./addresses"; + uint256[] memory chainIds = new uint256[](1); + chainIds[0] = 1; + + setAddresses(new Addresses(addressesFolderPath, chainIds)); + } + + function name() public pure override returns (string memory) { + return "SIP-03 Upgrade"; + } + + function description() + public + pure + override + returns (string memory) + { + return name(); + } + + function run() public override { + setupProposal(); + + setGovernor(addresses.getAddress("COMPOUND_GOVERNOR_BRAVO")); + + super.run(); + } + + function deploy() public override { + if (!addresses.isAddressSet("V4_VAULT_IMPL")) { + address vaultImpl = address(new Vault()); + addresses.addAddress("V4_VAULT_IMPL", vaultImpl, true); + } + } + + function build() + public + override + buildModifier(addresses.getAddress("COMPOUND_TIMELOCK_BRAVO")) + { + address vaultProxy = addresses.getAddress("VAULT_PROXY"); + bytes32 adminSlot = + vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT); + + address proxyAdmin = address(uint160(uint256(adminSlot))); + + /// recorded calls + + // upgrade to new implementation + ProxyAdmin(proxyAdmin).upgradeAndCall( + ITransparentUpgradeableProxy(vaultProxy), + addresses.getAddress("V4_VAULT_IMPLEMENTATION"), + "" + ); + + Vault(vaultProxy).setMaxSupply(1_000_000e18); + } + + function validate() public view override { + Vault vault = Vault(addresses.getAddress("VAULT_PROXY")); + + assertEq( + vault.authorizedToken(addresses.getAddress("USDC")), + true, + "USDC should be authorized" + ); + assertEq( + vault.authorizedToken(addresses.getAddress("DAI")), + true, + "DAI should be authorized" + ); + assertEq( + vault.authorizedToken(addresses.getAddress("USDT")), + true, + "USDT should be authorized" + ); + assertEq( + vault.maxSupply(), 1_000_000e18, "max supply not set" + ); + + address vaultProxy = addresses.getAddress("VAULT_PROXY"); + bytes32 adminSlot = + vm.load(vaultProxy, ERC1967Utils.ADMIN_SLOT); + address proxyAdmin = address(uint160(uint256(adminSlot))); + + assertEq( + ProxyAdmin(proxyAdmin).owner(), + addresses.getAddress("COMPOUND_TIMELOCK_BRAVO"), + "owner not set" + ); + } +} diff --git a/src/exercises/03/Vault04.sol b/src/exercises/04/Vault04.sol similarity index 89% rename from src/exercises/03/Vault04.sol rename to src/exercises/04/Vault04.sol index 1fa143c..52fec78 100644 --- a/src/exercises/03/Vault04.sol +++ b/src/exercises/04/Vault04.sol @@ -4,20 +4,16 @@ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {OwnableUpgradeable} from + "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import {VaultStorageOwnable} from - "src/exercises/storage/VaultStorageOwnable.sol"; +import {VaultStoragePausable} from + "src/exercises/storage/VaultStoragePausable.sol"; /// @notice Add maxsupply to the vault and update getNormalizedAmount logic -/// TODO make pauseable -/// make totalSupplied offsets the same -/// inherit pausable to mess up the storage slot offsets -/// add governance proposal that deploys and ugprades the existing vault from -/// proposal 03 -/// deploy Vault 03 to mainnet -/// add integration tests -contract Vault04 is VaultStorageOwnable { +/// allows pausing by owner +contract Vault is VaultStoragePausable { using SafeERC20 for IERC20; /// @notice Deposit event @@ -105,6 +101,18 @@ contract Vault04 is VaultStorageOwnable { emit MaxSupplyUpdated(previousMaxSupply, newMaxSupply); } + /// @notice pauses the contract, callable only by the owner + /// and when the contract is unpaused + function pause() external onlyOwner whenNotPaused { + _pause(); + } + + /// @notice unpauses the contract, callable only by the owner + /// and when the contract is paused + function unpause() external onlyOwner whenPaused { + _unpause(); + } + /// ------------------------------------------------------------- /// ------------------------------------------------------------- /// ----------------- PUBLIC MUTATIVE FUNCTIONS ----------------- @@ -114,7 +122,10 @@ contract Vault04 is VaultStorageOwnable { /// @notice Deposit tokens into the vault /// @param token The token to deposit, only authorized tokens allowed /// @param amount The amount to deposit - function deposit(address token, uint256 amount) external { + function deposit(address token, uint256 amount) + external + whenNotPaused + { require(authorizedToken[token], "Vault: token not authorized"); uint256 normalizedAmount = getNormalizedAmount(token, amount); diff --git a/test/TestVault00.t.sol b/test/TestVault00.t.sol index bf3e612..3210aac 100644 --- a/test/TestVault00.t.sol +++ b/test/TestVault00.t.sol @@ -43,7 +43,7 @@ contract TestVault00 is Test, SIP00 { dai = addresses.getAddress("DAI"); usdc = addresses.getAddress("USDC"); usdt = addresses.getAddress("USDT"); - vault = Vault(addresses.getAddress("V1_VAULT")); + vault = Vault(addresses.getAddress("V0_VAULT")); } function testValidate() public view { @@ -77,7 +77,7 @@ contract TestVault00 is Test, SIP00 { deal(usdt, address(this), usdtDepositAmount); USDT(usdt).approve( - addresses.getAddress("V1_VAULT"), usdtDepositAmount + addresses.getAddress("V0_VAULT"), usdtDepositAmount ); /// this executes 3 state transitions: @@ -163,7 +163,7 @@ contract TestVault00 is Test, SIP00 { vm.startPrank(sender); IERC20(token).safeIncreaseAllowance( - addresses.getAddress("V1_VAULT"), amount + addresses.getAddress("V0_VAULT"), amount ); /// this executes 3 state transitions: diff --git a/test/TestVault02.t.sol b/test/TestVault02.t.sol index a4584b8..3deaea4 100644 --- a/test/TestVault02.t.sol +++ b/test/TestVault02.t.sol @@ -6,10 +6,10 @@ import {console} from "@forge-std/console.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Test} from "@forge-std/Test.sol"; -import {Vault} from "src/exercises/00/Vault00.sol"; -import {SIP00} from "src/exercises/00/SIP00.sol"; +import {Vault} from "src/exercises/02/Vault02.sol"; +import {SIP02} from "src/exercises/02/SIP02.sol"; -contract TestVault02 is Test, SIP00 { +contract TestVault02 is Test, SIP02 { using SafeERC20 for IERC20; Vault public vault; @@ -42,7 +42,7 @@ contract TestVault02 is Test, SIP00 { dai = addresses.getAddress("DAI"); usdc = addresses.getAddress("USDC"); usdt = addresses.getAddress("USDT"); - vault = Vault(addresses.getAddress("V1_VAULT")); + vault = Vault(addresses.getAddress("V2_VAULT")); } function testValidate() public view { @@ -76,7 +76,7 @@ contract TestVault02 is Test, SIP00 { deal(usdt, address(this), usdtDepositAmount); USDT(usdt).approve( - addresses.getAddress("V1_VAULT"), usdtDepositAmount + addresses.getAddress("V2_VAULT"), usdtDepositAmount ); /// this executes 3 state transitions: @@ -162,7 +162,7 @@ contract TestVault02 is Test, SIP00 { vm.startPrank(sender); IERC20(token).safeIncreaseAllowance( - addresses.getAddress("V1_VAULT"), amount + addresses.getAddress("V2_VAULT"), amount ); /// this executes 3 state transitions: @@ -172,14 +172,17 @@ contract TestVault02 is Test, SIP00 { vault.deposit(token, amount); vm.stopPrank(); + uint256 normalizedAmount = + vault.getNormalizedAmount(token, amount); + assertEq( vault.balanceOf(sender), - startingUserBalance + amount, + startingUserBalance + normalizedAmount, "user vault balance not increased" ); assertEq( vault.totalSupplied(), - startingTotalSupplied + amount, + startingTotalSupplied + normalizedAmount, "vault total supplied not increased by deposited amount" ); assertEq( diff --git a/test/TestVault04.t.sol b/test/TestVault04.t.sol index 196a22d..fa8b058 100644 --- a/test/TestVault04.t.sol +++ b/test/TestVault04.t.sol @@ -6,12 +6,12 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Test} from "@forge-std/Test.sol"; import {SIP02} from "src/exercises/02/SIP02.sol"; -import {Vault04} from "src/exercises/04/Vault04.sol"; +import {Vault} from "src/exercises/04/Vault04.sol"; contract TestVault04 is Test, SIP02 { using SafeERC20 for IERC20; - Vault04 public vault; + Vault public vault; /// @notice user addresses address public immutable userA = address(1111); @@ -43,7 +43,7 @@ contract TestVault04 is Test, SIP02 { dai = addresses.getAddress("DAI"); usdc = addresses.getAddress("USDC"); usdt = addresses.getAddress("USDT"); - vault = Vault04(addresses.getAddress("VAULT_PROXY")); + vault = Vault(addresses.getAddress("VAULT_PROXY")); } function testVaultDepositDai() public {