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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/abi/index.cjs +2 -6
  2. package/dist/abi/index.cjs.map +1 -1
  3. package/dist/abi/index.d.cts +1 -286
  4. package/dist/abi/index.d.ts +1 -286
  5. package/dist/abi/index.js +1 -5
  6. package/dist/{chunk-R4L66ZR5.js → chunk-73CQTNLB.js} +10 -1
  7. package/dist/chunk-73CQTNLB.js.map +1 -0
  8. package/dist/{chunk-5YH4D7QF.js → chunk-7UBO7DY5.js} +1 -1
  9. package/dist/{chunk-FGKLDKJK.cjs → chunk-ALCWYDVG.cjs} +1 -1
  10. package/dist/{chunk-FGKLDKJK.cjs.map → chunk-ALCWYDVG.cjs.map} +1 -1
  11. package/dist/{chunk-X3I5XWAR.cjs → chunk-CQCSQPWG.cjs} +2 -15
  12. package/dist/chunk-CQCSQPWG.cjs.map +1 -0
  13. package/dist/{chunk-CWP4PFOP.cjs → chunk-DMW67WBU.cjs} +11 -2
  14. package/dist/chunk-DMW67WBU.cjs.map +1 -0
  15. package/dist/{chunk-C4ZDYG4D.js → chunk-DUY7Z2AI.js} +48 -6
  16. package/dist/chunk-DUY7Z2AI.js.map +1 -0
  17. package/dist/chunk-EDR5SFJN.cjs +351 -0
  18. package/dist/chunk-EDR5SFJN.cjs.map +1 -0
  19. package/dist/{chunk-FIKTQR7H.js → chunk-I2P3TIP7.js} +2 -2
  20. package/dist/{chunk-BNTVOKYT.cjs → chunk-KJKDLD7N.cjs} +51 -9
  21. package/dist/chunk-KJKDLD7N.cjs.map +1 -0
  22. package/dist/{chunk-VQSRCMMK.js → chunk-QGO6X6LG.js} +2 -15
  23. package/dist/chunk-QGO6X6LG.js.map +1 -0
  24. package/dist/chunk-W23EJNYG.js +351 -0
  25. package/dist/chunk-W23EJNYG.js.map +1 -0
  26. package/dist/{chunk-CAE2BVKI.cjs → chunk-Z2V525IS.cjs} +6 -6
  27. package/dist/{chunk-CAE2BVKI.cjs.map → chunk-Z2V525IS.cjs.map} +1 -1
  28. package/dist/contract/index.cjs +2 -5
  29. package/dist/contract/index.cjs.map +1 -1
  30. package/dist/contract/index.d.cts +2 -4
  31. package/dist/contract/index.d.ts +2 -4
  32. package/dist/contract/index.js +1 -4
  33. package/dist/eip712/index.cjs +9 -3
  34. package/dist/eip712/index.cjs.map +1 -1
  35. package/dist/eip712/index.d.cts +44 -2
  36. package/dist/eip712/index.d.ts +44 -2
  37. package/dist/eip712/index.js +8 -2
  38. package/dist/index-B06IJlHe.d.ts +244 -0
  39. package/dist/index-B7pGBych.d.cts +244 -0
  40. package/dist/index.cjs +365 -329
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +778 -459
  43. package/dist/index.d.ts +778 -459
  44. package/dist/index.js +383 -347
  45. package/dist/index.js.map +1 -1
  46. package/dist/quoting/index.cjs +3 -3
  47. package/dist/quoting/index.d.cts +1 -1
  48. package/dist/quoting/index.d.ts +1 -1
  49. package/dist/quoting/index.js +2 -2
  50. package/dist/swap/index.cjs +4 -3
  51. package/dist/swap/index.cjs.map +1 -1
  52. package/dist/swap/index.d.cts +3 -84
  53. package/dist/swap/index.d.ts +3 -84
  54. package/dist/swap/index.js +3 -2
  55. package/dist/{types-BDOnH5Le.d.ts → types-b5_Tokjl.d.cts} +8 -17
  56. package/dist/{types-BDOnH5Le.d.cts → types-b5_Tokjl.d.ts} +8 -17
  57. package/package.json +1 -1
  58. package/dist/chunk-27V32VNM.cjs +0 -370
  59. package/dist/chunk-27V32VNM.cjs.map +0 -1
  60. package/dist/chunk-4RYBJLF3.js +0 -370
  61. package/dist/chunk-4RYBJLF3.js.map +0 -1
  62. package/dist/chunk-5QJZT7VB.cjs +0 -46
  63. package/dist/chunk-5QJZT7VB.cjs.map +0 -1
  64. package/dist/chunk-6I6K43RQ.cjs +0 -149
  65. package/dist/chunk-6I6K43RQ.cjs.map +0 -1
  66. package/dist/chunk-BNTVOKYT.cjs.map +0 -1
  67. package/dist/chunk-C4ZDYG4D.js.map +0 -1
  68. package/dist/chunk-CWP4PFOP.cjs.map +0 -1
  69. package/dist/chunk-L74CZAVQ.cjs +0 -99
  70. package/dist/chunk-L74CZAVQ.cjs.map +0 -1
  71. package/dist/chunk-P56TUGTS.js +0 -46
  72. package/dist/chunk-P56TUGTS.js.map +0 -1
  73. package/dist/chunk-R4L66ZR5.js.map +0 -1
  74. package/dist/chunk-UU72CX7E.js +0 -149
  75. package/dist/chunk-UU72CX7E.js.map +0 -1
  76. package/dist/chunk-VQSRCMMK.js.map +0 -1
  77. package/dist/chunk-X3I5XWAR.cjs.map +0 -1
  78. package/dist/chunk-X4IXUTTD.js +0 -99
  79. package/dist/chunk-X4IXUTTD.js.map +0 -1
  80. package/dist/relay/index.cjs +0 -19
  81. package/dist/relay/index.cjs.map +0 -1
  82. package/dist/relay/index.d.cts +0 -75
  83. package/dist/relay/index.d.ts +0 -75
  84. package/dist/relay/index.js +0 -19
  85. package/dist/relay/index.js.map +0 -1
  86. /package/dist/{chunk-5YH4D7QF.js.map → chunk-7UBO7DY5.js.map} +0 -0
  87. /package/dist/{chunk-FIKTQR7H.js.map → chunk-I2P3TIP7.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { a as PointTokenDomainConfig, M as MintRequest, E as EIP712Signature, S as SignatureVerification, R as ReceiverConsent } from '../types-BDOnH5Le.cjs';
1
+ import { b as PointTokenDomainConfig, M as MintRequest, E as EIP712Signature, S as SignatureVerification, c as BurnRequest, R as ReceiverConsent } from '../types-b5_Tokjl.cjs';
2
2
  import { WalletClient, Hex, Address } from 'viem';
3
3
 
4
4
  declare function buildDomain(config: PointTokenDomainConfig): {
@@ -41,6 +41,48 @@ declare function buildMintRequestTypedData(domain: PointTokenDomainConfig, messa
41
41
  declare function signMintRequest(walletClient: WalletClient, domain: PointTokenDomainConfig, message: MintRequest): Promise<EIP712Signature>;
42
42
  declare function verifyMintRequest(domain: PointTokenDomainConfig, message: MintRequest, signature: Hex, expectedMinter: Address): Promise<SignatureVerification>;
43
43
 
44
+ /**
45
+ * EIP-712 helpers for `BurnRequest` — consumed by the sig-gated burn
46
+ * path on `PointToken`:
47
+ *
48
+ * burn(address from, uint256 amount, uint256 deadline, bytes burnerSig)
49
+ *
50
+ * Solidity type hash:
51
+ * BurnRequest(address from,uint256 amount,uint256 nonce,uint256 deadline)
52
+ *
53
+ * Issuer backend signs with its burner signer (HSM/KMS). On-chain
54
+ * `msg.sender` must equal `from`, and the recovered signer must be in
55
+ * `burners[]`. Nonce comes from `burnRequestNonces[from]` and is
56
+ * auto-incremented on success.
57
+ */
58
+ declare function buildBurnRequestTypedData(domain: PointTokenDomainConfig, message: BurnRequest): {
59
+ domain: {
60
+ name: string;
61
+ version: "1";
62
+ chainId: number;
63
+ verifyingContract: `0x${string}`;
64
+ };
65
+ types: {
66
+ readonly BurnRequest: readonly [{
67
+ readonly name: "from";
68
+ readonly type: "address";
69
+ }, {
70
+ readonly name: "amount";
71
+ readonly type: "uint256";
72
+ }, {
73
+ readonly name: "nonce";
74
+ readonly type: "uint256";
75
+ }, {
76
+ readonly name: "deadline";
77
+ readonly type: "uint256";
78
+ }];
79
+ };
80
+ primaryType: "BurnRequest";
81
+ message: BurnRequest;
82
+ };
83
+ declare function signBurnRequest(walletClient: WalletClient, domain: PointTokenDomainConfig, message: BurnRequest): Promise<EIP712Signature>;
84
+ declare function verifyBurnRequest(domain: PointTokenDomainConfig, message: BurnRequest, signature: Hex, expectedBurner: Address): Promise<SignatureVerification>;
85
+
44
86
  /**
45
87
  * Build the EIP-712 typed data object for a ReceiverConsent.
46
88
  * Returns the standard `{ domain, types, primaryType, message }` structure
@@ -80,4 +122,4 @@ declare function buildReceiverConsentTypedData(domain: PointTokenDomainConfig, m
80
122
  declare function signReceiverConsent(walletClient: WalletClient, domain: PointTokenDomainConfig, message: ReceiverConsent): Promise<EIP712Signature>;
81
123
  declare function verifyReceiverConsent(domain: PointTokenDomainConfig, message: ReceiverConsent, signature: Hex, expectedReceiver: Address): Promise<SignatureVerification>;
82
124
 
83
- export { buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signMintRequest, signReceiverConsent, verifyMintRequest, verifyReceiverConsent };
125
+ export { buildBurnRequestTypedData, buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signBurnRequest, signMintRequest, signReceiverConsent, verifyBurnRequest, verifyMintRequest, verifyReceiverConsent };
@@ -1,4 +1,4 @@
1
- import { a as PointTokenDomainConfig, M as MintRequest, E as EIP712Signature, S as SignatureVerification, R as ReceiverConsent } from '../types-BDOnH5Le.js';
1
+ import { b as PointTokenDomainConfig, M as MintRequest, E as EIP712Signature, S as SignatureVerification, c as BurnRequest, R as ReceiverConsent } from '../types-b5_Tokjl.js';
2
2
  import { WalletClient, Hex, Address } from 'viem';
3
3
 
4
4
  declare function buildDomain(config: PointTokenDomainConfig): {
@@ -41,6 +41,48 @@ declare function buildMintRequestTypedData(domain: PointTokenDomainConfig, messa
41
41
  declare function signMintRequest(walletClient: WalletClient, domain: PointTokenDomainConfig, message: MintRequest): Promise<EIP712Signature>;
42
42
  declare function verifyMintRequest(domain: PointTokenDomainConfig, message: MintRequest, signature: Hex, expectedMinter: Address): Promise<SignatureVerification>;
43
43
 
44
+ /**
45
+ * EIP-712 helpers for `BurnRequest` — consumed by the sig-gated burn
46
+ * path on `PointToken`:
47
+ *
48
+ * burn(address from, uint256 amount, uint256 deadline, bytes burnerSig)
49
+ *
50
+ * Solidity type hash:
51
+ * BurnRequest(address from,uint256 amount,uint256 nonce,uint256 deadline)
52
+ *
53
+ * Issuer backend signs with its burner signer (HSM/KMS). On-chain
54
+ * `msg.sender` must equal `from`, and the recovered signer must be in
55
+ * `burners[]`. Nonce comes from `burnRequestNonces[from]` and is
56
+ * auto-incremented on success.
57
+ */
58
+ declare function buildBurnRequestTypedData(domain: PointTokenDomainConfig, message: BurnRequest): {
59
+ domain: {
60
+ name: string;
61
+ version: "1";
62
+ chainId: number;
63
+ verifyingContract: `0x${string}`;
64
+ };
65
+ types: {
66
+ readonly BurnRequest: readonly [{
67
+ readonly name: "from";
68
+ readonly type: "address";
69
+ }, {
70
+ readonly name: "amount";
71
+ readonly type: "uint256";
72
+ }, {
73
+ readonly name: "nonce";
74
+ readonly type: "uint256";
75
+ }, {
76
+ readonly name: "deadline";
77
+ readonly type: "uint256";
78
+ }];
79
+ };
80
+ primaryType: "BurnRequest";
81
+ message: BurnRequest;
82
+ };
83
+ declare function signBurnRequest(walletClient: WalletClient, domain: PointTokenDomainConfig, message: BurnRequest): Promise<EIP712Signature>;
84
+ declare function verifyBurnRequest(domain: PointTokenDomainConfig, message: BurnRequest, signature: Hex, expectedBurner: Address): Promise<SignatureVerification>;
85
+
44
86
  /**
45
87
  * Build the EIP-712 typed data object for a ReceiverConsent.
46
88
  * Returns the standard `{ domain, types, primaryType, message }` structure
@@ -80,4 +122,4 @@ declare function buildReceiverConsentTypedData(domain: PointTokenDomainConfig, m
80
122
  declare function signReceiverConsent(walletClient: WalletClient, domain: PointTokenDomainConfig, message: ReceiverConsent): Promise<EIP712Signature>;
81
123
  declare function verifyReceiverConsent(domain: PointTokenDomainConfig, message: ReceiverConsent, signature: Hex, expectedReceiver: Address): Promise<SignatureVerification>;
82
124
 
83
- export { buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signMintRequest, signReceiverConsent, verifyMintRequest, verifyReceiverConsent };
125
+ export { buildBurnRequestTypedData, buildDomain, buildMintRequestTypedData, buildReceiverConsentTypedData, signBurnRequest, signMintRequest, signReceiverConsent, verifyBurnRequest, verifyMintRequest, verifyReceiverConsent };
@@ -1,19 +1,25 @@
1
1
  import {
2
+ buildBurnRequestTypedData,
2
3
  buildDomain,
3
4
  buildMintRequestTypedData,
4
5
  buildReceiverConsentTypedData,
6
+ signBurnRequest,
5
7
  signMintRequest,
6
8
  signReceiverConsent,
9
+ verifyBurnRequest,
7
10
  verifyMintRequest,
8
11
  verifyReceiverConsent
9
- } from "../chunk-C4ZDYG4D.js";
10
- import "../chunk-R4L66ZR5.js";
12
+ } from "../chunk-DUY7Z2AI.js";
13
+ import "../chunk-73CQTNLB.js";
11
14
  export {
15
+ buildBurnRequestTypedData,
12
16
  buildDomain,
13
17
  buildMintRequestTypedData,
14
18
  buildReceiverConsentTypedData,
19
+ signBurnRequest,
15
20
  signMintRequest,
16
21
  signReceiverConsent,
22
+ verifyBurnRequest,
17
23
  verifyMintRequest,
18
24
  verifyReceiverConsent
19
25
  };
@@ -0,0 +1,244 @@
1
+ import { Address, Hex, PublicClient } from 'viem';
2
+ import { Q as QuoteResult, d as PathKey } from './types-b5_Tokjl.js';
3
+
4
+ declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
5
+ /**
6
+ * Encode an ERC-20 approve(spender, amount) call.
7
+ */
8
+ declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
9
+ /**
10
+ * Encode a Permit2 approve(token, spender, amount, expiration) call.
11
+ */
12
+ declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
13
+
14
+ /** UniversalRouter command byte for V4 swap */
15
+ declare const V4_SWAP: 16;
16
+ declare const SWAP_EXACT_IN: 7;
17
+ declare const SETTLE_ALL: 12;
18
+ declare const TAKE_ALL: 15;
19
+ /**
20
+ * Build the calldata inputs[0] (the V4_SWAP command payload) for
21
+ * UniversalRouter.execute.
22
+ *
23
+ * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
24
+ *
25
+ * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
26
+ * are individually ABI-encoded, then wrapped together with the action bytes.
27
+ */
28
+ declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
29
+ /**
30
+ * Build the full commands + inputs args for UniversalRouter.execute.
31
+ */
32
+ declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
33
+ commands: Hex;
34
+ inputs: Hex[];
35
+ };
36
+ /**
37
+ * Build UniversalRouter execute args from a quote result.
38
+ *
39
+ * Takes the output of `findBestQuote` / `quoteBestRoute` and produces
40
+ * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
41
+ *
42
+ * @param quote - Quote result containing the path
43
+ * @param currencyIn - Input token address
44
+ * @param currencyOut - Output token address
45
+ * @param amountIn - Exact input amount (same value passed to the quoter)
46
+ * @param minAmountOut - Minimum acceptable output (caller applies slippage)
47
+ *
48
+ * @deprecated Since v1.4 — the Issuer App no longer handles swaps.
49
+ * For the new PT→USDT batch call on PAFI Web (Scenario 4 with
50
+ * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).
51
+ * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.
52
+ */
53
+ declare function buildSwapFromQuote(params: {
54
+ quote: QuoteResult;
55
+ currencyIn: Address;
56
+ currencyOut: Address;
57
+ amountIn: bigint;
58
+ minAmountOut: bigint;
59
+ }): {
60
+ commands: Hex;
61
+ inputs: Hex[];
62
+ };
63
+
64
+ interface SwapSimulationResult {
65
+ success: boolean;
66
+ gasEstimate: bigint;
67
+ }
68
+ /**
69
+ * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
70
+ *
71
+ * Runs the full V4 swap flow — token transfer via Permit2, swap via
72
+ * PoolManager, output settlement — without submitting a transaction.
73
+ * If the simulation reverts, throws a `SimulationError` with the reason.
74
+ *
75
+ * @param client - viem PublicClient
76
+ * @param routerAddress - UniversalRouter contract address
77
+ * @param commands - Packed command bytes (from buildSwapFromQuote)
78
+ * @param inputs - Encoded inputs per command (from buildSwapFromQuote)
79
+ * @param deadline - Unix timestamp after which the tx expires
80
+ * @param from - Address that will execute the swap
81
+ */
82
+ declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
83
+
84
+ /**
85
+ * ERC-4337 v0.7 EntryPoint standard address (deployed deterministically
86
+ * at the same address across chains).
87
+ * https://eips.ethereum.org/EIPS/eip-4337
88
+ */
89
+ declare const ENTRY_POINT_V07: Address;
90
+ /**
91
+ * A single call inside a batch. `BatchExecutor.execute(Call[])` iterates
92
+ * and invokes each one. When the batch runs via EIP-7702 delegation,
93
+ * `msg.sender` for each call is the user's EOA.
94
+ */
95
+ interface Operation {
96
+ target: Address;
97
+ value: bigint;
98
+ data: Hex;
99
+ }
100
+ /**
101
+ * Paymaster fields attached to a UserOperation. Populated by the
102
+ * Coinbase Paymaster (via PAFI Backend proxy) before the user signs.
103
+ */
104
+ interface PaymasterFields {
105
+ paymaster: Address;
106
+ paymasterData: Hex;
107
+ paymasterVerificationGasLimit: bigint;
108
+ paymasterPostOpGasLimit: bigint;
109
+ }
110
+ /**
111
+ * Partial UserOp used during preparation — before paymaster fields are
112
+ * attached or the user signs.
113
+ */
114
+ interface PartialUserOperation {
115
+ sender: Address;
116
+ nonce: bigint;
117
+ callData: Hex;
118
+ callGasLimit: bigint;
119
+ verificationGasLimit: bigint;
120
+ preVerificationGas: bigint;
121
+ maxFeePerGas: bigint;
122
+ maxPriorityFeePerGas: bigint;
123
+ }
124
+ /**
125
+ * Full ERC-4337 v0.7 UserOperation, ready for bundler submission.
126
+ */
127
+ interface UserOperation extends PartialUserOperation {
128
+ paymaster: Address;
129
+ paymasterData: Hex;
130
+ paymasterVerificationGasLimit: bigint;
131
+ paymasterPostOpGasLimit: bigint;
132
+ signature: Hex;
133
+ }
134
+ /**
135
+ * Receipt returned by a bundler after a UserOp lands on-chain.
136
+ */
137
+ interface UserOpReceipt {
138
+ userOpHash: Hex;
139
+ success: boolean;
140
+ txHash: Hex;
141
+ blockNumber: bigint;
142
+ gasUsed: bigint;
143
+ /** Effective gas cost paid (wei). */
144
+ actualGasCost: bigint;
145
+ }
146
+ /**
147
+ * Sentinel operation value used in tests + docs when `Operation.value`
148
+ * is irrelevant (ERC-20 transfers, for example).
149
+ */
150
+ declare const ZERO_VALUE = 0n;
151
+
152
+ /**
153
+ * v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with **gas fee
154
+ * deducted in PT** from the user's balance.
155
+ *
156
+ * Builds an unsigned `PartialUserOperation` that packages three inner
157
+ * calls into a single `BatchExecutor.execute(calls[])`:
158
+ *
159
+ * 1. `PT.approve(UniversalRouter, amountIn)` — let the router pull
160
+ * `amountIn` PT for the swap
161
+ * 2. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap
162
+ * PT → USDT, user receives `minAmountOut` USDT
163
+ * 3. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back
164
+ * for sponsoring the gas, in PT (application-level recovery —
165
+ * no custom paymaster contract needed)
166
+ *
167
+ * The user's wallet must hold `amountIn + gasFeePt` PT **before** the
168
+ * UserOp runs. The three inner calls execute atomically via
169
+ * EIP-7702 delegation (`msg.sender = user`), so a reverting swap
170
+ * unwinds the approve + fee transfer too.
171
+ *
172
+ * ## Fee model
173
+ *
174
+ * Exact-out on the **USDT side** is not attempted here. The user
175
+ * specifies `amountIn` PT for the swap; the minimum USDT out comes
176
+ * from a separate quote (not this function). The gas fee is a
177
+ * separate `transfer` call — it does NOT come out of the swap's USDT
178
+ * output, because that output goes straight to the user's wallet with
179
+ * no intermediate hook to skim from.
180
+ *
181
+ * If the FE wants "user receives exactly X USDT after gas", it should:
182
+ * 1. Quote PT→USDT for candidate `amountIn` values
183
+ * 2. Pick an `amountIn` where `minAmountOut ≈ X`
184
+ * 3. Separately compute `gasFeePt` from the operator's rate
185
+ * 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`
186
+ *
187
+ * ## Order of operations
188
+ *
189
+ * Approve → swap → fee transfer. The fee transfer comes **last** so
190
+ * if the swap reverts, the user is also refunded the fee (atomic
191
+ * batch revert). Doing fee transfer first would still unwind on
192
+ * revert, but ordering it last matches the intuitive "only charge
193
+ * gas on success" semantics.
194
+ */
195
+ interface BuildSwapWithGasDeductionParams {
196
+ /** User's EOA (with EIP-7702 delegation to BatchExecutor). */
197
+ userAddress: Address;
198
+ /** ERC-4337 account nonce — fetched from EntryPoint by the caller. */
199
+ aaNonce: bigint;
200
+ /** PT token address being swapped. */
201
+ pointTokenAddress: Address;
202
+ /** Destination currency (typically USDT). */
203
+ outputTokenAddress: Address;
204
+ /** UniversalRouter contract address (chain-specific). */
205
+ universalRouterAddress: Address;
206
+ /** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */
207
+ amountIn: bigint;
208
+ /**
209
+ * Minimum USDT to accept out of the swap. Caller applies slippage
210
+ * (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.
211
+ */
212
+ minAmountOut: bigint;
213
+ /** V4 pool path for the swap. Single-hop = 1 PathKey. */
214
+ swapPath: PathKey[];
215
+ /** Unix seconds. After this, the router rejects the swap. */
216
+ deadline: bigint;
217
+ /** PT amount transferred to `feeRecipient` as gas fee recovery. */
218
+ gasFeePt: bigint;
219
+ /** Where the gas fee lands — typically the operator or fee collector. */
220
+ feeRecipient: Address;
221
+ /**
222
+ * Optional — pre-signed Permit2 / EIP-2612 approval. If omitted, a
223
+ * standard `approve()` call is appended as the first batch op.
224
+ * Future work: support Permit2 so the approve is part of the swap
225
+ * input rather than a separate call.
226
+ */
227
+ gasLimits?: {
228
+ callGasLimit?: bigint;
229
+ verificationGasLimit?: bigint;
230
+ preVerificationGas?: bigint;
231
+ };
232
+ }
233
+ /**
234
+ * Build an unsigned UserOp for Scenario 4. Returns a
235
+ * `PartialUserOperation` — caller attaches paymaster sponsorship (via
236
+ * `POST /api/paymaster/sponsor`), adds the user's UserOp-hash
237
+ * signature, and submits to the Bundler.
238
+ *
239
+ * @throws when `amountIn` or `gasFeePt` is not positive, or when
240
+ * `swapPath` is empty (at least one PathKey required).
241
+ */
242
+ declare function buildSwapWithGasDeduction(params: BuildSwapWithGasDeductionParams): PartialUserOperation;
243
+
244
+ export { type BuildSwapWithGasDeductionParams as B, ENTRY_POINT_V07 as E, type Operation as O, type PartialUserOperation as P, type SwapSimulationResult as S, TAKE_ALL as T, type UserOperation as U, V4_SWAP as V, ZERO_VALUE as Z, type PaymasterFields as a, SETTLE_ALL as b, SWAP_EXACT_IN as c, type UserOpReceipt as d, buildErc20ApprovalCalldata as e, buildPermit2ApprovalCalldata as f, buildSwapFromQuote as g, buildSwapWithGasDeduction as h, buildUniversalRouterExecuteArgs as i, buildV4SwapInput as j, checkAllowance as k, simulateSwap as s };
@@ -0,0 +1,244 @@
1
+ import { Address, Hex, PublicClient } from 'viem';
2
+ import { Q as QuoteResult, d as PathKey } from './types-b5_Tokjl.cjs';
3
+
4
+ declare function checkAllowance(client: PublicClient, token: Address, owner: Address, spender: Address): Promise<bigint>;
5
+ /**
6
+ * Encode an ERC-20 approve(spender, amount) call.
7
+ */
8
+ declare function buildErc20ApprovalCalldata(spender: Address, amount: bigint): Hex;
9
+ /**
10
+ * Encode a Permit2 approve(token, spender, amount, expiration) call.
11
+ */
12
+ declare function buildPermit2ApprovalCalldata(token: Address, spender: Address, amount: bigint, expiration: number): Hex;
13
+
14
+ /** UniversalRouter command byte for V4 swap */
15
+ declare const V4_SWAP: 16;
16
+ declare const SWAP_EXACT_IN: 7;
17
+ declare const SETTLE_ALL: 12;
18
+ declare const TAKE_ALL: 15;
19
+ /**
20
+ * Build the calldata inputs[0] (the V4_SWAP command payload) for
21
+ * UniversalRouter.execute.
22
+ *
23
+ * Actions encoded: SWAP_EXACT_IN → SETTLE_ALL → TAKE_ALL
24
+ *
25
+ * Encoding matches the Uniswap V4 SDK's V4Planner — each action's params
26
+ * are individually ABI-encoded, then wrapped together with the action bytes.
27
+ */
28
+ declare function buildV4SwapInput(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): Hex;
29
+ /**
30
+ * Build the full commands + inputs args for UniversalRouter.execute.
31
+ */
32
+ declare function buildUniversalRouterExecuteArgs(currencyIn: Address, path: PathKey[], amountIn: bigint, minAmountOut: bigint, outputCurrency: Address): {
33
+ commands: Hex;
34
+ inputs: Hex[];
35
+ };
36
+ /**
37
+ * Build UniversalRouter execute args from a quote result.
38
+ *
39
+ * Takes the output of `findBestQuote` / `quoteBestRoute` and produces
40
+ * ready-to-use `{ commands, inputs }` for `UniversalRouter.execute`.
41
+ *
42
+ * @param quote - Quote result containing the path
43
+ * @param currencyIn - Input token address
44
+ * @param currencyOut - Output token address
45
+ * @param amountIn - Exact input amount (same value passed to the quoter)
46
+ * @param minAmountOut - Minimum acceptable output (caller applies slippage)
47
+ *
48
+ * @deprecated Since v1.4 — the Issuer App no longer handles swaps.
49
+ * For the new PT→USDT batch call on PAFI Web (Scenario 4 with
50
+ * EIP-7702 gas deduction), use `buildSwapWithGasDeduction()` (v1.5).
51
+ * This helper is kept for legacy v0.2.x consumers; will be removed in v2.0.
52
+ */
53
+ declare function buildSwapFromQuote(params: {
54
+ quote: QuoteResult;
55
+ currencyIn: Address;
56
+ currencyOut: Address;
57
+ amountIn: bigint;
58
+ minAmountOut: bigint;
59
+ }): {
60
+ commands: Hex;
61
+ inputs: Hex[];
62
+ };
63
+
64
+ interface SwapSimulationResult {
65
+ success: boolean;
66
+ gasEstimate: bigint;
67
+ }
68
+ /**
69
+ * Simulate a UniversalRouter.execute swap call via eth_call (no gas spent).
70
+ *
71
+ * Runs the full V4 swap flow — token transfer via Permit2, swap via
72
+ * PoolManager, output settlement — without submitting a transaction.
73
+ * If the simulation reverts, throws a `SimulationError` with the reason.
74
+ *
75
+ * @param client - viem PublicClient
76
+ * @param routerAddress - UniversalRouter contract address
77
+ * @param commands - Packed command bytes (from buildSwapFromQuote)
78
+ * @param inputs - Encoded inputs per command (from buildSwapFromQuote)
79
+ * @param deadline - Unix timestamp after which the tx expires
80
+ * @param from - Address that will execute the swap
81
+ */
82
+ declare function simulateSwap(client: PublicClient, routerAddress: Address, commands: Hex, inputs: Hex[], deadline: bigint, from: Address): Promise<SwapSimulationResult>;
83
+
84
+ /**
85
+ * ERC-4337 v0.7 EntryPoint standard address (deployed deterministically
86
+ * at the same address across chains).
87
+ * https://eips.ethereum.org/EIPS/eip-4337
88
+ */
89
+ declare const ENTRY_POINT_V07: Address;
90
+ /**
91
+ * A single call inside a batch. `BatchExecutor.execute(Call[])` iterates
92
+ * and invokes each one. When the batch runs via EIP-7702 delegation,
93
+ * `msg.sender` for each call is the user's EOA.
94
+ */
95
+ interface Operation {
96
+ target: Address;
97
+ value: bigint;
98
+ data: Hex;
99
+ }
100
+ /**
101
+ * Paymaster fields attached to a UserOperation. Populated by the
102
+ * Coinbase Paymaster (via PAFI Backend proxy) before the user signs.
103
+ */
104
+ interface PaymasterFields {
105
+ paymaster: Address;
106
+ paymasterData: Hex;
107
+ paymasterVerificationGasLimit: bigint;
108
+ paymasterPostOpGasLimit: bigint;
109
+ }
110
+ /**
111
+ * Partial UserOp used during preparation — before paymaster fields are
112
+ * attached or the user signs.
113
+ */
114
+ interface PartialUserOperation {
115
+ sender: Address;
116
+ nonce: bigint;
117
+ callData: Hex;
118
+ callGasLimit: bigint;
119
+ verificationGasLimit: bigint;
120
+ preVerificationGas: bigint;
121
+ maxFeePerGas: bigint;
122
+ maxPriorityFeePerGas: bigint;
123
+ }
124
+ /**
125
+ * Full ERC-4337 v0.7 UserOperation, ready for bundler submission.
126
+ */
127
+ interface UserOperation extends PartialUserOperation {
128
+ paymaster: Address;
129
+ paymasterData: Hex;
130
+ paymasterVerificationGasLimit: bigint;
131
+ paymasterPostOpGasLimit: bigint;
132
+ signature: Hex;
133
+ }
134
+ /**
135
+ * Receipt returned by a bundler after a UserOp lands on-chain.
136
+ */
137
+ interface UserOpReceipt {
138
+ userOpHash: Hex;
139
+ success: boolean;
140
+ txHash: Hex;
141
+ blockNumber: bigint;
142
+ gasUsed: bigint;
143
+ /** Effective gas cost paid (wei). */
144
+ actualGasCost: bigint;
145
+ }
146
+ /**
147
+ * Sentinel operation value used in tests + docs when `Operation.value`
148
+ * is irrelevant (ERC-20 transfers, for example).
149
+ */
150
+ declare const ZERO_VALUE = 0n;
151
+
152
+ /**
153
+ * v1.5 — Scenario 4: Swap PT → USDT on PAFI Web with **gas fee
154
+ * deducted in PT** from the user's balance.
155
+ *
156
+ * Builds an unsigned `PartialUserOperation` that packages three inner
157
+ * calls into a single `BatchExecutor.execute(calls[])`:
158
+ *
159
+ * 1. `PT.approve(UniversalRouter, amountIn)` — let the router pull
160
+ * `amountIn` PT for the swap
161
+ * 2. `UniversalRouter.execute(commands, inputs, deadline)` — V4 swap
162
+ * PT → USDT, user receives `minAmountOut` USDT
163
+ * 3. `PT.transfer(feeRecipient, gasFeePt)` — pay the operator back
164
+ * for sponsoring the gas, in PT (application-level recovery —
165
+ * no custom paymaster contract needed)
166
+ *
167
+ * The user's wallet must hold `amountIn + gasFeePt` PT **before** the
168
+ * UserOp runs. The three inner calls execute atomically via
169
+ * EIP-7702 delegation (`msg.sender = user`), so a reverting swap
170
+ * unwinds the approve + fee transfer too.
171
+ *
172
+ * ## Fee model
173
+ *
174
+ * Exact-out on the **USDT side** is not attempted here. The user
175
+ * specifies `amountIn` PT for the swap; the minimum USDT out comes
176
+ * from a separate quote (not this function). The gas fee is a
177
+ * separate `transfer` call — it does NOT come out of the swap's USDT
178
+ * output, because that output goes straight to the user's wallet with
179
+ * no intermediate hook to skim from.
180
+ *
181
+ * If the FE wants "user receives exactly X USDT after gas", it should:
182
+ * 1. Quote PT→USDT for candidate `amountIn` values
183
+ * 2. Pick an `amountIn` where `minAmountOut ≈ X`
184
+ * 3. Separately compute `gasFeePt` from the operator's rate
185
+ * 4. Ensure user's PT balance ≥ `amountIn + gasFeePt`
186
+ *
187
+ * ## Order of operations
188
+ *
189
+ * Approve → swap → fee transfer. The fee transfer comes **last** so
190
+ * if the swap reverts, the user is also refunded the fee (atomic
191
+ * batch revert). Doing fee transfer first would still unwind on
192
+ * revert, but ordering it last matches the intuitive "only charge
193
+ * gas on success" semantics.
194
+ */
195
+ interface BuildSwapWithGasDeductionParams {
196
+ /** User's EOA (with EIP-7702 delegation to BatchExecutor). */
197
+ userAddress: Address;
198
+ /** ERC-4337 account nonce — fetched from EntryPoint by the caller. */
199
+ aaNonce: bigint;
200
+ /** PT token address being swapped. */
201
+ pointTokenAddress: Address;
202
+ /** Destination currency (typically USDT). */
203
+ outputTokenAddress: Address;
204
+ /** UniversalRouter contract address (chain-specific). */
205
+ universalRouterAddress: Address;
206
+ /** PT units to swap. User's balance must be ≥ `amountIn + gasFeePt`. */
207
+ amountIn: bigint;
208
+ /**
209
+ * Minimum USDT to accept out of the swap. Caller applies slippage
210
+ * (typically ~0.5-1%) against a fresh quote. Sub-minimum swap reverts.
211
+ */
212
+ minAmountOut: bigint;
213
+ /** V4 pool path for the swap. Single-hop = 1 PathKey. */
214
+ swapPath: PathKey[];
215
+ /** Unix seconds. After this, the router rejects the swap. */
216
+ deadline: bigint;
217
+ /** PT amount transferred to `feeRecipient` as gas fee recovery. */
218
+ gasFeePt: bigint;
219
+ /** Where the gas fee lands — typically the operator or fee collector. */
220
+ feeRecipient: Address;
221
+ /**
222
+ * Optional — pre-signed Permit2 / EIP-2612 approval. If omitted, a
223
+ * standard `approve()` call is appended as the first batch op.
224
+ * Future work: support Permit2 so the approve is part of the swap
225
+ * input rather than a separate call.
226
+ */
227
+ gasLimits?: {
228
+ callGasLimit?: bigint;
229
+ verificationGasLimit?: bigint;
230
+ preVerificationGas?: bigint;
231
+ };
232
+ }
233
+ /**
234
+ * Build an unsigned UserOp for Scenario 4. Returns a
235
+ * `PartialUserOperation` — caller attaches paymaster sponsorship (via
236
+ * `POST /api/paymaster/sponsor`), adds the user's UserOp-hash
237
+ * signature, and submits to the Bundler.
238
+ *
239
+ * @throws when `amountIn` or `gasFeePt` is not positive, or when
240
+ * `swapPath` is empty (at least one PathKey required).
241
+ */
242
+ declare function buildSwapWithGasDeduction(params: BuildSwapWithGasDeductionParams): PartialUserOperation;
243
+
244
+ export { type BuildSwapWithGasDeductionParams as B, ENTRY_POINT_V07 as E, type Operation as O, type PartialUserOperation as P, type SwapSimulationResult as S, TAKE_ALL as T, type UserOperation as U, V4_SWAP as V, ZERO_VALUE as Z, type PaymasterFields as a, SETTLE_ALL as b, SWAP_EXACT_IN as c, type UserOpReceipt as d, buildErc20ApprovalCalldata as e, buildPermit2ApprovalCalldata as f, buildSwapFromQuote as g, buildSwapWithGasDeduction as h, buildUniversalRouterExecuteArgs as i, buildV4SwapInput as j, checkAllowance as k, simulateSwap as s };