@sun-protocol/sun-sdk-sunswap-v4 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/index.cjs +1186 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +327 -0
- package/dist/index.d.ts +327 -0
- package/dist/index.js +1115 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/address.ts","../src/actions.ts","../src/planner.ts","../src/pool-key.ts","../src/parameters.ts","../src/pool-id.ts","../src/reads.ts"],"sourcesContent":["export * from './address.js'\nexport * from './actions.js'\nexport * from './parameters.js'\nexport * from './planner.js'\nexport * from './pool-id.js'\nexport * from './pool-key.js'\nexport * from './reads.js'\nexport * from './types.js'\n","import { sha256 } from '@noble/hashes/sha256'\nimport { SDK_ERROR_CODES, sdkInvariant, type TronAddress } from '@sun-protocol/sun-sdk-core'\n\nconst BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\nconst TRON_ADDRESS_BYTES = 21\nconst TRON_ADDRESS_PAYLOAD_BYTES = 25\n\nfunction decodeBase58(value: string): Uint8Array {\n let decoded = 0n\n\n for (const char of value) {\n const index = BASE58_ALPHABET.indexOf(char)\n sdkInvariant(index >= 0, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'Invalid base58 character', { value, char })\n decoded = decoded * 58n + BigInt(index)\n }\n\n const bytes: number[] = []\n while (decoded > 0n) {\n bytes.unshift(Number(decoded & 0xffn))\n decoded >>= 8n\n }\n\n for (const char of value) {\n if (char !== '1') break\n bytes.unshift(0)\n }\n\n return Uint8Array.from(bytes)\n}\n\nexport function tronAddressToEvmHex(address: TronAddress | string): `0x${string}` {\n const decoded = decodeBase58(address)\n sdkInvariant(\n decoded.length === TRON_ADDRESS_PAYLOAD_BYTES,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'TRON address payload must be 25 bytes',\n { address, length: decoded.length },\n )\n\n const body = decoded.slice(0, TRON_ADDRESS_BYTES)\n sdkInvariant(body[0] === 0x41, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'TRON address must use 0x41 prefix', {\n address,\n })\n\n const expectedChecksum = sha256(sha256(body)).slice(0, 4)\n const actualChecksum = decoded.slice(TRON_ADDRESS_BYTES)\n sdkInvariant(\n expectedChecksum.every((byte, index) => byte === actualChecksum[index]),\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'TRON address has invalid base58 checksum',\n { address },\n )\n\n return `0x${Array.from(body.slice(1))\n .map((byte) => byte.toString(16).padStart(2, '0'))\n .join('')}`\n}\n","import { getContractAddress } from '@sun-protocol/sun-sdk-chains'\nimport { keccak256 } from '@ethersproject/keccak256'\nimport {\n SDK_ERROR_CODES,\n TRON_ZERO_ADDRESS,\n createContractCallAction,\n sdkInvariant,\n type BigintIsh,\n type ContractCallAction,\n type Network,\n type TokenRequirement,\n type TronAddress,\n} from '@sun-protocol/sun-sdk-core'\nimport {\n encodeV4DecreaseLiquidityPlannerPayload,\n encodeV4IncreaseLiquidityPlannerPayload,\n encodeV4MintPositionPlannerPayload,\n type V4BigintIsh,\n type V4PositionConfig,\n} from './planner.js'\nimport { tronAddressToEvmHex } from './address.js'\nimport { normalizeV4PoolKey, toV4PoolKeyTuple } from './pool-key.js'\nimport type { V4PoolKey } from './types.js'\n\nexport const V4_POSITION_MANAGER_SELECTORS = {\n initializePool: 'initializePool((address,address,address,uint24,bytes32),uint160)',\n modifyLiquidities: 'modifyLiquidities(bytes,uint256)',\n multicall: 'multicall(bytes[])',\n} as const\n\nexport interface V4ActionOptions {\n readonly network: Network\n readonly positionManager?: TronAddress\n readonly feeLimit?: number\n readonly callValue?: bigint\n readonly id?: string\n readonly metadata?: Record<string, unknown>\n readonly tokenRequirements?: readonly TokenRequirement[]\n}\n\nexport interface BuildV4InitializePoolActionParams extends V4ActionOptions {\n readonly poolKey: V4PoolKey\n readonly sqrtPriceX96: BigintIsh\n}\n\nexport interface BuildV4ModifyLiquiditiesActionParams extends V4ActionOptions {\n readonly payload: string\n readonly deadline: V4BigintIsh\n}\n\nexport interface BuildV4MulticallActionParams extends V4ActionOptions {\n readonly calls: readonly string[]\n}\n\n/** A signed Permit2 allowance to be forwarded by the V4 PositionManager multicall. */\nexport interface V4Permit2Signature {\n readonly details: {\n readonly token: TronAddress | string\n readonly amount: BigintIsh\n readonly expiration: BigintIsh\n readonly nonce: BigintIsh\n }\n readonly spender: TronAddress | string\n readonly sigDeadline: BigintIsh\n readonly signature: string\n}\n\nexport interface BuildV4MintPositionActionParams extends V4ActionOptions {\n readonly positionConfig: V4PositionConfig\n readonly liquidity: V4BigintIsh\n readonly amount0Max: V4BigintIsh\n readonly amount1Max: V4BigintIsh\n readonly owner: TronAddress\n readonly deadline: V4BigintIsh\n readonly sweepRecipient?: TronAddress\n readonly hookData?: string\n}\n\nexport interface BuildV4IncreaseLiquidityActionParams extends V4ActionOptions {\n readonly poolKey: V4PoolKey\n readonly tokenId: V4BigintIsh\n readonly liquidity: V4BigintIsh\n readonly amount0Max: V4BigintIsh\n readonly amount1Max: V4BigintIsh\n readonly deadline: V4BigintIsh\n readonly sweepRecipient?: TronAddress\n readonly hookData?: string\n}\n\nexport interface BuildV4DecreaseLiquidityActionParams extends V4ActionOptions {\n readonly poolKey: V4PoolKey\n readonly tokenId: V4BigintIsh\n readonly liquidity: V4BigintIsh\n readonly amount0Min: V4BigintIsh\n readonly amount1Min: V4BigintIsh\n readonly recipient: TronAddress\n readonly deadline: V4BigintIsh\n readonly hookData?: string\n readonly settlementMode?: 'take-pair' | 'close-currency'\n}\n\nexport interface BuildV4CollectActionParams extends V4ActionOptions {\n readonly poolKey: V4PoolKey\n readonly tokenId: V4BigintIsh\n readonly recipient: TronAddress\n readonly deadline: V4BigintIsh\n readonly hookData?: string\n readonly settlementMode?: 'take-pair' | 'close-currency'\n}\n\nexport type V4TokenRequirement = TokenRequirement\n\nconst HEX_BYTES_PATTERN = /^0x(?:[a-fA-F0-9]{2})*$/\n\nfunction calldataWord(value: bigint): string {\n sdkInvariant(value >= 0n && value < (1n << 256n), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'calldata word is out of range', {\n value: value.toString(),\n })\n return value.toString(16).padStart(64, '0')\n}\n\nfunction calldataAddress(value: unknown): string {\n const address = String(value)\n const hex = address.startsWith('0x')\n ? assertHexBytes(address, 'address').slice(2)\n : tronAddressToEvmHex(address).slice(2)\n sdkInvariant(hex.length === 40, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'address must be a 20-byte address', {\n value: address,\n })\n return hex.toLowerCase().padStart(64, '0')\n}\n\nfunction calldataBytes32(value: unknown): string {\n const normalized = assertHexBytes(String(value), 'bytes32').slice(2)\n sdkInvariant(normalized.length === 64, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'bytes32 must contain exactly 32 bytes')\n return normalized\n}\n\nfunction functionSelector(signature: string): string {\n return keccak256(new TextEncoder().encode(signature)).slice(2, 10)\n}\n\nfunction dynamicBytes(value: unknown): string {\n const bytes = assertHexBytes(String(value), 'bytes').slice(2)\n const padding = (64 - (bytes.length % 64)) % 64\n return `${calldataWord(BigInt(bytes.length / 2))}${bytes}${'0'.repeat(padding)}`\n}\n\nfunction calldataUint(value: BigintIsh, bits: number, label: string): string {\n const integer = BigInt(value.toString())\n const maximum = 1n << BigInt(bits)\n sdkInvariant(integer >= 0n && integer < maximum, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} is out of uint${bits} range`, {\n value: integer.toString(),\n })\n return calldataWord(integer)\n}\n\n/**\n * Encodes the PositionManager's Permit2Forward.permit call for use as one item\n * in PositionManager.multicall(bytes[]). This matches the legacy V4 add flow:\n * typed-data signing happens off-chain, then the signed permit is forwarded in\n * the final liquidity transaction.\n */\nexport function encodeV4Permit2ForwardCall(input: {\n readonly owner: TronAddress | string\n readonly permit: V4Permit2Signature\n}): `0x${string}` {\n const signature = input.permit.signature.startsWith('0x') ? input.permit.signature : `0x${input.permit.signature}`\n const selector = functionSelector('permit(address,((address,uint160,uint48,uint48),address,uint256),bytes)')\n const signatureOffset = calldataWord(256n)\n return `0x${selector}${calldataAddress(input.owner)}${calldataAddress(input.permit.details.token)}${calldataUint(input.permit.details.amount, 160, 'permit amount')}${calldataUint(input.permit.details.expiration, 48, 'permit expiration')}${calldataUint(input.permit.details.nonce, 48, 'permit nonce')}${calldataAddress(input.permit.spender)}${calldataUint(input.permit.sigDeadline, 256, 'permit sigDeadline')}${signatureOffset}${dynamicBytes(signature)}`\n}\n\n/** Encodes the two V4 position-manager actions that may be nested in multicall(bytes[]). */\nexport function encodeV4ContractCallAction(action: ContractCallAction): `0x${string}` {\n if (action.functionSelector === V4_POSITION_MANAGER_SELECTORS.initializePool) {\n const poolKey = action.parameters?.[0]?.value\n const sqrtPriceX96 = action.parameters?.[1]?.value\n sdkInvariant(\n typeof poolKey === 'object' && poolKey !== null && sqrtPriceX96 !== undefined,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'initializePool action parameters are malformed',\n )\n const key = poolKey as Record<string, unknown>\n return `0x${functionSelector(action.functionSelector)}${calldataAddress(key.currency0)}${calldataAddress(key.currency1)}${calldataAddress(key.hooks)}${calldataWord(BigInt(String(key.fee)))}${calldataBytes32(key.parameters)}${calldataWord(BigInt(String(sqrtPriceX96)))}`\n }\n\n if (action.functionSelector === V4_POSITION_MANAGER_SELECTORS.modifyLiquidities) {\n const payload = action.parameters?.[0]?.value\n const deadline = action.parameters?.[1]?.value\n sdkInvariant(payload !== undefined && deadline !== undefined, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'modifyLiquidities action parameters are malformed')\n return `0x${functionSelector(action.functionSelector)}${calldataWord(64n)}${calldataWord(BigInt(String(deadline)))}${dynamicBytes(payload)}`\n }\n\n sdkInvariant(false, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'V4 action cannot be encoded for multicall', {\n functionSelector: action.functionSelector,\n })\n throw new Error('Unsupported V4 multicall action')\n}\n\nfunction valueOf(value: BigintIsh | bigint): string {\n return BigInt(value.toString()).toString()\n}\n\nfunction positionManagerTarget(params: V4ActionOptions): TronAddress {\n return params.positionManager ?? getContractAddress(params.network, 'sunswapV4PositionManager')\n}\n\nfunction actionId(params: V4ActionOptions, suffix: string): string {\n return params.id ?? `sunswap-v4-${suffix}-${params.network}`\n}\n\nfunction assertHexBytes(value: string, label: string): string {\n sdkInvariant(HEX_BYTES_PATTERN.test(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be 0x-prefixed hex bytes`, {\n label,\n value,\n })\n return value.toLowerCase()\n}\n\nfunction nativeCallValue(poolKey: V4PoolKey, amount0: V4BigintIsh, amount1: V4BigintIsh): bigint {\n let value = 0n\n if (poolKey.currency0 === TRON_ZERO_ADDRESS) value += BigInt(amount0.toString())\n if (poolKey.currency1 === TRON_ZERO_ADDRESS) value += BigInt(amount1.toString())\n return value\n}\n\nfunction tokenRequirements(\n poolKey: V4PoolKey,\n amount0: V4BigintIsh,\n amount1: V4BigintIsh,\n spender: TronAddress,\n): readonly V4TokenRequirement[] {\n const requirements: V4TokenRequirement[] = []\n const normalizedAmount0 = valueOf(amount0)\n const normalizedAmount1 = valueOf(amount1)\n if (poolKey.currency0 !== TRON_ZERO_ADDRESS && BigInt(normalizedAmount0) > 0n) {\n requirements.push({\n token: poolKey.currency0,\n amount: normalizedAmount0,\n spender,\n approval: 'approve-or-permit2',\n })\n }\n if (poolKey.currency1 !== TRON_ZERO_ADDRESS && BigInt(normalizedAmount1) > 0n) {\n requirements.push({\n token: poolKey.currency1,\n amount: normalizedAmount1,\n spender,\n approval: 'approve-or-permit2',\n })\n }\n return requirements\n}\n\nexport function buildV4InitializePoolAction(params: BuildV4InitializePoolActionParams): ContractCallAction {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n\n return createContractCallAction({\n id: actionId(params, 'initialize-pool'),\n target: positionManagerTarget(params),\n functionSelector: V4_POSITION_MANAGER_SELECTORS.initializePool,\n parameters: [toV4PoolKeyTuple(poolKey), { type: 'uint160', value: valueOf(params.sqrtPriceX96) }],\n ...(params.callValue !== undefined ? { callValue: params.callValue } : {}),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n ...(params.metadata !== undefined ? { metadata: params.metadata } : {}),\n })\n}\n\nexport function buildV4ModifyLiquiditiesAction(params: BuildV4ModifyLiquiditiesActionParams): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'modify-liquidities'),\n target: positionManagerTarget(params),\n functionSelector: V4_POSITION_MANAGER_SELECTORS.modifyLiquidities,\n parameters: [\n { type: 'bytes', value: assertHexBytes(params.payload, 'payload') },\n { type: 'uint256', value: valueOf(params.deadline) },\n ],\n ...(params.callValue !== undefined ? { callValue: params.callValue } : {}),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n ...(params.tokenRequirements !== undefined ? { tokenRequirements: params.tokenRequirements } : {}),\n ...(params.metadata !== undefined ? { metadata: params.metadata } : {}),\n })\n}\n\nexport function buildV4MulticallAction(params: BuildV4MulticallActionParams): ContractCallAction {\n return createContractCallAction({\n id: actionId(params, 'multicall'),\n target: positionManagerTarget(params),\n functionSelector: V4_POSITION_MANAGER_SELECTORS.multicall,\n parameters: [{ type: 'bytes[]', value: params.calls.map((call, index) => assertHexBytes(call, `calls[${index}]`)) }],\n ...(params.callValue !== undefined ? { callValue: params.callValue } : {}),\n ...(params.feeLimit !== undefined ? { feeLimit: params.feeLimit } : {}),\n ...(params.tokenRequirements !== undefined ? { tokenRequirements: params.tokenRequirements } : {}),\n ...(params.metadata !== undefined ? { metadata: params.metadata } : {}),\n })\n}\n\nexport function buildV4MintPositionAction(params: BuildV4MintPositionActionParams): ContractCallAction {\n const poolKey = normalizeV4PoolKey(params.positionConfig.poolKey)\n const target = positionManagerTarget(params)\n const payload = encodeV4MintPositionPlannerPayload({\n positionConfig: { ...params.positionConfig, poolKey },\n liquidity: params.liquidity,\n amount0Max: params.amount0Max,\n amount1Max: params.amount1Max,\n owner: params.owner,\n ...(params.sweepRecipient !== undefined ? { sweepRecipient: params.sweepRecipient } : {}),\n ...(params.hookData !== undefined ? { hookData: params.hookData } : {}),\n })\n const computedCallValue = nativeCallValue(poolKey, params.amount0Max, params.amount1Max)\n\n return buildV4ModifyLiquiditiesAction({\n ...params,\n id: actionId(params, 'mint-position'),\n payload,\n deadline: params.deadline,\n callValue: params.callValue ?? computedCallValue,\n tokenRequirements: tokenRequirements(poolKey, params.amount0Max, params.amount1Max, target),\n })\n}\n\nexport function buildV4IncreaseLiquidityAction(params: BuildV4IncreaseLiquidityActionParams): ContractCallAction {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n const target = positionManagerTarget(params)\n const payload = encodeV4IncreaseLiquidityPlannerPayload({\n poolKey,\n tokenId: params.tokenId,\n liquidity: params.liquidity,\n amount0Max: params.amount0Max,\n amount1Max: params.amount1Max,\n ...(params.sweepRecipient !== undefined ? { sweepRecipient: params.sweepRecipient } : {}),\n ...(params.hookData !== undefined ? { hookData: params.hookData } : {}),\n })\n const computedCallValue = nativeCallValue(poolKey, params.amount0Max, params.amount1Max)\n\n return buildV4ModifyLiquiditiesAction({\n ...params,\n id: actionId(params, 'increase-liquidity'),\n payload,\n deadline: params.deadline,\n callValue: params.callValue ?? computedCallValue,\n tokenRequirements: tokenRequirements(poolKey, params.amount0Max, params.amount1Max, target),\n })\n}\n\nexport function buildV4DecreaseLiquidityAction(params: BuildV4DecreaseLiquidityActionParams): ContractCallAction {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n const payload = encodeV4DecreaseLiquidityPlannerPayload({\n poolKey,\n tokenId: params.tokenId,\n liquidity: params.liquidity,\n amount0Min: params.amount0Min,\n amount1Min: params.amount1Min,\n recipient: params.recipient,\n ...(params.settlementMode !== undefined ? { settlementMode: params.settlementMode } : {}),\n ...(params.hookData !== undefined ? { hookData: params.hookData } : {}),\n })\n\n return buildV4ModifyLiquiditiesAction({\n ...params,\n id: actionId(params, 'decrease-liquidity'),\n payload,\n deadline: params.deadline,\n callValue: params.callValue ?? 0n,\n })\n}\n\nexport function buildV4CollectAction(params: BuildV4CollectActionParams): ContractCallAction {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n const payload = encodeV4DecreaseLiquidityPlannerPayload({\n poolKey,\n tokenId: params.tokenId,\n liquidity: 0n,\n amount0Min: 0n,\n amount1Min: 0n,\n recipient: params.recipient,\n ...(params.settlementMode !== undefined ? { settlementMode: params.settlementMode } : {}),\n ...(params.hookData !== undefined ? { hookData: params.hookData } : {}),\n })\n\n return buildV4ModifyLiquiditiesAction({\n ...params,\n id: actionId(params, 'collect'),\n payload,\n deadline: params.deadline,\n callValue: params.callValue ?? 0n,\n })\n}\n","import { SDK_ERROR_CODES, TRON_ZERO_ADDRESS, assertTronAddress, sdkInvariant, type BigintIsh, type TronAddress } from '@sun-protocol/sun-sdk-core'\nimport { tronAddressToEvmHex } from './address.js'\nimport { normalizeV4PoolKey } from './pool-key.js'\nimport type { V4PoolKey } from './types.js'\n\nexport const V4_ACTIONS = {\n CL_INCREASE_LIQUIDITY: 0x00,\n CL_DECREASE_LIQUIDITY: 0x01,\n CL_MINT_POSITION: 0x02,\n SETTLE: 0x0b,\n SETTLE_PAIR: 0x0d,\n TAKE_PAIR: 0x11,\n CLOSE_CURRENCY: 0x12,\n SWEEP: 0x14,\n} as const\n\nexport const V4_ACTION_CONSTANTS = {\n OPEN_DELTA: 0n,\n MSG_SENDER: '0x0000000000000000000000000000000000000001',\n ADDRESS_THIS: '0x0000000000000000000000000000000000000002',\n} as const\n\nexport type V4Action = (typeof V4_ACTIONS)[keyof typeof V4_ACTIONS]\nexport type V4BigintIsh = BigintIsh | bigint\n\nexport interface V4PositionConfig {\n readonly poolKey: V4PoolKey\n readonly tickLower: number\n readonly tickUpper: number\n}\n\nexport interface V4PlannerPlan {\n readonly action: V4Action\n readonly params: readonly V4PlannerParam[]\n}\n\nexport type V4PlannerParam =\n | V4PositionConfig\n | TronAddress\n | `0x${string}`\n | V4BigintIsh\n | number\n | boolean\n\nexport interface EncodeV4MintPositionPayloadParams {\n readonly positionConfig: V4PositionConfig\n readonly liquidity: V4BigintIsh\n readonly amount0Max: V4BigintIsh\n readonly amount1Max: V4BigintIsh\n readonly owner: TronAddress\n readonly sweepRecipient?: TronAddress\n readonly hookData?: string\n}\n\nexport interface EncodeV4IncreaseLiquidityPayloadParams {\n readonly poolKey: V4PoolKey\n readonly tokenId: V4BigintIsh\n readonly liquidity: V4BigintIsh\n readonly amount0Max: V4BigintIsh\n readonly amount1Max: V4BigintIsh\n readonly sweepRecipient?: TronAddress\n readonly hookData?: string\n}\n\nexport interface EncodeV4DecreaseLiquidityPayloadParams {\n readonly poolKey: V4PoolKey\n readonly tokenId: V4BigintIsh\n readonly liquidity: V4BigintIsh\n readonly amount0Min: V4BigintIsh\n readonly amount1Min: V4BigintIsh\n readonly recipient: TronAddress\n readonly hookData?: string\n readonly settlementMode?: 'take-pair' | 'close-currency'\n}\n\nexport interface EncodeV4CollectPayloadParams {\n readonly poolKey: V4PoolKey\n readonly recipient: TronAddress\n}\n\nconst WORD_BYTES = 32\nconst WORD_HEX_LENGTH = WORD_BYTES * 2\nconst HEX_BYTES_PATTERN = /^0x(?:[a-fA-F0-9]{2})*$/\n\nconst V4_ACTION_NAMES: Record<V4Action, string> = {\n [V4_ACTIONS.CL_INCREASE_LIQUIDITY]: 'CL_INCREASE_LIQUIDITY',\n [V4_ACTIONS.CL_DECREASE_LIQUIDITY]: 'CL_DECREASE_LIQUIDITY',\n [V4_ACTIONS.CL_MINT_POSITION]: 'CL_MINT_POSITION',\n [V4_ACTIONS.SETTLE]: 'SETTLE',\n [V4_ACTIONS.SETTLE_PAIR]: 'SETTLE_PAIR',\n [V4_ACTIONS.TAKE_PAIR]: 'TAKE_PAIR',\n [V4_ACTIONS.CLOSE_CURRENCY]: 'CLOSE_CURRENCY',\n [V4_ACTIONS.SWEEP]: 'SWEEP',\n}\n\nfunction assertHexBytes(value: string, label: string): `0x${string}` {\n sdkInvariant(HEX_BYTES_PATTERN.test(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be 0x-prefixed hex bytes`, {\n label,\n value,\n })\n return value.toLowerCase() as `0x${string}`\n}\n\nfunction strip0x(value: string): string {\n return value.startsWith('0x') ? value.slice(2) : value\n}\n\nfunction word(value: bigint): string {\n sdkInvariant(value >= 0n, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'ABI word cannot encode a negative uint', {\n value: value.toString(),\n })\n return value.toString(16).padStart(WORD_HEX_LENGTH, '0')\n}\n\nfunction encodeUint(value: V4BigintIsh, bits: number, label: string): string {\n const uint = BigInt(value.toString())\n const max = 1n << BigInt(bits)\n sdkInvariant(uint >= 0n && uint < max, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} is out of uint${bits} range`, {\n label,\n value: uint.toString(),\n })\n return word(uint)\n}\n\nfunction encodeInt(value: number, bits: number, label: string): string {\n sdkInvariant(Number.isInteger(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be an integer`, { label, value })\n const int = BigInt(value)\n const min = -(1n << BigInt(bits - 1))\n const max = 1n << BigInt(bits - 1)\n sdkInvariant(int >= min && int < max, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} is out of int${bits} range`, {\n label,\n value,\n })\n return word(int >= 0n ? int : (1n << BigInt(WORD_BYTES * 8)) + int)\n}\n\nfunction encodeBool(value: boolean): string {\n return word(value ? 1n : 0n)\n}\n\nfunction encodeAddress(value: TronAddress | string, label: string): string {\n const address = value.startsWith('0x') ? assertHexBytes(value, label) : tronAddressToEvmHex(assertTronAddress(value, label))\n const hex = strip0x(address)\n sdkInvariant(hex.length === 40, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be a 20-byte address`, {\n label,\n value,\n })\n return hex.padStart(WORD_HEX_LENGTH, '0')\n}\n\nfunction encodeBytes(value: string, label: string): string {\n const bytes = strip0x(assertHexBytes(value, label))\n const length = bytes.length / 2\n const paddedLength = Math.ceil(length / WORD_BYTES) * WORD_HEX_LENGTH\n return `${word(BigInt(length))}${bytes.padEnd(paddedLength, '0')}`\n}\n\nfunction concatHex(parts: readonly string[]): `0x${string}` {\n return `0x${parts.join('')}`\n}\n\nfunction encodePoolKeyFields(poolKey: V4PoolKey): readonly string[] {\n const normalized = normalizeV4PoolKey(poolKey)\n return [\n encodeAddress(normalized.currency0, 'poolKey.currency0'),\n encodeAddress(normalized.currency1, 'poolKey.currency1'),\n encodeAddress(normalized.hooks, 'poolKey.hooks'),\n encodeUint(normalized.fee, 24, 'poolKey.fee'),\n strip0x(assertHexBytes(normalized.parameters, 'poolKey.parameters')),\n ]\n}\n\nfunction encodePositionConfig(config: V4PositionConfig): readonly string[] {\n return [\n ...encodePoolKeyFields(config.poolKey),\n encodeInt(config.tickLower, 24, 'tickLower'),\n encodeInt(config.tickUpper, 24, 'tickUpper'),\n ]\n}\n\nfunction encodeWithTrailingBytes(staticParts: readonly string[], bytesValue: string): `0x${string}` {\n return concatHex([...staticParts, word(BigInt((staticParts.length + 1) * WORD_BYTES)), encodeBytes(bytesValue, 'hookData')])\n}\n\nfunction assertParamCount(plan: V4PlannerPlan, expected: number): void {\n sdkInvariant(\n plan.params.length === expected,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n `V4 action ${V4_ACTION_NAMES[plan.action]} expects ${expected} params`,\n { action: plan.action, expected, actual: plan.params.length },\n )\n}\n\nfunction paramAt(plan: V4PlannerPlan, index: number): V4PlannerParam {\n const value = plan.params[index]\n sdkInvariant(value !== undefined, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `Missing V4 action param at index ${index}`, {\n action: plan.action,\n index,\n })\n return value\n}\n\nfunction asPositionConfig(value: V4PlannerParam, label: string): V4PositionConfig {\n sdkInvariant(typeof value === 'object' && value !== null && 'poolKey' in value, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be a V4 position config`, {\n label,\n })\n return value\n}\n\nfunction encodePlanParam(plan: V4PlannerPlan): `0x${string}` {\n switch (plan.action) {\n case V4_ACTIONS.CL_MINT_POSITION:\n assertParamCount(plan, 6)\n return encodeWithTrailingBytes(\n [\n ...encodePositionConfig(asPositionConfig(paramAt(plan, 0), 'positionConfig')),\n encodeUint(paramAt(plan, 1) as V4BigintIsh, 128, 'liquidity'),\n encodeUint(paramAt(plan, 2) as V4BigintIsh, 128, 'amount0Max'),\n encodeUint(paramAt(plan, 3) as V4BigintIsh, 128, 'amount1Max'),\n encodeAddress(paramAt(plan, 4) as TronAddress | string, 'owner'),\n ],\n paramAt(plan, 5) as string,\n )\n case V4_ACTIONS.CL_INCREASE_LIQUIDITY:\n assertParamCount(plan, 5)\n return encodeWithTrailingBytes(\n [\n encodeUint(paramAt(plan, 0) as V4BigintIsh, 256, 'tokenId'),\n encodeUint(paramAt(plan, 1) as V4BigintIsh, 128, 'liquidity'),\n encodeUint(paramAt(plan, 2) as V4BigintIsh, 128, 'amount0Max'),\n encodeUint(paramAt(plan, 3) as V4BigintIsh, 128, 'amount1Max'),\n ],\n paramAt(plan, 4) as string,\n )\n case V4_ACTIONS.CL_DECREASE_LIQUIDITY:\n assertParamCount(plan, 5)\n return encodeWithTrailingBytes(\n [\n encodeUint(paramAt(plan, 0) as V4BigintIsh, 256, 'tokenId'),\n encodeUint(paramAt(plan, 1) as V4BigintIsh, 128, 'liquidity'),\n encodeUint(paramAt(plan, 2) as V4BigintIsh, 128, 'amount0Min'),\n encodeUint(paramAt(plan, 3) as V4BigintIsh, 128, 'amount1Min'),\n ],\n paramAt(plan, 4) as string,\n )\n case V4_ACTIONS.SETTLE:\n assertParamCount(plan, 3)\n return concatHex([\n encodeAddress(paramAt(plan, 0) as TronAddress | string, 'currency'),\n encodeUint(paramAt(plan, 1) as V4BigintIsh, 256, 'amount'),\n encodeBool(paramAt(plan, 2) as boolean),\n ])\n case V4_ACTIONS.SETTLE_PAIR:\n assertParamCount(plan, 2)\n return concatHex([\n encodeAddress(paramAt(plan, 0) as TronAddress | string, 'currency0'),\n encodeAddress(paramAt(plan, 1) as TronAddress | string, 'currency1'),\n ])\n case V4_ACTIONS.TAKE_PAIR:\n assertParamCount(plan, 3)\n return concatHex([\n encodeAddress(paramAt(plan, 0) as TronAddress | string, 'currency0'),\n encodeAddress(paramAt(plan, 1) as TronAddress | string, 'currency1'),\n encodeAddress(paramAt(plan, 2) as TronAddress | string, 'recipient'),\n ])\n case V4_ACTIONS.CLOSE_CURRENCY:\n assertParamCount(plan, 1)\n return concatHex([encodeAddress(paramAt(plan, 0) as TronAddress | string, 'currency')])\n case V4_ACTIONS.SWEEP:\n assertParamCount(plan, 2)\n return concatHex([\n encodeAddress(paramAt(plan, 0) as TronAddress | string, 'currency'),\n encodeAddress(paramAt(plan, 1) as TronAddress | string, 'recipient'),\n ])\n default:\n sdkInvariant(false, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'Unsupported V4 action', { action: plan.action })\n throw new Error('Unsupported V4 action')\n }\n}\n\nfunction encodeDynamicBytesArray(values: readonly `0x${string}`[]): string {\n const encodedValues = values.map((value, index) => encodeBytes(value, `params[${index}]`))\n const offsets: string[] = []\n let tailOffset = BigInt(values.length * WORD_BYTES)\n for (const encodedValue of encodedValues) {\n offsets.push(word(tailOffset))\n tailOffset += BigInt(encodedValue.length / 2)\n }\n return `${word(BigInt(values.length))}${offsets.join('')}${encodedValues.join('')}`\n}\n\nexport function encodeV4Actions(plans: readonly V4PlannerPlan[]): `0x${string}` {\n const actions = plans.map((plan) => {\n sdkInvariant(V4_ACTION_NAMES[plan.action] !== undefined, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'Unsupported V4 action', {\n action: plan.action,\n })\n return plan.action.toString(16).padStart(2, '0')\n })\n return concatHex(actions)\n}\n\nexport function encodeV4ActionParams(plans: readonly V4PlannerPlan[]): readonly `0x${string}`[] {\n return plans.map((plan) => encodePlanParam(plan))\n}\n\nexport function encodeV4ActionsPlanner(plans: readonly V4PlannerPlan[]): `0x${string}` {\n const actions = encodeV4Actions(plans)\n const params = encodeV4ActionParams(plans)\n const encodedActions = encodeBytes(actions, 'actions')\n const encodedParams = encodeDynamicBytesArray(params)\n return concatHex([word(64n), word(BigInt(64 + encodedActions.length / 2)), encodedActions, encodedParams])\n}\n\nexport function encodeV4MintPositionPlannerPayload(params: EncodeV4MintPositionPayloadParams): `0x${string}` {\n const poolKey = normalizeV4PoolKey(params.positionConfig.poolKey)\n const owner = assertTronAddress(params.owner, 'owner')\n const sweepRecipient = params.sweepRecipient ? assertTronAddress(params.sweepRecipient, 'sweepRecipient') : owner\n const hookData = params.hookData ?? '0x'\n const plans: V4PlannerPlan[] = [\n {\n action: V4_ACTIONS.CL_MINT_POSITION,\n params: [{ ...params.positionConfig, poolKey }, params.liquidity, params.amount0Max, params.amount1Max, owner, hookData],\n },\n { action: V4_ACTIONS.SETTLE, params: [poolKey.currency0, V4_ACTION_CONSTANTS.OPEN_DELTA, poolKey.currency0 !== TRON_ZERO_ADDRESS] },\n { action: V4_ACTIONS.SETTLE, params: [poolKey.currency1, V4_ACTION_CONSTANTS.OPEN_DELTA, poolKey.currency1 !== TRON_ZERO_ADDRESS] },\n ]\n\n if (poolKey.currency0 === TRON_ZERO_ADDRESS) {\n plans.push({ action: V4_ACTIONS.SWEEP, params: [poolKey.currency0, sweepRecipient] })\n }\n if (poolKey.currency1 === TRON_ZERO_ADDRESS) {\n plans.push({ action: V4_ACTIONS.SWEEP, params: [poolKey.currency1, sweepRecipient] })\n }\n\n return encodeV4ActionsPlanner(plans)\n}\n\nexport function encodeV4IncreaseLiquidityPlannerPayload(params: EncodeV4IncreaseLiquidityPayloadParams): `0x${string}` {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n const hasNativeCurrency = poolKey.currency0 === TRON_ZERO_ADDRESS || poolKey.currency1 === TRON_ZERO_ADDRESS\n sdkInvariant(\n !hasNativeCurrency || params.sweepRecipient !== undefined,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'sweepRecipient is required when increasing liquidity with native currency',\n )\n const sweepRecipient = params.sweepRecipient !== undefined\n ? assertTronAddress(params.sweepRecipient, 'sweepRecipient')\n : undefined\n const plans: V4PlannerPlan[] = [\n {\n action: V4_ACTIONS.CL_INCREASE_LIQUIDITY,\n params: [params.tokenId, params.liquidity, params.amount0Max, params.amount1Max, params.hookData ?? '0x'],\n },\n { action: V4_ACTIONS.SETTLE, params: [poolKey.currency0, V4_ACTION_CONSTANTS.OPEN_DELTA, poolKey.currency0 !== TRON_ZERO_ADDRESS] },\n { action: V4_ACTIONS.SETTLE, params: [poolKey.currency1, V4_ACTION_CONSTANTS.OPEN_DELTA, poolKey.currency1 !== TRON_ZERO_ADDRESS] },\n ]\n\n if (sweepRecipient && poolKey.currency0 === TRON_ZERO_ADDRESS) {\n plans.push({ action: V4_ACTIONS.SWEEP, params: [poolKey.currency0, sweepRecipient] })\n }\n if (sweepRecipient && poolKey.currency1 === TRON_ZERO_ADDRESS) {\n plans.push({ action: V4_ACTIONS.SWEEP, params: [poolKey.currency1, sweepRecipient] })\n }\n\n return encodeV4ActionsPlanner(plans)\n}\n\nexport function encodeV4DecreaseLiquidityPlannerPayload(params: EncodeV4DecreaseLiquidityPayloadParams): `0x${string}` {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n const recipient = assertTronAddress(params.recipient, 'recipient')\n const plans: V4PlannerPlan[] = [\n {\n action: V4_ACTIONS.CL_DECREASE_LIQUIDITY,\n params: [params.tokenId, params.liquidity, params.amount0Min, params.amount1Min, params.hookData ?? '0x'],\n },\n ]\n if (params.settlementMode === 'close-currency') {\n plans.push(\n { action: V4_ACTIONS.CLOSE_CURRENCY, params: [poolKey.currency0] },\n { action: V4_ACTIONS.CLOSE_CURRENCY, params: [poolKey.currency1] },\n )\n } else {\n plans.push({ action: V4_ACTIONS.TAKE_PAIR, params: [poolKey.currency0, poolKey.currency1, recipient] })\n }\n return encodeV4ActionsPlanner(plans)\n}\n\nexport function encodeV4CollectPlannerPayload(params: EncodeV4CollectPayloadParams): `0x${string}` {\n const poolKey = normalizeV4PoolKey(params.poolKey)\n const recipient = assertTronAddress(params.recipient, 'recipient')\n return encodeV4ActionsPlanner([{ action: V4_ACTIONS.TAKE_PAIR, params: [poolKey.currency0, poolKey.currency1, recipient] }])\n}\n","import {\n SDK_ERROR_CODES,\n TRON_ZERO_ADDRESS,\n assertTronAddress,\n sdkInvariant,\n type Network,\n type TronAddress,\n} from '@sun-protocol/sun-sdk-core'\nimport type { ContractParameter } from '@sun-protocol/sun-sdk-core'\nimport { tronAddressToEvmHex } from './address.js'\nimport type { V4PoolId, V4PoolKey, V4PoolParameters } from './types.js'\n\nexport const V4_DYNAMIC_FEE_FLAG = 0x800000\nexport const V4_UINT24_MAX = 0xffffff\nexport const V4_MAX_STATIC_FEE = 1_000_000\nexport const V4_EMPTY_PARAMETERS = `0x${'0'.repeat(64)}` as V4PoolParameters\n\nconst BYTES32_PATTERN = /^0x[a-fA-F0-9]{64}$/\n\nexport interface CreateV4PoolKeyInput {\n readonly network: Network\n readonly currencyA: TronAddress | string\n readonly currencyB: TronAddress | string\n readonly hooks?: TronAddress | string\n readonly fee: number\n readonly parameters?: V4PoolParameters | string\n}\n\nfunction sortCurrencies(currencyA: TronAddress, currencyB: TronAddress): readonly [TronAddress, TronAddress] {\n sdkInvariant(\n currencyA !== currencyB,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'V4 pool currencies must be different',\n { currencyA, currencyB },\n )\n return tronAddressToEvmHex(currencyA) < tronAddressToEvmHex(currencyB) ? [currencyA, currencyB] : [currencyB, currencyA]\n}\n\nexport function isV4DynamicFee(fee: number): boolean {\n return (fee & V4_DYNAMIC_FEE_FLAG) !== 0\n}\n\nexport function getV4StaticFee(fee: number): number {\n return fee & ~V4_DYNAMIC_FEE_FLAG\n}\n\nexport function assertV4PoolParameters(value: string, label = 'parameters'): V4PoolParameters {\n sdkInvariant(BYTES32_PATTERN.test(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be bytes32 hex`, {\n label,\n value,\n })\n return value.toLowerCase() as V4PoolParameters\n}\n\nexport function assertV4PoolId(value: string, label = 'poolId'): V4PoolId {\n sdkInvariant(BYTES32_PATTERN.test(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be bytes32 hex`, {\n label,\n value,\n })\n return value.toLowerCase() as V4PoolId\n}\n\nexport function assertV4Fee(fee: number): number {\n sdkInvariant(Number.isInteger(fee), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'V4 fee must be an integer', { fee })\n sdkInvariant(fee >= 0 && fee <= V4_UINT24_MAX, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'V4 fee must fit uint24', {\n fee,\n })\n\n const staticFee = getV4StaticFee(fee)\n sdkInvariant(\n isV4DynamicFee(fee) || staticFee <= V4_MAX_STATIC_FEE,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'V4 static fee cannot exceed 100%',\n { fee, staticFee },\n )\n return fee\n}\n\nexport function assertV4HookFeeCombination(hooks: TronAddress, fee: number): void {\n sdkInvariant(\n !(hooks === TRON_ZERO_ADDRESS && isV4DynamicFee(fee)),\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'V4 dynamic fee requires a non-empty hook address',\n { hooks, fee },\n )\n}\n\nexport function normalizeV4PoolKey(input: V4PoolKey): V4PoolKey {\n const currency0 = assertTronAddress(input.currency0, 'currency0')\n const currency1 = assertTronAddress(input.currency1, 'currency1')\n const hooks = assertTronAddress(input.hooks, 'hooks')\n const [sorted0, sorted1] = sortCurrencies(currency0, currency1)\n const fee = assertV4Fee(input.fee)\n assertV4HookFeeCombination(hooks, fee)\n\n return {\n network: input.network,\n currency0: sorted0,\n currency1: sorted1,\n hooks,\n fee,\n parameters: assertV4PoolParameters(input.parameters),\n }\n}\n\nexport function createV4PoolKey(input: CreateV4PoolKeyInput): V4PoolKey {\n const currencyA = assertTronAddress(input.currencyA, 'currencyA')\n const currencyB = assertTronAddress(input.currencyB, 'currencyB')\n const [currency0, currency1] = sortCurrencies(currencyA, currencyB)\n const hooks = assertTronAddress(input.hooks ?? TRON_ZERO_ADDRESS, 'hooks')\n const fee = assertV4Fee(input.fee)\n assertV4HookFeeCombination(hooks, fee)\n\n return {\n network: input.network,\n currency0,\n currency1,\n hooks,\n fee,\n parameters: assertV4PoolParameters(input.parameters ?? V4_EMPTY_PARAMETERS),\n }\n}\n\nexport function toV4PoolKeyTuple(poolKey: V4PoolKey): ContractParameter {\n const normalized = normalizeV4PoolKey(poolKey)\n return {\n type: 'tuple',\n value: {\n currency0: normalized.currency0,\n currency1: normalized.currency1,\n hooks: normalized.hooks,\n fee: normalized.fee,\n parameters: normalized.parameters,\n },\n }\n}\n","import { SDK_ERROR_CODES, sdkInvariant } from '@sun-protocol/sun-sdk-core'\nimport type { V4HooksRegistration, V4PoolParameterConfig, V4PoolParameters } from './types.js'\nimport { assertV4PoolParameters } from './pool-key.js'\n\nexport const V4_HOOKS_REGISTRATION_OFFSET: Record<keyof V4HooksRegistration, number> = {\n beforeInitialize: 0,\n afterInitialize: 1,\n beforeAddLiquidity: 2,\n afterAddLiquidity: 3,\n beforeRemoveLiquidity: 4,\n afterRemoveLiquidity: 5,\n beforeSwap: 6,\n afterSwap: 7,\n beforeDonate: 8,\n afterDonate: 9,\n beforeSwapReturnsDelta: 10,\n afterSwapReturnsDelta: 11,\n afterAddLiquidityReturnsDelta: 12,\n afterRemoveLiquidityReturnsDelta: 13,\n}\n\nconst INT24_MIN = -0x800000\nconst INT24_MAX = 0x7fffff\nconst UINT16_MAX = 0xffff\nconst HOOKS_REGISTRATION_MAX = 0x3fff\nconst BYTES32_HEX_LENGTH = 64\ntype MutableHooksRegistration = {\n -readonly [Key in keyof V4HooksRegistration]?: V4HooksRegistration[Key]\n}\n\nfunction assertInt24(value: number, label: string): number {\n sdkInvariant(Number.isInteger(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be an integer`, {\n label,\n value,\n })\n sdkInvariant(value >= INT24_MIN && value <= INT24_MAX, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must fit int24`, {\n label,\n value,\n })\n return value\n}\n\nfunction signedInt24ToHex(value: number): string {\n const int24 = assertInt24(value, 'tickSpacing')\n const encoded = int24 < 0 ? 0x1000000 + int24 : int24\n return encoded.toString(16).padStart(6, '0')\n}\n\nfunction hexToSignedInt24(hex: string): number {\n const value = Number.parseInt(hex, 16)\n return value >= 0x800000 ? value - 0x1000000 : value\n}\n\nexport function encodeV4HooksRegistration(hooksRegistration: V4HooksRegistration = {}): number {\n let registration = 0\n\n for (const key of Object.keys(V4_HOOKS_REGISTRATION_OFFSET) as Array<keyof V4HooksRegistration>) {\n if (hooksRegistration[key]) {\n registration |= 1 << V4_HOOKS_REGISTRATION_OFFSET[key]\n }\n }\n\n return registration\n}\n\nexport function decodeV4HooksRegistration(registration: number): V4HooksRegistration {\n sdkInvariant(\n Number.isInteger(registration) && registration >= 0 && registration <= HOOKS_REGISTRATION_MAX,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'V4 hooks registration must fit the known 14-bit bitmap',\n { registration },\n )\n\n const decoded: MutableHooksRegistration = {}\n for (const key of Object.keys(V4_HOOKS_REGISTRATION_OFFSET) as Array<keyof V4HooksRegistration>) {\n if ((registration & (1 << V4_HOOKS_REGISTRATION_OFFSET[key])) !== 0) {\n decoded[key] = true\n }\n }\n\n return decoded\n}\n\nexport function encodeV4PoolParameters(params: V4PoolParameterConfig): V4PoolParameters {\n const tickSpacing = signedInt24ToHex(params.tickSpacing)\n const hooksRegistration = encodeV4HooksRegistration(params.hooksRegistration)\n\n sdkInvariant(\n hooksRegistration <= UINT16_MAX,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'V4 hooks registration must fit uint16',\n { hooksRegistration },\n )\n\n const hooksHex = hooksRegistration.toString(16).padStart(4, '0')\n return assertV4PoolParameters(`0x${`${tickSpacing}${hooksHex}`.padStart(BYTES32_HEX_LENGTH, '0')}`)\n}\n\nexport function decodeV4PoolParameters(encoded: V4PoolParameters | string): V4PoolParameterConfig {\n const parameters = assertV4PoolParameters(encoded)\n const hex = parameters.slice(2)\n const tickSpacingHex = hex.slice(-10, -4)\n const hooksHex = hex.slice(-4)\n const hooksRegistration = Number.parseInt(hooksHex, 16)\n\n return {\n tickSpacing: hexToSignedInt24(tickSpacingHex),\n hooksRegistration: decodeV4HooksRegistration(hooksRegistration),\n }\n}\n","import { SDK_ERROR_CODES, sdkInvariant, type TronAddress } from '@sun-protocol/sun-sdk-core'\nimport { keccak256 } from '@ethersproject/keccak256'\nimport { tronAddressToEvmHex } from './address.js'\nimport { normalizeV4PoolKey } from './pool-key.js'\nimport type { V4PoolId, V4PoolKey } from './types.js'\n\nconst EVM_ADDRESS_HEX_LENGTH = 40\nconst BYTES32_HEX_LENGTH = 64\n\nfunction assertHex(value: string, label: string): string {\n sdkInvariant(/^0x[a-fA-F0-9]*$/.test(value), SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, `${label} must be hex`, {\n label,\n value,\n })\n return value.toLowerCase()\n}\n\nfunction encodeAbiAddress(value: TronAddress | string): string {\n const address = tronAddressToEvmHex(value).slice(2)\n sdkInvariant(\n address.length === EVM_ADDRESS_HEX_LENGTH,\n SDK_ERROR_CODES.SDK_INVALID_ARGUMENT,\n 'Encoded EVM address must be 20 bytes',\n { value },\n )\n return address.padStart(BYTES32_HEX_LENGTH, '0')\n}\n\nfunction encodeAbiUint24(value: number): string {\n sdkInvariant(Number.isInteger(value) && value >= 0 && value <= 0xffffff, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'uint24 value is out of range', {\n value,\n })\n return value.toString(16).padStart(BYTES32_HEX_LENGTH, '0')\n}\n\nfunction encodeAbiBytes32(value: string): string {\n const bytes32 = assertHex(value, 'bytes32').slice(2)\n sdkInvariant(bytes32.length === BYTES32_HEX_LENGTH, SDK_ERROR_CODES.SDK_INVALID_ARGUMENT, 'bytes32 must be 32 bytes', {\n value,\n })\n return bytes32\n}\n\nexport function encodeV4PoolKey(poolKey: V4PoolKey): `0x${string}` {\n const normalized = normalizeV4PoolKey(poolKey)\n return `0x${[\n encodeAbiAddress(normalized.currency0),\n encodeAbiAddress(normalized.currency1),\n encodeAbiAddress(normalized.hooks),\n encodeAbiUint24(normalized.fee),\n encodeAbiBytes32(normalized.parameters),\n ].join('')}`\n}\n\nexport function computeV4PoolId(poolKey: V4PoolKey): V4PoolId {\n return keccak256(encodeV4PoolKey(poolKey)) as V4PoolId\n}\n","import { getContractAddress } from '@sun-protocol/sun-sdk-chains'\nimport type { BigintIsh, ContractParameter, Network, TronAddress } from '@sun-protocol/sun-sdk-core'\nimport { assertV4PoolId } from './pool-key.js'\nimport type { V4PoolId } from './types.js'\n\nexport interface V4ContractReadSpec {\n readonly target: TronAddress\n readonly functionSelector: string\n readonly parameters?: readonly ContractParameter[]\n readonly abiFunction?: V4ReadAbiFunction\n readonly metadata?: Record<string, unknown>\n}\n\ninterface V4ReadAbiParameter {\n readonly name?: string\n readonly type: string\n readonly components?: readonly V4ReadAbiParameter[]\n}\n\ninterface V4ReadAbiFunction {\n readonly type: 'function'\n readonly name: string\n readonly stateMutability: 'view'\n readonly inputs: readonly V4ReadAbiParameter[]\n readonly outputs: readonly V4ReadAbiParameter[]\n}\n\nconst V4_POOL_KEY_ABI_COMPONENTS = [\n { name: 'currency0', type: 'address' },\n { name: 'currency1', type: 'address' },\n { name: 'hooks', type: 'address' },\n { name: 'fee', type: 'uint24' },\n { name: 'parameters', type: 'bytes32' },\n] as const\n\nfunction positionReadAbi(\n name: string,\n inputs: readonly V4ReadAbiParameter[],\n outputs: readonly V4ReadAbiParameter[],\n): V4ReadAbiFunction {\n return { type: 'function', name, stateMutability: 'view', inputs, outputs }\n}\n\nexport const V4_POSITION_MANAGER_READ_SELECTORS = {\n ownerOf: 'ownerOf(uint256)',\n getApproved: 'getApproved(uint256)',\n isApprovedForAll: 'isApprovedForAll(address,address)',\n getPoolAndPositionInfo: 'getPoolAndPositionInfo(uint256)',\n getPositionLiquidity: 'getPositionLiquidity(uint256)',\n} as const\n\nexport const V4_POOL_MANAGER_READ_SELECTORS = {\n getSlot0: 'getSlot0(bytes32)',\n getLiquidity: 'getLiquidity(bytes32)',\n poolIdToPoolKey: 'poolIdToPoolKey(bytes32)',\n getFeeGrowthGlobals: 'getFeeGrowthGlobals(bytes32)',\n} as const\n\nexport interface V4ReadOptions {\n readonly network: Network\n readonly positionManager?: TronAddress\n readonly poolManager?: TronAddress\n}\n\nexport interface BuildV4PositionReadParams extends V4ReadOptions {\n readonly tokenId: BigintIsh\n}\n\nexport interface BuildV4PoolReadParams extends V4ReadOptions {\n readonly poolId: V4PoolId | string\n}\n\nexport interface BuildV4PositionFeesReadParams extends V4ReadOptions {\n readonly tokenId: BigintIsh\n readonly poolId: V4PoolId | string\n readonly tickLower: number\n readonly tickUpper: number\n readonly lpFeeHelper?: TronAddress\n}\n\nexport interface BuildV4PositionApprovalReadParams extends V4ReadOptions {\n readonly owner: TronAddress\n readonly operator: TronAddress\n}\n\nexport interface BuildV4HookRegistrationBitmapReadParams {\n readonly network: Network\n readonly hooks: TronAddress\n}\n\nfunction valueOf(value: BigintIsh): string {\n return BigInt(value.toString()).toString()\n}\n\nfunction bytes32ValueOf(value: BigintIsh): string {\n const normalized = BigInt(value.toString())\n if (normalized < 0n || normalized >= (1n << 256n)) {\n throw new RangeError('tokenId must fit in an unsigned 256-bit value')\n }\n return `0x${normalized.toString(16).padStart(64, '0')}`\n}\n\nfunction positionManagerTarget(params: V4ReadOptions): TronAddress {\n return params.positionManager ?? getContractAddress(params.network, 'sunswapV4PositionManager')\n}\n\nfunction poolManagerTarget(params: V4ReadOptions): TronAddress {\n return params.poolManager ?? getContractAddress(params.network, 'sunswapV4PoolManager')\n}\n\nfunction positionManagerRead(\n params: V4ReadOptions,\n functionSelector: string,\n parameters: readonly ContractParameter[],\n action: string,\n abiFunction: V4ReadAbiFunction,\n): V4ContractReadSpec {\n return {\n target: positionManagerTarget(params),\n functionSelector,\n parameters,\n abiFunction,\n metadata: { protocol: 'sunswap-v4', contract: 'position-manager', action, network: params.network },\n }\n}\n\nfunction poolReadAbi(functionSelector: string): V4ReadAbiFunction {\n const name = functionSelector.slice(0, functionSelector.indexOf('('))\n const outputs: Record<string, readonly V4ReadAbiParameter[]> = {\n getSlot0: [\n { name: 'sqrtPriceX96', type: 'uint160' },\n { name: 'tick', type: 'int24' },\n { name: 'protocolFee', type: 'uint24' },\n { name: 'lpFee', type: 'uint24' },\n ],\n getLiquidity: [{ name: 'liquidity', type: 'uint128' }],\n poolIdToPoolKey: V4_POOL_KEY_ABI_COMPONENTS,\n getFeeGrowthGlobals: [\n { name: 'feeGrowthGlobal0X128', type: 'uint256' },\n { name: 'feeGrowthGlobal1X128', type: 'uint256' },\n ],\n }\n return positionReadAbi(name, [{ name: 'id', type: 'bytes32' }], outputs[name] ?? [])\n}\n\nfunction poolManagerRead(params: V4ReadOptions, functionSelector: string, poolId: V4PoolId | string): V4ContractReadSpec {\n return {\n target: poolManagerTarget(params),\n functionSelector,\n parameters: [{ type: 'bytes32', value: assertV4PoolId(poolId) }],\n abiFunction: poolReadAbi(functionSelector),\n metadata: { protocol: 'sunswap-v4', contract: 'pool-manager', network: params.network },\n }\n}\n\nexport function buildV4PoolSlot0Read(params: BuildV4PoolReadParams): V4ContractReadSpec {\n return poolManagerRead(params, V4_POOL_MANAGER_READ_SELECTORS.getSlot0, params.poolId)\n}\n\nexport function buildV4PoolLiquidityRead(params: BuildV4PoolReadParams): V4ContractReadSpec {\n return poolManagerRead(params, V4_POOL_MANAGER_READ_SELECTORS.getLiquidity, params.poolId)\n}\n\nexport function buildV4PoolKeyRead(params: BuildV4PoolReadParams): V4ContractReadSpec {\n return poolManagerRead(params, V4_POOL_MANAGER_READ_SELECTORS.poolIdToPoolKey, params.poolId)\n}\n\nexport function buildV4PoolFeeGrowthGlobalsRead(params: BuildV4PoolReadParams): V4ContractReadSpec {\n return poolManagerRead(params, V4_POOL_MANAGER_READ_SELECTORS.getFeeGrowthGlobals, params.poolId)\n}\n\nexport function buildV4HookRegistrationBitmapRead(\n params: BuildV4HookRegistrationBitmapReadParams,\n): V4ContractReadSpec {\n return {\n target: params.hooks,\n functionSelector: 'getHooksRegistrationBitmap()',\n abiFunction: positionReadAbi(\n 'getHooksRegistrationBitmap',\n [],\n [{ name: 'permissions', type: 'uint16' }],\n ),\n metadata: {\n protocol: 'sunswap-v4',\n contract: 'hooks',\n action: 'get-registration-bitmap',\n network: params.network,\n },\n }\n}\n\nexport function buildV4PoolStateReads(params: BuildV4PoolReadParams): readonly V4ContractReadSpec[] {\n return [buildV4PoolSlot0Read(params), buildV4PoolLiquidityRead(params)]\n}\n\nexport function buildV4PositionOwnerRead(params: BuildV4PositionReadParams): V4ContractReadSpec {\n return positionManagerRead(\n params,\n V4_POSITION_MANAGER_READ_SELECTORS.ownerOf,\n [{ type: 'uint256', value: valueOf(params.tokenId) }],\n 'owner-of',\n positionReadAbi('ownerOf', [{ name: 'id', type: 'uint256' }], [{ name: 'owner', type: 'address' }]),\n )\n}\n\nexport function buildV4PositionApprovedRead(params: BuildV4PositionReadParams): V4ContractReadSpec {\n return positionManagerRead(\n params,\n V4_POSITION_MANAGER_READ_SELECTORS.getApproved,\n [{ type: 'uint256', value: valueOf(params.tokenId) }],\n 'get-approved',\n positionReadAbi('getApproved', [{ name: 'tokenId', type: 'uint256' }], [{ name: 'approved', type: 'address' }]),\n )\n}\n\nexport function buildV4PoolAndPositionInfoRead(params: BuildV4PositionReadParams): V4ContractReadSpec {\n return positionManagerRead(\n params,\n V4_POSITION_MANAGER_READ_SELECTORS.getPoolAndPositionInfo,\n [{ type: 'uint256', value: valueOf(params.tokenId) }],\n 'get-pool-and-position-info',\n positionReadAbi(\n 'getPoolAndPositionInfo',\n [{ name: 'tokenId', type: 'uint256' }],\n [\n { name: 'poolKey', type: 'tuple', components: V4_POOL_KEY_ABI_COMPONENTS },\n { name: 'info', type: 'uint256' },\n ],\n ),\n )\n}\n\nexport function buildV4PositionLiquidityRead(params: BuildV4PositionReadParams): V4ContractReadSpec {\n return positionManagerRead(\n params,\n V4_POSITION_MANAGER_READ_SELECTORS.getPositionLiquidity,\n [{ type: 'uint256', value: valueOf(params.tokenId) }],\n 'get-position-liquidity',\n positionReadAbi('getPositionLiquidity', [{ name: 'tokenId', type: 'uint256' }], [{ name: 'liquidity', type: 'uint128' }]),\n )\n}\n\nexport function buildV4PositionApprovalForAllRead(params: BuildV4PositionApprovalReadParams): V4ContractReadSpec {\n return positionManagerRead(\n params,\n V4_POSITION_MANAGER_READ_SELECTORS.isApprovedForAll,\n [\n { type: 'address', value: params.owner },\n { type: 'address', value: params.operator },\n ],\n 'is-approved-for-all',\n positionReadAbi(\n 'isApprovedForAll',\n [{ name: 'owner', type: 'address' }, { name: 'operator', type: 'address' }],\n [{ name: 'approved', type: 'bool' }],\n ),\n )\n}\n\nexport function buildV4PositionFeesRead(params: BuildV4PositionFeesReadParams): V4ContractReadSpec {\n return {\n target: params.lpFeeHelper ?? getContractAddress(params.network, 'sunswapV4LpFeeHelper'),\n functionSelector: 'getLPFees(address,bytes32,address,int24,int24,bytes32)',\n parameters: [\n { type: 'address', value: poolManagerTarget(params) },\n { type: 'bytes32', value: assertV4PoolId(params.poolId) },\n { type: 'address', value: positionManagerTarget(params) },\n { type: 'int24', value: params.tickLower },\n { type: 'int24', value: params.tickUpper },\n { type: 'bytes32', value: bytes32ValueOf(params.tokenId) },\n ],\n abiFunction: positionReadAbi(\n 'getLPFees',\n [\n { name: 'poolManager', type: 'address' },\n { name: 'poolId', type: 'bytes32' },\n { name: 'owner', type: 'address' },\n { name: 'tickLower', type: 'int24' },\n { name: 'tickUpper', type: 'int24' },\n { name: 'salt', type: 'bytes32' },\n ],\n [\n { name: 'feesOwed0', type: 'uint256' },\n { name: 'feesOwed1', type: 'uint256' },\n ],\n ),\n metadata: {\n protocol: 'sunswap-v4',\n contract: 'lp-fee-helper',\n action: 'get-position-fees',\n network: params.network,\n },\n }\n}\n\nexport function buildV4PositionReads(params: BuildV4PositionReadParams): readonly V4ContractReadSpec[] {\n return [\n buildV4PoolAndPositionInfoRead(params),\n buildV4PositionLiquidityRead(params),\n buildV4PositionOwnerRead(params),\n buildV4PositionApprovedRead(params),\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAuB;AACvB,0BAAgE;AAEhE,IAAM,kBAAkB;AACxB,IAAM,qBAAqB;AAC3B,IAAM,6BAA6B;AAEnC,SAAS,aAAa,OAA2B;AAC/C,MAAI,UAAU;AAEd,aAAW,QAAQ,OAAO;AACxB,UAAM,QAAQ,gBAAgB,QAAQ,IAAI;AAC1C,0CAAa,SAAS,GAAG,oCAAgB,sBAAsB,4BAA4B,EAAE,OAAO,KAAK,CAAC;AAC1G,cAAU,UAAU,MAAM,OAAO,KAAK;AAAA,EACxC;AAEA,QAAM,QAAkB,CAAC;AACzB,SAAO,UAAU,IAAI;AACnB,UAAM,QAAQ,OAAO,UAAU,KAAK,CAAC;AACrC,gBAAY;AAAA,EACd;AAEA,aAAW,QAAQ,OAAO;AACxB,QAAI,SAAS,IAAK;AAClB,UAAM,QAAQ,CAAC;AAAA,EACjB;AAEA,SAAO,WA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M,aAAa,MAAM,QAAQ;AAAA,QACnC,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,MAClC;AAAA,MACA;AAAA,QACE,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,QACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,MACvC;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,UAAU;AAAA,MACV,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,SAAS,OAAO;AAAA,IAClB;AAAA,EACF;AACF;AAEO,SAAS,qBAAqB,QAAkE;AACrG,SAAO;AAAA,IACL,+BAA+B,MAAM;AAAA,IACrC,6BAA6B,MAAM;AAAA,IACnC,yBAAyB,MAAM;AAAA,IAC/B,4BAA4B,MAAM;AAAA,EACpC;AACF;","names":["import_sun_sdk_core","import_sun_sdk_core","import_sun_sdk_core","HEX_BYTES_PATTERN","assertHexBytes","import_sun_sdk_core","import_sun_sdk_core","import_keccak256","BYTES32_HEX_LENGTH","import_sun_sdk_chains","valueOf","positionManagerTarget","functionSelector"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { TronAddress, Network, BigintIsh, TokenRequirement, ContractCallAction, ContractParameter } from '@sun-protocol/sun-sdk-core';
|
|
2
|
+
|
|
3
|
+
declare function tronAddressToEvmHex(address: TronAddress | string): `0x${string}`;
|
|
4
|
+
|
|
5
|
+
type V4PoolParameters = string & {
|
|
6
|
+
readonly __v4PoolParameters: unique symbol;
|
|
7
|
+
};
|
|
8
|
+
type V4PoolId = string & {
|
|
9
|
+
readonly __v4PoolId: unique symbol;
|
|
10
|
+
};
|
|
11
|
+
interface V4HooksRegistration {
|
|
12
|
+
readonly beforeInitialize?: boolean;
|
|
13
|
+
readonly afterInitialize?: boolean;
|
|
14
|
+
readonly beforeAddLiquidity?: boolean;
|
|
15
|
+
readonly afterAddLiquidity?: boolean;
|
|
16
|
+
readonly beforeRemoveLiquidity?: boolean;
|
|
17
|
+
readonly afterRemoveLiquidity?: boolean;
|
|
18
|
+
readonly beforeSwap?: boolean;
|
|
19
|
+
readonly afterSwap?: boolean;
|
|
20
|
+
readonly beforeDonate?: boolean;
|
|
21
|
+
readonly afterDonate?: boolean;
|
|
22
|
+
readonly beforeSwapReturnsDelta?: boolean;
|
|
23
|
+
readonly afterSwapReturnsDelta?: boolean;
|
|
24
|
+
readonly afterAddLiquidityReturnsDelta?: boolean;
|
|
25
|
+
readonly afterRemoveLiquidityReturnsDelta?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface V4PoolParameterConfig {
|
|
28
|
+
readonly tickSpacing: number;
|
|
29
|
+
readonly hooksRegistration?: V4HooksRegistration;
|
|
30
|
+
}
|
|
31
|
+
interface V4PoolKey {
|
|
32
|
+
readonly network: Network;
|
|
33
|
+
readonly currency0: TronAddress;
|
|
34
|
+
readonly currency1: TronAddress;
|
|
35
|
+
readonly hooks: TronAddress;
|
|
36
|
+
readonly fee: number;
|
|
37
|
+
readonly parameters: V4PoolParameters;
|
|
38
|
+
}
|
|
39
|
+
interface V4PoolState {
|
|
40
|
+
readonly poolKey: V4PoolKey;
|
|
41
|
+
readonly sqrtPriceX96: BigintIsh;
|
|
42
|
+
readonly tick: number;
|
|
43
|
+
readonly liquidity: BigintIsh;
|
|
44
|
+
}
|
|
45
|
+
interface V4TickRange {
|
|
46
|
+
readonly tickLower: number;
|
|
47
|
+
readonly tickUpper: number;
|
|
48
|
+
}
|
|
49
|
+
interface V4PositionKey extends V4TickRange {
|
|
50
|
+
readonly poolKey: V4PoolKey;
|
|
51
|
+
readonly salt?: string;
|
|
52
|
+
}
|
|
53
|
+
interface V4Position extends V4PositionKey {
|
|
54
|
+
readonly tokenId?: BigintIsh;
|
|
55
|
+
readonly liquidity: BigintIsh;
|
|
56
|
+
readonly tokensOwed0?: BigintIsh;
|
|
57
|
+
readonly tokensOwed1?: BigintIsh;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
declare const V4_ACTIONS: {
|
|
61
|
+
readonly CL_INCREASE_LIQUIDITY: 0;
|
|
62
|
+
readonly CL_DECREASE_LIQUIDITY: 1;
|
|
63
|
+
readonly CL_MINT_POSITION: 2;
|
|
64
|
+
readonly SETTLE: 11;
|
|
65
|
+
readonly SETTLE_PAIR: 13;
|
|
66
|
+
readonly TAKE_PAIR: 17;
|
|
67
|
+
readonly CLOSE_CURRENCY: 18;
|
|
68
|
+
readonly SWEEP: 20;
|
|
69
|
+
};
|
|
70
|
+
declare const V4_ACTION_CONSTANTS: {
|
|
71
|
+
readonly OPEN_DELTA: 0n;
|
|
72
|
+
readonly MSG_SENDER: "0x0000000000000000000000000000000000000001";
|
|
73
|
+
readonly ADDRESS_THIS: "0x0000000000000000000000000000000000000002";
|
|
74
|
+
};
|
|
75
|
+
type V4Action = (typeof V4_ACTIONS)[keyof typeof V4_ACTIONS];
|
|
76
|
+
type V4BigintIsh = BigintIsh | bigint;
|
|
77
|
+
interface V4PositionConfig {
|
|
78
|
+
readonly poolKey: V4PoolKey;
|
|
79
|
+
readonly tickLower: number;
|
|
80
|
+
readonly tickUpper: number;
|
|
81
|
+
}
|
|
82
|
+
interface V4PlannerPlan {
|
|
83
|
+
readonly action: V4Action;
|
|
84
|
+
readonly params: readonly V4PlannerParam[];
|
|
85
|
+
}
|
|
86
|
+
type V4PlannerParam = V4PositionConfig | TronAddress | `0x${string}` | V4BigintIsh | number | boolean;
|
|
87
|
+
interface EncodeV4MintPositionPayloadParams {
|
|
88
|
+
readonly positionConfig: V4PositionConfig;
|
|
89
|
+
readonly liquidity: V4BigintIsh;
|
|
90
|
+
readonly amount0Max: V4BigintIsh;
|
|
91
|
+
readonly amount1Max: V4BigintIsh;
|
|
92
|
+
readonly owner: TronAddress;
|
|
93
|
+
readonly sweepRecipient?: TronAddress;
|
|
94
|
+
readonly hookData?: string;
|
|
95
|
+
}
|
|
96
|
+
interface EncodeV4IncreaseLiquidityPayloadParams {
|
|
97
|
+
readonly poolKey: V4PoolKey;
|
|
98
|
+
readonly tokenId: V4BigintIsh;
|
|
99
|
+
readonly liquidity: V4BigintIsh;
|
|
100
|
+
readonly amount0Max: V4BigintIsh;
|
|
101
|
+
readonly amount1Max: V4BigintIsh;
|
|
102
|
+
readonly sweepRecipient?: TronAddress;
|
|
103
|
+
readonly hookData?: string;
|
|
104
|
+
}
|
|
105
|
+
interface EncodeV4DecreaseLiquidityPayloadParams {
|
|
106
|
+
readonly poolKey: V4PoolKey;
|
|
107
|
+
readonly tokenId: V4BigintIsh;
|
|
108
|
+
readonly liquidity: V4BigintIsh;
|
|
109
|
+
readonly amount0Min: V4BigintIsh;
|
|
110
|
+
readonly amount1Min: V4BigintIsh;
|
|
111
|
+
readonly recipient: TronAddress;
|
|
112
|
+
readonly hookData?: string;
|
|
113
|
+
readonly settlementMode?: 'take-pair' | 'close-currency';
|
|
114
|
+
}
|
|
115
|
+
interface EncodeV4CollectPayloadParams {
|
|
116
|
+
readonly poolKey: V4PoolKey;
|
|
117
|
+
readonly recipient: TronAddress;
|
|
118
|
+
}
|
|
119
|
+
declare function encodeV4Actions(plans: readonly V4PlannerPlan[]): `0x${string}`;
|
|
120
|
+
declare function encodeV4ActionParams(plans: readonly V4PlannerPlan[]): readonly `0x${string}`[];
|
|
121
|
+
declare function encodeV4ActionsPlanner(plans: readonly V4PlannerPlan[]): `0x${string}`;
|
|
122
|
+
declare function encodeV4MintPositionPlannerPayload(params: EncodeV4MintPositionPayloadParams): `0x${string}`;
|
|
123
|
+
declare function encodeV4IncreaseLiquidityPlannerPayload(params: EncodeV4IncreaseLiquidityPayloadParams): `0x${string}`;
|
|
124
|
+
declare function encodeV4DecreaseLiquidityPlannerPayload(params: EncodeV4DecreaseLiquidityPayloadParams): `0x${string}`;
|
|
125
|
+
declare function encodeV4CollectPlannerPayload(params: EncodeV4CollectPayloadParams): `0x${string}`;
|
|
126
|
+
|
|
127
|
+
declare const V4_POSITION_MANAGER_SELECTORS: {
|
|
128
|
+
readonly initializePool: "initializePool((address,address,address,uint24,bytes32),uint160)";
|
|
129
|
+
readonly modifyLiquidities: "modifyLiquidities(bytes,uint256)";
|
|
130
|
+
readonly multicall: "multicall(bytes[])";
|
|
131
|
+
};
|
|
132
|
+
interface V4ActionOptions {
|
|
133
|
+
readonly network: Network;
|
|
134
|
+
readonly positionManager?: TronAddress;
|
|
135
|
+
readonly feeLimit?: number;
|
|
136
|
+
readonly callValue?: bigint;
|
|
137
|
+
readonly id?: string;
|
|
138
|
+
readonly metadata?: Record<string, unknown>;
|
|
139
|
+
readonly tokenRequirements?: readonly TokenRequirement[];
|
|
140
|
+
}
|
|
141
|
+
interface BuildV4InitializePoolActionParams extends V4ActionOptions {
|
|
142
|
+
readonly poolKey: V4PoolKey;
|
|
143
|
+
readonly sqrtPriceX96: BigintIsh;
|
|
144
|
+
}
|
|
145
|
+
interface BuildV4ModifyLiquiditiesActionParams extends V4ActionOptions {
|
|
146
|
+
readonly payload: string;
|
|
147
|
+
readonly deadline: V4BigintIsh;
|
|
148
|
+
}
|
|
149
|
+
interface BuildV4MulticallActionParams extends V4ActionOptions {
|
|
150
|
+
readonly calls: readonly string[];
|
|
151
|
+
}
|
|
152
|
+
/** A signed Permit2 allowance to be forwarded by the V4 PositionManager multicall. */
|
|
153
|
+
interface V4Permit2Signature {
|
|
154
|
+
readonly details: {
|
|
155
|
+
readonly token: TronAddress | string;
|
|
156
|
+
readonly amount: BigintIsh;
|
|
157
|
+
readonly expiration: BigintIsh;
|
|
158
|
+
readonly nonce: BigintIsh;
|
|
159
|
+
};
|
|
160
|
+
readonly spender: TronAddress | string;
|
|
161
|
+
readonly sigDeadline: BigintIsh;
|
|
162
|
+
readonly signature: string;
|
|
163
|
+
}
|
|
164
|
+
interface BuildV4MintPositionActionParams extends V4ActionOptions {
|
|
165
|
+
readonly positionConfig: V4PositionConfig;
|
|
166
|
+
readonly liquidity: V4BigintIsh;
|
|
167
|
+
readonly amount0Max: V4BigintIsh;
|
|
168
|
+
readonly amount1Max: V4BigintIsh;
|
|
169
|
+
readonly owner: TronAddress;
|
|
170
|
+
readonly deadline: V4BigintIsh;
|
|
171
|
+
readonly sweepRecipient?: TronAddress;
|
|
172
|
+
readonly hookData?: string;
|
|
173
|
+
}
|
|
174
|
+
interface BuildV4IncreaseLiquidityActionParams extends V4ActionOptions {
|
|
175
|
+
readonly poolKey: V4PoolKey;
|
|
176
|
+
readonly tokenId: V4BigintIsh;
|
|
177
|
+
readonly liquidity: V4BigintIsh;
|
|
178
|
+
readonly amount0Max: V4BigintIsh;
|
|
179
|
+
readonly amount1Max: V4BigintIsh;
|
|
180
|
+
readonly deadline: V4BigintIsh;
|
|
181
|
+
readonly sweepRecipient?: TronAddress;
|
|
182
|
+
readonly hookData?: string;
|
|
183
|
+
}
|
|
184
|
+
interface BuildV4DecreaseLiquidityActionParams extends V4ActionOptions {
|
|
185
|
+
readonly poolKey: V4PoolKey;
|
|
186
|
+
readonly tokenId: V4BigintIsh;
|
|
187
|
+
readonly liquidity: V4BigintIsh;
|
|
188
|
+
readonly amount0Min: V4BigintIsh;
|
|
189
|
+
readonly amount1Min: V4BigintIsh;
|
|
190
|
+
readonly recipient: TronAddress;
|
|
191
|
+
readonly deadline: V4BigintIsh;
|
|
192
|
+
readonly hookData?: string;
|
|
193
|
+
readonly settlementMode?: 'take-pair' | 'close-currency';
|
|
194
|
+
}
|
|
195
|
+
interface BuildV4CollectActionParams extends V4ActionOptions {
|
|
196
|
+
readonly poolKey: V4PoolKey;
|
|
197
|
+
readonly tokenId: V4BigintIsh;
|
|
198
|
+
readonly recipient: TronAddress;
|
|
199
|
+
readonly deadline: V4BigintIsh;
|
|
200
|
+
readonly hookData?: string;
|
|
201
|
+
readonly settlementMode?: 'take-pair' | 'close-currency';
|
|
202
|
+
}
|
|
203
|
+
type V4TokenRequirement = TokenRequirement;
|
|
204
|
+
/**
|
|
205
|
+
* Encodes the PositionManager's Permit2Forward.permit call for use as one item
|
|
206
|
+
* in PositionManager.multicall(bytes[]). This matches the legacy V4 add flow:
|
|
207
|
+
* typed-data signing happens off-chain, then the signed permit is forwarded in
|
|
208
|
+
* the final liquidity transaction.
|
|
209
|
+
*/
|
|
210
|
+
declare function encodeV4Permit2ForwardCall(input: {
|
|
211
|
+
readonly owner: TronAddress | string;
|
|
212
|
+
readonly permit: V4Permit2Signature;
|
|
213
|
+
}): `0x${string}`;
|
|
214
|
+
/** Encodes the two V4 position-manager actions that may be nested in multicall(bytes[]). */
|
|
215
|
+
declare function encodeV4ContractCallAction(action: ContractCallAction): `0x${string}`;
|
|
216
|
+
declare function buildV4InitializePoolAction(params: BuildV4InitializePoolActionParams): ContractCallAction;
|
|
217
|
+
declare function buildV4ModifyLiquiditiesAction(params: BuildV4ModifyLiquiditiesActionParams): ContractCallAction;
|
|
218
|
+
declare function buildV4MulticallAction(params: BuildV4MulticallActionParams): ContractCallAction;
|
|
219
|
+
declare function buildV4MintPositionAction(params: BuildV4MintPositionActionParams): ContractCallAction;
|
|
220
|
+
declare function buildV4IncreaseLiquidityAction(params: BuildV4IncreaseLiquidityActionParams): ContractCallAction;
|
|
221
|
+
declare function buildV4DecreaseLiquidityAction(params: BuildV4DecreaseLiquidityActionParams): ContractCallAction;
|
|
222
|
+
declare function buildV4CollectAction(params: BuildV4CollectActionParams): ContractCallAction;
|
|
223
|
+
|
|
224
|
+
declare const V4_HOOKS_REGISTRATION_OFFSET: Record<keyof V4HooksRegistration, number>;
|
|
225
|
+
declare function encodeV4HooksRegistration(hooksRegistration?: V4HooksRegistration): number;
|
|
226
|
+
declare function decodeV4HooksRegistration(registration: number): V4HooksRegistration;
|
|
227
|
+
declare function encodeV4PoolParameters(params: V4PoolParameterConfig): V4PoolParameters;
|
|
228
|
+
declare function decodeV4PoolParameters(encoded: V4PoolParameters | string): V4PoolParameterConfig;
|
|
229
|
+
|
|
230
|
+
declare function encodeV4PoolKey(poolKey: V4PoolKey): `0x${string}`;
|
|
231
|
+
declare function computeV4PoolId(poolKey: V4PoolKey): V4PoolId;
|
|
232
|
+
|
|
233
|
+
declare const V4_DYNAMIC_FEE_FLAG = 8388608;
|
|
234
|
+
declare const V4_UINT24_MAX = 16777215;
|
|
235
|
+
declare const V4_MAX_STATIC_FEE = 1000000;
|
|
236
|
+
declare const V4_EMPTY_PARAMETERS: V4PoolParameters;
|
|
237
|
+
interface CreateV4PoolKeyInput {
|
|
238
|
+
readonly network: Network;
|
|
239
|
+
readonly currencyA: TronAddress | string;
|
|
240
|
+
readonly currencyB: TronAddress | string;
|
|
241
|
+
readonly hooks?: TronAddress | string;
|
|
242
|
+
readonly fee: number;
|
|
243
|
+
readonly parameters?: V4PoolParameters | string;
|
|
244
|
+
}
|
|
245
|
+
declare function isV4DynamicFee(fee: number): boolean;
|
|
246
|
+
declare function getV4StaticFee(fee: number): number;
|
|
247
|
+
declare function assertV4PoolParameters(value: string, label?: string): V4PoolParameters;
|
|
248
|
+
declare function assertV4PoolId(value: string, label?: string): V4PoolId;
|
|
249
|
+
declare function assertV4Fee(fee: number): number;
|
|
250
|
+
declare function assertV4HookFeeCombination(hooks: TronAddress, fee: number): void;
|
|
251
|
+
declare function normalizeV4PoolKey(input: V4PoolKey): V4PoolKey;
|
|
252
|
+
declare function createV4PoolKey(input: CreateV4PoolKeyInput): V4PoolKey;
|
|
253
|
+
declare function toV4PoolKeyTuple(poolKey: V4PoolKey): ContractParameter;
|
|
254
|
+
|
|
255
|
+
interface V4ContractReadSpec {
|
|
256
|
+
readonly target: TronAddress;
|
|
257
|
+
readonly functionSelector: string;
|
|
258
|
+
readonly parameters?: readonly ContractParameter[];
|
|
259
|
+
readonly abiFunction?: V4ReadAbiFunction;
|
|
260
|
+
readonly metadata?: Record<string, unknown>;
|
|
261
|
+
}
|
|
262
|
+
interface V4ReadAbiParameter {
|
|
263
|
+
readonly name?: string;
|
|
264
|
+
readonly type: string;
|
|
265
|
+
readonly components?: readonly V4ReadAbiParameter[];
|
|
266
|
+
}
|
|
267
|
+
interface V4ReadAbiFunction {
|
|
268
|
+
readonly type: 'function';
|
|
269
|
+
readonly name: string;
|
|
270
|
+
readonly stateMutability: 'view';
|
|
271
|
+
readonly inputs: readonly V4ReadAbiParameter[];
|
|
272
|
+
readonly outputs: readonly V4ReadAbiParameter[];
|
|
273
|
+
}
|
|
274
|
+
declare const V4_POSITION_MANAGER_READ_SELECTORS: {
|
|
275
|
+
readonly ownerOf: "ownerOf(uint256)";
|
|
276
|
+
readonly getApproved: "getApproved(uint256)";
|
|
277
|
+
readonly isApprovedForAll: "isApprovedForAll(address,address)";
|
|
278
|
+
readonly getPoolAndPositionInfo: "getPoolAndPositionInfo(uint256)";
|
|
279
|
+
readonly getPositionLiquidity: "getPositionLiquidity(uint256)";
|
|
280
|
+
};
|
|
281
|
+
declare const V4_POOL_MANAGER_READ_SELECTORS: {
|
|
282
|
+
readonly getSlot0: "getSlot0(bytes32)";
|
|
283
|
+
readonly getLiquidity: "getLiquidity(bytes32)";
|
|
284
|
+
readonly poolIdToPoolKey: "poolIdToPoolKey(bytes32)";
|
|
285
|
+
readonly getFeeGrowthGlobals: "getFeeGrowthGlobals(bytes32)";
|
|
286
|
+
};
|
|
287
|
+
interface V4ReadOptions {
|
|
288
|
+
readonly network: Network;
|
|
289
|
+
readonly positionManager?: TronAddress;
|
|
290
|
+
readonly poolManager?: TronAddress;
|
|
291
|
+
}
|
|
292
|
+
interface BuildV4PositionReadParams extends V4ReadOptions {
|
|
293
|
+
readonly tokenId: BigintIsh;
|
|
294
|
+
}
|
|
295
|
+
interface BuildV4PoolReadParams extends V4ReadOptions {
|
|
296
|
+
readonly poolId: V4PoolId | string;
|
|
297
|
+
}
|
|
298
|
+
interface BuildV4PositionFeesReadParams extends V4ReadOptions {
|
|
299
|
+
readonly tokenId: BigintIsh;
|
|
300
|
+
readonly poolId: V4PoolId | string;
|
|
301
|
+
readonly tickLower: number;
|
|
302
|
+
readonly tickUpper: number;
|
|
303
|
+
readonly lpFeeHelper?: TronAddress;
|
|
304
|
+
}
|
|
305
|
+
interface BuildV4PositionApprovalReadParams extends V4ReadOptions {
|
|
306
|
+
readonly owner: TronAddress;
|
|
307
|
+
readonly operator: TronAddress;
|
|
308
|
+
}
|
|
309
|
+
interface BuildV4HookRegistrationBitmapReadParams {
|
|
310
|
+
readonly network: Network;
|
|
311
|
+
readonly hooks: TronAddress;
|
|
312
|
+
}
|
|
313
|
+
declare function buildV4PoolSlot0Read(params: BuildV4PoolReadParams): V4ContractReadSpec;
|
|
314
|
+
declare function buildV4PoolLiquidityRead(params: BuildV4PoolReadParams): V4ContractReadSpec;
|
|
315
|
+
declare function buildV4PoolKeyRead(params: BuildV4PoolReadParams): V4ContractReadSpec;
|
|
316
|
+
declare function buildV4PoolFeeGrowthGlobalsRead(params: BuildV4PoolReadParams): V4ContractReadSpec;
|
|
317
|
+
declare function buildV4HookRegistrationBitmapRead(params: BuildV4HookRegistrationBitmapReadParams): V4ContractReadSpec;
|
|
318
|
+
declare function buildV4PoolStateReads(params: BuildV4PoolReadParams): readonly V4ContractReadSpec[];
|
|
319
|
+
declare function buildV4PositionOwnerRead(params: BuildV4PositionReadParams): V4ContractReadSpec;
|
|
320
|
+
declare function buildV4PositionApprovedRead(params: BuildV4PositionReadParams): V4ContractReadSpec;
|
|
321
|
+
declare function buildV4PoolAndPositionInfoRead(params: BuildV4PositionReadParams): V4ContractReadSpec;
|
|
322
|
+
declare function buildV4PositionLiquidityRead(params: BuildV4PositionReadParams): V4ContractReadSpec;
|
|
323
|
+
declare function buildV4PositionApprovalForAllRead(params: BuildV4PositionApprovalReadParams): V4ContractReadSpec;
|
|
324
|
+
declare function buildV4PositionFeesRead(params: BuildV4PositionFeesReadParams): V4ContractReadSpec;
|
|
325
|
+
declare function buildV4PositionReads(params: BuildV4PositionReadParams): readonly V4ContractReadSpec[];
|
|
326
|
+
|
|
327
|
+
export { type BuildV4CollectActionParams, type BuildV4DecreaseLiquidityActionParams, type BuildV4HookRegistrationBitmapReadParams, type BuildV4IncreaseLiquidityActionParams, type BuildV4InitializePoolActionParams, type BuildV4MintPositionActionParams, type BuildV4ModifyLiquiditiesActionParams, type BuildV4MulticallActionParams, type BuildV4PoolReadParams, type BuildV4PositionApprovalReadParams, type BuildV4PositionFeesReadParams, type BuildV4PositionReadParams, type CreateV4PoolKeyInput, type EncodeV4CollectPayloadParams, type EncodeV4DecreaseLiquidityPayloadParams, type EncodeV4IncreaseLiquidityPayloadParams, type EncodeV4MintPositionPayloadParams, type V4Action, type V4ActionOptions, type V4BigintIsh, type V4ContractReadSpec, type V4HooksRegistration, type V4Permit2Signature, type V4PlannerParam, type V4PlannerPlan, type V4PoolId, type V4PoolKey, type V4PoolParameterConfig, type V4PoolParameters, type V4PoolState, type V4Position, type V4PositionConfig, type V4PositionKey, type V4ReadOptions, type V4TickRange, type V4TokenRequirement, V4_ACTIONS, V4_ACTION_CONSTANTS, V4_DYNAMIC_FEE_FLAG, V4_EMPTY_PARAMETERS, V4_HOOKS_REGISTRATION_OFFSET, V4_MAX_STATIC_FEE, V4_POOL_MANAGER_READ_SELECTORS, V4_POSITION_MANAGER_READ_SELECTORS, V4_POSITION_MANAGER_SELECTORS, V4_UINT24_MAX, assertV4Fee, assertV4HookFeeCombination, assertV4PoolId, assertV4PoolParameters, buildV4CollectAction, buildV4DecreaseLiquidityAction, buildV4HookRegistrationBitmapRead, buildV4IncreaseLiquidityAction, buildV4InitializePoolAction, buildV4MintPositionAction, buildV4ModifyLiquiditiesAction, buildV4MulticallAction, buildV4PoolAndPositionInfoRead, buildV4PoolFeeGrowthGlobalsRead, buildV4PoolKeyRead, buildV4PoolLiquidityRead, buildV4PoolSlot0Read, buildV4PoolStateReads, buildV4PositionApprovalForAllRead, buildV4PositionApprovedRead, buildV4PositionFeesRead, buildV4PositionLiquidityRead, buildV4PositionOwnerRead, buildV4PositionReads, computeV4PoolId, createV4PoolKey, decodeV4HooksRegistration, decodeV4PoolParameters, encodeV4ActionParams, encodeV4Actions, encodeV4ActionsPlanner, encodeV4CollectPlannerPayload, encodeV4ContractCallAction, encodeV4DecreaseLiquidityPlannerPayload, encodeV4HooksRegistration, encodeV4IncreaseLiquidityPlannerPayload, encodeV4MintPositionPlannerPayload, encodeV4Permit2ForwardCall, encodeV4PoolKey, encodeV4PoolParameters, getV4StaticFee, isV4DynamicFee, normalizeV4PoolKey, toV4PoolKeyTuple, tronAddressToEvmHex };
|