@pafi-dev/core 0.3.0-beta.1 → 0.3.0-beta.11

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 (86) hide show
  1. package/README.md +99 -1118
  2. package/dist/abi/index.cjs +2 -6
  3. package/dist/abi/index.cjs.map +1 -1
  4. package/dist/abi/index.d.cts +1 -286
  5. package/dist/abi/index.d.ts +1 -286
  6. package/dist/abi/index.js +1 -5
  7. package/dist/{chunk-R4L66ZR5.js → chunk-73CQTNLB.js} +10 -1
  8. package/dist/chunk-73CQTNLB.js.map +1 -0
  9. package/dist/{chunk-5YH4D7QF.js → chunk-7UBO7DY5.js} +1 -1
  10. package/dist/{chunk-FGKLDKJK.cjs → chunk-ALCWYDVG.cjs} +1 -1
  11. package/dist/{chunk-FGKLDKJK.cjs.map → chunk-ALCWYDVG.cjs.map} +1 -1
  12. package/dist/{chunk-X3I5XWAR.cjs → chunk-CQCSQPWG.cjs} +2 -15
  13. package/dist/chunk-CQCSQPWG.cjs.map +1 -0
  14. package/dist/{chunk-CWP4PFOP.cjs → chunk-DMW67WBU.cjs} +11 -2
  15. package/dist/chunk-DMW67WBU.cjs.map +1 -0
  16. package/dist/{chunk-C4ZDYG4D.js → chunk-DUY7Z2AI.js} +48 -6
  17. package/dist/chunk-DUY7Z2AI.js.map +1 -0
  18. package/dist/{chunk-CXFUP2YK.cjs → chunk-EDR5SFJN.cjs} +46 -6
  19. package/dist/chunk-EDR5SFJN.cjs.map +1 -0
  20. package/dist/{chunk-FIKTQR7H.js → chunk-I2P3TIP7.js} +2 -2
  21. package/dist/{chunk-BNTVOKYT.cjs → chunk-KJKDLD7N.cjs} +51 -9
  22. package/dist/chunk-KJKDLD7N.cjs.map +1 -0
  23. package/dist/{chunk-VQSRCMMK.js → chunk-QGO6X6LG.js} +2 -15
  24. package/dist/chunk-QGO6X6LG.js.map +1 -0
  25. package/dist/{chunk-IK4UK7KT.js → chunk-W23EJNYG.js} +44 -4
  26. package/dist/chunk-W23EJNYG.js.map +1 -0
  27. package/dist/{chunk-CAE2BVKI.cjs → chunk-Z2V525IS.cjs} +6 -6
  28. package/dist/{chunk-CAE2BVKI.cjs.map → chunk-Z2V525IS.cjs.map} +1 -1
  29. package/dist/contract/index.cjs +2 -5
  30. package/dist/contract/index.cjs.map +1 -1
  31. package/dist/contract/index.d.cts +2 -4
  32. package/dist/contract/index.d.ts +2 -4
  33. package/dist/contract/index.js +1 -4
  34. package/dist/eip712/index.cjs +9 -3
  35. package/dist/eip712/index.cjs.map +1 -1
  36. package/dist/eip712/index.d.cts +44 -2
  37. package/dist/eip712/index.d.ts +44 -2
  38. package/dist/eip712/index.js +8 -2
  39. package/dist/{index-CNALKsH1.d.ts → index-B06IJlHe.d.ts} +1 -1
  40. package/dist/{index-BpUYHGu3.d.cts → index-B7pGBych.d.cts} +1 -1
  41. package/dist/index.cjs +434 -247
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.cts +905 -411
  44. package/dist/index.d.ts +905 -411
  45. package/dist/index.js +447 -260
  46. package/dist/index.js.map +1 -1
  47. package/dist/quoting/index.cjs +3 -3
  48. package/dist/quoting/index.d.cts +1 -1
  49. package/dist/quoting/index.d.ts +1 -1
  50. package/dist/quoting/index.js +2 -2
  51. package/dist/swap/index.cjs +2 -3
  52. package/dist/swap/index.cjs.map +1 -1
  53. package/dist/swap/index.d.cts +2 -2
  54. package/dist/swap/index.d.ts +2 -2
  55. package/dist/swap/index.js +1 -2
  56. package/dist/{types-BDOnH5Le.d.cts → types-b5_Tokjl.d.cts} +8 -17
  57. package/dist/{types-BDOnH5Le.d.ts → types-b5_Tokjl.d.ts} +8 -17
  58. package/package.json +1 -1
  59. package/dist/chunk-27V32VNM.cjs +0 -370
  60. package/dist/chunk-27V32VNM.cjs.map +0 -1
  61. package/dist/chunk-4RYBJLF3.js +0 -370
  62. package/dist/chunk-4RYBJLF3.js.map +0 -1
  63. package/dist/chunk-5QJZT7VB.cjs +0 -46
  64. package/dist/chunk-5QJZT7VB.cjs.map +0 -1
  65. package/dist/chunk-BNTVOKYT.cjs.map +0 -1
  66. package/dist/chunk-C4ZDYG4D.js.map +0 -1
  67. package/dist/chunk-CWP4PFOP.cjs.map +0 -1
  68. package/dist/chunk-CXFUP2YK.cjs.map +0 -1
  69. package/dist/chunk-IK4UK7KT.js.map +0 -1
  70. package/dist/chunk-L74CZAVQ.cjs +0 -99
  71. package/dist/chunk-L74CZAVQ.cjs.map +0 -1
  72. package/dist/chunk-P56TUGTS.js +0 -46
  73. package/dist/chunk-P56TUGTS.js.map +0 -1
  74. package/dist/chunk-R4L66ZR5.js.map +0 -1
  75. package/dist/chunk-VQSRCMMK.js.map +0 -1
  76. package/dist/chunk-X3I5XWAR.cjs.map +0 -1
  77. package/dist/chunk-X4IXUTTD.js +0 -99
  78. package/dist/chunk-X4IXUTTD.js.map +0 -1
  79. package/dist/relay/index.cjs +0 -19
  80. package/dist/relay/index.cjs.map +0 -1
  81. package/dist/relay/index.d.cts +0 -75
  82. package/dist/relay/index.d.ts +0 -75
  83. package/dist/relay/index.js +0 -19
  84. package/dist/relay/index.js.map +0 -1
  85. /package/dist/{chunk-5YH4D7QF.js.map → chunk-7UBO7DY5.js.map} +0 -0
  86. /package/dist/{chunk-FIKTQR7H.js.map → chunk-I2P3TIP7.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pointTokenFactoryAbi
3
- } from "./chunk-5YH4D7QF.js";
3
+ } from "./chunk-7UBO7DY5.js";
4
4
  import {
5
5
  createLoginMessage,
6
6
  parseLoginMessage,
@@ -14,25 +14,27 @@ import {
14
14
  getPointTokenIssuer,
15
15
  getReceiverConsentNonce,
16
16
  getTokenName,
17
- getUsdt,
18
17
  isActiveIssuer,
19
18
  isMinter,
20
19
  verifyMintCap
21
- } from "./chunk-VQSRCMMK.js";
20
+ } from "./chunk-QGO6X6LG.js";
22
21
  import {
23
22
  issuerRegistryAbi,
24
23
  mintingOracleAbi,
25
24
  pointTokenAbi
26
25
  } from "./chunk-FXNG4G22.js";
27
26
  import {
27
+ buildBurnRequestTypedData,
28
28
  buildDomain,
29
29
  buildMintRequestTypedData,
30
30
  buildReceiverConsentTypedData,
31
+ signBurnRequest,
31
32
  signMintRequest,
32
33
  signReceiverConsent,
34
+ verifyBurnRequest,
33
35
  verifyMintRequest,
34
36
  verifyReceiverConsent
35
- } from "./chunk-C4ZDYG4D.js";
37
+ } from "./chunk-DUY7Z2AI.js";
36
38
  import {
37
39
  buildAllPaths,
38
40
  combineRoutes,
@@ -40,7 +42,7 @@ import {
40
42
  quoteBestRoute,
41
43
  quoteExactInput,
42
44
  quoteExactInputSingle
43
- } from "./chunk-FIKTQR7H.js";
45
+ } from "./chunk-I2P3TIP7.js";
44
46
  import {
45
47
  v4QuoterAbi
46
48
  } from "./chunk-KFWZRL7I.js";
@@ -51,24 +53,19 @@ import {
51
53
  SUPPORTED_CHAINS,
52
54
  UNIVERSAL_ROUTER_ADDRESSES,
53
55
  V4_QUOTER_ADDRESSES,
56
+ burnRequestTypes,
54
57
  mintRequestTypes,
55
58
  receiverConsentTypes
56
- } from "./chunk-R4L66ZR5.js";
57
- import {
58
- buildRelaySwapParams,
59
- decodeExtData,
60
- decodeMintAndSwap,
61
- encodeExtData,
62
- encodeMintAndSwap,
63
- simulateMintAndSwap
64
- } from "./chunk-X4IXUTTD.js";
65
- import {
66
- relayAbi
67
- } from "./chunk-4RYBJLF3.js";
59
+ } from "./chunk-73CQTNLB.js";
68
60
  import {
61
+ ApiError,
69
62
  BATCH_EXECUTOR_ABI,
63
+ ConfigurationError,
64
+ PafiSDKError,
70
65
  SETTLE_ALL,
71
66
  SWAP_EXACT_IN,
67
+ SigningError,
68
+ SimulationError,
72
69
  TAKE_ALL,
73
70
  V4_SWAP,
74
71
  assembleUserOperation,
@@ -86,23 +83,156 @@ import {
86
83
  erc20TransferOp,
87
84
  rawCallOp,
88
85
  simulateSwap
89
- } from "./chunk-IK4UK7KT.js";
86
+ } from "./chunk-W23EJNYG.js";
90
87
  import {
91
88
  erc20Abi,
92
89
  permit2Abi,
93
90
  universalRouterAbi
94
91
  } from "./chunk-2PIXFXA2.js";
95
- import {
96
- ApiError,
97
- ConfigurationError,
98
- PafiSDKError,
99
- SigningError,
100
- SimulationError
101
- } from "./chunk-P56TUGTS.js";
102
92
 
103
93
  // src/index.ts
104
94
  import { createPublicClient, http } from "viem";
105
95
 
96
+ // src/perp/buildPerpDepositWithGasDeduction.ts
97
+ import { encodeFunctionData } from "viem";
98
+
99
+ // src/contracts/real/orderlyVault.ts
100
+ import { keccak256, encodePacked, encodeAbiParameters } from "viem";
101
+ var ORDERLY_VAULT_BASE_MAINNET = "0xDe5cE5DD048596e46Ff671b13317aCC3C5B59b01";
102
+ var ORDERLY_VAULT_ADDRESSES = {
103
+ 8453: ORDERLY_VAULT_BASE_MAINNET
104
+ };
105
+ var BROKER_HASHES = {
106
+ /** Default partner broker on Base — most commonly whitelisted. */
107
+ woofi_pro: keccak256(encodePacked(["string"], ["woofi_pro"])),
108
+ /** Orderly's own white-label broker. */
109
+ orderly: keccak256(encodePacked(["string"], ["orderly"])),
110
+ /** LogX. */
111
+ logx: keccak256(encodePacked(["string"], ["logx"]))
112
+ };
113
+ var TOKEN_HASHES = {
114
+ USDC: keccak256(encodePacked(["string"], ["USDC"]))
115
+ };
116
+ function computeAccountId(user, brokerHash) {
117
+ return keccak256(
118
+ encodeAbiParameters(
119
+ [
120
+ { type: "address" },
121
+ { type: "bytes32" }
122
+ ],
123
+ [user, brokerHash]
124
+ )
125
+ );
126
+ }
127
+ var ORDERLY_VAULT_ABI = [
128
+ // Deposit USDC into Orderly perp account. Emits LayerZero message
129
+ // to the Orderly chain. `msg.value` MUST equal `getDepositFee(...)`.
130
+ {
131
+ type: "function",
132
+ name: "deposit",
133
+ stateMutability: "payable",
134
+ inputs: [
135
+ {
136
+ name: "data",
137
+ type: "tuple",
138
+ components: [
139
+ { name: "accountId", type: "bytes32" },
140
+ { name: "brokerHash", type: "bytes32" },
141
+ { name: "tokenHash", type: "bytes32" },
142
+ { name: "tokenAmount", type: "uint128" }
143
+ ]
144
+ }
145
+ ],
146
+ outputs: []
147
+ },
148
+ // Quote the LayerZero fee for a deposit message. Pass the same
149
+ // VaultDepositFE struct you intend to send.
150
+ {
151
+ type: "function",
152
+ name: "getDepositFee",
153
+ stateMutability: "view",
154
+ inputs: [
155
+ { name: "user", type: "address" },
156
+ {
157
+ name: "data",
158
+ type: "tuple",
159
+ components: [
160
+ { name: "accountId", type: "bytes32" },
161
+ { name: "brokerHash", type: "bytes32" },
162
+ { name: "tokenHash", type: "bytes32" },
163
+ { name: "tokenAmount", type: "uint128" }
164
+ ]
165
+ }
166
+ ],
167
+ outputs: [{ name: "", type: "uint256" }]
168
+ },
169
+ // Pre-flight check — is this brokerId whitelisted on this Vault?
170
+ {
171
+ type: "function",
172
+ name: "getAllowedBroker",
173
+ stateMutability: "view",
174
+ inputs: [{ name: "brokerHash", type: "bytes32" }],
175
+ outputs: [{ name: "", type: "bool" }]
176
+ },
177
+ // Pre-flight check — what ERC-20 address does this token symbol
178
+ // resolve to on this Vault?
179
+ {
180
+ type: "function",
181
+ name: "getAllowedToken",
182
+ stateMutability: "view",
183
+ inputs: [{ name: "tokenHash", type: "bytes32" }],
184
+ outputs: [{ name: "", type: "address" }]
185
+ }
186
+ ];
187
+
188
+ // src/perp/buildPerpDepositWithGasDeduction.ts
189
+ function buildPerpDepositWithGasDeduction(params) {
190
+ if (params.amount <= 0n) {
191
+ throw new Error("buildPerpDepositWithGasDeduction: amount must be positive");
192
+ }
193
+ if (params.layerZeroFee < 0n) {
194
+ throw new Error(
195
+ "buildPerpDepositWithGasDeduction: layerZeroFee cannot be negative"
196
+ );
197
+ }
198
+ if (params.depositData.tokenAmount !== params.amount) {
199
+ throw new Error(
200
+ `buildPerpDepositWithGasDeduction: depositData.tokenAmount (${params.depositData.tokenAmount}) must equal amount (${params.amount})`
201
+ );
202
+ }
203
+ const vault = params.vaultAddress ?? ORDERLY_VAULT_ADDRESSES[params.chainId];
204
+ if (!vault) {
205
+ throw new Error(
206
+ `buildPerpDepositWithGasDeduction: no Orderly Vault address for chainId ${params.chainId}`
207
+ );
208
+ }
209
+ const depositCallData = encodeFunctionData({
210
+ abi: ORDERLY_VAULT_ABI,
211
+ functionName: "deposit",
212
+ args: [params.depositData]
213
+ });
214
+ const operations = [
215
+ erc20ApproveOp(params.usdcAddress, vault, params.amount),
216
+ {
217
+ ...rawCallOp(vault, depositCallData),
218
+ // BatchExecutor passes `value` from the inner call along; this
219
+ // becomes the LayerZero fee. The aggregated `msg.value` for the
220
+ // top-level UserOp must equal the sum of inner `value`s.
221
+ value: params.layerZeroFee
222
+ }
223
+ ];
224
+ return buildPartialUserOperation({
225
+ sender: params.userAddress,
226
+ nonce: params.aaNonce,
227
+ operations,
228
+ gasLimits: {
229
+ callGasLimit: params.gasLimits?.callGasLimit ?? 800000n,
230
+ verificationGasLimit: params.gasLimits?.verificationGasLimit ?? 150000n,
231
+ preVerificationGas: params.gasLimits?.preVerificationGas ?? 50000n
232
+ }
233
+ });
234
+ }
235
+
106
236
  // src/userop/types.ts
107
237
  var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
108
238
  var ZERO_VALUE = 0n;
@@ -150,186 +280,300 @@ async function checkEthAndBranch(params) {
150
280
  return balance >= required ? "normal" : "paymaster";
151
281
  }
152
282
 
153
- // src/contracts/mocks/relayerV2.mock.ts
154
- import { parseAbi } from "viem";
155
- var MOCK_RELAYER_V2_ABI = parseAbi([
156
- "function mint((address to, uint256 amount, uint256 feeAmount, address feeRecipient, uint256 nonce, uint256 deadline, bytes extData) request, (uint8 v, bytes32 r, bytes32 s) userSig, (uint8 v, bytes32 r, bytes32 s) issuerSig) external",
157
- // View functions we'll likely want (nonce getter is standard)
158
- "function mintRequestNonce(address user) external view returns (uint256)",
159
- "event Minted(address indexed user, uint256 amount, uint256 feeAmount, address indexed feeRecipient, bytes32 requestHash)"
160
- ]);
161
- var MOCK_RELAYER_V2_MINT_SELECTOR = "0xMOCKED__";
283
+ // src/delegation/checkDelegation.ts
284
+ var EIP7702_MAGIC = "0xef0100";
285
+ function parseEip7702DelegatedAddress(code) {
286
+ if (!code || code === "0x" || code === "0x0") return null;
287
+ const normalized = code.toLowerCase();
288
+ const magic = EIP7702_MAGIC.toLowerCase();
289
+ const idx = normalized.indexOf(magic);
290
+ if (idx === -1) return null;
291
+ const raw = normalized.slice(idx + magic.length, idx + magic.length + 40);
292
+ if (raw.length !== 40) return null;
293
+ return `0x${raw}`;
294
+ }
295
+ async function checkDelegation(client, address) {
296
+ const code = await client.getCode({ address });
297
+ return parseEip7702DelegatedAddress(code);
298
+ }
299
+ async function isDelegatedTo(client, address, target) {
300
+ const impl = await checkDelegation(client, address);
301
+ if (!impl) return false;
302
+ return impl.toLowerCase() === target.toLowerCase();
303
+ }
162
304
 
163
- // src/contracts/mocks/pointTokenV2.mock.ts
164
- import { parseAbi as parseAbi2 } from "viem";
165
- var MOCK_POINT_TOKEN_V2_ABI = parseAbi2([
166
- // Variant A
167
- "function burn(uint256 amount) external",
168
- // Variant B
169
- "function burnWithSig((address user, address pointToken, uint256 amount, uint256 nonce, uint256 deadline) consent, (uint8 v, bytes32 r, bytes32 s) sig) external",
170
- // Standard reads we always need
171
- "function balanceOf(address user) external view returns (uint256)",
172
- "function burnNonce(address user) external view returns (uint256)",
173
- // ERC-20 Transfer event (inherited) BurnIndexer filters `to = 0x0`
174
- "event Transfer(address indexed from, address indexed to, uint256 value)"
305
+ // src/delegation/buildDelegationUserOp.ts
306
+ function buildDelegationUserOp(params) {
307
+ return buildPartialUserOperation({
308
+ sender: params.userAddress,
309
+ nonce: params.aaNonce,
310
+ operations: [
311
+ {
312
+ // Self-call with no data — triggers EIP-7702 delegation without
313
+ // executing any inner logic. The BatchExecutor.execute([]) call with
314
+ // an empty array would revert, so we target the EOA itself (which
315
+ // forwards to BatchExecutor that then no-ops on empty input).
316
+ target: params.userAddress,
317
+ value: 0n,
318
+ data: "0x"
319
+ }
320
+ ],
321
+ gasLimits: {
322
+ callGasLimit: params.gasLimits?.callGasLimit ?? 50000n,
323
+ verificationGasLimit: params.gasLimits?.verificationGasLimit ?? 150000n,
324
+ preVerificationGas: params.gasLimits?.preVerificationGas ?? 50000n
325
+ }
326
+ });
327
+ }
328
+ async function getAaNonce(client, userAddress) {
329
+ const ENTRY_POINT = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
330
+ const NONCE_ABI = [
331
+ {
332
+ inputs: [
333
+ { name: "sender", type: "address" },
334
+ { name: "key", type: "uint192" }
335
+ ],
336
+ name: "getNonce",
337
+ outputs: [{ name: "nonce", type: "uint256" }],
338
+ stateMutability: "view",
339
+ type: "function"
340
+ }
341
+ ];
342
+ return client.readContract({
343
+ address: ENTRY_POINT,
344
+ abi: NONCE_ABI,
345
+ functionName: "getNonce",
346
+ args: [userAddress, 0n]
347
+ });
348
+ }
349
+
350
+ // src/contracts/real/pointToken.ts
351
+ import { parseAbi } from "viem";
352
+ var POINT_TOKEN_ABI = parseAbi([
353
+ // --- Mint paths ---
354
+ "function mint(address to, uint256 amount) external",
355
+ "function mint(address to, uint256 amount, uint256 deadline, bytes minterSig) external",
356
+ // --- Burn paths ---
357
+ "function burn(address from, uint256 amount) external",
358
+ "function burn(address from, uint256 amount, uint256 deadline, bytes burnerSig) external",
359
+ // --- Authorization reads ---
360
+ "function minters(address account) external view returns (bool)",
361
+ "function burners(address account) external view returns (bool)",
362
+ // --- Authorization writes (owner-only; used by provisioning scripts) ---
363
+ "function addMinter(address minter) external",
364
+ "function removeMinter(address minter) external",
365
+ "function addBurner(address burner) external",
366
+ "function removeBurner(address burner) external",
367
+ // --- Nonces (sig-gated paths) ---
368
+ "function mintRequestNonces(address receiver) external view returns (uint256)",
369
+ "function burnRequestNonces(address from) external view returns (uint256)",
370
+ // --- Oracle ---
371
+ "function mintingOracle() external view returns (address)",
372
+ "function setMintingOracle(address _mintingOracle) external",
373
+ // --- Issuer ---
374
+ "function issuer() external view returns (address)",
375
+ // --- Standard ERC-20 reads ---
376
+ "function balanceOf(address account) external view returns (uint256)",
377
+ "function totalSupply() external view returns (uint256)",
378
+ "function name() external view returns (string)",
379
+ "function symbol() external view returns (string)",
380
+ "function decimals() external view returns (uint8)",
381
+ // --- EIP-712 domain (for off-chain sig verification) ---
382
+ "function DOMAIN_SEPARATOR() external view returns (bytes32)",
383
+ "function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)",
384
+ // --- Events ---
385
+ // PointIndexer filters Transfer(from=0x0) for mints
386
+ // BurnIndexer filters Transfer(to=0x0) for burns
387
+ "event Transfer(address indexed from, address indexed to, uint256 value)",
388
+ "event MinterAdded(address indexed minter)",
389
+ "event MinterRemoved(address indexed minter)",
390
+ "event BurnerAdded(address indexed burner)",
391
+ "event BurnerRemoved(address indexed burner)",
392
+ "event MintingOracleUpdated(address indexed mintingOracle)"
175
393
  ]);
176
394
 
177
- // src/contracts/mocks/batchExecutor.mock.ts
178
- var MOCK_BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = "0x000000000000000000000000000000000000DE01";
179
- var MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = "0x000000000000000000000000000000000000DE02";
395
+ // src/contracts/real/batchExecutor.ts
396
+ var BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = "0x000000000000000000000000000000000000DE01";
397
+ var BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = "0x7702cb554e6bFb442cb743A7dF23154544a7176C";
180
398
 
181
- // src/contracts/mocks/addresses.mock.ts
182
- var MOCK_PLACEHOLDER = (suffix) => `0x000000000000000000000000000000000000${suffix.toLowerCase().padStart(4, "0")}`;
183
- var MOCK_ADDRESSES = {
184
- // Base Sepoliasafe targets for integration tests (MockRelayer
185
- // fixtures deployed by Hardhat will override these at test time)
186
- 84532: {
187
- relayerV2: MOCK_PLACEHOLDER("de10"),
188
- pointToken: MOCK_PLACEHOLDER("de11"),
189
- batchExecutor: MOCK_PLACEHOLDER("de01"),
190
- usdt: MOCK_PLACEHOLDER("de12"),
191
- issuerRegistry: MOCK_PLACEHOLDER("de13"),
192
- mintingOracle: MOCK_PLACEHOLDER("de14")
193
- },
194
- // Base mainnet — intentionally left as placeholder. Do NOT ship to
195
- // prod without swapping.
399
+ // src/contracts/real/addresses.ts
400
+ var PLACEHOLDER_DEAD = (suffix) => `0x000000000000000000000000000000000000${suffix.toLowerCase().padStart(4, "0")}`;
401
+ var CONTRACT_ADDRESSES = {
402
+ // Base mainnetSC-delivered (2026-04-21, 2026-04-22)
403
+ // registry: IssuerRegistry 0xda2D3338CF70F462Ac175F5f2edfa45660CA4f31
404
+ // factory: PointTokenFactory 0x36c0BAb2faBE45EfA6d13001143e43A266Af673B
405
+ // oracle: MintingOracle 0xD85165939C700E51c8a45099316C6482634C2Ab9
406
+ // tokenImpl: PointToken (impl) 0x2e6FB1B0C1A51abb83eC974890126a64eC02E995
407
+ // mockUsdt: MockERC20 0x5d313485Ba59C3bb91e1A9C0C11782F0b83d5dcd
408
+ // POINT: PointToken instance 0x7d25E7156E51F865D522fd3ef257a6B5DD41b97e
409
+ // batchExecutor: Coinbase SW v2 0x7702cb554e6bFb442cb743A7dF23154544a7176C
410
+ // pafiHook: PAFIHook (V4, 10%) 0x870cAF9882d3160602AaC1769C2B264A2d8EC044
196
411
  8453: {
197
- relayerV2: MOCK_PLACEHOLDER("dead"),
198
- pointToken: MOCK_PLACEHOLDER("dead"),
199
- batchExecutor: MOCK_PLACEHOLDER("dead"),
200
- usdt: MOCK_PLACEHOLDER("dead"),
201
- issuerRegistry: MOCK_PLACEHOLDER("dead"),
202
- mintingOracle: MOCK_PLACEHOLDER("dead")
412
+ pointToken: "0x7d25E7156E51F865D522fd3ef257a6B5DD41b97e",
413
+ batchExecutor: "0x7702cb554e6bFb442cb743A7dF23154544a7176C",
414
+ usdt: "0x5d313485Ba59C3bb91e1A9C0C11782F0b83d5dcd",
415
+ issuerRegistry: "0xda2D3338CF70F462Ac175F5f2edfa45660CA4f31",
416
+ mintingOracle: "0xD85165939C700E51c8a45099316C6482634C2Ab9",
417
+ pafiHook: "0x870cAF9882d3160602AaC1769C2B264A2d8EC044"
418
+ },
419
+ // Base Sepolia — not in active use; placeholders kept so the map
420
+ // compiles for tooling that enumerates chains.
421
+ 84532: {
422
+ pointToken: PLACEHOLDER_DEAD("dead"),
423
+ batchExecutor: PLACEHOLDER_DEAD("de01"),
424
+ usdt: PLACEHOLDER_DEAD("dead"),
425
+ issuerRegistry: PLACEHOLDER_DEAD("dead"),
426
+ mintingOracle: PLACEHOLDER_DEAD("dead"),
427
+ pafiHook: PLACEHOLDER_DEAD("dead")
203
428
  }
204
429
  };
205
- function getMockAddresses(chainId) {
206
- const addrs = MOCK_ADDRESSES[chainId];
430
+ var POINT_TOKEN_FACTORY_ADDRESSES = {
431
+ 8453: "0x36c0BAb2faBE45EfA6d13001143e43A266Af673B",
432
+ 84532: PLACEHOLDER_DEAD("dead")
433
+ };
434
+ var POINT_TOKEN_IMPL_ADDRESSES = {
435
+ 8453: "0x2e6FB1B0C1A51abb83eC974890126a64eC02E995",
436
+ 84532: PLACEHOLDER_DEAD("dead")
437
+ };
438
+ function getContractAddresses(chainId) {
439
+ const addrs = CONTRACT_ADDRESSES[chainId];
207
440
  if (!addrs) {
208
441
  throw new Error(
209
- `getMockAddresses: no mock addresses for chainId ${chainId}. Supported: ${Object.keys(MOCK_ADDRESSES).join(", ")}`
442
+ `getContractAddresses: no addresses for chainId ${chainId}. Supported: ${Object.keys(CONTRACT_ADDRESSES).join(", ")}`
210
443
  );
211
444
  }
212
445
  return addrs;
213
446
  }
214
447
 
215
- // src/contracts/mocks/eip712/mintRequestV2.mock.ts
216
- import {
217
- parseSignature,
218
- recoverTypedDataAddress
219
- } from "viem";
220
- var MOCK_MINT_REQUEST_V2_TYPES = {
221
- MintRequest: [
222
- { name: "to", type: "address" },
223
- { name: "amount", type: "uint256" },
224
- { name: "feeAmount", type: "uint256" },
225
- { name: "feeRecipient", type: "address" },
226
- { name: "nonce", type: "uint256" },
227
- { name: "deadline", type: "uint256" },
228
- { name: "extData", type: "bytes" }
229
- ]
230
- };
231
- function buildMockMintRequestV2TypedData(domain, message) {
232
- return {
233
- domain: buildDomain(domain),
234
- types: MOCK_MINT_REQUEST_V2_TYPES,
235
- primaryType: "MintRequest",
236
- message
237
- };
238
- }
239
- async function signMockMintRequestV2(walletClient, domain, message) {
240
- const serialized = await walletClient.signTypedData({
241
- account: walletClient.account,
242
- domain: buildDomain(domain),
243
- types: MOCK_MINT_REQUEST_V2_TYPES,
244
- primaryType: "MintRequest",
245
- message
246
- });
247
- const { v, r, s } = parseSignature(serialized);
248
- return {
249
- v: Number(v),
250
- r,
251
- s,
252
- serialized
448
+ // src/web-handoff/webPopup.ts
449
+ var DEFAULT_WIDTH = 900;
450
+ var DEFAULT_HEIGHT = 700;
451
+ var DEFAULT_NAME = "pafi-web";
452
+ function openWebPopup(url, options = {}) {
453
+ if (typeof window === "undefined" || typeof window.open !== "function") {
454
+ throw new Error(
455
+ "openWebPopup: `window.open` is not available in this runtime. Register a platform adapter via setPafiWebModalAdapter() instead."
456
+ );
457
+ }
458
+ const width = options.width ?? DEFAULT_WIDTH;
459
+ const height = options.height ?? DEFAULT_HEIGHT;
460
+ const name = options.windowName ?? DEFAULT_NAME;
461
+ const screenW = window.screen?.availWidth ?? window.innerWidth;
462
+ const screenH = window.screen?.availHeight ?? window.innerHeight;
463
+ const left = Math.max(0, Math.floor((screenW - width) / 2));
464
+ const top = Math.max(0, Math.floor((screenH - height) / 2));
465
+ const features = [
466
+ `width=${width}`,
467
+ `height=${height}`,
468
+ `left=${left}`,
469
+ `top=${top}`,
470
+ "resizable=yes",
471
+ "scrollbars=yes",
472
+ "noopener=no"
473
+ // we need opener.postMessage to work
474
+ ].join(",");
475
+ const popup = window.open(url, name, features);
476
+ if (!popup) {
477
+ throw new Error(
478
+ "openWebPopup: popup was blocked. Ensure this call runs inside a user gesture (click handler)."
479
+ );
480
+ }
481
+ let closed = false;
482
+ let pollId = null;
483
+ let messageListener = null;
484
+ const dispose = () => {
485
+ if (closed) return;
486
+ closed = true;
487
+ if (pollId !== null) {
488
+ clearInterval(pollId);
489
+ pollId = null;
490
+ }
491
+ if (messageListener) {
492
+ window.removeEventListener("message", messageListener);
493
+ messageListener = null;
494
+ }
495
+ options.onClose?.();
253
496
  };
254
- }
255
- async function verifyMockMintRequestV2(domain, message, signature, expectedSigner) {
256
- const recoveredAddress = await recoverTypedDataAddress({
257
- domain: buildDomain(domain),
258
- types: MOCK_MINT_REQUEST_V2_TYPES,
259
- primaryType: "MintRequest",
260
- message,
261
- signature
262
- });
263
- const isValid = recoveredAddress.toLowerCase() === expectedSigner.toLowerCase();
497
+ pollId = setInterval(() => {
498
+ if (popup.closed) {
499
+ dispose();
500
+ }
501
+ }, 500);
502
+ if (options.onMessage) {
503
+ const allowed = options.allowedOrigins ?? [];
504
+ const onMessage = options.onMessage;
505
+ messageListener = (event) => {
506
+ if (event.source !== popup) return;
507
+ if (!allowed.includes(event.origin)) return;
508
+ onMessage(event.data, event.origin);
509
+ };
510
+ window.addEventListener("message", messageListener);
511
+ }
264
512
  return {
265
- isValid,
266
- recoveredAddress
513
+ get isOpen() {
514
+ return !closed && !popup.closed;
515
+ },
516
+ close() {
517
+ if (closed) return;
518
+ try {
519
+ popup.close();
520
+ } catch {
521
+ }
522
+ dispose();
523
+ },
524
+ focus() {
525
+ if (closed || popup.closed) return;
526
+ try {
527
+ popup.focus();
528
+ } catch {
529
+ }
530
+ },
531
+ postMessage(data) {
532
+ if (closed || popup.closed) return;
533
+ try {
534
+ popup.postMessage(data, "*");
535
+ } catch {
536
+ }
537
+ }
267
538
  };
268
539
  }
269
-
270
- // src/contracts/mocks/eip712/burnConsent.mock.ts
271
- import {
272
- parseSignature as parseSignature2,
273
- recoverTypedDataAddress as recoverTypedDataAddress2
274
- } from "viem";
275
- var MOCK_BURN_CONSENT_TYPES = {
276
- BurnConsent: [
277
- { name: "user", type: "address" },
278
- { name: "pointToken", type: "address" },
279
- { name: "amount", type: "uint256" },
280
- { name: "nonce", type: "uint256" },
281
- { name: "deadline", type: "uint256" }
282
- ]
540
+ var webPopupAdapter = {
541
+ open(url, options) {
542
+ return openWebPopup(url, options);
543
+ }
283
544
  };
284
- function buildMockBurnConsentTypedData(domain, message) {
285
- return {
286
- domain: buildDomain(domain),
287
- types: MOCK_BURN_CONSENT_TYPES,
288
- primaryType: "BurnConsent",
289
- message
290
- };
545
+
546
+ // src/web-handoff/index.ts
547
+ var registeredAdapter = null;
548
+ function setPafiWebModalAdapter(adapter) {
549
+ registeredAdapter = adapter;
291
550
  }
292
- async function signMockBurnConsent(walletClient, domain, message) {
293
- const serialized = await walletClient.signTypedData({
294
- account: walletClient.account,
295
- domain: buildDomain(domain),
296
- types: MOCK_BURN_CONSENT_TYPES,
297
- primaryType: "BurnConsent",
298
- message
299
- });
300
- const { v, r, s } = parseSignature2(serialized);
301
- return {
302
- v: Number(v),
303
- r,
304
- s,
305
- serialized
306
- };
551
+ function getPafiWebModalAdapter() {
552
+ return registeredAdapter;
307
553
  }
308
- async function verifyMockBurnConsent(domain, message, signature, expectedUser) {
309
- const recoveredAddress = await recoverTypedDataAddress2({
310
- domain: buildDomain(domain),
311
- types: MOCK_BURN_CONSENT_TYPES,
312
- primaryType: "BurnConsent",
313
- message,
314
- signature
315
- });
316
- const isValid = recoveredAddress.toLowerCase() === expectedUser.toLowerCase();
317
- return {
318
- isValid,
319
- recoveredAddress
320
- };
554
+ async function openPafiWebModal(url, options = {}) {
555
+ if (!url || typeof url !== "string") {
556
+ throw new Error("openPafiWebModal: `url` is required");
557
+ }
558
+ if (registeredAdapter) {
559
+ return Promise.resolve(registeredAdapter.open(url, options));
560
+ }
561
+ if (typeof window !== "undefined" && typeof window.open === "function") {
562
+ return openWebPopup(url, options);
563
+ }
564
+ throw new Error(
565
+ "openPafiWebModal: no adapter registered and `window.open` is unavailable. Call `setPafiWebModalAdapter()` with a platform-specific adapter (e.g. SFSafariViewController on iOS) during app boot."
566
+ );
321
567
  }
322
568
 
323
569
  // src/index.ts
324
570
  var PafiSDK = class {
325
571
  _pointTokenAddress;
326
- _relayContractAddress;
327
572
  _signer;
328
573
  _provider;
329
574
  _chainId;
330
575
  constructor(config) {
331
576
  this._pointTokenAddress = config.pointTokenAddress;
332
- this._relayContractAddress = config.relayContractAddress;
333
577
  this._signer = config.signer;
334
578
  this._chainId = config.chainId;
335
579
  if (config.provider) {
@@ -346,9 +590,6 @@ var PafiSDK = class {
346
590
  setPointTokenAddress(address) {
347
591
  this._pointTokenAddress = address;
348
592
  }
349
- setRelayContractAddress(address) {
350
- this._relayContractAddress = address;
351
- }
352
593
  setSigner(signer) {
353
594
  this._signer = signer;
354
595
  }
@@ -395,18 +636,10 @@ var PafiSDK = class {
395
636
  // -------------------------------------------------------------------------
396
637
  // EIP-712 — delegates to pure functions
397
638
  // -------------------------------------------------------------------------
398
- /**
399
- * Build the EIP-712 typed data for a MintRequest.
400
- * Pass the result to any external signer (Privy, WalletConnect, etc.).
401
- */
402
639
  async buildMintRequestTypedData(message) {
403
640
  const domain = await this.getDomain();
404
641
  return buildMintRequestTypedData(domain, message);
405
642
  }
406
- /**
407
- * Build the EIP-712 typed data for a ReceiverConsent.
408
- * Pass the result to any external signer (Privy, WalletConnect, etc.).
409
- */
410
643
  async buildReceiverConsentTypedData(message) {
411
644
  const domain = await this.getDomain();
412
645
  return buildReceiverConsentTypedData(domain, message);
@@ -445,15 +678,6 @@ var PafiSDK = class {
445
678
  );
446
679
  }
447
680
  // -------------------------------------------------------------------------
448
- // Relay calldata — delegates to pure functions
449
- // -------------------------------------------------------------------------
450
- encodeMintAndSwap(mint, swap) {
451
- return encodeMintAndSwap(mint, swap);
452
- }
453
- decodeMintAndSwap(calldata) {
454
- return decodeMintAndSwap(calldata);
455
- }
456
- // -------------------------------------------------------------------------
457
681
  // Quoting — delegates to pure functions
458
682
  // -------------------------------------------------------------------------
459
683
  /**
@@ -483,41 +707,9 @@ var PafiSDK = class {
483
707
  buildSwapFromQuote(params) {
484
708
  return buildSwapFromQuote(params);
485
709
  }
486
- /**
487
- * Build Relay SwapParams + extData from a quote result.
488
- * Returns ready-to-use args for `Relay.mintAndSwap`.
489
- */
490
- buildRelaySwapParams(params) {
491
- return buildRelaySwapParams(params);
492
- }
493
- /**
494
- * Encode extData for ReceiverConsent and MintParams.
495
- * extData = abi.encode(minAmountOut, feeInUsdt)
496
- */
497
- encodeExtData(minAmountOut, feeInUsdt) {
498
- return encodeExtData(minAmountOut, feeInUsdt);
499
- }
500
710
  // -------------------------------------------------------------------------
501
711
  // Simulation — dry-run via eth_call (no gas spent)
502
712
  // -------------------------------------------------------------------------
503
- /**
504
- * Simulate a Relay.mintAndSwap call. Catches reverts (bad signatures,
505
- * expired deadlines, insufficient mint cap, pool errors) before submitting.
506
- *
507
- * @param relayAddress - Relay contract address
508
- * @param mint - MintParams with real signatures
509
- * @param swap - SwapParams (path + deadline)
510
- * @param from - Relayer address that will submit the tx
511
- */
512
- async simulateMintAndSwap(relayAddress, mint, swap, from) {
513
- return simulateMintAndSwap(
514
- this.requireProvider(),
515
- relayAddress,
516
- mint,
517
- swap,
518
- from
519
- );
520
- }
521
713
  /**
522
714
  * Simulate a UniversalRouter.execute swap call. Catches reverts (bad
523
715
  * approvals, insufficient balance, pool errors) before submitting.
@@ -540,17 +732,7 @@ var PafiSDK = class {
540
732
  }
541
733
  // -------------------------------------------------------------------------
542
734
  // Auth — EIP-4361 login helpers (offline, stateless)
543
- //
544
- // These are convenience wrappers around the pure functions in
545
- // `./auth/loginMessage.ts`. They do NOT hit the network — the caller is
546
- // responsible for fetching the nonce, POSTing the signed message, and
547
- // storing the JWT returned by the issuer backend.
548
735
  // -------------------------------------------------------------------------
549
- /**
550
- * Build an EIP-4361 login message for the current signer + chain. The
551
- * caller supplies the issuer-specific fields (domain, nonce, uri); the SDK
552
- * fills in the wallet address and chain id from its own config.
553
- */
554
736
  async createLoginMessage(params) {
555
737
  const signer = this.requireSigner();
556
738
  const chainId = this.requireChainId();
@@ -573,27 +755,30 @@ var PafiSDK = class {
573
755
  export {
574
756
  ApiError,
575
757
  BATCH_EXECUTOR_ABI,
576
- MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET as BATCH_EXECUTOR_ADDRESS_BASE_MAINNET,
577
- MOCK_BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA as BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA,
578
- MOCK_BURN_CONSENT_TYPES as BURN_CONSENT_TYPES,
758
+ BATCH_EXECUTOR_ADDRESS_BASE_MAINNET,
759
+ BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA,
760
+ BROKER_HASHES,
579
761
  COMMON_POOLS,
580
762
  COMMON_TOKENS,
581
- MOCK_ADDRESSES as CONTRACT_ADDRESSES,
763
+ CONTRACT_ADDRESSES,
582
764
  ConfigurationError,
583
765
  ENTRY_POINT_V07,
584
- MOCK_MINT_REQUEST_V2_TYPES as MINT_REQUEST_V2_TYPES,
766
+ ORDERLY_VAULT_ABI,
767
+ ORDERLY_VAULT_ADDRESSES,
768
+ ORDERLY_VAULT_BASE_MAINNET,
769
+ POINT_TOKEN_FACTORY_ADDRESSES,
770
+ POINT_TOKEN_IMPL_ADDRESSES,
585
771
  POINT_TOKEN_POOLS,
586
- MOCK_POINT_TOKEN_V2_ABI as POINT_TOKEN_V2_ABI,
772
+ POINT_TOKEN_ABI as POINT_TOKEN_V2_ABI,
587
773
  PafiSDK,
588
774
  PafiSDKError,
589
- MOCK_RELAYER_V2_ABI as RELAYER_V2_ABI,
590
- MOCK_RELAYER_V2_MINT_SELECTOR as RELAYER_V2_MINT_SELECTOR,
591
775
  SETTLE_ALL,
592
776
  SUPPORTED_CHAINS,
593
777
  SWAP_EXACT_IN,
594
778
  SigningError,
595
779
  SimulationError,
596
780
  TAKE_ALL,
781
+ TOKEN_HASHES,
597
782
  UNIVERSAL_ROUTER_ADDRESSES,
598
783
  V4_QUOTER_ADDRESSES,
599
784
  V4_SWAP,
@@ -601,49 +786,53 @@ export {
601
786
  _resetPaymasterConfigForTests,
602
787
  assembleUserOperation,
603
788
  buildAllPaths,
604
- buildMockBurnConsentTypedData as buildBurnConsentTypedData,
789
+ buildBurnRequestTypedData,
790
+ buildDelegationUserOp,
605
791
  buildDomain,
606
792
  buildErc20ApprovalCalldata,
607
793
  buildMintRequestTypedData,
608
- buildMockMintRequestV2TypedData as buildMintRequestV2TypedData,
609
794
  buildPartialUserOperation,
610
795
  buildPermit2ApprovalCalldata,
796
+ buildPerpDepositWithGasDeduction,
611
797
  buildReceiverConsentTypedData,
612
- buildRelaySwapParams,
613
798
  buildSwapFromQuote,
614
799
  buildSwapWithGasDeduction,
615
800
  buildUniversalRouterExecuteArgs,
616
801
  buildV4SwapInput,
802
+ burnRequestTypes,
617
803
  checkAllowance,
804
+ checkDelegation,
618
805
  checkEthAndBranch,
619
806
  combineRoutes,
807
+ computeAccountId,
620
808
  createLoginMessage,
621
- decodeExtData,
622
- decodeMintAndSwap,
623
809
  encodeBatchExecute,
624
- encodeExtData,
625
- encodeMintAndSwap,
626
810
  erc20Abi,
627
811
  erc20ApproveOp,
628
812
  erc20BurnOp,
629
813
  erc20TransferOp,
630
814
  findBestQuote,
631
- getMockAddresses as getContractAddresses,
815
+ getAaNonce,
816
+ getContractAddresses,
632
817
  getIssuer2 as getIssuer,
633
818
  getMintRequestNonce,
819
+ getPafiWebModalAdapter,
634
820
  getPaymasterConfig,
635
821
  getPointTokenBalance,
636
822
  getPointTokenIssuer,
637
823
  getIssuer as getPointTokenIssuerAddress,
638
824
  getReceiverConsentNonce,
639
825
  getTokenName,
640
- getUsdt,
641
826
  isActiveIssuer,
827
+ isDelegatedTo,
642
828
  isMinter,
643
829
  isPaymasterConfigured,
644
830
  issuerRegistryAbi,
645
831
  mintRequestTypes,
646
832
  mintingOracleAbi,
833
+ openPafiWebModal,
834
+ openWebPopup,
835
+ parseEip7702DelegatedAddress,
647
836
  parseLoginMessage,
648
837
  permit2Abi,
649
838
  pointTokenAbi,
@@ -653,21 +842,19 @@ export {
653
842
  quoteExactInputSingle,
654
843
  rawCallOp,
655
844
  receiverConsentTypes,
656
- relayAbi,
845
+ setPafiWebModalAdapter,
657
846
  setPaymasterConfig,
658
- signMockBurnConsent as signBurnConsent,
847
+ signBurnRequest,
659
848
  signMintRequest,
660
- signMockMintRequestV2 as signMintRequestV2,
661
849
  signReceiverConsent,
662
- simulateMintAndSwap,
663
850
  simulateSwap,
664
851
  universalRouterAbi,
665
852
  v4QuoterAbi,
666
- verifyMockBurnConsent as verifyBurnConsent,
853
+ verifyBurnRequest,
667
854
  verifyLoginMessage,
668
855
  verifyMintCap,
669
856
  verifyMintRequest,
670
- verifyMockMintRequestV2 as verifyMintRequestV2,
671
- verifyReceiverConsent
857
+ verifyReceiverConsent,
858
+ webPopupAdapter
672
859
  };
673
860
  //# sourceMappingURL=index.js.map