From cd05a5e660000eca8b5a67b005a90374bc0d01c3 Mon Sep 17 00:00:00 2001 From: ungaro Date: Wed, 25 Dec 2024 15:51:25 -0500 Subject: [PATCH] formatting and tests --- nest/src/vault/NestAtomicQueue.sol | 3 +- nest/src/vault/NestBoringVaultModule.sol | 3 +- nest/src/vault/NestTeller.sol | 4 +- nest/test/NestBoringVaultModuleTest.t.sol | 45 ++++++++++++++++ nest/test/NestTeller.t.sol | 63 +++++++++++++++++++++++ 5 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 nest/test/NestBoringVaultModuleTest.t.sol create mode 100644 nest/test/NestTeller.t.sol diff --git a/nest/src/vault/NestAtomicQueue.sol b/nest/src/vault/NestAtomicQueue.sol index 84fd94e..a7250f2 100644 --- a/nest/src/vault/NestAtomicQueue.sol +++ b/nest/src/vault/NestAtomicQueue.sol @@ -10,11 +10,10 @@ import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol"; import { AtomicQueue } from "@boringvault/src/atomic-queue/AtomicQueue.sol"; -import { IComponentToken } from "../interfaces/IComponentToken.sol"; import { IAtomicQueue } from "../interfaces/IAtomicQueue.sol"; +import { IComponentToken } from "../interfaces/IComponentToken.sol"; import { NestBoringVaultModule } from "./NestBoringVaultModule.sol"; - /** * @title NestAtomicQueue * @notice AtomicQueue implementation for the Nest vault diff --git a/nest/src/vault/NestBoringVaultModule.sol b/nest/src/vault/NestBoringVaultModule.sol index 5d3436c..5d2cd3b 100644 --- a/nest/src/vault/NestBoringVaultModule.sol +++ b/nest/src/vault/NestBoringVaultModule.sol @@ -4,15 +4,14 @@ pragma solidity ^0.8.25; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; -import { ERC20 } from "@solmate/tokens/ERC20.sol"; import { Auth, Authority } from "@solmate/auth/Auth.sol"; +import { ERC20 } from "@solmate/tokens/ERC20.sol"; import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol"; import { IAccountantWithRateProviders } from "../interfaces/IAccountantWithRateProviders.sol"; import { IBoringVault } from "../interfaces/IBoringVault.sol"; import { IComponentToken } from "../interfaces/IComponentToken.sol"; - /** * @title NestBoringVaultModule * @notice Base implementation for Nest vault modules diff --git a/nest/src/vault/NestTeller.sol b/nest/src/vault/NestTeller.sol index 203520c..de858f8 100644 --- a/nest/src/vault/NestTeller.sol +++ b/nest/src/vault/NestTeller.sol @@ -4,8 +4,8 @@ pragma solidity ^0.8.25; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; -import { ERC20 } from "@solmate/tokens/ERC20.sol"; import { Auth, Authority } from "@solmate/auth/Auth.sol"; +import { ERC20 } from "@solmate/tokens/ERC20.sol"; import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol"; import { MultiChainLayerZeroTellerWithMultiAssetSupport } from @@ -14,8 +14,6 @@ import { MultiChainLayerZeroTellerWithMultiAssetSupport } from import { ITeller } from "../interfaces/ITeller.sol"; import { NestBoringVaultModule } from "./NestBoringVaultModule.sol"; - - /** * @title NestTeller * @notice Teller implementation for the Nest vault diff --git a/nest/test/NestBoringVaultModuleTest.t.sol b/nest/test/NestBoringVaultModuleTest.t.sol new file mode 100644 index 0000000..b4d5750 --- /dev/null +++ b/nest/test/NestBoringVaultModuleTest.t.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.25; + +import { MockAccountantWithRateProviders } from "../src/mocks/MockAccountantWithRateProviders.sol"; +import { MockERC20 } from "../src/mocks/MockERC20.sol"; +import { MockUSDC } from "../src/mocks/MockUSDC.sol"; +import { MockVault } from "../src/mocks/MockVault.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import { Test } from "forge-std/Test.sol"; + +abstract contract NestBoringVaultModuleTest is Test { + + MockUSDC public asset; + MockVault public vault; + MockAccountantWithRateProviders public accountant; + + address public owner; + address public user; + + function setUp() public virtual { + owner = address(this); + user = makeAddr("user"); + + // Deploy mocks + asset = new MockUSDC(); + vault = new MockVault( + owner, // _owner + "Mock Vault", // _name + "MVLT", // _symbol + address(asset) // _usdc + ); + + accountant = new MockAccountantWithRateProviders( + address(vault), // _vault + address(asset), // _base + 1e18 // startingExchangeRate (1:1 ratio) + ); + } + + // Common tests that apply to all NestBoringVaultModule implementations + function testInitialization() public virtual; + //function testOwnershipAndAuth() public virtual; + //function testAssetHandling() public virtual; + +} diff --git a/nest/test/NestTeller.t.sol b/nest/test/NestTeller.t.sol new file mode 100644 index 0000000..e0662a8 --- /dev/null +++ b/nest/test/NestTeller.t.sol @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.25; + +import { NestTeller } from "../src/vault/NestTeller.sol"; +import { NestBoringVaultModuleTest } from "./NestBoringVaultModuleTest.t.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +contract NestTellerTest is NestBoringVaultModuleTest { + + NestTeller public teller; + address public endpoint; + uint256 public constant MINIMUM_MINT_PERCENTAGE = 9900; // 99% + + function setUp() public override { + super.setUp(); + endpoint = makeAddr("endpoint"); + + // Deal some tokens to the vault for initial liquidity + deal(address(asset), address(vault), 1_000_000e6); + + // Setup initial rates in accountant + accountant.setRateInQuote(1e18); // 1:1 ratio + + teller = new NestTeller( + owner, address(vault), address(accountant), endpoint, address(asset), MINIMUM_MINT_PERCENTAGE + ); + + // Approve teller to spend vault's tokens + vm.prank(address(vault)); + IERC20(address(asset)).approve(address(teller), type(uint256).max); + } + + function testInitialization() public override { + assertEq(teller.owner(), owner); + assertEq(address(teller.vaultContract()), address(vault)); + assertEq(address(teller.accountantContract()), address(accountant)); + assertEq(teller.asset(), address(asset)); + assertEq(teller.minimumMintPercentage(), MINIMUM_MINT_PERCENTAGE); + } + + function testDeposit( + uint256 amount + ) public { + // Bound the amount to reasonable values + amount = bound(amount, 1e6, 1_000_000e6); + + // Give user some tokens + deal(address(asset), user, amount); + + // Approve teller + vm.startPrank(user); + IERC20(address(asset)).approve(address(teller), amount); + + // Deposit + uint256 shares = teller.deposit(amount, user, user); + + // Verify + assertGt(shares, 0, "Should have received shares"); + assertEq(IERC20(address(asset)).balanceOf(address(vault)), amount, "Vault should have received tokens"); + vm.stopPrank(); + } + +}