@pafi-dev/core 0.1.2 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/{chunk-O7LQKCBT.cjs → chunk-6I6K43RQ.cjs} +1 -1
- package/dist/chunk-6I6K43RQ.cjs.map +1 -0
- package/dist/{chunk-4QOWQQCH.cjs → chunk-L74CZAVQ.cjs} +1 -1
- package/dist/chunk-L74CZAVQ.cjs.map +1 -0
- package/dist/{chunk-37BBGXTS.js → chunk-UU72CX7E.js} +1 -1
- package/dist/{chunk-37BBGXTS.js.map → chunk-UU72CX7E.js.map} +1 -1
- package/dist/{chunk-DSCUHT3F.js → chunk-X4IXUTTD.js} +1 -1
- package/dist/chunk-X4IXUTTD.js.map +1 -0
- package/dist/index.cjs +164 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +271 -2
- package/dist/index.d.ts +271 -2
- package/dist/index.js +155 -2
- package/dist/index.js.map +1 -1
- package/dist/relay/index.cjs +2 -2
- package/dist/relay/index.d.cts +13 -0
- package/dist/relay/index.d.ts +13 -0
- package/dist/relay/index.js +1 -1
- package/dist/swap/index.cjs +2 -2
- package/dist/swap/index.d.cts +5 -0
- package/dist/swap/index.d.ts +5 -0
- package/dist/swap/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-4QOWQQCH.cjs.map +0 -1
- package/dist/chunk-DSCUHT3F.js.map +0 -1
- package/dist/chunk-O7LQKCBT.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address,
|
|
1
|
+
import { Address, Hex, PublicClient, WalletClient } from 'viem';
|
|
2
2
|
import { P as PoolKey, C as ChainConfig, a as PafiSDKConfig, b as PointTokenDomainConfig, M as MintRequest, R as ReceiverConsent, E as EIP712Signature, S as SignatureVerification, c as MintParams, d as SwapParams, B as BestQuote, Q as QuoteResult, e as PathKey } from './types-CkRJzrZr.cjs';
|
|
3
3
|
export { I as Issuer } from './types-CkRJzrZr.cjs';
|
|
4
4
|
export { erc20Abi, issuerRegistryAbi, mintingOracleAbi, permit2Abi, pointTokenAbi, pointTokenFactoryAbi, relayAbi, universalRouterAbi, v4QuoterAbi } from './abi/index.cjs';
|
|
@@ -74,6 +74,275 @@ declare class ApiError extends PafiSDKError {
|
|
|
74
74
|
constructor(message: string, status?: number | undefined);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* ERC-4337 v0.7 EntryPoint standard address (deployed deterministically
|
|
79
|
+
* at the same address across chains).
|
|
80
|
+
* https://eips.ethereum.org/EIPS/eip-4337
|
|
81
|
+
*/
|
|
82
|
+
declare const ENTRY_POINT_V07: Address;
|
|
83
|
+
/**
|
|
84
|
+
* A single call inside a batch. `BatchExecutor.execute(Call[])` iterates
|
|
85
|
+
* and invokes each one. When the batch runs via EIP-7702 delegation,
|
|
86
|
+
* `msg.sender` for each call is the user's EOA.
|
|
87
|
+
*/
|
|
88
|
+
interface Operation {
|
|
89
|
+
target: Address;
|
|
90
|
+
value: bigint;
|
|
91
|
+
data: Hex;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Paymaster fields attached to a UserOperation. Populated by the
|
|
95
|
+
* Coinbase Paymaster (via PAFI Backend proxy) before the user signs.
|
|
96
|
+
*/
|
|
97
|
+
interface PaymasterFields {
|
|
98
|
+
paymaster: Address;
|
|
99
|
+
paymasterData: Hex;
|
|
100
|
+
paymasterVerificationGasLimit: bigint;
|
|
101
|
+
paymasterPostOpGasLimit: bigint;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Partial UserOp used during preparation — before paymaster fields are
|
|
105
|
+
* attached or the user signs.
|
|
106
|
+
*/
|
|
107
|
+
interface PartialUserOperation {
|
|
108
|
+
sender: Address;
|
|
109
|
+
nonce: bigint;
|
|
110
|
+
callData: Hex;
|
|
111
|
+
callGasLimit: bigint;
|
|
112
|
+
verificationGasLimit: bigint;
|
|
113
|
+
preVerificationGas: bigint;
|
|
114
|
+
maxFeePerGas: bigint;
|
|
115
|
+
maxPriorityFeePerGas: bigint;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Full ERC-4337 v0.7 UserOperation, ready for bundler submission.
|
|
119
|
+
*/
|
|
120
|
+
interface UserOperation extends PartialUserOperation {
|
|
121
|
+
paymaster: Address;
|
|
122
|
+
paymasterData: Hex;
|
|
123
|
+
paymasterVerificationGasLimit: bigint;
|
|
124
|
+
paymasterPostOpGasLimit: bigint;
|
|
125
|
+
signature: Hex;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Receipt returned by a bundler after a UserOp lands on-chain.
|
|
129
|
+
*/
|
|
130
|
+
interface UserOpReceipt {
|
|
131
|
+
userOpHash: Hex;
|
|
132
|
+
success: boolean;
|
|
133
|
+
txHash: Hex;
|
|
134
|
+
blockNumber: bigint;
|
|
135
|
+
gasUsed: bigint;
|
|
136
|
+
/** Effective gas cost paid (wei). */
|
|
137
|
+
actualGasCost: bigint;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sentinel operation value used in tests + docs when `Operation.value`
|
|
141
|
+
* is irrelevant (ERC-20 transfers, for example).
|
|
142
|
+
*/
|
|
143
|
+
declare const ZERO_VALUE = 0n;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch
|
|
147
|
+
* to move fee tokens from the user to the fee recipient atomically with
|
|
148
|
+
* the main action.
|
|
149
|
+
*/
|
|
150
|
+
declare function erc20TransferOp(token: Address, to: Address, amount: bigint): Operation;
|
|
151
|
+
/**
|
|
152
|
+
* Build an ERC-20 `approve(spender, amount)` operation. Used inside a
|
|
153
|
+
* batch before a swap / deposit call so the AMM / protocol can pull
|
|
154
|
+
* tokens from the user.
|
|
155
|
+
*/
|
|
156
|
+
declare function erc20ApproveOp(token: Address, spender: Address, amount: bigint): Operation;
|
|
157
|
+
/**
|
|
158
|
+
* Build an ERC-20 `burn(amount)` operation (OpenZeppelin ERC20Burnable
|
|
159
|
+
* extension). Burns from `msg.sender`, which — via EIP-7702 — is the
|
|
160
|
+
* user's EOA.
|
|
161
|
+
*
|
|
162
|
+
* Requires the PointToken contract to expose a public `burn(uint256)`
|
|
163
|
+
* without a role check. See
|
|
164
|
+
* [SDK_V1.4_TASKS.md §11 — PointToken.burn callable via batch].
|
|
165
|
+
*/
|
|
166
|
+
declare function erc20BurnOp(token: Address, amount: bigint): Operation;
|
|
167
|
+
/**
|
|
168
|
+
* Build a raw call operation with caller-supplied calldata. Useful for
|
|
169
|
+
* non-ERC-20 contracts (PoolManager.swap, PerpDEX.deposit, Relayer.mint)
|
|
170
|
+
* where the encoding is specific to that protocol.
|
|
171
|
+
*/
|
|
172
|
+
declare function rawCallOp(target: Address, data: `0x${string}`, value?: bigint): Operation;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Standard BatchExecutor ABI — a contract that takes an array of calls
|
|
176
|
+
* and invokes each one in sequence, reverting all if any fail.
|
|
177
|
+
*
|
|
178
|
+
* Compatible with OpenZeppelin `Account.execute(Call[])`, Biconomy
|
|
179
|
+
* `executeBatch`, Safe `MultiSend`, and most EIP-7702 delegation
|
|
180
|
+
* targets. The exact deployed address is supplied by the infra team
|
|
181
|
+
* (see [V1.4_V1.5_READINESS.md B2]).
|
|
182
|
+
*/
|
|
183
|
+
declare const BATCH_EXECUTOR_ABI: readonly [{
|
|
184
|
+
readonly name: "execute";
|
|
185
|
+
readonly type: "function";
|
|
186
|
+
readonly stateMutability: "nonpayable";
|
|
187
|
+
readonly inputs: readonly [{
|
|
188
|
+
readonly type: "tuple[]";
|
|
189
|
+
readonly components: readonly [{
|
|
190
|
+
readonly type: "address";
|
|
191
|
+
readonly name: "target";
|
|
192
|
+
}, {
|
|
193
|
+
readonly type: "uint256";
|
|
194
|
+
readonly name: "value";
|
|
195
|
+
}, {
|
|
196
|
+
readonly type: "bytes";
|
|
197
|
+
readonly name: "data";
|
|
198
|
+
}];
|
|
199
|
+
readonly name: "calls";
|
|
200
|
+
}];
|
|
201
|
+
readonly outputs: readonly [];
|
|
202
|
+
}];
|
|
203
|
+
/**
|
|
204
|
+
* Encode a batch of operations into calldata for `BatchExecutor.execute()`.
|
|
205
|
+
* The resulting calldata goes into `UserOperation.callData`.
|
|
206
|
+
*
|
|
207
|
+
* When the EOA has an EIP-7702 delegation to a BatchExecutor, calling
|
|
208
|
+
* this calldata against the EOA runs all operations with
|
|
209
|
+
* `msg.sender = EOA` for each inner call.
|
|
210
|
+
*
|
|
211
|
+
* @param operations batch of calls, in execution order
|
|
212
|
+
* @returns calldata bytes for `execute((address,uint256,bytes)[])`
|
|
213
|
+
*/
|
|
214
|
+
declare function encodeBatchExecute(operations: Operation[]): Hex;
|
|
215
|
+
|
|
216
|
+
interface BuildPartialUserOpParams {
|
|
217
|
+
/** User's EOA (with EIP-7702 delegation). */
|
|
218
|
+
sender: Address;
|
|
219
|
+
/** Batch of operations — encoded into callData via `encodeBatchExecute`. */
|
|
220
|
+
operations: Operation[];
|
|
221
|
+
/** EntryPoint nonce for this sender. Caller fetches from the EntryPoint contract. */
|
|
222
|
+
nonce: bigint;
|
|
223
|
+
/** Optional gas overrides; bundler re-estimates before submission. */
|
|
224
|
+
gasLimits?: {
|
|
225
|
+
callGasLimit?: bigint;
|
|
226
|
+
verificationGasLimit?: bigint;
|
|
227
|
+
preVerificationGas?: bigint;
|
|
228
|
+
};
|
|
229
|
+
/** Optional fee overrides; bundler usually fills these. */
|
|
230
|
+
feeOverrides?: {
|
|
231
|
+
maxFeePerGas?: bigint;
|
|
232
|
+
maxPriorityFeePerGas?: bigint;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Build a partial ERC-4337 UserOperation from a batch of operations.
|
|
237
|
+
* Paymaster fields and signature are populated later:
|
|
238
|
+
* 1. Call `PafiBackendClient.requestSponsorship()` → get paymaster fields
|
|
239
|
+
* 2. Compute userOpHash and have the user sign it (via Privy)
|
|
240
|
+
* 3. Attach `signature` → submit to bundler
|
|
241
|
+
*
|
|
242
|
+
* This function is a pure struct builder — no network calls.
|
|
243
|
+
*/
|
|
244
|
+
declare function buildPartialUserOperation(params: BuildPartialUserOpParams): PartialUserOperation;
|
|
245
|
+
/**
|
|
246
|
+
* Assemble a full UserOperation once paymaster fields + signature are
|
|
247
|
+
* known. Used after `PafiBackendClient.requestSponsorship()` and user
|
|
248
|
+
* signing complete.
|
|
249
|
+
*/
|
|
250
|
+
declare function assembleUserOperation(partial: PartialUserOperation, paymaster: {
|
|
251
|
+
paymaster: Address;
|
|
252
|
+
paymasterData: `0x${string}`;
|
|
253
|
+
paymasterVerificationGasLimit: bigint;
|
|
254
|
+
paymasterPostOpGasLimit: bigint;
|
|
255
|
+
}, signature: `0x${string}`): UserOperation;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Module-level paymaster config shared by all batch builders and the
|
|
259
|
+
* `@pafi/issuer` RelayService. Holds the fee recipient address and the
|
|
260
|
+
* PAFI-assigned issuer identity.
|
|
261
|
+
*
|
|
262
|
+
* v1.4 update: the paymaster endpoint is **PAFI Backend**, which proxies
|
|
263
|
+
* to Coinbase Paymaster. See [SPONSORED_PATH_FLOW.md].
|
|
264
|
+
*/
|
|
265
|
+
interface PaymasterConfig {
|
|
266
|
+
/**
|
|
267
|
+
* PAFI Backend API base URL. Example:
|
|
268
|
+
* https://api.pacificfinance.org/paymaster
|
|
269
|
+
*/
|
|
270
|
+
pafiBackendUrl: string;
|
|
271
|
+
/** PAFI-assigned issuer ID. Passed in X-Issuer-Id header. */
|
|
272
|
+
issuerId: string;
|
|
273
|
+
/** Per-issuer API key (or JWT) for Authorization header. */
|
|
274
|
+
apiKey: string;
|
|
275
|
+
/**
|
|
276
|
+
* Where the fee transfer lands inside the batch call. Fee recovery is
|
|
277
|
+
* application-level — Paymaster sponsors gas, fee is a separate
|
|
278
|
+
* ERC-20 transfer inside the batch that reimburses the issuer.
|
|
279
|
+
*/
|
|
280
|
+
feeRecipient: Address;
|
|
281
|
+
/** EIP-4337 EntryPoint address. Default: v0.7 (same across chains). */
|
|
282
|
+
entryPoint?: Address;
|
|
283
|
+
/** Chain ID the paymaster sponsors on. Defaults to consumer config. */
|
|
284
|
+
chainId?: number;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Which PAFI-defined scenario this UserOp represents. PAFI Backend
|
|
288
|
+
* validates the request's target contracts + function selectors
|
|
289
|
+
* match the expected pattern for the scenario.
|
|
290
|
+
*/
|
|
291
|
+
type SponsorshipScenario = "mint" | "burn" | "swap" | "perp-deposit";
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Set the application-wide paymaster config. Safe to call multiple
|
|
295
|
+
* times (later calls override earlier). Throws if required fields
|
|
296
|
+
* are missing.
|
|
297
|
+
*/
|
|
298
|
+
declare function setPaymasterConfig(config: PaymasterConfig): void;
|
|
299
|
+
/**
|
|
300
|
+
* Get the current paymaster config. Throws if `setPaymasterConfig()`
|
|
301
|
+
* has not been called yet — this surfaces boot-order bugs early
|
|
302
|
+
* instead of failing with "paymaster.feeRecipient is undefined" at
|
|
303
|
+
* the point of use.
|
|
304
|
+
*/
|
|
305
|
+
declare function getPaymasterConfig(): PaymasterConfig;
|
|
306
|
+
/** Test helper — clear the singleton. */
|
|
307
|
+
declare function _resetPaymasterConfigForTests(): void;
|
|
308
|
+
/** Check whether paymaster config has been initialized. */
|
|
309
|
+
declare function isPaymasterConfigured(): boolean;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Submission path chosen by `checkEthAndBranch`.
|
|
313
|
+
* - `normal`: initiator has enough ETH; submit via `walletClient.writeContract`
|
|
314
|
+
* or a plain `eth_sendRawTransaction`. No paymaster round-trip.
|
|
315
|
+
* - `paymaster`: initiator doesn't have enough ETH; wrap the batch as a
|
|
316
|
+
* UserOperation and route through PAFI Backend → Coinbase Paymaster
|
|
317
|
+
* → Bundler.
|
|
318
|
+
*/
|
|
319
|
+
type SubmissionPath = "normal" | "paymaster";
|
|
320
|
+
interface CheckEthAndBranchParams {
|
|
321
|
+
/** viem PublicClient bound to the target chain. */
|
|
322
|
+
client: PublicClient;
|
|
323
|
+
/** The address whose ETH balance we check. */
|
|
324
|
+
initiator: Address;
|
|
325
|
+
/** Estimated gas cost in wei for the upcoming tx. */
|
|
326
|
+
estimatedGasWei: bigint;
|
|
327
|
+
/**
|
|
328
|
+
* Optional safety margin multiplier (basis points). Defaults to
|
|
329
|
+
* 11_000 (110%) — the initiator needs 10% above the estimate to
|
|
330
|
+
* qualify for the normal path. Prevents edge cases where gas price
|
|
331
|
+
* spikes between estimation and submission cause a "has enough"
|
|
332
|
+
* decision to fail at broadcast time.
|
|
333
|
+
*/
|
|
334
|
+
marginBps?: number;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Step 3 of the Generalized Flow ([SPONSORED_PATH_FLOW.md §2]):
|
|
338
|
+
* choose between the normal path (initiator pays ETH directly) and the
|
|
339
|
+
* paymaster path (bundler + Coinbase Paymaster).
|
|
340
|
+
*
|
|
341
|
+
* Intentionally synchronous in spirit — the only network call is
|
|
342
|
+
* `getBalance`. Callers can parallelize it with other reads.
|
|
343
|
+
*/
|
|
344
|
+
declare function checkEthAndBranch(params: CheckEthAndBranchParams): Promise<SubmissionPath>;
|
|
345
|
+
|
|
77
346
|
declare class PafiSDK {
|
|
78
347
|
private _pointTokenAddress?;
|
|
79
348
|
private _relayContractAddress?;
|
|
@@ -236,4 +505,4 @@ declare class PafiSDK {
|
|
|
236
505
|
signLoginMessage(message: string): Promise<Hex>;
|
|
237
506
|
}
|
|
238
507
|
|
|
239
|
-
export { ApiError, BestQuote, COMMON_POOLS, COMMON_TOKENS, ChainConfig, ConfigurationError, EIP712Signature, LoginMessageParams, MintParams, MintRequest, POINT_TOKEN_POOLS, PafiSDK, PafiSDKConfig, PafiSDKError, PathKey, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, SignatureVerification, SigningError, SimulationError, SimulationResult, SwapParams, SwapSimulationResult, UNIVERSAL_ROUTER_ADDRESSES, V4_QUOTER_ADDRESSES, mintRequestTypes, receiverConsentTypes };
|
|
508
|
+
export { ApiError, BATCH_EXECUTOR_ABI, BestQuote, type BuildPartialUserOpParams, COMMON_POOLS, COMMON_TOKENS, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, EIP712Signature, ENTRY_POINT_V07, LoginMessageParams, MintParams, MintRequest, type Operation, POINT_TOKEN_POOLS, PafiSDK, PafiSDKConfig, PafiSDKError, type PartialUserOperation, PathKey, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, SignatureVerification, SigningError, SimulationError, SimulationResult, type SponsorshipScenario, type SubmissionPath, SwapParams, SwapSimulationResult, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOperation, V4_QUOTER_ADDRESSES, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildPartialUserOperation, checkEthAndBranch, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, getPaymasterConfig, isPaymasterConfigured, mintRequestTypes, rawCallOp, receiverConsentTypes, setPaymasterConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address,
|
|
1
|
+
import { Address, Hex, PublicClient, WalletClient } from 'viem';
|
|
2
2
|
import { P as PoolKey, C as ChainConfig, a as PafiSDKConfig, b as PointTokenDomainConfig, M as MintRequest, R as ReceiverConsent, E as EIP712Signature, S as SignatureVerification, c as MintParams, d as SwapParams, B as BestQuote, Q as QuoteResult, e as PathKey } from './types-CkRJzrZr.js';
|
|
3
3
|
export { I as Issuer } from './types-CkRJzrZr.js';
|
|
4
4
|
export { erc20Abi, issuerRegistryAbi, mintingOracleAbi, permit2Abi, pointTokenAbi, pointTokenFactoryAbi, relayAbi, universalRouterAbi, v4QuoterAbi } from './abi/index.js';
|
|
@@ -74,6 +74,275 @@ declare class ApiError extends PafiSDKError {
|
|
|
74
74
|
constructor(message: string, status?: number | undefined);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* ERC-4337 v0.7 EntryPoint standard address (deployed deterministically
|
|
79
|
+
* at the same address across chains).
|
|
80
|
+
* https://eips.ethereum.org/EIPS/eip-4337
|
|
81
|
+
*/
|
|
82
|
+
declare const ENTRY_POINT_V07: Address;
|
|
83
|
+
/**
|
|
84
|
+
* A single call inside a batch. `BatchExecutor.execute(Call[])` iterates
|
|
85
|
+
* and invokes each one. When the batch runs via EIP-7702 delegation,
|
|
86
|
+
* `msg.sender` for each call is the user's EOA.
|
|
87
|
+
*/
|
|
88
|
+
interface Operation {
|
|
89
|
+
target: Address;
|
|
90
|
+
value: bigint;
|
|
91
|
+
data: Hex;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Paymaster fields attached to a UserOperation. Populated by the
|
|
95
|
+
* Coinbase Paymaster (via PAFI Backend proxy) before the user signs.
|
|
96
|
+
*/
|
|
97
|
+
interface PaymasterFields {
|
|
98
|
+
paymaster: Address;
|
|
99
|
+
paymasterData: Hex;
|
|
100
|
+
paymasterVerificationGasLimit: bigint;
|
|
101
|
+
paymasterPostOpGasLimit: bigint;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Partial UserOp used during preparation — before paymaster fields are
|
|
105
|
+
* attached or the user signs.
|
|
106
|
+
*/
|
|
107
|
+
interface PartialUserOperation {
|
|
108
|
+
sender: Address;
|
|
109
|
+
nonce: bigint;
|
|
110
|
+
callData: Hex;
|
|
111
|
+
callGasLimit: bigint;
|
|
112
|
+
verificationGasLimit: bigint;
|
|
113
|
+
preVerificationGas: bigint;
|
|
114
|
+
maxFeePerGas: bigint;
|
|
115
|
+
maxPriorityFeePerGas: bigint;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Full ERC-4337 v0.7 UserOperation, ready for bundler submission.
|
|
119
|
+
*/
|
|
120
|
+
interface UserOperation extends PartialUserOperation {
|
|
121
|
+
paymaster: Address;
|
|
122
|
+
paymasterData: Hex;
|
|
123
|
+
paymasterVerificationGasLimit: bigint;
|
|
124
|
+
paymasterPostOpGasLimit: bigint;
|
|
125
|
+
signature: Hex;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Receipt returned by a bundler after a UserOp lands on-chain.
|
|
129
|
+
*/
|
|
130
|
+
interface UserOpReceipt {
|
|
131
|
+
userOpHash: Hex;
|
|
132
|
+
success: boolean;
|
|
133
|
+
txHash: Hex;
|
|
134
|
+
blockNumber: bigint;
|
|
135
|
+
gasUsed: bigint;
|
|
136
|
+
/** Effective gas cost paid (wei). */
|
|
137
|
+
actualGasCost: bigint;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sentinel operation value used in tests + docs when `Operation.value`
|
|
141
|
+
* is irrelevant (ERC-20 transfers, for example).
|
|
142
|
+
*/
|
|
143
|
+
declare const ZERO_VALUE = 0n;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Build an ERC-20 `transfer(to, amount)` operation. Used inside a batch
|
|
147
|
+
* to move fee tokens from the user to the fee recipient atomically with
|
|
148
|
+
* the main action.
|
|
149
|
+
*/
|
|
150
|
+
declare function erc20TransferOp(token: Address, to: Address, amount: bigint): Operation;
|
|
151
|
+
/**
|
|
152
|
+
* Build an ERC-20 `approve(spender, amount)` operation. Used inside a
|
|
153
|
+
* batch before a swap / deposit call so the AMM / protocol can pull
|
|
154
|
+
* tokens from the user.
|
|
155
|
+
*/
|
|
156
|
+
declare function erc20ApproveOp(token: Address, spender: Address, amount: bigint): Operation;
|
|
157
|
+
/**
|
|
158
|
+
* Build an ERC-20 `burn(amount)` operation (OpenZeppelin ERC20Burnable
|
|
159
|
+
* extension). Burns from `msg.sender`, which — via EIP-7702 — is the
|
|
160
|
+
* user's EOA.
|
|
161
|
+
*
|
|
162
|
+
* Requires the PointToken contract to expose a public `burn(uint256)`
|
|
163
|
+
* without a role check. See
|
|
164
|
+
* [SDK_V1.4_TASKS.md §11 — PointToken.burn callable via batch].
|
|
165
|
+
*/
|
|
166
|
+
declare function erc20BurnOp(token: Address, amount: bigint): Operation;
|
|
167
|
+
/**
|
|
168
|
+
* Build a raw call operation with caller-supplied calldata. Useful for
|
|
169
|
+
* non-ERC-20 contracts (PoolManager.swap, PerpDEX.deposit, Relayer.mint)
|
|
170
|
+
* where the encoding is specific to that protocol.
|
|
171
|
+
*/
|
|
172
|
+
declare function rawCallOp(target: Address, data: `0x${string}`, value?: bigint): Operation;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Standard BatchExecutor ABI — a contract that takes an array of calls
|
|
176
|
+
* and invokes each one in sequence, reverting all if any fail.
|
|
177
|
+
*
|
|
178
|
+
* Compatible with OpenZeppelin `Account.execute(Call[])`, Biconomy
|
|
179
|
+
* `executeBatch`, Safe `MultiSend`, and most EIP-7702 delegation
|
|
180
|
+
* targets. The exact deployed address is supplied by the infra team
|
|
181
|
+
* (see [V1.4_V1.5_READINESS.md B2]).
|
|
182
|
+
*/
|
|
183
|
+
declare const BATCH_EXECUTOR_ABI: readonly [{
|
|
184
|
+
readonly name: "execute";
|
|
185
|
+
readonly type: "function";
|
|
186
|
+
readonly stateMutability: "nonpayable";
|
|
187
|
+
readonly inputs: readonly [{
|
|
188
|
+
readonly type: "tuple[]";
|
|
189
|
+
readonly components: readonly [{
|
|
190
|
+
readonly type: "address";
|
|
191
|
+
readonly name: "target";
|
|
192
|
+
}, {
|
|
193
|
+
readonly type: "uint256";
|
|
194
|
+
readonly name: "value";
|
|
195
|
+
}, {
|
|
196
|
+
readonly type: "bytes";
|
|
197
|
+
readonly name: "data";
|
|
198
|
+
}];
|
|
199
|
+
readonly name: "calls";
|
|
200
|
+
}];
|
|
201
|
+
readonly outputs: readonly [];
|
|
202
|
+
}];
|
|
203
|
+
/**
|
|
204
|
+
* Encode a batch of operations into calldata for `BatchExecutor.execute()`.
|
|
205
|
+
* The resulting calldata goes into `UserOperation.callData`.
|
|
206
|
+
*
|
|
207
|
+
* When the EOA has an EIP-7702 delegation to a BatchExecutor, calling
|
|
208
|
+
* this calldata against the EOA runs all operations with
|
|
209
|
+
* `msg.sender = EOA` for each inner call.
|
|
210
|
+
*
|
|
211
|
+
* @param operations batch of calls, in execution order
|
|
212
|
+
* @returns calldata bytes for `execute((address,uint256,bytes)[])`
|
|
213
|
+
*/
|
|
214
|
+
declare function encodeBatchExecute(operations: Operation[]): Hex;
|
|
215
|
+
|
|
216
|
+
interface BuildPartialUserOpParams {
|
|
217
|
+
/** User's EOA (with EIP-7702 delegation). */
|
|
218
|
+
sender: Address;
|
|
219
|
+
/** Batch of operations — encoded into callData via `encodeBatchExecute`. */
|
|
220
|
+
operations: Operation[];
|
|
221
|
+
/** EntryPoint nonce for this sender. Caller fetches from the EntryPoint contract. */
|
|
222
|
+
nonce: bigint;
|
|
223
|
+
/** Optional gas overrides; bundler re-estimates before submission. */
|
|
224
|
+
gasLimits?: {
|
|
225
|
+
callGasLimit?: bigint;
|
|
226
|
+
verificationGasLimit?: bigint;
|
|
227
|
+
preVerificationGas?: bigint;
|
|
228
|
+
};
|
|
229
|
+
/** Optional fee overrides; bundler usually fills these. */
|
|
230
|
+
feeOverrides?: {
|
|
231
|
+
maxFeePerGas?: bigint;
|
|
232
|
+
maxPriorityFeePerGas?: bigint;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Build a partial ERC-4337 UserOperation from a batch of operations.
|
|
237
|
+
* Paymaster fields and signature are populated later:
|
|
238
|
+
* 1. Call `PafiBackendClient.requestSponsorship()` → get paymaster fields
|
|
239
|
+
* 2. Compute userOpHash and have the user sign it (via Privy)
|
|
240
|
+
* 3. Attach `signature` → submit to bundler
|
|
241
|
+
*
|
|
242
|
+
* This function is a pure struct builder — no network calls.
|
|
243
|
+
*/
|
|
244
|
+
declare function buildPartialUserOperation(params: BuildPartialUserOpParams): PartialUserOperation;
|
|
245
|
+
/**
|
|
246
|
+
* Assemble a full UserOperation once paymaster fields + signature are
|
|
247
|
+
* known. Used after `PafiBackendClient.requestSponsorship()` and user
|
|
248
|
+
* signing complete.
|
|
249
|
+
*/
|
|
250
|
+
declare function assembleUserOperation(partial: PartialUserOperation, paymaster: {
|
|
251
|
+
paymaster: Address;
|
|
252
|
+
paymasterData: `0x${string}`;
|
|
253
|
+
paymasterVerificationGasLimit: bigint;
|
|
254
|
+
paymasterPostOpGasLimit: bigint;
|
|
255
|
+
}, signature: `0x${string}`): UserOperation;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Module-level paymaster config shared by all batch builders and the
|
|
259
|
+
* `@pafi/issuer` RelayService. Holds the fee recipient address and the
|
|
260
|
+
* PAFI-assigned issuer identity.
|
|
261
|
+
*
|
|
262
|
+
* v1.4 update: the paymaster endpoint is **PAFI Backend**, which proxies
|
|
263
|
+
* to Coinbase Paymaster. See [SPONSORED_PATH_FLOW.md].
|
|
264
|
+
*/
|
|
265
|
+
interface PaymasterConfig {
|
|
266
|
+
/**
|
|
267
|
+
* PAFI Backend API base URL. Example:
|
|
268
|
+
* https://api.pacificfinance.org/paymaster
|
|
269
|
+
*/
|
|
270
|
+
pafiBackendUrl: string;
|
|
271
|
+
/** PAFI-assigned issuer ID. Passed in X-Issuer-Id header. */
|
|
272
|
+
issuerId: string;
|
|
273
|
+
/** Per-issuer API key (or JWT) for Authorization header. */
|
|
274
|
+
apiKey: string;
|
|
275
|
+
/**
|
|
276
|
+
* Where the fee transfer lands inside the batch call. Fee recovery is
|
|
277
|
+
* application-level — Paymaster sponsors gas, fee is a separate
|
|
278
|
+
* ERC-20 transfer inside the batch that reimburses the issuer.
|
|
279
|
+
*/
|
|
280
|
+
feeRecipient: Address;
|
|
281
|
+
/** EIP-4337 EntryPoint address. Default: v0.7 (same across chains). */
|
|
282
|
+
entryPoint?: Address;
|
|
283
|
+
/** Chain ID the paymaster sponsors on. Defaults to consumer config. */
|
|
284
|
+
chainId?: number;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Which PAFI-defined scenario this UserOp represents. PAFI Backend
|
|
288
|
+
* validates the request's target contracts + function selectors
|
|
289
|
+
* match the expected pattern for the scenario.
|
|
290
|
+
*/
|
|
291
|
+
type SponsorshipScenario = "mint" | "burn" | "swap" | "perp-deposit";
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Set the application-wide paymaster config. Safe to call multiple
|
|
295
|
+
* times (later calls override earlier). Throws if required fields
|
|
296
|
+
* are missing.
|
|
297
|
+
*/
|
|
298
|
+
declare function setPaymasterConfig(config: PaymasterConfig): void;
|
|
299
|
+
/**
|
|
300
|
+
* Get the current paymaster config. Throws if `setPaymasterConfig()`
|
|
301
|
+
* has not been called yet — this surfaces boot-order bugs early
|
|
302
|
+
* instead of failing with "paymaster.feeRecipient is undefined" at
|
|
303
|
+
* the point of use.
|
|
304
|
+
*/
|
|
305
|
+
declare function getPaymasterConfig(): PaymasterConfig;
|
|
306
|
+
/** Test helper — clear the singleton. */
|
|
307
|
+
declare function _resetPaymasterConfigForTests(): void;
|
|
308
|
+
/** Check whether paymaster config has been initialized. */
|
|
309
|
+
declare function isPaymasterConfigured(): boolean;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Submission path chosen by `checkEthAndBranch`.
|
|
313
|
+
* - `normal`: initiator has enough ETH; submit via `walletClient.writeContract`
|
|
314
|
+
* or a plain `eth_sendRawTransaction`. No paymaster round-trip.
|
|
315
|
+
* - `paymaster`: initiator doesn't have enough ETH; wrap the batch as a
|
|
316
|
+
* UserOperation and route through PAFI Backend → Coinbase Paymaster
|
|
317
|
+
* → Bundler.
|
|
318
|
+
*/
|
|
319
|
+
type SubmissionPath = "normal" | "paymaster";
|
|
320
|
+
interface CheckEthAndBranchParams {
|
|
321
|
+
/** viem PublicClient bound to the target chain. */
|
|
322
|
+
client: PublicClient;
|
|
323
|
+
/** The address whose ETH balance we check. */
|
|
324
|
+
initiator: Address;
|
|
325
|
+
/** Estimated gas cost in wei for the upcoming tx. */
|
|
326
|
+
estimatedGasWei: bigint;
|
|
327
|
+
/**
|
|
328
|
+
* Optional safety margin multiplier (basis points). Defaults to
|
|
329
|
+
* 11_000 (110%) — the initiator needs 10% above the estimate to
|
|
330
|
+
* qualify for the normal path. Prevents edge cases where gas price
|
|
331
|
+
* spikes between estimation and submission cause a "has enough"
|
|
332
|
+
* decision to fail at broadcast time.
|
|
333
|
+
*/
|
|
334
|
+
marginBps?: number;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Step 3 of the Generalized Flow ([SPONSORED_PATH_FLOW.md §2]):
|
|
338
|
+
* choose between the normal path (initiator pays ETH directly) and the
|
|
339
|
+
* paymaster path (bundler + Coinbase Paymaster).
|
|
340
|
+
*
|
|
341
|
+
* Intentionally synchronous in spirit — the only network call is
|
|
342
|
+
* `getBalance`. Callers can parallelize it with other reads.
|
|
343
|
+
*/
|
|
344
|
+
declare function checkEthAndBranch(params: CheckEthAndBranchParams): Promise<SubmissionPath>;
|
|
345
|
+
|
|
77
346
|
declare class PafiSDK {
|
|
78
347
|
private _pointTokenAddress?;
|
|
79
348
|
private _relayContractAddress?;
|
|
@@ -236,4 +505,4 @@ declare class PafiSDK {
|
|
|
236
505
|
signLoginMessage(message: string): Promise<Hex>;
|
|
237
506
|
}
|
|
238
507
|
|
|
239
|
-
export { ApiError, BestQuote, COMMON_POOLS, COMMON_TOKENS, ChainConfig, ConfigurationError, EIP712Signature, LoginMessageParams, MintParams, MintRequest, POINT_TOKEN_POOLS, PafiSDK, PafiSDKConfig, PafiSDKError, PathKey, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, SignatureVerification, SigningError, SimulationError, SimulationResult, SwapParams, SwapSimulationResult, UNIVERSAL_ROUTER_ADDRESSES, V4_QUOTER_ADDRESSES, mintRequestTypes, receiverConsentTypes };
|
|
508
|
+
export { ApiError, BATCH_EXECUTOR_ABI, BestQuote, type BuildPartialUserOpParams, COMMON_POOLS, COMMON_TOKENS, ChainConfig, type CheckEthAndBranchParams, ConfigurationError, EIP712Signature, ENTRY_POINT_V07, LoginMessageParams, MintParams, MintRequest, type Operation, POINT_TOKEN_POOLS, PafiSDK, PafiSDKConfig, PafiSDKError, type PartialUserOperation, PathKey, type PaymasterConfig, type PaymasterFields, PointTokenDomainConfig, PoolKey, QuoteResult, ReceiverConsent, SUPPORTED_CHAINS, SignatureVerification, SigningError, SimulationError, SimulationResult, type SponsorshipScenario, type SubmissionPath, SwapParams, SwapSimulationResult, UNIVERSAL_ROUTER_ADDRESSES, type UserOpReceipt, type UserOperation, V4_QUOTER_ADDRESSES, ZERO_VALUE, _resetPaymasterConfigForTests, assembleUserOperation, buildPartialUserOperation, checkEthAndBranch, encodeBatchExecute, erc20ApproveOp, erc20BurnOp, erc20TransferOp, getPaymasterConfig, isPaymasterConfigured, mintRequestTypes, rawCallOp, receiverConsentTypes, setPaymasterConfig };
|