removed PriceConstraint and implemented LineConstraint; MockDeploy copied/separated from Deploy

This commit is contained in:
Tim Olson
2023-11-01 17:56:25 -04:00
parent 7b64745438
commit 03b7ac11e3
7 changed files with 122 additions and 49 deletions

View File

@@ -142,4 +142,23 @@ contract MockEnv {
);
return swapper.exactInputSingle(params);
}
function price() public view returns (uint160 sqrtPrice) {
(sqrtPrice,,,,,,) = pool.slot0();
}
function swapToPrice(uint160 sqrtPriceLimitX96) public {
console2.log('swapToPrice');
console2.log(sqrtPriceLimitX96);
uint160 curPrice = price();
console2.log(curPrice);
if( curPrice == sqrtPriceLimitX96 )
return;
MockERC20 inToken = curPrice > sqrtPriceLimitX96 ? MockERC20(token0) : MockERC20(token1);
MockERC20 outToken = curPrice < sqrtPriceLimitX96 ? MockERC20(token0) : MockERC20(token1);
// instead of calculating how much we need, we just mint an absurd amount
uint256 aLot = 2**100;
inToken.mint(address(this), aLot);
swap(inToken, outToken, aLot, sqrtPriceLimitX96);
}
}