@pafi-dev/core 0.3.0-beta.0 → 0.3.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,84 +1,3 @@
1
- import { Address, Hex, PublicClient } from 'viem';
2
- import { Q as QuoteResult, e as PathKey } from '../types-BDOnH5Le.cjs';
3
-
4
- declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
5
- /**
6
- * Encode an ERC-20 approve(spender, amount) call.
7
- */
8
- declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
9
- /**
10
- * Encode a Permit2 approve(token, spender, amount, expiration) call.
11
- */
12
- declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
13
-
14
- /** UniversalRouter command byte for V4 swap */
15
- declare const V4_SWAP: 16;
16
- declare const SWAP_EXACT_IN: 7;
17
- declare const SETTLE_ALL: 12;
18
- declare const TAKE_ALL: 15;
19
- /**
20
- * Build the calldata inputs[0] (the V4_SWAP command payload) for
21
- * UniversalRouter.execute.
22
- *
23
- * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
24
- *
25
- * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
26
- * are individually ABI-encoded, then wrapped together with the action bytes.
27
- */
28
- declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
29
- /**
30
- * Build the full commands + inputs args for UniversalRouter.execute.
31
- */
32
- declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
33
- commands: Hex;
34
- inputs: Hex[];
35
- };
36
- /**
37
- * Build UniversalRouter execute args from a quote result.
38
- *
39
- * Takes the output of `findBestQuote` / `quoteBestRoute` and produces
40
- * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
41
- *
42
- * @param quote - Quote result containing the path
43
- * @param currencyIn - Input token address
44
- * @param currencyOut - Output token address
45
- * @param amountIn - Exact input amount (same value passed to the quoter)
46
- * @param minAmountOut - Minimum acceptable output (caller applies slippage)
47
- *
48
- * @deprecated Since v1.4 — the Issuer App no longer handles swaps.
49
- * For the new PT→USDT batch call on PAFI Web (Scenario 4 with
50
- * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).
51
- * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.
52
- */
53
- declare function buildSwapFromQuote(params: {
54
- quote: QuoteResult;
55
- currencyIn: Address;
56
- currencyOut: Address;
57
- amountIn: bigint;
58
- minAmountOut: bigint;
59
- }): {
60
- commands: Hex;
61
- inputs: Hex[];
62
- };
63
-
64
- interface SwapSimulationResult {
65
- success: boolean;
66
- gasEstimate: bigint;
67
- }
68
- /**
69
- * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
70
- *
71
- * Runs the full V4 swap flow — token transfer via Permit2, swap via
72
- * PoolManager, output settlement — without submitting a transaction.
73
- * If the simulation reverts, throws a `SimulationError` with the reason.
74
- *
75
- * @param client - viem PublicClient
76
- * @param routerAddress - UniversalRouter contract address
77
- * @param commands - Packed command bytes (from buildSwapFromQuote)
78
- * @param inputs - Encoded inputs per command (from buildSwapFromQuote)
79
- * @param deadline - Unix timestamp after which the tx expires
80
- * @param from - Address that will execute the swap
81
- */
82
- declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
83
-
84
- export { SETTLE_ALL, SWAP_EXACT_IN, type SwapSimulationResult, TAKE_ALL, V4_SWAP, buildErc20ApprovalCalldata, buildPermit2ApprovalCalldata, buildSwapFromQuote, buildUniversalRouterExecuteArgs, buildV4SwapInput, checkAllowance, simulateSwap };
1
+ export { B as BuildSwapWithGasDeductionParams, b as SETTLE_ALL, c as SWAP_EXACT_IN, S as SwapSimulationResult, T as TAKE_ALL, V as V4_SWAP, e as buildErc20ApprovalCalldata, f as buildPermit2ApprovalCalldata, g as buildSwapFromQuote, h as buildSwapWithGasDeduction, i as buildUniversalRouterExecuteArgs, j as buildV4SwapInput, k as checkAllowance, s as simulateSwap } from '../index-BpUYHGu3.cjs';
2
+ import 'viem';
3
+ import '../types-BDOnH5Le.cjs';
@@ -1,84 +1,3 @@
1
- import { Address, Hex, PublicClient } from 'viem';
2
- import { Q as QuoteResult, e as PathKey } from '../types-BDOnH5Le.js';
3
-
4
- declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
5
- /**
6
- * Encode an ERC-20 approve(spender, amount) call.
7
- */
8
- declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
9
- /**
10
- * Encode a Permit2 approve(token, spender, amount, expiration) call.
11
- */
12
- declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
13
-
14
- /** UniversalRouter command byte for V4 swap */
15
- declare const V4_SWAP: 16;
16
- declare const SWAP_EXACT_IN: 7;
17
- declare const SETTLE_ALL: 12;
18
- declare const TAKE_ALL: 15;
19
- /**
20
- * Build the calldata inputs[0] (the V4_SWAP command payload) for
21
- * UniversalRouter.execute.
22
- *
23
- * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
24
- *
25
- * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
26
- * are individually ABI-encoded, then wrapped together with the action bytes.
27
- */
28
- declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
29
- /**
30
- * Build the full commands + inputs args for UniversalRouter.execute.
31
- */
32
- declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
33
- commands: Hex;
34
- inputs: Hex[];
35
- };
36
- /**
37
- * Build UniversalRouter execute args from a quote result.
38
- *
39
- * Takes the output of `findBestQuote` / `quoteBestRoute` and produces
40
- * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
41
- *
42
- * @param quote - Quote result containing the path
43
- * @param currencyIn - Input token address
44
- * @param currencyOut - Output token address
45
- * @param amountIn - Exact input amount (same value passed to the quoter)
46
- * @param minAmountOut - Minimum acceptable output (caller applies slippage)
47
- *
48
- * @deprecated Since v1.4 — the Issuer App no longer handles swaps.
49
- * For the new PT→USDT batch call on PAFI Web (Scenario 4 with
50
- * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).
51
- * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.
52
- */
53
- declare function buildSwapFromQuote(params: {
54
- quote: QuoteResult;
55
- currencyIn: Address;
56
- currencyOut: Address;
57
- amountIn: bigint;
58
- minAmountOut: bigint;
59
- }): {
60
- commands: Hex;
61
- inputs: Hex[];
62
- };
63
-
64
- interface SwapSimulationResult {
65
- success: boolean;
66
- gasEstimate: bigint;
67
- }
68
- /**
69
- * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
70
- *
71
- * Runs the full V4 swap flow — token transfer via Permit2, swap via
72
- * PoolManager, output settlement — without submitting a transaction.
73
- * If the simulation reverts, throws a `SimulationError` with the reason.
74
- *
75
- * @param client - viem PublicClient
76
- * @param routerAddress - UniversalRouter contract address
77
- * @param commands - Packed command bytes (from buildSwapFromQuote)
78
- * @param inputs - Encoded inputs per command (from buildSwapFromQuote)
79
- * @param deadline - Unix timestamp after which the tx expires
80
- * @param from - Address that will execute the swap
81
- */
82
- declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
83
-
84
- export { SETTLE_ALL, SWAP_EXACT_IN, type SwapSimulationResult, TAKE_ALL, V4_SWAP, buildErc20ApprovalCalldata, buildPermit2ApprovalCalldata, buildSwapFromQuote, buildUniversalRouterExecuteArgs, buildV4SwapInput, checkAllowance, simulateSwap };
1
+ export { B as BuildSwapWithGasDeductionParams, b as SETTLE_ALL, c as SWAP_EXACT_IN, S as SwapSimulationResult, T as TAKE_ALL, V as V4_SWAP, e as buildErc20ApprovalCalldata, f as buildPermit2ApprovalCalldata, g as buildSwapFromQuote, h as buildSwapWithGasDeduction, i as buildUniversalRouterExecuteArgs, j as buildV4SwapInput, k as checkAllowance, s as simulateSwap } from '../index-CNALKsH1.js';
2
+ import 'viem';
3
+ import '../types-BDOnH5Le.js';
@@ -6,11 +6,12 @@ import {
6
6
  buildErc20ApprovalCalldata,
7
7
  buildPermit2ApprovalCalldata,
8
8
  buildSwapFromQuote,
9
+ buildSwapWithGasDeduction,
9
10
  buildUniversalRouterExecuteArgs,
10
11
  buildV4SwapInput,
11
12
  checkAllowance,
12
13
  simulateSwap
13
- } from "../chunk-UU72CX7E.js";
14
+ } from "../chunk-IK4UK7KT.js";
14
15
  import "../chunk-2PIXFXA2.js";
15
16
  import "../chunk-P56TUGTS.js";
16
17
  export {
@@ -21,6 +22,7 @@ export {
21
22
  buildErc20ApprovalCalldata,
22
23
  buildPermit2ApprovalCalldata,
23
24
  buildSwapFromQuote,
25
+ buildSwapWithGasDeduction,
24
26
  buildUniversalRouterExecuteArgs,
25
27
  buildV4SwapInput,
26
28
  checkAllowance,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pafi-dev/core",
3
- "version": "0.3.0-beta.0",
3
+ "version": "0.3.0-beta.2",
4
4
  "description": "EIP-712 signing, contract interaction, and Relay calldata for the PAFI point token system",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1,149 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
- var _chunkIPXARZ6Fcjs = require('./chunk-IPXARZ6F.cjs');
6
-
7
-
8
- var _chunk5QJZT7VBcjs = require('./chunk-5QJZT7VB.cjs');
9
-
10
- // src/swap/approval.ts
11
- var _viem = require('viem');
12
- async function checkAllowance(client, token, owner, spender) {
13
- return client.readContract({
14
- address: token,
15
- abi: _chunkIPXARZ6Fcjs.erc20Abi,
16
- functionName: "allowance",
17
- args: [owner, spender]
18
- });
19
- }
20
- function buildErc20ApprovalCalldata(spender, amount) {
21
- return _viem.encodeFunctionData.call(void 0, {
22
- abi: _chunkIPXARZ6Fcjs.erc20Abi,
23
- functionName: "approve",
24
- args: [spender, amount]
25
- });
26
- }
27
- function buildPermit2ApprovalCalldata(token, spender, amount, expiration) {
28
- return _viem.encodeFunctionData.call(void 0, {
29
- abi: _chunkIPXARZ6Fcjs.permit2Abi,
30
- functionName: "approve",
31
- args: [token, spender, amount, expiration]
32
- });
33
- }
34
-
35
- // src/swap/universalRouter.ts
36
-
37
- var V4_SWAP = 16;
38
- var SWAP_EXACT_IN = 7;
39
- var SETTLE_ALL = 12;
40
- var TAKE_ALL = 15;
41
- var PATH_KEY_ABI_COMPONENTS = [
42
- { name: "intermediateCurrency", type: "address" },
43
- { name: "fee", type: "uint256" },
44
- { name: "tickSpacing", type: "int24" },
45
- { name: "hooks", type: "address" },
46
- { name: "hookData", type: "bytes" }
47
- ];
48
- var EXACT_INPUT_PARAMS_ABI = [
49
- { name: "currencyIn", type: "address" },
50
- {
51
- name: "path",
52
- type: "tuple[]",
53
- components: PATH_KEY_ABI_COMPONENTS
54
- },
55
- { name: "amountIn", type: "uint128" },
56
- { name: "amountOutMinimum", type: "uint128" }
57
- ];
58
- function buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency) {
59
- const actions = _viem.encodePacked.call(void 0,
60
- ["uint8", "uint8", "uint8"],
61
- [SWAP_EXACT_IN, SETTLE_ALL, TAKE_ALL]
62
- );
63
- const swapParam = _viem.encodeAbiParameters.call(void 0,
64
- [{ name: "swap", type: "tuple", components: EXACT_INPUT_PARAMS_ABI }],
65
- [
66
- {
67
- currencyIn,
68
- path: path.map((p) => ({
69
- intermediateCurrency: p.intermediateCurrency,
70
- fee: BigInt(p.fee),
71
- tickSpacing: p.tickSpacing,
72
- hooks: p.hooks,
73
- hookData: p.hookData
74
- })),
75
- amountIn,
76
- amountOutMinimum: minAmountOut
77
- }
78
- ]
79
- );
80
- const settleParam = _viem.encodeAbiParameters.call(void 0,
81
- [
82
- { name: "currency", type: "address" },
83
- { name: "maxAmount", type: "uint256" }
84
- ],
85
- [currencyIn, amountIn]
86
- );
87
- const takeParam = _viem.encodeAbiParameters.call(void 0,
88
- [
89
- { name: "currency", type: "address" },
90
- { name: "minAmount", type: "uint256" }
91
- ],
92
- [outputCurrency, minAmountOut]
93
- );
94
- return _viem.encodeAbiParameters.call(void 0,
95
- [
96
- { name: "actions", type: "bytes" },
97
- { name: "params", type: "bytes[]" }
98
- ],
99
- [actions, [swapParam, settleParam, takeParam]]
100
- );
101
- }
102
- function buildUniversalRouterExecuteArgs(currencyIn, path, amountIn, minAmountOut, outputCurrency) {
103
- const commands = _viem.encodePacked.call(void 0, ["uint8"], [V4_SWAP]);
104
- const inputs = [
105
- buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency)
106
- ];
107
- return { commands, inputs };
108
- }
109
- function buildSwapFromQuote(params) {
110
- return buildUniversalRouterExecuteArgs(
111
- params.currencyIn,
112
- params.quote.path,
113
- params.amountIn,
114
- params.minAmountOut,
115
- params.currencyOut
116
- );
117
- }
118
-
119
- // src/swap/simulate.ts
120
- async function simulateSwap(client, routerAddress, commands, inputs, deadline, from) {
121
- try {
122
- const gasEstimate = await client.estimateContractGas({
123
- address: routerAddress,
124
- abi: _chunkIPXARZ6Fcjs.universalRouterAbi,
125
- functionName: "execute",
126
- args: [commands, inputs, deadline],
127
- account: from
128
- });
129
- return { success: true, gasEstimate };
130
- } catch (error) {
131
- const message = error instanceof Error ? error.message : "Unknown simulation error";
132
- throw new (0, _chunk5QJZT7VBcjs.SimulationError)("swap", message);
133
- }
134
- }
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
- exports.checkAllowance = checkAllowance; exports.buildErc20ApprovalCalldata = buildErc20ApprovalCalldata; exports.buildPermit2ApprovalCalldata = buildPermit2ApprovalCalldata; exports.V4_SWAP = V4_SWAP; exports.SWAP_EXACT_IN = SWAP_EXACT_IN; exports.SETTLE_ALL = SETTLE_ALL; exports.TAKE_ALL = TAKE_ALL; exports.buildV4SwapInput = buildV4SwapInput; exports.buildUniversalRouterExecuteArgs = buildUniversalRouterExecuteArgs; exports.buildSwapFromQuote = buildSwapFromQuote; exports.simulateSwap = simulateSwap;
149
- //# sourceMappingURL=chunk-6I6K43RQ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-6I6K43RQ.cjs","../src/swap/approval.ts","../src/swap/universalRouter.ts","../src/swap/simulate.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACTA,4BAAmC;AAKnC,MAAA,SAAsB,cAAA,CACpB,MAAA,EACA,KAAA,EACA,KAAA,EACA,OAAA,EACiB;AACjB,EAAA,OAAO,MAAA,CAAO,YAAA,CAAa;AAAA,IACzB,OAAA,EAAS,KAAA;AAAA,IACT,GAAA,EAAK,0BAAA;AAAA,IACL,YAAA,EAAc,WAAA;AAAA,IACd,IAAA,EAAM,CAAC,KAAA,EAAO,OAAO;AAAA,EACvB,CAAC,CAAA;AACH;AAKO,SAAS,0BAAA,CACd,OAAA,EACA,MAAA,EACK;AACL,EAAA,OAAO,sCAAA;AAAmB,IACxB,GAAA,EAAK,0BAAA;AAAA,IACL,YAAA,EAAc,SAAA;AAAA,IACd,IAAA,EAAM,CAAC,OAAA,EAAS,MAAM;AAAA,EACxB,CAAC,CAAA;AACH;AAKO,SAAS,4BAAA,CACd,KAAA,EACA,OAAA,EACA,MAAA,EACA,UAAA,EACK;AACL,EAAA,OAAO,sCAAA;AAAmB,IACxB,GAAA,EAAK,4BAAA;AAAA,IACL,YAAA,EAAc,SAAA;AAAA,IACd,IAAA,EAAM,CAAC,KAAA,EAAO,OAAA,EA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AM,IAAI,sCAAA,CAAgB,MAAA,EAAQ,OAAO,CAAA;AAAA,EAC3C;AACF;AHwFA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,4fAAC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-6I6K43RQ.cjs","sourcesContent":[null,"import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex, PublicClient } from \"viem\";\nimport { erc20Abi } from \"../abi/erc20\";\nimport { permit2Abi } from \"../abi/permit2\";\n\nexport async function checkAllowance(\n client: PublicClient,\n token: Address,\n owner: Address,\n spender: Address,\n): Promise<bigint> {\n return client.readContract({\n address: token,\n abi: erc20Abi,\n functionName: \"allowance\",\n args: [owner, spender],\n });\n}\n\n/**\n * Encode an ERC-20 approve(spender, amount) call.\n */\nexport function buildErc20ApprovalCalldata(\n spender: Address,\n amount: bigint,\n): Hex {\n return encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n });\n}\n\n/**\n * Encode a Permit2 approve(token, spender, amount, expiration) call.\n */\nexport function buildPermit2ApprovalCalldata(\n token: Address,\n spender: Address,\n amount: bigint,\n expiration: number,\n): Hex {\n return encodeFunctionData({\n abi: permit2Abi,\n functionName: \"approve\",\n args: [token, spender, amount, expiration],\n });\n}\n","import { encodeAbiParameters, encodePacked } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport type { PathKey, QuoteResult } from \"../types\";\n\n// -------------------------------------------------------------------------\n// V4 UniversalRouter command / action constants\n// Reference: https://github.com/Uniswap/v4-periphery/blob/main/src/libraries/Actions.sol\n// -------------------------------------------------------------------------\n\n/** UniversalRouter command byte for V4 swap */\nexport const V4_SWAP = 0x10 as const;\n\n/** V4 actions */\nexport const SWAP_EXACT_IN_SINGLE = 0x06 as const;\nexport const SWAP_EXACT_IN = 0x07 as const;\nexport const SETTLE_ALL = 0x0c as const;\nexport const TAKE_ALL = 0x0f as const;\n\n// -------------------------------------------------------------------------\n// ABI type strings matching Uniswap's V4Planner encoding\n// Reference: https://github.com/Uniswap/sdks/blob/main/sdks/v4-sdk/src/utils/v4Planner.ts\n//\n// IMPORTANT: PathKey.fee is uint256 in the V4 Router ABI (not uint24).\n// -------------------------------------------------------------------------\n\n// PathKey components for V4 Router ABI encoding.\n// IMPORTANT: fee is uint256 in the V4 Router (not uint24 as in PoolKey).\n// Reference: https://github.com/Uniswap/sdks/blob/main/sdks/v4-sdk/src/utils/v4Planner.ts\nconst PATH_KEY_ABI_COMPONENTS = [\n { name: \"intermediateCurrency\", type: \"address\" },\n { name: \"fee\", type: \"uint256\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n { name: \"hookData\", type: \"bytes\" },\n] as const;\n\nconst EXACT_INPUT_PARAMS_ABI = [\n { name: \"currencyIn\", type: \"address\" },\n {\n name: \"path\",\n type: \"tuple[]\",\n components: PATH_KEY_ABI_COMPONENTS,\n },\n { name: \"amountIn\", type: \"uint128\" },\n { name: \"amountOutMinimum\", type: \"uint128\" },\n] as const;\n\n/**\n * Build the calldata inputs[0] (the V4_SWAP command payload) for\n * UniversalRouter.execute.\n *\n * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL\n *\n * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params\n * are individually ABI-encoded, then wrapped together with the action bytes.\n */\nexport function buildV4SwapInput(\n currencyIn: Address,\n path: PathKey[],\n amountIn: bigint,\n minAmountOut: bigint,\n outputCurrency: Address,\n): Hex {\n const actions = encodePacked(\n [\"uint8\", \"uint8\", \"uint8\"],\n [SWAP_EXACT_IN, SETTLE_ALL, TAKE_ALL],\n );\n\n // Param 0: ExactInputParams — encoded as a single tuple so the CalldataDecoder\n // can locate it via a single offset pointer. fee is uint256 per V4 Router spec.\n const swapParam = encodeAbiParameters(\n [{ name: \"swap\", type: \"tuple\", components: EXACT_INPUT_PARAMS_ABI }],\n [\n {\n currencyIn,\n path: path.map((p) => ({\n intermediateCurrency: p.intermediateCurrency,\n fee: BigInt(p.fee),\n tickSpacing: p.tickSpacing,\n hooks: p.hooks,\n hookData: p.hookData,\n })),\n amountIn,\n amountOutMinimum: minAmountOut,\n },\n ],\n );\n\n // Param 1: SETTLE_ALL { currency, maxAmount }\n const settleParam = encodeAbiParameters(\n [\n { name: \"currency\", type: \"address\" },\n { name: \"maxAmount\", type: \"uint256\" },\n ],\n [currencyIn, amountIn],\n );\n\n // Param 2: TAKE_ALL { currency, minAmount }\n const takeParam = encodeAbiParameters(\n [\n { name: \"currency\", type: \"address\" },\n { name: \"minAmount\", type: \"uint256\" },\n ],\n [outputCurrency, minAmountOut],\n );\n\n return encodeAbiParameters(\n [\n { name: \"actions\", type: \"bytes\" },\n { name: \"params\", type: \"bytes[]\" },\n ],\n [actions, [swapParam, settleParam, takeParam]],\n );\n}\n\n/**\n * Build the full commands + inputs args for UniversalRouter.execute.\n */\nexport function buildUniversalRouterExecuteArgs(\n currencyIn: Address,\n path: PathKey[],\n amountIn: bigint,\n minAmountOut: bigint,\n outputCurrency: Address,\n): { commands: Hex; inputs: Hex[] } {\n const commands = encodePacked([\"uint8\"], [V4_SWAP]);\n const inputs: Hex[] = [\n buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency),\n ];\n return { commands, inputs };\n}\n\n/**\n * Build UniversalRouter execute args from a quote result.\n *\n * Takes the output of `findBestQuote` / `quoteBestRoute` and produces\n * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.\n *\n * @param quote - Quote result containing the path\n * @param currencyIn - Input token address\n * @param currencyOut - Output token address\n * @param amountIn - Exact input amount (same value passed to the quoter)\n * @param minAmountOut - Minimum acceptable output (caller applies slippage)\n *\n * @deprecated Since v1.4 — the Issuer App no longer handles swaps.\n * For the new PT→USDT batch call on PAFI Web (Scenario 4 with\n * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).\n * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.\n */\nexport function buildSwapFromQuote(params: {\n quote: QuoteResult;\n currencyIn: Address;\n currencyOut: Address;\n amountIn: bigint;\n minAmountOut: bigint;\n}): { commands: Hex; inputs: Hex[] } {\n return buildUniversalRouterExecuteArgs(\n params.currencyIn,\n params.quote.path,\n params.amountIn,\n params.minAmountOut,\n params.currencyOut,\n );\n}\n","import type { Address, Hex, PublicClient } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport { SimulationError } from \"../errors\";\n\nexport interface SwapSimulationResult {\n success: boolean;\n gasEstimate: bigint;\n}\n\n/**\n * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).\n *\n * Runs the full V4 swap flow — token transfer via Permit2, swap via\n * PoolManager, output settlement — without submitting a transaction.\n * If the simulation reverts, throws a `SimulationError` with the reason.\n *\n * @param client - viem PublicClient\n * @param routerAddress - UniversalRouter contract address\n * @param commands - Packed command bytes (from buildSwapFromQuote)\n * @param inputs - Encoded inputs per command (from buildSwapFromQuote)\n * @param deadline - Unix timestamp after which the tx expires\n * @param from - Address that will execute the swap\n */\nexport async function simulateSwap(\n client: PublicClient,\n routerAddress: Address,\n commands: Hex,\n inputs: Hex[],\n deadline: bigint,\n from: Address,\n): Promise<SwapSimulationResult> {\n try {\n const gasEstimate = await client.estimateContractGas({\n address: routerAddress,\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, deadline],\n account: from,\n });\n\n return { success: true, gasEstimate };\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : \"Unknown simulation error\";\n throw new SimulationError(\"swap\", message);\n }\n}\n"]}
@@ -1,149 +0,0 @@
1
- import {
2
- erc20Abi,
3
- permit2Abi,
4
- universalRouterAbi
5
- } from "./chunk-2PIXFXA2.js";
6
- import {
7
- SimulationError
8
- } from "./chunk-P56TUGTS.js";
9
-
10
- // src/swap/approval.ts
11
- import { encodeFunctionData } from "viem";
12
- async function checkAllowance(client, token, owner, spender) {
13
- return client.readContract({
14
- address: token,
15
- abi: erc20Abi,
16
- functionName: "allowance",
17
- args: [owner, spender]
18
- });
19
- }
20
- function buildErc20ApprovalCalldata(spender, amount) {
21
- return encodeFunctionData({
22
- abi: erc20Abi,
23
- functionName: "approve",
24
- args: [spender, amount]
25
- });
26
- }
27
- function buildPermit2ApprovalCalldata(token, spender, amount, expiration) {
28
- return encodeFunctionData({
29
- abi: permit2Abi,
30
- functionName: "approve",
31
- args: [token, spender, amount, expiration]
32
- });
33
- }
34
-
35
- // src/swap/universalRouter.ts
36
- import { encodeAbiParameters, encodePacked } from "viem";
37
- var V4_SWAP = 16;
38
- var SWAP_EXACT_IN = 7;
39
- var SETTLE_ALL = 12;
40
- var TAKE_ALL = 15;
41
- var PATH_KEY_ABI_COMPONENTS = [
42
- { name: "intermediateCurrency", type: "address" },
43
- { name: "fee", type: "uint256" },
44
- { name: "tickSpacing", type: "int24" },
45
- { name: "hooks", type: "address" },
46
- { name: "hookData", type: "bytes" }
47
- ];
48
- var EXACT_INPUT_PARAMS_ABI = [
49
- { name: "currencyIn", type: "address" },
50
- {
51
- name: "path",
52
- type: "tuple[]",
53
- components: PATH_KEY_ABI_COMPONENTS
54
- },
55
- { name: "amountIn", type: "uint128" },
56
- { name: "amountOutMinimum", type: "uint128" }
57
- ];
58
- function buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency) {
59
- const actions = encodePacked(
60
- ["uint8", "uint8", "uint8"],
61
- [SWAP_EXACT_IN, SETTLE_ALL, TAKE_ALL]
62
- );
63
- const swapParam = encodeAbiParameters(
64
- [{ name: "swap", type: "tuple", components: EXACT_INPUT_PARAMS_ABI }],
65
- [
66
- {
67
- currencyIn,
68
- path: path.map((p) => ({
69
- intermediateCurrency: p.intermediateCurrency,
70
- fee: BigInt(p.fee),
71
- tickSpacing: p.tickSpacing,
72
- hooks: p.hooks,
73
- hookData: p.hookData
74
- })),
75
- amountIn,
76
- amountOutMinimum: minAmountOut
77
- }
78
- ]
79
- );
80
- const settleParam = encodeAbiParameters(
81
- [
82
- { name: "currency", type: "address" },
83
- { name: "maxAmount", type: "uint256" }
84
- ],
85
- [currencyIn, amountIn]
86
- );
87
- const takeParam = encodeAbiParameters(
88
- [
89
- { name: "currency", type: "address" },
90
- { name: "minAmount", type: "uint256" }
91
- ],
92
- [outputCurrency, minAmountOut]
93
- );
94
- return encodeAbiParameters(
95
- [
96
- { name: "actions", type: "bytes" },
97
- { name: "params", type: "bytes[]" }
98
- ],
99
- [actions, [swapParam, settleParam, takeParam]]
100
- );
101
- }
102
- function buildUniversalRouterExecuteArgs(currencyIn, path, amountIn, minAmountOut, outputCurrency) {
103
- const commands = encodePacked(["uint8"], [V4_SWAP]);
104
- const inputs = [
105
- buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency)
106
- ];
107
- return { commands, inputs };
108
- }
109
- function buildSwapFromQuote(params) {
110
- return buildUniversalRouterExecuteArgs(
111
- params.currencyIn,
112
- params.quote.path,
113
- params.amountIn,
114
- params.minAmountOut,
115
- params.currencyOut
116
- );
117
- }
118
-
119
- // src/swap/simulate.ts
120
- async function simulateSwap(client, routerAddress, commands, inputs, deadline, from) {
121
- try {
122
- const gasEstimate = await client.estimateContractGas({
123
- address: routerAddress,
124
- abi: universalRouterAbi,
125
- functionName: "execute",
126
- args: [commands, inputs, deadline],
127
- account: from
128
- });
129
- return { success: true, gasEstimate };
130
- } catch (error) {
131
- const message = error instanceof Error ? error.message : "Unknown simulation error";
132
- throw new SimulationError("swap", message);
133
- }
134
- }
135
-
136
- export {
137
- checkAllowance,
138
- buildErc20ApprovalCalldata,
139
- buildPermit2ApprovalCalldata,
140
- V4_SWAP,
141
- SWAP_EXACT_IN,
142
- SETTLE_ALL,
143
- TAKE_ALL,
144
- buildV4SwapInput,
145
- buildUniversalRouterExecuteArgs,
146
- buildSwapFromQuote,
147
- simulateSwap
148
- };
149
- //# sourceMappingURL=chunk-UU72CX7E.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/swap/approval.ts","../src/swap/universalRouter.ts","../src/swap/simulate.ts"],"sourcesContent":["import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex, PublicClient } from \"viem\";\nimport { erc20Abi } from \"../abi/erc20\";\nimport { permit2Abi } from \"../abi/permit2\";\n\nexport async function checkAllowance(\n client: PublicClient,\n token: Address,\n owner: Address,\n spender: Address,\n): Promise<bigint> {\n return client.readContract({\n address: token,\n abi: erc20Abi,\n functionName: \"allowance\",\n args: [owner, spender],\n });\n}\n\n/**\n * Encode an ERC-20 approve(spender, amount) call.\n */\nexport function buildErc20ApprovalCalldata(\n spender: Address,\n amount: bigint,\n): Hex {\n return encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n });\n}\n\n/**\n * Encode a Permit2 approve(token, spender, amount, expiration) call.\n */\nexport function buildPermit2ApprovalCalldata(\n token: Address,\n spender: Address,\n amount: bigint,\n expiration: number,\n): Hex {\n return encodeFunctionData({\n abi: permit2Abi,\n functionName: \"approve\",\n args: [token, spender, amount, expiration],\n });\n}\n","import { encodeAbiParameters, encodePacked } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport type { PathKey, QuoteResult } from \"../types\";\n\n// -------------------------------------------------------------------------\n// V4 UniversalRouter command / action constants\n// Reference: https://github.com/Uniswap/v4-periphery/blob/main/src/libraries/Actions.sol\n// -------------------------------------------------------------------------\n\n/** UniversalRouter command byte for V4 swap */\nexport const V4_SWAP = 0x10 as const;\n\n/** V4 actions */\nexport const SWAP_EXACT_IN_SINGLE = 0x06 as const;\nexport const SWAP_EXACT_IN = 0x07 as const;\nexport const SETTLE_ALL = 0x0c as const;\nexport const TAKE_ALL = 0x0f as const;\n\n// -------------------------------------------------------------------------\n// ABI type strings matching Uniswap's V4Planner encoding\n// Reference: https://github.com/Uniswap/sdks/blob/main/sdks/v4-sdk/src/utils/v4Planner.ts\n//\n// IMPORTANT: PathKey.fee is uint256 in the V4 Router ABI (not uint24).\n// -------------------------------------------------------------------------\n\n// PathKey components for V4 Router ABI encoding.\n// IMPORTANT: fee is uint256 in the V4 Router (not uint24 as in PoolKey).\n// Reference: https://github.com/Uniswap/sdks/blob/main/sdks/v4-sdk/src/utils/v4Planner.ts\nconst PATH_KEY_ABI_COMPONENTS = [\n { name: \"intermediateCurrency\", type: \"address\" },\n { name: \"fee\", type: \"uint256\" },\n { name: \"tickSpacing\", type: \"int24\" },\n { name: \"hooks\", type: \"address\" },\n { name: \"hookData\", type: \"bytes\" },\n] as const;\n\nconst EXACT_INPUT_PARAMS_ABI = [\n { name: \"currencyIn\", type: \"address\" },\n {\n name: \"path\",\n type: \"tuple[]\",\n components: PATH_KEY_ABI_COMPONENTS,\n },\n { name: \"amountIn\", type: \"uint128\" },\n { name: \"amountOutMinimum\", type: \"uint128\" },\n] as const;\n\n/**\n * Build the calldata inputs[0] (the V4_SWAP command payload) for\n * UniversalRouter.execute.\n *\n * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL\n *\n * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params\n * are individually ABI-encoded, then wrapped together with the action bytes.\n */\nexport function buildV4SwapInput(\n currencyIn: Address,\n path: PathKey[],\n amountIn: bigint,\n minAmountOut: bigint,\n outputCurrency: Address,\n): Hex {\n const actions = encodePacked(\n [\"uint8\", \"uint8\", \"uint8\"],\n [SWAP_EXACT_IN, SETTLE_ALL, TAKE_ALL],\n );\n\n // Param 0: ExactInputParams — encoded as a single tuple so the CalldataDecoder\n // can locate it via a single offset pointer. fee is uint256 per V4 Router spec.\n const swapParam = encodeAbiParameters(\n [{ name: \"swap\", type: \"tuple\", components: EXACT_INPUT_PARAMS_ABI }],\n [\n {\n currencyIn,\n path: path.map((p) => ({\n intermediateCurrency: p.intermediateCurrency,\n fee: BigInt(p.fee),\n tickSpacing: p.tickSpacing,\n hooks: p.hooks,\n hookData: p.hookData,\n })),\n amountIn,\n amountOutMinimum: minAmountOut,\n },\n ],\n );\n\n // Param 1: SETTLE_ALL { currency, maxAmount }\n const settleParam = encodeAbiParameters(\n [\n { name: \"currency\", type: \"address\" },\n { name: \"maxAmount\", type: \"uint256\" },\n ],\n [currencyIn, amountIn],\n );\n\n // Param 2: TAKE_ALL { currency, minAmount }\n const takeParam = encodeAbiParameters(\n [\n { name: \"currency\", type: \"address\" },\n { name: \"minAmount\", type: \"uint256\" },\n ],\n [outputCurrency, minAmountOut],\n );\n\n return encodeAbiParameters(\n [\n { name: \"actions\", type: \"bytes\" },\n { name: \"params\", type: \"bytes[]\" },\n ],\n [actions, [swapParam, settleParam, takeParam]],\n );\n}\n\n/**\n * Build the full commands + inputs args for UniversalRouter.execute.\n */\nexport function buildUniversalRouterExecuteArgs(\n currencyIn: Address,\n path: PathKey[],\n amountIn: bigint,\n minAmountOut: bigint,\n outputCurrency: Address,\n): { commands: Hex; inputs: Hex[] } {\n const commands = encodePacked([\"uint8\"], [V4_SWAP]);\n const inputs: Hex[] = [\n buildV4SwapInput(currencyIn, path, amountIn, minAmountOut, outputCurrency),\n ];\n return { commands, inputs };\n}\n\n/**\n * Build UniversalRouter execute args from a quote result.\n *\n * Takes the output of `findBestQuote` / `quoteBestRoute` and produces\n * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.\n *\n * @param quote - Quote result containing the path\n * @param currencyIn - Input token address\n * @param currencyOut - Output token address\n * @param amountIn - Exact input amount (same value passed to the quoter)\n * @param minAmountOut - Minimum acceptable output (caller applies slippage)\n *\n * @deprecated Since v1.4 — the Issuer App no longer handles swaps.\n * For the new PT→USDT batch call on PAFI Web (Scenario 4 with\n * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).\n * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.\n */\nexport function buildSwapFromQuote(params: {\n quote: QuoteResult;\n currencyIn: Address;\n currencyOut: Address;\n amountIn: bigint;\n minAmountOut: bigint;\n}): { commands: Hex; inputs: Hex[] } {\n return buildUniversalRouterExecuteArgs(\n params.currencyIn,\n params.quote.path,\n params.amountIn,\n params.minAmountOut,\n params.currencyOut,\n );\n}\n","import type { Address, Hex, PublicClient } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport { SimulationError } from \"../errors\";\n\nexport interface SwapSimulationResult {\n success: boolean;\n gasEstimate: bigint;\n}\n\n/**\n * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).\n *\n * Runs the full V4 swap flow — token transfer via Permit2, swap via\n * PoolManager, output settlement — without submitting a transaction.\n * If the simulation reverts, throws a `SimulationError` with the reason.\n *\n * @param client - viem PublicClient\n * @param routerAddress - UniversalRouter contract address\n * @param commands - Packed command bytes (from buildSwapFromQuote)\n * @param inputs - Encoded inputs per command (from buildSwapFromQuote)\n * @param deadline - Unix timestamp after which the tx expires\n * @param from - Address that will execute the swap\n */\nexport async function simulateSwap(\n client: PublicClient,\n routerAddress: Address,\n commands: Hex,\n inputs: Hex[],\n deadline: bigint,\n from: Address,\n): Promise<SwapSimulationResult> {\n try {\n const gasEstimate = await client.estimateContractGas({\n address: routerAddress,\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, deadline],\n account: from,\n });\n\n return { success: true, gasEstimate };\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : \"Unknown simulation error\";\n throw new SimulationError(\"swap\", message);\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,0BAA0B;AAKnC,eAAsB,eACpB,QACA,OACA,OACA,SACiB;AACjB,SAAO,OAAO,aAAa;AAAA,IACzB,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,OAAO,OAAO;AAAA,EACvB,CAAC;AACH;AAKO,SAAS,2BACd,SACA,QACK;AACL,SAAO,mBAAmB;AAAA,IACxB,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,SAAS,MAAM;AAAA,EACxB,CAAC;AACH;AAKO,SAAS,6BACd,OACA,SACA,QACA,YACK;AACL,SAAO,mBAAmB;AAAA,IACxB,KAAK;AAAA,IACL,cAAc;AAAA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