Skip to content

Commit

Permalink
fix: uint 128
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Aug 29, 2024
1 parent dc7488e commit db53977
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/L1YearnEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,10 @@ contract L1YearnEscrow is L1Escrow {
* @param _minimumBuffer The new minimum buffer to enforce.
*/
function updateMinimumBuffer(
uint256 _minimumBuffer
uint128 _minimumBuffer
) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
VaultStorage storage $ = _getVaultStorage();
require(_minimumBuffer <= type(uint128).max, "max size");
$.minimumBuffer = uint128(_minimumBuffer);
$.minimumBuffer = _minimumBuffer;

emit UpdateMinimumBuffer(_minimumBuffer);
}
Expand All @@ -316,11 +315,10 @@ contract L1YearnEscrow is L1Escrow {
* @param _depositLimit The new deposit limit to enforce.
*/
function updateDepositLimit(
uint256 _depositLimit
uint128 _depositLimit
) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
VaultStorage storage $ = _getVaultStorage();
require(_depositLimit <= type(uint128).max, "max size");
$.depositLimit = uint128(_depositLimit);
$.depositLimit = _depositLimit;

emit UpdateDepositLimit(_depositLimit);
}
Expand Down
19 changes: 11 additions & 8 deletions test/L1Escrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ contract EscrowTest is Setup {
);
mockEscrow = deployMockL1Escrow();

// Only Admin can update deposit limit
vm.expectRevert();
mockEscrow.updateDepositLimit(0);

Expand All @@ -174,12 +175,13 @@ contract EscrowTest is Setup {
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(_amount);
mockEscrow.updateDepositLimit(uint128(_amount));

bytes memory data = abi.encode(user, _amount);
uint256 depositCount = polygonZkEVMBridge.depositCount();
Expand Down Expand Up @@ -213,7 +215,7 @@ contract EscrowTest is Setup {
mockEscrow.bridgeToken(user, _amount, true);

vm.prank(governator);
mockEscrow.updateDepositLimit(_amount * 2);
mockEscrow.updateDepositLimit(uint128(_amount * 2));

vm.prank(user);
mockEscrow.bridgeToken(user, _amount, true);
Expand Down Expand Up @@ -312,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);

Expand Down Expand Up @@ -355,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)
Expand Down Expand Up @@ -556,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)
Expand Down

0 comments on commit db53977

Please sign in to comment.