From 95e76706125755e53d739e8e3c9aae3f641ab127 Mon Sep 17 00:00:00 2001 From: Imad-Allal Date: Wed, 22 May 2024 00:28:38 +0100 Subject: [PATCH 1/5] Writing tests for NovaVault interfaces --- src/NovaAdapterVelo.sol | 4 ++ src/NovaVault.sol | 20 ++++--- src/interfaces/INovaAdapterBase.sol | 2 +- src/{librairies => libraries}/Errors.sol | 0 test/NovaVault.t.sol | 75 ++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 9 deletions(-) rename src/{librairies => libraries}/Errors.sol (100%) create mode 100644 test/NovaVault.t.sol diff --git a/src/NovaAdapterVelo.sol b/src/NovaAdapterVelo.sol index 6a8dd08..370edce 100644 --- a/src/NovaAdapterVelo.sol +++ b/src/NovaAdapterVelo.sol @@ -67,4 +67,8 @@ contract NovaAdapterVelo is NovaAdapterBase { return (amount0, amount1); } + + function getAsset() external view returns (ERC20) { + return asset; + } } diff --git a/src/NovaVault.sol b/src/NovaVault.sol index 3cf8289..4dc472f 100644 --- a/src/NovaVault.sol +++ b/src/NovaVault.sol @@ -4,20 +4,23 @@ pragma solidity ^0.8.13; import {Errors} from "./libraries/Errors.sol"; import {INovaVault} from "./interfaces/INovaVault.sol"; import {INovaAdapterBase} from "./interfaces/INovaAdapterBase.sol"; +import {ERC20} from "@solmate/tokens/ERC20.sol"; + +import {console} from "forge-std/console.sol"; contract NovaVault is INovaVault { mapping(address => address) public _novaAdapters; - function constructor( - address[] calldata stables, - address[] calldata novaAdapters + constructor( + address[] memory stables, + address[] memory novaAdapters ) { _approveNovaAdapters(stables, novaAdapters); } function _approveNovaAdapters( - address[] calldata stables, - address[] calldata novaAdapters, + address[] memory stables, + address[] memory novaAdapters ) internal { require( stables.length == novaAdapters.length, @@ -39,7 +42,8 @@ contract NovaVault is INovaVault { Errors.ADAPTER_ALREADY_APPROVED ); - ERC20 underlyingAsset = INovaAdapterBase(adapter).asset(); + ERC20 underlyingAsset = INovaAdapterBase(adapter).getAsset(); + require( address(underlyingAsset) == stable, Errors.INVALID_STABLE_TO_ADAPTER_MAPPING @@ -58,7 +62,7 @@ contract NovaVault is INovaVault { (bool success, bytes memory data) = adapter.delegatecall( abi.encodeWithSignature("deposit(uint256)", assets) ); - return (success, data) + return (success, data); } function withdraw(address stable, uint256 shares) external returns (bool , bytes memory) { @@ -70,6 +74,6 @@ contract NovaVault is INovaVault { (bool success, bytes memory data) = adapter.delegatecall( abi.encodeWithSignature("withdraw(uint256)", shares) ); - return (success, data) + return (success, data); } } \ No newline at end of file diff --git a/src/interfaces/INovaAdapterBase.sol b/src/interfaces/INovaAdapterBase.sol index 4e2b5fa..fa965af 100644 --- a/src/interfaces/INovaAdapterBase.sol +++ b/src/interfaces/INovaAdapterBase.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.13; import {ERC20} from "@solmate/tokens/ERC20.sol"; interface INovaAdapterBase { - function asset() external view returns (ERC20); + function getAsset() external view returns (ERC20); function deposit(uint256 assets) external returns (bool , uint256); function withdraw(uint256 shares) external returns (bool, uint256); } \ No newline at end of file diff --git a/src/librairies/Errors.sol b/src/libraries/Errors.sol similarity index 100% rename from src/librairies/Errors.sol rename to src/libraries/Errors.sol diff --git a/test/NovaVault.t.sol b/test/NovaVault.t.sol new file mode 100644 index 0000000..64e0b8e --- /dev/null +++ b/test/NovaVault.t.sol @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {ERC20} from "@solmate/tokens/ERC20.sol"; +import {Test, console} from "forge-std/Test.sol"; +import {NovaVault} from "../src/NovaVault.sol"; +import {NovaAdapterVelo} from "../src/NovaAdapterVelo.sol"; +import {IVelodromePool} from "../src/interfaces/IVelodromePool.sol"; + +contract NovaVaultTest is Test { + address public POOL = 0x94c0A04C0d74571aa9EE25Dd6c29E2A36f5699aE; + address public sDAI = 0x2218a117083f5B482B0bB821d27056Ba9c04b1D3; + NovaAdapterVelo public adapter; + NovaVault public vault; + IVelodromePool veloPool; + address underlyingAddress; + ERC20 underlying; + address private veloToken0; + address private veloToken1; + address[] stables; + address[] novaAdapters; + + address public underlyingWhale = 0xacD03D601e5bB1B275Bb94076fF46ED9D753435A; + + function setUp() public { + veloPool = IVelodromePool(POOL); + veloToken0 = veloPool.token0(); + veloToken1 = veloPool.token1(); + if (veloToken0 == sDAI) { + underlyingAddress = veloToken1; + } else if (veloToken1 == sDAI) { + underlyingAddress = veloToken0; + } else { + revert("Velodrome pool should be made of `asset` and `sDAI`!"); + } + + underlying = ERC20(underlyingAddress); + + adapter = new NovaAdapterVelo( + underlying, + sDAI, + POOL, + "NovaAdapterVelo", + "NV", + 18 + ); + + stables.push(underlyingAddress); + novaAdapters.push(address(adapter)); + + vault = new NovaVault(stables, novaAdapters); + } + + function testNovaVaultDepositAndWithdraw() public { + uint256 aliceUnderlyingAmount = 100 * 1e6; + address alice = address(0xABCD); + + vm.prank(underlyingWhale); + underlying.transfer(alice, aliceUnderlyingAmount); + + vm.prank(alice); + underlying.approve(address(adapter), aliceUnderlyingAmount); + assertEq(underlying.allowance(alice, address(adapter)), aliceUnderlyingAmount); + + + vm.prank(alice); + (bool success, bytes memory data) = vault.deposit(address(underlyingAddress), aliceUnderlyingAmount); + assert(success); + + vm.prank(alice); + (success, data) = vault.withdraw(underlyingAddress, aliceUnderlyingAmount); + assert(success); + } + +} \ No newline at end of file From 969bf5bd7580a907d393bd7d2e1361d2d86c1f10 Mon Sep 17 00:00:00 2001 From: Imad-Allal Date: Wed, 22 May 2024 19:01:32 +0100 Subject: [PATCH 2/5] Trying to transfer directly from the NovaVault to NovaAdapterVelo --- src/NovaAdapterBase.sol | 13 ++-- src/NovaVault.sol | 3 + test/NovaAdapterVelo.t.sol | 150 ++++++++++++++++++------------------- test/NovaVault.t.sol | 4 +- 4 files changed, 87 insertions(+), 83 deletions(-) diff --git a/src/NovaAdapterBase.sol b/src/NovaAdapterBase.sol index 81085eb..848df3b 100644 --- a/src/NovaAdapterBase.sol +++ b/src/NovaAdapterBase.sol @@ -2,6 +2,7 @@ pragma solidity ^0.8.13; import {ERC20} from "@solmate/tokens/ERC20.sol"; +import {console} from "forge-std/console.sol"; abstract contract NovaAdapterBase is ERC20 { @@ -25,18 +26,18 @@ abstract contract NovaAdapterBase is ERC20 { sDAI = _sDAI; } - function deposit(uint256 assets) external returns (bool , uint256) { - bool success = asset.transferFrom(msg.sender, address(this), assets); - if(!success){ - revert TransferFailed(msg.sender, address(this), assets); - } + function deposit(uint256 assets) external returns (uint256) { + // bool success = asset.transferFrom(msg.sender, address(this), assets); + // if(!success){ + // revert TransferFailed(msg.sender, address(this), assets); + // } (, int256 sDai) = _swap(int256(assets), true); uint256 sDaiToMint = uint256(-sDai); _mint(msg.sender, sDaiToMint); - return (true, sDaiToMint); + return sDaiToMint; } function withdraw(uint256 shares) external returns (bool, uint256) { diff --git a/src/NovaVault.sol b/src/NovaVault.sol index 4dc472f..e3ec2f4 100644 --- a/src/NovaVault.sol +++ b/src/NovaVault.sol @@ -59,6 +59,9 @@ contract NovaVault is INovaVault { adapter != address(0), Errors.NO_ADAPTER_APPROVED ); + + ERC20(stable).transferFrom(msg.sender, adapter, assets); + (bool success, bytes memory data) = adapter.delegatecall( abi.encodeWithSignature("deposit(uint256)", assets) ); diff --git a/test/NovaAdapterVelo.t.sol b/test/NovaAdapterVelo.t.sol index f77c9a6..086046c 100644 --- a/test/NovaAdapterVelo.t.sol +++ b/test/NovaAdapterVelo.t.sol @@ -1,91 +1,91 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; +// // SPDX-License-Identifier: UNLICENSED +// pragma solidity ^0.8.13; -import {ERC20} from "@solmate/tokens/ERC20.sol"; -import {Test, console} from "forge-std/Test.sol"; -import {NovaAdapterVelo} from "../src/NovaAdapterVelo.sol"; -import {IVelodromePool} from "../src/interfaces/IVelodromePool.sol"; +// import {ERC20} from "@solmate/tokens/ERC20.sol"; +// import {Test, console} from "forge-std/Test.sol"; +// import {NovaAdapterVelo} from "../src/NovaAdapterVelo.sol"; +// import {IVelodromePool} from "../src/interfaces/IVelodromePool.sol"; -contract NovaAdapterVeloTest is Test { - address public POOL = 0x94c0A04C0d74571aa9EE25Dd6c29E2A36f5699aE; - address public sDAI = 0x2218a117083f5B482B0bB821d27056Ba9c04b1D3; - NovaAdapterVelo public vault; - IVelodromePool veloPool; - address underlyingAddress; - ERC20 underlying; - address private veloToken0; - address private veloToken1; +// contract NovaAdapterVeloTest is Test { +// address public POOL = 0x94c0A04C0d74571aa9EE25Dd6c29E2A36f5699aE; +// address public sDAI = 0x2218a117083f5B482B0bB821d27056Ba9c04b1D3; +// NovaAdapterVelo public vault; +// IVelodromePool veloPool; +// address underlyingAddress; +// ERC20 underlying; +// address private veloToken0; +// address private veloToken1; - address public underlyingWhale = 0xacD03D601e5bB1B275Bb94076fF46ED9D753435A; +// address public underlyingWhale = 0xacD03D601e5bB1B275Bb94076fF46ED9D753435A; - function setUp() public { - veloPool = IVelodromePool(POOL); - veloToken0 = veloPool.token0(); - veloToken1 = veloPool.token1(); - if (veloToken0 == sDAI) { - underlyingAddress = veloToken1; - } else if (veloToken1 == sDAI) { - underlyingAddress = veloToken0; - } else { - revert("Velodrome pool should be made of `asset` and `sDAI`!"); - } +// function setUp() public { +// veloPool = IVelodromePool(POOL); +// veloToken0 = veloPool.token0(); +// veloToken1 = veloPool.token1(); +// if (veloToken0 == sDAI) { +// underlyingAddress = veloToken1; +// } else if (veloToken1 == sDAI) { +// underlyingAddress = veloToken0; +// } else { +// revert("Velodrome pool should be made of `asset` and `sDAI`!"); +// } - underlying = ERC20(underlyingAddress); +// underlying = ERC20(underlyingAddress); - vault = new NovaAdapterVelo( - underlying, - sDAI, - POOL, - "NovaAdapterVelo", - "NV", - 18 - ); - } +// vault = new NovaAdapterVelo( +// underlying, +// sDAI, +// POOL, +// "NovaAdapterVelo", +// "NV", +// 18 +// ); +// } - function testDeposit() public{ - uint256 aliceUnderlyingAmount = 100 * 1e6; - address alice = address(0xABCD); +// function testDeposit() public{ +// uint256 aliceUnderlyingAmount = 100 * 1e6; +// address alice = address(0xABCD); - vm.prank(underlyingWhale); - underlying.transfer(alice, aliceUnderlyingAmount); +// vm.prank(underlyingWhale); +// underlying.transfer(alice, aliceUnderlyingAmount); - vm.prank(alice); - underlying.approve(address(vault), aliceUnderlyingAmount); - assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); +// vm.prank(alice); +// underlying.approve(address(vault), aliceUnderlyingAmount); +// assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); - vm.prank(alice); - (bool success, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); +// vm.prank(alice); +// (bool success, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); - assert(success); - assertEq(underlying.balanceOf(alice), 0); - assertEq(vault.balanceOf(alice), sDaiMinted); - assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); - } +// assert(success); +// assertEq(underlying.balanceOf(alice), 0); +// assertEq(vault.balanceOf(alice), sDaiMinted); +// assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); +// } - function testWithdraw() public{ - uint256 aliceUnderlyingAmount = 100 * 1e6; - address alice = address(0xABCD); +// function testWithdraw() public{ +// uint256 aliceUnderlyingAmount = 100 * 1e6; +// address alice = address(0xABCD); - vm.prank(underlyingWhale); - underlying.transfer(alice, aliceUnderlyingAmount); +// vm.prank(underlyingWhale); +// underlying.transfer(alice, aliceUnderlyingAmount); - vm.prank(alice); - underlying.approve(address(vault), aliceUnderlyingAmount); - assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); +// vm.prank(alice); +// underlying.approve(address(vault), aliceUnderlyingAmount); +// assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); - vm.prank(alice); - (bool succesDeposit, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); - assert(succesDeposit); - assertEq(underlying.balanceOf(alice), 0); - assertEq(vault.balanceOf(alice), sDaiMinted); - assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); +// vm.prank(alice); +// (bool succesDeposit, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); +// assert(succesDeposit); +// assertEq(underlying.balanceOf(alice), 0); +// assertEq(vault.balanceOf(alice), sDaiMinted); +// assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); - vm.prank(alice); - (bool successWithdraw, uint256 underlyingWithdrawn) = vault.withdraw(sDaiMinted); - assert(successWithdraw); - assertEq(underlying.balanceOf(alice), underlyingWithdrawn); - assertEq(vault.balanceOf(alice), 0); - assertEq(ERC20(sDAI).balanceOf(address(vault)), 0); - assertEq(underlying.balanceOf(address(vault)), 0); - } -} \ No newline at end of file +// vm.prank(alice); +// (bool successWithdraw, uint256 underlyingWithdrawn) = vault.withdraw(sDaiMinted); +// assert(successWithdraw); +// assertEq(underlying.balanceOf(alice), underlyingWithdrawn); +// assertEq(vault.balanceOf(alice), 0); +// assertEq(ERC20(sDAI).balanceOf(address(vault)), 0); +// assertEq(underlying.balanceOf(address(vault)), 0); +// } +// } \ No newline at end of file diff --git a/test/NovaVault.t.sol b/test/NovaVault.t.sol index 64e0b8e..0ab1918 100644 --- a/test/NovaVault.t.sol +++ b/test/NovaVault.t.sol @@ -59,8 +59,8 @@ contract NovaVaultTest is Test { underlying.transfer(alice, aliceUnderlyingAmount); vm.prank(alice); - underlying.approve(address(adapter), aliceUnderlyingAmount); - assertEq(underlying.allowance(alice, address(adapter)), aliceUnderlyingAmount); + underlying.approve(address(vault), aliceUnderlyingAmount); + assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); vm.prank(alice); From 46d693269633877a0c72841c9ff5f28dc10ff739 Mon Sep 17 00:00:00 2001 From: "lakonema2000@gmail" Date: Thu, 23 May 2024 21:20:58 +0200 Subject: [PATCH 3/5] use call instead of delegatecall --- src/NovaVault.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NovaVault.sol b/src/NovaVault.sol index e3ec2f4..f53d9b5 100644 --- a/src/NovaVault.sol +++ b/src/NovaVault.sol @@ -62,7 +62,7 @@ contract NovaVault is INovaVault { ERC20(stable).transferFrom(msg.sender, adapter, assets); - (bool success, bytes memory data) = adapter.delegatecall( + (bool success, bytes memory data) = adapter.call( abi.encodeWithSignature("deposit(uint256)", assets) ); return (success, data); @@ -74,7 +74,7 @@ contract NovaVault is INovaVault { adapter != address(0), Errors.NO_ADAPTER_APPROVED ); - (bool success, bytes memory data) = adapter.delegatecall( + (bool success, bytes memory data) = adapter.call( abi.encodeWithSignature("withdraw(uint256)", shares) ); return (success, data); From a80160bf4b434a74fc1cafd3a24d3bb99e788f02 Mon Sep 17 00:00:00 2001 From: "lakonema2000@gmail" Date: Thu, 23 May 2024 21:27:12 +0200 Subject: [PATCH 4/5] adapted vault contract to make both vault and adapter tests pass --- src/NovaAdapterBase.sol | 12 +-- src/NovaVault.sol | 3 +- test/NovaAdapterVelo.t.sol | 150 ++++++++++++++++++------------------- 3 files changed, 83 insertions(+), 82 deletions(-) diff --git a/src/NovaAdapterBase.sol b/src/NovaAdapterBase.sol index 848df3b..61c11c1 100644 --- a/src/NovaAdapterBase.sol +++ b/src/NovaAdapterBase.sol @@ -26,18 +26,18 @@ abstract contract NovaAdapterBase is ERC20 { sDAI = _sDAI; } - function deposit(uint256 assets) external returns (uint256) { - // bool success = asset.transferFrom(msg.sender, address(this), assets); - // if(!success){ - // revert TransferFailed(msg.sender, address(this), assets); - // } + function deposit(uint256 assets) external returns (bool, uint256) { + bool success = asset.transferFrom(msg.sender, address(this), assets); + if(!success){ + revert TransferFailed(msg.sender, address(this), assets); + } (, int256 sDai) = _swap(int256(assets), true); uint256 sDaiToMint = uint256(-sDai); _mint(msg.sender, sDaiToMint); - return sDaiToMint; + return (true, sDaiToMint); } function withdraw(uint256 shares) external returns (bool, uint256) { diff --git a/src/NovaVault.sol b/src/NovaVault.sol index f53d9b5..e30ec21 100644 --- a/src/NovaVault.sol +++ b/src/NovaVault.sol @@ -60,7 +60,8 @@ contract NovaVault is INovaVault { Errors.NO_ADAPTER_APPROVED ); - ERC20(stable).transferFrom(msg.sender, adapter, assets); + ERC20(stable).transferFrom(msg.sender, address(this), assets); + ERC20(stable).approve(adapter, assets); (bool success, bytes memory data) = adapter.call( abi.encodeWithSignature("deposit(uint256)", assets) diff --git a/test/NovaAdapterVelo.t.sol b/test/NovaAdapterVelo.t.sol index 086046c..f77c9a6 100644 --- a/test/NovaAdapterVelo.t.sol +++ b/test/NovaAdapterVelo.t.sol @@ -1,91 +1,91 @@ -// // SPDX-License-Identifier: UNLICENSED -// pragma solidity ^0.8.13; +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; -// import {ERC20} from "@solmate/tokens/ERC20.sol"; -// import {Test, console} from "forge-std/Test.sol"; -// import {NovaAdapterVelo} from "../src/NovaAdapterVelo.sol"; -// import {IVelodromePool} from "../src/interfaces/IVelodromePool.sol"; +import {ERC20} from "@solmate/tokens/ERC20.sol"; +import {Test, console} from "forge-std/Test.sol"; +import {NovaAdapterVelo} from "../src/NovaAdapterVelo.sol"; +import {IVelodromePool} from "../src/interfaces/IVelodromePool.sol"; -// contract NovaAdapterVeloTest is Test { -// address public POOL = 0x94c0A04C0d74571aa9EE25Dd6c29E2A36f5699aE; -// address public sDAI = 0x2218a117083f5B482B0bB821d27056Ba9c04b1D3; -// NovaAdapterVelo public vault; -// IVelodromePool veloPool; -// address underlyingAddress; -// ERC20 underlying; -// address private veloToken0; -// address private veloToken1; +contract NovaAdapterVeloTest is Test { + address public POOL = 0x94c0A04C0d74571aa9EE25Dd6c29E2A36f5699aE; + address public sDAI = 0x2218a117083f5B482B0bB821d27056Ba9c04b1D3; + NovaAdapterVelo public vault; + IVelodromePool veloPool; + address underlyingAddress; + ERC20 underlying; + address private veloToken0; + address private veloToken1; -// address public underlyingWhale = 0xacD03D601e5bB1B275Bb94076fF46ED9D753435A; + address public underlyingWhale = 0xacD03D601e5bB1B275Bb94076fF46ED9D753435A; -// function setUp() public { -// veloPool = IVelodromePool(POOL); -// veloToken0 = veloPool.token0(); -// veloToken1 = veloPool.token1(); -// if (veloToken0 == sDAI) { -// underlyingAddress = veloToken1; -// } else if (veloToken1 == sDAI) { -// underlyingAddress = veloToken0; -// } else { -// revert("Velodrome pool should be made of `asset` and `sDAI`!"); -// } + function setUp() public { + veloPool = IVelodromePool(POOL); + veloToken0 = veloPool.token0(); + veloToken1 = veloPool.token1(); + if (veloToken0 == sDAI) { + underlyingAddress = veloToken1; + } else if (veloToken1 == sDAI) { + underlyingAddress = veloToken0; + } else { + revert("Velodrome pool should be made of `asset` and `sDAI`!"); + } -// underlying = ERC20(underlyingAddress); + underlying = ERC20(underlyingAddress); -// vault = new NovaAdapterVelo( -// underlying, -// sDAI, -// POOL, -// "NovaAdapterVelo", -// "NV", -// 18 -// ); -// } + vault = new NovaAdapterVelo( + underlying, + sDAI, + POOL, + "NovaAdapterVelo", + "NV", + 18 + ); + } -// function testDeposit() public{ -// uint256 aliceUnderlyingAmount = 100 * 1e6; -// address alice = address(0xABCD); + function testDeposit() public{ + uint256 aliceUnderlyingAmount = 100 * 1e6; + address alice = address(0xABCD); -// vm.prank(underlyingWhale); -// underlying.transfer(alice, aliceUnderlyingAmount); + vm.prank(underlyingWhale); + underlying.transfer(alice, aliceUnderlyingAmount); -// vm.prank(alice); -// underlying.approve(address(vault), aliceUnderlyingAmount); -// assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); + vm.prank(alice); + underlying.approve(address(vault), aliceUnderlyingAmount); + assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); -// vm.prank(alice); -// (bool success, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); + vm.prank(alice); + (bool success, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); -// assert(success); -// assertEq(underlying.balanceOf(alice), 0); -// assertEq(vault.balanceOf(alice), sDaiMinted); -// assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); -// } + assert(success); + assertEq(underlying.balanceOf(alice), 0); + assertEq(vault.balanceOf(alice), sDaiMinted); + assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); + } -// function testWithdraw() public{ -// uint256 aliceUnderlyingAmount = 100 * 1e6; -// address alice = address(0xABCD); + function testWithdraw() public{ + uint256 aliceUnderlyingAmount = 100 * 1e6; + address alice = address(0xABCD); -// vm.prank(underlyingWhale); -// underlying.transfer(alice, aliceUnderlyingAmount); + vm.prank(underlyingWhale); + underlying.transfer(alice, aliceUnderlyingAmount); -// vm.prank(alice); -// underlying.approve(address(vault), aliceUnderlyingAmount); -// assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); + vm.prank(alice); + underlying.approve(address(vault), aliceUnderlyingAmount); + assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); -// vm.prank(alice); -// (bool succesDeposit, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); -// assert(succesDeposit); -// assertEq(underlying.balanceOf(alice), 0); -// assertEq(vault.balanceOf(alice), sDaiMinted); -// assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); + vm.prank(alice); + (bool succesDeposit, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); + assert(succesDeposit); + assertEq(underlying.balanceOf(alice), 0); + assertEq(vault.balanceOf(alice), sDaiMinted); + assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); -// vm.prank(alice); -// (bool successWithdraw, uint256 underlyingWithdrawn) = vault.withdraw(sDaiMinted); -// assert(successWithdraw); -// assertEq(underlying.balanceOf(alice), underlyingWithdrawn); -// assertEq(vault.balanceOf(alice), 0); -// assertEq(ERC20(sDAI).balanceOf(address(vault)), 0); -// assertEq(underlying.balanceOf(address(vault)), 0); -// } -// } \ No newline at end of file + vm.prank(alice); + (bool successWithdraw, uint256 underlyingWithdrawn) = vault.withdraw(sDaiMinted); + assert(successWithdraw); + assertEq(underlying.balanceOf(alice), underlyingWithdrawn); + assertEq(vault.balanceOf(alice), 0); + assertEq(ERC20(sDAI).balanceOf(address(vault)), 0); + assertEq(underlying.balanceOf(address(vault)), 0); + } +} \ No newline at end of file From 7c474ebcd83324f41c8e97d8be9fb5ada0bb66fb Mon Sep 17 00:00:00 2001 From: Imad-Allal Date: Sat, 25 May 2024 10:10:32 +0100 Subject: [PATCH 5/5] Addressing the comments --- src/NovaAdapterBase.sol | 1 - src/NovaVault.sol | 2 -- test/NovaAdapterVelo.t.sol | 32 ++++++++++++++++---------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/NovaAdapterBase.sol b/src/NovaAdapterBase.sol index 61c11c1..89fae18 100644 --- a/src/NovaAdapterBase.sol +++ b/src/NovaAdapterBase.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.13; import {ERC20} from "@solmate/tokens/ERC20.sol"; -import {console} from "forge-std/console.sol"; abstract contract NovaAdapterBase is ERC20 { diff --git a/src/NovaVault.sol b/src/NovaVault.sol index e30ec21..2605318 100644 --- a/src/NovaVault.sol +++ b/src/NovaVault.sol @@ -6,8 +6,6 @@ import {INovaVault} from "./interfaces/INovaVault.sol"; import {INovaAdapterBase} from "./interfaces/INovaAdapterBase.sol"; import {ERC20} from "@solmate/tokens/ERC20.sol"; -import {console} from "forge-std/console.sol"; - contract NovaVault is INovaVault { mapping(address => address) public _novaAdapters; diff --git a/test/NovaAdapterVelo.t.sol b/test/NovaAdapterVelo.t.sol index f77c9a6..225986a 100644 --- a/test/NovaAdapterVelo.t.sol +++ b/test/NovaAdapterVelo.t.sol @@ -9,7 +9,7 @@ import {IVelodromePool} from "../src/interfaces/IVelodromePool.sol"; contract NovaAdapterVeloTest is Test { address public POOL = 0x94c0A04C0d74571aa9EE25Dd6c29E2A36f5699aE; address public sDAI = 0x2218a117083f5B482B0bB821d27056Ba9c04b1D3; - NovaAdapterVelo public vault; + NovaAdapterVelo public adapter; IVelodromePool veloPool; address underlyingAddress; ERC20 underlying; @@ -32,7 +32,7 @@ contract NovaAdapterVeloTest is Test { underlying = ERC20(underlyingAddress); - vault = new NovaAdapterVelo( + adapter = new NovaAdapterVelo( underlying, sDAI, POOL, @@ -50,16 +50,16 @@ contract NovaAdapterVeloTest is Test { underlying.transfer(alice, aliceUnderlyingAmount); vm.prank(alice); - underlying.approve(address(vault), aliceUnderlyingAmount); - assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); + underlying.approve(address(adapter), aliceUnderlyingAmount); + assertEq(underlying.allowance(alice, address(adapter)), aliceUnderlyingAmount); vm.prank(alice); - (bool success, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); + (bool success, uint256 sDaiMinted) = adapter.deposit(aliceUnderlyingAmount); assert(success); assertEq(underlying.balanceOf(alice), 0); - assertEq(vault.balanceOf(alice), sDaiMinted); - assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); + assertEq(adapter.balanceOf(alice), sDaiMinted); + assertEq(ERC20(sDAI).balanceOf(address(adapter)), sDaiMinted); } function testWithdraw() public{ @@ -70,22 +70,22 @@ contract NovaAdapterVeloTest is Test { underlying.transfer(alice, aliceUnderlyingAmount); vm.prank(alice); - underlying.approve(address(vault), aliceUnderlyingAmount); - assertEq(underlying.allowance(alice, address(vault)), aliceUnderlyingAmount); + underlying.approve(address(adapter), aliceUnderlyingAmount); + assertEq(underlying.allowance(alice, address(adapter)), aliceUnderlyingAmount); vm.prank(alice); - (bool succesDeposit, uint256 sDaiMinted) = vault.deposit(aliceUnderlyingAmount); + (bool succesDeposit, uint256 sDaiMinted) = adapter.deposit(aliceUnderlyingAmount); assert(succesDeposit); assertEq(underlying.balanceOf(alice), 0); - assertEq(vault.balanceOf(alice), sDaiMinted); - assertEq(ERC20(sDAI).balanceOf(address(vault)), sDaiMinted); + assertEq(adapter.balanceOf(alice), sDaiMinted); + assertEq(ERC20(sDAI).balanceOf(address(adapter)), sDaiMinted); vm.prank(alice); - (bool successWithdraw, uint256 underlyingWithdrawn) = vault.withdraw(sDaiMinted); + (bool successWithdraw, uint256 underlyingWithdrawn) = adapter.withdraw(sDaiMinted); assert(successWithdraw); assertEq(underlying.balanceOf(alice), underlyingWithdrawn); - assertEq(vault.balanceOf(alice), 0); - assertEq(ERC20(sDAI).balanceOf(address(vault)), 0); - assertEq(underlying.balanceOf(address(vault)), 0); + assertEq(adapter.balanceOf(alice), 0); + assertEq(ERC20(sDAI).balanceOf(address(adapter)), 0); + assertEq(underlying.balanceOf(address(adapter)), 0); } } \ No newline at end of file