@reptilianhq/uniswap-sdk 0.9.0 → 0.10.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 CHANGED
@@ -2,14 +2,15 @@
2
2
 
3
3
  Reptilian-maintained integration SDK, released independently through GitHub Packages.
4
4
  It owns Uniswap protocol mechanics: reviewed deployments, ABI encoding and decoding,
5
- unsigned v3 transaction material, calldata review, receipt evidence, and v4 observations.
5
+ unsigned v3/v4 transaction material, calldata review, receipt evidence, and v4 observations.
6
6
  It never owns keys, authorization policy, transaction submission, persistence, or orchestration.
7
7
 
8
8
  ## Capabilities and ownership
9
9
 
10
10
  - `./v4`: full pool identity, Initialize-log normalization, pool state,
11
11
  exact-input Quoter simulation, ordered quote batches, initialized tick windows,
12
- reviewed Arc infrastructure, and unsigned position-mint material with strict review.
12
+ reviewed Arc infrastructure, and unsigned position mint, increase, partial-removal,
13
+ and atomic full-close material with strict review.
13
14
  - `./v3`: Robinhood v3 deployment identity, compatibility checks, unsigned
14
15
  position transaction builders, strict calldata review, and receipt evidence.
15
16
  - `./deployments`, `./compatibility`, `./transactions`, `./receipts`: stable
@@ -83,6 +84,14 @@ finality, capability policy and secret storage. For multicall consumers, use
83
84
  Those helpers preserve the existing host's transport, block and sender context;
84
85
  the host must check chain/deployment identity and Quoter multicall compatibility.
85
86
 
87
+ V4 position management is deliberately position-scoped. The host must first bind
88
+ the owner, token ID, PoolKey, ticks, and current liquidity at one observation block,
89
+ then independently authorize and simulate the returned unsigned transaction. Increase
90
+ material may carry an exact Permit2 batch. Removal material returns both currencies to
91
+ PositionManager's `msgSender()`; a full exit can burn the NFT atomically. These builders
92
+ do not merge positions or imply that a managed strategy position is the launch position,
93
+ even when both positions happen to share the same underlying pool.
94
+
86
95
  ## Observation and quote guarantees
87
96
 
88
97
  The direct-client RPC operations check chain identity (the `./batch` host owns that check). Pool/tick reads check StateView's
package/RELEASING.md CHANGED
@@ -58,8 +58,8 @@ Run `npm ci --ignore-scripts` and `npm run check`. Checks include TypeScript,
58
58
  lint, unit tests, built Node ESM runtime smoke, a runnable consumer example using
59
59
  the public package subpaths, publisher checksum and tests,
60
60
  packed export lint, and packed ESM/type resolution. The published scope includes
61
- v4 observations and provider plans plus v3 reviewed deployments, exact runtime
62
- code hashes, unsigned transaction construction, calldata review, compatibility
61
+ v4 observations and provider plans plus v3/v4 reviewed deployments, exact runtime
62
+ code hashes, unsigned position mint/increase/removal construction, calldata review, compatibility
63
63
  checks, pinned receipt evidence, and a self-hash-checked copy of the shared SDK
64
64
  conformance rules. Run `npm run test:fork` separately with an
65
65
  archive-capable `SDK_FORK_EIP155_4663_RPC_URL`; it simulates and executes the
@@ -42,6 +42,40 @@ export type V4MintPositionParams = {
42
42
  */
43
43
  modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
44
44
  };
45
+ export type V4RemovePositionParams = {
46
+ positionManager: Address;
47
+ pool: V4PoolState;
48
+ tokenId: bigint;
49
+ tickLower: number;
50
+ tickUpper: number;
51
+ /** Current on-chain position liquidity at the reviewed observation block. */
52
+ liquidity: bigint;
53
+ /** Exact liquidity units to remove. */
54
+ liquidityToRemove: bigint;
55
+ /** Burns the position NFT after removing all liquidity. */
56
+ burnToken?: boolean;
57
+ /** Integer basis points, 0-10000. */
58
+ slippageToleranceBps: number;
59
+ deadlineSeconds: bigint;
60
+ /** Passed to the hook's callbacks verbatim; this SDK does not construct it. */
61
+ hookData?: Hex;
62
+ /** Permission flags reviewed for a nonzero pool hook. */
63
+ modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
64
+ };
65
+ export type V4IncreasePositionParams = {
66
+ positionManager: Address;
67
+ pool: V4PoolState;
68
+ tokenId: bigint;
69
+ tickLower: number;
70
+ tickUpper: number;
71
+ /** Exact liquidity units to add to the existing position. */
72
+ liquidityToAdd: bigint;
73
+ slippageToleranceBps: number;
74
+ deadlineSeconds: bigint;
75
+ hookData?: Hex;
76
+ batchPermit?: V4BatchPermit;
77
+ modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
78
+ };
45
79
  export type V4BatchPermitDetail = {
46
80
  token: Address;
47
81
  amount: bigint;
@@ -75,6 +109,16 @@ export type V4BatchPermit = {
75
109
  * assumed benign.
76
110
  */
77
111
  export declare function buildV4MintPositionTransaction(input: V4MintPositionParams): V4TransactionMaterial;
112
+ /**
113
+ * Builds unsigned calldata that removes exact liquidity units from one V4 position and
114
+ * returns both currencies to PositionManager's `msgSender()`. Full exits may atomically
115
+ * burn the NFT. The caller must independently bind the token ID to the supplied PoolKey,
116
+ * ticks, liquidity and owner at the same observation block; V4 removal calldata contains
117
+ * a token ID rather than the complete PoolKey.
118
+ */
119
+ export declare function buildV4RemovePositionTransaction(input: V4RemovePositionParams): V4TransactionMaterial;
120
+ /** Builds unsigned calldata that increases one existing V4 position. */
121
+ export declare function buildV4IncreasePositionTransaction(input: V4IncreasePositionParams): V4TransactionMaterial;
78
122
  export type V4PoolKeyMaterial = {
79
123
  currency0: Address;
80
124
  currency1: Address;
@@ -127,6 +171,55 @@ export type V4ExpectedMint = V4PoolKeyMaterial & {
127
171
  */
128
172
  modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
129
173
  };
174
+ export type V4ExpectedRemoval = V4PoolKeyMaterial & {
175
+ tokenId: bigint;
176
+ /** Exact liquidity units reviewed for removal. Required for partial exits. */
177
+ liquidityToRemove: bigint;
178
+ burnToken: boolean;
179
+ modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
180
+ };
181
+ export type V4ExpectedIncrease = V4PoolKeyMaterial & {
182
+ tokenId: bigint;
183
+ batchPermit?: {
184
+ owner: Address;
185
+ spender: Address;
186
+ sigDeadline: bigint;
187
+ details: readonly V4BatchPermitDetail[];
188
+ };
189
+ modelledHookPermissions?: readonly (keyof V4HookPermissions)[];
190
+ };
191
+ export type V4IncreaseActionParams = {
192
+ tokenId: bigint;
193
+ liquidityAdded: bigint;
194
+ amount0Max: bigint;
195
+ amount1Max: bigint;
196
+ hookData: Hex;
197
+ currency0: Address;
198
+ currency1: Address;
199
+ deadline: bigint;
200
+ batchPermitOwner?: Address;
201
+ };
202
+ /** Reviews the exact increase/settlement shape emitted by the corresponding builder. */
203
+ export declare function reviewV4IncreasePositionCalldata(data: Hex, expected: V4ExpectedIncrease): V4IncreaseActionParams;
204
+ export type V4RemoveActionParams = {
205
+ tokenId: bigint;
206
+ liquidityRemoved: bigint;
207
+ amount0Min: bigint;
208
+ amount1Min: bigint;
209
+ hookData: Hex;
210
+ currency0: Address;
211
+ currency1: Address;
212
+ recipient: Address;
213
+ deadline: bigint;
214
+ burned: boolean;
215
+ };
216
+ /**
217
+ * Reviews the exact removal shape emitted by `buildV4RemovePositionTransaction`:
218
+ * one DECREASE_LIQUIDITY or BURN_POSITION action followed by TAKE_PAIR to
219
+ * PositionManager's `msgSender()` sentinel. Pool identity beyond the currency pair
220
+ * must be independently proven by a same-block token-ID position read.
221
+ */
222
+ export declare function reviewV4RemovePositionCalldata(data: Hex, expected: V4ExpectedRemoval): V4RemoveActionParams;
130
223
  /**
131
224
  * Decodes and verifies calldata built by `buildV4MintPositionTransaction`: a
132
225
  * `modifyLiquidities` call — optionally wrapped in a `multicall` alongside pool
@@ -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;AAKxH,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEjF,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,CAA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I,EAAE,GAAG,EAAE,QAAQ,EAAE,kBAAkB,GAAG,sBAAsB,CA6FhH;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,GAAG,oBAAoB,CAoF3G;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,kBAAkB,CA2HpG"}
@@ -111,16 +111,161 @@ export function buildV4MintPositionTransaction(input) {
111
111
  throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the mint parameters', { cause });
112
112
  }
113
113
  }
114
+ /**
115
+ * Builds unsigned calldata that removes exact liquidity units from one V4 position and
116
+ * returns both currencies to PositionManager's `msgSender()`. Full exits may atomically
117
+ * burn the NFT. The caller must independently bind the token ID to the supplied PoolKey,
118
+ * ticks, liquidity and owner at the same observation block; V4 removal calldata contains
119
+ * a token ID rather than the complete PoolKey.
120
+ */
121
+ export function buildV4RemovePositionTransaction(input) {
122
+ if (input.tokenId < 0n)
123
+ invalid('Position token ID must be non-negative');
124
+ if (input.liquidity <= 0n)
125
+ invalid('Current position liquidity must be positive');
126
+ if (input.liquidityToRemove <= 0n || input.liquidityToRemove > input.liquidity) {
127
+ invalid('Liquidity to remove must be positive and no greater than current position liquidity');
128
+ }
129
+ if (!Number.isInteger(input.tickLower) || !Number.isInteger(input.tickUpper) || input.tickLower >= input.tickUpper) {
130
+ invalid('tickLower must be an integer less than tickUpper');
131
+ }
132
+ if (input.burnToken && input.liquidityToRemove !== input.liquidity) {
133
+ invalid('burnToken requires removing all current position liquidity');
134
+ }
135
+ const positionManager = checkedAddress(input.positionManager);
136
+ const hooks = checkedAddress(input.pool.hooks);
137
+ if (!same(hooks, zeroAddress)) {
138
+ if (!input.modelledHookPermissions) {
139
+ invalid('pool.hooks is set but no modelledHookPermissions were supplied to verify it');
140
+ }
141
+ const unmodelled = unmodelledV4HookPermissions(hooks, input.modelledHookPermissions);
142
+ if (unmodelled.length)
143
+ invalid(`Pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);
144
+ }
145
+ try {
146
+ 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);
147
+ const position = new Position({
148
+ pool,
149
+ liquidity: input.liquidity.toString(),
150
+ tickLower: input.tickLower,
151
+ tickUpper: input.tickUpper,
152
+ });
153
+ const params = V4PositionManager.removeCallParameters(position, {
154
+ tokenId: input.tokenId.toString(),
155
+ liquidityPercentage: new Percent(input.liquidityToRemove.toString(), input.liquidity.toString()),
156
+ burnToken: input.burnToken ?? false,
157
+ slippageTolerance: slippagePercent(input.slippageToleranceBps),
158
+ hookData: input.hookData,
159
+ deadline: input.deadlineSeconds.toString(),
160
+ });
161
+ return { to: positionManager, data: params.calldata, value: BigInt(params.value) };
162
+ }
163
+ catch (cause) {
164
+ if (cause instanceof UniswapSdkError)
165
+ throw cause;
166
+ throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the removal parameters', { cause });
167
+ }
168
+ }
169
+ /** Builds unsigned calldata that increases one existing V4 position. */
170
+ export function buildV4IncreasePositionTransaction(input) {
171
+ if (input.tokenId < 0n)
172
+ invalid('Position token ID must be non-negative');
173
+ if (input.liquidityToAdd <= 0n)
174
+ invalid('Liquidity to add must be positive');
175
+ if (!Number.isInteger(input.tickLower) || !Number.isInteger(input.tickUpper) || input.tickLower >= input.tickUpper) {
176
+ invalid('tickLower must be an integer less than tickUpper');
177
+ }
178
+ const positionManager = checkedAddress(input.positionManager);
179
+ const hooks = checkedAddress(input.pool.hooks);
180
+ if (!same(hooks, zeroAddress)) {
181
+ if (!input.modelledHookPermissions)
182
+ invalid('pool.hooks is set but no modelledHookPermissions were supplied to verify it');
183
+ const unmodelled = unmodelledV4HookPermissions(hooks, input.modelledHookPermissions);
184
+ if (unmodelled.length)
185
+ invalid(`Pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);
186
+ }
187
+ if (input.batchPermit)
188
+ validateBatchPermit(input.batchPermit, positionManager, input.pool);
189
+ try {
190
+ 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);
191
+ const position = new Position({
192
+ pool,
193
+ liquidity: input.liquidityToAdd.toString(),
194
+ tickLower: input.tickLower,
195
+ tickUpper: input.tickUpper,
196
+ });
197
+ const params = V4PositionManager.addCallParameters(position, {
198
+ tokenId: input.tokenId.toString(),
199
+ useNative: pool.currency0.isNative ? pool.currency0 : undefined,
200
+ slippageTolerance: slippagePercent(input.slippageToleranceBps),
201
+ hookData: input.hookData,
202
+ deadline: input.deadlineSeconds.toString(),
203
+ ...(input.batchPermit ? { batchPermit: serializableBatchPermit(input.batchPermit) } : {}),
204
+ });
205
+ return { to: positionManager, data: params.calldata, value: BigInt(params.value) };
206
+ }
207
+ catch (cause) {
208
+ if (cause instanceof UniswapSdkError)
209
+ throw cause;
210
+ throw new UniswapSdkError('INVALID_ARGUMENT', 'Official Uniswap SDK rejected the increase parameters', { cause });
211
+ }
212
+ }
213
+ function validateBatchPermit(batchPermit, positionManager, pool) {
214
+ if (!same(batchPermit.permitBatch.spender, positionManager)) {
215
+ invalid('batchPermit.permitBatch.spender must be the position manager this transaction submits to');
216
+ }
217
+ if (!batchPermit.permitBatch.details.length)
218
+ invalid('batchPermit.permitBatch.details must include at least one token');
219
+ const poolTokens = [pool.currency0, pool.currency1]
220
+ .filter(currency => !currency.isNative)
221
+ .map(currency => checkedAddress(currency.wrapped.address));
222
+ const seen = new Set();
223
+ for (const detail of batchPermit.permitBatch.details) {
224
+ const token = checkedAddress(detail.token);
225
+ if (!poolTokens.some(poolToken => same(poolToken, token))) {
226
+ invalid('batchPermit.permitBatch.details references a token that is not part of this position pool');
227
+ }
228
+ if (seen.has(token.toLowerCase()))
229
+ invalid('batchPermit.permitBatch.details lists the same token more than once');
230
+ seen.add(token.toLowerCase());
231
+ }
232
+ }
233
+ function serializableBatchPermit(batchPermit) {
234
+ return {
235
+ owner: checkedAddress(batchPermit.owner),
236
+ permitBatch: {
237
+ details: batchPermit.permitBatch.details.map(detail => ({
238
+ token: checkedAddress(detail.token),
239
+ amount: detail.amount.toString(),
240
+ expiration: detail.expiration.toString(),
241
+ nonce: detail.nonce.toString(),
242
+ })),
243
+ spender: checkedAddress(batchPermit.permitBatch.spender),
244
+ sigDeadline: batchPermit.permitBatch.sigDeadline.toString(),
245
+ },
246
+ signature: batchPermit.signature,
247
+ };
248
+ }
114
249
  const MINT_POSITION_ACTION = 2;
250
+ const INCREASE_LIQUIDITY_ACTION = 0;
251
+ const DECREASE_LIQUIDITY_ACTION = 1;
252
+ const BURN_POSITION_ACTION = 3;
115
253
  const SETTLE_PAIR_ACTION = 13;
254
+ const TAKE_PAIR_ACTION = 17;
255
+ const CLOSE_CURRENCY_ACTION = 18;
116
256
  const SWEEP_ACTION = 20;
117
257
  /** PositionManager's `msgSender()` sentinel; the only address `SWEEP` may refund to. */
118
258
  const MSG_SENDER = '0x0000000000000000000000000000000000000001';
119
259
  const unlockDataParams = parseAbiParameters('bytes actions, bytes[] params');
120
260
  const poolKeyStruct = '(address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks)';
121
261
  const mintPositionParams = parseAbiParameters(`${poolKeyStruct} poolKey, int24 tickLower, int24 tickUpper, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, address owner, bytes hookData`);
262
+ const increaseLiquidityParams = parseAbiParameters('uint256 tokenId, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, bytes hookData');
122
263
  const settlePairParams = parseAbiParameters('address currency0, address currency1');
123
264
  const sweepParams = parseAbiParameters('address currency, address to');
265
+ const decreaseLiquidityParams = parseAbiParameters('uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes hookData');
266
+ const burnPositionParams = parseAbiParameters('uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes hookData');
267
+ const takePairParams = parseAbiParameters('address currency0, address currency1, address recipient');
268
+ const closeCurrencyParams = parseAbiParameters('address currency');
124
269
  function mismatch(message) {
125
270
  throw new UniswapSdkError('CALLDATA_MISMATCH', message);
126
271
  }
@@ -156,6 +301,204 @@ function sameBatchPermitDetails(actual, expected) {
156
301
  }
157
302
  return true;
158
303
  }
304
+ /** Reviews the exact increase/settlement shape emitted by the corresponding builder. */
305
+ export function reviewV4IncreasePositionCalldata(data, expected) {
306
+ try {
307
+ const decoded = decodeFunctionData({ abi: v4PositionManagerAbi, data });
308
+ let unlockData;
309
+ let deadline;
310
+ let batchPermit;
311
+ if (decoded.functionName === 'multicall') {
312
+ const calls = decoded.args[0].map(call => decodeFunctionData({ abi: v4PositionManagerAbi, data: call }));
313
+ if (calls.length < 1 || calls.length > 2)
314
+ mismatch('Increase calldata multicall has an unexpected call count');
315
+ const increaseCall = calls.at(-1);
316
+ if (increaseCall.functionName !== 'modifyLiquidities')
317
+ mismatch('Increase calldata multicall must end with modifyLiquidities');
318
+ if (calls.length === 2) {
319
+ const permitCall = calls[0];
320
+ if (permitCall.functionName !== 'permitBatch')
321
+ mismatch('Increase calldata contains an unreviewed call before modifyLiquidities');
322
+ const [owner, permit] = permitCall.args;
323
+ batchPermit = {
324
+ owner,
325
+ spender: permit.spender,
326
+ sigDeadline: permit.sigDeadline,
327
+ details: permit.details.map(detail => ({ token: detail.token, amount: detail.amount, expiration: BigInt(detail.expiration), nonce: BigInt(detail.nonce) })),
328
+ };
329
+ }
330
+ [unlockData, deadline] = increaseCall.args;
331
+ }
332
+ else if (decoded.functionName === 'modifyLiquidities') {
333
+ [unlockData, deadline] = decoded.args;
334
+ }
335
+ else {
336
+ return mismatch('Increase calldata is not a position-manager modifyLiquidities call');
337
+ }
338
+ const [actionsBytes, actionParams] = decodeAbiParameters(unlockDataParams, unlockData);
339
+ const actionIds = decodeActionIds(actionsBytes);
340
+ if (actionIds.length < 3 || actionIds.length > 4 || actionIds.length !== actionParams.length) {
341
+ mismatch('Increase calldata has an unexpected action count');
342
+ }
343
+ if (actionIds[0] !== INCREASE_LIQUIDITY_ACTION)
344
+ mismatch('Increase calldata must begin with INCREASE_LIQUIDITY');
345
+ const [tokenId, liquidityAdded, amount0Max, amount1Max, hookData] = decodeAbiParameters(increaseLiquidityParams, actionParams[0]);
346
+ if (tokenId !== expected.tokenId)
347
+ mismatch('Increase calldata targets a different position token ID');
348
+ if (liquidityAdded <= 0n)
349
+ mismatch('Increase calldata adds non-positive liquidity');
350
+ if (actionIds[1] !== CLOSE_CURRENCY_ACTION || actionIds[2] !== CLOSE_CURRENCY_ACTION) {
351
+ mismatch('INCREASE_LIQUIDITY must be followed by CLOSE_CURRENCY for both pool currencies');
352
+ }
353
+ const [currency0] = decodeAbiParameters(closeCurrencyParams, actionParams[1]);
354
+ const [currency1] = decodeAbiParameters(closeCurrencyParams, actionParams[2]);
355
+ if (!same(currency0, expected.currency0) || !same(currency1, expected.currency1)) {
356
+ mismatch('CLOSE_CURRENCY actions target a different currency pair than expected');
357
+ }
358
+ if (actionIds.length === 4) {
359
+ if (actionIds[3] !== SWEEP_ACTION)
360
+ mismatch('Increase calldata has an unreviewed action after CLOSE_CURRENCY');
361
+ const [sweepCurrency, sweepTo] = decodeAbiParameters(sweepParams, actionParams[3]);
362
+ if (!same(sweepCurrency, zeroAddress) && !same(sweepCurrency, expected.currency0))
363
+ mismatch('SWEEP refunds an unexpected currency');
364
+ if (!same(sweepTo, MSG_SENDER))
365
+ mismatch('SWEEP sends the refund to an unexpected recipient');
366
+ }
367
+ if (!same(expected.hooks, zeroAddress)) {
368
+ if (!expected.modelledHookPermissions)
369
+ mismatch('Increase targets a pool with a hook but no modelled permissions were supplied');
370
+ const unmodelled = unmodelledV4HookPermissions(expected.hooks, expected.modelledHookPermissions);
371
+ if (unmodelled.length)
372
+ mismatch(`Increase pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);
373
+ }
374
+ if (batchPermit) {
375
+ if (!expected.batchPermit)
376
+ mismatch('Increase calldata includes a Permit2 batch approval but no expected approval was supplied');
377
+ const poolTokens = [expected.currency0, expected.currency1];
378
+ const seen = new Set();
379
+ for (const detail of batchPermit.details) {
380
+ if (same(detail.token, zeroAddress) || !poolTokens.some(token => same(token, detail.token))) {
381
+ mismatch('Permit2 batch approval references a token outside the position pool');
382
+ }
383
+ if (seen.has(detail.token.toLowerCase()))
384
+ mismatch('Permit2 batch approval lists the same token more than once');
385
+ seen.add(detail.token.toLowerCase());
386
+ }
387
+ if (!same(batchPermit.owner, expected.batchPermit.owner)
388
+ || !same(batchPermit.spender, expected.batchPermit.spender)
389
+ || batchPermit.sigDeadline !== expected.batchPermit.sigDeadline
390
+ || !sameBatchPermitDetails(batchPermit.details, expected.batchPermit.details)) {
391
+ mismatch('Increase Permit2 batch approval does not match what was expected');
392
+ }
393
+ }
394
+ return {
395
+ tokenId,
396
+ liquidityAdded,
397
+ amount0Max,
398
+ amount1Max,
399
+ hookData,
400
+ currency0,
401
+ currency1,
402
+ deadline,
403
+ ...(batchPermit ? { batchPermitOwner: batchPermit.owner } : {}),
404
+ };
405
+ }
406
+ catch (error) {
407
+ if (error instanceof UniswapSdkError)
408
+ throw error;
409
+ throw new UniswapSdkError('CALLDATA_MISMATCH', 'Increase calldata contains undecodable position-manager calls', { cause: error });
410
+ }
411
+ }
412
+ /**
413
+ * Reviews the exact removal shape emitted by `buildV4RemovePositionTransaction`:
414
+ * one DECREASE_LIQUIDITY or BURN_POSITION action followed by TAKE_PAIR to
415
+ * PositionManager's `msgSender()` sentinel. Pool identity beyond the currency pair
416
+ * must be independently proven by a same-block token-ID position read.
417
+ */
418
+ export function reviewV4RemovePositionCalldata(data, expected) {
419
+ try {
420
+ const decoded = decodeFunctionData({ abi: v4PositionManagerAbi, data });
421
+ let unlockData;
422
+ let deadline;
423
+ if (decoded.functionName === 'multicall') {
424
+ const calls = decoded.args[0].map(call => decodeFunctionData({ abi: v4PositionManagerAbi, data: call }));
425
+ if (calls.length !== 1 || calls[0].functionName !== 'modifyLiquidities') {
426
+ mismatch('Removal calldata multicall must contain exactly one modifyLiquidities call');
427
+ }
428
+ [unlockData, deadline] = calls[0].args;
429
+ }
430
+ else if (decoded.functionName === 'modifyLiquidities') {
431
+ [unlockData, deadline] = decoded.args;
432
+ }
433
+ else {
434
+ return mismatch('Removal calldata is not a position-manager modifyLiquidities call');
435
+ }
436
+ const [actionsBytes, actionParams] = decodeAbiParameters(unlockDataParams, unlockData);
437
+ const actionIds = decodeActionIds(actionsBytes);
438
+ if (actionIds.length !== 2 || actionParams.length !== 2) {
439
+ mismatch('Removal calldata must contain exactly one liquidity action followed by TAKE_PAIR');
440
+ }
441
+ let tokenId;
442
+ let liquidityRemoved;
443
+ let amount0Min;
444
+ let amount1Min;
445
+ let hookData;
446
+ let burned;
447
+ if (actionIds[0] === DECREASE_LIQUIDITY_ACTION) {
448
+ [tokenId, liquidityRemoved, amount0Min, amount1Min, hookData] = decodeAbiParameters(decreaseLiquidityParams, actionParams[0]);
449
+ burned = false;
450
+ if (liquidityRemoved <= 0n)
451
+ mismatch('Removal calldata removes non-positive liquidity');
452
+ }
453
+ else if (actionIds[0] === BURN_POSITION_ACTION) {
454
+ [tokenId, amount0Min, amount1Min, hookData] = decodeAbiParameters(burnPositionParams, actionParams[0]);
455
+ liquidityRemoved = expected.liquidityToRemove;
456
+ burned = true;
457
+ }
458
+ else {
459
+ return mismatch('Removal calldata must begin with DECREASE_LIQUIDITY or BURN_POSITION');
460
+ }
461
+ if (actionIds[1] !== TAKE_PAIR_ACTION)
462
+ mismatch('Removal liquidity action must be followed by TAKE_PAIR');
463
+ const [currency0, currency1, recipient] = decodeAbiParameters(takePairParams, actionParams[1]);
464
+ if (!same(currency0, expected.currency0) || !same(currency1, expected.currency1)) {
465
+ mismatch('TAKE_PAIR withdraws a different currency pair than expected');
466
+ }
467
+ if (!same(recipient, MSG_SENDER))
468
+ mismatch('TAKE_PAIR sends withdrawn assets to an unexpected recipient');
469
+ if (tokenId !== expected.tokenId)
470
+ mismatch('Removal calldata targets a different position token ID');
471
+ if (burned !== expected.burnToken)
472
+ mismatch('Removal calldata burn behavior differs from expected');
473
+ if (liquidityRemoved !== expected.liquidityToRemove)
474
+ mismatch('Removal calldata removes different liquidity than expected');
475
+ if (!same(expected.hooks, zeroAddress)) {
476
+ if (!expected.modelledHookPermissions) {
477
+ mismatch('Removal targets a pool with a hook but no modelled permissions were supplied to verify it');
478
+ }
479
+ const unmodelled = unmodelledV4HookPermissions(expected.hooks, expected.modelledHookPermissions);
480
+ if (unmodelled.length)
481
+ mismatch(`Removal pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);
482
+ }
483
+ return {
484
+ tokenId,
485
+ liquidityRemoved,
486
+ amount0Min,
487
+ amount1Min,
488
+ hookData,
489
+ currency0,
490
+ currency1,
491
+ recipient,
492
+ deadline,
493
+ burned,
494
+ };
495
+ }
496
+ catch (error) {
497
+ if (error instanceof UniswapSdkError)
498
+ throw error;
499
+ throw new UniswapSdkError('CALLDATA_MISMATCH', 'Removal calldata contains undecodable position-manager calls', { cause: error });
500
+ }
501
+ }
159
502
  /**
160
503
  * Decodes and verifies calldata built by `buildV4MintPositionTransaction`: a
161
504
  * `modifyLiquidities` call — optionally wrapped in a `multicall` alongside pool
@@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AAO,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"]}
1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AK,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\nexport type V4RemovePositionParams = {\n positionManager: Address;\n pool: V4PoolState;\n tokenId: bigint;\n tickLower: number;\n tickUpper: number;\n /** Current on-chain position liquidity at the reviewed observation block. */\n liquidity: bigint;\n /** Exact liquidity units to remove. */\n liquidityToRemove: bigint;\n /** Burns the position NFT after removing all liquidity. */\n burnToken?: boolean;\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 /** Permission flags reviewed for a nonzero pool hook. */\n modelledHookPermissions?: readonly (keyof V4HookPermissions)[];\n};\n\nexport type V4IncreasePositionParams = {\n positionManager: Address;\n pool: V4PoolState;\n tokenId: bigint;\n tickLower: number;\n tickUpper: number;\n /** Exact liquidity units to add to the existing position. */\n liquidityToAdd: bigint;\n slippageToleranceBps: number;\n deadlineSeconds: bigint;\n hookData?: Hex;\n batchPermit?: V4BatchPermit;\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\n/**\n * Builds unsigned calldata that removes exact liquidity units from one V4 position and\n * returns both currencies to PositionManager's `msgSender()`. Full exits may atomically\n * burn the NFT. The caller must independently bind the token ID to the supplied PoolKey,\n * ticks, liquidity and owner at the same observation block; V4 removal calldata contains\n * a token ID rather than the complete PoolKey.\n */\nexport function buildV4RemovePositionTransaction(input: V4RemovePositionParams): V4TransactionMaterial {\n if (input.tokenId < 0n) invalid('Position token ID must be non-negative');\n if (input.liquidity <= 0n) invalid('Current position liquidity must be positive');\n if (input.liquidityToRemove <= 0n || input.liquidityToRemove > input.liquidity) {\n invalid('Liquidity to remove must be positive and no greater than current position liquidity');\n }\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.burnToken && input.liquidityToRemove !== input.liquidity) {\n invalid('burnToken requires removing all current position liquidity');\n }\n const positionManager = checkedAddress(input.positionManager);\n const hooks = checkedAddress(input.pool.hooks);\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 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.removeCallParameters(position, {\n tokenId: input.tokenId.toString(),\n liquidityPercentage: new Percent(input.liquidityToRemove.toString(), input.liquidity.toString()),\n burnToken: input.burnToken ?? false,\n slippageTolerance: slippagePercent(input.slippageToleranceBps),\n hookData: input.hookData,\n deadline: input.deadlineSeconds.toString(),\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 removal parameters', { cause });\n }\n}\n\n/** Builds unsigned calldata that increases one existing V4 position. */\nexport function buildV4IncreasePositionTransaction(input: V4IncreasePositionParams): V4TransactionMaterial {\n if (input.tokenId < 0n) invalid('Position token ID must be non-negative');\n if (input.liquidityToAdd <= 0n) invalid('Liquidity to add 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 const positionManager = checkedAddress(input.positionManager);\n const hooks = checkedAddress(input.pool.hooks);\n if (!same(hooks, zeroAddress)) {\n if (!input.modelledHookPermissions) invalid('pool.hooks is set but no modelledHookPermissions were supplied to verify it');\n const unmodelled = unmodelledV4HookPermissions(hooks, input.modelledHookPermissions);\n if (unmodelled.length) invalid(`Pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);\n }\n if (input.batchPermit) validateBatchPermit(input.batchPermit, positionManager, input.pool);\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.liquidityToAdd.toString(),\n tickLower: input.tickLower,\n tickUpper: input.tickUpper,\n });\n const params = V4PositionManager.addCallParameters(position, {\n tokenId: input.tokenId.toString(),\n useNative: pool.currency0.isNative ? pool.currency0 : undefined,\n slippageTolerance: slippagePercent(input.slippageToleranceBps),\n hookData: input.hookData,\n deadline: input.deadlineSeconds.toString(),\n ...(input.batchPermit ? { batchPermit: serializableBatchPermit(input.batchPermit) } : {}),\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 increase parameters', { cause });\n }\n}\n\nfunction validateBatchPermit(batchPermit: V4BatchPermit, positionManager: Address, pool: V4PoolState): void {\n if (!same(batchPermit.permitBatch.spender, positionManager)) {\n invalid('batchPermit.permitBatch.spender must be the position manager this transaction submits to');\n }\n if (!batchPermit.permitBatch.details.length) invalid('batchPermit.permitBatch.details must include at least one token');\n const poolTokens = [pool.currency0, 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 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 position 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\nfunction serializableBatchPermit(batchPermit: V4BatchPermit) {\n return {\n owner: checkedAddress(batchPermit.owner),\n permitBatch: {\n details: 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(batchPermit.permitBatch.spender),\n sigDeadline: batchPermit.permitBatch.sigDeadline.toString(),\n },\n signature: batchPermit.signature,\n };\n}\n\nconst MINT_POSITION_ACTION = 2;\nconst INCREASE_LIQUIDITY_ACTION = 0;\nconst DECREASE_LIQUIDITY_ACTION = 1;\nconst BURN_POSITION_ACTION = 3;\nconst SETTLE_PAIR_ACTION = 13;\nconst TAKE_PAIR_ACTION = 17;\nconst CLOSE_CURRENCY_ACTION = 18;\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 increaseLiquidityParams = parseAbiParameters(\n 'uint256 tokenId, uint256 liquidity, uint128 amount0Max, uint128 amount1Max, bytes hookData',\n);\nconst settlePairParams = parseAbiParameters('address currency0, address currency1');\nconst sweepParams = parseAbiParameters('address currency, address to');\nconst decreaseLiquidityParams = parseAbiParameters(\n 'uint256 tokenId, uint256 liquidity, uint128 amount0Min, uint128 amount1Min, bytes hookData',\n);\nconst burnPositionParams = parseAbiParameters(\n 'uint256 tokenId, uint128 amount0Min, uint128 amount1Min, bytes hookData',\n);\nconst takePairParams = parseAbiParameters('address currency0, address currency1, address recipient');\nconst closeCurrencyParams = parseAbiParameters('address currency');\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\nexport type V4ExpectedRemoval = V4PoolKeyMaterial & {\n tokenId: bigint;\n /** Exact liquidity units reviewed for removal. Required for partial exits. */\n liquidityToRemove: bigint;\n burnToken: boolean;\n modelledHookPermissions?: readonly (keyof V4HookPermissions)[];\n};\n\nexport type V4ExpectedIncrease = V4PoolKeyMaterial & {\n tokenId: bigint;\n batchPermit?: { owner: Address; spender: Address; sigDeadline: bigint; details: readonly V4BatchPermitDetail[] };\n modelledHookPermissions?: readonly (keyof V4HookPermissions)[];\n};\n\nexport type V4IncreaseActionParams = {\n tokenId: bigint;\n liquidityAdded: bigint;\n amount0Max: bigint;\n amount1Max: bigint;\n hookData: Hex;\n currency0: Address;\n currency1: Address;\n deadline: bigint;\n batchPermitOwner?: Address;\n};\n\n/** Reviews the exact increase/settlement shape emitted by the corresponding builder. */\nexport function reviewV4IncreasePositionCalldata(data: Hex, expected: V4ExpectedIncrease): V4IncreaseActionParams {\n try {\n const decoded = decodeFunctionData({ abi: v4PositionManagerAbi, data });\n let unlockData: Hex;\n let deadline: bigint;\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 < 1 || calls.length > 2) mismatch('Increase calldata multicall has an unexpected call count');\n const increaseCall = calls.at(-1)!;\n if (increaseCall.functionName !== 'modifyLiquidities') mismatch('Increase calldata multicall must end with modifyLiquidities');\n if (calls.length === 2) {\n const permitCall = calls[0]!;\n if (permitCall.functionName !== 'permitBatch') mismatch('Increase calldata contains an unreviewed call before modifyLiquidities');\n const [owner, permit] = permitCall.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: permit.spender,\n sigDeadline: permit.sigDeadline,\n details: permit.details.map(detail => ({ token: detail.token, amount: detail.amount, expiration: BigInt(detail.expiration), nonce: BigInt(detail.nonce) })),\n };\n }\n [unlockData, deadline] = increaseCall.args as [Hex, bigint];\n } else if (decoded.functionName === 'modifyLiquidities') {\n [unlockData, deadline] = decoded.args;\n } else {\n return mismatch('Increase 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 < 3 || actionIds.length > 4 || actionIds.length !== actionParams.length) {\n mismatch('Increase calldata has an unexpected action count');\n }\n if (actionIds[0] !== INCREASE_LIQUIDITY_ACTION) mismatch('Increase calldata must begin with INCREASE_LIQUIDITY');\n const [tokenId, liquidityAdded, amount0Max, amount1Max, hookData] = decodeAbiParameters(\n increaseLiquidityParams,\n actionParams[0]!,\n ) as [bigint, bigint, bigint, bigint, Hex];\n if (tokenId !== expected.tokenId) mismatch('Increase calldata targets a different position token ID');\n if (liquidityAdded <= 0n) mismatch('Increase calldata adds non-positive liquidity');\n if (actionIds[1] !== CLOSE_CURRENCY_ACTION || actionIds[2] !== CLOSE_CURRENCY_ACTION) {\n mismatch('INCREASE_LIQUIDITY must be followed by CLOSE_CURRENCY for both pool currencies');\n }\n const [currency0] = decodeAbiParameters(closeCurrencyParams, actionParams[1]!) as [Address];\n const [currency1] = decodeAbiParameters(closeCurrencyParams, actionParams[2]!) as [Address];\n if (!same(currency0, expected.currency0) || !same(currency1, expected.currency1)) {\n mismatch('CLOSE_CURRENCY actions target a different currency pair than expected');\n }\n if (actionIds.length === 4) {\n if (actionIds[3] !== SWEEP_ACTION) mismatch('Increase calldata has an unreviewed action after CLOSE_CURRENCY');\n const [sweepCurrency, sweepTo] = decodeAbiParameters(sweepParams, actionParams[3]!) as [Address, Address];\n if (!same(sweepCurrency, zeroAddress) && !same(sweepCurrency, expected.currency0)) mismatch('SWEEP refunds an unexpected currency');\n if (!same(sweepTo, MSG_SENDER)) mismatch('SWEEP sends the refund to an unexpected recipient');\n }\n if (!same(expected.hooks, zeroAddress)) {\n if (!expected.modelledHookPermissions) mismatch('Increase targets a pool with a hook but no modelled permissions were supplied');\n const unmodelled = unmodelledV4HookPermissions(expected.hooks, expected.modelledHookPermissions);\n if (unmodelled.length) mismatch(`Increase pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);\n }\n if (batchPermit) {\n if (!expected.batchPermit) mismatch('Increase calldata includes a Permit2 batch approval but no expected approval was supplied');\n const poolTokens = [expected.currency0, expected.currency1];\n const seen = new Set<string>();\n for (const detail of batchPermit.details) {\n if (same(detail.token, zeroAddress) || !poolTokens.some(token => same(token, detail.token))) {\n mismatch('Permit2 batch approval references a token outside the position pool');\n }\n if (seen.has(detail.token.toLowerCase())) mismatch('Permit2 batch approval lists the same token more than once');\n seen.add(detail.token.toLowerCase());\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('Increase Permit2 batch approval does not match what was expected');\n }\n }\n return {\n tokenId,\n liquidityAdded,\n amount0Max,\n amount1Max,\n hookData,\n currency0,\n currency1,\n deadline,\n ...(batchPermit ? { batchPermitOwner: batchPermit.owner } : {}),\n };\n } catch (error) {\n if (error instanceof UniswapSdkError) throw error;\n throw new UniswapSdkError('CALLDATA_MISMATCH', 'Increase calldata contains undecodable position-manager calls', { cause: error });\n }\n}\n\nexport type V4RemoveActionParams = {\n tokenId: bigint;\n liquidityRemoved: bigint;\n amount0Min: bigint;\n amount1Min: bigint;\n hookData: Hex;\n currency0: Address;\n currency1: Address;\n recipient: Address;\n deadline: bigint;\n burned: boolean;\n};\n\n/**\n * Reviews the exact removal shape emitted by `buildV4RemovePositionTransaction`:\n * one DECREASE_LIQUIDITY or BURN_POSITION action followed by TAKE_PAIR to\n * PositionManager's `msgSender()` sentinel. Pool identity beyond the currency pair\n * must be independently proven by a same-block token-ID position read.\n */\nexport function reviewV4RemovePositionCalldata(data: Hex, expected: V4ExpectedRemoval): V4RemoveActionParams {\n try {\n const decoded = decodeFunctionData({ abi: v4PositionManagerAbi, data });\n let unlockData: Hex;\n let deadline: bigint;\n if (decoded.functionName === 'multicall') {\n const calls = decoded.args[0].map(call => decodeFunctionData({ abi: v4PositionManagerAbi, data: call }));\n if (calls.length !== 1 || calls[0]!.functionName !== 'modifyLiquidities') {\n mismatch('Removal calldata multicall must contain exactly one modifyLiquidities call');\n }\n [unlockData, deadline] = calls[0]!.args as [Hex, bigint];\n } else if (decoded.functionName === 'modifyLiquidities') {\n [unlockData, deadline] = decoded.args;\n } else {\n return mismatch('Removal 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 !== 2 || actionParams.length !== 2) {\n mismatch('Removal calldata must contain exactly one liquidity action followed by TAKE_PAIR');\n }\n\n let tokenId: bigint;\n let liquidityRemoved: bigint;\n let amount0Min: bigint;\n let amount1Min: bigint;\n let hookData: Hex;\n let burned: boolean;\n if (actionIds[0] === DECREASE_LIQUIDITY_ACTION) {\n [tokenId, liquidityRemoved, amount0Min, amount1Min, hookData] = decodeAbiParameters(\n decreaseLiquidityParams,\n actionParams[0]!,\n ) as [bigint, bigint, bigint, bigint, Hex];\n burned = false;\n if (liquidityRemoved <= 0n) mismatch('Removal calldata removes non-positive liquidity');\n } else if (actionIds[0] === BURN_POSITION_ACTION) {\n [tokenId, amount0Min, amount1Min, hookData] = decodeAbiParameters(\n burnPositionParams,\n actionParams[0]!,\n ) as [bigint, bigint, bigint, Hex];\n liquidityRemoved = expected.liquidityToRemove;\n burned = true;\n } else {\n return mismatch('Removal calldata must begin with DECREASE_LIQUIDITY or BURN_POSITION');\n }\n\n if (actionIds[1] !== TAKE_PAIR_ACTION) mismatch('Removal liquidity action must be followed by TAKE_PAIR');\n const [currency0, currency1, recipient] = decodeAbiParameters(\n takePairParams,\n actionParams[1]!,\n ) as [Address, Address, Address];\n if (!same(currency0, expected.currency0) || !same(currency1, expected.currency1)) {\n mismatch('TAKE_PAIR withdraws a different currency pair than expected');\n }\n if (!same(recipient, MSG_SENDER)) mismatch('TAKE_PAIR sends withdrawn assets to an unexpected recipient');\n if (tokenId !== expected.tokenId) mismatch('Removal calldata targets a different position token ID');\n if (burned !== expected.burnToken) mismatch('Removal calldata burn behavior differs from expected');\n if (liquidityRemoved !== expected.liquidityToRemove) mismatch('Removal calldata removes different liquidity than expected');\n\n if (!same(expected.hooks, zeroAddress)) {\n if (!expected.modelledHookPermissions) {\n mismatch('Removal targets a pool with a hook but no modelled permissions were supplied to verify it');\n }\n const unmodelled = unmodelledV4HookPermissions(expected.hooks, expected.modelledHookPermissions);\n if (unmodelled.length) mismatch(`Removal pool hook implements unmodelled permissions: ${unmodelled.join(', ')}`);\n }\n\n return {\n tokenId,\n liquidityRemoved,\n amount0Min,\n amount1Min,\n hookData,\n currency0,\n currency1,\n recipient,\n deadline,\n burned,\n };\n } catch (error) {\n if (error instanceof UniswapSdkError) throw error;\n throw new UniswapSdkError('CALLDATA_MISMATCH', 'Removal calldata contains undecodable position-manager calls', { cause: error });\n }\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/dist/v4.d.ts CHANGED
@@ -7,8 +7,8 @@ export type { V4Tick, V4TickWindow } from './depth.js';
7
7
  export { decodeV4PoolInitialization } from './events.js';
8
8
  export { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';
9
9
  export type { V4HookPermissions } from './hooks.js';
10
- export { buildV4MintPositionTransaction, reviewV4MintPositionCalldata } from './v4-transactions.js';
11
- export type { V4BatchPermit, V4BatchPermitDetail, V4ExpectedMint, V4MintActionParams, V4MintPositionParams, V4PoolKeyMaterial, V4PoolState, V4TransactionMaterial } from './v4-transactions.js';
10
+ export { buildV4MintPositionTransaction, buildV4IncreasePositionTransaction, buildV4RemovePositionTransaction, reviewV4MintPositionCalldata, reviewV4IncreasePositionCalldata, reviewV4RemovePositionCalldata, } from './v4-transactions.js';
11
+ export type { V4BatchPermit, V4BatchPermitDetail, V4ExpectedMint, V4ExpectedIncrease, V4ExpectedRemoval, V4MintActionParams, V4MintPositionParams, V4IncreaseActionParams, V4IncreasePositionParams, V4PoolKeyMaterial, V4PoolState, V4RemoveActionParams, V4RemovePositionParams, V4TransactionMaterial, } from './v4-transactions.js';
12
12
  export { buildV4MintPermitBatchTypedData } from './permit2.js';
13
13
  export type { V4PermitBatchDetailInput, V4PermitBatchTypedData } from './permit2.js';
14
14
  export { arcUniswapV4Mainnet, getArcUniswapV4Deployment } from './deployments.js';
package/dist/v4.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"v4.d.ts","sourceRoot":"","sources":["../src/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC9E,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACnG,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACpH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAClF,YAAY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OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAClF,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EACL,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,EAChC,4BAA4B,EAC5B,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,YAAY,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAClF,YAAY,EACV,sCAAsC,EACtC,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AACrE,YAAY,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/v4.js CHANGED
@@ -3,7 +3,7 @@ export { readV4Pool, quoteV4ExactInput, quoteV4Batch, verifyV4DeploymentWiring }
3
3
  export { readV4TickWindow, ticksInWord } from './depth.js';
4
4
  export { decodeV4PoolInitialization } from './events.js';
5
5
  export { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';
6
- export { buildV4MintPositionTransaction, reviewV4MintPositionCalldata } from './v4-transactions.js';
6
+ export { buildV4MintPositionTransaction, buildV4IncreasePositionTransaction, buildV4RemovePositionTransaction, reviewV4MintPositionCalldata, reviewV4IncreasePositionCalldata, reviewV4RemovePositionCalldata, } from './v4-transactions.js';
7
7
  export { buildV4MintPermitBatchTypedData } from './permit2.js';
8
8
  export { arcUniswapV4Mainnet, getArcUniswapV4Deployment } from './deployments.js';
9
9
  export { verifyArcUniswapV4Compatibility } from './compatibility.js';
package/dist/v4.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"v4.js","sourceRoot":"","sources":["../src/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEnG,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAElF,OAAO,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAUlF,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { poolKeyFromCurrencies, getV4PoolId, poolReference } from './pool.js';\nexport type { V4Deployment, V4PoolKey, V4PoolReference } from './pool.js';\nexport { readV4Pool, quoteV4ExactInput, quoteV4Batch, verifyV4DeploymentWiring } from './reads.js';\nexport type { V4ReadClient, V4Observation, V4PoolSnapshot, V4QuoteInput, V4Quote, V4QuoteResult } from './reads.js';\nexport { readV4TickWindow, ticksInWord } from './depth.js';\nexport type { V4Tick, V4TickWindow } from './depth.js';\nexport { decodeV4PoolInitialization } from './events.js';\nexport { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';\nexport type { V4HookPermissions } from './hooks.js';\nexport { buildV4MintPositionTransaction, reviewV4MintPositionCalldata } from './v4-transactions.js';\nexport type { V4BatchPermit, V4BatchPermitDetail, V4ExpectedMint, V4MintActionParams, V4MintPositionParams, V4PoolKeyMaterial, V4PoolState, V4TransactionMaterial } from './v4-transactions.js';\nexport { buildV4MintPermitBatchTypedData } from './permit2.js';\nexport type { V4PermitBatchDetailInput, V4PermitBatchTypedData } from './permit2.js';\nexport { arcUniswapV4Mainnet, getArcUniswapV4Deployment } from './deployments.js';\nexport type {\n ArcUniswapV4ArtifactBackedContractName,\n ArcUniswapV4ContractName,\n ArcUniswapV4Contracts,\n ArcUniswapV4Deployment,\n ArcUniswapV4DeploymentId,\n ArcUniswapV4RuntimeCodeHashes,\n ArcUniswapV4RetainedArtifact,\n} from './deployments.js';\nexport { verifyArcUniswapV4Compatibility } from './compatibility.js';\nexport type { ArcUniswapV4CompatibilityReport } from './compatibility.js';\n"]}
1
+ {"version":3,"file":"v4.js","sourceRoot":"","sources":["../src/v4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEnG,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAElF,OAAO,EACL,8BAA8B,EAC9B,kCAAkC,EAClC,gCAAgC,EAChC,4BAA4B,EAC5B,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAUlF,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { poolKeyFromCurrencies, getV4PoolId, poolReference } from './pool.js';\nexport type { V4Deployment, V4PoolKey, V4PoolReference } from './pool.js';\nexport { readV4Pool, quoteV4ExactInput, quoteV4Batch, verifyV4DeploymentWiring } from './reads.js';\nexport type { V4ReadClient, V4Observation, V4PoolSnapshot, V4QuoteInput, V4Quote, V4QuoteResult } from './reads.js';\nexport { readV4TickWindow, ticksInWord } from './depth.js';\nexport type { V4Tick, V4TickWindow } from './depth.js';\nexport { decodeV4PoolInitialization } from './events.js';\nexport { decodeV4HookPermissions, unmodelledV4HookPermissions } from './hooks.js';\nexport type { V4HookPermissions } from './hooks.js';\nexport {\n buildV4MintPositionTransaction,\n buildV4IncreasePositionTransaction,\n buildV4RemovePositionTransaction,\n reviewV4MintPositionCalldata,\n reviewV4IncreasePositionCalldata,\n reviewV4RemovePositionCalldata,\n} from './v4-transactions.js';\nexport type {\n V4BatchPermit,\n V4BatchPermitDetail,\n V4ExpectedMint,\n V4ExpectedIncrease,\n V4ExpectedRemoval,\n V4MintActionParams,\n V4MintPositionParams,\n V4IncreaseActionParams,\n V4IncreasePositionParams,\n V4PoolKeyMaterial,\n V4PoolState,\n V4RemoveActionParams,\n V4RemovePositionParams,\n V4TransactionMaterial,\n} from './v4-transactions.js';\nexport { buildV4MintPermitBatchTypedData } from './permit2.js';\nexport type { V4PermitBatchDetailInput, V4PermitBatchTypedData } from './permit2.js';\nexport { arcUniswapV4Mainnet, getArcUniswapV4Deployment } from './deployments.js';\nexport type {\n ArcUniswapV4ArtifactBackedContractName,\n ArcUniswapV4ContractName,\n ArcUniswapV4Contracts,\n ArcUniswapV4Deployment,\n ArcUniswapV4DeploymentId,\n ArcUniswapV4RuntimeCodeHashes,\n ArcUniswapV4RetainedArtifact,\n} from './deployments.js';\nexport { verifyArcUniswapV4Compatibility } from './compatibility.js';\nexport type { ArcUniswapV4CompatibilityReport } from './compatibility.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reptilianhq/uniswap-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Deployment-explicit Uniswap observations and reviewed transaction material.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -128,6 +128,6 @@
128
128
  "reptilianRelease": {
129
129
  "schemaVersion": 1,
130
130
  "group": "uniswap-sdk",
131
- "sourceSha": "d080edda42054fce10727545c05464fce3f797ae"
131
+ "sourceSha": "215332af5c7b0996d71cf43980c4f553c300eb80"
132
132
  }
133
133
  }