Skip to content

Commit

Permalink
formatting and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ungaro committed Dec 25, 2024
1 parent e4536d4 commit cd05a5e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 7 deletions.
3 changes: 1 addition & 2 deletions nest/src/vault/NestAtomicQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nest/src/vault/NestBoringVaultModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions nest/src/vault/NestTeller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 45 additions & 0 deletions nest/test/NestBoringVaultModuleTest.t.sol
Original file line number Diff line number Diff line change
@@ -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;

}
63 changes: 63 additions & 0 deletions nest/test/NestTeller.t.sol
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit cd05a5e

Please sign in to comment.