-
Notifications
You must be signed in to change notification settings - Fork 0
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
build: deposit limit #17
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,94 @@ contract EscrowTest is Setup { | |
assertEq(vault.balanceOf(address(mockEscrow)), 0); | ||
} | ||
|
||
function test_bridgeAsset_maxDepositLimit(uint256 _amount) public { | ||
function test_bridgeAsset_escrowDepositLimit(uint256 _amount) public { | ||
_amount = bound(_amount, minFuzzAmount, maxFuzzAmount); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can _amount be 0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, will add a section to show that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test using a 0 deposit limit is here https://github.com/yearn/yearn-stb/pull/17/files#diff-52b3b649a24d8bf5f33c53bf9546c7aee0a6133a5503d8525a1a1e5dab36f656R170 |
||
address counterPart = l1Deployer.getL2EscrowAddress( | ||
l2RollupID, | ||
address(asset) | ||
); | ||
mockEscrow = deployMockL1Escrow(); | ||
|
||
// Only Admin can update deposit limit | ||
vm.expectRevert(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some comments would be helpful :) // reverts because caller does is not allowed to change the deposit limit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
mockEscrow.updateDepositLimit(0); | ||
|
||
vm.prank(governator); | ||
mockEscrow.updateDepositLimit(0); | ||
|
||
// Simulate a bridge txn | ||
airdrop(asset, user, _amount); | ||
|
||
vm.prank(user); | ||
asset.approve(address(mockEscrow), _amount); | ||
|
||
// OVer Deposit limit | ||
vm.expectRevert("deposit limit"); | ||
vm.prank(user); | ||
mockEscrow.bridgeToken(user, _amount, true); | ||
|
||
vm.prank(governator); | ||
mockEscrow.updateDepositLimit(uint128(_amount)); | ||
|
||
bytes memory data = abi.encode(user, _amount); | ||
uint256 depositCount = polygonZkEVMBridge.depositCount(); | ||
vm.expectEmit(true, true, true, true, address(polygonZkEVMBridge)); | ||
emit BridgeEvent( | ||
1, | ||
l1RollupID, | ||
address(mockEscrow), | ||
l2RollupID, | ||
counterPart, | ||
0, | ||
data, | ||
uint32(depositCount) | ||
); | ||
vm.prank(user); | ||
mockEscrow.bridgeToken(user, _amount, true); | ||
|
||
assertEq(vault.totalAssets(), _amount); | ||
assertEq(mockEscrow.deposited(), _amount); | ||
assertEq(asset.balanceOf(user), 0); | ||
assertEq(asset.balanceOf(address(mockEscrow)), 0); | ||
assertEq(vault.balanceOf(address(mockEscrow)), _amount); | ||
|
||
airdrop(asset, user, _amount); | ||
|
||
vm.prank(user); | ||
asset.approve(address(mockEscrow), _amount); | ||
|
||
vm.expectRevert("deposit limit"); | ||
vm.prank(user); | ||
mockEscrow.bridgeToken(user, _amount, true); | ||
|
||
vm.prank(governator); | ||
mockEscrow.updateDepositLimit(uint128(_amount * 2)); | ||
|
||
vm.prank(user); | ||
mockEscrow.bridgeToken(user, _amount, true); | ||
|
||
assertEq(vault.totalAssets(), _amount * 2); | ||
assertEq(mockEscrow.deposited(), _amount * 2); | ||
assertEq(asset.balanceOf(user), 0); | ||
assertEq(asset.balanceOf(address(mockEscrow)), 0); | ||
assertEq(vault.balanceOf(address(mockEscrow)), _amount * 2); | ||
|
||
// Withdraw half | ||
uint256 toWithdraw = _amount + 10; | ||
|
||
data = abi.encode(user, toWithdraw); | ||
|
||
vm.prank(address(polygonZkEVMBridge)); | ||
mockEscrow.onMessageReceived(counterPart, l2RollupID, data); | ||
|
||
assertEq(vault.totalAssets(), _amount - 10); | ||
assertEq(mockEscrow.deposited(), _amount * 2 - toWithdraw); | ||
assertEq(asset.balanceOf(user), toWithdraw); | ||
assertEq(asset.balanceOf(address(mockEscrow)), 0); | ||
assertEq(vault.balanceOf(address(mockEscrow)), _amount - 10); | ||
} | ||
|
||
function test_bridgeAsset_vaultDepositLimit(uint256 _amount) public { | ||
_amount = bound(_amount, minFuzzAmount, maxFuzzAmount); | ||
address counterPart = l1Deployer.getL2EscrowAddress( | ||
l2RollupID, | ||
|
@@ -227,17 +314,18 @@ contract EscrowTest is Setup { | |
|
||
function test_bridgeAsset_minimumBuffer( | ||
uint256 _amount, | ||
uint256 _minimumBuffer | ||
uint128 _minimumBuffer | ||
) public { | ||
_amount = bound(_amount, minFuzzAmount, maxFuzzAmount); | ||
_minimumBuffer = bound(_minimumBuffer, 10, maxFuzzAmount); | ||
_minimumBuffer = uint128(bound(_minimumBuffer, 10, maxFuzzAmount)); | ||
address counterPart = l1Deployer.getL2EscrowAddress( | ||
l2RollupID, | ||
address(asset) | ||
); | ||
|
||
mockEscrow = deployMockL1Escrow(); | ||
|
||
// Only Admin can update | ||
vm.expectRevert(); | ||
mockEscrow.updateMinimumBuffer(_minimumBuffer); | ||
|
||
|
@@ -270,9 +358,9 @@ contract EscrowTest is Setup { | |
assertEq(vault.balanceOf(address(mockEscrow)), 0); | ||
} | ||
|
||
function test_rebalance(uint256 _amount, uint256 _minimumBuffer) public { | ||
function test_rebalance(uint256 _amount, uint128 _minimumBuffer) public { | ||
_amount = bound(_amount, minFuzzAmount, maxFuzzAmount); | ||
_minimumBuffer = bound(_minimumBuffer, 10, maxFuzzAmount); | ||
_minimumBuffer = uint128(bound(_minimumBuffer, 10, maxFuzzAmount)); | ||
address counterPart = l1Deployer.getL2EscrowAddress( | ||
l2RollupID, | ||
address(asset) | ||
|
@@ -471,10 +559,10 @@ contract EscrowTest is Setup { | |
|
||
function test_illiquidWithdraw_withBuffer( | ||
uint256 _amount, | ||
uint256 _minimumBuffer | ||
uint128 _minimumBuffer | ||
) public { | ||
_amount = bound(_amount, minFuzzAmount, maxFuzzAmount); | ||
_minimumBuffer = bound(_minimumBuffer, 10, _amount / 2); | ||
_minimumBuffer = uint128(bound(_minimumBuffer, 10, _amount / 2)); | ||
address counterPart = l1Deployer.getL2EscrowAddress( | ||
l2RollupID, | ||
address(asset) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like to use string error codes when using requires (e.g. "DEPOSIT_LIMIT") - or custom errors with reverts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i follow.
Are you saying just change the revert string to "DEPOSIT_LIMIT" instead of "deposit limit" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but it's minor
I find it easier to integrate with frontends etc