@pafi-dev/issuer 0.5.36 → 0.5.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ __export(index_exports, {
36
36
  MemorySessionStore: () => MemorySessionStore,
37
37
  NonceManager: () => NonceManager,
38
38
  PAFI_ISSUER_SDK_VERSION: () => PAFI_ISSUER_SDK_VERSION,
39
- PAFI_SUBGRAPH_URL: () => import_core12.PAFI_SUBGRAPH_URL,
39
+ PAFI_SUBGRAPH_URL: () => import_core14.PAFI_SUBGRAPH_URL,
40
40
  PTClaimError: () => PTClaimError,
41
41
  PTClaimHandler: () => PTClaimHandler,
42
42
  PTRedeemError: () => PTRedeemError,
@@ -59,11 +59,13 @@ __export(index_exports, {
59
59
  createSubgraphNativeUsdtQuoter: () => createSubgraphNativeUsdtQuoter,
60
60
  createSubgraphPoolsProvider: () => createSubgraphPoolsProvider,
61
61
  handleClaimStatus: () => handleClaimStatus,
62
+ handleDelegateSubmit: () => handleDelegateSubmit,
62
63
  handleMobilePrepare: () => handleMobilePrepare,
63
64
  handleMobileSubmit: () => handleMobileSubmit,
64
65
  handleRedeemStatus: () => handleRedeemStatus,
65
66
  mergePaymasterFields: () => mergePaymasterFields,
66
67
  prepareMobileUserOp: () => prepareMobileUserOp,
68
+ quotePointTokenToUsdt: () => quotePointTokenToUsdt,
67
69
  relayUserOp: () => relayUserOp,
68
70
  requestPaymaster: () => requestPaymaster,
69
71
  serializeEntryToJsonRpc: () => serializeEntryToJsonRpc,
@@ -2409,9 +2411,144 @@ var PerpDepositHandler = class {
2409
2411
  }
2410
2412
  };
2411
2413
 
2414
+ // src/api/delegateHandler.ts
2415
+ var import_core12 = require("@pafi-dev/core");
2416
+ var DEFAULT_DELEGATE_GAS = {
2417
+ callGasLimit: 100000n,
2418
+ verificationGasLimit: 150000n,
2419
+ preVerificationGas: 50000n
2420
+ };
2421
+ async function handleDelegateSubmit(params) {
2422
+ const { batchExecutor } = (0, import_core12.getContractAddresses)(params.chainId);
2423
+ const callData = (0, import_core12.encodeBatchExecute)([]);
2424
+ const userOp = {
2425
+ sender: params.userAddress,
2426
+ nonce: params.aaNonce,
2427
+ callData,
2428
+ callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_DELEGATE_GAS.callGasLimit,
2429
+ verificationGasLimit: params.gasLimits?.verificationGasLimit ?? DEFAULT_DELEGATE_GAS.verificationGasLimit,
2430
+ preVerificationGas: params.gasLimits?.preVerificationGas ?? DEFAULT_DELEGATE_GAS.preVerificationGas,
2431
+ maxFeePerGas: params.fees.maxFeePerGas ?? 0n,
2432
+ maxPriorityFeePerGas: params.fees.maxPriorityFeePerGas ?? 0n
2433
+ };
2434
+ const paymasterFields = await requestPaymaster({
2435
+ client: params.pafiBackendClient,
2436
+ chainId: params.chainId,
2437
+ scenario: "delegate",
2438
+ userOp,
2439
+ pointTokenAddress: batchExecutor,
2440
+ onWarning: params.onWarning
2441
+ });
2442
+ const merged = {
2443
+ ...userOp,
2444
+ ...paymasterFields ?? {}
2445
+ };
2446
+ const userOpJson = (0, import_core12.serializeUserOpToJsonRpc)(
2447
+ {
2448
+ sender: merged.sender,
2449
+ nonce: merged.nonce,
2450
+ callData: merged.callData,
2451
+ callGasLimit: merged.callGasLimit,
2452
+ verificationGasLimit: merged.verificationGasLimit,
2453
+ preVerificationGas: merged.preVerificationGas,
2454
+ maxFeePerGas: merged.maxFeePerGas,
2455
+ maxPriorityFeePerGas: merged.maxPriorityFeePerGas,
2456
+ paymaster: paymasterFields?.paymaster,
2457
+ paymasterVerificationGasLimit: paymasterFields?.paymasterVerificationGasLimit,
2458
+ paymasterPostOpGasLimit: paymasterFields?.paymasterPostOpGasLimit,
2459
+ paymasterData: paymasterFields?.paymasterData
2460
+ },
2461
+ // Delegation UserOp is submitted unsigned — the EIP-7702 authorization
2462
+ // is the user's "consent"; no separate AA signature is needed.
2463
+ "0x"
2464
+ );
2465
+ const authorization = (0, import_core12.buildEip7702Authorization)({
2466
+ chainId: params.chainId,
2467
+ address: batchExecutor,
2468
+ nonce: params.delegationNonce,
2469
+ authSig: params.authSig
2470
+ });
2471
+ const result = await relayUserOp({
2472
+ client: params.pafiBackendClient,
2473
+ userOp: userOpJson,
2474
+ entryPoint: import_core12.ENTRY_POINT_V08,
2475
+ eip7702Auth: authorization
2476
+ });
2477
+ return {
2478
+ userOpHash: result.userOpHash,
2479
+ isSponsored: !!paymasterFields,
2480
+ authorization
2481
+ };
2482
+ }
2483
+
2484
+ // src/api/quoteHelper.ts
2485
+ var import_core13 = require("@pafi-dev/core");
2486
+ var DEFAULT_DEADLINE_SECONDS = 300;
2487
+ async function quotePointTokenToUsdt(params) {
2488
+ const now = params.now ?? (() => Date.now());
2489
+ const suggestedDeadline = Math.floor(now() / 1e3) + (params.deadlineSeconds ?? DEFAULT_DEADLINE_SECONDS);
2490
+ if (params.pointAmount === 0n) {
2491
+ return {
2492
+ estimatedUsdtOut: 0n,
2493
+ netUsdtOut: 0n,
2494
+ exchangeRate: "0.00000000",
2495
+ gasEstimate: 0n,
2496
+ suggestedDeadline
2497
+ };
2498
+ }
2499
+ if (params.pools.length === 0) {
2500
+ return {
2501
+ estimatedUsdtOut: 0n,
2502
+ netUsdtOut: 0n,
2503
+ exchangeRate: "0.00000000",
2504
+ gasEstimate: 0n,
2505
+ suggestedDeadline,
2506
+ quoteError: "QUOTE_UNAVAILABLE"
2507
+ };
2508
+ }
2509
+ const { usdt: usdtAddress } = (0, import_core13.getContractAddresses)(params.chainId);
2510
+ let estimatedUsdtOut = 0n;
2511
+ let gasEstimate = 0n;
2512
+ try {
2513
+ const best = await (0, import_core13.findBestQuote)(
2514
+ params.provider,
2515
+ params.chainId,
2516
+ params.pointTokenAddress,
2517
+ usdtAddress,
2518
+ params.pointAmount,
2519
+ params.pools
2520
+ );
2521
+ estimatedUsdtOut = best.bestRoute.amountOut;
2522
+ gasEstimate = best.bestRoute.gasEstimate;
2523
+ } catch {
2524
+ return {
2525
+ estimatedUsdtOut: 0n,
2526
+ netUsdtOut: 0n,
2527
+ exchangeRate: "0.00000000",
2528
+ gasEstimate: 0n,
2529
+ suggestedDeadline,
2530
+ quoteError: "QUOTE_UNAVAILABLE"
2531
+ };
2532
+ }
2533
+ const netUsdtOut = estimatedUsdtOut > params.gasFeeUsdt ? estimatedUsdtOut - params.gasFeeUsdt : 0n;
2534
+ const quoteError = estimatedUsdtOut > 0n && netUsdtOut === 0n ? "AMOUNT_TOO_SMALL_FOR_GAS" : void 0;
2535
+ const rateNum = estimatedUsdtOut > 0n ? Number(
2536
+ estimatedUsdtOut * 1000000n * 10n ** 18n / params.pointAmount
2537
+ ) / 1e6 : 0;
2538
+ const exchangeRate = rateNum.toFixed(8);
2539
+ return {
2540
+ estimatedUsdtOut,
2541
+ netUsdtOut,
2542
+ exchangeRate,
2543
+ gasEstimate,
2544
+ suggestedDeadline,
2545
+ ...quoteError ? { quoteError } : {}
2546
+ };
2547
+ }
2548
+
2412
2549
  // src/pools/subgraphPoolsProvider.ts
2413
2550
  var import_viem10 = require("viem");
2414
- var import_core12 = require("@pafi-dev/core");
2551
+ var import_core14 = require("@pafi-dev/core");
2415
2552
  var DEFAULT_CACHE_TTL_MS = 3e4;
2416
2553
  var POOL_QUERY = `
2417
2554
  query GetPoolForPointToken($id: ID!) {
@@ -2429,7 +2566,7 @@ var POOL_QUERY = `
2429
2566
  }
2430
2567
  `;
2431
2568
  function createSubgraphPoolsProvider(config = {}) {
2432
- const subgraphUrl = config.subgraphUrl ?? import_core12.PAFI_SUBGRAPH_URL;
2569
+ const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
2433
2570
  try {
2434
2571
  const parsed = new URL(subgraphUrl);
2435
2572
  if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
@@ -2561,7 +2698,7 @@ var PRICE_QUERY = `
2561
2698
  }
2562
2699
  `;
2563
2700
  function createSubgraphNativeUsdtQuoter(config = {}) {
2564
- const subgraphUrl = config.subgraphUrl ?? import_core12.PAFI_SUBGRAPH_URL;
2701
+ const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
2565
2702
  try {
2566
2703
  const parsed = new URL(subgraphUrl);
2567
2704
  if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
@@ -2691,7 +2828,7 @@ function createNativePtQuoter(config) {
2691
2828
  provider,
2692
2829
  pointTokenAddress,
2693
2830
  chainlinkFeedAddress = "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70",
2694
- subgraphUrl = import_core12.PAFI_SUBGRAPH_URL,
2831
+ subgraphUrl = import_core14.PAFI_SUBGRAPH_URL,
2695
2832
  cacheTtlMs = 3e4,
2696
2833
  fallbackEthPriceUsd = 3e3,
2697
2834
  fallbackPtPriceUsdt = 0.1,
@@ -2773,7 +2910,7 @@ function parseBigDecimalTo18(s) {
2773
2910
  }
2774
2911
 
2775
2912
  // src/balance/balanceAggregator.ts
2776
- var import_core13 = require("@pafi-dev/core");
2913
+ var import_core15 = require("@pafi-dev/core");
2777
2914
  var BalanceAggregator = class {
2778
2915
  provider;
2779
2916
  ledger;
@@ -2794,7 +2931,7 @@ var BalanceAggregator = class {
2794
2931
  async getCombinedBalance(user, pointToken) {
2795
2932
  const [offChain, onChain] = await Promise.all([
2796
2933
  this.ledger.getBalance(user, pointToken),
2797
- (0, import_core13.getPointTokenBalance)(this.provider, pointToken, user)
2934
+ (0, import_core15.getPointTokenBalance)(this.provider, pointToken, user)
2798
2935
  ]);
2799
2936
  return {
2800
2937
  offChain,
@@ -3028,7 +3165,7 @@ var PafiBackendClient = class {
3028
3165
 
3029
3166
  // src/config.ts
3030
3167
  var import_viem12 = require("viem");
3031
- var import_core14 = require("@pafi-dev/core");
3168
+ var import_core16 = require("@pafi-dev/core");
3032
3169
  function createIssuerService(config) {
3033
3170
  if (!config.provider) {
3034
3171
  throw new Error("createIssuerService: provider is required");
@@ -3098,7 +3235,7 @@ function createIssuerService(config) {
3098
3235
  indexers.set(tokenAddress, new PointIndexer(indexerConfig));
3099
3236
  }
3100
3237
  const firstIndexer = indexers.get(tokenAddresses[0]);
3101
- const chainAddresses = (0, import_core14.getContractAddresses)(config.chainId);
3238
+ const chainAddresses = (0, import_core16.getContractAddresses)(config.chainId);
3102
3239
  const resolvedContracts = {
3103
3240
  batchExecutor: chainAddresses.batchExecutor,
3104
3241
  usdt: chainAddresses.usdt,
@@ -3147,7 +3284,7 @@ function createIssuerService(config) {
3147
3284
 
3148
3285
  // src/issuer-state/validator.ts
3149
3286
  var import_viem13 = require("viem");
3150
- var import_core15 = require("@pafi-dev/core");
3287
+ var import_core17 = require("@pafi-dev/core");
3151
3288
  var ISSUER_RECORD_TTL_MS = 3e4;
3152
3289
  var IssuerStateValidator = class _IssuerStateValidator {
3153
3290
  constructor(provider, registryAddress) {
@@ -3164,7 +3301,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
3164
3301
  * `CONTRACT_ADDRESSES` map for the given chain.
3165
3302
  */
3166
3303
  static forChain(provider, chainId) {
3167
- const { issuerRegistry } = (0, import_core15.getContractAddresses)(chainId);
3304
+ const { issuerRegistry } = (0, import_core17.getContractAddresses)(chainId);
3168
3305
  return new _IssuerStateValidator(provider, issuerRegistry);
3169
3306
  }
3170
3307
  /**
@@ -3193,7 +3330,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
3193
3330
  if (cached) return cached;
3194
3331
  const issuer = await this.provider.readContract({
3195
3332
  address: key,
3196
- abi: import_core15.POINT_TOKEN_V2_ABI,
3333
+ abi: import_core17.POINT_TOKEN_V2_ABI,
3197
3334
  functionName: "issuer"
3198
3335
  });
3199
3336
  this.pointTokenIssuerCache.set(key, (0, import_viem13.getAddress)(issuer));
@@ -3274,13 +3411,13 @@ var IssuerStateValidator = class _IssuerStateValidator {
3274
3411
  const [issuerTuple, totalSupply] = await Promise.all([
3275
3412
  this.provider.readContract({
3276
3413
  address: this.registryAddress,
3277
- abi: import_core15.issuerRegistryGetIssuerFlatAbi,
3414
+ abi: import_core17.issuerRegistryGetIssuerFlatAbi,
3278
3415
  functionName: "getIssuer",
3279
3416
  args: [issuerAddr]
3280
3417
  }),
3281
3418
  this.provider.readContract({
3282
3419
  address: tokenAddr,
3283
- abi: import_core15.POINT_TOKEN_V2_ABI,
3420
+ abi: import_core17.POINT_TOKEN_V2_ABI,
3284
3421
  functionName: "totalSupply"
3285
3422
  })
3286
3423
  ]);
@@ -3344,11 +3481,13 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
3344
3481
  createSubgraphNativeUsdtQuoter,
3345
3482
  createSubgraphPoolsProvider,
3346
3483
  handleClaimStatus,
3484
+ handleDelegateSubmit,
3347
3485
  handleMobilePrepare,
3348
3486
  handleMobileSubmit,
3349
3487
  handleRedeemStatus,
3350
3488
  mergePaymasterFields,
3351
3489
  prepareMobileUserOp,
3490
+ quotePointTokenToUsdt,
3352
3491
  relayUserOp,
3353
3492
  requestPaymaster,
3354
3493
  serializeEntryToJsonRpc,