Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor v4 to infinity #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Pancake v4 Core

1. `0.8.26` in `foundry.toml` as it provides better gas optimization
2. `.prettierrc` explictly set `singleQuote: false` to overwrite any local dev's settings
# Infinity Core

## Running test

1. Install dependencies with `forge install` and `yarn`
2. Run test with `forge test --isolate`

See https://github.com/pancakeswap/pancake-v4-core/pull/35 on why `--isolate` flag is used.
See https://github.com/pancakeswap/infinity-core/pull/35 on why `--isolate` flag is used.

## Update dependencies

Expand Down Expand Up @@ -45,7 +42,6 @@ forge script script/01_DeployVault.s.sol:DeployVaultScript -vvv \
--slow
```


### Verifying
Each script includes a verification command. Verification needs to be performed separately since the contract is deployed using the create3 method.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pancake-v4-core",
"description": "Pancakeswap smart contracts",
"name": "infinity-core",
"description": "Inifinity core contracts",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion script/01_DeployVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
*/
contract DeployVaultScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/VAULT/0.90");
return keccak256("INFINITY-CORE/VAULT/0.90");
}

function run() public {
Expand Down
2 changes: 1 addition & 1 deletion script/02_DeployCLPoolManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
*/
contract DeployCLPoolManagerScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/CLPoolManager/0.90");
return keccak256("INFINITY-CORE/CLPoolManager/0.90");
}

function run() public {
Expand Down
2 changes: 1 addition & 1 deletion script/03_DeployBinPoolManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
*/
contract DeployBinPoolManagerScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/BinPoolManager/0.90");
return keccak256("INFINITY-CORE/BinPoolManager/0.90");
}

function run() public {
Expand Down
2 changes: 1 addition & 1 deletion script/04a_DeployCLProtocolFeeController.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
*/
contract DeployCLProtocolFeeControllerScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/CLProtocolFeeController/0.91");
return keccak256("INFINITY-CORE/CLProtocolFeeController/0.91");
}

function run() public {
Expand Down
2 changes: 1 addition & 1 deletion script/05a_DeployBinProtocolFeeController.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
*/
contract DeployBinProtocolFeeControllerScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/BinProtocolFeeController/0.91");
return keccak256("INFINITY-CORE-CORE/BinProtocolFeeController/0.91");
}

function run() public {
Expand Down
2 changes: 1 addition & 1 deletion src/pool-cl/interfaces/ICLHooks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uint8 constant HOOKS_AFTER_REMOVE_LIQUIDIY_RETURNS_DELTA_OFFSET = 13;
/// @notice The PoolManager contract decides whether to invoke specific hooks by inspecting the leading bits
/// of the hooks contract address. For example, a 1 bit in the first bit of the address will
/// cause the 'before swap' hook to be invoked. See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
/// @dev Should only be callable by PoolManager.
interface ICLHooks is IHooks {
/// @notice The hook called before the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
Expand Down
1 change: 0 additions & 1 deletion src/test/MockFeePoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ contract MockFeePoolManager is ProtocolFees {
PoolId id = key.toId();
Slot0 memory slot0 = pools[id];

// Similar to uni-v4 logic (deduct protocolFee portion first)
uint24 protocolFee = isSwap ? slot0.protocolFee : 0;

if (protocolFee > 0) {
Expand Down
8 changes: 4 additions & 4 deletions test/pool-bin/BinPoolManagerBehaviorComparison.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ abstract contract LBFuzzer is LBHelper, BinTestHelper {
// lb init
lbPair = ILBPair(lbFactory.createLBPair(address(token0), address(token1), boundActiveId, boundBinStep));

// v4#bin init
// bin init
key_ = PoolKey({
currency0: currency0,
currency1: currency1,
Expand Down Expand Up @@ -113,15 +113,15 @@ abstract contract LBFuzzer is LBHelper, BinTestHelper {
(, bytes32 amountsLeft, uint256[] memory liquidityMinted) =
lbPair.mint(address(this), mintParams.liquidityConfigs, address(this));

// calc v4 positon share before mint
// calc positon share before mint
uint256[] memory sharesBefore = new uint256[](liquidityMinted.length);
for (uint256 i = 0; i < liquidityMinted.length; i++) {
uint24 id = uint24(uint256(mintParams.liquidityConfigs[i]));
BinPosition.Info memory positionInfo = manager.getPosition(key.toId(), address(liquidityHelper), id, 0);
sharesBefore[i] = positionInfo.share;
}

// v4#bin mint
// bin mint
BalanceDelta delta = liquidityHelper.mint(key, mintParams, "");

// check
Expand Down Expand Up @@ -155,7 +155,7 @@ abstract contract LBFuzzer is LBHelper, BinTestHelper {

function swap(ILBPair lbPair, PoolKey memory key, bool swapForY, uint128 amountIn) public {
amountIn = uint128(bound(amountIn, 0.1 ether, 10000 ether));
// v4#bin swap
// bin swap
BinSwapHelper.TestSettings memory testSettings =
BinSwapHelper.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

Expand Down
4 changes: 2 additions & 2 deletions test/pool-bin/helpers/BinMintBurnFeeHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract BinMintBurnFeeHook is BaseBinTestHook {
}

/// @dev take 2x of the mint amount as fee
/// meant for https://github.com/pancakeswap/pancake-v4-core/pull/203 to ensure reserveOfApp underflow won't happen
/// meant for https://github.com/pancakeswap/infinity-core/pull/203 to ensure reserveOfApp underflow won't happen
function afterMint(
address,
PoolKey calldata key,
Expand All @@ -76,7 +76,7 @@ contract BinMintBurnFeeHook is BaseBinTestHook {
}

/// @dev take 4x the burn amount as fee
/// meant for https://github.com/pancakeswap/pancake-v4-core/pull/203 to ensure reserveOfApp underflow won't happen
/// meant for https://github.com/pancakeswap/infinity-core/pull/203 to ensure reserveOfApp underflow won't happen
function afterBurn(
address,
PoolKey calldata key,
Expand Down
2 changes: 1 addition & 1 deletion test/pool-bin/libraries/math/PackedUint128Math.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ contract PackedUint128MathTest is Test {
bytes32 amounts = uint128(type(uint128).max).encode(uint128(type(uint128).max));

/// @dev This shouldn't happen as swapFee passed in will be inclusive of protocolFee
/// However, adding safeCast protects against future extension of v4 in the case the fee is not inclusive
/// However, adding safeCast protects against future extension of infinity in the case the fee is not inclusive
uint24 protocolFee = 100;
uint24 swapFee = 10;

Expand Down
26 changes: 13 additions & 13 deletions test/pool-cl/CLPoolManagerBehaviorComparison.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract contract V3Fuzzer is V3Helper, Deployers, Fuzzers, IUniswapV3MintCallba
router = new CLPoolManagerRouter(vault, manager);

(currency0, currency1) = deployCurrencies(2 ** 255);
// ensure router has enough allowance to move tokens, required for v4
// ensure router has enough allowance to move tokens, required for infinity
IERC20(Currency.unwrap(currency0)).approve(address(router), type(uint256).max);
IERC20(Currency.unwrap(currency1)).approve(address(router), type(uint256).max);
}
Expand Down Expand Up @@ -78,26 +78,26 @@ abstract contract V3Fuzzer is V3Helper, Deployers, Fuzzers, IUniswapV3MintCallba
int256 liquidityDeltaUnbound,
bool tight
) internal {
ICLPoolManager.ModifyLiquidityParams memory v4LiquidityParams = ICLPoolManager.ModifyLiquidityParams({
ICLPoolManager.ModifyLiquidityParams memory infinityLiquidityParams = ICLPoolManager.ModifyLiquidityParams({
tickLower: lowerTickUnsanitized,
tickUpper: upperTickUnsanitized,
liquidityDelta: liquidityDeltaUnbound,
salt: 0
});

v4LiquidityParams = tight
? createFuzzyLiquidityParamsWithTightBound(key_, v4LiquidityParams, sqrtPriceX96, 20)
: createFuzzyLiquidityParams(key_, v4LiquidityParams, sqrtPriceX96);
infinityLiquidityParams = tight
? createFuzzyLiquidityParamsWithTightBound(key_, infinityLiquidityParams, sqrtPriceX96, 20)
: createFuzzyLiquidityParams(key_, infinityLiquidityParams, sqrtPriceX96);

v3Pool.mint(
address(this),
v4LiquidityParams.tickLower,
v4LiquidityParams.tickUpper,
uint128(int128(v4LiquidityParams.liquidityDelta)),
infinityLiquidityParams.tickLower,
infinityLiquidityParams.tickUpper,
uint128(int128(infinityLiquidityParams.liquidityDelta)),
""
);

router.modifyPosition(key_, v4LiquidityParams, "");
router.modifyPosition(key_, infinityLiquidityParams, "");
}

function swap(IUniswapV3Pool pool, PoolKey memory key_, bool zeroForOne, int128 amountSpecified)
Expand All @@ -115,15 +115,15 @@ abstract contract V3Fuzzer is V3Helper, Deployers, Fuzzers, IUniswapV3MintCallba
zeroForOne ? MIN_PRICE_LIMIT : MAX_PRICE_LIMIT,
""
);
// v3 can handle bigger numbers than v4, so if we exceed int128, check that the next call reverts
// v3 can handle bigger numbers than infinity, so if we exceed int128, check that the next call reverts
bool overflows = false;
if (
amount0Delta > type(int128).max || amount1Delta > type(int128).max || amount0Delta < type(int128).min
|| amount1Delta < type(int128).min
) {
overflows = true;
}
// v4 swap
// infinity swap
ICLPoolManager.SwapParams memory swapParams = ICLPoolManager.SwapParams({
zeroForOne: zeroForOne,
amountSpecified: amountSpecified,
Expand All @@ -136,14 +136,14 @@ abstract contract V3Fuzzer is V3Helper, Deployers, Fuzzers, IUniswapV3MintCallba
try router.swap(key_, swapParams, testSettings, "") returns (BalanceDelta delta_) {
delta = delta_;
} catch (bytes memory reason) {
require(overflows, "v4 should not overflow");
require(overflows, "infinity should not overflow");
assertEq(bytes4(reason), SafeCast.SafeCastOverflow.selector);
delta = toBalanceDelta(0, 0);
amount0Delta = 0;
amount1Delta = 0;
}

// because signs for v3 and v4 swaps are inverted, add values up to get the difference
// because signs for v3 and infinity swaps are inverted, add values up to get the difference
amount0Diff = amount0Delta + delta.amount0();
amount1Diff = amount1Delta + delta.amount1();
}
Expand Down
4 changes: 2 additions & 2 deletions test/pool-cl/helpers/CLMintBurnFeeHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract CLMintBurnFeeHook is BaseCLTestHook {
}

/// @dev take 2x of the mint amount as fee
/// meant for https://github.com/pancakeswap/pancake-v4-core/pull/203 to ensure reserveOfApp underflow won't happen
/// meant for https://github.com/pancakeswap/infinity-core/pull/203 to ensure reserveOfApp underflow won't happen
function afterAddLiquidity(
address,
PoolKey calldata key,
Expand All @@ -75,7 +75,7 @@ contract CLMintBurnFeeHook is BaseCLTestHook {
}

/// @dev take 4x the burn amount as fee
/// meant for https://github.com/pancakeswap/pancake-v4-core/pull/203 to ensure reserveOfApp underflow won't happen
/// meant for https://github.com/pancakeswap/infinity-core/pull/203 to ensure reserveOfApp underflow won't happen
function afterRemoveLiquidity(
address,
PoolKey calldata key,
Expand Down
Loading