Skip to content

Commit

Permalink
test: add random amounts to target functions
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Jun 25, 2024
1 parent f234d46 commit 34bc281
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions test/invariant/RMMHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,26 +157,30 @@ contract RMMHandler is CommonBase, StdUtils, StdCheats {
ghost_totalLiquidity += int256(deltaLiquidity);
}

function swapExactTokenForYt() public createActor countCall(this.swapExactTokenForYt.selector) {
uint256 amountIn = 1 ether;
deal(currentActor, amountIn);
function swapExactTokenForYt(uint256 amountTokenIn)
public
createActor
countCall(this.swapExactTokenForYt.selector)
{
amountTokenIn = bound(amountTokenIn, 0.1 ether, 100 ether);
deal(currentActor, amountTokenIn);

vm.startPrank(currentActor);
weth.deposit{value: amountIn}();
weth.deposit{value: amountTokenIn}();

PYIndex index = YT.newIndex();

(uint256 syMinted, uint256 ytOut) =
rmm.computeTokenToYT(index, address(weth), amountIn, 10 ether, block.timestamp, 0, 1_000);
rmm.computeTokenToYT(index, address(weth), amountTokenIn, 10 ether, block.timestamp, 0, 1_000);

uint256 amountPtIn = rmm.computeSYToYT(index, syMinted, 10 ether, block.timestamp, ytOut, 0.005 ether);
(uint256 amountInWad, uint256 amountOutWad,, int256 deltaLiquidity,) =
rmm.prepareSwapPtIn(amountPtIn, block.timestamp, index);

weth.approve(address(rmm), amountIn);
weth.approve(address(rmm), amountTokenIn);
rmm.swapExactTokenForYt(
address(weth),
amountIn,
amountTokenIn,
ytOut,
syMinted,
ytOut.mulDivDown(99, 100),
Expand All @@ -192,8 +196,8 @@ contract RMMHandler is CommonBase, StdUtils, StdCheats {
ghost_totalLiquidity += int256(deltaLiquidity);
}

function swapExactPtForSy() public createActor countCall(this.swapExactPtForSy.selector) {
uint256 amountIn = 1 ether;
function swapExactPtForSy(uint256 amountIn) public createActor countCall(this.swapExactPtForSy.selector) {
amountIn = bound(amountIn, 0.1 ether, 100 ether);
deal(address(PT), currentActor, amountIn);
vm.startPrank(currentActor);
PT.approve(address(rmm), amountIn);
Expand All @@ -205,9 +209,8 @@ contract RMMHandler is CommonBase, StdUtils, StdCheats {
ghost_totalLiquidity += int256(deltaLiquidity);
}

function swapExactSyForPt() public createActor countCall(this.swapExactSyForPt.selector) {
uint256 amountIn = 1 ether;

function swapExactSyForPt(uint256 amountIn) public createActor countCall(this.swapExactSyForPt.selector) {
amountIn = bound(amountIn, 0.1 ether, 100 ether);
deal(address(SY), currentActor, amountIn);
vm.startPrank(currentActor);
SY.approve(address(rmm), amountIn);
Expand All @@ -219,8 +222,8 @@ contract RMMHandler is CommonBase, StdUtils, StdCheats {
ghost_totalLiquidity += int256(deltaLiquidity);
}

function swapExactYtForSy() public createActor countCall(this.swapExactYtForSy.selector) {
uint256 ytIn = 1 ether;
function swapExactYtForSy(uint256 ytIn) public createActor countCall(this.swapExactYtForSy.selector) {
ytIn = bound(ytIn, 0.1 ether, 100 ether);

deal(address(YT), currentActor, ytIn);
vm.startPrank(currentActor);
Expand Down

0 comments on commit 34bc281

Please sign in to comment.