Skip to content

Commit

Permalink
fix(v4-sdk): Update initializePool parameters (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 authored Oct 22, 2024
1 parent f0ec7ee commit d910d6b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
12 changes: 3 additions & 9 deletions sdks/v4-sdk/src/PositionManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ describe('PositionManager', () => {
* 1) "initializePool((address,address,uint24,int24,address),uint160,bytes)"
(0x0000000000000000000000000000000000000001, 0x0000000000000000000000000000000000000002, 3000, 60, 0x0000000000000000000000000000000000000000)
79228162514264337593543950336
0x00
*/
expect(calldata).toEqual(
'0x3b1fda97000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000'
'0xf7020405000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000'
)
expect(value).toEqual('0x00')
})
Expand All @@ -84,10 +83,9 @@ describe('PositionManager', () => {
* 1) "initializePool((address,address,uint24,int24,address),uint160,bytes)"
(0x0000000000000000000000000000000000000001, 0x0000000000000000000000000000000000000002, 3000, 60, 0x1100000000000000000000000000000000002401)
79228162514264337593543950336
0x00
*/
expect(calldata).toEqual(
'0x3b1fda97000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000003c0000000000000000000000001100000000000000000000000000000000002401000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000'
'0xf7020405000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000011000000000000000000000000000000000024010000000000000000000000000000000000000001000000000000000000000000'
)
expect(value).toEqual('0x00')
})
Expand Down Expand Up @@ -219,11 +217,7 @@ describe('PositionManager', () => {
const calldataList = Multicall.decodeMulticall(calldata)
// Expect initializePool to be called correctly
expect(calldataList[0]).toEqual(
V4PositionManager.INTERFACE.encodeFunctionData('initializePool', [
pool_0_1.poolKey,
SQRT_PRICE_1_1.toString(),
EMPTY_BYTES,
])
V4PositionManager.INTERFACE.encodeFunctionData('initializePool', [pool_0_1.poolKey, SQRT_PRICE_1_1.toString()])
)
const planner = new V4Planner()
const { amount0: amount0Max, amount1: amount1Max } = position.mintAmountsWithSlippage(slippageTolerance)
Expand Down
11 changes: 4 additions & 7 deletions sdks/v4-sdk/src/PositionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ export abstract class V4PositionManager {
/**
* Public methods to encode method parameters for different actions on the PositionManager contract
*/
public static createCallParameters(poolKey: PoolKey, sqrtPriceX96: BigintIsh, hookData?: string): MethodParameters {
public static createCallParameters(poolKey: PoolKey, sqrtPriceX96: BigintIsh): MethodParameters {
return {
calldata: this.encodeInitializePool(poolKey, sqrtPriceX96, hookData),
calldata: this.encodeInitializePool(poolKey, sqrtPriceX96),
value: toHex(0),
}
}
Expand All @@ -237,9 +237,7 @@ export abstract class V4PositionManager {
// Encode initialize pool.
if (isMint(options) && shouldCreatePool(options)) {
// No planner used here because initializePool is not supported as an Action
calldataList.push(
V4PositionManager.encodeInitializePool(position.pool.poolKey, options.sqrtPriceX96!, options.hookData)
)
calldataList.push(V4PositionManager.encodeInitializePool(position.pool.poolKey, options.sqrtPriceX96!))
}

// adjust for slippage
Expand Down Expand Up @@ -412,11 +410,10 @@ export abstract class V4PositionManager {
}

// Initialize a pool
private static encodeInitializePool(poolKey: PoolKey, sqrtPriceX96: BigintIsh, hookData?: string): string {
private static encodeInitializePool(poolKey: PoolKey, sqrtPriceX96: BigintIsh): string {
return V4PositionManager.INTERFACE.encodeFunctionData(PositionFunctions.INITIALIZE_POOL, [
poolKey,
sqrtPriceX96.toString(),
hookData ?? '0x',
])
}

Expand Down
14 changes: 10 additions & 4 deletions sdks/v4-sdk/src/utils/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const abi = [
{ name: '_poolManager', type: 'address', internalType: 'contract IPoolManager' },
{ name: '_permit2', type: 'address', internalType: 'contract IAllowanceTransfer' },
{ name: '_unsubscribeGasLimit', type: 'uint256', internalType: 'uint256' },
{ name: '_tokenDescriptor', type: 'address', internalType: 'contract IPositionDescriptor' },
],
stateMutability: 'nonpayable',
},
Expand Down Expand Up @@ -85,7 +86,6 @@ export const abi = [
],
},
{ name: 'sqrtPriceX96', type: 'uint160', internalType: 'uint160' },
{ name: 'hookData', type: 'bytes', internalType: 'bytes' },
],
outputs: [{ name: '', type: 'int24', internalType: 'int24' }],
stateMutability: 'payable',
Expand Down Expand Up @@ -358,12 +358,19 @@ export const abi = [
outputs: [{ name: '', type: 'string', internalType: 'string' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'tokenDescriptor',
inputs: [],
outputs: [{ name: '', type: 'address', internalType: 'contract IPositionDescriptor' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'tokenURI',
inputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
inputs: [{ name: 'tokenId', type: 'uint256', internalType: 'uint256' }],
outputs: [{ name: '', type: 'string', internalType: 'string' }],
stateMutability: 'pure',
stateMutability: 'view',
},
{
type: 'function',
Expand Down Expand Up @@ -494,7 +501,6 @@ export const abi = [
{ type: 'error', name: 'NotPoolManager', inputs: [] },
{ type: 'error', name: 'NotSubscribed', inputs: [] },
{ type: 'error', name: 'SignatureDeadlineExpired', inputs: [] },
{ type: 'error', name: 'SliceOutOfBounds', inputs: [] },
{ type: 'error', name: 'Unauthorized', inputs: [] },
{ type: 'error', name: 'UnsupportedAction', inputs: [{ name: 'action', type: 'uint256', internalType: 'uint256' }] },
{
Expand Down

0 comments on commit d910d6b

Please sign in to comment.