@pafi-dev/core 0.5.3 → 0.5.4
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/dist/{chunk-YU7MFR6Y.cjs → chunk-B3PYJGTH.cjs} +14 -2
- package/dist/chunk-B3PYJGTH.cjs.map +1 -0
- package/dist/{chunk-CQCSQPWG.cjs → chunk-G6IUSI5S.cjs} +1 -1
- package/dist/{chunk-CQCSQPWG.cjs.map → chunk-G6IUSI5S.cjs.map} +1 -1
- package/dist/{chunk-QGO6X6LG.js → chunk-HZTR4RHR.js} +1 -1
- package/dist/chunk-HZTR4RHR.js.map +1 -0
- package/dist/{chunk-T6Y32SNK.js → chunk-MWKJODJE.js} +14 -2
- package/dist/{chunk-T6Y32SNK.js.map → chunk-MWKJODJE.js.map} +1 -1
- package/dist/contract/index.cjs +2 -2
- package/dist/contract/index.js +1 -1
- package/dist/index.cjs +43 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/swap/index.cjs +2 -2
- package/dist/swap/index.js +1 -1
- package/package.json +1 -1
- package/dist/abi/index.d.cts +0 -2194
- package/dist/abi/index.d.ts +0 -2194
- package/dist/auth/index.d.cts +0 -151
- package/dist/auth/index.d.ts +0 -151
- package/dist/chunk-QGO6X6LG.js.map +0 -1
- package/dist/chunk-YU7MFR6Y.cjs.map +0 -1
- package/dist/contract/index.d.cts +0 -22
- package/dist/contract/index.d.ts +0 -22
- package/dist/eip712/index.d.cts +0 -125
- package/dist/eip712/index.d.ts +0 -125
- package/dist/index-BEx-Q1bW.d.cts +0 -227
- package/dist/index-r4xCdQO7.d.ts +0 -227
- package/dist/index.d.cts +0 -1607
- package/dist/index.d.ts +0 -1607
- package/dist/quoting/index.d.cts +0 -59
- package/dist/quoting/index.d.ts +0 -59
- package/dist/swap/index.d.cts +0 -3
- package/dist/swap/index.d.ts +0 -3
- package/dist/types-b5_Tokjl.d.cts +0 -89
- package/dist/types-b5_Tokjl.d.ts +0 -89
|
@@ -195,6 +195,17 @@ function encodeBatchExecute(operations) {
|
|
|
195
195
|
]
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
+
function decodeBatchExecuteCalls(callData) {
|
|
199
|
+
const { args } = _viem.decodeFunctionData.call(void 0, {
|
|
200
|
+
abi: BATCH_EXECUTOR_ABI,
|
|
201
|
+
data: callData
|
|
202
|
+
});
|
|
203
|
+
return args[0].map((c) => ({
|
|
204
|
+
to: c.target,
|
|
205
|
+
data: c.data,
|
|
206
|
+
value: c.value.toString()
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
198
209
|
|
|
199
210
|
// src/userop/buildUserOperation.ts
|
|
200
211
|
var DEFAULT_CALL_GAS_LIMIT = 500000n;
|
|
@@ -357,5 +368,6 @@ function buildSwapWithGasDeduction(params) {
|
|
|
357
368
|
|
|
358
369
|
|
|
359
370
|
|
|
360
|
-
|
|
361
|
-
|
|
371
|
+
|
|
372
|
+
exports.PafiSDKError = PafiSDKError; exports.ConfigurationError = ConfigurationError; exports.SigningError = SigningError; exports.SimulationError = SimulationError; exports.ApiError = ApiError; 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; exports.BATCH_EXECUTOR_ABI = BATCH_EXECUTOR_ABI; exports.encodeBatchExecute = encodeBatchExecute; exports.decodeBatchExecuteCalls = decodeBatchExecuteCalls; exports.buildPartialUserOperation = buildPartialUserOperation; exports.assembleUserOperation = assembleUserOperation; exports.erc20TransferOp = erc20TransferOp; exports.erc20ApproveOp = erc20ApproveOp; exports.erc20BurnOp = erc20BurnOp; exports.rawCallOp = rawCallOp; exports.buildSwapWithGasDeduction = buildSwapWithGasDeduction;
|
|
373
|
+
//# sourceMappingURL=chunk-B3PYJGTH.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-B3PYJGTH.cjs","../src/swap/approval.ts","../src/swap/universalRouter.ts","../src/errors.ts","../src/swap/simulate.ts","../src/swap/buildSwapWithGasDeduction.ts","../src/userop/batchExecute.ts","../src/userop/buildUserOperation.ts","../src/userop/operations.ts"],"names":["encodeFunctionData","erc20Abi"],"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,EAAS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ACF;AAWa;AACJ,EAAA;AACG,IAAA;AACD,IAAA;AACkB,IAAA;AAClBA,MAAAA;AACS,MAAA;AACQ,MAAA;AACvB,IAAA;AACH,EAAA;AACF;AAWuE;AAC9D,EAAA;AACG,IAAA;AACD,IAAA;AACkB,IAAA;AAClB,MAAA;AACS,MAAA;AACD,MAAA;AACd,IAAA;AACH,EAAA;AACF;AAWa;AACkB,EAAA;AAC/B;AR8LwD;AACA;AK7KhC;AACK,EAAA;AACT,IAAA;AAClB,EAAA;AAC8B,EAAA;AAClB,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAC0B,EAAA;AACd,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AACkC,EAAA;AACtB,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAE6B,EAAA;AACpB,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACT,EAAA;AAE6C,EAAA;AACtC,IAAA;AACS,IAAA;AAC0B,IAAA;AACzC,EAAA;AAE+B,EAAA;AACvB,IAAA;AACA,IAAA;AACA,IAAA;AACe,IAAA;AACxB,EAAA;AAEgC,EAAA;AAC9B,IAAA;AACS,MAAA;AACP,MAAA;AACO,MAAA;AACT,IAAA;AAC6C,IAAA;AACJ,IAAA;AAC3C,EAAA;AAE0B,EAAA;AACb,IAAA;AACT,MAAA;AACS,QAAA;AACA,QAAA;AACA,QAAA;AACT,MAAA;AACF,IAAA;AACF,EAAA;AAEiC,EAAA;AAChB,IAAA;AACD,IAAA;AACd,IAAA;AACW,IAAA;AACuC,MAAA;AAE5B,MAAA;AACkB,MAAA;AACxC,IAAA;AACD,EAAA;AACH;ALwKwD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-B3PYJGTH.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","export class PafiSDKError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PafiSDKError\";\n }\n}\n\nexport class ConfigurationError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"ConfigurationError\";\n }\n}\n\nexport class SigningError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"SigningError\";\n }\n}\n\nexport class SimulationError extends PafiSDKError {\n constructor(\n public operation: string,\n public reason: string,\n ) {\n super(`Simulation failed for ${operation}: ${reason}`);\n this.name = \"SimulationError\";\n }\n}\n\nexport class ApiError extends PafiSDKError {\n constructor(\n message: string,\n public status?: number,\n ) {\n super(message);\n this.name = \"ApiError\";\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","import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport type { PathKey } from \"../types\";\nimport { buildPartialUserOperation } from \"../userop/buildUserOperation\";\nimport type { PartialUserOperation } from \"../userop/types\";\nimport {\n erc20ApproveOp,\n erc20TransferOp,\n rawCallOp,\n} from \"../userop/operations\";\nimport type { Operation } from \"../userop/types\";\nimport { buildUniversalRouterExecuteArgs } from \"./universalRouter\";\nimport { buildPermit2ApprovalCalldata } from \"./approval\";\nimport { PERMIT2_ADDRESS } from \"../constants\";\n\n/**\n * v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with gas fee\n * deducted in PT from the user's balance.\n *\n * Builds an unsigned `PartialUserOperation` that packages up to four\n * inner calls into a single `BatchExecutor.execute(calls[])`:\n *\n * 1. `PT.approve(Permit2, amountIn)` — grant Permit2 ERC-20 allowance\n * 2. `Permit2.approve(PT, router, amountIn, deadline)` — authorize\n * the UniversalRouter to pull PT via Permit2\n * 3. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap\n * PT → USDT; user receives ≥ `minAmountOut` USDT\n * 4. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back\n * for sponsoring the gas, in PT (omitted when `gasFeePt` is 0)\n *\n * The user's wallet must hold `amountIn + gasFeePt` PT before the\n * UserOp runs. All inner calls execute atomically via EIP-7702\n * delegation (`msg.sender = user`), so a reverting swap unwinds\n * the approvals and fee transfer too.\n *\n * ## Fee model\n *\n * The gas fee is a separate `transfer` after the swap — it does NOT\n * come out of the USDT output, because that output goes straight to\n * the user's wallet with no intermediate hook.\n *\n * If the FE wants \"user receives exactly X USDT after gas\":\n * 1. Quote PT→USDT for candidate `amountIn` values\n * 2. Pick an `amountIn` where `minAmountOut ≈ X`\n * 3. Separately compute `gasFeePt` from the operator's rate\n * 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`\n *\n * ## Order of operations\n *\n * Fee transfer is last so a reverting swap also refunds the fee\n * (atomic batch revert semantics).\n */\nexport interface BuildSwapWithGasDeductionParams {\n /** User's EOA (with EIP-7702 delegation to BatchExecutor). */\n userAddress: Address;\n /** ERC-4337 account nonce — fetched from EntryPoint by the caller. */\n aaNonce: bigint;\n\n /** PT token address being swapped. */\n pointTokenAddress: Address;\n /** Destination currency (typically USDT). */\n outputTokenAddress: Address;\n /** UniversalRouter contract address (chain-specific). */\n universalRouterAddress: Address;\n\n /** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */\n amountIn: bigint;\n /**\n * Minimum USDT to accept out of the swap. Caller applies slippage\n * (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.\n */\n minAmountOut: bigint;\n\n /** V4 pool path for the swap. Single-hop = 1 PathKey. */\n swapPath: PathKey[];\n /** Unix seconds. After this, the router rejects the swap. */\n deadline: bigint;\n\n /** PT amount transferred to `feeRecipient` as gas fee recovery. */\n gasFeePt: bigint;\n /** Where the gas fee lands — typically the operator or fee collector. */\n feeRecipient: Address;\n\n /** Override ERC-4337 gas estimates. Defaults are conservative; tune down for cheaper UserOps. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n}\n\n/**\n * Build an unsigned UserOp for Scenario 4. Returns a\n * `PartialUserOperation` — caller attaches paymaster sponsorship (via\n * `POST /api/paymaster/sponsor`), adds the user's UserOp-hash\n * signature, and submits to the Bundler.\n *\n * @throws when `amountIn` or `gasFeePt` is not positive, or when\n * `swapPath` is empty (at least one PathKey required).\n */\nexport function buildSwapWithGasDeduction(\n params: BuildSwapWithGasDeductionParams,\n): PartialUserOperation {\n if (params.amountIn <= 0n) {\n throw new Error(\"buildSwapWithGasDeduction: amountIn must be positive\");\n }\n if (params.minAmountOut < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: minAmountOut must be non-negative\",\n );\n }\n if (params.gasFeePt < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: gasFeePt must be non-negative\",\n );\n }\n if (params.swapPath.length === 0) {\n throw new Error(\n \"buildSwapWithGasDeduction: swapPath must contain at least one PathKey\",\n );\n }\n\n const { commands, inputs } = buildUniversalRouterExecuteArgs(\n params.pointTokenAddress,\n params.swapPath,\n params.amountIn,\n params.minAmountOut,\n params.outputTokenAddress,\n );\n\n const swapCallData: Hex = encodeFunctionData({\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, params.deadline],\n });\n\n const permit2ApproveData: Hex = buildPermit2ApprovalCalldata(\n params.pointTokenAddress,\n params.universalRouterAddress,\n params.amountIn,\n Number(params.deadline),\n );\n\n const operations: Operation[] = [\n erc20ApproveOp(\n params.pointTokenAddress,\n PERMIT2_ADDRESS,\n params.amountIn,\n ),\n rawCallOp(PERMIT2_ADDRESS, permit2ApproveData),\n rawCallOp(params.universalRouterAddress, swapCallData),\n ];\n\n if (params.gasFeePt > 0n) {\n operations.push(\n erc20TransferOp(\n params.pointTokenAddress,\n params.feeRecipient,\n params.gasFeePt,\n ),\n );\n }\n\n return buildPartialUserOperation({\n sender: params.userAddress,\n nonce: params.aaNonce,\n operations,\n gasLimits: {\n callGasLimit: params.gasLimits?.callGasLimit ?? 700_000n,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ?? 150_000n,\n preVerificationGas: params.gasLimits?.preVerificationGas ?? 50_000n,\n },\n });\n}\n","import { decodeFunctionData, encodeFunctionData, parseAbi } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * Standard BatchExecutor ABI — a contract that takes an array of calls\n * and invokes each one in sequence, reverting all if any fail.\n *\n * Compatible with OpenZeppelin `Account.execute(Call[])`, Biconomy\n * `executeBatch`, Safe `MultiSend`, and most EIP-7702 delegation\n * targets. The exact deployed address is supplied by the infra team\n * (see [V1.4_V1.5_READINESS.md B2]).\n */\nexport const BATCH_EXECUTOR_ABI = parseAbi([\n \"function execute((address target, uint256 value, bytes data)[] calls)\",\n]);\n\n/**\n * Encode a batch of operations into calldata for `BatchExecutor.execute()`.\n * The resulting calldata goes into `UserOperation.callData`.\n *\n * When the EOA has an EIP-7702 delegation to a BatchExecutor, calling\n * this calldata against the EOA runs all operations with\n * `msg.sender = EOA` for each inner call.\n *\n * @param operations batch of calls, in execution order\n * @returns calldata bytes for `execute((address,uint256,bytes)[])`\n */\nexport function encodeBatchExecute(operations: Operation[]): Hex {\n if (operations.length === 0) {\n throw new Error(\"encodeBatchExecute: operations array must not be empty\");\n }\n return encodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n functionName: \"execute\",\n args: [\n operations.map((op) => ({\n target: op.target,\n value: op.value,\n data: op.data,\n })),\n ],\n });\n}\n\n/**\n * Decode `BatchExecutor.execute(calls[])` callData back into individual\n * `{ to, data, value }` objects.\n *\n * Used by issuer backends to convert a `PartialUserOperation.callData`\n * into the `calls[]` array returned to web/FE clients (which submit via\n * `permissionless.sendTransaction({ calls })`).\n */\nexport function decodeBatchExecuteCalls(\n callData: Hex,\n): Array<{ to: string; data: string; value: string }> {\n const { args } = decodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n data: callData,\n });\n return (\n args[0] as ReadonlyArray<{ target: Address; value: bigint; data: Hex }>\n ).map((c) => ({\n to: c.target,\n data: c.data,\n value: c.value.toString(),\n }));\n}\n","import type { Address } from \"viem\";\nimport type { Operation, PartialUserOperation, UserOperation } from \"./types\";\nimport { encodeBatchExecute } from \"./batchExecute\";\n\n/**\n * Default gas limits — rough upper bounds for a 2-op batch on Base.\n * Bundler re-estimates before submission, so these are only used when\n * the caller doesn't supply their own.\n */\nconst DEFAULT_CALL_GAS_LIMIT = 500_000n;\nconst DEFAULT_VERIFICATION_GAS_LIMIT = 150_000n;\nconst DEFAULT_PRE_VERIFICATION_GAS = 50_000n;\n\nexport interface BuildPartialUserOpParams {\n /** User's EOA (with EIP-7702 delegation). */\n sender: Address;\n /** Batch of operations — encoded into callData via `encodeBatchExecute`. */\n operations: Operation[];\n /** EntryPoint nonce for this sender. Caller fetches from the EntryPoint contract. */\n nonce: bigint;\n /** Optional gas overrides; bundler re-estimates before submission. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n /** Optional fee overrides; bundler usually fills these. */\n feeOverrides?: {\n maxFeePerGas?: bigint;\n maxPriorityFeePerGas?: bigint;\n };\n}\n\n/**\n * Build a partial ERC-4337 UserOperation from a batch of operations.\n * Paymaster fields and signature are populated later:\n * 1. Call `PafiBackendClient.requestSponsorship()` → get paymaster fields\n * 2. Compute userOpHash and have the user sign it (via Privy)\n * 3. Attach `signature` → submit to bundler\n *\n * This function is a pure struct builder — no network calls.\n */\nexport function buildPartialUserOperation(\n params: BuildPartialUserOpParams,\n): PartialUserOperation {\n return {\n sender: params.sender,\n nonce: params.nonce,\n callData: encodeBatchExecute(params.operations),\n callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ??\n DEFAULT_VERIFICATION_GAS_LIMIT,\n preVerificationGas:\n params.gasLimits?.preVerificationGas ?? DEFAULT_PRE_VERIFICATION_GAS,\n maxFeePerGas: params.feeOverrides?.maxFeePerGas ?? 0n,\n maxPriorityFeePerGas: params.feeOverrides?.maxPriorityFeePerGas ?? 0n,\n };\n}\n\n/**\n * Assemble a full UserOperation once paymaster fields + signature are\n * known. Used after `PafiBackendClient.requestSponsorship()` and user\n * signing complete.\n */\nexport function assembleUserOperation(\n partial: PartialUserOperation,\n paymaster: {\n paymaster: Address;\n paymasterData: `0x${string}`;\n paymasterVerificationGasLimit: bigint;\n paymasterPostOpGasLimit: bigint;\n },\n signature: `0x${string}`,\n): UserOperation {\n return {\n ...partial,\n paymaster: paymaster.paymaster,\n paymasterData: paymaster.paymasterData,\n paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,\n paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,\n signature,\n };\n}\n","import { encodeFunctionData, erc20Abi, parseAbi } from \"viem\";\nimport type { Address } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * ERC20Burnable extension — `burn(uint256 amount)` burns from msg.sender.\n * The EOA (via EIP-7702 delegation) is the `msg.sender` when a batch\n * runs — so this burns the user's balance without any role check.\n */\nconst ERC20_BURNABLE_ABI = parseAbi([\"function burn(uint256 amount)\"]);\n\n/**\n * Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch\n * to move fee tokens from the user to the fee recipient atomically with\n * the main action.\n */\nexport function erc20TransferOp(\n token: Address,\n to: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"transfer\",\n args: [to, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `approve(spender, amount)` operation. Used inside a\n * batch before a swap / deposit call so the AMM / protocol can pull\n * tokens from the user.\n */\nexport function erc20ApproveOp(\n token: Address,\n spender: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `burn(amount)` operation (OpenZeppelin ERC20Burnable\n * extension). Burns from `msg.sender`, which — via EIP-7702 — is the\n * user's EOA.\n *\n * Requires the PointToken contract to expose a public `burn(uint256)`\n * without a role check. See\n * [SDK_V1.4_TASKS.md §11 — PointToken.burn callable via batch].\n */\nexport function erc20BurnOp(token: Address, amount: bigint): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_BURNABLE_ABI,\n functionName: \"burn\",\n args: [amount],\n }),\n };\n}\n\n/**\n * Build a raw call operation with caller-supplied calldata. Useful for\n * non-ERC-20 contracts (PoolManager.swap, PerpDEX.deposit, Relayer.mint)\n * where the encoding is specific to that protocol.\n */\nexport function rawCallOp(\n target: Address,\n data: `0x${string}`,\n value: bigint = 0n,\n): Operation {\n return { target, value, data };\n}\n"]}
|
|
@@ -122,4 +122,4 @@ async function getPointTokenIssuer(client, oracleAddress, pointToken) {
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
exports.getMintRequestNonce = getMintRequestNonce; exports.getReceiverConsentNonce = getReceiverConsentNonce; exports.isMinter = isMinter; exports.getTokenName = getTokenName; exports.getIssuer = getIssuer; exports.getPointTokenBalance = getPointTokenBalance; exports.getIssuer2 = getIssuer2; exports.isActiveIssuer = isActiveIssuer; exports.verifyMintCap = verifyMintCap; exports.getPointTokenIssuer = getPointTokenIssuer;
|
|
125
|
-
//# sourceMappingURL=chunk-
|
|
125
|
+
//# sourceMappingURL=chunk-G6IUSI5S.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-G6IUSI5S.cjs","../src/contract/pointToken.ts","../src/contract/issuerRegistry.ts","../src/contract/mintingOracle.ts"],"names":["getIssuer"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACHA,MAAA,SAAsB,mBAAA,CACpB,MAAA,EACA,UAAA,EACA,QAAA,EACiB;AACjB,EAAA,OAAO,MAAA,CAAO,YAAA,CAAa;AAAA,IACzB,OAAA,EAAS,UAAA;AAAA,IACT,GAAA,EAAK,+BAAA;AAAA,IACL,YAAA,EAAc,mBAAA;AAAA,IACd,IAAA,EAAM,CAAC,QAAQ;AAAA,EACjB,CAAC,CAAA;AACH;AAEA,MAAA,SAAsB,uBAAA,CACpB,MAAA,EACA,UAAA,EACA,QAAA,EACiB;AACjB,EAAA,OAAO,MAAA,CAAO,YAAA,CAAa;AAAA,IACzB,OAAA,EAAS,UAAA;AAAA,IACT,GAAA,EAAK,+BAAA;AAAA,IACL,YAAA,EAAc,uBAAA;AAAA,IACd,IAAA,EAAM,CAAC,QAAQ;AAAA,EACjB,CAAC,CAAA;AACH;AAEA,MAAA,SAAsB,QAAA,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AC","file":"/Users/phitran/Pacific-Finance/pafi-backend/pafi-sdk/packages/core/dist/chunk-G6IUSI5S.cjs","sourcesContent":[null,"import type { Address, PublicClient } from \"viem\";\nimport { pointTokenAbi } from \"../abi/pointToken\";\n\nexport async function getMintRequestNonce(\n client: PublicClient,\n pointToken: Address,\n receiver: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"mintRequestNonces\",\n args: [receiver],\n });\n}\n\nexport async function getReceiverConsentNonce(\n client: PublicClient,\n pointToken: Address,\n receiver: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"receiverConsentNonces\",\n args: [receiver],\n });\n}\n\nexport async function isMinter(\n client: PublicClient,\n pointToken: Address,\n account: Address,\n): Promise<boolean> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"minters\",\n args: [account],\n });\n}\n\nexport async function getTokenName(\n client: PublicClient,\n pointToken: Address,\n): Promise<string> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"name\",\n });\n}\n\nexport async function getIssuer(\n client: PublicClient,\n pointToken: Address,\n): Promise<Address> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"issuer\",\n });\n}\n\n/**\n * Read the ERC-20 on-chain balance for `holder`. Returned in raw 18-decimal\n * base units. Use alongside the issuer's off-chain ledger balance to render\n * a combined \"total balance\" in the app UI.\n */\nexport async function getPointTokenBalance(\n client: PublicClient,\n pointToken: Address,\n holder: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"balanceOf\",\n args: [holder],\n });\n}\n\nexport async function getBurnRequestNonce(\n client: PublicClient,\n pointToken: Address,\n from: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"burnRequestNonces\",\n args: [from],\n });\n}\n","import type { Address, PublicClient } from \"viem\";\nimport { issuerRegistryAbi } from \"../abi/issuerRegistry\";\nimport type { Issuer } from \"../types\";\n\nexport async function getIssuer(\n client: PublicClient,\n registryAddress: Address,\n issuer: Address,\n): Promise<Issuer> {\n const result = await client.readContract({\n address: registryAddress,\n abi: issuerRegistryAbi,\n functionName: \"getIssuer\",\n args: [issuer],\n });\n\n const [\n issuerAddress,\n signerAddress,\n name,\n symbol,\n declaredTotalSupply,\n capBasisPoints,\n active,\n pointToken,\n mintingOracle,\n ] = result;\n\n return {\n issuerAddress,\n signerAddress,\n name,\n symbol,\n declaredTotalSupply,\n capBasisPoints,\n active,\n pointToken,\n mintingOracle,\n };\n}\n\nexport async function isActiveIssuer(\n client: PublicClient,\n registryAddress: Address,\n issuer: Address,\n): Promise<boolean> {\n return client.readContract({\n address: registryAddress,\n abi: issuerRegistryAbi,\n functionName: \"isActiveIssuer\",\n args: [issuer],\n });\n}\n","import type { Address, PublicClient } from \"viem\";\nimport { mintingOracleAbi } from \"../abi/mintingOracle\";\n\nexport async function verifyMintCap(\n client: PublicClient,\n oracleAddress: Address,\n issuer: Address,\n amount: bigint,\n): Promise<void> {\n await client.readContract({\n address: oracleAddress,\n abi: mintingOracleAbi,\n functionName: \"verifyMintCap\",\n args: [issuer, amount],\n });\n}\n\nexport async function getPointTokenIssuer(\n client: PublicClient,\n oracleAddress: Address,\n pointToken: Address,\n): Promise<Address> {\n return client.readContract({\n address: oracleAddress,\n abi: mintingOracleAbi,\n functionName: \"pointTokenToIssuer\",\n args: [pointToken],\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/contract/pointToken.ts","../src/contract/issuerRegistry.ts","../src/contract/mintingOracle.ts"],"sourcesContent":["import type { Address, PublicClient } from \"viem\";\nimport { pointTokenAbi } from \"../abi/pointToken\";\n\nexport async function getMintRequestNonce(\n client: PublicClient,\n pointToken: Address,\n receiver: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"mintRequestNonces\",\n args: [receiver],\n });\n}\n\nexport async function getReceiverConsentNonce(\n client: PublicClient,\n pointToken: Address,\n receiver: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"receiverConsentNonces\",\n args: [receiver],\n });\n}\n\nexport async function isMinter(\n client: PublicClient,\n pointToken: Address,\n account: Address,\n): Promise<boolean> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"minters\",\n args: [account],\n });\n}\n\nexport async function getTokenName(\n client: PublicClient,\n pointToken: Address,\n): Promise<string> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"name\",\n });\n}\n\nexport async function getIssuer(\n client: PublicClient,\n pointToken: Address,\n): Promise<Address> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"issuer\",\n });\n}\n\n/**\n * Read the ERC-20 on-chain balance for `holder`. Returned in raw 18-decimal\n * base units. Use alongside the issuer's off-chain ledger balance to render\n * a combined \"total balance\" in the app UI.\n */\nexport async function getPointTokenBalance(\n client: PublicClient,\n pointToken: Address,\n holder: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"balanceOf\",\n args: [holder],\n });\n}\n\nexport async function getBurnRequestNonce(\n client: PublicClient,\n pointToken: Address,\n from: Address,\n): Promise<bigint> {\n return client.readContract({\n address: pointToken,\n abi: pointTokenAbi,\n functionName: \"burnRequestNonces\",\n args: [from],\n });\n}\n","import type { Address, PublicClient } from \"viem\";\nimport { issuerRegistryAbi } from \"../abi/issuerRegistry\";\nimport type { Issuer } from \"../types\";\n\nexport async function getIssuer(\n client: PublicClient,\n registryAddress: Address,\n issuer: Address,\n): Promise<Issuer> {\n const result = await client.readContract({\n address: registryAddress,\n abi: issuerRegistryAbi,\n functionName: \"getIssuer\",\n args: [issuer],\n });\n\n const [\n issuerAddress,\n signerAddress,\n name,\n symbol,\n declaredTotalSupply,\n capBasisPoints,\n active,\n pointToken,\n mintingOracle,\n ] = result;\n\n return {\n issuerAddress,\n signerAddress,\n name,\n symbol,\n declaredTotalSupply,\n capBasisPoints,\n active,\n pointToken,\n mintingOracle,\n };\n}\n\nexport async function isActiveIssuer(\n client: PublicClient,\n registryAddress: Address,\n issuer: Address,\n): Promise<boolean> {\n return client.readContract({\n address: registryAddress,\n abi: issuerRegistryAbi,\n functionName: \"isActiveIssuer\",\n args: [issuer],\n });\n}\n","import type { Address, PublicClient } from \"viem\";\nimport { mintingOracleAbi } from \"../abi/mintingOracle\";\n\nexport async function verifyMintCap(\n client: PublicClient,\n oracleAddress: Address,\n issuer: Address,\n amount: bigint,\n): Promise<void> {\n await client.readContract({\n address: oracleAddress,\n abi: mintingOracleAbi,\n functionName: \"verifyMintCap\",\n args: [issuer, amount],\n });\n}\n\nexport async function getPointTokenIssuer(\n client: PublicClient,\n oracleAddress: Address,\n pointToken: Address,\n): Promise<Address> {\n return client.readContract({\n address: oracleAddress,\n abi: mintingOracleAbi,\n functionName: \"pointTokenToIssuer\",\n args: [pointToken],\n });\n}\n"],"mappings":";;;;;;;AAGA,eAAsB,oBACpB,QACA,YACA,UACiB;AACjB,SAAO,OAAO,aAAa;AAAA,IACzB,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,QAAQ;AAAA,EACjB,CAAC;AACH;AAEA,eAAsB,wBACpB,QACA,YACA,UACiB;AACjB,SAAO,OAAO,aAAa;AAAA,IACzB,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,QAAQ;AAAA,EACjB,CAAC;AACH;AAEA,eAAsB,SACpB,QACA,YACA,SACkB;AAClB,SAAO,OAAO,aAAa;AAAA,IACzB,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,OAAO;AAAA,EAChB,CAAC;AACH;AAEA,eAAsB,aACpB,QACA,YACiB;AACjB,SAAO,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KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,UAAU;AAAA,EACnB,CAAC;AACH;","names":["getIssuer"]}
|
|
@@ -175,7 +175,7 @@ async function simulateSwap(client, routerAddress, commands, inputs, deadline, f
|
|
|
175
175
|
import { encodeFunctionData as encodeFunctionData4 } from "viem";
|
|
176
176
|
|
|
177
177
|
// src/userop/batchExecute.ts
|
|
178
|
-
import { encodeFunctionData as encodeFunctionData2, parseAbi } from "viem";
|
|
178
|
+
import { decodeFunctionData, encodeFunctionData as encodeFunctionData2, parseAbi } from "viem";
|
|
179
179
|
var BATCH_EXECUTOR_ABI = parseAbi([
|
|
180
180
|
"function execute((address target, uint256 value, bytes data)[] calls)"
|
|
181
181
|
]);
|
|
@@ -195,6 +195,17 @@ function encodeBatchExecute(operations) {
|
|
|
195
195
|
]
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
+
function decodeBatchExecuteCalls(callData) {
|
|
199
|
+
const { args } = decodeFunctionData({
|
|
200
|
+
abi: BATCH_EXECUTOR_ABI,
|
|
201
|
+
data: callData
|
|
202
|
+
});
|
|
203
|
+
return args[0].map((c) => ({
|
|
204
|
+
to: c.target,
|
|
205
|
+
data: c.data,
|
|
206
|
+
value: c.value.toString()
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
198
209
|
|
|
199
210
|
// src/userop/buildUserOperation.ts
|
|
200
211
|
var DEFAULT_CALL_GAS_LIMIT = 500000n;
|
|
@@ -350,6 +361,7 @@ export {
|
|
|
350
361
|
simulateSwap,
|
|
351
362
|
BATCH_EXECUTOR_ABI,
|
|
352
363
|
encodeBatchExecute,
|
|
364
|
+
decodeBatchExecuteCalls,
|
|
353
365
|
buildPartialUserOperation,
|
|
354
366
|
assembleUserOperation,
|
|
355
367
|
erc20TransferOp,
|
|
@@ -358,4 +370,4 @@ export {
|
|
|
358
370
|
rawCallOp,
|
|
359
371
|
buildSwapWithGasDeduction
|
|
360
372
|
};
|
|
361
|
-
//# sourceMappingURL=chunk-
|
|
373
|
+
//# sourceMappingURL=chunk-MWKJODJE.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/swap/approval.ts","../src/swap/universalRouter.ts","../src/errors.ts","../src/swap/simulate.ts","../src/swap/buildSwapWithGasDeduction.ts","../src/userop/batchExecute.ts","../src/userop/buildUserOperation.ts","../src/userop/operations.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","export class PafiSDKError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PafiSDKError\";\n }\n}\n\nexport class ConfigurationError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"ConfigurationError\";\n }\n}\n\nexport class SigningError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"SigningError\";\n }\n}\n\nexport class SimulationError extends PafiSDKError {\n constructor(\n public operation: string,\n public reason: string,\n ) {\n super(`Simulation failed for ${operation}: ${reason}`);\n this.name = \"SimulationError\";\n }\n}\n\nexport class ApiError extends PafiSDKError {\n constructor(\n message: string,\n public status?: number,\n ) {\n super(message);\n this.name = \"ApiError\";\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","import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport type { PathKey } from \"../types\";\nimport { buildPartialUserOperation } from \"../userop/buildUserOperation\";\nimport type { PartialUserOperation } from \"../userop/types\";\nimport {\n erc20ApproveOp,\n erc20TransferOp,\n rawCallOp,\n} from \"../userop/operations\";\nimport type { Operation } from \"../userop/types\";\nimport { buildUniversalRouterExecuteArgs } from \"./universalRouter\";\nimport { buildPermit2ApprovalCalldata } from \"./approval\";\nimport { PERMIT2_ADDRESS } from \"../constants\";\n\n/**\n * v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with gas fee\n * deducted in PT from the user's balance.\n *\n * Builds an unsigned `PartialUserOperation` that packages up to four\n * inner calls into a single `BatchExecutor.execute(calls[])`:\n *\n * 1. `PT.approve(Permit2, amountIn)` — grant Permit2 ERC-20 allowance\n * 2. `Permit2.approve(PT, router, amountIn, deadline)` — authorize\n * the UniversalRouter to pull PT via Permit2\n * 3. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap\n * PT → USDT; user receives ≥ `minAmountOut` USDT\n * 4. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back\n * for sponsoring the gas, in PT (omitted when `gasFeePt` is 0)\n *\n * The user's wallet must hold `amountIn + gasFeePt` PT before the\n * UserOp runs. All inner calls execute atomically via EIP-7702\n * delegation (`msg.sender = user`), so a reverting swap unwinds\n * the approvals and fee transfer too.\n *\n * ## Fee model\n *\n * The gas fee is a separate `transfer` after the swap — it does NOT\n * come out of the USDT output, because that output goes straight to\n * the user's wallet with no intermediate hook.\n *\n * If the FE wants \"user receives exactly X USDT after gas\":\n * 1. Quote PT→USDT for candidate `amountIn` values\n * 2. Pick an `amountIn` where `minAmountOut ≈ X`\n * 3. Separately compute `gasFeePt` from the operator's rate\n * 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`\n *\n * ## Order of operations\n *\n * Fee transfer is last so a reverting swap also refunds the fee\n * (atomic batch revert semantics).\n */\nexport interface BuildSwapWithGasDeductionParams {\n /** User's EOA (with EIP-7702 delegation to BatchExecutor). */\n userAddress: Address;\n /** ERC-4337 account nonce — fetched from EntryPoint by the caller. */\n aaNonce: bigint;\n\n /** PT token address being swapped. */\n pointTokenAddress: Address;\n /** Destination currency (typically USDT). */\n outputTokenAddress: Address;\n /** UniversalRouter contract address (chain-specific). */\n universalRouterAddress: Address;\n\n /** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */\n amountIn: bigint;\n /**\n * Minimum USDT to accept out of the swap. Caller applies slippage\n * (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.\n */\n minAmountOut: bigint;\n\n /** V4 pool path for the swap. Single-hop = 1 PathKey. */\n swapPath: PathKey[];\n /** Unix seconds. After this, the router rejects the swap. */\n deadline: bigint;\n\n /** PT amount transferred to `feeRecipient` as gas fee recovery. */\n gasFeePt: bigint;\n /** Where the gas fee lands — typically the operator or fee collector. */\n feeRecipient: Address;\n\n /** Override ERC-4337 gas estimates. Defaults are conservative; tune down for cheaper UserOps. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n}\n\n/**\n * Build an unsigned UserOp for Scenario 4. Returns a\n * `PartialUserOperation` — caller attaches paymaster sponsorship (via\n * `POST /api/paymaster/sponsor`), adds the user's UserOp-hash\n * signature, and submits to the Bundler.\n *\n * @throws when `amountIn` or `gasFeePt` is not positive, or when\n * `swapPath` is empty (at least one PathKey required).\n */\nexport function buildSwapWithGasDeduction(\n params: BuildSwapWithGasDeductionParams,\n): PartialUserOperation {\n if (params.amountIn <= 0n) {\n throw new Error(\"buildSwapWithGasDeduction: amountIn must be positive\");\n }\n if (params.minAmountOut < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: minAmountOut must be non-negative\",\n );\n }\n if (params.gasFeePt < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: gasFeePt must be non-negative\",\n );\n }\n if (params.swapPath.length === 0) {\n throw new Error(\n \"buildSwapWithGasDeduction: swapPath must contain at least one PathKey\",\n );\n }\n\n const { commands, inputs } = buildUniversalRouterExecuteArgs(\n params.pointTokenAddress,\n params.swapPath,\n params.amountIn,\n params.minAmountOut,\n params.outputTokenAddress,\n );\n\n const swapCallData: Hex = encodeFunctionData({\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, params.deadline],\n });\n\n const permit2ApproveData: Hex = buildPermit2ApprovalCalldata(\n params.pointTokenAddress,\n params.universalRouterAddress,\n params.amountIn,\n Number(params.deadline),\n );\n\n const operations: Operation[] = [\n erc20ApproveOp(\n params.pointTokenAddress,\n PERMIT2_ADDRESS,\n params.amountIn,\n ),\n rawCallOp(PERMIT2_ADDRESS, permit2ApproveData),\n rawCallOp(params.universalRouterAddress, swapCallData),\n ];\n\n if (params.gasFeePt > 0n) {\n operations.push(\n erc20TransferOp(\n params.pointTokenAddress,\n params.feeRecipient,\n params.gasFeePt,\n ),\n );\n }\n\n return buildPartialUserOperation({\n sender: params.userAddress,\n nonce: params.aaNonce,\n operations,\n gasLimits: {\n callGasLimit: params.gasLimits?.callGasLimit ?? 700_000n,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ?? 150_000n,\n preVerificationGas: params.gasLimits?.preVerificationGas ?? 50_000n,\n },\n });\n}\n","import { encodeFunctionData, parseAbi } from \"viem\";\nimport type { Hex } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * Standard BatchExecutor ABI — a contract that takes an array of calls\n * and invokes each one in sequence, reverting all if any fail.\n *\n * Compatible with OpenZeppelin `Account.execute(Call[])`, Biconomy\n * `executeBatch`, Safe `MultiSend`, and most EIP-7702 delegation\n * targets. The exact deployed address is supplied by the infra team\n * (see [V1.4_V1.5_READINESS.md B2]).\n */\nexport const BATCH_EXECUTOR_ABI = parseAbi([\n \"function execute((address target, uint256 value, bytes data)[] calls)\",\n]);\n\n/**\n * Encode a batch of operations into calldata for `BatchExecutor.execute()`.\n * The resulting calldata goes into `UserOperation.callData`.\n *\n * When the EOA has an EIP-7702 delegation to a BatchExecutor, calling\n * this calldata against the EOA runs all operations with\n * `msg.sender = EOA` for each inner call.\n *\n * @param operations batch of calls, in execution order\n * @returns calldata bytes for `execute((address,uint256,bytes)[])`\n */\nexport function encodeBatchExecute(operations: Operation[]): Hex {\n if (operations.length === 0) {\n throw new Error(\"encodeBatchExecute: operations array must not be empty\");\n }\n return encodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n functionName: \"execute\",\n args: [\n operations.map((op) => ({\n target: op.target,\n value: op.value,\n data: op.data,\n })),\n ],\n });\n}\n","import type { Address } from \"viem\";\nimport type { Operation, PartialUserOperation, UserOperation } from \"./types\";\nimport { encodeBatchExecute } from \"./batchExecute\";\n\n/**\n * Default gas limits — rough upper bounds for a 2-op batch on Base.\n * Bundler re-estimates before submission, so these are only used when\n * the caller doesn't supply their own.\n */\nconst DEFAULT_CALL_GAS_LIMIT = 500_000n;\nconst DEFAULT_VERIFICATION_GAS_LIMIT = 150_000n;\nconst DEFAULT_PRE_VERIFICATION_GAS = 50_000n;\n\nexport interface BuildPartialUserOpParams {\n /** User's EOA (with EIP-7702 delegation). */\n sender: Address;\n /** Batch of operations — encoded into callData via `encodeBatchExecute`. */\n operations: Operation[];\n /** EntryPoint nonce for this sender. Caller fetches from the EntryPoint contract. */\n nonce: bigint;\n /** Optional gas overrides; bundler re-estimates before submission. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n /** Optional fee overrides; bundler usually fills these. */\n feeOverrides?: {\n maxFeePerGas?: bigint;\n maxPriorityFeePerGas?: bigint;\n };\n}\n\n/**\n * Build a partial ERC-4337 UserOperation from a batch of operations.\n * Paymaster fields and signature are populated later:\n * 1. Call `PafiBackendClient.requestSponsorship()` → get paymaster fields\n * 2. Compute userOpHash and have the user sign it (via Privy)\n * 3. Attach `signature` → submit to bundler\n *\n * This function is a pure struct builder — no network calls.\n */\nexport function buildPartialUserOperation(\n params: BuildPartialUserOpParams,\n): PartialUserOperation {\n return {\n sender: params.sender,\n nonce: params.nonce,\n callData: encodeBatchExecute(params.operations),\n callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ??\n DEFAULT_VERIFICATION_GAS_LIMIT,\n preVerificationGas:\n params.gasLimits?.preVerificationGas ?? DEFAULT_PRE_VERIFICATION_GAS,\n maxFeePerGas: params.feeOverrides?.maxFeePerGas ?? 0n,\n maxPriorityFeePerGas: params.feeOverrides?.maxPriorityFeePerGas ?? 0n,\n };\n}\n\n/**\n * Assemble a full UserOperation once paymaster fields + signature are\n * known. Used after `PafiBackendClient.requestSponsorship()` and user\n * signing complete.\n */\nexport function assembleUserOperation(\n partial: PartialUserOperation,\n paymaster: {\n paymaster: Address;\n paymasterData: `0x${string}`;\n paymasterVerificationGasLimit: bigint;\n paymasterPostOpGasLimit: bigint;\n },\n signature: `0x${string}`,\n): UserOperation {\n return {\n ...partial,\n paymaster: paymaster.paymaster,\n paymasterData: paymaster.paymasterData,\n paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,\n paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,\n signature,\n };\n}\n","import { encodeFunctionData, erc20Abi, parseAbi } from \"viem\";\nimport type { Address } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * ERC20Burnable extension — `burn(uint256 amount)` burns from msg.sender.\n * The EOA (via EIP-7702 delegation) is the `msg.sender` when a batch\n * runs — so this burns the user's balance without any role check.\n */\nconst ERC20_BURNABLE_ABI = parseAbi([\"function burn(uint256 amount)\"]);\n\n/**\n * Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch\n * to move fee tokens from the user to the fee recipient atomically with\n * the main action.\n */\nexport function erc20TransferOp(\n token: Address,\n to: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"transfer\",\n args: [to, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `approve(spender, amount)` operation. Used inside a\n * batch before a swap / deposit call so the AMM / protocol can pull\n * tokens from the user.\n */\nexport function erc20ApproveOp(\n token: Address,\n spender: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `burn(amount)` operation (OpenZeppelin ERC20Burnable\n * extension). Burns from `msg.sender`, which — via EIP-7702 — is the\n * user's EOA.\n *\n * Requires the PointToken contract to expose a public `burn(uint256)`\n * without a role check. See\n * [SDK_V1.4_TASKS.md §11 — PointToken.burn callable via batch].\n */\nexport function erc20BurnOp(token: Address, amount: bigint): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_BURNABLE_ABI,\n functionName: \"burn\",\n args: [amount],\n }),\n };\n}\n\n/**\n * Build a raw call operation with caller-supplied calldata. Useful for\n * non-ERC-20 contracts (PoolManager.swap, PerpDEX.deposit, Relayer.mint)\n * where the encoding is specific to that protocol.\n */\nexport function rawCallOp(\n target: Address,\n data: `0x${string}`,\n value: bigint = 0n,\n): Operation {\n return { target, value, data };\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,S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;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO,0BAA0B;AAAA,IAC/B,QAAQ,OAAO;AAAA,IACf,OAAO,OAAO;AAAA,IACd;AAAA,IACA,WAAW;AAAA,MACT,cAAc,OAAO,WAAW,gBAAgB;AAAA,MAChD,sBACE,OAAO,WAAW,wBAAwB;AAAA,MAC5C,oBAAoB,OAAO,WAAW,sBAAsB;AAAA,IAC9D;AAAA,EACF,CAAC;AACH;","names":["encodeFunctionData","encodeFunctionData","encodeFunctionData","erc20Abi","parseAbi","encodeFunctionData"]}
|
|
1
|
+
{"version":3,"sources":["../src/swap/approval.ts","../src/swap/universalRouter.ts","../src/errors.ts","../src/swap/simulate.ts","../src/swap/buildSwapWithGasDeduction.ts","../src/userop/batchExecute.ts","../src/userop/buildUserOperation.ts","../src/userop/operations.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","export class PafiSDKError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PafiSDKError\";\n }\n}\n\nexport class ConfigurationError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"ConfigurationError\";\n }\n}\n\nexport class SigningError extends PafiSDKError {\n constructor(message: string) {\n super(message);\n this.name = \"SigningError\";\n }\n}\n\nexport class SimulationError extends PafiSDKError {\n constructor(\n public operation: string,\n public reason: string,\n ) {\n super(`Simulation failed for ${operation}: ${reason}`);\n this.name = \"SimulationError\";\n }\n}\n\nexport class ApiError extends PafiSDKError {\n constructor(\n message: string,\n public status?: number,\n ) {\n super(message);\n this.name = \"ApiError\";\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","import { encodeFunctionData } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport { universalRouterAbi } from \"../abi/universalRouter\";\nimport type { PathKey } from \"../types\";\nimport { buildPartialUserOperation } from \"../userop/buildUserOperation\";\nimport type { PartialUserOperation } from \"../userop/types\";\nimport {\n erc20ApproveOp,\n erc20TransferOp,\n rawCallOp,\n} from \"../userop/operations\";\nimport type { Operation } from \"../userop/types\";\nimport { buildUniversalRouterExecuteArgs } from \"./universalRouter\";\nimport { buildPermit2ApprovalCalldata } from \"./approval\";\nimport { PERMIT2_ADDRESS } from \"../constants\";\n\n/**\n * v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with gas fee\n * deducted in PT from the user's balance.\n *\n * Builds an unsigned `PartialUserOperation` that packages up to four\n * inner calls into a single `BatchExecutor.execute(calls[])`:\n *\n * 1. `PT.approve(Permit2, amountIn)` — grant Permit2 ERC-20 allowance\n * 2. `Permit2.approve(PT, router, amountIn, deadline)` — authorize\n * the UniversalRouter to pull PT via Permit2\n * 3. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap\n * PT → USDT; user receives ≥ `minAmountOut` USDT\n * 4. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back\n * for sponsoring the gas, in PT (omitted when `gasFeePt` is 0)\n *\n * The user's wallet must hold `amountIn + gasFeePt` PT before the\n * UserOp runs. All inner calls execute atomically via EIP-7702\n * delegation (`msg.sender = user`), so a reverting swap unwinds\n * the approvals and fee transfer too.\n *\n * ## Fee model\n *\n * The gas fee is a separate `transfer` after the swap — it does NOT\n * come out of the USDT output, because that output goes straight to\n * the user's wallet with no intermediate hook.\n *\n * If the FE wants \"user receives exactly X USDT after gas\":\n * 1. Quote PT→USDT for candidate `amountIn` values\n * 2. Pick an `amountIn` where `minAmountOut ≈ X`\n * 3. Separately compute `gasFeePt` from the operator's rate\n * 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`\n *\n * ## Order of operations\n *\n * Fee transfer is last so a reverting swap also refunds the fee\n * (atomic batch revert semantics).\n */\nexport interface BuildSwapWithGasDeductionParams {\n /** User's EOA (with EIP-7702 delegation to BatchExecutor). */\n userAddress: Address;\n /** ERC-4337 account nonce — fetched from EntryPoint by the caller. */\n aaNonce: bigint;\n\n /** PT token address being swapped. */\n pointTokenAddress: Address;\n /** Destination currency (typically USDT). */\n outputTokenAddress: Address;\n /** UniversalRouter contract address (chain-specific). */\n universalRouterAddress: Address;\n\n /** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */\n amountIn: bigint;\n /**\n * Minimum USDT to accept out of the swap. Caller applies slippage\n * (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.\n */\n minAmountOut: bigint;\n\n /** V4 pool path for the swap. Single-hop = 1 PathKey. */\n swapPath: PathKey[];\n /** Unix seconds. After this, the router rejects the swap. */\n deadline: bigint;\n\n /** PT amount transferred to `feeRecipient` as gas fee recovery. */\n gasFeePt: bigint;\n /** Where the gas fee lands — typically the operator or fee collector. */\n feeRecipient: Address;\n\n /** Override ERC-4337 gas estimates. Defaults are conservative; tune down for cheaper UserOps. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n}\n\n/**\n * Build an unsigned UserOp for Scenario 4. Returns a\n * `PartialUserOperation` — caller attaches paymaster sponsorship (via\n * `POST /api/paymaster/sponsor`), adds the user's UserOp-hash\n * signature, and submits to the Bundler.\n *\n * @throws when `amountIn` or `gasFeePt` is not positive, or when\n * `swapPath` is empty (at least one PathKey required).\n */\nexport function buildSwapWithGasDeduction(\n params: BuildSwapWithGasDeductionParams,\n): PartialUserOperation {\n if (params.amountIn <= 0n) {\n throw new Error(\"buildSwapWithGasDeduction: amountIn must be positive\");\n }\n if (params.minAmountOut < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: minAmountOut must be non-negative\",\n );\n }\n if (params.gasFeePt < 0n) {\n throw new Error(\n \"buildSwapWithGasDeduction: gasFeePt must be non-negative\",\n );\n }\n if (params.swapPath.length === 0) {\n throw new Error(\n \"buildSwapWithGasDeduction: swapPath must contain at least one PathKey\",\n );\n }\n\n const { commands, inputs } = buildUniversalRouterExecuteArgs(\n params.pointTokenAddress,\n params.swapPath,\n params.amountIn,\n params.minAmountOut,\n params.outputTokenAddress,\n );\n\n const swapCallData: Hex = encodeFunctionData({\n abi: universalRouterAbi,\n functionName: \"execute\",\n args: [commands, inputs, params.deadline],\n });\n\n const permit2ApproveData: Hex = buildPermit2ApprovalCalldata(\n params.pointTokenAddress,\n params.universalRouterAddress,\n params.amountIn,\n Number(params.deadline),\n );\n\n const operations: Operation[] = [\n erc20ApproveOp(\n params.pointTokenAddress,\n PERMIT2_ADDRESS,\n params.amountIn,\n ),\n rawCallOp(PERMIT2_ADDRESS, permit2ApproveData),\n rawCallOp(params.universalRouterAddress, swapCallData),\n ];\n\n if (params.gasFeePt > 0n) {\n operations.push(\n erc20TransferOp(\n params.pointTokenAddress,\n params.feeRecipient,\n params.gasFeePt,\n ),\n );\n }\n\n return buildPartialUserOperation({\n sender: params.userAddress,\n nonce: params.aaNonce,\n operations,\n gasLimits: {\n callGasLimit: params.gasLimits?.callGasLimit ?? 700_000n,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ?? 150_000n,\n preVerificationGas: params.gasLimits?.preVerificationGas ?? 50_000n,\n },\n });\n}\n","import { decodeFunctionData, encodeFunctionData, parseAbi } from \"viem\";\nimport type { Address, Hex } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * Standard BatchExecutor ABI — a contract that takes an array of calls\n * and invokes each one in sequence, reverting all if any fail.\n *\n * Compatible with OpenZeppelin `Account.execute(Call[])`, Biconomy\n * `executeBatch`, Safe `MultiSend`, and most EIP-7702 delegation\n * targets. The exact deployed address is supplied by the infra team\n * (see [V1.4_V1.5_READINESS.md B2]).\n */\nexport const BATCH_EXECUTOR_ABI = parseAbi([\n \"function execute((address target, uint256 value, bytes data)[] calls)\",\n]);\n\n/**\n * Encode a batch of operations into calldata for `BatchExecutor.execute()`.\n * The resulting calldata goes into `UserOperation.callData`.\n *\n * When the EOA has an EIP-7702 delegation to a BatchExecutor, calling\n * this calldata against the EOA runs all operations with\n * `msg.sender = EOA` for each inner call.\n *\n * @param operations batch of calls, in execution order\n * @returns calldata bytes for `execute((address,uint256,bytes)[])`\n */\nexport function encodeBatchExecute(operations: Operation[]): Hex {\n if (operations.length === 0) {\n throw new Error(\"encodeBatchExecute: operations array must not be empty\");\n }\n return encodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n functionName: \"execute\",\n args: [\n operations.map((op) => ({\n target: op.target,\n value: op.value,\n data: op.data,\n })),\n ],\n });\n}\n\n/**\n * Decode `BatchExecutor.execute(calls[])` callData back into individual\n * `{ to, data, value }` objects.\n *\n * Used by issuer backends to convert a `PartialUserOperation.callData`\n * into the `calls[]` array returned to web/FE clients (which submit via\n * `permissionless.sendTransaction({ calls })`).\n */\nexport function decodeBatchExecuteCalls(\n callData: Hex,\n): Array<{ to: string; data: string; value: string }> {\n const { args } = decodeFunctionData({\n abi: BATCH_EXECUTOR_ABI,\n data: callData,\n });\n return (\n args[0] as ReadonlyArray<{ target: Address; value: bigint; data: Hex }>\n ).map((c) => ({\n to: c.target,\n data: c.data,\n value: c.value.toString(),\n }));\n}\n","import type { Address } from \"viem\";\nimport type { Operation, PartialUserOperation, UserOperation } from \"./types\";\nimport { encodeBatchExecute } from \"./batchExecute\";\n\n/**\n * Default gas limits — rough upper bounds for a 2-op batch on Base.\n * Bundler re-estimates before submission, so these are only used when\n * the caller doesn't supply their own.\n */\nconst DEFAULT_CALL_GAS_LIMIT = 500_000n;\nconst DEFAULT_VERIFICATION_GAS_LIMIT = 150_000n;\nconst DEFAULT_PRE_VERIFICATION_GAS = 50_000n;\n\nexport interface BuildPartialUserOpParams {\n /** User's EOA (with EIP-7702 delegation). */\n sender: Address;\n /** Batch of operations — encoded into callData via `encodeBatchExecute`. */\n operations: Operation[];\n /** EntryPoint nonce for this sender. Caller fetches from the EntryPoint contract. */\n nonce: bigint;\n /** Optional gas overrides; bundler re-estimates before submission. */\n gasLimits?: {\n callGasLimit?: bigint;\n verificationGasLimit?: bigint;\n preVerificationGas?: bigint;\n };\n /** Optional fee overrides; bundler usually fills these. */\n feeOverrides?: {\n maxFeePerGas?: bigint;\n maxPriorityFeePerGas?: bigint;\n };\n}\n\n/**\n * Build a partial ERC-4337 UserOperation from a batch of operations.\n * Paymaster fields and signature are populated later:\n * 1. Call `PafiBackendClient.requestSponsorship()` → get paymaster fields\n * 2. Compute userOpHash and have the user sign it (via Privy)\n * 3. Attach `signature` → submit to bundler\n *\n * This function is a pure struct builder — no network calls.\n */\nexport function buildPartialUserOperation(\n params: BuildPartialUserOpParams,\n): PartialUserOperation {\n return {\n sender: params.sender,\n nonce: params.nonce,\n callData: encodeBatchExecute(params.operations),\n callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT,\n verificationGasLimit:\n params.gasLimits?.verificationGasLimit ??\n DEFAULT_VERIFICATION_GAS_LIMIT,\n preVerificationGas:\n params.gasLimits?.preVerificationGas ?? DEFAULT_PRE_VERIFICATION_GAS,\n maxFeePerGas: params.feeOverrides?.maxFeePerGas ?? 0n,\n maxPriorityFeePerGas: params.feeOverrides?.maxPriorityFeePerGas ?? 0n,\n };\n}\n\n/**\n * Assemble a full UserOperation once paymaster fields + signature are\n * known. Used after `PafiBackendClient.requestSponsorship()` and user\n * signing complete.\n */\nexport function assembleUserOperation(\n partial: PartialUserOperation,\n paymaster: {\n paymaster: Address;\n paymasterData: `0x${string}`;\n paymasterVerificationGasLimit: bigint;\n paymasterPostOpGasLimit: bigint;\n },\n signature: `0x${string}`,\n): UserOperation {\n return {\n ...partial,\n paymaster: paymaster.paymaster,\n paymasterData: paymaster.paymasterData,\n paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,\n paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,\n signature,\n };\n}\n","import { encodeFunctionData, erc20Abi, parseAbi } from \"viem\";\nimport type { Address } from \"viem\";\nimport type { Operation } from \"./types\";\n\n/**\n * ERC20Burnable extension — `burn(uint256 amount)` burns from msg.sender.\n * The EOA (via EIP-7702 delegation) is the `msg.sender` when a batch\n * runs — so this burns the user's balance without any role check.\n */\nconst ERC20_BURNABLE_ABI = parseAbi([\"function burn(uint256 amount)\"]);\n\n/**\n * Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch\n * to move fee tokens from the user to the fee recipient atomically with\n * the main action.\n */\nexport function erc20TransferOp(\n token: Address,\n to: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"transfer\",\n args: [to, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `approve(spender, amount)` operation. Used inside a\n * batch before a swap / deposit call so the AMM / protocol can pull\n * tokens from the user.\n */\nexport function erc20ApproveOp(\n token: Address,\n spender: Address,\n amount: bigint,\n): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: erc20Abi,\n functionName: \"approve\",\n args: [spender, amount],\n }),\n };\n}\n\n/**\n * Build an ERC-20 `burn(amount)` operation (OpenZeppelin ERC20Burnable\n * extension). Burns from `msg.sender`, which — via EIP-7702 — is the\n * user's EOA.\n *\n * Requires the PointToken contract to expose a public `burn(uint256)`\n * without a role check. See\n * [SDK_V1.4_TASKS.md §11 — PointToken.burn callable via batch].\n */\nexport function erc20BurnOp(token: Address, amount: bigint): Operation {\n return {\n target: token,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_BURNABLE_ABI,\n functionName: \"burn\",\n args: [amount],\n }),\n };\n}\n\n/**\n * Build a raw call operation with caller-supplied calldata. Useful for\n * non-ERC-20 contracts (PoolManager.swap, PerpDEX.deposit, Relayer.mint)\n * where the encoding is specific to that protocol.\n */\nexport function rawCallOp(\n target: Address,\n data: `0x${string}`,\n value: bigint = 0n,\n): Operation {\n return { target, value, data };\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,IACd,MAAM,CAAC,OAAO,SAAS,QAAQ,UAAU;AAAA,EAC3C,CAAC;AACH;;;AC/CA,SAAS,qBAAqB,oBAAoB;AAU3C,IAAM,UAAU;AAIhB,IAAM,gBAAgB;AACtB,IAAM,aAAa;AACnB,IAAM,WAAW;AAYxB,IAAM,0BAA0B;AAAA,EAC9B,EAAE,MAAM,wBAAwB,MAAM,UAAU;AAAA,EAChD,EAAE,MAAM,OAAO,MAAM,UAAU;AAAA,EAC/B,EAAE,MAAM,eAAe,MAA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AsB;AAAA,IAC9D;AAAA,EACF,CAAC;AACH;","names":["encodeFunctionData","encodeFunctionData","encodeFunctionData","erc20Abi","parseAbi","encodeFunctionData"]}
|
package/dist/contract/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkG6IUSI5Scjs = require('../chunk-G6IUSI5S.cjs');
|
|
13
13
|
require('../chunk-S2XRFFP3.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
@@ -22,5 +22,5 @@ require('../chunk-S2XRFFP3.cjs');
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
exports.getIssuer =
|
|
25
|
+
exports.getIssuer = _chunkG6IUSI5Scjs.getIssuer2; exports.getMintRequestNonce = _chunkG6IUSI5Scjs.getMintRequestNonce; exports.getPointTokenBalance = _chunkG6IUSI5Scjs.getPointTokenBalance; exports.getPointTokenIssuer = _chunkG6IUSI5Scjs.getPointTokenIssuer; exports.getPointTokenIssuerAddress = _chunkG6IUSI5Scjs.getIssuer; exports.getReceiverConsentNonce = _chunkG6IUSI5Scjs.getReceiverConsentNonce; exports.getTokenName = _chunkG6IUSI5Scjs.getTokenName; exports.isActiveIssuer = _chunkG6IUSI5Scjs.isActiveIssuer; exports.isMinter = _chunkG6IUSI5Scjs.isMinter; exports.verifyMintCap = _chunkG6IUSI5Scjs.verifyMintCap;
|
|
26
26
|
//# sourceMappingURL=index.cjs.map
|
package/dist/contract/index.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@ var _chunkFNJZUNK3cjs = require('./chunk-FNJZUNK3.cjs');
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _chunkG6IUSI5Scjs = require('./chunk-G6IUSI5S.cjs');
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
@@ -79,7 +79,8 @@ var _chunkCL3QSI4Ocjs = require('./chunk-CL3QSI4O.cjs');
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
|
|
83
|
+
var _chunkB3PYJGTHcjs = require('./chunk-B3PYJGTH.cjs');
|
|
83
84
|
|
|
84
85
|
|
|
85
86
|
|
|
@@ -221,16 +222,16 @@ function buildPerpDepositWithGasDeduction(params) {
|
|
|
221
222
|
args: [params.depositData]
|
|
222
223
|
});
|
|
223
224
|
const operations = [
|
|
224
|
-
|
|
225
|
+
_chunkB3PYJGTHcjs.erc20ApproveOp.call(void 0, params.usdcAddress, vault, params.amount),
|
|
225
226
|
{
|
|
226
|
-
...
|
|
227
|
+
..._chunkB3PYJGTHcjs.rawCallOp.call(void 0, vault, depositCallData),
|
|
227
228
|
// BatchExecutor passes `value` from the inner call along; this
|
|
228
229
|
// becomes the LayerZero fee. The aggregated `msg.value` for the
|
|
229
230
|
// top-level UserOp must equal the sum of inner `value`s.
|
|
230
231
|
value: params.layerZeroFee
|
|
231
232
|
}
|
|
232
233
|
];
|
|
233
|
-
return
|
|
234
|
+
return _chunkB3PYJGTHcjs.buildPartialUserOperation.call(void 0, {
|
|
234
235
|
sender: params.userAddress,
|
|
235
236
|
nonce: params.aaNonce,
|
|
236
237
|
operations,
|
|
@@ -245,6 +246,28 @@ function buildPerpDepositWithGasDeduction(params) {
|
|
|
245
246
|
// src/userop/types.ts
|
|
246
247
|
var ZERO_VALUE = 0n;
|
|
247
248
|
|
|
249
|
+
// src/userop/serializeUserOp.ts
|
|
250
|
+
function serializeUserOpToJsonRpc(userOp, signature) {
|
|
251
|
+
const p = userOp;
|
|
252
|
+
return {
|
|
253
|
+
sender: p.sender,
|
|
254
|
+
nonce: `0x${p.nonce.toString(16)}`,
|
|
255
|
+
factory: null,
|
|
256
|
+
factoryData: null,
|
|
257
|
+
callData: p.callData,
|
|
258
|
+
callGasLimit: `0x${p.callGasLimit.toString(16)}`,
|
|
259
|
+
verificationGasLimit: `0x${p.verificationGasLimit.toString(16)}`,
|
|
260
|
+
preVerificationGas: `0x${p.preVerificationGas.toString(16)}`,
|
|
261
|
+
maxFeePerGas: `0x${p.maxFeePerGas.toString(16)}`,
|
|
262
|
+
maxPriorityFeePerGas: `0x${p.maxPriorityFeePerGas.toString(16)}`,
|
|
263
|
+
paymaster: _nullishCoalesce(p.paymaster, () => ( null)),
|
|
264
|
+
paymasterData: _nullishCoalesce(p.paymasterData, () => ( null)),
|
|
265
|
+
paymasterVerificationGasLimit: p.paymasterVerificationGasLimit != null ? `0x${p.paymasterVerificationGasLimit.toString(16)}` : null,
|
|
266
|
+
paymasterPostOpGasLimit: p.paymasterPostOpGasLimit != null ? `0x${p.paymasterPostOpGasLimit.toString(16)}` : null,
|
|
267
|
+
signature
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
248
271
|
// src/userop/computeUserOpHash.ts
|
|
249
272
|
|
|
250
273
|
|
|
@@ -375,7 +398,7 @@ async function isDelegatedTo(client, address, target) {
|
|
|
375
398
|
|
|
376
399
|
// src/delegation/buildDelegationUserOp.ts
|
|
377
400
|
function buildDelegationUserOp(params) {
|
|
378
|
-
return
|
|
401
|
+
return _chunkB3PYJGTHcjs.buildPartialUserOperation.call(void 0, {
|
|
379
402
|
sender: params.userAddress,
|
|
380
403
|
nonce: params.aaNonce,
|
|
381
404
|
operations: [
|
|
@@ -831,25 +854,25 @@ var PafiSDK = class {
|
|
|
831
854
|
// -------------------------------------------------------------------------
|
|
832
855
|
requirePointToken() {
|
|
833
856
|
if (!this._pointTokenAddress) {
|
|
834
|
-
throw new (0,
|
|
857
|
+
throw new (0, _chunkB3PYJGTHcjs.ConfigurationError)("pointTokenAddress not set");
|
|
835
858
|
}
|
|
836
859
|
return this._pointTokenAddress;
|
|
837
860
|
}
|
|
838
861
|
requireProvider() {
|
|
839
862
|
if (!this._provider) {
|
|
840
|
-
throw new (0,
|
|
863
|
+
throw new (0, _chunkB3PYJGTHcjs.ConfigurationError)("provider not set");
|
|
841
864
|
}
|
|
842
865
|
return this._provider;
|
|
843
866
|
}
|
|
844
867
|
requireSigner() {
|
|
845
868
|
if (!this._signer) {
|
|
846
|
-
throw new (0,
|
|
869
|
+
throw new (0, _chunkB3PYJGTHcjs.ConfigurationError)("signer not set");
|
|
847
870
|
}
|
|
848
871
|
return this._signer;
|
|
849
872
|
}
|
|
850
873
|
requireChainId() {
|
|
851
874
|
if (this._chainId === void 0) {
|
|
852
|
-
throw new (0,
|
|
875
|
+
throw new (0, _chunkB3PYJGTHcjs.ConfigurationError)("chainId not set");
|
|
853
876
|
}
|
|
854
877
|
return this._chainId;
|
|
855
878
|
}
|
|
@@ -860,7 +883,7 @@ var PafiSDK = class {
|
|
|
860
883
|
const provider = this.requireProvider();
|
|
861
884
|
const pointToken = this.requirePointToken();
|
|
862
885
|
const chainId = this.requireChainId();
|
|
863
|
-
const name = await
|
|
886
|
+
const name = await _chunkG6IUSI5Scjs.getTokenName.call(void 0, provider, pointToken);
|
|
864
887
|
return { name, verifyingContract: pointToken, chainId };
|
|
865
888
|
}
|
|
866
889
|
// -------------------------------------------------------------------------
|
|
@@ -894,14 +917,14 @@ var PafiSDK = class {
|
|
|
894
917
|
// Contract reads
|
|
895
918
|
// -------------------------------------------------------------------------
|
|
896
919
|
async getMintRequestNonce(receiver) {
|
|
897
|
-
return
|
|
920
|
+
return _chunkG6IUSI5Scjs.getMintRequestNonce.call(void 0,
|
|
898
921
|
this.requireProvider(),
|
|
899
922
|
this.requirePointToken(),
|
|
900
923
|
receiver
|
|
901
924
|
);
|
|
902
925
|
}
|
|
903
926
|
async getReceiverConsentNonce(receiver) {
|
|
904
|
-
return
|
|
927
|
+
return _chunkG6IUSI5Scjs.getReceiverConsentNonce.call(void 0,
|
|
905
928
|
this.requireProvider(),
|
|
906
929
|
this.requirePointToken(),
|
|
907
930
|
receiver
|
|
@@ -935,7 +958,7 @@ var PafiSDK = class {
|
|
|
935
958
|
* The caller provides `minAmountOut` after applying their own slippage.
|
|
936
959
|
*/
|
|
937
960
|
buildSwapFromQuote(params) {
|
|
938
|
-
return
|
|
961
|
+
return _chunkB3PYJGTHcjs.buildSwapFromQuote.call(void 0, params);
|
|
939
962
|
}
|
|
940
963
|
// -------------------------------------------------------------------------
|
|
941
964
|
// Simulation — dry-run via eth_call (no gas spent)
|
|
@@ -951,7 +974,7 @@ var PafiSDK = class {
|
|
|
951
974
|
* @param from - Address that will execute the swap
|
|
952
975
|
*/
|
|
953
976
|
async simulateSwap(routerAddress, commands, inputs, deadline, from) {
|
|
954
|
-
return
|
|
977
|
+
return _chunkB3PYJGTHcjs.simulateSwap.call(void 0,
|
|
955
978
|
this.requireProvider(),
|
|
956
979
|
routerAddress,
|
|
957
980
|
commands,
|
|
@@ -968,7 +991,7 @@ var PafiSDK = class {
|
|
|
968
991
|
const chainId = this.requireChainId();
|
|
969
992
|
const account = signer.account;
|
|
970
993
|
if (!account) {
|
|
971
|
-
throw new (0,
|
|
994
|
+
throw new (0, _chunkB3PYJGTHcjs.ConfigurationError)("signer has no account attached");
|
|
972
995
|
}
|
|
973
996
|
return _chunkFNJZUNK3cjs.createLoginMessage.call(void 0, { ...params, address: account.address, chainId });
|
|
974
997
|
}
|
|
@@ -977,7 +1000,7 @@ var PafiSDK = class {
|
|
|
977
1000
|
const signer = this.requireSigner();
|
|
978
1001
|
const account = signer.account;
|
|
979
1002
|
if (!account) {
|
|
980
|
-
throw new (0,
|
|
1003
|
+
throw new (0, _chunkB3PYJGTHcjs.ConfigurationError)("signer has no account attached");
|
|
981
1004
|
}
|
|
982
1005
|
return signer.signMessage({ account, message });
|
|
983
1006
|
}
|
|
@@ -1102,5 +1125,7 @@ var PafiSDK = class {
|
|
|
1102
1125
|
|
|
1103
1126
|
|
|
1104
1127
|
|
|
1105
|
-
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
exports.ApiError = _chunkB3PYJGTHcjs.ApiError; exports.BATCH_EXECUTOR_ABI = _chunkB3PYJGTHcjs.BATCH_EXECUTOR_ABI; exports.BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = BATCH_EXECUTOR_ADDRESS_BASE_MAINNET; exports.BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA; exports.BROKER_HASHES = BROKER_HASHES; exports.COMMON_POOLS = _chunk52SZJDFTcjs.COMMON_POOLS; exports.COMMON_TOKENS = _chunk52SZJDFTcjs.COMMON_TOKENS; exports.CONTRACT_ADDRESSES = CONTRACT_ADDRESSES; exports.ConfigurationError = _chunkB3PYJGTHcjs.ConfigurationError; exports.ENTRY_POINT_V07 = _chunk52SZJDFTcjs.ENTRY_POINT_V07; exports.ORDERLY_VAULT_ABI = ORDERLY_VAULT_ABI; exports.ORDERLY_VAULT_ADDRESSES = ORDERLY_VAULT_ADDRESSES; exports.ORDERLY_VAULT_BASE_MAINNET = ORDERLY_VAULT_BASE_MAINNET; exports.PAFI_SUBGRAPH_URL = PAFI_SUBGRAPH_URL; exports.PERMIT2_ADDRESS = _chunk52SZJDFTcjs.PERMIT2_ADDRESS; exports.POINT_TOKEN_FACTORY_ADDRESSES = POINT_TOKEN_FACTORY_ADDRESSES; exports.POINT_TOKEN_IMPL_ADDRESSES = POINT_TOKEN_IMPL_ADDRESSES; exports.POINT_TOKEN_POOLS = _chunk52SZJDFTcjs.POINT_TOKEN_POOLS; exports.POINT_TOKEN_V2_ABI = POINT_TOKEN_ABI; exports.PafiSDK = PafiSDK; exports.PafiSDKError = _chunkB3PYJGTHcjs.PafiSDKError; exports.SETTLE_ALL = _chunkB3PYJGTHcjs.SETTLE_ALL; exports.SPONSOR_AUTH_DOMAIN_NAME = _chunkFNJZUNK3cjs.SPONSOR_AUTH_DOMAIN_NAME; exports.SPONSOR_AUTH_TYPES = _chunkFNJZUNK3cjs.SPONSOR_AUTH_TYPES; exports.SUPPORTED_CHAINS = _chunk52SZJDFTcjs.SUPPORTED_CHAINS; exports.SWAP_EXACT_IN = _chunkB3PYJGTHcjs.SWAP_EXACT_IN; exports.SigningError = _chunkB3PYJGTHcjs.SigningError; exports.SimulationError = _chunkB3PYJGTHcjs.SimulationError; exports.TAKE_ALL = _chunkB3PYJGTHcjs.TAKE_ALL; exports.TOKEN_HASHES = TOKEN_HASHES; exports.UNIVERSAL_ROUTER_ADDRESSES = _chunk52SZJDFTcjs.UNIVERSAL_ROUTER_ADDRESSES; exports.V4_QUOTER_ADDRESSES = _chunk52SZJDFTcjs.V4_QUOTER_ADDRESSES; exports.V4_SWAP = _chunkB3PYJGTHcjs.V4_SWAP; exports.ZERO_VALUE = ZERO_VALUE; exports._resetPaymasterConfigForTests = _resetPaymasterConfigForTests; exports.assembleUserOperation = _chunkB3PYJGTHcjs.assembleUserOperation; exports.buildAllPaths = _chunkARZSGP5Ycjs.buildAllPaths; exports.buildBurnRequestTypedData = _chunk2PY5RNVScjs.buildBurnRequestTypedData; exports.buildDelegationUserOp = buildDelegationUserOp; exports.buildDomain = _chunk2PY5RNVScjs.buildDomain; exports.buildErc20ApprovalCalldata = _chunkB3PYJGTHcjs.buildErc20ApprovalCalldata; exports.buildMintRequestTypedData = _chunk2PY5RNVScjs.buildMintRequestTypedData; exports.buildPartialUserOperation = _chunkB3PYJGTHcjs.buildPartialUserOperation; exports.buildPermit2ApprovalCalldata = _chunkB3PYJGTHcjs.buildPermit2ApprovalCalldata; exports.buildPerpDepositWithGasDeduction = buildPerpDepositWithGasDeduction; exports.buildReceiverConsentTypedData = _chunk2PY5RNVScjs.buildReceiverConsentTypedData; exports.buildSponsorAuthDomain = _chunkFNJZUNK3cjs.buildSponsorAuthDomain; exports.buildSponsorAuthTypedData = _chunkFNJZUNK3cjs.buildSponsorAuthTypedData; exports.buildSwapFromQuote = _chunkB3PYJGTHcjs.buildSwapFromQuote; exports.buildSwapWithGasDeduction = _chunkB3PYJGTHcjs.buildSwapWithGasDeduction; exports.buildUniversalRouterExecuteArgs = _chunkB3PYJGTHcjs.buildUniversalRouterExecuteArgs; exports.buildV4SwapInput = _chunkB3PYJGTHcjs.buildV4SwapInput; exports.burnRequestTypes = _chunk52SZJDFTcjs.burnRequestTypes; exports.checkAllowance = _chunkB3PYJGTHcjs.checkAllowance; exports.checkDelegation = checkDelegation; exports.checkEthAndBranch = checkEthAndBranch; exports.combineRoutes = _chunkARZSGP5Ycjs.combineRoutes; exports.computeAccountId = computeAccountId; exports.computeAuthorizationHash = computeAuthorizationHash; exports.computeCallDataHash = _chunkFNJZUNK3cjs.computeCallDataHash; exports.computeUserOpHash = computeUserOpHash; exports.createLoginMessage = _chunkFNJZUNK3cjs.createLoginMessage; exports.createPafiProxyTransport = createPafiProxyTransport; exports.decodeBatchExecuteCalls = _chunkB3PYJGTHcjs.decodeBatchExecuteCalls; exports.encodeBatchExecute = _chunkB3PYJGTHcjs.encodeBatchExecute; exports.erc20Abi = _chunkIPXARZ6Fcjs.erc20Abi; exports.erc20ApproveOp = _chunkB3PYJGTHcjs.erc20ApproveOp; exports.erc20BurnOp = _chunkB3PYJGTHcjs.erc20BurnOp; exports.erc20TransferOp = _chunkB3PYJGTHcjs.erc20TransferOp; exports.fetchPafiPools = fetchPafiPools; exports.findBestQuote = _chunkARZSGP5Ycjs.findBestQuote; exports.getAaNonce = getAaNonce; exports.getContractAddresses = getContractAddresses; exports.getIssuer = _chunkG6IUSI5Scjs.getIssuer2; exports.getMintRequestNonce = _chunkG6IUSI5Scjs.getMintRequestNonce; exports.getPafiWebModalAdapter = getPafiWebModalAdapter; exports.getPaymasterConfig = getPaymasterConfig; exports.getPointTokenBalance = _chunkG6IUSI5Scjs.getPointTokenBalance; exports.getPointTokenIssuer = _chunkG6IUSI5Scjs.getPointTokenIssuer; exports.getPointTokenIssuerAddress = _chunkG6IUSI5Scjs.getIssuer; exports.getReceiverConsentNonce = _chunkG6IUSI5Scjs.getReceiverConsentNonce; exports.getTokenName = _chunkG6IUSI5Scjs.getTokenName; exports.isActiveIssuer = _chunkG6IUSI5Scjs.isActiveIssuer; exports.isDelegatedTo = isDelegatedTo; exports.isDelegatedToTarget = isDelegatedToTarget; exports.isMinter = _chunkG6IUSI5Scjs.isMinter; exports.isPaymasterConfigured = isPaymasterConfigured; exports.isPaymasterError = isPaymasterError; exports.issuerRegistryAbi = _chunkS2XRFFP3cjs.issuerRegistryAbi; exports.mintRequestTypes = _chunk52SZJDFTcjs.mintRequestTypes; exports.mintingOracleAbi = _chunkS2XRFFP3cjs.mintingOracleAbi; exports.openPafiWebModal = openPafiWebModal; exports.openWebPopup = openWebPopup; exports.parseEip7702DelegatedAddress = parseEip7702DelegatedAddress; exports.parseLoginMessage = _chunkFNJZUNK3cjs.parseLoginMessage; exports.permit2Abi = _chunkIPXARZ6Fcjs.permit2Abi; exports.pointTokenAbi = _chunkS2XRFFP3cjs.pointTokenAbi; exports.pointTokenFactoryAbi = _chunkALCWYDVGcjs.pointTokenFactoryAbi; exports.quoteBestRoute = _chunkARZSGP5Ycjs.quoteBestRoute; exports.quoteExactInput = _chunkARZSGP5Ycjs.quoteExactInput; exports.quoteExactInputSingle = _chunkARZSGP5Ycjs.quoteExactInputSingle; exports.rawCallOp = _chunkB3PYJGTHcjs.rawCallOp; exports.receiverConsentTypes = _chunk52SZJDFTcjs.receiverConsentTypes; exports.sendWithPaymasterFallback = sendWithPaymasterFallback; exports.serializeUserOpToJsonRpc = serializeUserOpToJsonRpc; exports.setPafiWebModalAdapter = setPafiWebModalAdapter; exports.setPaymasterConfig = setPaymasterConfig; exports.signBurnRequest = _chunk2PY5RNVScjs.signBurnRequest; exports.signMintRequest = _chunk2PY5RNVScjs.signMintRequest; exports.signReceiverConsent = _chunk2PY5RNVScjs.signReceiverConsent; exports.signSponsorAuth = _chunkFNJZUNK3cjs.signSponsorAuth; exports.simulateSwap = _chunkB3PYJGTHcjs.simulateSwap; exports.universalRouterAbi = _chunkIPXARZ6Fcjs.universalRouterAbi; exports.v4QuoterAbi = _chunkCL3QSI4Ocjs.v4QuoterAbi; exports.verifyBurnRequest = _chunk2PY5RNVScjs.verifyBurnRequest; exports.verifyLoginMessage = _chunkFNJZUNK3cjs.verifyLoginMessage; exports.verifyMintCap = _chunkG6IUSI5Scjs.verifyMintCap; exports.verifyMintRequest = _chunk2PY5RNVScjs.verifyMintRequest; exports.verifyReceiverConsent = _chunk2PY5RNVScjs.verifyReceiverConsent; exports.verifySponsorAuth = _chunkFNJZUNK3cjs.verifySponsorAuth; exports.webPopupAdapter = webPopupAdapter;
|
|
1106
1131
|
//# sourceMappingURL=index.cjs.map
|