@reptilianhq/uniswap-sdk 0.7.0 → 0.8.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.
@@ -1,5 +1,6 @@
1
1
  import type { Currency } from '@uniswap/sdk-core';
2
2
  import { type Address, type Hex } from 'viem';
3
+ import { type V4HookPermissions } from './hooks.js';
3
4
  export type V4TransactionMaterial = {
4
5
  to: Address;
5
6
  data: Hex;
@@ -33,6 +34,13 @@ export type V4MintPositionParams = {
33
34
  createPool?: boolean;
34
35
  /** A Permit2 batch approval signed by the caller's own wallet; see `buildV4MintPermitBatchTypedData`. */
35
36
  batchPermit?: V4BatchPermit;
37
+ /**
38
+ * Permission flags the caller has reviewed for `pool.hooks` (see `decodeV4HookPermissions`).
39
+ * Required whenever `pool.hooks` is not the zero address: a hook implementing a callback the
40
+ * caller has not modelled can move price, take a cut, or otherwise change what this mint
41
+ * actually does, so minting into one is refused rather than assumed benign.
42
+ */
43
+ modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
36
44
  };
37
45
  export type V4BatchPermitDetail = {
38
46
  token: Address;
@@ -58,9 +66,13 @@ export type V4BatchPermit = {
58
66
  * Pass `batchPermit` (built via `buildV4MintPermitBatchTypedData` and signed by the caller's own
59
67
  * wallet) to fold a Permit2 approval into this same transaction instead of requiring a prior,
60
68
  * separate ERC20 `approve`. Without it, callers must already hold a plain ERC20 approval or the
61
- * built transaction will revert on-chain. Hook-permission gating (refusing a pool whose hook
62
- * implements more than the caller has modelled) is the caller's responsibility either way; this
63
- * function only encodes what it is given.
69
+ * built transaction will revert on-chain.
70
+ *
71
+ * If `pool.hooks` is not the zero address, `modelledHookPermissions` is required and this
72
+ * function refuses to mint if the hook implements any permission flag outside it (see
73
+ * `decodeV4HookPermissions`/`unmodelledV4HookPermissions`) — a hook can move price, take a cut,
74
+ * or otherwise change what this mint actually does, so an unreviewed one is refused rather than
75
+ * assumed benign.
64
76
  */
65
77
  export declare function buildV4MintPositionTransaction(input: V4MintPositionParams): V4TransactionMaterial;
66
78
  export type V4PoolKeyMaterial = {
@@ -107,6 +119,13 @@ export type V4ExpectedMint = V4PoolKeyMaterial & {
107
119
  sigDeadline: bigint;
108
120
  details: readonly V4BatchPermitDetail[];
109
121
  };
122
+ /**
123
+ * Required if `hooks` is not the zero address; the permission flags the caller has reviewed
124
+ * for it. Minting into a hook that implements any other permission flag is refused — the
125
+ * same gate `buildV4MintPositionTransaction` applies when building this calldata in the
126
+ * first place, re-checked here independently of what the builder was told.
127
+ */
128
+ modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
110
129
  };
111
130
  /**
112
131
  * Decodes and verifies calldata built by `buildV4MintPositionTransaction`: a
@@ -1 +1 @@
1
- {"version":3,"file":"v4-transactions.d.ts","sourceRoot":"","sources":["../src/v4-transactions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAA4E,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAMxH,MAAM,MAAM,qBAAqB,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,GAAG,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9E,oGAAoG;AACpG,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,QAAQ,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE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import { checkedAddress } from './pool.js';
4
4
  import { invalid, UniswapSdkError } from './errors.js';
5
5
  import { v4PositionManagerAbi } from './abis.js';
6
+ import { unmodelledV4HookPermissions } from './hooks.js';
6
7
  function slippagePercent(bps) {
7
8
  if (!Number.isInteger(bps) || bps < 0 || bps > 10_000) {
8
9
  invalid('slippageToleranceBps must be an integer between 0 and 10000');
@@ -21,9 +22,13 @@ function same(a, b) {
21
22
  * Pass `batchPermit` (built via `buildV4MintPermitBatchTypedData` and signed by the caller's own
22
23
  * wallet) to fold a Permit2 approval into this same transaction instead of requiring a prior,
23
24
  * separate ERC20 `approve`. Without it, callers must already hold a plain ERC20 approval or the
24
- * built transaction will revert on-chain. Hook-permission gating (refusing a pool whose hook
25
- * implements more than the caller has modelled) is the caller's responsibility either way; this
26
- * function only encodes what it is given.
25
+ * built transaction will revert on-chain.
26
+ *
27
+ * If `pool.hooks` is not the zero address, `modelledHookPermissions` is required and this
28
+ * function refuses to mint if the hook implements any permission flag outside it (see
29
+ * `decodeV4HookPermissions`/`unmodelledV4HookPermissions`) — a hook can move price, take a cut,
30
+ * or otherwise change what this mint actually does, so an unreviewed one is refused rather than
31
+ * assumed benign.
27
32
  */
28
33
  export function buildV4MintPositionTransaction(input) {
29
34
  if (input.liquidity <= 0n)
@@ -36,6 +41,15 @@ export function buildV4MintPositionTransaction(input) {
36
41
  const positionManager = checkedAddress(input.positionManager);
37
42
  const recipient = checkedAddress(input.recipient);
38
43
  const slippageTolerance = slippagePercent(input.slippageToleranceBps);
44
+ const hooks = checkedAddress(input.pool.hooks);
45
+ if (!same(hooks, zeroAddress)) {
46
+ if (!input.modelledHookPermissions) {
47
+ invalid('pool.hooks is set but no modelledHookPermissions were supplied to verify it');
48
+ }
49
+ const unmodelled = unmodelledV4HookPermissions(hooks, input.modelledHookPermissions);
50
+ if (unmodelled.length)
51
+ invalid(`Pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);
52
+ }
39
53
  if (input.batchPermit) {
40
54
  if (!same(input.batchPermit.permitBatch.spender, positionManager)) {
41
55
  invalid('batchPermit.permitBatch.spender must be the position manager this transaction submits to');
@@ -57,7 +71,7 @@ export function buildV4MintPositionTransaction(input) {
57
71
  }
58
72
  }
59
73
  try {
60
- const pool = new Pool(input.pool.currency0, input.pool.currency1, input.pool.fee, input.pool.tickSpacing, checkedAddress(input.pool.hooks), input.pool.sqrtPriceX96.toString(), input.pool.liquidity.toString(), input.pool.tickCurrent);
74
+ const pool = new Pool(input.pool.currency0, input.pool.currency1, input.pool.fee, input.pool.tickSpacing, hooks, input.pool.sqrtPriceX96.toString(), input.pool.liquidity.toString(), input.pool.tickCurrent);
61
75
  const position = new Position({
62
76
  pool,
63
77
  liquidity: input.liquidity.toString(),
@@ -241,6 +255,14 @@ export function reviewV4MintPositionCalldata(data, expected) {
241
255
  mismatch('Mint calldata targets a different pool than expected');
242
256
  if (!same(owner, expected.recipient))
243
257
  mismatch('Mint calldata sends the position NFT to a different recipient');
258
+ if (!same(poolKey.hooks, zeroAddress)) {
259
+ if (!expected.modelledHookPermissions) {
260
+ mismatch('Mint calldata targets a pool with a hook but no modelled permissions were supplied to verify it');
261
+ }
262
+ const unmodelled = unmodelledV4HookPermissions(poolKey.hooks, expected.modelledHookPermissions);
263
+ if (unmodelled.length)
264
+ mismatch(`Mint calldata's pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);
265
+ }
244
266
  if (initialization) {
245
267
  if (expected.sqrtPriceX96 === undefined) {
246
268
  mismatch('Mint calldata initializes the pool but no expected starting price was supplied to verify it');
@@ -1 +1 @@
1
- {"version":3,"file":"v4-transactions.js","sourceRoot":"","sources":["../src/v4-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAA0B,MAAM,MAAM,CAAC;AACxH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,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WAAW,KAAK,QAAQ,CAAC,WAAW,CAAC,WAAW;mBAC5D,CAAC,sBAAsB,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;gBAChF,QAAQ,CAAC,0EAA0E,CAAC,CAAC;YACvF,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ;YAC3F,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjF,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,eAAe;YAAE,MAAM,KAAK,CAAC;QAClD,MAAM,IAAI,eAAe,CAAC,mBAAmB,EAAE,2DAA2D,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChI,CAAC;AACH,CAAC","sourcesContent":["import type { Currency } from '@uniswap/sdk-core';\nimport { decodeAbiParameters, decodeFunctionData, parseAbiParameters, zeroAddress, type Address, type Hex } from 'viem';\nimport { Percent, Pool, Position, V4PositionManager } from './official-sdk.cjs';\nimport { checkedAddress } from './pool.js';\nimport { invalid, UniswapSdkError } from './errors.js';\nimport { v4PositionManagerAbi } from './abis.js';\n\nexport type V4TransactionMaterial = { to: Address; data: Hex; value: bigint };\n\n/** Pool state as read from PoolManager/StateView (e.g. via `readV4Pool`), not yet a mint target. */\nexport type V4PoolState = {\n currency0: Currency;\n currency1: Currency;\n fee: number;\n tickSpacing: number;\n hooks: Address;\n sqrtPriceX96: bigint;\n liquidity: bigint;\n tickCurrent: number;\n};\n\nexport type V4MintPositionParams = {\n positionManager: Address;\n pool: V4PoolState;\n tickLower: number;\n tickUpper: number;\n /** Liquidity units to mint, not a token amount. */\n liquidity: bigint;\n recipient: Address;\n /** Integer basis points, 0-10000. */\n slippageToleranceBps: number;\n deadlineSeconds: bigint;\n /** Passed to the hook's callbacks verbatim; this SDK does not construct it. */\n hookData?: Hex;\n /** Atomically initializes the pool before minting. Requires `pool.sqrtPriceX96` to be the intended starting price. */\n createPool?: boolean;\n /** A Permit2 batch approval signed by the caller's own wallet; see `buildV4MintPermitBatchTypedData`. */\n batchPermit?: V4BatchPermit;\n};\n\nfunction slippagePercent(bps: number): Percent {\n if (!Number.isInteger(bps) || bps < 0 || bps > 10_000) {\n invalid('slippageToleranceBps must be an integer between 0 and 10000');\n }\n return new Percent(bps, 10_000);\n}\n\nfunction same(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\nexport type V4BatchPermitDetail = { token: Address; amount: bigint; expiration: bigint; nonce: bigint };\nexport type V4BatchPermit = {\n owner: Address;\n permitBatch: { details: readonly V4BatchPermitDetail[]; spender: Address; sigDeadline: bigint };\n signature: Hex;\n};\n\n/**\n * Builds unsigned calldata for `PositionManager.modifyLiquidities` minting a new v4 position.\n * Delegates encoding to `@uniswap/v4-sdk`'s `V4PositionManager`/`V4PositionPlanner` (the same\n * Actions/multicall encoding Uniswap's own SDK uses) rather than hand-rolling it, since v4's\n * calldata is a sequence of packed actions, not a single ABI-encoded function call like v3's.\n *\n * Pass `batchPermit` (built via `buildV4MintPermitBatchTypedData` and signed by the caller's own\n * wallet) to fold a Permit2 approval into this same transaction instead of requiring a prior,\n * separate ERC20 `approve`. Without it, callers must already hold a plain ERC20 approval or the\n * built transaction will revert on-chain. Hook-permission gating (refusing a pool whose hook\n * implements more than the caller has modelled) is the caller's responsibility either way; this\n * function only encodes what it is given.\n */\nexport function buildV4MintPositionTransaction(input: V4MintPositionParams): V4TransactionMaterial {\n if (input.liquidity <= 0n) invalid('Mint liquidity must be positive');\n if (!Number.isInteger(input.tickLower) || !Number.isInteger(input.tickUpper) || input.tickLower >= input.tickUpper) {\n invalid('tickLower must be an integer less than tickUpper');\n }\n if (input.createPool && input.pool.sqrtPriceX96 <= 0n) invalid('createPool requires a positive initial sqrtPriceX96');\n const positionManager = checkedAddress(input.positionManager);\n const recipient = checkedAddress(input.recipient);\n const slippageTolerance = slippagePercent(input.slippageToleranceBps);\n\n if (input.batchPermit) {\n if (!same(input.batchPermit.permitBatch.spender, positionManager)) {\n invalid('batchPermit.permitBatch.spender must be the position manager this transaction submits to');\n }\n if (!input.batchPermit.permitBatch.details.length) invalid('batchPermit.permitBatch.details must include at least one token');\n const poolTokens = [input.pool.currency0, input.pool.currency1]\n .filter(currency => !currency.isNative)\n .map(currency => checkedAddress(currency.wrapped.address as Address));\n const seen = new Set<string>();\n for (const detail of input.batchPermit.permitBatch.details) {\n const token = checkedAddress(detail.token);\n if (!poolTokens.some(poolToken => same(poolToken, token))) {\n invalid('batchPermit.permitBatch.details references a token that is not part of this mint\\'s pool');\n }\n if (seen.has(token.toLowerCase())) invalid('batchPermit.permitBatch.details lists the same token more than once');\n seen.add(token.toLowerCase());\n }\n }\n\n try {\n const pool = new Pool(\n input.pool.currency0,\n input.pool.currency1,\n input.pool.fee,\n input.pool.tickSpacing,\n checkedAddress(input.pool.hooks),\n input.pool.sqrtPriceX96.toString(),\n input.pool.liquidity.toString(),\n input.pool.tickCurrent,\n );\n const position = new Position({\n pool,\n liquidity: input.liquidity.toString(),\n tickLower: input.tickLower,\n tickUpper: input.tickUpper,\n });\n const params = V4PositionManager.addCallParameters(position, {\n recipient,\n createPool: input.createPool ?? false,\n ...(input.createPool ? { sqrtPriceX96: input.pool.sqrtPriceX96.toString() } : {}),\n useNative: pool.currency0.isNative ? pool.currency0 : undefined,\n slippageTolerance,\n hookData: input.hookData,\n deadline: input.deadlineSeconds.toString(),\n ...(input.batchPermit ? {\n batchPermit: {\n owner: checkedAddress(input.batchPermit.owner),\n permitBatch: {\n details: input.batchPermit.permitBatch.details.map(detail => ({\n token: checkedAddress(detail.token),\n amount: detail.amount.toString(),\n expiration: detail.expiration.toString(),\n nonce: detail.nonce.toString(),\n })),\n spender: checkedAddress(input.batchPermit.permitBatch.spender),\n sigDeadline: input.batchPermit.permitBatch.sigDeadline.toString(),\n },\n signature: input.batchPermit.signature,\n },\n } : {}),\n });\n return { to: positionManager, data: params.calldata as Hex, value: BigInt(params.value) };\n } catch (cause) {\n if (cause instanceof UniswapSdkError) throw cause;\n throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the mint parameters', { cause });\n }\n}\n\nconst MINT_POSITION_ACTION = 2;\nconst SETTLE_PAIR_ACTION = 13;\nconst SWEEP_ACTION = 20;\n/** PositionManager's `msgSender()` sentinel; the only address `SWEEP` may refund to. */\nconst MSG_SENDER: Address = '0x0000000000000000000000000000000000000001';\n\nconst unlockDataParams = parseAbiParameters('bytes actions, bytes[] params');\nconst poolKeyStruct = '(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks)';\nconst mintPositionParams = parseAbiParameters(\n `${poolKeyStruct} poolKey, int24 tickLower, int24 tickUpper, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, address owner, bytes hookData`,\n);\nconst settlePairParams = parseAbiParameters('address currency0, address currency1');\nconst sweepParams = parseAbiParameters('address currency, address to');\n\nexport type V4PoolKeyMaterial = { currency0: Address; currency1: Address; fee: number; tickSpacing: number; hooks: Address };\nexport type V4MintActionParams = {\n poolKey: V4PoolKeyMaterial;\n tickLower: number;\n tickUpper: number;\n liquidity: bigint;\n amount0Max: bigint;\n amount1Max: bigint;\n owner: Address;\n hookData: Hex;\n deadline: bigint;\n /** Present only if this mint atomically initializes the pool; the price it initializes at. */\n createdAtSqrtPriceX96?: bigint;\n /** Present only if this mint folds in a Permit2 batch approval; the address that signed it. */\n batchPermitOwner?: Address;\n};\n\nfunction mismatch(message: string): never {\n throw new UniswapSdkError('CALLDATA_MISMATCH', message);\n}\n\n/** `bytes actions` packs one uint8 opcode per action, two hex characters each. */\nfunction decodeActionIds(actions: Hex): number[] {\n const hex = actions.slice(2);\n if (hex.length % 2 !== 0) mismatch('Mint calldata has a malformed action byte string');\n const ids: number[] = [];\n for (let i = 0; i < hex.length; i += 2) ids.push(parseInt(hex.slice(i, i + 2), 16));\n return ids;\n}\n\nfunction samePoolKey(a: V4PoolKeyMaterial, b: V4PoolKeyMaterial): boolean {\n return same(a.currency0, b.currency0) && same(a.currency1, b.currency1)\n && a.fee === b.fee && a.tickSpacing === b.tickSpacing && same(a.hooks, b.hooks);\n}\n\n/**\n * A 1:1 pairing, not \"every actual detail matches some expected detail\" — that weaker check\n * would let `[A, A]` pass against `expected = [A, B]` (both actual entries match A; lengths\n * happen to agree), silently ignoring that B was never actually authorized and A appears twice.\n */\nfunction sameBatchPermitDetails(actual: readonly V4BatchPermitDetail[], expected: readonly V4BatchPermitDetail[]): boolean {\n if (actual.length !== expected.length) return false;\n const remaining = expected.slice();\n for (const detail of actual) {\n const index = remaining.findIndex(candidate => same(candidate.token, detail.token)\n && candidate.amount === detail.amount && candidate.expiration === detail.expiration && candidate.nonce === detail.nonce);\n if (index === -1) return false;\n remaining.splice(index, 1);\n }\n return true;\n}\n\nexport type V4ExpectedMint = V4PoolKeyMaterial & {\n recipient: Address;\n /**\n * Required if this mint might atomically create the pool; the only price that\n * mint may set. Checked only in that direction: supplying it does not require\n * the calldata to actually create the pool — a plain mint into an\n * already-initialized pool is unaffected either way, distinguishable from a\n * pool-creating mint by `createdAtSqrtPriceX96` being absent from the result.\n */\n sqrtPriceX96?: bigint;\n /**\n * Required if this mint folds in a Permit2 batch approval; the only owner/spender/\n * sigDeadline/token-detail set that approval may authorize. Checked only in that\n * direction, the same as `sqrtPriceX96` — omitting it fails closed if the calldata\n * does include a permit, rather than trusting whatever it authorizes.\n */\n batchPermit?: { owner: Address; spender: Address; sigDeadline: bigint; details: readonly V4BatchPermitDetail[] };\n};\n\n/**\n * Decodes and verifies calldata built by `buildV4MintPositionTransaction`: a\n * `modifyLiquidities` call — optionally wrapped in a `multicall` alongside pool\n * initialization and/or a Permit2 batch approval — encoding exactly a MINT_POSITION\n * action, a SETTLE_PAIR, and, for a native-currency0 mint, a trailing SWEEP. This is\n * the only action shape that function produces; any other sequence is calldata this\n * decoder does not recognise as its own and refuses, rather than guessing at its\n * meaning.\n *\n * `expected` must name the full pool (including `hooks`), not just the token\n * pair — a mint into the same pair through a different, unreviewed hook is a\n * different pool with different economics, not a cosmetic difference.\n * `currency0`/`currency1` must already be in canonical (sorted) order, and a\n * native-currency pool's `currency0` must be the zero address, matching how\n * `V4PoolKey`/`Pool` represent it elsewhere in this SDK — this function does\n * not reorder or reinterpret them. Pass `sqrtPriceX96` when the mint might\n * atomically create the pool; omitting it fails closed rather than silently\n * accepting whatever starting price the calldata sets. Pass `batchPermit` when\n * the mint might fold in a Permit2 approval, for the same reason — a decoded\n * permit's token/owner/spender are also self-checked against the pool regardless\n * of what `expected` claims.\n */\nexport function reviewV4MintPositionCalldata(data: Hex, expected: V4ExpectedMint): V4MintActionParams {\n try {\n const decoded = decodeFunctionData({ abi: v4PositionManagerAbi, data });\n let unlockData: Hex;\n let deadline: bigint;\n let initialization: { key: V4PoolKeyMaterial; sqrtPriceX96: bigint } | undefined;\n let batchPermit: { owner: Address; spender: Address; sigDeadline: bigint; details: readonly V4BatchPermitDetail[] } | undefined;\n if (decoded.functionName === 'multicall') {\n const calls = decoded.args[0].map(call => decodeFunctionData({ abi: v4PositionManagerAbi, data: call }));\n if (calls.length < 2 || calls.length > 3) mismatch('Mint calldata multicall does not have the call count a plain mint produces');\n const mintCall = calls.at(-1)!;\n if (mintCall.functionName !== 'modifyLiquidities') mismatch('Mint calldata multicall must end with the position mint');\n for (const call of calls.slice(0, -1)) {\n if (call.functionName === 'initializePool') {\n if (initialization) mismatch('Mint calldata multicall contains more than one pool initialization');\n initialization = { key: call.args[0] as V4PoolKeyMaterial, sqrtPriceX96: call.args[1] as bigint };\n } else if (call.functionName === 'permitBatch') {\n if (batchPermit) mismatch('Mint calldata multicall contains more than one permit batch');\n const [owner, permitBatch] = call.args as readonly [Address, { details: readonly { token: Address; amount: bigint; expiration: number; nonce: number }[]; spender: Address; sigDeadline: bigint }, Hex];\n batchPermit = {\n owner,\n spender: permitBatch.spender,\n sigDeadline: permitBatch.sigDeadline,\n details: permitBatch.details.map(detail => ({ token: detail.token, amount: detail.amount, expiration: BigInt(detail.expiration), nonce: BigInt(detail.nonce) })),\n };\n } else {\n mismatch('Mint calldata multicall contains an unreviewed call before the position mint');\n }\n }\n [unlockData, deadline] = mintCall.args as [Hex, bigint];\n } else if (decoded.functionName === 'modifyLiquidities') {\n [unlockData, deadline] = decoded.args;\n } else {\n return mismatch('Mint calldata is not a position-manager modifyLiquidities call');\n }\n\n const [actionsBytes, actionParams] = decodeAbiParameters(unlockDataParams, unlockData) as [Hex, readonly Hex[]];\n const actionIds = decodeActionIds(actionsBytes);\n if (actionIds.length !== actionParams.length) mismatch('Mint calldata has a different number of actions and action parameters');\n if (actionIds.length < 2 || actionIds.length > 3) mismatch('Mint calldata does not have the action count a plain mint produces');\n\n if (actionIds[0] !== MINT_POSITION_ACTION) mismatch('Mint calldata must begin with a MINT_POSITION action');\n const [poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData] = decodeAbiParameters(\n mintPositionParams,\n actionParams[0]!,\n ) as [V4PoolKeyMaterial, number, number, bigint, bigint, bigint, Address, Hex];\n if (liquidity <= 0n) mismatch('Mint calldata mints non-positive liquidity');\n\n if (initialization && !samePoolKey(initialization.key, poolKey)) {\n mismatch('Mint pool initialization targets a different pool than the position mint');\n }\n\n if (actionIds[1] !== SETTLE_PAIR_ACTION) mismatch('MINT_POSITION must be followed by a SETTLE_PAIR');\n const [settleCurrency0, settleCurrency1] = decodeAbiParameters(settlePairParams, actionParams[1]!) as [Address, Address];\n if (!same(settleCurrency0, poolKey.currency0) || !same(settleCurrency1, poolKey.currency1)) {\n mismatch('SETTLE_PAIR settles a different pair than the minted position');\n }\n\n if (actionIds.length === 3) {\n if (actionIds[2] !== SWEEP_ACTION) mismatch('Mint calldata has an unreviewed action after SETTLE_PAIR');\n const [sweepCurrency, sweepTo] = decodeAbiParameters(sweepParams, actionParams[2]!) as [Address, Address];\n if (!same(sweepCurrency, zeroAddress) && !same(sweepCurrency, poolKey.currency0)) {\n mismatch('SWEEP refunds an unexpected currency');\n }\n if (!same(sweepTo, MSG_SENDER)) mismatch('SWEEP sends the refund to an unexpected recipient');\n }\n\n if (!samePoolKey(poolKey, expected)) mismatch('Mint calldata targets a different pool than expected');\n if (!same(owner, expected.recipient)) mismatch('Mint calldata sends the position NFT to a different recipient');\n\n if (initialization) {\n if (expected.sqrtPriceX96 === undefined) {\n mismatch('Mint calldata initializes the pool but no expected starting price was supplied to verify it');\n }\n if (initialization.sqrtPriceX96 !== expected.sqrtPriceX96) {\n mismatch('Mint calldata initializes the pool at a different starting price than expected');\n }\n }\n\n if (batchPermit) {\n // Self-checked against the decoded poolKey regardless of what `expected` claims, so a\n // caller who fails to scrutinize `expected` still can't be tricked into treating a permit\n // for an unrelated or duplicated token as reviewed.\n const poolTokens = [poolKey.currency0, poolKey.currency1];\n const seenTokens = new Set<string>();\n for (const detail of batchPermit.details) {\n if (same(detail.token, zeroAddress)) mismatch('Permit2 batch approval cannot cover the native currency');\n if (!poolTokens.some(poolToken => same(poolToken, detail.token))) {\n mismatch('Permit2 batch approval references a token that is not part of the minted pool');\n }\n const key = detail.token.toLowerCase();\n if (seenTokens.has(key)) mismatch('Permit2 batch approval lists the same token more than once');\n seenTokens.add(key);\n }\n\n if (!expected.batchPermit) {\n mismatch('Mint calldata includes a Permit2 batch approval but no expected approval was supplied to verify it');\n }\n if (!same(batchPermit.owner, expected.batchPermit.owner)\n || !same(batchPermit.spender, expected.batchPermit.spender)\n || batchPermit.sigDeadline !== expected.batchPermit.sigDeadline\n || !sameBatchPermitDetails(batchPermit.details, expected.batchPermit.details)) {\n mismatch('Mint calldata\\'s Permit2 batch approval does not match what was expected');\n }\n }\n\n return {\n poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData, deadline,\n ...(initialization ? { createdAtSqrtPriceX96: initialization.sqrtPriceX96 } : {}),\n ...(batchPermit ? { batchPermitOwner: batchPermit.owner } : {}),\n };\n } catch (error) {\n if (error instanceof UniswapSdkError) throw error;\n throw new UniswapSdkError('CALLDATA_MISMATCH', 'Mint calldata contains undecodable position-manager calls', { cause: error });\n }\n}\n"]}
1
+ {"version":3,"file":"v4-transactions.js","sourceRoot":"","sources":["../src/v4-transactions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,WAAW,EAA0B,MAAM,MAAM,CAAC;AACxH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,2BAA2B,EAA0B,MAAM,YAAY,CAAC;AA0CjF,SAAS,eAAe,CAAC,GAAW;IAClC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,GAAG,MAAM,EAAE,CAAC;QACtD,OAAO,CAAC,6DAA6D,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,CAAS;IAChC,OAAO,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7C,CAAC;AASD;;;;;;;;;;;;;;;;GAgBG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C1B,QAAQ,CAAC,oGAAoG,CAAC,CAAC;YACjH,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;mBACnD,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC;mBACxD,WAAW,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,CAAC,WAAW;mBAC5D,CAAC,sBAAsB,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;gBAChF,QAAQ,CAAC,0EAA0E,CAAC,CAAC;YACvF,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ;YAC3F,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACjF,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,eAAe;YAAE,MAAM,KAAK,CAAC;QAClD,MAAM,IAAI,eAAe,CAAC,mBAAmB,EAAE,2DAA2D,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAChI,CAAC;AACH,CAAC","sourcesContent":["import type { Currency } from '@uniswap/sdk-core';\nimport { decodeAbiParameters, decodeFunctionData, parseAbiParameters, zeroAddress, type Address, type Hex } from 'viem';\nimport { Percent, Pool, Position, V4PositionManager } from './official-sdk.cjs';\nimport { checkedAddress } from './pool.js';\nimport { invalid, UniswapSdkError } from './errors.js';\nimport { v4PositionManagerAbi } from './abis.js';\nimport { unmodelledV4HookPermissions, type V4HookPermissions } from './hooks.js';\n\nexport type V4TransactionMaterial = { to: Address; data: Hex; value: bigint };\n\n/** Pool state as read from PoolManager/StateView (e.g. via `readV4Pool`), not yet a mint target. */\nexport type V4PoolState = {\n currency0: Currency;\n currency1: Currency;\n fee: number;\n tickSpacing: number;\n hooks: Address;\n sqrtPriceX96: bigint;\n liquidity: bigint;\n tickCurrent: number;\n};\n\nexport type V4MintPositionParams = {\n positionManager: Address;\n pool: V4PoolState;\n tickLower: number;\n tickUpper: number;\n /** Liquidity units to mint, not a token amount. */\n liquidity: bigint;\n recipient: Address;\n /** Integer basis points, 0-10000. */\n slippageToleranceBps: number;\n deadlineSeconds: bigint;\n /** Passed to the hook's callbacks verbatim; this SDK does not construct it. */\n hookData?: Hex;\n /** Atomically initializes the pool before minting. Requires `pool.sqrtPriceX96` to be the intended starting price. */\n createPool?: boolean;\n /** A Permit2 batch approval signed by the caller's own wallet; see `buildV4MintPermitBatchTypedData`. */\n batchPermit?: V4BatchPermit;\n /**\n * Permission flags the caller has reviewed for `pool.hooks` (see `decodeV4HookPermissions`).\n * Required whenever `pool.hooks` is not the zero address: a hook implementing a callback the\n * caller has not modelled can move price, take a cut, or otherwise change what this mint\n * actually does, so minting into one is refused rather than assumed benign.\n */\n modelledHookPermissions?: readonly (keyof V4HookPermissions)[];\n};\n\nfunction slippagePercent(bps: number): Percent {\n if (!Number.isInteger(bps) || bps < 0 || bps > 10_000) {\n invalid('slippageToleranceBps must be an integer between 0 and 10000');\n }\n return new Percent(bps, 10_000);\n}\n\nfunction same(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n\nexport type V4BatchPermitDetail = { token: Address; amount: bigint; expiration: bigint; nonce: bigint };\nexport type V4BatchPermit = {\n owner: Address;\n permitBatch: { details: readonly V4BatchPermitDetail[]; spender: Address; sigDeadline: bigint };\n signature: Hex;\n};\n\n/**\n * Builds unsigned calldata for `PositionManager.modifyLiquidities` minting a new v4 position.\n * Delegates encoding to `@uniswap/v4-sdk`'s `V4PositionManager`/`V4PositionPlanner` (the same\n * Actions/multicall encoding Uniswap's own SDK uses) rather than hand-rolling it, since v4's\n * calldata is a sequence of packed actions, not a single ABI-encoded function call like v3's.\n *\n * Pass `batchPermit` (built via `buildV4MintPermitBatchTypedData` and signed by the caller's own\n * wallet) to fold a Permit2 approval into this same transaction instead of requiring a prior,\n * separate ERC20 `approve`. Without it, callers must already hold a plain ERC20 approval or the\n * built transaction will revert on-chain.\n *\n * If `pool.hooks` is not the zero address, `modelledHookPermissions` is required and this\n * function refuses to mint if the hook implements any permission flag outside it (see\n * `decodeV4HookPermissions`/`unmodelledV4HookPermissions`) — a hook can move price, take a cut,\n * or otherwise change what this mint actually does, so an unreviewed one is refused rather than\n * assumed benign.\n */\nexport function buildV4MintPositionTransaction(input: V4MintPositionParams): V4TransactionMaterial {\n if (input.liquidity <= 0n) invalid('Mint liquidity must be positive');\n if (!Number.isInteger(input.tickLower) || !Number.isInteger(input.tickUpper) || input.tickLower >= input.tickUpper) {\n invalid('tickLower must be an integer less than tickUpper');\n }\n if (input.createPool && input.pool.sqrtPriceX96 <= 0n) invalid('createPool requires a positive initial sqrtPriceX96');\n const positionManager = checkedAddress(input.positionManager);\n const recipient = checkedAddress(input.recipient);\n const slippageTolerance = slippagePercent(input.slippageToleranceBps);\n const hooks = checkedAddress(input.pool.hooks);\n\n if (!same(hooks, zeroAddress)) {\n if (!input.modelledHookPermissions) {\n invalid('pool.hooks is set but no modelledHookPermissions were supplied to verify it');\n }\n const unmodelled = unmodelledV4HookPermissions(hooks, input.modelledHookPermissions);\n if (unmodelled.length) invalid(`Pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);\n }\n\n if (input.batchPermit) {\n if (!same(input.batchPermit.permitBatch.spender, positionManager)) {\n invalid('batchPermit.permitBatch.spender must be the position manager this transaction submits to');\n }\n if (!input.batchPermit.permitBatch.details.length) invalid('batchPermit.permitBatch.details must include at least one token');\n const poolTokens = [input.pool.currency0, input.pool.currency1]\n .filter(currency => !currency.isNative)\n .map(currency => checkedAddress(currency.wrapped.address as Address));\n const seen = new Set<string>();\n for (const detail of input.batchPermit.permitBatch.details) {\n const token = checkedAddress(detail.token);\n if (!poolTokens.some(poolToken => same(poolToken, token))) {\n invalid('batchPermit.permitBatch.details references a token that is not part of this mint\\'s pool');\n }\n if (seen.has(token.toLowerCase())) invalid('batchPermit.permitBatch.details lists the same token more than once');\n seen.add(token.toLowerCase());\n }\n }\n\n try {\n const pool = new Pool(\n input.pool.currency0,\n input.pool.currency1,\n input.pool.fee,\n input.pool.tickSpacing,\n hooks,\n input.pool.sqrtPriceX96.toString(),\n input.pool.liquidity.toString(),\n input.pool.tickCurrent,\n );\n const position = new Position({\n pool,\n liquidity: input.liquidity.toString(),\n tickLower: input.tickLower,\n tickUpper: input.tickUpper,\n });\n const params = V4PositionManager.addCallParameters(position, {\n recipient,\n createPool: input.createPool ?? false,\n ...(input.createPool ? { sqrtPriceX96: input.pool.sqrtPriceX96.toString() } : {}),\n useNative: pool.currency0.isNative ? pool.currency0 : undefined,\n slippageTolerance,\n hookData: input.hookData,\n deadline: input.deadlineSeconds.toString(),\n ...(input.batchPermit ? {\n batchPermit: {\n owner: checkedAddress(input.batchPermit.owner),\n permitBatch: {\n details: input.batchPermit.permitBatch.details.map(detail => ({\n token: checkedAddress(detail.token),\n amount: detail.amount.toString(),\n expiration: detail.expiration.toString(),\n nonce: detail.nonce.toString(),\n })),\n spender: checkedAddress(input.batchPermit.permitBatch.spender),\n sigDeadline: input.batchPermit.permitBatch.sigDeadline.toString(),\n },\n signature: input.batchPermit.signature,\n },\n } : {}),\n });\n return { to: positionManager, data: params.calldata as Hex, value: BigInt(params.value) };\n } catch (cause) {\n if (cause instanceof UniswapSdkError) throw cause;\n throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the mint parameters', { cause });\n }\n}\n\nconst MINT_POSITION_ACTION = 2;\nconst SETTLE_PAIR_ACTION = 13;\nconst SWEEP_ACTION = 20;\n/** PositionManager's `msgSender()` sentinel; the only address `SWEEP` may refund to. */\nconst MSG_SENDER: Address = '0x0000000000000000000000000000000000000001';\n\nconst unlockDataParams = parseAbiParameters('bytes actions, bytes[] params');\nconst poolKeyStruct = '(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks)';\nconst mintPositionParams = parseAbiParameters(\n `${poolKeyStruct} poolKey, int24 tickLower, int24 tickUpper, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, address owner, bytes hookData`,\n);\nconst settlePairParams = parseAbiParameters('address currency0, address currency1');\nconst sweepParams = parseAbiParameters('address currency, address to');\n\nexport type V4PoolKeyMaterial = { currency0: Address; currency1: Address; fee: number; tickSpacing: number; hooks: Address };\nexport type V4MintActionParams = {\n poolKey: V4PoolKeyMaterial;\n tickLower: number;\n tickUpper: number;\n liquidity: bigint;\n amount0Max: bigint;\n amount1Max: bigint;\n owner: Address;\n hookData: Hex;\n deadline: bigint;\n /** Present only if this mint atomically initializes the pool; the price it initializes at. */\n createdAtSqrtPriceX96?: bigint;\n /** Present only if this mint folds in a Permit2 batch approval; the address that signed it. */\n batchPermitOwner?: Address;\n};\n\nfunction mismatch(message: string): never {\n throw new UniswapSdkError('CALLDATA_MISMATCH', message);\n}\n\n/** `bytes actions` packs one uint8 opcode per action, two hex characters each. */\nfunction decodeActionIds(actions: Hex): number[] {\n const hex = actions.slice(2);\n if (hex.length % 2 !== 0) mismatch('Mint calldata has a malformed action byte string');\n const ids: number[] = [];\n for (let i = 0; i < hex.length; i += 2) ids.push(parseInt(hex.slice(i, i + 2), 16));\n return ids;\n}\n\nfunction samePoolKey(a: V4PoolKeyMaterial, b: V4PoolKeyMaterial): boolean {\n return same(a.currency0, b.currency0) && same(a.currency1, b.currency1)\n && a.fee === b.fee && a.tickSpacing === b.tickSpacing && same(a.hooks, b.hooks);\n}\n\n/**\n * A 1:1 pairing, not \"every actual detail matches some expected detail\" — that weaker check\n * would let `[A, A]` pass against `expected = [A, B]` (both actual entries match A; lengths\n * happen to agree), silently ignoring that B was never actually authorized and A appears twice.\n */\nfunction sameBatchPermitDetails(actual: readonly V4BatchPermitDetail[], expected: readonly V4BatchPermitDetail[]): boolean {\n if (actual.length !== expected.length) return false;\n const remaining = expected.slice();\n for (const detail of actual) {\n const index = remaining.findIndex(candidate => same(candidate.token, detail.token)\n && candidate.amount === detail.amount && candidate.expiration === detail.expiration && candidate.nonce === detail.nonce);\n if (index === -1) return false;\n remaining.splice(index, 1);\n }\n return true;\n}\n\nexport type V4ExpectedMint = V4PoolKeyMaterial & {\n recipient: Address;\n /**\n * Required if this mint might atomically create the pool; the only price that\n * mint may set. Checked only in that direction: supplying it does not require\n * the calldata to actually create the pool — a plain mint into an\n * already-initialized pool is unaffected either way, distinguishable from a\n * pool-creating mint by `createdAtSqrtPriceX96` being absent from the result.\n */\n sqrtPriceX96?: bigint;\n /**\n * Required if this mint folds in a Permit2 batch approval; the only owner/spender/\n * sigDeadline/token-detail set that approval may authorize. Checked only in that\n * direction, the same as `sqrtPriceX96` — omitting it fails closed if the calldata\n * does include a permit, rather than trusting whatever it authorizes.\n */\n batchPermit?: { owner: Address; spender: Address; sigDeadline: bigint; details: readonly V4BatchPermitDetail[] };\n /**\n * Required if `hooks` is not the zero address; the permission flags the caller has reviewed\n * for it. Minting into a hook that implements any other permission flag is refused — the\n * same gate `buildV4MintPositionTransaction` applies when building this calldata in the\n * first place, re-checked here independently of what the builder was told.\n */\n modelledHookPermissions?: readonly (keyof V4HookPermissions)[];\n};\n\n/**\n * Decodes and verifies calldata built by `buildV4MintPositionTransaction`: a\n * `modifyLiquidities` call — optionally wrapped in a `multicall` alongside pool\n * initialization and/or a Permit2 batch approval — encoding exactly a MINT_POSITION\n * action, a SETTLE_PAIR, and, for a native-currency0 mint, a trailing SWEEP. This is\n * the only action shape that function produces; any other sequence is calldata this\n * decoder does not recognise as its own and refuses, rather than guessing at its\n * meaning.\n *\n * `expected` must name the full pool (including `hooks`), not just the token\n * pair — a mint into the same pair through a different, unreviewed hook is a\n * different pool with different economics, not a cosmetic difference.\n * `currency0`/`currency1` must already be in canonical (sorted) order, and a\n * native-currency pool's `currency0` must be the zero address, matching how\n * `V4PoolKey`/`Pool` represent it elsewhere in this SDK — this function does\n * not reorder or reinterpret them. Pass `sqrtPriceX96` when the mint might\n * atomically create the pool; omitting it fails closed rather than silently\n * accepting whatever starting price the calldata sets. Pass `batchPermit` when\n * the mint might fold in a Permit2 approval, for the same reason — a decoded\n * permit's token/owner/spender are also self-checked against the pool regardless\n * of what `expected` claims.\n */\nexport function reviewV4MintPositionCalldata(data: Hex, expected: V4ExpectedMint): V4MintActionParams {\n try {\n const decoded = decodeFunctionData({ abi: v4PositionManagerAbi, data });\n let unlockData: Hex;\n let deadline: bigint;\n let initialization: { key: V4PoolKeyMaterial; sqrtPriceX96: bigint } | undefined;\n let batchPermit: { owner: Address; spender: Address; sigDeadline: bigint; details: readonly V4BatchPermitDetail[] } | undefined;\n if (decoded.functionName === 'multicall') {\n const calls = decoded.args[0].map(call => decodeFunctionData({ abi: v4PositionManagerAbi, data: call }));\n if (calls.length < 2 || calls.length > 3) mismatch('Mint calldata multicall does not have the call count a plain mint produces');\n const mintCall = calls.at(-1)!;\n if (mintCall.functionName !== 'modifyLiquidities') mismatch('Mint calldata multicall must end with the position mint');\n for (const call of calls.slice(0, -1)) {\n if (call.functionName === 'initializePool') {\n if (initialization) mismatch('Mint calldata multicall contains more than one pool initialization');\n initialization = { key: call.args[0] as V4PoolKeyMaterial, sqrtPriceX96: call.args[1] as bigint };\n } else if (call.functionName === 'permitBatch') {\n if (batchPermit) mismatch('Mint calldata multicall contains more than one permit batch');\n const [owner, permitBatch] = call.args as readonly [Address, { details: readonly { token: Address; amount: bigint; expiration: number; nonce: number }[]; spender: Address; sigDeadline: bigint }, Hex];\n batchPermit = {\n owner,\n spender: permitBatch.spender,\n sigDeadline: permitBatch.sigDeadline,\n details: permitBatch.details.map(detail => ({ token: detail.token, amount: detail.amount, expiration: BigInt(detail.expiration), nonce: BigInt(detail.nonce) })),\n };\n } else {\n mismatch('Mint calldata multicall contains an unreviewed call before the position mint');\n }\n }\n [unlockData, deadline] = mintCall.args as [Hex, bigint];\n } else if (decoded.functionName === 'modifyLiquidities') {\n [unlockData, deadline] = decoded.args;\n } else {\n return mismatch('Mint calldata is not a position-manager modifyLiquidities call');\n }\n\n const [actionsBytes, actionParams] = decodeAbiParameters(unlockDataParams, unlockData) as [Hex, readonly Hex[]];\n const actionIds = decodeActionIds(actionsBytes);\n if (actionIds.length !== actionParams.length) mismatch('Mint calldata has a different number of actions and action parameters');\n if (actionIds.length < 2 || actionIds.length > 3) mismatch('Mint calldata does not have the action count a plain mint produces');\n\n if (actionIds[0] !== MINT_POSITION_ACTION) mismatch('Mint calldata must begin with a MINT_POSITION action');\n const [poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData] = decodeAbiParameters(\n mintPositionParams,\n actionParams[0]!,\n ) as [V4PoolKeyMaterial, number, number, bigint, bigint, bigint, Address, Hex];\n if (liquidity <= 0n) mismatch('Mint calldata mints non-positive liquidity');\n\n if (initialization && !samePoolKey(initialization.key, poolKey)) {\n mismatch('Mint pool initialization targets a different pool than the position mint');\n }\n\n if (actionIds[1] !== SETTLE_PAIR_ACTION) mismatch('MINT_POSITION must be followed by a SETTLE_PAIR');\n const [settleCurrency0, settleCurrency1] = decodeAbiParameters(settlePairParams, actionParams[1]!) as [Address, Address];\n if (!same(settleCurrency0, poolKey.currency0) || !same(settleCurrency1, poolKey.currency1)) {\n mismatch('SETTLE_PAIR settles a different pair than the minted position');\n }\n\n if (actionIds.length === 3) {\n if (actionIds[2] !== SWEEP_ACTION) mismatch('Mint calldata has an unreviewed action after SETTLE_PAIR');\n const [sweepCurrency, sweepTo] = decodeAbiParameters(sweepParams, actionParams[2]!) as [Address, Address];\n if (!same(sweepCurrency, zeroAddress) && !same(sweepCurrency, poolKey.currency0)) {\n mismatch('SWEEP refunds an unexpected currency');\n }\n if (!same(sweepTo, MSG_SENDER)) mismatch('SWEEP sends the refund to an unexpected recipient');\n }\n\n if (!samePoolKey(poolKey, expected)) mismatch('Mint calldata targets a different pool than expected');\n if (!same(owner, expected.recipient)) mismatch('Mint calldata sends the position NFT to a different recipient');\n\n if (!same(poolKey.hooks, zeroAddress)) {\n if (!expected.modelledHookPermissions) {\n mismatch('Mint calldata targets a pool with a hook but no modelled permissions were supplied to verify it');\n }\n const unmodelled = unmodelledV4HookPermissions(poolKey.hooks, expected.modelledHookPermissions);\n if (unmodelled.length) mismatch(`Mint calldata's pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);\n }\n\n if (initialization) {\n if (expected.sqrtPriceX96 === undefined) {\n mismatch('Mint calldata initializes the pool but no expected starting price was supplied to verify it');\n }\n if (initialization.sqrtPriceX96 !== expected.sqrtPriceX96) {\n mismatch('Mint calldata initializes the pool at a different starting price than expected');\n }\n }\n\n if (batchPermit) {\n // Self-checked against the decoded poolKey regardless of what `expected` claims, so a\n // caller who fails to scrutinize `expected` still can't be tricked into treating a permit\n // for an unrelated or duplicated token as reviewed.\n const poolTokens = [poolKey.currency0, poolKey.currency1];\n const seenTokens = new Set<string>();\n for (const detail of batchPermit.details) {\n if (same(detail.token, zeroAddress)) mismatch('Permit2 batch approval cannot cover the native currency');\n if (!poolTokens.some(poolToken => same(poolToken, detail.token))) {\n mismatch('Permit2 batch approval references a token that is not part of the minted pool');\n }\n const key = detail.token.toLowerCase();\n if (seenTokens.has(key)) mismatch('Permit2 batch approval lists the same token more than once');\n seenTokens.add(key);\n }\n\n if (!expected.batchPermit) {\n mismatch('Mint calldata includes a Permit2 batch approval but no expected approval was supplied to verify it');\n }\n if (!same(batchPermit.owner, expected.batchPermit.owner)\n || !same(batchPermit.spender, expected.batchPermit.spender)\n || batchPermit.sigDeadline !== expected.batchPermit.sigDeadline\n || !sameBatchPermitDetails(batchPermit.details, expected.batchPermit.details)) {\n mismatch('Mint calldata\\'s Permit2 batch approval does not match what was expected');\n }\n }\n\n return {\n poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, hookData, deadline,\n ...(initialization ? { createdAtSqrtPriceX96: initialization.sqrtPriceX96 } : {}),\n ...(batchPermit ? { batchPermitOwner: batchPermit.owner } : {}),\n };\n } catch (error) {\n if (error instanceof UniswapSdkError) throw error;\n throw new UniswapSdkError('CALLDATA_MISMATCH', 'Mint calldata contains undecodable position-manager calls', { cause: error });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reptilianhq/uniswap-sdk",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Deployment-explicit Uniswap observations and reviewed transaction material.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -125,6 +125,6 @@
125
125
  "reptilianRelease": {
126
126
  "schemaVersion": 1,
127
127
  "group": "uniswap-sdk",
128
- "sourceSha": "ddc02cb00ad5698c34105c8bd851eab3b97b6409"
128
+ "sourceSha": "029525e00354cc1bdda7f016f88983dddbe6b911"
129
129
  }
130
130
  }