@bananapus/nana-sdk-core 3.2.0 → 3.4.1

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.
Files changed (75) hide show
  1. package/dist/cjs/review/heldWrite.js +1 -1
  2. package/dist/cjs/review/heldWrite.js.map +1 -1
  3. package/dist/cjs/review/messages.d.ts +3 -1
  4. package/dist/cjs/review/messages.d.ts.map +1 -1
  5. package/dist/cjs/review/messages.js +4 -2
  6. package/dist/cjs/review/messages.js.map +1 -1
  7. package/dist/cjs/review/writeHold.d.ts +9 -6
  8. package/dist/cjs/review/writeHold.d.ts.map +1 -1
  9. package/dist/cjs/review/writeHold.js +12 -4
  10. package/dist/cjs/review/writeHold.js.map +1 -1
  11. package/dist/cjs/review/writeRecovery.d.ts +3 -2
  12. package/dist/cjs/review/writeRecovery.d.ts.map +1 -1
  13. package/dist/cjs/review/writeRecovery.js +3 -2
  14. package/dist/cjs/review/writeRecovery.js.map +1 -1
  15. package/dist/cjs/v6/cashOut.d.ts.map +1 -1
  16. package/dist/cjs/v6/cashOut.js +11 -39
  17. package/dist/cjs/v6/cashOut.js.map +1 -1
  18. package/dist/cjs/v6/defifa.d.ts +4 -2
  19. package/dist/cjs/v6/defifa.d.ts.map +1 -1
  20. package/dist/cjs/v6/defifa.js +10 -6
  21. package/dist/cjs/v6/defifa.js.map +1 -1
  22. package/dist/cjs/v6/executionErrors.d.ts +107 -0
  23. package/dist/cjs/v6/executionErrors.d.ts.map +1 -0
  24. package/dist/cjs/v6/executionErrors.js +373 -0
  25. package/dist/cjs/v6/executionErrors.js.map +1 -0
  26. package/dist/cjs/v6/index.d.ts +2 -0
  27. package/dist/cjs/v6/index.d.ts.map +1 -1
  28. package/dist/cjs/v6/index.js +6 -1
  29. package/dist/cjs/v6/index.js.map +1 -1
  30. package/dist/cjs/v6/pay.d.ts +32 -11
  31. package/dist/cjs/v6/pay.d.ts.map +1 -1
  32. package/dist/cjs/v6/pay.js +360 -42
  33. package/dist/cjs/v6/pay.js.map +1 -1
  34. package/dist/cjs/v6/uniswapV3.d.ts +21 -0
  35. package/dist/cjs/v6/uniswapV3.d.ts.map +1 -0
  36. package/dist/cjs/v6/uniswapV3.js +72 -0
  37. package/dist/cjs/v6/uniswapV3.js.map +1 -0
  38. package/dist/esm/review/heldWrite.js +2 -2
  39. package/dist/esm/review/heldWrite.js.map +1 -1
  40. package/dist/esm/review/messages.d.ts +3 -1
  41. package/dist/esm/review/messages.d.ts.map +1 -1
  42. package/dist/esm/review/messages.js +3 -1
  43. package/dist/esm/review/messages.js.map +1 -1
  44. package/dist/esm/review/writeHold.d.ts +9 -6
  45. package/dist/esm/review/writeHold.d.ts.map +1 -1
  46. package/dist/esm/review/writeHold.js +12 -4
  47. package/dist/esm/review/writeHold.js.map +1 -1
  48. package/dist/esm/review/writeRecovery.d.ts +3 -2
  49. package/dist/esm/review/writeRecovery.d.ts.map +1 -1
  50. package/dist/esm/review/writeRecovery.js +3 -2
  51. package/dist/esm/review/writeRecovery.js.map +1 -1
  52. package/dist/esm/v6/cashOut.d.ts.map +1 -1
  53. package/dist/esm/v6/cashOut.js +11 -39
  54. package/dist/esm/v6/cashOut.js.map +1 -1
  55. package/dist/esm/v6/defifa.d.ts +4 -2
  56. package/dist/esm/v6/defifa.d.ts.map +1 -1
  57. package/dist/esm/v6/defifa.js +10 -6
  58. package/dist/esm/v6/defifa.js.map +1 -1
  59. package/dist/esm/v6/executionErrors.d.ts +107 -0
  60. package/dist/esm/v6/executionErrors.d.ts.map +1 -0
  61. package/dist/esm/v6/executionErrors.js +367 -0
  62. package/dist/esm/v6/executionErrors.js.map +1 -0
  63. package/dist/esm/v6/index.d.ts +2 -0
  64. package/dist/esm/v6/index.d.ts.map +1 -1
  65. package/dist/esm/v6/index.js +2 -0
  66. package/dist/esm/v6/index.js.map +1 -1
  67. package/dist/esm/v6/pay.d.ts +32 -11
  68. package/dist/esm/v6/pay.d.ts.map +1 -1
  69. package/dist/esm/v6/pay.js +360 -43
  70. package/dist/esm/v6/pay.js.map +1 -1
  71. package/dist/esm/v6/uniswapV3.d.ts +21 -0
  72. package/dist/esm/v6/uniswapV3.d.ts.map +1 -0
  73. package/dist/esm/v6/uniswapV3.js +68 -0
  74. package/dist/esm/v6/uniswapV3.js.map +1 -0
  75. package/package.json +1 -1
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getDefifaHoldings = void 0;
17
+ exports.getDefifaHoldings = exports.payRetrySlippageBps = exports.PAY_MAX_SLIPPAGE_BPS = exports.decodePayFailure = void 0;
18
18
  __exportStar(require("./types.js"), exports);
19
19
  __exportStar(require("./currency.js"), exports);
20
20
  __exportStar(require("./fees.js"), exports);
@@ -30,12 +30,17 @@ __exportStar(require("./priceFeeds.js"), exports);
30
30
  __exportStar(require("./permit2.js"), exports);
31
31
  __exportStar(require("./projectPayers.js"), exports);
32
32
  __exportStar(require("./cashOut.js"), exports);
33
+ var executionErrors_js_1 = require("./executionErrors.js");
34
+ Object.defineProperty(exports, "decodePayFailure", { enumerable: true, get: function () { return executionErrors_js_1.decodePayFailure; } });
35
+ Object.defineProperty(exports, "PAY_MAX_SLIPPAGE_BPS", { enumerable: true, get: function () { return executionErrors_js_1.PAY_MAX_SLIPPAGE_BPS; } });
36
+ Object.defineProperty(exports, "payRetrySlippageBps", { enumerable: true, get: function () { return executionErrors_js_1.payRetrySlippageBps; } });
33
37
  __exportStar(require("./nft.js"), exports);
34
38
  __exportStar(require("./nftInventory.js"), exports);
35
39
  __exportStar(require("./defifa.js"), exports);
36
40
  var defifaHoldings_js_1 = require("./defifaHoldings.js");
37
41
  Object.defineProperty(exports, "getDefifaHoldings", { enumerable: true, get: function () { return defifaHoldings_js_1.getDefifaHoldings; } });
38
42
  __exportStar(require("./tokens.js"), exports);
43
+ __exportStar(require("./uniswapV3.js"), exports);
39
44
  __exportStar(require("./uniswapV4.js"), exports);
40
45
  __exportStar(require("./uniswapV4Fees.js"), exports);
41
46
  __exportStar(require("./permissions.js"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v6/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,gDAA8B;AAC9B,4CAA0B;AAC1B,8CAA4B;AAC5B,iDAA+B;AAC/B,gDAA8B;AAC9B,8CAA4B;AAC5B,qDAAmC;AACnC,+CAA6B;AAC7B,iDAA+B;AAC/B,2CAAyB;AACzB,kDAAgC;AAChC,+CAA6B;AAC7B,qDAAmC;AACnC,+CAA6B;AAC7B,2CAAyB;AACzB,oDAAkC;AAClC,8CAA4B;AAC5B,yDAI6B;AAH3B,sHAAA,iBAAiB,OAAA;AAInB,8CAA4B;AAC5B,iDAA+B;AAC/B,qDAAmC;AACnC,mDAAiC;AACjC,+CAA6B;AAC7B,6CAA2B;AAC3B,8CAA4B;AAC5B,iDAA+B;AAC/B,6DAA2C;AAC3C,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v6/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,gDAA8B;AAC9B,4CAA0B;AAC1B,8CAA4B;AAC5B,iDAA+B;AAC/B,gDAA8B;AAC9B,8CAA4B;AAC5B,qDAAmC;AACnC,+CAA6B;AAC7B,iDAA+B;AAC/B,2CAAyB;AACzB,kDAAgC;AAChC,+CAA6B;AAC7B,qDAAmC;AACnC,+CAA6B;AAC7B,2DAO8B;AAN5B,sHAAA,gBAAgB,OAAA;AAChB,0HAAA,oBAAoB,OAAA;AACpB,yHAAA,mBAAmB,OAAA;AAKrB,2CAAyB;AACzB,oDAAkC;AAClC,8CAA4B;AAC5B,yDAI6B;AAH3B,sHAAA,iBAAiB,OAAA;AAInB,8CAA4B;AAC5B,iDAA+B;AAC/B,iDAA+B;AAC/B,qDAAmC;AACnC,mDAAiC;AACjC,+CAA6B;AAC7B,6CAA2B;AAC3B,8CAA4B;AAC5B,iDAA+B;AAC/B,6DAA2C;AAC3C,qDAAmC"}
@@ -122,29 +122,50 @@ export interface PreparedUserPay {
122
122
  preview: PayPreview;
123
123
  minReturnedTokens: bigint;
124
124
  }
125
+ /** `prepareUserPay`'s tolerance on its quote and fallback minimum: 1%. */
126
+ export declare const PAY_DEFAULT_SLIPPAGE_BPS = 100n;
125
127
  /**
126
128
  * Prepare a person's payment with {@link buildUserPayMetadata}: preview it,
127
129
  * and set the minimum the terminal enforces on the beneficiary's balance.
128
130
  *
129
- * When the project's buyback hook honors `skipSplits` and its pool is in the
130
- * paid token, this quotes that pool (fee and price impact included) and sends
131
- * the slippage-floored quote as an explicit minimum. The hook then swaps
132
- * whenever the pool beats the payer's share of a mint, and reverts below the
133
- * floor. Without it the hook routes by its TWAP floor, which reaches zero on
134
- * large buys against a thin pool and sends them to minting even when the pool
135
- * pays far more.
131
+ * When the project's buyback hook would swap, this quotes its pool (fee and
132
+ * price impact included) and sends the slippage-floored quote as an explicit
133
+ * minimum, so the payer gets the pool's rate whenever it
134
+ * beats minting. The hook compares that minimum to the swap output plus the
135
+ * leftover mint: the whole leftover mint when the swapped tokens go through
136
+ * the reserved split (`skipSplits` false, and always on hook 1.1.1, which
137
+ * ignores `skipSplits`), its beneficiary share when they skip it. The
138
+ * terminal minimum is the beneficiary's part of that guarantee, plus what the
139
+ * terminal issues itself (such as for NFT splits). The quoted payment is
140
+ * previewed again first, and stays on the mint path if the hook would not
141
+ * swap with that minimum. Without a quote the hook routes by its TWAP floor,
142
+ * which reaches zero on large buys against a thin pool and sends them to
143
+ * minting even when the pool pays far more.
136
144
  *
137
- * Otherwise (no pool, hook 1.1.1, a router converting the token first, or a
138
- * failed quote) the hook routes by TWAP. The minimum is then the payer's mint
145
+ * Behind a router terminal, its registry or its gateway, when the router
146
+ * converts the paid token first with one swap, the pool is the one in the
147
+ * token it converts to, quoted on what that swap is quoted to return. If the
148
+ * conversion returns noticeably less, the hook's minimum reverts the payment.
149
+ * If it returns more, the hook mints once minting reaches the minimum, which
150
+ * happens only when the pool beats minting by less than `slippageBps` plus
151
+ * that gain. The payer still receives at least the minimum, and no fixed
152
+ * minimum avoids this when the pool's edge is inside the conversion's
153
+ * uncertainty. Other routes, such as cashing a project token out first, keep
154
+ * the fallback.
155
+ *
156
+ * Otherwise (no pool, or a failed quote) the minimum is the payer's mint
139
157
  * entitlement when the hook would swap, since the hook never settles below it,
140
- * and the terminal's own issuance when it would not.
158
+ * and the terminal's own issuance when it would not. If the payment then
159
+ * reverts, {@link decodePayFailure} says why. To let the payer accept less,
160
+ * prepare again with a larger `slippageBps`: the hook's minimum is in the
161
+ * metadata, so lowering `minReturnedTokens` alone does not relax it.
141
162
  *
142
163
  * When the ruleset calls buyback hook 1.4 directly (or through the omnichain
143
164
  * deployer) instead of through the registry, the metadata is keyed to the hook,
144
165
  * which reads nothing else.
145
166
  *
146
167
  * @param args.slippageBps Tolerance on the pool quote and on the fallback
147
- * minimum. Defaults to 100 (1%).
168
+ * minimum. Defaults to {@link PAY_DEFAULT_SLIPPAGE_BPS}.
148
169
  * @param args.skipSplits Whether the beneficiary keeps the swapped tokens
149
170
  * without the reserved split. Defaults to true, as a person's pay card does;
150
171
  * pass false for payments that should honor the project's splits, such as
@@ -1 +1 @@
1
- {"version":3,"file":"pay.d.ts","sourceRoot":"","sources":["../../../src/v6/pay.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,GAAG,EACH,YAAY,EAIb,MAAM,MAAM,CAAC;AAMd,OAAO,EAEL,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AASxC;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,SAAS,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACj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E,OAAO,CAAC;IACtB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,GAAG,CAeN;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,IAAI,EACJ,gBAAgB,EAChB,oBAAoB,EACpB,UAAkB,GACnB,EAAE;IACD,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GAAG,GAAG,CAUN;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,OAAO,EACP,KAAK,EACL,oBAAyB,EACzB,UAAiB,EACjB,IAAkD,GACnD,EAAE;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,GAAG,GAAG,CAqBN"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PAY_DEFAULT_SLIPPAGE_BPS = void 0;
3
4
  exports.buildPayTx = buildPayTx;
4
5
  exports.previewPay = previewPay;
5
6
  exports.effectivePayPreview = effectivePayPreview;
@@ -12,7 +13,9 @@ const constants_js_1 = require("../constants.js");
12
13
  const juicebox_js_1 = require("../generated/juicebox.js");
13
14
  const hook_js_1 = require("../utils/hook.js");
14
15
  const cashOut_js_1 = require("./cashOut.js");
16
+ const terminals_js_1 = require("./terminals.js");
15
17
  const types_js_1 = require("./types.js");
18
+ const uniswapV3_js_1 = require("./uniswapV3.js");
16
19
  const uniswapV4_js_1 = require("./uniswapV4.js");
17
20
  /**
18
21
  * Build a `pay(projectId, token, amount, beneficiary, minReturnedTokens, memo,
@@ -312,35 +315,293 @@ const poolKeyOfAbi = [
312
315
  ],
313
316
  },
314
317
  ];
318
+ /** `prepareUserPay`'s tolerance on its quote and fallback minimum: 1%. */
319
+ exports.PAY_DEFAULT_SLIPPAGE_BPS = 100n;
320
+ /**
321
+ * The buyback pool a payment's spec reports, and the terminal token it is
322
+ * keyed to, or null. A router converts the paid token first, so its pool is
323
+ * keyed to another token the project accepts. The pool id is the key's hash,
324
+ * so a match proves the key.
325
+ */
326
+ async function buybackPoolOf(client, { chainId, hook, projectId, token, poolId, }) {
327
+ const poolOf = async (terminalToken) => ({
328
+ terminalToken,
329
+ key: await client.readContract({
330
+ address: hook,
331
+ abi: poolKeyOfAbi,
332
+ functionName: "poolKeyOf",
333
+ args: [
334
+ projectId,
335
+ terminalToken.toLowerCase() === constants_js_1.NATIVE_TOKEN.toLowerCase()
336
+ ? viem_1.zeroAddress
337
+ : terminalToken,
338
+ ],
339
+ }),
340
+ });
341
+ const paid = await poolOf(token);
342
+ if ((0, uniswapV4_js_1.uniswapV4PoolId)(paid.key) === poolId)
343
+ return paid;
344
+ const contexts = await (0, terminals_js_1.getAccountingContexts)(client, { chainId, projectId });
345
+ const pools = await Promise.all(contexts
346
+ .filter((c) => c.token.toLowerCase() !== token.toLowerCase())
347
+ .map((c) => poolOf(c.token)));
348
+ return pools.find((p) => (0, uniswapV4_js_1.uniswapV4PoolId)(p.key) === poolId) ?? null;
349
+ }
350
+ const previewPayForOutputs = juicebox_js_1.jbMultiTerminalAbi.find((item) => item.type === "function" && item.name === "previewPayFor").outputs;
351
+ // Only these reads of the router and core: their full ABIs would weigh on every pay card.
352
+ const routerConversionAbi = [
353
+ {
354
+ type: "function",
355
+ name: "projectIdOf",
356
+ stateMutability: "view",
357
+ inputs: [{ name: "token", type: "address" }],
358
+ outputs: [{ name: "", type: "uint256" }],
359
+ },
360
+ {
361
+ type: "function",
362
+ name: "primaryTerminalOf",
363
+ stateMutability: "view",
364
+ inputs: [
365
+ { name: "projectId", type: "uint256" },
366
+ { name: "token", type: "address" },
367
+ ],
368
+ outputs: [{ name: "", type: "address" }],
369
+ },
370
+ {
371
+ type: "function",
372
+ name: "previewTerminalPayOf",
373
+ stateMutability: "view",
374
+ inputs: [
375
+ { name: "destTerminal", type: "address" },
376
+ { name: "projectId", type: "uint256" },
377
+ { name: "token", type: "address" },
378
+ { name: "amount", type: "uint256" },
379
+ { name: "beneficiary", type: "address" },
380
+ { name: "metadata", type: "bytes" },
381
+ ],
382
+ outputs: previewPayForOutputs,
383
+ },
384
+ {
385
+ type: "function",
386
+ name: "wrappedNativeToken",
387
+ stateMutability: "view",
388
+ inputs: [],
389
+ outputs: [{ name: "", type: "address" }],
390
+ },
391
+ {
392
+ type: "function",
393
+ name: "previewSwapAmountOutOf",
394
+ stateMutability: "view",
395
+ inputs: [
396
+ { name: "tokenIn", type: "address" },
397
+ { name: "tokenOut", type: "address" },
398
+ { name: "amount", type: "uint256" },
399
+ { name: "metadata", type: "bytes" },
400
+ ],
401
+ outputs: [{ name: "amountOut", type: "uint256" }],
402
+ },
403
+ {
404
+ type: "function",
405
+ name: "discoverBestPool",
406
+ stateMutability: "view",
407
+ inputs: [
408
+ { name: "normalizedTokenIn", type: "address" },
409
+ { name: "normalizedTokenOut", type: "address" },
410
+ ],
411
+ outputs: [
412
+ {
413
+ name: "",
414
+ type: "tuple",
415
+ components: [
416
+ { name: "isV4", type: "bool" },
417
+ { name: "v3Pool", type: "address" },
418
+ {
419
+ name: "v4Key",
420
+ type: "tuple",
421
+ components: [
422
+ { name: "currency0", type: "address" },
423
+ { name: "currency1", type: "address" },
424
+ { name: "fee", type: "uint24" },
425
+ { name: "tickSpacing", type: "int24" },
426
+ { name: "hooks", type: "address" },
427
+ ],
428
+ },
429
+ ],
430
+ },
431
+ ],
432
+ },
433
+ ];
434
+ const v3PoolFeeAbi = [
435
+ {
436
+ type: "function",
437
+ name: "fee",
438
+ stateMutability: "view",
439
+ inputs: [],
440
+ outputs: [{ name: "", type: "uint24" }],
441
+ },
442
+ ];
443
+ /**
444
+ * What the router terminal's swap of the whole payment into `tokenOut` is
445
+ * quoted to return (fee and price impact included), and the floor it reverts
446
+ * below, from the pool the router picks. Null when the route is not that one
447
+ * swap, such as when the router cashes a project token out first.
448
+ */
449
+ async function routerConversionOf(client, { chainId, tokenIn, tokenOut, amount, }) {
450
+ const router = (0, types_js_1.v6Address)("JBRouterTerminal", chainId);
451
+ const [sourceProjectId, wrapped] = await Promise.all([
452
+ client.readContract({
453
+ address: (0, types_js_1.v6Address)("JBTokens", chainId),
454
+ abi: routerConversionAbi,
455
+ functionName: "projectIdOf",
456
+ args: [tokenIn],
457
+ }),
458
+ client.readContract({
459
+ address: router,
460
+ abi: routerConversionAbi,
461
+ functionName: "wrappedNativeToken",
462
+ }),
463
+ ]);
464
+ // The router cashes a project token out before any swap.
465
+ if (sourceProjectId !== 0n)
466
+ return null;
467
+ const isNative = (t) => t.toLowerCase() === constants_js_1.NATIVE_TOKEN.toLowerCase() ||
468
+ t.toLowerCase() === viem_1.zeroAddress;
469
+ const wrap = (t) => (isNative(t) ? wrapped : t);
470
+ const [floor, pool] = await Promise.all([
471
+ client.readContract({
472
+ address: router,
473
+ abi: routerConversionAbi,
474
+ functionName: "previewSwapAmountOutOf",
475
+ args: [tokenIn, tokenOut, amount, "0x"],
476
+ }),
477
+ client.readContract({
478
+ address: router,
479
+ abi: routerConversionAbi,
480
+ functionName: "discoverBestPool",
481
+ args: [wrap(tokenIn), wrap(tokenOut)],
482
+ }),
483
+ ]);
484
+ let expected;
485
+ if (pool.isV4) {
486
+ // V4 pools hold the native token itself, which the router uses for wrapped input.
487
+ const unwrap = (t) => wrap(t).toLowerCase() === wrapped.toLowerCase() ? viem_1.zeroAddress : t;
488
+ const zeroForOne = (0, uniswapV4_js_1.uniswapV4SwapDirection)({
489
+ poolKey: pool.v4Key,
490
+ tokenIn: unwrap(tokenIn),
491
+ tokenOut: unwrap(tokenOut),
492
+ });
493
+ if (zeroForOne === null)
494
+ return null;
495
+ expected = await (0, uniswapV4_js_1.quoteUniswapV4ExactInputSingle)(client, {
496
+ chainId,
497
+ poolKey: pool.v4Key,
498
+ zeroForOne,
499
+ amountIn: amount,
500
+ });
501
+ }
502
+ else {
503
+ expected = await (0, uniswapV3_js_1.quoteUniswapV3ExactInputSingle)(client, {
504
+ chainId,
505
+ tokenIn: wrap(tokenIn),
506
+ tokenOut: wrap(tokenOut),
507
+ fee: await client.readContract({
508
+ address: pool.v3Pool,
509
+ abi: v3PoolFeeAbi,
510
+ functionName: "fee",
511
+ }),
512
+ amountIn: amount,
513
+ });
514
+ }
515
+ return expected >= floor ? { expected, floor } : null;
516
+ }
517
+ /**
518
+ * The buyback spec the destination returns when the router's conversion
519
+ * returns what it is quoted to, and the router's floor. The hook's input is
520
+ * the conversion less anything taken before it, such as an NFT split, and the
521
+ * hook mints instead of swapping once minting that input reaches a fixed
522
+ * minimum, so the minimum is set from this spec. Null when the route is not
523
+ * one swap of the whole payment.
524
+ */
525
+ async function routedBuybackSpecOf(client, { chainId, projectId, tokenIn, tokenOut, amount, beneficiary, metadata, hook, reservedPercent, }) {
526
+ const conversion = await routerConversionOf(client, {
527
+ chainId,
528
+ tokenIn,
529
+ tokenOut,
530
+ amount,
531
+ });
532
+ if (!conversion)
533
+ return null;
534
+ const destination = await client.readContract({
535
+ address: (0, types_js_1.v6Address)("JBDirectory", chainId),
536
+ abi: routerConversionAbi,
537
+ functionName: "primaryTerminalOf",
538
+ args: [projectId, tokenOut],
539
+ });
540
+ const [, , , specs] = await client.readContract({
541
+ address: (0, types_js_1.v6Address)("JBRouterTerminal", chainId),
542
+ abi: routerConversionAbi,
543
+ functionName: "previewTerminalPayOf",
544
+ args: [
545
+ destination,
546
+ projectId,
547
+ tokenOut,
548
+ conversion.expected,
549
+ beneficiary,
550
+ metadata,
551
+ ],
552
+ });
553
+ const raw = specs.find((s) => s.hook.toLowerCase() === hook.toLowerCase());
554
+ const spec = raw && decodeBuybackPaySpec(raw, reservedPercent);
555
+ return spec ? { spec, floor: conversion.floor } : null;
556
+ }
315
557
  /**
316
558
  * Prepare a person's payment with {@link buildUserPayMetadata}: preview it,
317
559
  * and set the minimum the terminal enforces on the beneficiary's balance.
318
560
  *
319
- * When the project's buyback hook honors `skipSplits` and its pool is in the
320
- * paid token, this quotes that pool (fee and price impact included) and sends
321
- * the slippage-floored quote as an explicit minimum. The hook then swaps
322
- * whenever the pool beats the payer's share of a mint, and reverts below the
323
- * floor. Without it the hook routes by its TWAP floor, which reaches zero on
324
- * large buys against a thin pool and sends them to minting even when the pool
325
- * pays far more.
561
+ * When the project's buyback hook would swap, this quotes its pool (fee and
562
+ * price impact included) and sends the slippage-floored quote as an explicit
563
+ * minimum, so the payer gets the pool's rate whenever it
564
+ * beats minting. The hook compares that minimum to the swap output plus the
565
+ * leftover mint: the whole leftover mint when the swapped tokens go through
566
+ * the reserved split (`skipSplits` false, and always on hook 1.1.1, which
567
+ * ignores `skipSplits`), its beneficiary share when they skip it. The
568
+ * terminal minimum is the beneficiary's part of that guarantee, plus what the
569
+ * terminal issues itself (such as for NFT splits). The quoted payment is
570
+ * previewed again first, and stays on the mint path if the hook would not
571
+ * swap with that minimum. Without a quote the hook routes by its TWAP floor,
572
+ * which reaches zero on large buys against a thin pool and sends them to
573
+ * minting even when the pool pays far more.
574
+ *
575
+ * Behind a router terminal, its registry or its gateway, when the router
576
+ * converts the paid token first with one swap, the pool is the one in the
577
+ * token it converts to, quoted on what that swap is quoted to return. If the
578
+ * conversion returns noticeably less, the hook's minimum reverts the payment.
579
+ * If it returns more, the hook mints once minting reaches the minimum, which
580
+ * happens only when the pool beats minting by less than `slippageBps` plus
581
+ * that gain. The payer still receives at least the minimum, and no fixed
582
+ * minimum avoids this when the pool's edge is inside the conversion's
583
+ * uncertainty. Other routes, such as cashing a project token out first, keep
584
+ * the fallback.
326
585
  *
327
- * Otherwise (no pool, hook 1.1.1, a router converting the token first, or a
328
- * failed quote) the hook routes by TWAP. The minimum is then the payer's mint
586
+ * Otherwise (no pool, or a failed quote) the minimum is the payer's mint
329
587
  * entitlement when the hook would swap, since the hook never settles below it,
330
- * and the terminal's own issuance when it would not.
588
+ * and the terminal's own issuance when it would not. If the payment then
589
+ * reverts, {@link decodePayFailure} says why. To let the payer accept less,
590
+ * prepare again with a larger `slippageBps`: the hook's minimum is in the
591
+ * metadata, so lowering `minReturnedTokens` alone does not relax it.
331
592
  *
332
593
  * When the ruleset calls buyback hook 1.4 directly (or through the omnichain
333
594
  * deployer) instead of through the registry, the metadata is keyed to the hook,
334
595
  * which reads nothing else.
335
596
  *
336
597
  * @param args.slippageBps Tolerance on the pool quote and on the fallback
337
- * minimum. Defaults to 100 (1%).
598
+ * minimum. Defaults to {@link PAY_DEFAULT_SLIPPAGE_BPS}.
338
599
  * @param args.skipSplits Whether the beneficiary keeps the swapped tokens
339
600
  * without the reserved split. Defaults to true, as a person's pay card does;
340
601
  * pass false for payments that should honor the project's splits, such as
341
602
  * fees or revenue routed into a project.
342
603
  */
343
- async function prepareUserPay(client, { tiers, slippageBps = 100n, skipSplits = true, ...args }) {
604
+ async function prepareUserPay(client, { tiers, slippageBps = exports.PAY_DEFAULT_SLIPPAGE_BPS, skipSplits = true, ...args }) {
344
605
  const { chainId, projectId, token } = args;
345
606
  let metadata = buildUserPayMetadata({ chainId, tiers, skipSplits });
346
607
  let read = await readPay(client, { ...args, metadata });
@@ -362,47 +623,104 @@ async function prepareUserPay(client, { tiers, slippageBps = 100n, skipSplits =
362
623
  maxBigInt(mintEntitlementOf(buyback, weight) - 2n, 0n)
363
624
  : terminalBeneficiaryTokenCount, slippageBps),
364
625
  };
365
- if (!buyback?.skipSplits || buyback.amountToSwapWith === 0n)
626
+ if (!buyback || buyback.amountToSwapWith === 0n)
366
627
  return fallback;
367
628
  try {
368
- const poolKey = await client.readContract({
369
- address: buyback.hook,
370
- abi: poolKeyOfAbi,
371
- functionName: "poolKeyOf",
372
- args: [
373
- projectId,
374
- token.toLowerCase() === constants_js_1.NATIVE_TOKEN.toLowerCase()
375
- ? viem_1.zeroAddress
376
- : token,
377
- ],
629
+ const pool = await buybackPoolOf(client, {
630
+ chainId,
631
+ hook: buyback.hook,
632
+ projectId,
633
+ token,
634
+ poolId: buyback.poolId,
378
635
  });
379
- // A router converts the paid token first, so its pool is a different one.
380
- if ((0, uniswapV4_js_1.uniswapV4PoolId)(poolKey) !== buyback.poolId)
636
+ if (!pool)
381
637
  return fallback;
638
+ let swap = buyback;
639
+ if (pool.terminalToken !== token) {
640
+ // A router converts the payment first, and its preview gave the hook the
641
+ // router's slippage floor. A minimum quoted on that would let a normal
642
+ // conversion mint while the pool pays more, so quote what the hook
643
+ // receives when the conversion returns its quote. A conversion well
644
+ // below its quote then fails with a reason.
645
+ const routed = await routedBuybackSpecOf(client, {
646
+ chainId,
647
+ projectId,
648
+ tokenIn: token,
649
+ tokenOut: pool.terminalToken,
650
+ amount: args.amount,
651
+ beneficiary: args.beneficiary,
652
+ metadata,
653
+ hook: buyback.hook,
654
+ reservedPercent: buyback.reservedPercent,
655
+ });
656
+ // The floor preview must be this route's: no more than the floor reached the hook.
657
+ if (!routed ||
658
+ routed.floor < buyback.amountToSwapWith ||
659
+ routed.spec.poolId !== buyback.poolId) {
660
+ return fallback;
661
+ }
662
+ swap = routed.spec;
663
+ }
382
664
  const quote = await (0, uniswapV4_js_1.quoteUniswapV4ExactInputSingle)(client, {
383
665
  chainId,
384
- poolKey,
385
- zeroForOne: !buyback.projectTokenIs0,
386
- amountIn: buyback.amountToSwapWith,
666
+ poolKey: pool.key,
667
+ zeroForOne: !swap.projectTokenIs0,
668
+ amountIn: swap.amountToSwapWith,
387
669
  });
388
670
  const minimumSwapAmountOut = (0, cashOut_js_1.slippageFloor)(quote, slippageBps);
389
671
  // The pool loses to minting: leave the payment on the mint path.
390
- if (minimumSwapAmountOut <= buyback.tokenCountWithoutHook)
672
+ if (minimumSwapAmountOut <= swap.tokenCountWithoutHook)
391
673
  return fallback;
392
- const directMint = splitOf(directMintOf(buyback, weight), buyback.reservedPercent);
674
+ const quotedMetadata = buildUserPayMetadata({
675
+ chainId,
676
+ tiers,
677
+ minimumSwapAmountOut,
678
+ skipSplits,
679
+ ...(hook ? { hook } : {}),
680
+ });
681
+ // The hook rejects a minimum it cannot route, such as on a pool with no
682
+ // liquidity in range, and then the payment stays on the mint path.
683
+ const [, quotedBeneficiaryCount, quotedReservedCount, quotedSpecs] = await client.readContract({
684
+ address: args.terminal,
685
+ abi: juicebox_js_1.jbMultiTerminalAbi,
686
+ functionName: "previewPayFor",
687
+ args: [projectId, token, args.amount, args.beneficiary, quotedMetadata],
688
+ });
689
+ // It must still swap, and in the quoted pool: a router may pick another route.
690
+ const quotedSpec = quotedSpecs.find((s) => s.hook.toLowerCase() === buyback.hook.toLowerCase());
691
+ if (!quotedSpec ||
692
+ quotedSpec.noop ||
693
+ decodeBuybackPaySpec(quotedSpec, buyback.reservedPercent)?.poolId !==
694
+ buyback.poolId) {
695
+ return fallback;
696
+ }
697
+ // A router folds the hook's estimate into its counts, so only the
698
+ // multi-terminal's own counts are known to be its issuance.
699
+ const issuedByTerminal = args.terminal.toLowerCase() ===
700
+ (0, types_js_1.v6Address)("JBMultiTerminal", chainId).toLowerCase()
701
+ ? {
702
+ beneficiaryTokenCount: quotedBeneficiaryCount,
703
+ reservedTokenCount: quotedReservedCount,
704
+ }
705
+ : { beneficiaryTokenCount: 0n, reservedTokenCount: 0n };
706
+ const directMint = directMintOf(swap, weight);
707
+ // The swapped tokens skip the split, or are reminted through it with the
708
+ // direct mint. The terminal's own issuance, such as for NFT splits, adds.
709
+ const settle = (swapTokenCount) => {
710
+ const split = swap.skipSplits
711
+ ? splitOf(directMint, swap.reservedPercent)
712
+ : splitOf(swapTokenCount + directMint, swap.reservedPercent);
713
+ return {
714
+ beneficiaryTokenCount: (swap.skipSplits ? swapTokenCount : 0n) +
715
+ split.beneficiaryTokenCount +
716
+ issuedByTerminal.beneficiaryTokenCount,
717
+ reservedTokenCount: split.reservedTokenCount + issuedByTerminal.reservedTokenCount,
718
+ };
719
+ };
393
720
  return {
394
- metadata: buildUserPayMetadata({
395
- chainId,
396
- tiers,
397
- minimumSwapAmountOut,
398
- skipSplits,
399
- ...(hook ? { hook } : {}),
400
- }),
401
- preview: {
402
- beneficiaryTokenCount: quote + directMint.beneficiaryTokenCount,
403
- reservedTokenCount: directMint.reservedTokenCount,
404
- },
405
- minReturnedTokens: minimumSwapAmountOut,
721
+ metadata: quotedMetadata,
722
+ preview: settle(quote),
723
+ minReturnedTokens: settle(minimumSwapAmountOut).beneficiaryTokenCount,
406
724
  };
407
725
  }
408
726
  catch {