-
Notifications
You must be signed in to change notification settings - Fork 343
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
fix(contracts): add rebasing compatibility for HypERC4626
#4524
base: main
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 |
---|---|---|
|
@@ -108,6 +108,11 @@ contract HypERC4626CollateralTest is HypTokenTest { | |
_connectRouters(domains, addresses); | ||
} | ||
|
||
function testDisableInitializers() public { | ||
vm.expectRevert("Initializable: contract is already initialized"); | ||
remoteToken.initialize(0, "", "", address(0), address(0), address(0)); | ||
} | ||
|
||
function test_collateralDomain() public view { | ||
assertEq( | ||
remoteRebasingToken.collateralDomain(), | ||
|
@@ -172,6 +177,108 @@ contract HypERC4626CollateralTest is HypTokenTest { | |
); | ||
} | ||
|
||
function testTransferFrom() public { | ||
Check notice Code scanning / Olympix Integrated Security Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
|
||
_performRemoteTransferWithoutExpectation(0, transferAmount); | ||
assertEq(remoteToken.balanceOf(BOB), transferAmount); | ||
|
||
uint256 transferAmount2 = 50e18; | ||
vm.prank(BOB); | ||
remoteToken.approve(CAROL, transferAmount2); | ||
|
||
vm.prank(CAROL); | ||
bool success = remoteToken.transferFrom(BOB, DANIEL, transferAmount2); | ||
assertTrue(success, "TransferFrom should succeed"); | ||
|
||
assertEq( | ||
remoteToken.balanceOf(BOB), | ||
transferAmount - transferAmount2, | ||
"BOB's balance should decrease" | ||
); | ||
assertEq( | ||
remoteToken.balanceOf(DANIEL), | ||
transferAmount2, | ||
"DANIEL's balance should increase" | ||
); | ||
assertEq( | ||
remoteToken.allowance(BOB, CAROL), | ||
0, | ||
"Allowance should be zero after transfer" | ||
); | ||
} | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
|
||
function testTransferEvent() public { | ||
Check notice Code scanning / Olympix Integrated Security Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
|
||
_performRemoteTransferWithoutExpectation(0, transferAmount); | ||
assertEq(remoteToken.balanceOf(BOB), transferAmount); | ||
|
||
uint256 transferAmount2 = 50e18; | ||
vm.expectEmit(true, true, false, true); | ||
emit Transfer(BOB, CAROL, transferAmount2); | ||
|
||
vm.prank(BOB); | ||
remoteToken.transfer(CAROL, transferAmount2); | ||
|
||
assertEq( | ||
remoteToken.balanceOf(BOB), | ||
transferAmount - transferAmount2, | ||
"BOB's balance should decrease" | ||
); | ||
assertEq( | ||
remoteToken.balanceOf(CAROL), | ||
transferAmount2, | ||
"CAROL's balance should increase" | ||
); | ||
} | ||
|
||
function testTotalShares() public { | ||
Check notice Code scanning / Olympix Integrated Security Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
|
||
uint256 initialShares = remoteRebasingToken.totalShares(); | ||
assertEq(initialShares, 0, "Initial shares should be zero"); | ||
|
||
_performRemoteTransferWithoutExpectation(0, transferAmount); | ||
uint256 sharesAfterTransfer = remoteRebasingToken.totalShares(); | ||
assertEq( | ||
sharesAfterTransfer, | ||
remoteRebasingToken.assetsToShares(transferAmount), | ||
"Shares should match transferred amount converted to shares" | ||
); | ||
|
||
_accrueYield(); | ||
localRebasingToken.rebase(DESTINATION); | ||
remoteMailbox.processNextInboundMessage(); | ||
|
||
uint256 sharesAfterYield = remoteRebasingToken.totalShares(); | ||
assertEq( | ||
sharesAfterYield, | ||
sharesAfterTransfer, | ||
"Total shares should remain constant after yield accrual" | ||
); | ||
} | ||
|
||
function testShareBalanceOf() public { | ||
Check notice Code scanning / Olympix Integrated Security Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
|
||
_performRemoteTransferWithoutExpectation(0, transferAmount); | ||
|
||
uint256 bobShareBalance = remoteRebasingToken.shareBalanceOf(BOB); | ||
assertEq( | ||
bobShareBalance, | ||
remoteRebasingToken.assetsToShares(transferAmount), | ||
"Bob's share balance should match transferred amount converted to shares" | ||
); | ||
|
||
_accrueYield(); | ||
localRebasingToken.rebase(DESTINATION); | ||
remoteMailbox.processNextInboundMessage(); | ||
|
||
uint256 bobShareBalanceAfterYield = remoteRebasingToken.shareBalanceOf( | ||
BOB | ||
); | ||
assertEq( | ||
bobShareBalanceAfterYield, | ||
bobShareBalance, | ||
"Bob's share balance should remain constant after yield accrual" | ||
); | ||
} | ||
|
||
function testWithdrawalWithoutYield() public { | ||
_performRemoteTransferWithoutExpectation(0, transferAmount); | ||
assertEq(remoteToken.balanceOf(BOB), transferAmount); | ||
|
@@ -385,6 +492,32 @@ contract HypERC4626CollateralTest is HypTokenTest { | |
); | ||
} | ||
|
||
function testTotalSupply() public { | ||
Check notice Code scanning / Olympix Integrated Security Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
Reentrant functions which emit events after making an external call may lead to out-of-order events. For more information, visit: http://detectors.olympixdevsectools.com/article/web3-vulnerability/reentrancy-events
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. annoying that this is showing up here |
||
uint256 initialSupply = remoteToken.totalSupply(); | ||
assertEq(initialSupply, 0, "Initial supply should be zero"); | ||
|
||
_performRemoteTransferWithoutExpectation(0, transferAmount); | ||
uint256 supplyAfterTransfer = remoteToken.totalSupply(); | ||
assertEq( | ||
supplyAfterTransfer, | ||
transferAmount, | ||
"Supply should match transferred amount" | ||
); | ||
|
||
_accrueYield(); | ||
localRebasingToken.rebase(DESTINATION); | ||
remoteMailbox.processNextInboundMessage(); | ||
|
||
uint256 supplyAfterYield = remoteToken.totalSupply(); | ||
assertApproxEqRelDecimal( | ||
supplyAfterYield, | ||
transferAmount + _discountedYield(), | ||
1e14, | ||
0, | ||
"Supply should include yield" | ||
); | ||
} | ||
|
||
function testTransfer_withHookSpecified( | ||
uint256, | ||
bytes calldata | ||
|
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.
does this not already emit an event?
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.
It does but the event will shares amount as transferAmount in the event which is not desirable