@pafi-dev/issuer 0.5.40 → 0.5.42

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
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  DefaultPolicyEngine: () => DefaultPolicyEngine,
30
30
  FeeManager: () => FeeManager,
31
31
  InMemoryCursorStore: () => InMemoryCursorStore,
32
+ IssuerApiAdapter: () => IssuerApiAdapter,
32
33
  IssuerApiHandlers: () => IssuerApiHandlers,
33
34
  IssuerStateError: () => IssuerStateError,
34
35
  IssuerStateValidator: () => IssuerStateValidator,
@@ -36,7 +37,7 @@ __export(index_exports, {
36
37
  MemorySessionStore: () => MemorySessionStore,
37
38
  NonceManager: () => NonceManager,
38
39
  PAFI_ISSUER_SDK_VERSION: () => PAFI_ISSUER_SDK_VERSION,
39
- PAFI_SUBGRAPH_URL: () => import_core14.PAFI_SUBGRAPH_URL,
40
+ PAFI_SUBGRAPH_URL: () => import_core15.PAFI_SUBGRAPH_URL,
40
41
  PTClaimError: () => PTClaimError,
41
42
  PTClaimHandler: () => PTClaimHandler,
42
43
  PTRedeemError: () => PTRedeemError,
@@ -2618,9 +2619,422 @@ function createSdkErrorMapper(factories) {
2618
2619
  };
2619
2620
  }
2620
2621
 
2621
- // src/pools/subgraphPoolsProvider.ts
2622
+ // src/api/issuerApiAdapter.ts
2622
2623
  var import_viem11 = require("viem");
2623
2624
  var import_core14 = require("@pafi-dev/core");
2625
+ var IssuerApiAdapter = class {
2626
+ cfg;
2627
+ constructor(config) {
2628
+ this.cfg = config;
2629
+ }
2630
+ // ------------------------------ Read endpoints ---------------------------
2631
+ async config(chainId) {
2632
+ const result = await this.cfg.issuerService.api.handleConfig(chainId);
2633
+ return {
2634
+ chainId: result.chainId,
2635
+ contracts: result.contracts
2636
+ };
2637
+ }
2638
+ async gasFee() {
2639
+ const result = await this.cfg.issuerService.api.handleGasFee();
2640
+ return { gasFeeUsdt: result.gasFeeUsdt.toString() };
2641
+ }
2642
+ async pools(authenticatedAddress, chainId, pointTokenAddress) {
2643
+ const result = await this.cfg.issuerService.api.handlePools(
2644
+ authenticatedAddress,
2645
+ { chainId, pointTokenAddress: (0, import_viem11.getAddress)(pointTokenAddress) }
2646
+ );
2647
+ return { pools: result.pools };
2648
+ }
2649
+ async user(authenticatedAddress, chainId, userAddress, pointTokenAddress) {
2650
+ const result = await this.cfg.issuerService.api.handleUser(
2651
+ authenticatedAddress,
2652
+ {
2653
+ chainId,
2654
+ userAddress: (0, import_viem11.getAddress)(userAddress),
2655
+ pointTokenAddress: (0, import_viem11.getAddress)(pointTokenAddress)
2656
+ }
2657
+ );
2658
+ return {
2659
+ mintRequestNonce: result.mintRequestNonce.toString(),
2660
+ receiverConsentNonce: result.receiverConsentNonce.toString(),
2661
+ offChainBalance: result.offChainBalance.toString(),
2662
+ onChainBalance: result.onChainBalance.toString(),
2663
+ totalBalance: result.totalBalance.toString(),
2664
+ balance: result.offChainBalance.toString(),
2665
+ isMinter: result.isMinter
2666
+ };
2667
+ }
2668
+ async quote(authenticatedAddress, chainId, pointTokenAddress, pointAmount) {
2669
+ const [gasFeeResult, poolsResult] = await Promise.all([
2670
+ this.cfg.issuerService.api.handleGasFee(),
2671
+ this.cfg.issuerService.api.handlePools(authenticatedAddress, {
2672
+ chainId,
2673
+ pointTokenAddress: (0, import_viem11.getAddress)(pointTokenAddress)
2674
+ })
2675
+ ]);
2676
+ const quote = await quotePointTokenToUsdt({
2677
+ provider: this.cfg.provider,
2678
+ chainId,
2679
+ pointTokenAddress: (0, import_viem11.getAddress)(pointTokenAddress),
2680
+ pointAmount,
2681
+ pools: poolsResult.pools,
2682
+ gasFeeUsdt: gasFeeResult.gasFeeUsdt
2683
+ });
2684
+ const dto = {
2685
+ pointAmount: pointAmount.toString(),
2686
+ estimatedUsdtOut: quote.estimatedUsdtOut.toString(),
2687
+ gasFeeUsdt: gasFeeResult.gasFeeUsdt.toString(),
2688
+ netUsdtOut: quote.netUsdtOut.toString(),
2689
+ exchangeRate: quote.exchangeRate,
2690
+ suggestedDeadline: quote.suggestedDeadline.toString(),
2691
+ gasEstimate: quote.gasEstimate.toString()
2692
+ };
2693
+ if (quote.quoteError) dto.quoteError = quote.quoteError;
2694
+ return dto;
2695
+ }
2696
+ // ------------------------------ Action endpoints -------------------------
2697
+ async claim(input) {
2698
+ const ptClaimHandler = this.assertHandler(
2699
+ this.cfg.ptClaimHandler,
2700
+ "ptClaimHandler",
2701
+ "claim"
2702
+ );
2703
+ const pointTokenAddress = (0, import_viem11.getAddress)(input.pointTokenAddress);
2704
+ const result = await ptClaimHandler.handle({
2705
+ authenticatedAddress: input.authenticatedAddress,
2706
+ userAddress: input.authenticatedAddress,
2707
+ amount: input.amount,
2708
+ pointTokenAddress,
2709
+ chainId: input.chainId,
2710
+ aaNonce: input.aaNonce,
2711
+ mintRequestNonce: input.mintRequestNonce
2712
+ });
2713
+ const sponsorAuth = await this.buildSponsorAuth(
2714
+ input.authenticatedAddress,
2715
+ result.userOp.callData,
2716
+ input.chainId,
2717
+ "mint"
2718
+ );
2719
+ return {
2720
+ calls: result.calls,
2721
+ callsFallback: result.callsFallback,
2722
+ feeAmount: result.feeAmount.toString(),
2723
+ lockId: result.lockId,
2724
+ signatureDeadline: result.signatureDeadline.toString(),
2725
+ sponsorAuth
2726
+ };
2727
+ }
2728
+ async redeem(input) {
2729
+ this.assertRedeemHandler();
2730
+ const response = await this.cfg.ptRedeemHandler.handle({
2731
+ userAddress: input.authenticatedAddress,
2732
+ authenticatedAddress: input.authenticatedAddress,
2733
+ amount: input.amount,
2734
+ aaNonce: input.aaNonce,
2735
+ chainId: input.chainId
2736
+ });
2737
+ const sponsorAuth = await this.buildSponsorAuth(
2738
+ input.authenticatedAddress,
2739
+ response.userOp.callData,
2740
+ input.chainId,
2741
+ "burn"
2742
+ );
2743
+ return {
2744
+ calls: (0, import_core14.decodeBatchExecuteCalls)(response.userOp.callData),
2745
+ callsFallback: response.fallback ? (0, import_core14.decodeBatchExecuteCalls)(response.fallback.userOp.callData) : void 0,
2746
+ feeAmount: response.feeAmount.toString(),
2747
+ lockId: response.lockId,
2748
+ lockIdFallback: response.fallback?.lockId,
2749
+ netCreditAmount: response.netCreditAmount.toString(),
2750
+ netCreditAmountFallback: response.fallback?.netCreditAmount.toString(),
2751
+ expiresInSeconds: response.expiresInSeconds,
2752
+ signatureDeadline: response.signatureDeadline.toString(),
2753
+ sponsorAuth
2754
+ };
2755
+ }
2756
+ async swap(input) {
2757
+ const swapHandler = this.assertHandler(
2758
+ this.cfg.swapHandler,
2759
+ "swapHandler",
2760
+ "swap"
2761
+ );
2762
+ const result = await swapHandler.handle({
2763
+ userAddress: input.authenticatedAddress,
2764
+ chainId: input.chainId,
2765
+ pointTokenAddress: (0, import_viem11.getAddress)(input.pointTokenAddress),
2766
+ amountIn: input.amountIn,
2767
+ aaNonce: input.aaNonce,
2768
+ slippageBps: input.slippageBps
2769
+ });
2770
+ const sponsorAuth = await this.buildSponsorAuth(
2771
+ input.authenticatedAddress,
2772
+ result.userOp.callData,
2773
+ input.chainId,
2774
+ "swap"
2775
+ );
2776
+ return {
2777
+ calls: result.calls,
2778
+ callsFallback: result.callsFallback,
2779
+ feeAmount: result.feeAmount.toString(),
2780
+ estimatedUsdtOut: result.estimatedUsdtOut.toString(),
2781
+ minAmountOut: result.minAmountOut.toString(),
2782
+ estimatedUsdtOutFallback: result.estimatedUsdtOutFallback?.toString(),
2783
+ minAmountOutFallback: result.minAmountOutFallback?.toString(),
2784
+ deadline: result.deadline.toString(),
2785
+ sponsorAuth
2786
+ };
2787
+ }
2788
+ async perpDeposit(input) {
2789
+ const perpHandler = this.assertHandler(
2790
+ this.cfg.perpHandler,
2791
+ "perpHandler",
2792
+ "perpDeposit"
2793
+ );
2794
+ const result = await perpHandler.handle({
2795
+ userAddress: input.authenticatedAddress,
2796
+ chainId: input.chainId,
2797
+ amount: input.amount,
2798
+ brokerId: input.brokerId,
2799
+ aaNonce: input.aaNonce
2800
+ });
2801
+ const sponsorAuth = await this.buildSponsorAuth(
2802
+ input.authenticatedAddress,
2803
+ result.userOp.callData,
2804
+ input.chainId,
2805
+ "perp-deposit"
2806
+ );
2807
+ return {
2808
+ calls: result.calls,
2809
+ callsFallback: result.callsFallback,
2810
+ relayTokenFee: result.relayTokenFee.toString(),
2811
+ maxFee: result.maxFee.toString(),
2812
+ netDeposit: result.netDeposit.toString(),
2813
+ ptGasFee: result.feeAmount.toString(),
2814
+ accountId: result.accountId,
2815
+ brokerHash: result.brokerHash,
2816
+ usdcAddress: result.usdcAddress,
2817
+ relayAddress: result.relayAddress,
2818
+ sponsorAuth
2819
+ };
2820
+ }
2821
+ // ------------------------------ Mobile endpoints -------------------------
2822
+ async claimPrepare(input) {
2823
+ const ptClaimHandler = this.assertHandler(
2824
+ this.cfg.ptClaimHandler,
2825
+ "ptClaimHandler",
2826
+ "claimPrepare"
2827
+ );
2828
+ const pointTokenAddress = (0, import_viem11.getAddress)(input.pointTokenAddress);
2829
+ const claimResult = await ptClaimHandler.handle({
2830
+ authenticatedAddress: input.authenticatedAddress,
2831
+ userAddress: input.authenticatedAddress,
2832
+ amount: input.amount,
2833
+ pointTokenAddress,
2834
+ chainId: input.chainId,
2835
+ aaNonce: input.aaNonce,
2836
+ mintRequestNonce: input.mintRequestNonce
2837
+ });
2838
+ const prepared = await this.runMobilePrepare(
2839
+ input.authenticatedAddress,
2840
+ input.chainId,
2841
+ claimResult.lockId,
2842
+ claimResult.userOp,
2843
+ claimResult.fallback,
2844
+ "mint",
2845
+ pointTokenAddress,
2846
+ claimResult.expiresInSeconds
2847
+ );
2848
+ return {
2849
+ lockId: claimResult.lockId,
2850
+ userOpHash: prepared.sponsored.userOpHash,
2851
+ typedData: prepared.sponsored.typedData,
2852
+ userOpHashFallback: prepared.fallback?.userOpHash,
2853
+ typedDataFallback: prepared.fallback?.typedData,
2854
+ feeAmount: claimResult.feeAmount.toString(),
2855
+ signatureDeadline: claimResult.signatureDeadline.toString(),
2856
+ expiresInSeconds: claimResult.expiresInSeconds,
2857
+ sponsored: prepared.isSponsored,
2858
+ needsDelegation: prepared.needsDelegation
2859
+ };
2860
+ }
2861
+ async claimSubmit(input) {
2862
+ return await handleMobileSubmit({
2863
+ lockId: input.lockId,
2864
+ authenticatedAddress: input.authenticatedAddress,
2865
+ signature: input.signature,
2866
+ variant: input.variant,
2867
+ store: this.cfg.pendingUserOpStore,
2868
+ bindUserOpHash: (lockId, hash) => this.cfg.ledger.bindMintUserOpHash(lockId, hash),
2869
+ pafiBackendClient: this.cfg.pafiBackendClient
2870
+ });
2871
+ }
2872
+ async redeemPrepare(input) {
2873
+ this.assertRedeemHandler();
2874
+ const pointTokenAddress = (0, import_viem11.getAddress)(input.pointTokenAddress);
2875
+ const redeemResponse = await this.cfg.ptRedeemHandler.handle({
2876
+ userAddress: input.authenticatedAddress,
2877
+ authenticatedAddress: input.authenticatedAddress,
2878
+ amount: input.amount,
2879
+ aaNonce: input.aaNonce,
2880
+ chainId: input.chainId
2881
+ });
2882
+ const prepared = await this.runMobilePrepare(
2883
+ input.authenticatedAddress,
2884
+ input.chainId,
2885
+ redeemResponse.lockId,
2886
+ redeemResponse.userOp,
2887
+ redeemResponse.fallback?.userOp,
2888
+ "burn",
2889
+ pointTokenAddress,
2890
+ redeemResponse.expiresInSeconds
2891
+ );
2892
+ return {
2893
+ lockId: redeemResponse.lockId,
2894
+ userOpHash: prepared.sponsored.userOpHash,
2895
+ typedData: prepared.sponsored.typedData,
2896
+ userOpHashFallback: prepared.fallback?.userOpHash,
2897
+ typedDataFallback: prepared.fallback?.typedData,
2898
+ netCreditAmount: redeemResponse.netCreditAmount.toString(),
2899
+ netCreditAmountFallback: redeemResponse.fallback?.netCreditAmount.toString(),
2900
+ feeAmount: redeemResponse.feeAmount.toString(),
2901
+ signatureDeadline: redeemResponse.signatureDeadline.toString(),
2902
+ expiresInSeconds: redeemResponse.expiresInSeconds,
2903
+ sponsored: prepared.isSponsored,
2904
+ needsDelegation: prepared.needsDelegation
2905
+ };
2906
+ }
2907
+ async redeemSubmit(input) {
2908
+ return await handleMobileSubmit({
2909
+ lockId: input.lockId,
2910
+ authenticatedAddress: input.authenticatedAddress,
2911
+ signature: input.signature,
2912
+ variant: input.variant,
2913
+ store: this.cfg.pendingUserOpStore,
2914
+ bindUserOpHash: (lockId, hash) => this.cfg.ledger.bindCreditUserOpHash(lockId, hash),
2915
+ pafiBackendClient: this.cfg.pafiBackendClient
2916
+ });
2917
+ }
2918
+ async claimStatus(authenticatedAddress, lockId) {
2919
+ return await handleClaimStatus({
2920
+ lockId,
2921
+ userAddress: authenticatedAddress,
2922
+ ledger: this.cfg.ledger,
2923
+ pafiBackendClient: this.cfg.pafiBackendClient,
2924
+ onWarning: this.cfg.onWarning
2925
+ });
2926
+ }
2927
+ async redeemStatus(authenticatedAddress, lockId) {
2928
+ return await handleRedeemStatus({
2929
+ lockId,
2930
+ userAddress: authenticatedAddress,
2931
+ ledger: this.cfg.ledger,
2932
+ pafiBackendClient: this.cfg.pafiBackendClient,
2933
+ onWarning: this.cfg.onWarning
2934
+ });
2935
+ }
2936
+ // ------------------------------ Delegate endpoints -----------------------
2937
+ async delegateStatus(authenticatedAddress, chainId) {
2938
+ const { batchExecutor } = (0, import_core14.getContractAddresses)(chainId);
2939
+ const code = await this.cfg.provider.getCode({
2940
+ address: authenticatedAddress
2941
+ });
2942
+ return {
2943
+ isDelegated: (0, import_core14.parseEip7702DelegatedAddress)(code) !== null,
2944
+ batchExecutorAddress: batchExecutor
2945
+ };
2946
+ }
2947
+ async delegatePrepare(authenticatedAddress, chainId) {
2948
+ const { batchExecutor } = (0, import_core14.getContractAddresses)(chainId);
2949
+ const accountNonce = BigInt(
2950
+ await this.cfg.provider.getTransactionCount({
2951
+ address: authenticatedAddress
2952
+ })
2953
+ );
2954
+ const authorizationHash = (0, import_core14.computeAuthorizationHash)(
2955
+ chainId,
2956
+ batchExecutor,
2957
+ accountNonce
2958
+ );
2959
+ return {
2960
+ authorizationHash,
2961
+ delegationNonce: accountNonce.toString(),
2962
+ batchExecutorAddress: batchExecutor,
2963
+ chainId
2964
+ };
2965
+ }
2966
+ async delegateSubmit(input) {
2967
+ const fees = await this.cfg.provider.estimateFeesPerGas();
2968
+ const result = await handleDelegateSubmit({
2969
+ userAddress: input.authenticatedAddress,
2970
+ chainId: input.chainId,
2971
+ delegationNonce: input.delegationNonce,
2972
+ aaNonce: input.aaNonce,
2973
+ authSig: input.authSig,
2974
+ fees,
2975
+ pafiBackendClient: this.cfg.pafiBackendClient,
2976
+ onWarning: this.cfg.onWarning
2977
+ });
2978
+ return { userOpHash: result.userOpHash };
2979
+ }
2980
+ // ------------------------------ Internal helpers -------------------------
2981
+ /**
2982
+ * Build + sign a SponsorAuth payload. Returns `undefined` when no
2983
+ * issuer id is configured, so the controller can skip the field.
2984
+ */
2985
+ async buildSponsorAuth(authenticatedAddress, callData, chainId, scenario) {
2986
+ if (!this.cfg.pafiIssuerId) return void 0;
2987
+ return (0, import_core14.buildAndSignSponsorAuth)({
2988
+ userAddress: authenticatedAddress,
2989
+ callData,
2990
+ chainId,
2991
+ scenario,
2992
+ issuerId: this.cfg.pafiIssuerId,
2993
+ issuerSignerWallet: this.cfg.issuerSignerWallet
2994
+ });
2995
+ }
2996
+ async runMobilePrepare(authenticatedAddress, chainId, lockId, partialUserOp, partialUserOpFallback, scenario, pointTokenAddress, ttlSeconds) {
2997
+ return await handleMobilePrepare({
2998
+ userAddress: authenticatedAddress,
2999
+ chainId,
3000
+ lockId,
3001
+ partialUserOp,
3002
+ partialUserOpFallback,
3003
+ scenario,
3004
+ pointTokenAddress,
3005
+ ttlSeconds,
3006
+ store: this.cfg.pendingUserOpStore,
3007
+ provider: this.cfg.provider,
3008
+ pafiBackendClient: this.cfg.pafiBackendClient,
3009
+ onWarning: this.cfg.onWarning
3010
+ });
3011
+ }
3012
+ assertRedeemHandler() {
3013
+ if (!this.cfg.ptRedeemHandler) {
3014
+ throw new Error(
3015
+ "PTRedeemHandler not wired \u2014 IssuerApiAdapter.redeem* require a configured ptRedeemHandler."
3016
+ );
3017
+ }
3018
+ }
3019
+ /**
3020
+ * Narrow an optional handler to non-null and throw a clear error when
3021
+ * the issuer wired the adapter without it. Lets issuers opt out of
3022
+ * flows they don't expose (gg56 ships only mobile claim/redeem, so
3023
+ * `swapHandler` + `perpHandler` aren't constructed).
3024
+ */
3025
+ assertHandler(handler, fieldName, methodName) {
3026
+ if (handler === null || handler === void 0) {
3027
+ throw new Error(
3028
+ `${fieldName} not wired \u2014 IssuerApiAdapter.${methodName}() requires a configured ${fieldName}.`
3029
+ );
3030
+ }
3031
+ return handler;
3032
+ }
3033
+ };
3034
+
3035
+ // src/pools/subgraphPoolsProvider.ts
3036
+ var import_viem12 = require("viem");
3037
+ var import_core15 = require("@pafi-dev/core");
2624
3038
  var DEFAULT_CACHE_TTL_MS = 3e4;
2625
3039
  var POOL_QUERY = `
2626
3040
  query GetPoolForPointToken($id: ID!) {
@@ -2638,7 +3052,7 @@ var POOL_QUERY = `
2638
3052
  }
2639
3053
  `;
2640
3054
  function createSubgraphPoolsProvider(config = {}) {
2641
- const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
3055
+ const subgraphUrl = config.subgraphUrl ?? import_core15.PAFI_SUBGRAPH_URL;
2642
3056
  try {
2643
3057
  const parsed = new URL(subgraphUrl);
2644
3058
  if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
@@ -2720,7 +3134,7 @@ async function fetchPoolsFromSubgraph(fetchImpl, subgraphUrl, pointTokenAddress)
2720
3134
  return [];
2721
3135
  }
2722
3136
  const { pool } = token;
2723
- if (!(0, import_viem11.isAddress)(pool.hooks)) {
3137
+ if (!(0, import_viem12.isAddress)(pool.hooks)) {
2724
3138
  console.error(
2725
3139
  "[PAFI] SubgraphPoolsProvider: invalid hooks address in response:",
2726
3140
  pool.hooks,
@@ -2728,7 +3142,7 @@ async function fetchPoolsFromSubgraph(fetchImpl, subgraphUrl, pointTokenAddress)
2728
3142
  );
2729
3143
  return [];
2730
3144
  }
2731
- if (!(0, import_viem11.isAddress)(pool.token0.id) || !(0, import_viem11.isAddress)(pool.token1.id)) {
3145
+ if (!(0, import_viem12.isAddress)(pool.token0.id) || !(0, import_viem12.isAddress)(pool.token1.id)) {
2732
3146
  console.error(
2733
3147
  "[PAFI] SubgraphPoolsProvider: invalid token address in response \u2014 skipping pool"
2734
3148
  );
@@ -2770,7 +3184,7 @@ var PRICE_QUERY = `
2770
3184
  }
2771
3185
  `;
2772
3186
  function createSubgraphNativeUsdtQuoter(config = {}) {
2773
- const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
3187
+ const subgraphUrl = config.subgraphUrl ?? import_core15.PAFI_SUBGRAPH_URL;
2774
3188
  try {
2775
3189
  const parsed = new URL(subgraphUrl);
2776
3190
  if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
@@ -2878,8 +3292,8 @@ function toUsdtPerNative(priceFloat, usdtDecimals) {
2878
3292
  }
2879
3293
 
2880
3294
  // src/pools/nativePtQuoter.ts
2881
- var import_viem12 = require("viem");
2882
- var CHAINLINK_ABI = (0, import_viem12.parseAbi)([
3295
+ var import_viem13 = require("viem");
3296
+ var CHAINLINK_ABI = (0, import_viem13.parseAbi)([
2883
3297
  "function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)"
2884
3298
  ]);
2885
3299
  var CHAINLINK_MAX_AGE_S = 3600n;
@@ -2900,7 +3314,7 @@ function createNativePtQuoter(config) {
2900
3314
  provider,
2901
3315
  pointTokenAddress,
2902
3316
  chainlinkFeedAddress = "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70",
2903
- subgraphUrl = import_core14.PAFI_SUBGRAPH_URL,
3317
+ subgraphUrl = import_core15.PAFI_SUBGRAPH_URL,
2904
3318
  cacheTtlMs = 3e4,
2905
3319
  fallbackEthPriceUsd = 3e3,
2906
3320
  fallbackPtPriceUsdt = 0.1,
@@ -2982,7 +3396,7 @@ function parseBigDecimalTo18(s) {
2982
3396
  }
2983
3397
 
2984
3398
  // src/balance/balanceAggregator.ts
2985
- var import_core15 = require("@pafi-dev/core");
3399
+ var import_core16 = require("@pafi-dev/core");
2986
3400
  var BalanceAggregator = class {
2987
3401
  provider;
2988
3402
  ledger;
@@ -3003,7 +3417,7 @@ var BalanceAggregator = class {
3003
3417
  async getCombinedBalance(user, pointToken) {
3004
3418
  const [offChain, onChain] = await Promise.all([
3005
3419
  this.ledger.getBalance(user, pointToken),
3006
- (0, import_core15.getPointTokenBalance)(this.provider, pointToken, user)
3420
+ (0, import_core16.getPointTokenBalance)(this.provider, pointToken, user)
3007
3421
  ]);
3008
3422
  return {
3009
3423
  offChain,
@@ -3236,8 +3650,8 @@ var PafiBackendClient = class {
3236
3650
  };
3237
3651
 
3238
3652
  // src/config.ts
3239
- var import_viem13 = require("viem");
3240
- var import_core16 = require("@pafi-dev/core");
3653
+ var import_viem14 = require("viem");
3654
+ var import_core17 = require("@pafi-dev/core");
3241
3655
  function createIssuerService(config) {
3242
3656
  if (!config.provider) {
3243
3657
  throw new Error("createIssuerService: provider is required");
@@ -3257,7 +3671,7 @@ function createIssuerService(config) {
3257
3671
  "createIssuerService: at least one of pointTokenAddress / pointTokenAddresses is required"
3258
3672
  );
3259
3673
  }
3260
- const tokenAddresses = rawAddresses.map((a) => (0, import_viem13.getAddress)(a));
3674
+ const tokenAddresses = rawAddresses.map((a) => (0, import_viem14.getAddress)(a));
3261
3675
  const ledger = config.ledger;
3262
3676
  const sessionStore = config.sessionStore ?? new MemorySessionStore();
3263
3677
  const policy = config.policy ?? new DefaultPolicyEngine({ ledger });
@@ -3307,7 +3721,7 @@ function createIssuerService(config) {
3307
3721
  indexers.set(tokenAddress, new PointIndexer(indexerConfig));
3308
3722
  }
3309
3723
  const firstIndexer = indexers.get(tokenAddresses[0]);
3310
- const chainAddresses = (0, import_core16.getContractAddresses)(config.chainId);
3724
+ const chainAddresses = (0, import_core17.getContractAddresses)(config.chainId);
3311
3725
  const resolvedContracts = {
3312
3726
  batchExecutor: chainAddresses.batchExecutor,
3313
3727
  usdt: chainAddresses.usdt,
@@ -3355,8 +3769,8 @@ function createIssuerService(config) {
3355
3769
  }
3356
3770
 
3357
3771
  // src/issuer-state/validator.ts
3358
- var import_viem14 = require("viem");
3359
- var import_core17 = require("@pafi-dev/core");
3772
+ var import_viem15 = require("viem");
3773
+ var import_core18 = require("@pafi-dev/core");
3360
3774
  var ISSUER_RECORD_TTL_MS = 3e4;
3361
3775
  var IssuerStateValidator = class _IssuerStateValidator {
3362
3776
  constructor(provider, registryAddress) {
@@ -3373,7 +3787,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
3373
3787
  * `CONTRACT_ADDRESSES` map for the given chain.
3374
3788
  */
3375
3789
  static forChain(provider, chainId) {
3376
- const { issuerRegistry } = (0, import_core17.getContractAddresses)(chainId);
3790
+ const { issuerRegistry } = (0, import_core18.getContractAddresses)(chainId);
3377
3791
  return new _IssuerStateValidator(provider, issuerRegistry);
3378
3792
  }
3379
3793
  /**
@@ -3382,7 +3796,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
3382
3796
  */
3383
3797
  invalidate(pointToken) {
3384
3798
  if (pointToken) {
3385
- const key = (0, import_viem14.getAddress)(pointToken);
3799
+ const key = (0, import_viem15.getAddress)(pointToken);
3386
3800
  this.pointTokenIssuerCache.delete(key);
3387
3801
  this.stateCache.delete(key);
3388
3802
  this.inflight.delete(key);
@@ -3397,23 +3811,23 @@ var IssuerStateValidator = class _IssuerStateValidator {
3397
3811
  * The issuer field is set at `initialize()` and never changes.
3398
3812
  */
3399
3813
  async getIssuerAddressForPointToken(pointToken) {
3400
- const key = (0, import_viem14.getAddress)(pointToken);
3814
+ const key = (0, import_viem15.getAddress)(pointToken);
3401
3815
  const cached = this.pointTokenIssuerCache.get(key);
3402
3816
  if (cached) return cached;
3403
3817
  const issuer = await this.provider.readContract({
3404
3818
  address: key,
3405
- abi: import_core17.POINT_TOKEN_V2_ABI,
3819
+ abi: import_core18.POINT_TOKEN_V2_ABI,
3406
3820
  functionName: "issuer"
3407
3821
  });
3408
- this.pointTokenIssuerCache.set(key, (0, import_viem14.getAddress)(issuer));
3409
- return (0, import_viem14.getAddress)(issuer);
3822
+ this.pointTokenIssuerCache.set(key, (0, import_viem15.getAddress)(issuer));
3823
+ return (0, import_viem15.getAddress)(issuer);
3410
3824
  }
3411
3825
  /**
3412
3826
  * Read registry record + totalSupply, with 30s cache and in-flight
3413
3827
  * deduplication. Does NOT throw on inactive/missing — returns raw state.
3414
3828
  */
3415
3829
  async getIssuerState(pointToken) {
3416
- const tokenAddr = (0, import_viem14.getAddress)(pointToken);
3830
+ const tokenAddr = (0, import_viem15.getAddress)(pointToken);
3417
3831
  const now = Date.now();
3418
3832
  const cached = this.stateCache.get(tokenAddr);
3419
3833
  if (cached && cached.expiresAt > now) return cached.value;
@@ -3483,13 +3897,13 @@ var IssuerStateValidator = class _IssuerStateValidator {
3483
3897
  const [issuerTuple, totalSupply] = await Promise.all([
3484
3898
  this.provider.readContract({
3485
3899
  address: this.registryAddress,
3486
- abi: import_core17.issuerRegistryGetIssuerFlatAbi,
3900
+ abi: import_core18.issuerRegistryGetIssuerFlatAbi,
3487
3901
  functionName: "getIssuer",
3488
3902
  args: [issuerAddr]
3489
3903
  }),
3490
3904
  this.provider.readContract({
3491
3905
  address: tokenAddr,
3492
- abi: import_core17.POINT_TOKEN_V2_ABI,
3906
+ abi: import_core18.POINT_TOKEN_V2_ABI,
3493
3907
  functionName: "totalSupply"
3494
3908
  })
3495
3909
  ]);
@@ -3523,6 +3937,7 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
3523
3937
  DefaultPolicyEngine,
3524
3938
  FeeManager,
3525
3939
  InMemoryCursorStore,
3940
+ IssuerApiAdapter,
3526
3941
  IssuerApiHandlers,
3527
3942
  IssuerStateError,
3528
3943
  IssuerStateValidator,