@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
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,141 +53,189 @@ 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,
62
+ BATCH_EXECUTOR_ABI,
63
+ ConfigurationError,
64
+ PafiSDKError,
69
65
  SETTLE_ALL,
70
66
  SWAP_EXACT_IN,
67
+ SigningError,
68
+ SimulationError,
71
69
  TAKE_ALL,
72
70
  V4_SWAP,
71
+ assembleUserOperation,
73
72
  buildErc20ApprovalCalldata,
73
+ buildPartialUserOperation,
74
74
  buildPermit2ApprovalCalldata,
75
75
  buildSwapFromQuote,
76
+ buildSwapWithGasDeduction,
76
77
  buildUniversalRouterExecuteArgs,
77
78
  buildV4SwapInput,
78
79
  checkAllowance,
80
+ encodeBatchExecute,
81
+ erc20ApproveOp,
82
+ erc20BurnOp,
83
+ erc20TransferOp,
84
+ rawCallOp,
79
85
  simulateSwap
80
- } from "./chunk-UU72CX7E.js";
86
+ } from "./chunk-W23EJNYG.js";
81
87
  import {
82
88
  erc20Abi,
83
89
  permit2Abi,
84
90
  universalRouterAbi
85
91
  } from "./chunk-2PIXFXA2.js";
86
- import {
87
- ApiError,
88
- ConfigurationError,
89
- PafiSDKError,
90
- SigningError,
91
- SimulationError
92
- } from "./chunk-P56TUGTS.js";
93
92
 
94
93
  // src/index.ts
95
94
  import { createPublicClient, http } from "viem";
96
95
 
97
- // src/userop/types.ts
98
- var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
99
- var ZERO_VALUE = 0n;
96
+ // src/perp/buildPerpDepositWithGasDeduction.ts
97
+ import { encodeFunctionData } from "viem";
100
98
 
101
- // src/userop/operations.ts
102
- import { encodeFunctionData, erc20Abi as erc20Abi2, parseAbi } from "viem";
103
- var ERC20_BURNABLE_ABI = parseAbi(["function burn(uint256 amount)"]);
104
- function erc20TransferOp(token, to, amount) {
105
- return {
106
- target: token,
107
- value: 0n,
108
- data: encodeFunctionData({
109
- abi: erc20Abi2,
110
- functionName: "transfer",
111
- args: [to, amount]
112
- })
113
- };
114
- }
115
- function erc20ApproveOp(token, spender, amount) {
116
- return {
117
- target: token,
118
- value: 0n,
119
- data: encodeFunctionData({
120
- abi: erc20Abi2,
121
- functionName: "approve",
122
- args: [spender, amount]
123
- })
124
- };
125
- }
126
- function erc20BurnOp(token, amount) {
127
- return {
128
- target: token,
129
- value: 0n,
130
- data: encodeFunctionData({
131
- abi: ERC20_BURNABLE_ABI,
132
- functionName: "burn",
133
- args: [amount]
134
- })
135
- };
136
- }
137
- function rawCallOp(target, data, value = 0n) {
138
- return { target, value, data };
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
+ );
139
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
+ ];
140
187
 
141
- // src/userop/batchExecute.ts
142
- import { encodeFunctionData as encodeFunctionData2, parseAbi as parseAbi2 } from "viem";
143
- var BATCH_EXECUTOR_ABI = parseAbi2([
144
- "function execute((address target, uint256 value, bytes data)[] calls)"
145
- ]);
146
- function encodeBatchExecute(operations) {
147
- if (operations.length === 0) {
148
- throw new Error("encodeBatchExecute: operations array must not be empty");
149
- }
150
- return encodeFunctionData2({
151
- abi: BATCH_EXECUTOR_ABI,
152
- functionName: "execute",
153
- args: [
154
- operations.map((op) => ({
155
- target: op.target,
156
- value: op.value,
157
- data: op.data
158
- }))
159
- ]
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
+ }
160
233
  });
161
234
  }
162
235
 
163
- // src/userop/buildUserOperation.ts
164
- var DEFAULT_CALL_GAS_LIMIT = 500000n;
165
- var DEFAULT_VERIFICATION_GAS_LIMIT = 150000n;
166
- var DEFAULT_PRE_VERIFICATION_GAS = 50000n;
167
- function buildPartialUserOperation(params) {
168
- return {
169
- sender: params.sender,
170
- nonce: params.nonce,
171
- callData: encodeBatchExecute(params.operations),
172
- callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT,
173
- verificationGasLimit: params.gasLimits?.verificationGasLimit ?? DEFAULT_VERIFICATION_GAS_LIMIT,
174
- preVerificationGas: params.gasLimits?.preVerificationGas ?? DEFAULT_PRE_VERIFICATION_GAS,
175
- maxFeePerGas: params.feeOverrides?.maxFeePerGas ?? 0n,
176
- maxPriorityFeePerGas: params.feeOverrides?.maxPriorityFeePerGas ?? 0n
177
- };
178
- }
179
- function assembleUserOperation(partial, paymaster, signature) {
180
- return {
181
- ...partial,
182
- paymaster: paymaster.paymaster,
183
- paymasterData: paymaster.paymasterData,
184
- paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,
185
- paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,
186
- signature
187
- };
188
- }
236
+ // src/userop/types.ts
237
+ var ENTRY_POINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
238
+ var ZERO_VALUE = 0n;
189
239
 
190
240
  // src/paymaster/config.ts
191
241
  var _config = null;
@@ -230,186 +280,233 @@ async function checkEthAndBranch(params) {
230
280
  return balance >= required ? "normal" : "paymaster";
231
281
  }
232
282
 
233
- // src/contracts/mocks/relayerV2.mock.ts
234
- import { parseAbi as parseAbi3 } from "viem";
235
- var MOCK_RELAYER_V2_ABI = parseAbi3([
236
- "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",
237
- // View functions we'll likely want (nonce getter is standard)
238
- "function mintRequestNonce(address user) external view returns (uint256)",
239
- "event Minted(address indexed user, uint256 amount, uint256 feeAmount, address indexed feeRecipient, bytes32 requestHash)"
283
+ // src/contracts/real/pointToken.ts
284
+ import { parseAbi } from "viem";
285
+ var POINT_TOKEN_ABI = parseAbi([
286
+ // --- Mint paths ---
287
+ "function mint(address to, uint256 amount) external",
288
+ "function mint(address to, uint256 amount, uint256 deadline, bytes minterSig) external",
289
+ // --- Burn paths ---
290
+ "function burn(address from, uint256 amount) external",
291
+ "function burn(address from, uint256 amount, uint256 deadline, bytes burnerSig) external",
292
+ // --- Authorization reads ---
293
+ "function minters(address account) external view returns (bool)",
294
+ "function burners(address account) external view returns (bool)",
295
+ // --- Authorization writes (owner-only; used by provisioning scripts) ---
296
+ "function addMinter(address minter) external",
297
+ "function removeMinter(address minter) external",
298
+ "function addBurner(address burner) external",
299
+ "function removeBurner(address burner) external",
300
+ // --- Nonces (sig-gated paths) ---
301
+ "function mintRequestNonces(address receiver) external view returns (uint256)",
302
+ "function burnRequestNonces(address from) external view returns (uint256)",
303
+ // --- Oracle ---
304
+ "function mintingOracle() external view returns (address)",
305
+ "function setMintingOracle(address _mintingOracle) external",
306
+ // --- Issuer ---
307
+ "function issuer() external view returns (address)",
308
+ // --- Standard ERC-20 reads ---
309
+ "function balanceOf(address account) external view returns (uint256)",
310
+ "function totalSupply() external view returns (uint256)",
311
+ "function name() external view returns (string)",
312
+ "function symbol() external view returns (string)",
313
+ "function decimals() external view returns (uint8)",
314
+ // --- EIP-712 domain (for off-chain sig verification) ---
315
+ "function DOMAIN_SEPARATOR() external view returns (bytes32)",
316
+ "function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)",
317
+ // --- Events ---
318
+ // PointIndexer filters Transfer(from=0x0) for mints
319
+ // BurnIndexer filters Transfer(to=0x0) for burns
320
+ "event Transfer(address indexed from, address indexed to, uint256 value)",
321
+ "event MinterAdded(address indexed minter)",
322
+ "event MinterRemoved(address indexed minter)",
323
+ "event BurnerAdded(address indexed burner)",
324
+ "event BurnerRemoved(address indexed burner)",
325
+ "event MintingOracleUpdated(address indexed mintingOracle)"
240
326
  ]);
241
- var MOCK_RELAYER_V2_MINT_SELECTOR = "0xMOCKED__";
242
327
 
243
- // src/contracts/mocks/pointTokenV2.mock.ts
244
- import { parseAbi as parseAbi4 } from "viem";
245
- var MOCK_POINT_TOKEN_V2_ABI = parseAbi4([
246
- // Variant A
247
- "function burn(uint256 amount) external",
248
- // Variant B
249
- "function burnWithSig((address user, address pointToken, uint256 amount, uint256 nonce, uint256 deadline) consent, (uint8 v, bytes32 r, bytes32 s) sig) external",
250
- // Standard reads we always need
251
- "function balanceOf(address user) external view returns (uint256)",
252
- "function burnNonce(address user) external view returns (uint256)",
253
- // ERC-20 Transfer event (inherited) — BurnIndexer filters `to = 0x0`
254
- "event Transfer(address indexed from, address indexed to, uint256 value)"
255
- ]);
256
-
257
- // src/contracts/mocks/batchExecutor.mock.ts
258
- var MOCK_BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = "0x000000000000000000000000000000000000DE01";
259
- var MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = "0x000000000000000000000000000000000000DE02";
328
+ // src/contracts/real/batchExecutor.ts
329
+ var BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = "0x000000000000000000000000000000000000DE01";
330
+ var BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = "0x7702cb554e6bFb442cb743A7dF23154544a7176C";
260
331
 
261
- // src/contracts/mocks/addresses.mock.ts
262
- var MOCK_PLACEHOLDER = (suffix) => `0x000000000000000000000000000000000000${suffix.toLowerCase().padStart(4, "0")}`;
263
- var MOCK_ADDRESSES = {
264
- // Base Sepoliasafe targets for integration tests (MockRelayer
265
- // fixtures deployed by Hardhat will override these at test time)
266
- 84532: {
267
- relayerV2: MOCK_PLACEHOLDER("de10"),
268
- pointToken: MOCK_PLACEHOLDER("de11"),
269
- batchExecutor: MOCK_PLACEHOLDER("de01"),
270
- usdt: MOCK_PLACEHOLDER("de12"),
271
- issuerRegistry: MOCK_PLACEHOLDER("de13"),
272
- mintingOracle: MOCK_PLACEHOLDER("de14")
273
- },
274
- // Base mainnet — intentionally left as placeholder. Do NOT ship to
275
- // prod without swapping.
332
+ // src/contracts/real/addresses.ts
333
+ var PLACEHOLDER_DEAD = (suffix) => `0x000000000000000000000000000000000000${suffix.toLowerCase().padStart(4, "0")}`;
334
+ var CONTRACT_ADDRESSES = {
335
+ // Base mainnetSC-delivered (2026-04-21, 2026-04-22)
336
+ // registry: IssuerRegistry 0xda2D3338CF70F462Ac175F5f2edfa45660CA4f31
337
+ // factory: PointTokenFactory 0x36c0BAb2faBE45EfA6d13001143e43A266Af673B
338
+ // oracle: MintingOracle 0xD85165939C700E51c8a45099316C6482634C2Ab9
339
+ // tokenImpl: PointToken (impl) 0x2e6FB1B0C1A51abb83eC974890126a64eC02E995
340
+ // mockUsdt: MockERC20 0x5d313485Ba59C3bb91e1A9C0C11782F0b83d5dcd
341
+ // POINT: PointToken instance 0x7d25E7156E51F865D522fd3ef257a6B5DD41b97e
342
+ // batchExecutor: Coinbase SW v2 0x7702cb554e6bFb442cb743A7dF23154544a7176C
343
+ // pafiHook: PAFIHook (V4, 10%) 0x870cAF9882d3160602AaC1769C2B264A2d8EC044
276
344
  8453: {
277
- relayerV2: MOCK_PLACEHOLDER("dead"),
278
- pointToken: MOCK_PLACEHOLDER("dead"),
279
- batchExecutor: MOCK_PLACEHOLDER("dead"),
280
- usdt: MOCK_PLACEHOLDER("dead"),
281
- issuerRegistry: MOCK_PLACEHOLDER("dead"),
282
- mintingOracle: MOCK_PLACEHOLDER("dead")
345
+ pointToken: "0x7d25E7156E51F865D522fd3ef257a6B5DD41b97e",
346
+ batchExecutor: "0x7702cb554e6bFb442cb743A7dF23154544a7176C",
347
+ usdt: "0x5d313485Ba59C3bb91e1A9C0C11782F0b83d5dcd",
348
+ issuerRegistry: "0xda2D3338CF70F462Ac175F5f2edfa45660CA4f31",
349
+ mintingOracle: "0xD85165939C700E51c8a45099316C6482634C2Ab9",
350
+ pafiHook: "0x870cAF9882d3160602AaC1769C2B264A2d8EC044"
351
+ },
352
+ // Base Sepolia — not in active use; placeholders kept so the map
353
+ // compiles for tooling that enumerates chains.
354
+ 84532: {
355
+ pointToken: PLACEHOLDER_DEAD("dead"),
356
+ batchExecutor: PLACEHOLDER_DEAD("de01"),
357
+ usdt: PLACEHOLDER_DEAD("dead"),
358
+ issuerRegistry: PLACEHOLDER_DEAD("dead"),
359
+ mintingOracle: PLACEHOLDER_DEAD("dead"),
360
+ pafiHook: PLACEHOLDER_DEAD("dead")
283
361
  }
284
362
  };
285
- function getMockAddresses(chainId) {
286
- const addrs = MOCK_ADDRESSES[chainId];
363
+ var POINT_TOKEN_FACTORY_ADDRESSES = {
364
+ 8453: "0x36c0BAb2faBE45EfA6d13001143e43A266Af673B",
365
+ 84532: PLACEHOLDER_DEAD("dead")
366
+ };
367
+ var POINT_TOKEN_IMPL_ADDRESSES = {
368
+ 8453: "0x2e6FB1B0C1A51abb83eC974890126a64eC02E995",
369
+ 84532: PLACEHOLDER_DEAD("dead")
370
+ };
371
+ function getContractAddresses(chainId) {
372
+ const addrs = CONTRACT_ADDRESSES[chainId];
287
373
  if (!addrs) {
288
374
  throw new Error(
289
- `getMockAddresses: no mock addresses for chainId ${chainId}. Supported: ${Object.keys(MOCK_ADDRESSES).join(", ")}`
375
+ `getContractAddresses: no addresses for chainId ${chainId}. Supported: ${Object.keys(CONTRACT_ADDRESSES).join(", ")}`
290
376
  );
291
377
  }
292
378
  return addrs;
293
379
  }
294
380
 
295
- // src/contracts/mocks/eip712/mintRequestV2.mock.ts
296
- import {
297
- parseSignature,
298
- recoverTypedDataAddress
299
- } from "viem";
300
- var MOCK_MINT_REQUEST_V2_TYPES = {
301
- MintRequest: [
302
- { name: "to", type: "address" },
303
- { name: "amount", type: "uint256" },
304
- { name: "feeAmount", type: "uint256" },
305
- { name: "feeRecipient", type: "address" },
306
- { name: "nonce", type: "uint256" },
307
- { name: "deadline", type: "uint256" },
308
- { name: "extData", type: "bytes" }
309
- ]
310
- };
311
- function buildMockMintRequestV2TypedData(domain, message) {
312
- return {
313
- domain: buildDomain(domain),
314
- types: MOCK_MINT_REQUEST_V2_TYPES,
315
- primaryType: "MintRequest",
316
- message
317
- };
318
- }
319
- async function signMockMintRequestV2(walletClient, domain, message) {
320
- const serialized = await walletClient.signTypedData({
321
- account: walletClient.account,
322
- domain: buildDomain(domain),
323
- types: MOCK_MINT_REQUEST_V2_TYPES,
324
- primaryType: "MintRequest",
325
- message
326
- });
327
- const { v, r, s } = parseSignature(serialized);
328
- return {
329
- v: Number(v),
330
- r,
331
- s,
332
- serialized
381
+ // src/web-handoff/webPopup.ts
382
+ var DEFAULT_WIDTH = 900;
383
+ var DEFAULT_HEIGHT = 700;
384
+ var DEFAULT_NAME = "pafi-web";
385
+ function openWebPopup(url, options = {}) {
386
+ if (typeof window === "undefined" || typeof window.open !== "function") {
387
+ throw new Error(
388
+ "openWebPopup: `window.open` is not available in this runtime. Register a platform adapter via setPafiWebModalAdapter() instead."
389
+ );
390
+ }
391
+ const width = options.width ?? DEFAULT_WIDTH;
392
+ const height = options.height ?? DEFAULT_HEIGHT;
393
+ const name = options.windowName ?? DEFAULT_NAME;
394
+ const screenW = window.screen?.availWidth ?? window.innerWidth;
395
+ const screenH = window.screen?.availHeight ?? window.innerHeight;
396
+ const left = Math.max(0, Math.floor((screenW - width) / 2));
397
+ const top = Math.max(0, Math.floor((screenH - height) / 2));
398
+ const features = [
399
+ `width=${width}`,
400
+ `height=${height}`,
401
+ `left=${left}`,
402
+ `top=${top}`,
403
+ "resizable=yes",
404
+ "scrollbars=yes",
405
+ "noopener=no"
406
+ // we need opener.postMessage to work
407
+ ].join(",");
408
+ const popup = window.open(url, name, features);
409
+ if (!popup) {
410
+ throw new Error(
411
+ "openWebPopup: popup was blocked. Ensure this call runs inside a user gesture (click handler)."
412
+ );
413
+ }
414
+ let closed = false;
415
+ let pollId = null;
416
+ let messageListener = null;
417
+ const dispose = () => {
418
+ if (closed) return;
419
+ closed = true;
420
+ if (pollId !== null) {
421
+ clearInterval(pollId);
422
+ pollId = null;
423
+ }
424
+ if (messageListener) {
425
+ window.removeEventListener("message", messageListener);
426
+ messageListener = null;
427
+ }
428
+ options.onClose?.();
333
429
  };
334
- }
335
- async function verifyMockMintRequestV2(domain, message, signature, expectedSigner) {
336
- const recoveredAddress = await recoverTypedDataAddress({
337
- domain: buildDomain(domain),
338
- types: MOCK_MINT_REQUEST_V2_TYPES,
339
- primaryType: "MintRequest",
340
- message,
341
- signature
342
- });
343
- const isValid = recoveredAddress.toLowerCase() === expectedSigner.toLowerCase();
430
+ pollId = setInterval(() => {
431
+ if (popup.closed) {
432
+ dispose();
433
+ }
434
+ }, 500);
435
+ if (options.onMessage) {
436
+ const allowed = options.allowedOrigins ?? [];
437
+ const onMessage = options.onMessage;
438
+ messageListener = (event) => {
439
+ if (event.source !== popup) return;
440
+ if (!allowed.includes(event.origin)) return;
441
+ onMessage(event.data, event.origin);
442
+ };
443
+ window.addEventListener("message", messageListener);
444
+ }
344
445
  return {
345
- isValid,
346
- recoveredAddress
446
+ get isOpen() {
447
+ return !closed && !popup.closed;
448
+ },
449
+ close() {
450
+ if (closed) return;
451
+ try {
452
+ popup.close();
453
+ } catch {
454
+ }
455
+ dispose();
456
+ },
457
+ focus() {
458
+ if (closed || popup.closed) return;
459
+ try {
460
+ popup.focus();
461
+ } catch {
462
+ }
463
+ },
464
+ postMessage(data) {
465
+ if (closed || popup.closed) return;
466
+ try {
467
+ popup.postMessage(data, "*");
468
+ } catch {
469
+ }
470
+ }
347
471
  };
348
472
  }
349
-
350
- // src/contracts/mocks/eip712/burnConsent.mock.ts
351
- import {
352
- parseSignature as parseSignature2,
353
- recoverTypedDataAddress as recoverTypedDataAddress2
354
- } from "viem";
355
- var MOCK_BURN_CONSENT_TYPES = {
356
- BurnConsent: [
357
- { name: "user", type: "address" },
358
- { name: "pointToken", type: "address" },
359
- { name: "amount", type: "uint256" },
360
- { name: "nonce", type: "uint256" },
361
- { name: "deadline", type: "uint256" }
362
- ]
473
+ var webPopupAdapter = {
474
+ open(url, options) {
475
+ return openWebPopup(url, options);
476
+ }
363
477
  };
364
- function buildMockBurnConsentTypedData(domain, message) {
365
- return {
366
- domain: buildDomain(domain),
367
- types: MOCK_BURN_CONSENT_TYPES,
368
- primaryType: "BurnConsent",
369
- message
370
- };
478
+
479
+ // src/web-handoff/index.ts
480
+ var registeredAdapter = null;
481
+ function setPafiWebModalAdapter(adapter) {
482
+ registeredAdapter = adapter;
371
483
  }
372
- async function signMockBurnConsent(walletClient, domain, message) {
373
- const serialized = await walletClient.signTypedData({
374
- account: walletClient.account,
375
- domain: buildDomain(domain),
376
- types: MOCK_BURN_CONSENT_TYPES,
377
- primaryType: "BurnConsent",
378
- message
379
- });
380
- const { v, r, s } = parseSignature2(serialized);
381
- return {
382
- v: Number(v),
383
- r,
384
- s,
385
- serialized
386
- };
484
+ function getPafiWebModalAdapter() {
485
+ return registeredAdapter;
387
486
  }
388
- async function verifyMockBurnConsent(domain, message, signature, expectedUser) {
389
- const recoveredAddress = await recoverTypedDataAddress2({
390
- domain: buildDomain(domain),
391
- types: MOCK_BURN_CONSENT_TYPES,
392
- primaryType: "BurnConsent",
393
- message,
394
- signature
395
- });
396
- const isValid = recoveredAddress.toLowerCase() === expectedUser.toLowerCase();
397
- return {
398
- isValid,
399
- recoveredAddress
400
- };
487
+ async function openPafiWebModal(url, options = {}) {
488
+ if (!url || typeof url !== "string") {
489
+ throw new Error("openPafiWebModal: `url` is required");
490
+ }
491
+ if (registeredAdapter) {
492
+ return Promise.resolve(registeredAdapter.open(url, options));
493
+ }
494
+ if (typeof window !== "undefined" && typeof window.open === "function") {
495
+ return openWebPopup(url, options);
496
+ }
497
+ throw new Error(
498
+ "openPafiWebModal: no adapter registered and `window.open` is unavailable. Call `setPafiWebModalAdapter()` with a platform-specific adapter (e.g. SFSafariViewController on iOS) during app boot."
499
+ );
401
500
  }
402
501
 
403
502
  // src/index.ts
404
503
  var PafiSDK = class {
405
504
  _pointTokenAddress;
406
- _relayContractAddress;
407
505
  _signer;
408
506
  _provider;
409
507
  _chainId;
410
508
  constructor(config) {
411
509
  this._pointTokenAddress = config.pointTokenAddress;
412
- this._relayContractAddress = config.relayContractAddress;
413
510
  this._signer = config.signer;
414
511
  this._chainId = config.chainId;
415
512
  if (config.provider) {
@@ -426,9 +523,6 @@ var PafiSDK = class {
426
523
  setPointTokenAddress(address) {
427
524
  this._pointTokenAddress = address;
428
525
  }
429
- setRelayContractAddress(address) {
430
- this._relayContractAddress = address;
431
- }
432
526
  setSigner(signer) {
433
527
  this._signer = signer;
434
528
  }
@@ -475,18 +569,10 @@ var PafiSDK = class {
475
569
  // -------------------------------------------------------------------------
476
570
  // EIP-712 — delegates to pure functions
477
571
  // -------------------------------------------------------------------------
478
- /**
479
- * Build the EIP-712 typed data for a MintRequest.
480
- * Pass the result to any external signer (Privy, WalletConnect, etc.).
481
- */
482
572
  async buildMintRequestTypedData(message) {
483
573
  const domain = await this.getDomain();
484
574
  return buildMintRequestTypedData(domain, message);
485
575
  }
486
- /**
487
- * Build the EIP-712 typed data for a ReceiverConsent.
488
- * Pass the result to any external signer (Privy, WalletConnect, etc.).
489
- */
490
576
  async buildReceiverConsentTypedData(message) {
491
577
  const domain = await this.getDomain();
492
578
  return buildReceiverConsentTypedData(domain, message);
@@ -525,15 +611,6 @@ var PafiSDK = class {
525
611
  );
526
612
  }
527
613
  // -------------------------------------------------------------------------
528
- // Relay calldata — delegates to pure functions
529
- // -------------------------------------------------------------------------
530
- encodeMintAndSwap(mint, swap) {
531
- return encodeMintAndSwap(mint, swap);
532
- }
533
- decodeMintAndSwap(calldata) {
534
- return decodeMintAndSwap(calldata);
535
- }
536
- // -------------------------------------------------------------------------
537
614
  // Quoting — delegates to pure functions
538
615
  // -------------------------------------------------------------------------
539
616
  /**
@@ -563,41 +640,9 @@ var PafiSDK = class {
563
640
  buildSwapFromQuote(params) {
564
641
  return buildSwapFromQuote(params);
565
642
  }
566
- /**
567
- * Build Relay SwapParams + extData from a quote result.
568
- * Returns ready-to-use args for `Relay.mintAndSwap`.
569
- */
570
- buildRelaySwapParams(params) {
571
- return buildRelaySwapParams(params);
572
- }
573
- /**
574
- * Encode extData for ReceiverConsent and MintParams.
575
- * extData = abi.encode(minAmountOut, feeInUsdt)
576
- */
577
- encodeExtData(minAmountOut, feeInUsdt) {
578
- return encodeExtData(minAmountOut, feeInUsdt);
579
- }
580
643
  // -------------------------------------------------------------------------
581
644
  // Simulation — dry-run via eth_call (no gas spent)
582
645
  // -------------------------------------------------------------------------
583
- /**
584
- * Simulate a Relay.mintAndSwap call. Catches reverts (bad signatures,
585
- * expired deadlines, insufficient mint cap, pool errors) before submitting.
586
- *
587
- * @param relayAddress - Relay contract address
588
- * @param mint - MintParams with real signatures
589
- * @param swap - SwapParams (path + deadline)
590
- * @param from - Relayer address that will submit the tx
591
- */
592
- async simulateMintAndSwap(relayAddress, mint, swap, from) {
593
- return simulateMintAndSwap(
594
- this.requireProvider(),
595
- relayAddress,
596
- mint,
597
- swap,
598
- from
599
- );
600
- }
601
646
  /**
602
647
  * Simulate a UniversalRouter.execute swap call. Catches reverts (bad
603
648
  * approvals, insufficient balance, pool errors) before submitting.
@@ -620,17 +665,7 @@ var PafiSDK = class {
620
665
  }
621
666
  // -------------------------------------------------------------------------
622
667
  // Auth — EIP-4361 login helpers (offline, stateless)
623
- //
624
- // These are convenience wrappers around the pure functions in
625
- // `./auth/loginMessage.ts`. They do NOT hit the network — the caller is
626
- // responsible for fetching the nonce, POSTing the signed message, and
627
- // storing the JWT returned by the issuer backend.
628
668
  // -------------------------------------------------------------------------
629
- /**
630
- * Build an EIP-4361 login message for the current signer + chain. The
631
- * caller supplies the issuer-specific fields (domain, nonce, uri); the SDK
632
- * fills in the wallet address and chain id from its own config.
633
- */
634
669
  async createLoginMessage(params) {
635
670
  const signer = this.requireSigner();
636
671
  const chainId = this.requireChainId();
@@ -653,27 +688,30 @@ var PafiSDK = class {
653
688
  export {
654
689
  ApiError,
655
690
  BATCH_EXECUTOR_ABI,
656
- MOCK_BATCH_EXECUTOR_ADDRESS_BASE_MAINNET as BATCH_EXECUTOR_ADDRESS_BASE_MAINNET,
657
- MOCK_BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA as BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA,
658
- MOCK_BURN_CONSENT_TYPES as BURN_CONSENT_TYPES,
691
+ BATCH_EXECUTOR_ADDRESS_BASE_MAINNET,
692
+ BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA,
693
+ BROKER_HASHES,
659
694
  COMMON_POOLS,
660
695
  COMMON_TOKENS,
661
- MOCK_ADDRESSES as CONTRACT_ADDRESSES,
696
+ CONTRACT_ADDRESSES,
662
697
  ConfigurationError,
663
698
  ENTRY_POINT_V07,
664
- MOCK_MINT_REQUEST_V2_TYPES as MINT_REQUEST_V2_TYPES,
699
+ ORDERLY_VAULT_ABI,
700
+ ORDERLY_VAULT_ADDRESSES,
701
+ ORDERLY_VAULT_BASE_MAINNET,
702
+ POINT_TOKEN_FACTORY_ADDRESSES,
703
+ POINT_TOKEN_IMPL_ADDRESSES,
665
704
  POINT_TOKEN_POOLS,
666
- MOCK_POINT_TOKEN_V2_ABI as POINT_TOKEN_V2_ABI,
705
+ POINT_TOKEN_ABI as POINT_TOKEN_V2_ABI,
667
706
  PafiSDK,
668
707
  PafiSDKError,
669
- MOCK_RELAYER_V2_ABI as RELAYER_V2_ABI,
670
- MOCK_RELAYER_V2_MINT_SELECTOR as RELAYER_V2_MINT_SELECTOR,
671
708
  SETTLE_ALL,
672
709
  SUPPORTED_CHAINS,
673
710
  SWAP_EXACT_IN,
674
711
  SigningError,
675
712
  SimulationError,
676
713
  TAKE_ALL,
714
+ TOKEN_HASHES,
677
715
  UNIVERSAL_ROUTER_ADDRESSES,
678
716
  V4_QUOTER_ADDRESSES,
679
717
  V4_SWAP,
@@ -681,48 +719,48 @@ export {
681
719
  _resetPaymasterConfigForTests,
682
720
  assembleUserOperation,
683
721
  buildAllPaths,
684
- buildMockBurnConsentTypedData as buildBurnConsentTypedData,
722
+ buildBurnRequestTypedData,
685
723
  buildDomain,
686
724
  buildErc20ApprovalCalldata,
687
725
  buildMintRequestTypedData,
688
- buildMockMintRequestV2TypedData as buildMintRequestV2TypedData,
689
726
  buildPartialUserOperation,
690
727
  buildPermit2ApprovalCalldata,
728
+ buildPerpDepositWithGasDeduction,
691
729
  buildReceiverConsentTypedData,
692
- buildRelaySwapParams,
693
730
  buildSwapFromQuote,
731
+ buildSwapWithGasDeduction,
694
732
  buildUniversalRouterExecuteArgs,
695
733
  buildV4SwapInput,
734
+ burnRequestTypes,
696
735
  checkAllowance,
697
736
  checkEthAndBranch,
698
737
  combineRoutes,
738
+ computeAccountId,
699
739
  createLoginMessage,
700
- decodeExtData,
701
- decodeMintAndSwap,
702
740
  encodeBatchExecute,
703
- encodeExtData,
704
- encodeMintAndSwap,
705
741
  erc20Abi,
706
742
  erc20ApproveOp,
707
743
  erc20BurnOp,
708
744
  erc20TransferOp,
709
745
  findBestQuote,
710
- getMockAddresses as getContractAddresses,
746
+ getContractAddresses,
711
747
  getIssuer2 as getIssuer,
712
748
  getMintRequestNonce,
749
+ getPafiWebModalAdapter,
713
750
  getPaymasterConfig,
714
751
  getPointTokenBalance,
715
752
  getPointTokenIssuer,
716
753
  getIssuer as getPointTokenIssuerAddress,
717
754
  getReceiverConsentNonce,
718
755
  getTokenName,
719
- getUsdt,
720
756
  isActiveIssuer,
721
757
  isMinter,
722
758
  isPaymasterConfigured,
723
759
  issuerRegistryAbi,
724
760
  mintRequestTypes,
725
761
  mintingOracleAbi,
762
+ openPafiWebModal,
763
+ openWebPopup,
726
764
  parseLoginMessage,
727
765
  permit2Abi,
728
766
  pointTokenAbi,
@@ -732,21 +770,19 @@ export {
732
770
  quoteExactInputSingle,
733
771
  rawCallOp,
734
772
  receiverConsentTypes,
735
- relayAbi,
773
+ setPafiWebModalAdapter,
736
774
  setPaymasterConfig,
737
- signMockBurnConsent as signBurnConsent,
775
+ signBurnRequest,
738
776
  signMintRequest,
739
- signMockMintRequestV2 as signMintRequestV2,
740
777
  signReceiverConsent,
741
- simulateMintAndSwap,
742
778
  simulateSwap,
743
779
  universalRouterAbi,
744
780
  v4QuoterAbi,
745
- verifyMockBurnConsent as verifyBurnConsent,
781
+ verifyBurnRequest,
746
782
  verifyLoginMessage,
747
783
  verifyMintCap,
748
784
  verifyMintRequest,
749
- verifyMockMintRequestV2 as verifyMintRequestV2,
750
- verifyReceiverConsent
785
+ verifyReceiverConsent,
786
+ webPopupAdapter
751
787
  };
752
788
  //# sourceMappingURL=index.js.map