Skip to content

Commit 97497e1

Browse files
committed
init: deposit test
1 parent 354205f commit 97497e1

5 files changed

Lines changed: 155 additions & 0 deletions

File tree

Makefile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
-include .env
2+
3+
.PHONY: all test clean deploy fund help install snapshot format anvil
4+
5+
DEFAULT_ANVIL_KEY := 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
6+
7+
help:
8+
@echo "Usage:"
9+
@echo " make deploy [ARGS=...]\n example: make deploy ARGS=\"--network sepolia\""
10+
@echo ""
11+
@echo " make fund [ARGS=...]\n example: make deploy ARGS=\"--network sepolia\""
12+
13+
all: clean remove install update build
14+
15+
# Clean the repo
16+
clean :; forge clean
17+
18+
# Remove modules
19+
remove :; rm -rf .gitmodules && rm -rf .git/modules/* && rm -rf lib && touch .gitmodules && git add . && git commit -m "modules"
20+
21+
install :; forge install Cyfrin/foundry-devops && forge install foundry-rs/forge-std && forge install OpenZeppelin/openzeppelin-contracts && forge install vectorized/solady
22+
23+
# Update Dependencies
24+
update:; forge update
25+
26+
build:; forge build
27+
28+
FORK_NETWORK_ARGS := --fork-url mainnet --block-number $(BLOCK_NUMBER) --etherscan-api-key etherscan_api_key
29+
30+
test :; forge test $(FORK_NETWORK_ARGS)
31+
32+
snapshot :; forge snapshot
33+
34+
format :; forge fmt
35+
36+
anvil :; anvil -m 'test test test test test test test test test test test junk' --steps-tracing --block-time 1
37+
38+
gasReport:
39+
forge test $(FORK_NETWORK_ARGS) --gas-report
40+
41+
coverage:
42+
forge coverage $(FORK_NETWORK_ARGS)
43+
44+
coverageLCOV:
45+
forge coverage $(FORK_NETWORK_ARGS) --report lcov
46+
47+
48+
testDeposit:
49+
forge test --mt test_deposit $(FORK_NETWORK_ARGS) -vvvv --json

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
This is a minimal implementation of a [ERC-4626](https://eips.ethereum.org/EIPS/eip-4626)(Vault).
66

7+
This SimpleVault accepts an ERC20 token and issues shares with respect to it.
8+
9+
80% of the deposited token is split equally and supplied between Aave Pool and Morpho Vault.
710

811
Reference:
912

script/HelperConfig.s.sol

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+
pragma solidity 0.8.30;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
6+
contract HelperConfig is Script {
7+
struct NetworkConfig {
8+
address usdc;
9+
address morpho_vault;
10+
address aave_pool;
11+
uint256 entryFee;
12+
uint256 exitFee;
13+
address usdc_holder;
14+
}
15+
16+
address internal constant ETH_USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
17+
address internal constant ETH_MORPHO_VAULT = 0xbeeff2C5bF38f90e3482a8b19F12E5a6D2FCa757;
18+
address internal constant ETH_AAVE_POOL = 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2;
19+
address internal constant ETH_USDC_HOLDER = 0xE20d20b0cC4e44Cd23D5B0488D5250A9ac426875;
20+
21+
uint256 internal constant ENTRY_FEE = 5; // 0.05% in BPS
22+
uint256 internal constant EXIT_FEE = 10; // 0.1% in BPS
23+
24+
function getNetworkConfig() public view returns (NetworkConfig memory config) {
25+
if (block.chainid == 1) {
26+
config = getMainnetConfig();
27+
}
28+
}
29+
30+
function getMainnetConfig() public pure returns (NetworkConfig memory config) {
31+
config = NetworkConfig({
32+
usdc: ETH_USDC,
33+
morpho_vault: ETH_MORPHO_VAULT,
34+
aave_pool: ETH_AAVE_POOL,
35+
entryFee: ENTRY_FEE,
36+
exitFee: EXIT_FEE,
37+
usdc_holder: ETH_USDC_HOLDER
38+
});
39+
}
40+
}

src/lib/Errors.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pragma solidity ^0.8.30;
33

44
library Errors {
55
error ZeroAddress();
6+
error InvalidInputs();
67
}

test/unit/SimpleVault.t.sol

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+
pragma solidity 0.8.30;
3+
4+
import {Test} from "forge-std/Test.sol";
5+
import {IERC20} from "@openzeppelin/interfaces/IERC20.sol";
6+
7+
import {SimpleVault} from "../../src/SimpleVault.sol";
8+
import {SimpleStrategy} from "../../src/SimpleStrategy.sol";
9+
10+
import {HelperConfig} from "../../script/HelperConfig.s.sol";
11+
12+
contract SimpleVaultTest is Test {
13+
SimpleVault vault;
14+
SimpleStrategy strategy;
15+
16+
HelperConfig.NetworkConfig networkConfig;
17+
18+
address feeRecipient;
19+
address user;
20+
21+
uint256 public constant USDC_TO_MINT = 100_000_000e6;
22+
23+
function setUp() public {
24+
HelperConfig config = new HelperConfig();
25+
networkConfig = config.getNetworkConfig();
26+
27+
vault = new SimpleVault(networkConfig.usdc);
28+
29+
strategy = new SimpleStrategy(address(vault), networkConfig.aave_pool, networkConfig.morpho_vault);
30+
31+
feeRecipient = makeAddr("FEE_RECIPIENT");
32+
user = makeAddr("USER");
33+
34+
vault.setStrategy(address(strategy));
35+
vault.setEntryFee(networkConfig.entryFee);
36+
vault.setExitFee(networkConfig.exitFee);
37+
vault.setFeeRecipient(feeRecipient);
38+
39+
vm.prank(networkConfig.usdc_holder);
40+
IERC20(networkConfig.usdc).transfer(user, USDC_TO_MINT);
41+
}
42+
43+
function test_symbol() public view {
44+
assertEq(vault.symbol(), "SV");
45+
}
46+
47+
function test_name() public view {
48+
assertEq(vault.name(), "Simple Vault");
49+
}
50+
51+
function test_asset() public view {
52+
assertEq(vault.asset(), networkConfig.usdc);
53+
}
54+
55+
function test_deposit() public {
56+
uint256 depositAmount = 100_000e6;
57+
58+
vm.startPrank(user);
59+
IERC20(networkConfig.usdc).approve(address(vault), depositAmount);
60+
vault.deposit(depositAmount, user);
61+
}
62+
}

0 commit comments

Comments
 (0)