Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💥 Implement ERC-4626 Tokenised Vault #74

Merged
merged 34 commits into from
Feb 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9960760
🔨 started implementing ERC4626
pcaversaccio Feb 15, 2023
bb2e9f5
📖 add README and CHANGELOG entries
pcaversaccio Feb 16, 2023
7b621eb
🔨 mul_div function
pcaversaccio Feb 16, 2023
5cad78d
🔨 mul_div tests
pcaversaccio Feb 16, 2023
d2acac9
🔨 fix overflow failing test
pcaversaccio Feb 16, 2023
cedc942
🔨 further small optimisation in mul_div
pcaversaccio Feb 17, 2023
58a5824
♻️ fix yarn.lock & update submodules
pcaversaccio Feb 17, 2023
61862fd
Merge branch 'main' into feat/erc4626
pcaversaccio Feb 17, 2023
478d087
🕵️ change `~empty(uint256)` to `max_value(uint256)` for gas optimisation
pcaversaccio Feb 19, 2023
0ad5cf4
♻️ cleanup
pcaversaccio Feb 19, 2023
e2a5b8f
Merge branch 'main' into feat/erc4626
pcaversaccio Feb 19, 2023
c3af8cf
Merge branch 'main' into feat/erc4626
pcaversaccio Feb 20, 2023
3b86485
♻️ bump @types/node
pcaversaccio Feb 20, 2023
b2cb791
Merge branch 'main' into feat/erc4626
pcaversaccio Feb 20, 2023
e8d43ca
👀 first version
pcaversaccio Feb 20, 2023
1d50a47
⛏ fix link in ERC20
pcaversaccio Feb 21, 2023
0457787
✍🏽 code comments
pcaversaccio Feb 21, 2023
7a1f0ca
✍🏽 further code comments
pcaversaccio Feb 21, 2023
c785a4c
✍🏽 further code comments
pcaversaccio Feb 21, 2023
f4bed69
Merge branch 'main' into feat/erc4626
pcaversaccio Feb 22, 2023
f2f8d9e
🔨 erc4626 test setup
pcaversaccio Feb 22, 2023
328a36e
forge install: erc4626-tests
pcaversaccio Feb 22, 2023
de44bef
🔨 erc4626 fuzz tests
pcaversaccio Feb 22, 2023
7046a10
🔨 increase max rejects
pcaversaccio Feb 22, 2023
66ab83a
🔨 initial setup tests
pcaversaccio Feb 23, 2023
f3bc2e0
🔨 testEmptyVaultDeposit
pcaversaccio Feb 23, 2023
f639e9c
🔨 tests EmptyVault
pcaversaccio Feb 24, 2023
d666483
🔨 furter ERC4626 tests
pcaversaccio Feb 24, 2023
cc15b96
🔨 invariant tests
pcaversaccio Feb 24, 2023
896f110
📖 add comments on external code size checks
pcaversaccio Feb 24, 2023
1e6783b
⬆️ update to solc 0.8.19
pcaversaccio Feb 25, 2023
b3e09e3
♻️ bump eslint and submodules
pcaversaccio Feb 26, 2023
5319c91
♻️ refactors and gas snapshot
pcaversaccio Feb 26, 2023
4e8ba3f
♻️ correct test code comments
pcaversaccio Feb 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔨 testEmptyVaultDeposit
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed Feb 23, 2023
commit f3bc2e0fa1a00538bda0d2614cbf136b3275c575
198 changes: 197 additions & 1 deletion test/extensions/ERC4626.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ contract ERC4626VaultTest is ERC4626Test {

address private deployer = address(vyperDeployer);
address private underlyingAddr = address(underlying);
// solhint-disable-next-line var-name-mixedcase
address private zeroAddress = address(0);
/* solhint-disable var-name-mixedcase */
address private ERC4626ExtendedDecimalsOffset0Addr;
address private ERC4626ExtendedDecimalsOffset6Addr;
address private ERC4626ExtendedDecimalsOffset12Addr;
address private ERC4626ExtendedDecimalsOffset18Addr;
/* solhint-enable var-name-mixedcase */

event Transfer(address indexed from, address indexed to, uint256 value);

Expand Down Expand Up @@ -118,6 +123,9 @@ contract ERC4626VaultTest is ERC4626Test {
argsDecimalsOffset6
)
);
ERC4626ExtendedDecimalsOffset6Addr = address(
ERC4626ExtendedDecimalsOffset6
);

bytes memory argsDecimalsOffset12 = abi.encode(
_NAME,
Expand All @@ -134,6 +142,9 @@ contract ERC4626VaultTest is ERC4626Test {
argsDecimalsOffset12
)
);
ERC4626ExtendedDecimalsOffset12Addr = address(
ERC4626ExtendedDecimalsOffset12
);

bytes memory argsDecimalsOffset18 = abi.encode(
_NAME,
Expand All @@ -150,6 +161,9 @@ contract ERC4626VaultTest is ERC4626Test {
argsDecimalsOffset18
)
);
ERC4626ExtendedDecimalsOffset18Addr = address(
ERC4626ExtendedDecimalsOffset18
);

/**
* @dev ERC-4626 property tests (https://github.com/a16z/erc4626-tests) setup.
Expand Down Expand Up @@ -250,4 +264,186 @@ contract ERC4626VaultTest is ERC4626Test {
)
);
}

function testEmptyVaultDeposit() public {
address holder = makeAddr("holder");
address receiver = makeAddr("receiver");
uint256 assets = 1;
uint256 shares = 1;
vm.startPrank(holder);
underlying.mint(holder, type(uint16).max);
underlying.approve(
ERC4626ExtendedDecimalsOffset0Addr,
type(uint256).max
);
underlying.approve(
ERC4626ExtendedDecimalsOffset6Addr,
type(uint256).max
);
underlying.approve(
ERC4626ExtendedDecimalsOffset12Addr,
type(uint256).max
);
underlying.approve(
ERC4626ExtendedDecimalsOffset18Addr,
type(uint256).max
);

assertEq(ERC4626ExtendedDecimalsOffset0.totalAssets(), 0);
assertEq(
ERC4626ExtendedDecimalsOffset0.maxDeposit(holder),
type(uint256).max
);
assertEq(ERC4626ExtendedDecimalsOffset0.previewDeposit(assets), shares);

assertEq(ERC4626ExtendedDecimalsOffset6.totalAssets(), 0);
assertEq(
ERC4626ExtendedDecimalsOffset6.maxDeposit(holder),
type(uint256).max
);
assertEq(
ERC4626ExtendedDecimalsOffset6.previewDeposit(assets),
shares * 10 ** 6
);

assertEq(ERC4626ExtendedDecimalsOffset12.totalAssets(), 0);
assertEq(
ERC4626ExtendedDecimalsOffset12.maxDeposit(holder),
type(uint256).max
);
assertEq(
ERC4626ExtendedDecimalsOffset12.previewDeposit(assets),
shares * 10 ** 12
);

assertEq(ERC4626ExtendedDecimalsOffset18.totalAssets(), 0);
assertEq(
ERC4626ExtendedDecimalsOffset18.maxDeposit(holder),
type(uint256).max
);
assertEq(
ERC4626ExtendedDecimalsOffset18.previewDeposit(assets),
shares * 10 ** 18
);

vm.expectEmit(true, true, false, true, underlyingAddr);
emit Transfer(holder, ERC4626ExtendedDecimalsOffset0Addr, assets);
vm.expectEmit(
true,
true,
false,
true,
ERC4626ExtendedDecimalsOffset0Addr
);
emit Transfer(zeroAddress, receiver, shares);
vm.expectEmit(
true,
true,
true,
true,
ERC4626ExtendedDecimalsOffset0Addr
);
emit Deposit(holder, receiver, assets, shares);
ERC4626ExtendedDecimalsOffset0.deposit(assets, receiver);

vm.expectEmit(true, true, false, true, underlyingAddr);
emit Transfer(holder, ERC4626ExtendedDecimalsOffset6Addr, assets);
vm.expectEmit(
true,
true,
false,
true,
ERC4626ExtendedDecimalsOffset6Addr
);
emit Transfer(zeroAddress, receiver, shares * 10 ** 6);
vm.expectEmit(
true,
true,
true,
true,
ERC4626ExtendedDecimalsOffset6Addr
);
emit Deposit(holder, receiver, assets, shares * 10 ** 6);
ERC4626ExtendedDecimalsOffset6.deposit(assets, receiver);

vm.expectEmit(true, true, false, true, underlyingAddr);
emit Transfer(holder, ERC4626ExtendedDecimalsOffset12Addr, assets);
vm.expectEmit(
true,
true,
false,
true,
ERC4626ExtendedDecimalsOffset12Addr
);
emit Transfer(zeroAddress, receiver, shares * 10 ** 12);
vm.expectEmit(
true,
true,
true,
true,
ERC4626ExtendedDecimalsOffset12Addr
);
emit Deposit(holder, receiver, assets, shares * 10 ** 12);
ERC4626ExtendedDecimalsOffset12.deposit(assets, receiver);

vm.expectEmit(true, true, false, true, underlyingAddr);
emit Transfer(holder, ERC4626ExtendedDecimalsOffset18Addr, assets);
vm.expectEmit(
true,
true,
false,
true,
ERC4626ExtendedDecimalsOffset18Addr
);
emit Transfer(zeroAddress, receiver, shares * 10 ** 18);
vm.expectEmit(
true,
true,
true,
true,
ERC4626ExtendedDecimalsOffset18Addr
);
emit Deposit(holder, receiver, assets, shares * 10 ** 18);
ERC4626ExtendedDecimalsOffset18.deposit(assets, receiver);

assertEq(underlying.balanceOf(holder), type(uint16).max - 4);
assertEq(ERC4626ExtendedDecimalsOffset0.totalAssets(), assets);
assertEq(ERC4626ExtendedDecimalsOffset0.balanceOf(holder), 0);
assertEq(ERC4626ExtendedDecimalsOffset0.balanceOf(receiver), shares);
assertEq(ERC4626ExtendedDecimalsOffset0.totalSupply(), shares);

assertEq(ERC4626ExtendedDecimalsOffset6.totalAssets(), assets);
assertEq(ERC4626ExtendedDecimalsOffset6.balanceOf(holder), 0);
assertEq(
ERC4626ExtendedDecimalsOffset6.balanceOf(receiver),
shares * 10 ** 6
);
assertEq(
ERC4626ExtendedDecimalsOffset6.totalSupply(),
shares * 10 ** 6
);

assertEq(ERC4626ExtendedDecimalsOffset12.totalAssets(), assets);
assertEq(ERC4626ExtendedDecimalsOffset12.balanceOf(holder), 0);
assertEq(
ERC4626ExtendedDecimalsOffset12.balanceOf(receiver),
shares * 10 ** 12
);
assertEq(
ERC4626ExtendedDecimalsOffset12.totalSupply(),
shares * 10 ** 12
);

assertEq(ERC4626ExtendedDecimalsOffset18.totalAssets(), assets);
assertEq(ERC4626ExtendedDecimalsOffset18.balanceOf(holder), 0);
assertEq(
ERC4626ExtendedDecimalsOffset18.balanceOf(receiver),
shares * 10 ** 18
);
assertEq(
ERC4626ExtendedDecimalsOffset18.totalSupply(),
shares * 10 ** 18
);
vm.stopPrank();
}
}