@pafi-dev/core 0.5.22 → 0.6.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.
Files changed (60) hide show
  1. package/dist/abi/index.cjs +3 -7
  2. package/dist/abi/index.cjs.map +1 -1
  3. package/dist/abi/index.js +6 -10
  4. package/dist/chunk-3QDZFDEL.cjs +223 -0
  5. package/dist/chunk-3QDZFDEL.cjs.map +1 -0
  6. package/dist/{chunk-Y2MZ7MKJ.js → chunk-6CXTFOIH.js} +196 -2
  7. package/dist/chunk-6CXTFOIH.js.map +1 -0
  8. package/dist/{chunk-R6OFGVMP.cjs → chunk-Q6WCDZXI.cjs} +196 -2
  9. package/dist/chunk-Q6WCDZXI.cjs.map +1 -0
  10. package/dist/{chunk-TXA4GK5C.js → chunk-UOKI5GG6.js} +87 -7
  11. package/dist/chunk-UOKI5GG6.js.map +1 -0
  12. package/dist/eip712/index.cjs +2 -3
  13. package/dist/eip712/index.cjs.map +1 -1
  14. package/dist/eip712/index.js +1 -2
  15. package/dist/index.cjs +184 -168
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +69 -48
  18. package/dist/index.d.ts +69 -48
  19. package/dist/index.js +164 -148
  20. package/dist/index.js.map +1 -1
  21. package/package.json +1 -31
  22. package/dist/chunk-2PIXFXA2.js +0 -135
  23. package/dist/chunk-2PIXFXA2.js.map +0 -1
  24. package/dist/chunk-CL3QSI4O.cjs +0 -65
  25. package/dist/chunk-CL3QSI4O.cjs.map +0 -1
  26. package/dist/chunk-DX73FB4P.cjs +0 -143
  27. package/dist/chunk-DX73FB4P.cjs.map +0 -1
  28. package/dist/chunk-IPXARZ6F.cjs +0 -135
  29. package/dist/chunk-IPXARZ6F.cjs.map +0 -1
  30. package/dist/chunk-JJ2LGENO.cjs +0 -373
  31. package/dist/chunk-JJ2LGENO.cjs.map +0 -1
  32. package/dist/chunk-KFWZRL7I.js +0 -65
  33. package/dist/chunk-KFWZRL7I.js.map +0 -1
  34. package/dist/chunk-L5UHQQVC.cjs +0 -136
  35. package/dist/chunk-L5UHQQVC.cjs.map +0 -1
  36. package/dist/chunk-R6OFGVMP.cjs.map +0 -1
  37. package/dist/chunk-TXA4GK5C.js.map +0 -1
  38. package/dist/chunk-VG23GIWQ.js +0 -373
  39. package/dist/chunk-VG23GIWQ.js.map +0 -1
  40. package/dist/chunk-WAFUL62X.js +0 -136
  41. package/dist/chunk-WAFUL62X.js.map +0 -1
  42. package/dist/chunk-X2JZFK4C.cjs +0 -87
  43. package/dist/chunk-X2JZFK4C.cjs.map +0 -1
  44. package/dist/chunk-Y2MZ7MKJ.js.map +0 -1
  45. package/dist/chunk-Y3HMGOYW.js +0 -87
  46. package/dist/chunk-Y3HMGOYW.js.map +0 -1
  47. package/dist/index-3C_HdEIm.d.cts +0 -227
  48. package/dist/index-DKtVEoRC.d.ts +0 -227
  49. package/dist/quoting/index.cjs +0 -19
  50. package/dist/quoting/index.cjs.map +0 -1
  51. package/dist/quoting/index.d.cts +0 -59
  52. package/dist/quoting/index.d.ts +0 -59
  53. package/dist/quoting/index.js +0 -19
  54. package/dist/quoting/index.js.map +0 -1
  55. package/dist/swap/index.cjs +0 -31
  56. package/dist/swap/index.cjs.map +0 -1
  57. package/dist/swap/index.d.cts +0 -3
  58. package/dist/swap/index.d.ts +0 -3
  59. package/dist/swap/index.js +0 -31
  60. package/dist/swap/index.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  import {
2
- pointTokenFactoryAbi
3
- } from "./chunk-Y2MZ7MKJ.js";
2
+ erc20Abi,
3
+ permit2Abi,
4
+ pointTokenFactoryAbi,
5
+ universalRouterAbi,
6
+ v4QuoterAbi
7
+ } from "./chunk-6CXTFOIH.js";
4
8
  import {
5
9
  SPONSOR_AUTH_DOMAIN_NAME,
6
10
  SPONSOR_AUTH_TYPES,
@@ -33,62 +37,6 @@ import {
33
37
  mintingOracleAbi,
34
38
  pointTokenAbi
35
39
  } from "./chunk-5JZOJIBT.js";
36
- import {
37
- buildBurnRequestTypedData,
38
- buildDomain,
39
- buildMintRequestTypedData,
40
- buildReceiverConsentTypedData,
41
- signBurnRequest,
42
- signMintRequest,
43
- signReceiverConsent,
44
- verifyBurnRequest,
45
- verifyMintRequest,
46
- verifyReceiverConsent
47
- } from "./chunk-TXA4GK5C.js";
48
- import {
49
- buildAllPaths,
50
- combineRoutes,
51
- findBestQuote,
52
- quoteBestRoute,
53
- quoteExactInput,
54
- quoteExactInputSingle
55
- } from "./chunk-WAFUL62X.js";
56
- import {
57
- v4QuoterAbi
58
- } from "./chunk-KFWZRL7I.js";
59
- import {
60
- ApiError,
61
- BATCH_EXECUTOR_ABI,
62
- ConfigurationError,
63
- PafiSDKError,
64
- SETTLE_ALL,
65
- SWAP_EXACT_IN,
66
- SigningError,
67
- SimulationError,
68
- TAKE_ALL,
69
- V4_SWAP,
70
- assembleUserOperation,
71
- buildErc20ApprovalCalldata,
72
- buildPartialUserOperation,
73
- buildPermit2ApprovalCalldata,
74
- buildSwapFromQuote,
75
- buildSwapWithGasDeduction,
76
- buildUniversalRouterExecuteArgs,
77
- buildV4SwapInput,
78
- checkAllowance,
79
- decodeBatchExecuteCalls,
80
- encodeBatchExecute,
81
- erc20ApproveOp,
82
- erc20BurnOp,
83
- erc20TransferOp,
84
- rawCallOp,
85
- simulateSwap
86
- } from "./chunk-VG23GIWQ.js";
87
- import {
88
- erc20Abi,
89
- permit2Abi,
90
- universalRouterAbi
91
- } from "./chunk-2PIXFXA2.js";
92
40
  import {
93
41
  COMMON_POOLS,
94
42
  COMMON_TOKENS,
@@ -99,16 +47,64 @@ import {
99
47
  SUPPORTED_CHAINS,
100
48
  UNIVERSAL_ROUTER_ADDRESSES,
101
49
  V4_QUOTER_ADDRESSES,
50
+ buildBurnRequestTypedData,
51
+ buildDomain,
52
+ buildMintRequestTypedData,
53
+ buildReceiverConsentTypedData,
102
54
  burnRequestTypes,
103
55
  mintRequestTypes,
104
- receiverConsentTypes
105
- } from "./chunk-Y3HMGOYW.js";
56
+ receiverConsentTypes,
57
+ signBurnRequest,
58
+ signMintRequest,
59
+ signReceiverConsent,
60
+ verifyBurnRequest,
61
+ verifyMintRequest,
62
+ verifyReceiverConsent
63
+ } from "./chunk-UOKI5GG6.js";
106
64
 
107
65
  // src/index.ts
108
66
  import { createPublicClient, http as http2 } from "viem";
109
67
 
68
+ // src/errors.ts
69
+ var PafiSDKError = class extends Error {
70
+ constructor(message) {
71
+ super(message);
72
+ this.name = "PafiSDKError";
73
+ }
74
+ };
75
+ var ConfigurationError = class extends PafiSDKError {
76
+ constructor(message) {
77
+ super(message);
78
+ this.name = "ConfigurationError";
79
+ }
80
+ };
81
+ var SigningError = class extends PafiSDKError {
82
+ constructor(message) {
83
+ super(message);
84
+ this.name = "SigningError";
85
+ }
86
+ };
87
+ var SimulationError = class extends PafiSDKError {
88
+ constructor(operation, reason) {
89
+ super(`Simulation failed for ${operation}: ${reason}`);
90
+ this.operation = operation;
91
+ this.reason = reason;
92
+ this.name = "SimulationError";
93
+ }
94
+ operation;
95
+ reason;
96
+ };
97
+ var ApiError = class extends PafiSDKError {
98
+ constructor(message, status) {
99
+ super(message);
100
+ this.status = status;
101
+ this.name = "ApiError";
102
+ }
103
+ status;
104
+ };
105
+
110
106
  // src/perp/buildPerpDepositWithGasDeduction.ts
111
- import { encodeFunctionData } from "viem";
107
+ import { encodeFunctionData as encodeFunctionData3 } from "viem";
112
108
 
113
109
  // src/contracts/real/orderlyVault.ts
114
110
  import { keccak256, encodePacked, encodeAbiParameters } from "viem";
@@ -199,6 +195,106 @@ var ORDERLY_VAULT_ABI = [
199
195
  }
200
196
  ];
201
197
 
198
+ // src/userop/operations.ts
199
+ import { encodeFunctionData, erc20Abi as erc20Abi2, parseAbi } from "viem";
200
+ var ERC20_BURNABLE_ABI = parseAbi(["function burn(uint256 amount)"]);
201
+ function erc20TransferOp(token, to, amount) {
202
+ return {
203
+ target: token,
204
+ value: 0n,
205
+ data: encodeFunctionData({
206
+ abi: erc20Abi2,
207
+ functionName: "transfer",
208
+ args: [to, amount]
209
+ })
210
+ };
211
+ }
212
+ function erc20ApproveOp(token, spender, amount) {
213
+ return {
214
+ target: token,
215
+ value: 0n,
216
+ data: encodeFunctionData({
217
+ abi: erc20Abi2,
218
+ functionName: "approve",
219
+ args: [spender, amount]
220
+ })
221
+ };
222
+ }
223
+ function erc20BurnOp(token, amount) {
224
+ return {
225
+ target: token,
226
+ value: 0n,
227
+ data: encodeFunctionData({
228
+ abi: ERC20_BURNABLE_ABI,
229
+ functionName: "burn",
230
+ args: [amount]
231
+ })
232
+ };
233
+ }
234
+ function rawCallOp(target, data, value = 0n) {
235
+ return { target, value, data };
236
+ }
237
+
238
+ // src/userop/batchExecute.ts
239
+ import { decodeFunctionData, encodeFunctionData as encodeFunctionData2, parseAbi as parseAbi2 } from "viem";
240
+ var BATCH_EXECUTOR_ABI = parseAbi2([
241
+ "function executeBatch((address target, uint256 value, bytes data)[] calls)"
242
+ ]);
243
+ function encodeBatchExecute(operations) {
244
+ if (operations.length === 0) {
245
+ throw new Error("encodeBatchExecute: operations array must not be empty");
246
+ }
247
+ return encodeFunctionData2({
248
+ abi: BATCH_EXECUTOR_ABI,
249
+ functionName: "executeBatch",
250
+ args: [
251
+ operations.map((op) => ({
252
+ target: op.target,
253
+ value: op.value,
254
+ data: op.data
255
+ }))
256
+ ]
257
+ });
258
+ }
259
+ function decodeBatchExecuteCalls(callData) {
260
+ const { args } = decodeFunctionData({
261
+ abi: BATCH_EXECUTOR_ABI,
262
+ data: callData
263
+ });
264
+ return args[0].map((c) => ({
265
+ to: c.target,
266
+ data: c.data,
267
+ value: c.value.toString()
268
+ }));
269
+ }
270
+
271
+ // src/userop/buildUserOperation.ts
272
+ var DEFAULT_CALL_GAS_LIMIT = 500000n;
273
+ var DEFAULT_VERIFICATION_GAS_LIMIT = 150000n;
274
+ var DEFAULT_PRE_VERIFICATION_GAS = 50000n;
275
+ function buildPartialUserOperation(params) {
276
+ return {
277
+ sender: params.sender,
278
+ nonce: params.nonce,
279
+ callData: encodeBatchExecute(params.operations),
280
+ callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_CALL_GAS_LIMIT,
281
+ verificationGasLimit: params.gasLimits?.verificationGasLimit ?? DEFAULT_VERIFICATION_GAS_LIMIT,
282
+ preVerificationGas: params.gasLimits?.preVerificationGas ?? DEFAULT_PRE_VERIFICATION_GAS,
283
+ maxFeePerGas: params.feeOverrides?.maxFeePerGas ?? 0n,
284
+ maxPriorityFeePerGas: params.feeOverrides?.maxPriorityFeePerGas ?? 0n
285
+ };
286
+ }
287
+ function assembleUserOperation(partial, paymaster, signature) {
288
+ return {
289
+ ...partial,
290
+ paymaster: paymaster.paymaster,
291
+ paymasterData: paymaster.paymasterData,
292
+ paymasterVerificationGasLimit: paymaster.paymasterVerificationGasLimit,
293
+ paymasterPostOpGasLimit: paymaster.paymasterPostOpGasLimit,
294
+ signature
295
+ };
296
+ }
297
+
202
298
  // src/perp/buildPerpDepositWithGasDeduction.ts
203
299
  function buildPerpDepositWithGasDeduction(params) {
204
300
  if (params.amount <= 0n) {
@@ -220,7 +316,7 @@ function buildPerpDepositWithGasDeduction(params) {
220
316
  `buildPerpDepositWithGasDeduction: no Orderly Vault address for chainId ${params.chainId}`
221
317
  );
222
318
  }
223
- const depositCallData = encodeFunctionData({
319
+ const depositCallData = encodeFunctionData3({
224
320
  abi: ORDERLY_VAULT_ABI,
225
321
  functionName: "deposit",
226
322
  args: [params.depositData]
@@ -248,7 +344,7 @@ function buildPerpDepositWithGasDeduction(params) {
248
344
  }
249
345
 
250
346
  // src/perp/buildPerpDepositViaRelay.ts
251
- import { encodeFunctionData as encodeFunctionData2, erc20Abi as erc20Abi2 } from "viem";
347
+ import { encodeFunctionData as encodeFunctionData4, erc20Abi as erc20Abi3 } from "viem";
252
348
  var ORDERLY_RELAY_ABI = [
253
349
  {
254
350
  type: "function",
@@ -314,8 +410,8 @@ function buildPerpDepositViaRelay(params) {
314
410
  operations.push({
315
411
  target: params.pointTokenAddress,
316
412
  value: 0n,
317
- data: encodeFunctionData2({
318
- abi: erc20Abi2,
413
+ data: encodeFunctionData4({
414
+ abi: erc20Abi3,
319
415
  functionName: "transfer",
320
416
  args: [params.gasFeePtRecipient, params.gasFeePt]
321
417
  })
@@ -328,7 +424,7 @@ function buildPerpDepositViaRelay(params) {
328
424
  params.request.totalAmount
329
425
  )
330
426
  );
331
- const depositCallData = encodeFunctionData2({
427
+ const depositCallData = encodeFunctionData4({
332
428
  abi: ORDERLY_RELAY_ABI,
333
429
  functionName: "deposit",
334
430
  args: [
@@ -657,7 +753,7 @@ async function sendWithPaymasterFallback(params) {
657
753
  }
658
754
 
659
755
  // src/fee/operatorFeeQuoter.ts
660
- import { parseAbi } from "viem";
756
+ import { parseAbi as parseAbi3 } from "viem";
661
757
 
662
758
  // src/subgraph/pools.ts
663
759
  import { isAddress } from "viem";
@@ -784,7 +880,7 @@ function getContractAddresses(chainId) {
784
880
  }
785
881
 
786
882
  // src/fee/operatorFeeQuoter.ts
787
- var CHAINLINK_ABI = parseAbi([
883
+ var CHAINLINK_ABI = parseAbi3([
788
884
  "function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80)"
789
885
  ]);
790
886
  var CHAINLINK_MAX_AGE_S = 3600n;
@@ -1035,8 +1131,6 @@ var PafiSDK = class {
1035
1131
  // -------------------------------------------------------------------------
1036
1132
  mint;
1037
1133
  consent;
1038
- swap;
1039
- quote;
1040
1134
  auth;
1041
1135
  constructor(config) {
1042
1136
  this._pointTokenAddress = config.pointTokenAddress;
@@ -1061,13 +1155,6 @@ var PafiSDK = class {
1061
1155
  verify: this.verifyReceiverConsent.bind(this),
1062
1156
  getNonce: this.getReceiverConsentNonce.bind(this)
1063
1157
  };
1064
- this.swap = {
1065
- buildFromQuote: this.buildSwapFromQuote.bind(this),
1066
- simulate: this.simulateSwap.bind(this)
1067
- };
1068
- this.quote = {
1069
- findBest: this.findBestQuote.bind(this)
1070
- };
1071
1158
  this.auth = {
1072
1159
  createLoginMessage: this.createLoginMessage.bind(this),
1073
1160
  signMessage: this.signLoginMessage.bind(this)
@@ -1167,59 +1254,6 @@ var PafiSDK = class {
1167
1254
  );
1168
1255
  }
1169
1256
  // -------------------------------------------------------------------------
1170
- // Quoting — delegates to pure functions
1171
- // -------------------------------------------------------------------------
1172
- /**
1173
- * Find the best swap route from `tokenIn` to `tokenOut`.
1174
- * Merges `pools` with COMMON_POOLS for the configured chain, builds all
1175
- * paths, and quotes via a single multicall RPC call.
1176
- */
1177
- async findBestQuote(tokenIn, tokenOut, exactAmount, pools = [], quoterAddress, maxHops) {
1178
- return findBestQuote(
1179
- this.requireProvider(),
1180
- this.requireChainId(),
1181
- tokenIn,
1182
- tokenOut,
1183
- exactAmount,
1184
- pools,
1185
- quoterAddress,
1186
- maxHops
1187
- );
1188
- }
1189
- // -------------------------------------------------------------------------
1190
- // Swap building — delegates to pure functions
1191
- // -------------------------------------------------------------------------
1192
- /**
1193
- * Build UniversalRouter execute args from a quote result.
1194
- * The caller provides `minAmountOut` after applying their own slippage.
1195
- */
1196
- buildSwapFromQuote(params) {
1197
- return buildSwapFromQuote(params);
1198
- }
1199
- // -------------------------------------------------------------------------
1200
- // Simulation — dry-run via eth_call (no gas spent)
1201
- // -------------------------------------------------------------------------
1202
- /**
1203
- * Simulate a UniversalRouter.execute swap call. Catches reverts (bad
1204
- * approvals, insufficient balance, pool errors) before submitting.
1205
- *
1206
- * @param routerAddress - UniversalRouter contract address
1207
- * @param commands - Packed command bytes (from buildSwapFromQuote)
1208
- * @param inputs - Encoded inputs (from buildSwapFromQuote)
1209
- * @param deadline - Unix timestamp
1210
- * @param from - Address that will execute the swap
1211
- */
1212
- async simulateSwap(routerAddress, commands, inputs, deadline, from) {
1213
- return simulateSwap(
1214
- this.requireProvider(),
1215
- routerAddress,
1216
- commands,
1217
- inputs,
1218
- deadline,
1219
- from
1220
- );
1221
- }
1222
- // -------------------------------------------------------------------------
1223
1257
  // Auth — EIP-4361 login helpers (offline, stateless)
1224
1258
  // -------------------------------------------------------------------------
1225
1259
  async createLoginMessage(params) {
@@ -1267,47 +1301,34 @@ export {
1267
1301
  pointTokenAbi as POINT_TOKEN_V2_ABI,
1268
1302
  PafiSDK,
1269
1303
  PafiSDKError,
1270
- SETTLE_ALL,
1271
1304
  SIMPLE_7702_IMPL_BASE_MAINNET,
1272
1305
  SPONSOR_AUTH_DOMAIN_NAME,
1273
1306
  SPONSOR_AUTH_TYPES,
1274
1307
  SUPPORTED_CHAINS,
1275
- SWAP_EXACT_IN,
1276
1308
  SigningError,
1277
1309
  SimulationError,
1278
- TAKE_ALL,
1279
1310
  TOKEN_HASHES,
1280
1311
  UNIVERSAL_ROUTER_ADDRESSES,
1281
1312
  V4_QUOTER_ADDRESSES,
1282
- V4_SWAP,
1283
1313
  ZERO_VALUE,
1284
1314
  _resetPaymasterConfigForTests,
1285
1315
  assembleUserOperation,
1286
- buildAllPaths,
1287
1316
  buildAndSignSponsorAuth,
1288
1317
  buildBurnRequestTypedData,
1289
1318
  buildDelegationUserOp,
1290
1319
  buildDomain,
1291
1320
  buildEip7702Authorization,
1292
- buildErc20ApprovalCalldata,
1293
1321
  buildMintRequestTypedData,
1294
1322
  buildPartialUserOperation,
1295
- buildPermit2ApprovalCalldata,
1296
1323
  buildPerpDepositViaRelay,
1297
1324
  buildPerpDepositWithGasDeduction,
1298
1325
  buildReceiverConsentTypedData,
1299
1326
  buildSponsorAuthDomain,
1300
1327
  buildSponsorAuthTypedData,
1301
- buildSwapFromQuote,
1302
- buildSwapWithGasDeduction,
1303
- buildUniversalRouterExecuteArgs,
1304
1328
  buildUserOpTypedData,
1305
- buildV4SwapInput,
1306
1329
  burnRequestTypes,
1307
- checkAllowance,
1308
1330
  checkDelegation,
1309
1331
  checkEthAndBranch,
1310
- combineRoutes,
1311
1332
  computeAccountId,
1312
1333
  computeAuthorizationHash,
1313
1334
  computeCallDataHash,
@@ -1322,7 +1343,6 @@ export {
1322
1343
  erc20BurnOp,
1323
1344
  erc20TransferOp,
1324
1345
  fetchPafiPools,
1325
- findBestQuote,
1326
1346
  getAaNonce,
1327
1347
  getBurnRequestNonce,
1328
1348
  getContractAddresses,
@@ -1353,9 +1373,6 @@ export {
1353
1373
  permit2Abi,
1354
1374
  pointTokenAbi,
1355
1375
  pointTokenFactoryAbi,
1356
- quoteBestRoute,
1357
- quoteExactInput,
1358
- quoteExactInputSingle,
1359
1376
  quoteOperatorFeePt,
1360
1377
  rawCallOp,
1361
1378
  receiverConsentTypes,
@@ -1367,7 +1384,6 @@ export {
1367
1384
  signMintRequest,
1368
1385
  signReceiverConsent,
1369
1386
  signSponsorAuth,
1370
- simulateSwap,
1371
1387
  splitAuthorizationSig,
1372
1388
  universalRouterAbi,
1373
1389
  v4QuoterAbi,