Skip to content

Commit

Permalink
fix swap router corner case (#56)
Browse files Browse the repository at this point in the history
* fix swap router corner case

* fix test when not enough supply amount

* better error msg
  • Loading branch information
shunjizhan authored Jun 27, 2024
1 parent 3190596 commit 784ae22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/SwapAndStakeEuphratesRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ contract SwapAndStakeEuphratesRouter is BaseRouter {
}

function routeImpl(ERC20 token) internal override {
// transfer supplyAmount to maker if possible
token.safeTransfer(_instructions.maker, Math.min(_instructions.supplyAmount, token.balanceOf(address(this))));
if (token.balanceOf(address(this)) < _instructions.supplyAmount) {
revert("SwapAndStakeEuphratesRouter: not enough token supplied");
}
token.safeTransfer(_instructions.maker, _instructions.supplyAmount);

// stake remain token to euphrates pool
if (address(token) == address(IStakingTo(_instructions.euphrates).shareTypes(_instructions.poolId))) {
Expand Down
9 changes: 1 addition & 8 deletions test/SwapAndStakeEuphratesRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,8 @@ contract SwapAndStakeEuphratesRouterTest is Test {
assertEq(euphrates.shares(0, alice), 0);

vm.prank(bob);
vm.expectRevert("SwapAndStakeEuphratesRouter: not enough token supplied");
router.routeNoFee(token1);
assertEq(token1.balanceOf(address(router)), 0);
assertEq(token2.balanceOf(address(router)), 0);
assertEq(token1.balanceOf(alice), 0);
assertEq(token2.balanceOf(alice), 0);
assertEq(token1.balanceOf(maker), 6 ether);
assertEq(token2.balanceOf(maker), 0);
assertEq(token1.balanceOf(address(euphrates)), 0);
assertEq(euphrates.shares(0, alice), 0);
}

function testRescure_withTargetToken() public {
Expand Down

0 comments on commit 784ae22

Please sign in to comment.