@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 +441 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +368 -124
- package/dist/index.d.ts +368 -124
- package/dist/index.js +434 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2593,6 +2593,427 @@ function createSdkErrorMapper(factories) {
|
|
|
2593
2593
|
};
|
|
2594
2594
|
}
|
|
2595
2595
|
|
|
2596
|
+
// src/api/issuerApiAdapter.ts
|
|
2597
|
+
import { getAddress as getAddress10 } from "viem";
|
|
2598
|
+
import {
|
|
2599
|
+
buildAndSignSponsorAuth,
|
|
2600
|
+
computeAuthorizationHash,
|
|
2601
|
+
decodeBatchExecuteCalls as decodeBatchExecuteCalls4,
|
|
2602
|
+
encodeBatchExecute as encodeBatchExecute2,
|
|
2603
|
+
ENTRY_POINT_V08 as ENTRY_POINT_V083,
|
|
2604
|
+
getContractAddresses as getContractAddresses8,
|
|
2605
|
+
parseEip7702DelegatedAddress as parseEip7702DelegatedAddress2
|
|
2606
|
+
} from "@pafi-dev/core";
|
|
2607
|
+
var IssuerApiAdapter = class {
|
|
2608
|
+
cfg;
|
|
2609
|
+
constructor(config) {
|
|
2610
|
+
this.cfg = config;
|
|
2611
|
+
}
|
|
2612
|
+
// ------------------------------ Read endpoints ---------------------------
|
|
2613
|
+
async config(chainId) {
|
|
2614
|
+
const result = await this.cfg.issuerService.api.handleConfig(chainId);
|
|
2615
|
+
return {
|
|
2616
|
+
chainId: result.chainId,
|
|
2617
|
+
contracts: result.contracts
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
async gasFee() {
|
|
2621
|
+
const result = await this.cfg.issuerService.api.handleGasFee();
|
|
2622
|
+
return { gasFeeUsdt: result.gasFeeUsdt.toString() };
|
|
2623
|
+
}
|
|
2624
|
+
async pools(authenticatedAddress, chainId, pointTokenAddress) {
|
|
2625
|
+
const result = await this.cfg.issuerService.api.handlePools(
|
|
2626
|
+
authenticatedAddress,
|
|
2627
|
+
{ chainId, pointTokenAddress: getAddress10(pointTokenAddress) }
|
|
2628
|
+
);
|
|
2629
|
+
return { pools: result.pools };
|
|
2630
|
+
}
|
|
2631
|
+
async user(authenticatedAddress, chainId, userAddress, pointTokenAddress) {
|
|
2632
|
+
const result = await this.cfg.issuerService.api.handleUser(
|
|
2633
|
+
authenticatedAddress,
|
|
2634
|
+
{
|
|
2635
|
+
chainId,
|
|
2636
|
+
userAddress: getAddress10(userAddress),
|
|
2637
|
+
pointTokenAddress: getAddress10(pointTokenAddress)
|
|
2638
|
+
}
|
|
2639
|
+
);
|
|
2640
|
+
return {
|
|
2641
|
+
mintRequestNonce: result.mintRequestNonce.toString(),
|
|
2642
|
+
receiverConsentNonce: result.receiverConsentNonce.toString(),
|
|
2643
|
+
offChainBalance: result.offChainBalance.toString(),
|
|
2644
|
+
onChainBalance: result.onChainBalance.toString(),
|
|
2645
|
+
totalBalance: result.totalBalance.toString(),
|
|
2646
|
+
balance: result.offChainBalance.toString(),
|
|
2647
|
+
isMinter: result.isMinter
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
async quote(authenticatedAddress, chainId, pointTokenAddress, pointAmount) {
|
|
2651
|
+
const [gasFeeResult, poolsResult] = await Promise.all([
|
|
2652
|
+
this.cfg.issuerService.api.handleGasFee(),
|
|
2653
|
+
this.cfg.issuerService.api.handlePools(authenticatedAddress, {
|
|
2654
|
+
chainId,
|
|
2655
|
+
pointTokenAddress: getAddress10(pointTokenAddress)
|
|
2656
|
+
})
|
|
2657
|
+
]);
|
|
2658
|
+
const quote = await quotePointTokenToUsdt({
|
|
2659
|
+
provider: this.cfg.provider,
|
|
2660
|
+
chainId,
|
|
2661
|
+
pointTokenAddress: getAddress10(pointTokenAddress),
|
|
2662
|
+
pointAmount,
|
|
2663
|
+
pools: poolsResult.pools,
|
|
2664
|
+
gasFeeUsdt: gasFeeResult.gasFeeUsdt
|
|
2665
|
+
});
|
|
2666
|
+
const dto = {
|
|
2667
|
+
pointAmount: pointAmount.toString(),
|
|
2668
|
+
estimatedUsdtOut: quote.estimatedUsdtOut.toString(),
|
|
2669
|
+
gasFeeUsdt: gasFeeResult.gasFeeUsdt.toString(),
|
|
2670
|
+
netUsdtOut: quote.netUsdtOut.toString(),
|
|
2671
|
+
exchangeRate: quote.exchangeRate,
|
|
2672
|
+
suggestedDeadline: quote.suggestedDeadline.toString(),
|
|
2673
|
+
gasEstimate: quote.gasEstimate.toString()
|
|
2674
|
+
};
|
|
2675
|
+
if (quote.quoteError) dto.quoteError = quote.quoteError;
|
|
2676
|
+
return dto;
|
|
2677
|
+
}
|
|
2678
|
+
// ------------------------------ Action endpoints -------------------------
|
|
2679
|
+
async claim(input) {
|
|
2680
|
+
const ptClaimHandler = this.assertHandler(
|
|
2681
|
+
this.cfg.ptClaimHandler,
|
|
2682
|
+
"ptClaimHandler",
|
|
2683
|
+
"claim"
|
|
2684
|
+
);
|
|
2685
|
+
const pointTokenAddress = getAddress10(input.pointTokenAddress);
|
|
2686
|
+
const result = await ptClaimHandler.handle({
|
|
2687
|
+
authenticatedAddress: input.authenticatedAddress,
|
|
2688
|
+
userAddress: input.authenticatedAddress,
|
|
2689
|
+
amount: input.amount,
|
|
2690
|
+
pointTokenAddress,
|
|
2691
|
+
chainId: input.chainId,
|
|
2692
|
+
aaNonce: input.aaNonce,
|
|
2693
|
+
mintRequestNonce: input.mintRequestNonce
|
|
2694
|
+
});
|
|
2695
|
+
const sponsorAuth = await this.buildSponsorAuth(
|
|
2696
|
+
input.authenticatedAddress,
|
|
2697
|
+
result.userOp.callData,
|
|
2698
|
+
input.chainId,
|
|
2699
|
+
"mint"
|
|
2700
|
+
);
|
|
2701
|
+
return {
|
|
2702
|
+
calls: result.calls,
|
|
2703
|
+
callsFallback: result.callsFallback,
|
|
2704
|
+
feeAmount: result.feeAmount.toString(),
|
|
2705
|
+
lockId: result.lockId,
|
|
2706
|
+
signatureDeadline: result.signatureDeadline.toString(),
|
|
2707
|
+
sponsorAuth
|
|
2708
|
+
};
|
|
2709
|
+
}
|
|
2710
|
+
async redeem(input) {
|
|
2711
|
+
this.assertRedeemHandler();
|
|
2712
|
+
const response = await this.cfg.ptRedeemHandler.handle({
|
|
2713
|
+
userAddress: input.authenticatedAddress,
|
|
2714
|
+
authenticatedAddress: input.authenticatedAddress,
|
|
2715
|
+
amount: input.amount,
|
|
2716
|
+
aaNonce: input.aaNonce,
|
|
2717
|
+
chainId: input.chainId
|
|
2718
|
+
});
|
|
2719
|
+
const sponsorAuth = await this.buildSponsorAuth(
|
|
2720
|
+
input.authenticatedAddress,
|
|
2721
|
+
response.userOp.callData,
|
|
2722
|
+
input.chainId,
|
|
2723
|
+
"burn"
|
|
2724
|
+
);
|
|
2725
|
+
return {
|
|
2726
|
+
calls: decodeBatchExecuteCalls4(response.userOp.callData),
|
|
2727
|
+
callsFallback: response.fallback ? decodeBatchExecuteCalls4(response.fallback.userOp.callData) : void 0,
|
|
2728
|
+
feeAmount: response.feeAmount.toString(),
|
|
2729
|
+
lockId: response.lockId,
|
|
2730
|
+
lockIdFallback: response.fallback?.lockId,
|
|
2731
|
+
netCreditAmount: response.netCreditAmount.toString(),
|
|
2732
|
+
netCreditAmountFallback: response.fallback?.netCreditAmount.toString(),
|
|
2733
|
+
expiresInSeconds: response.expiresInSeconds,
|
|
2734
|
+
signatureDeadline: response.signatureDeadline.toString(),
|
|
2735
|
+
sponsorAuth
|
|
2736
|
+
};
|
|
2737
|
+
}
|
|
2738
|
+
async swap(input) {
|
|
2739
|
+
const swapHandler = this.assertHandler(
|
|
2740
|
+
this.cfg.swapHandler,
|
|
2741
|
+
"swapHandler",
|
|
2742
|
+
"swap"
|
|
2743
|
+
);
|
|
2744
|
+
const result = await swapHandler.handle({
|
|
2745
|
+
userAddress: input.authenticatedAddress,
|
|
2746
|
+
chainId: input.chainId,
|
|
2747
|
+
pointTokenAddress: getAddress10(input.pointTokenAddress),
|
|
2748
|
+
amountIn: input.amountIn,
|
|
2749
|
+
aaNonce: input.aaNonce,
|
|
2750
|
+
slippageBps: input.slippageBps
|
|
2751
|
+
});
|
|
2752
|
+
const sponsorAuth = await this.buildSponsorAuth(
|
|
2753
|
+
input.authenticatedAddress,
|
|
2754
|
+
result.userOp.callData,
|
|
2755
|
+
input.chainId,
|
|
2756
|
+
"swap"
|
|
2757
|
+
);
|
|
2758
|
+
return {
|
|
2759
|
+
calls: result.calls,
|
|
2760
|
+
callsFallback: result.callsFallback,
|
|
2761
|
+
feeAmount: result.feeAmount.toString(),
|
|
2762
|
+
estimatedUsdtOut: result.estimatedUsdtOut.toString(),
|
|
2763
|
+
minAmountOut: result.minAmountOut.toString(),
|
|
2764
|
+
estimatedUsdtOutFallback: result.estimatedUsdtOutFallback?.toString(),
|
|
2765
|
+
minAmountOutFallback: result.minAmountOutFallback?.toString(),
|
|
2766
|
+
deadline: result.deadline.toString(),
|
|
2767
|
+
sponsorAuth
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
async perpDeposit(input) {
|
|
2771
|
+
const perpHandler = this.assertHandler(
|
|
2772
|
+
this.cfg.perpHandler,
|
|
2773
|
+
"perpHandler",
|
|
2774
|
+
"perpDeposit"
|
|
2775
|
+
);
|
|
2776
|
+
const result = await perpHandler.handle({
|
|
2777
|
+
userAddress: input.authenticatedAddress,
|
|
2778
|
+
chainId: input.chainId,
|
|
2779
|
+
amount: input.amount,
|
|
2780
|
+
brokerId: input.brokerId,
|
|
2781
|
+
aaNonce: input.aaNonce
|
|
2782
|
+
});
|
|
2783
|
+
const sponsorAuth = await this.buildSponsorAuth(
|
|
2784
|
+
input.authenticatedAddress,
|
|
2785
|
+
result.userOp.callData,
|
|
2786
|
+
input.chainId,
|
|
2787
|
+
"perp-deposit"
|
|
2788
|
+
);
|
|
2789
|
+
return {
|
|
2790
|
+
calls: result.calls,
|
|
2791
|
+
callsFallback: result.callsFallback,
|
|
2792
|
+
relayTokenFee: result.relayTokenFee.toString(),
|
|
2793
|
+
maxFee: result.maxFee.toString(),
|
|
2794
|
+
netDeposit: result.netDeposit.toString(),
|
|
2795
|
+
ptGasFee: result.feeAmount.toString(),
|
|
2796
|
+
accountId: result.accountId,
|
|
2797
|
+
brokerHash: result.brokerHash,
|
|
2798
|
+
usdcAddress: result.usdcAddress,
|
|
2799
|
+
relayAddress: result.relayAddress,
|
|
2800
|
+
sponsorAuth
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
// ------------------------------ Mobile endpoints -------------------------
|
|
2804
|
+
async claimPrepare(input) {
|
|
2805
|
+
const ptClaimHandler = this.assertHandler(
|
|
2806
|
+
this.cfg.ptClaimHandler,
|
|
2807
|
+
"ptClaimHandler",
|
|
2808
|
+
"claimPrepare"
|
|
2809
|
+
);
|
|
2810
|
+
const pointTokenAddress = getAddress10(input.pointTokenAddress);
|
|
2811
|
+
const claimResult = await ptClaimHandler.handle({
|
|
2812
|
+
authenticatedAddress: input.authenticatedAddress,
|
|
2813
|
+
userAddress: input.authenticatedAddress,
|
|
2814
|
+
amount: input.amount,
|
|
2815
|
+
pointTokenAddress,
|
|
2816
|
+
chainId: input.chainId,
|
|
2817
|
+
aaNonce: input.aaNonce,
|
|
2818
|
+
mintRequestNonce: input.mintRequestNonce
|
|
2819
|
+
});
|
|
2820
|
+
const prepared = await this.runMobilePrepare(
|
|
2821
|
+
input.authenticatedAddress,
|
|
2822
|
+
input.chainId,
|
|
2823
|
+
claimResult.lockId,
|
|
2824
|
+
claimResult.userOp,
|
|
2825
|
+
claimResult.fallback,
|
|
2826
|
+
"mint",
|
|
2827
|
+
pointTokenAddress,
|
|
2828
|
+
claimResult.expiresInSeconds
|
|
2829
|
+
);
|
|
2830
|
+
return {
|
|
2831
|
+
lockId: claimResult.lockId,
|
|
2832
|
+
userOpHash: prepared.sponsored.userOpHash,
|
|
2833
|
+
typedData: prepared.sponsored.typedData,
|
|
2834
|
+
userOpHashFallback: prepared.fallback?.userOpHash,
|
|
2835
|
+
typedDataFallback: prepared.fallback?.typedData,
|
|
2836
|
+
feeAmount: claimResult.feeAmount.toString(),
|
|
2837
|
+
signatureDeadline: claimResult.signatureDeadline.toString(),
|
|
2838
|
+
expiresInSeconds: claimResult.expiresInSeconds,
|
|
2839
|
+
sponsored: prepared.isSponsored,
|
|
2840
|
+
needsDelegation: prepared.needsDelegation
|
|
2841
|
+
};
|
|
2842
|
+
}
|
|
2843
|
+
async claimSubmit(input) {
|
|
2844
|
+
return await handleMobileSubmit({
|
|
2845
|
+
lockId: input.lockId,
|
|
2846
|
+
authenticatedAddress: input.authenticatedAddress,
|
|
2847
|
+
signature: input.signature,
|
|
2848
|
+
variant: input.variant,
|
|
2849
|
+
store: this.cfg.pendingUserOpStore,
|
|
2850
|
+
bindUserOpHash: (lockId, hash) => this.cfg.ledger.bindMintUserOpHash(lockId, hash),
|
|
2851
|
+
pafiBackendClient: this.cfg.pafiBackendClient
|
|
2852
|
+
});
|
|
2853
|
+
}
|
|
2854
|
+
async redeemPrepare(input) {
|
|
2855
|
+
this.assertRedeemHandler();
|
|
2856
|
+
const pointTokenAddress = getAddress10(input.pointTokenAddress);
|
|
2857
|
+
const redeemResponse = await this.cfg.ptRedeemHandler.handle({
|
|
2858
|
+
userAddress: input.authenticatedAddress,
|
|
2859
|
+
authenticatedAddress: input.authenticatedAddress,
|
|
2860
|
+
amount: input.amount,
|
|
2861
|
+
aaNonce: input.aaNonce,
|
|
2862
|
+
chainId: input.chainId
|
|
2863
|
+
});
|
|
2864
|
+
const prepared = await this.runMobilePrepare(
|
|
2865
|
+
input.authenticatedAddress,
|
|
2866
|
+
input.chainId,
|
|
2867
|
+
redeemResponse.lockId,
|
|
2868
|
+
redeemResponse.userOp,
|
|
2869
|
+
redeemResponse.fallback?.userOp,
|
|
2870
|
+
"burn",
|
|
2871
|
+
pointTokenAddress,
|
|
2872
|
+
redeemResponse.expiresInSeconds
|
|
2873
|
+
);
|
|
2874
|
+
return {
|
|
2875
|
+
lockId: redeemResponse.lockId,
|
|
2876
|
+
userOpHash: prepared.sponsored.userOpHash,
|
|
2877
|
+
typedData: prepared.sponsored.typedData,
|
|
2878
|
+
userOpHashFallback: prepared.fallback?.userOpHash,
|
|
2879
|
+
typedDataFallback: prepared.fallback?.typedData,
|
|
2880
|
+
netCreditAmount: redeemResponse.netCreditAmount.toString(),
|
|
2881
|
+
netCreditAmountFallback: redeemResponse.fallback?.netCreditAmount.toString(),
|
|
2882
|
+
feeAmount: redeemResponse.feeAmount.toString(),
|
|
2883
|
+
signatureDeadline: redeemResponse.signatureDeadline.toString(),
|
|
2884
|
+
expiresInSeconds: redeemResponse.expiresInSeconds,
|
|
2885
|
+
sponsored: prepared.isSponsored,
|
|
2886
|
+
needsDelegation: prepared.needsDelegation
|
|
2887
|
+
};
|
|
2888
|
+
}
|
|
2889
|
+
async redeemSubmit(input) {
|
|
2890
|
+
return await handleMobileSubmit({
|
|
2891
|
+
lockId: input.lockId,
|
|
2892
|
+
authenticatedAddress: input.authenticatedAddress,
|
|
2893
|
+
signature: input.signature,
|
|
2894
|
+
variant: input.variant,
|
|
2895
|
+
store: this.cfg.pendingUserOpStore,
|
|
2896
|
+
bindUserOpHash: (lockId, hash) => this.cfg.ledger.bindCreditUserOpHash(lockId, hash),
|
|
2897
|
+
pafiBackendClient: this.cfg.pafiBackendClient
|
|
2898
|
+
});
|
|
2899
|
+
}
|
|
2900
|
+
async claimStatus(authenticatedAddress, lockId) {
|
|
2901
|
+
return await handleClaimStatus({
|
|
2902
|
+
lockId,
|
|
2903
|
+
userAddress: authenticatedAddress,
|
|
2904
|
+
ledger: this.cfg.ledger,
|
|
2905
|
+
pafiBackendClient: this.cfg.pafiBackendClient,
|
|
2906
|
+
onWarning: this.cfg.onWarning
|
|
2907
|
+
});
|
|
2908
|
+
}
|
|
2909
|
+
async redeemStatus(authenticatedAddress, lockId) {
|
|
2910
|
+
return await handleRedeemStatus({
|
|
2911
|
+
lockId,
|
|
2912
|
+
userAddress: authenticatedAddress,
|
|
2913
|
+
ledger: this.cfg.ledger,
|
|
2914
|
+
pafiBackendClient: this.cfg.pafiBackendClient,
|
|
2915
|
+
onWarning: this.cfg.onWarning
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2918
|
+
// ------------------------------ Delegate endpoints -----------------------
|
|
2919
|
+
async delegateStatus(authenticatedAddress, chainId) {
|
|
2920
|
+
const { batchExecutor } = getContractAddresses8(chainId);
|
|
2921
|
+
const code = await this.cfg.provider.getCode({
|
|
2922
|
+
address: authenticatedAddress
|
|
2923
|
+
});
|
|
2924
|
+
return {
|
|
2925
|
+
isDelegated: parseEip7702DelegatedAddress2(code) !== null,
|
|
2926
|
+
batchExecutorAddress: batchExecutor
|
|
2927
|
+
};
|
|
2928
|
+
}
|
|
2929
|
+
async delegatePrepare(authenticatedAddress, chainId) {
|
|
2930
|
+
const { batchExecutor } = getContractAddresses8(chainId);
|
|
2931
|
+
const accountNonce = BigInt(
|
|
2932
|
+
await this.cfg.provider.getTransactionCount({
|
|
2933
|
+
address: authenticatedAddress
|
|
2934
|
+
})
|
|
2935
|
+
);
|
|
2936
|
+
const authorizationHash = computeAuthorizationHash(
|
|
2937
|
+
chainId,
|
|
2938
|
+
batchExecutor,
|
|
2939
|
+
accountNonce
|
|
2940
|
+
);
|
|
2941
|
+
return {
|
|
2942
|
+
authorizationHash,
|
|
2943
|
+
delegationNonce: accountNonce.toString(),
|
|
2944
|
+
batchExecutorAddress: batchExecutor,
|
|
2945
|
+
chainId
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
async delegateSubmit(input) {
|
|
2949
|
+
const fees = await this.cfg.provider.estimateFeesPerGas();
|
|
2950
|
+
const result = await handleDelegateSubmit({
|
|
2951
|
+
userAddress: input.authenticatedAddress,
|
|
2952
|
+
chainId: input.chainId,
|
|
2953
|
+
delegationNonce: input.delegationNonce,
|
|
2954
|
+
aaNonce: input.aaNonce,
|
|
2955
|
+
authSig: input.authSig,
|
|
2956
|
+
fees,
|
|
2957
|
+
pafiBackendClient: this.cfg.pafiBackendClient,
|
|
2958
|
+
onWarning: this.cfg.onWarning
|
|
2959
|
+
});
|
|
2960
|
+
return { userOpHash: result.userOpHash };
|
|
2961
|
+
}
|
|
2962
|
+
// ------------------------------ Internal helpers -------------------------
|
|
2963
|
+
/**
|
|
2964
|
+
* Build + sign a SponsorAuth payload. Returns `undefined` when no
|
|
2965
|
+
* issuer id is configured, so the controller can skip the field.
|
|
2966
|
+
*/
|
|
2967
|
+
async buildSponsorAuth(authenticatedAddress, callData, chainId, scenario) {
|
|
2968
|
+
if (!this.cfg.pafiIssuerId) return void 0;
|
|
2969
|
+
return buildAndSignSponsorAuth({
|
|
2970
|
+
userAddress: authenticatedAddress,
|
|
2971
|
+
callData,
|
|
2972
|
+
chainId,
|
|
2973
|
+
scenario,
|
|
2974
|
+
issuerId: this.cfg.pafiIssuerId,
|
|
2975
|
+
issuerSignerWallet: this.cfg.issuerSignerWallet
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
2978
|
+
async runMobilePrepare(authenticatedAddress, chainId, lockId, partialUserOp, partialUserOpFallback, scenario, pointTokenAddress, ttlSeconds) {
|
|
2979
|
+
return await handleMobilePrepare({
|
|
2980
|
+
userAddress: authenticatedAddress,
|
|
2981
|
+
chainId,
|
|
2982
|
+
lockId,
|
|
2983
|
+
partialUserOp,
|
|
2984
|
+
partialUserOpFallback,
|
|
2985
|
+
scenario,
|
|
2986
|
+
pointTokenAddress,
|
|
2987
|
+
ttlSeconds,
|
|
2988
|
+
store: this.cfg.pendingUserOpStore,
|
|
2989
|
+
provider: this.cfg.provider,
|
|
2990
|
+
pafiBackendClient: this.cfg.pafiBackendClient,
|
|
2991
|
+
onWarning: this.cfg.onWarning
|
|
2992
|
+
});
|
|
2993
|
+
}
|
|
2994
|
+
assertRedeemHandler() {
|
|
2995
|
+
if (!this.cfg.ptRedeemHandler) {
|
|
2996
|
+
throw new Error(
|
|
2997
|
+
"PTRedeemHandler not wired \u2014 IssuerApiAdapter.redeem* require a configured ptRedeemHandler."
|
|
2998
|
+
);
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
/**
|
|
3002
|
+
* Narrow an optional handler to non-null and throw a clear error when
|
|
3003
|
+
* the issuer wired the adapter without it. Lets issuers opt out of
|
|
3004
|
+
* flows they don't expose (gg56 ships only mobile claim/redeem, so
|
|
3005
|
+
* `swapHandler` + `perpHandler` aren't constructed).
|
|
3006
|
+
*/
|
|
3007
|
+
assertHandler(handler, fieldName, methodName) {
|
|
3008
|
+
if (handler === null || handler === void 0) {
|
|
3009
|
+
throw new Error(
|
|
3010
|
+
`${fieldName} not wired \u2014 IssuerApiAdapter.${methodName}() requires a configured ${fieldName}.`
|
|
3011
|
+
);
|
|
3012
|
+
}
|
|
3013
|
+
return handler;
|
|
3014
|
+
}
|
|
3015
|
+
};
|
|
3016
|
+
|
|
2596
3017
|
// src/pools/subgraphPoolsProvider.ts
|
|
2597
3018
|
import { isAddress } from "viem";
|
|
2598
3019
|
import { PAFI_SUBGRAPH_URL } from "@pafi-dev/core";
|
|
@@ -3211,8 +3632,8 @@ var PafiBackendClient = class {
|
|
|
3211
3632
|
};
|
|
3212
3633
|
|
|
3213
3634
|
// src/config.ts
|
|
3214
|
-
import { getAddress as
|
|
3215
|
-
import { getContractAddresses as
|
|
3635
|
+
import { getAddress as getAddress11 } from "viem";
|
|
3636
|
+
import { getContractAddresses as getContractAddresses9 } from "@pafi-dev/core";
|
|
3216
3637
|
function createIssuerService(config) {
|
|
3217
3638
|
if (!config.provider) {
|
|
3218
3639
|
throw new Error("createIssuerService: provider is required");
|
|
@@ -3232,7 +3653,7 @@ function createIssuerService(config) {
|
|
|
3232
3653
|
"createIssuerService: at least one of pointTokenAddress / pointTokenAddresses is required"
|
|
3233
3654
|
);
|
|
3234
3655
|
}
|
|
3235
|
-
const tokenAddresses = rawAddresses.map((a) =>
|
|
3656
|
+
const tokenAddresses = rawAddresses.map((a) => getAddress11(a));
|
|
3236
3657
|
const ledger = config.ledger;
|
|
3237
3658
|
const sessionStore = config.sessionStore ?? new MemorySessionStore();
|
|
3238
3659
|
const policy = config.policy ?? new DefaultPolicyEngine({ ledger });
|
|
@@ -3282,7 +3703,7 @@ function createIssuerService(config) {
|
|
|
3282
3703
|
indexers.set(tokenAddress, new PointIndexer(indexerConfig));
|
|
3283
3704
|
}
|
|
3284
3705
|
const firstIndexer = indexers.get(tokenAddresses[0]);
|
|
3285
|
-
const chainAddresses =
|
|
3706
|
+
const chainAddresses = getContractAddresses9(config.chainId);
|
|
3286
3707
|
const resolvedContracts = {
|
|
3287
3708
|
batchExecutor: chainAddresses.batchExecutor,
|
|
3288
3709
|
usdt: chainAddresses.usdt,
|
|
@@ -3330,11 +3751,11 @@ function createIssuerService(config) {
|
|
|
3330
3751
|
}
|
|
3331
3752
|
|
|
3332
3753
|
// src/issuer-state/validator.ts
|
|
3333
|
-
import { getAddress as
|
|
3754
|
+
import { getAddress as getAddress12 } from "viem";
|
|
3334
3755
|
import {
|
|
3335
3756
|
POINT_TOKEN_V2_ABI as POINT_TOKEN_V2_ABI3,
|
|
3336
3757
|
issuerRegistryGetIssuerFlatAbi,
|
|
3337
|
-
getContractAddresses as
|
|
3758
|
+
getContractAddresses as getContractAddresses10
|
|
3338
3759
|
} from "@pafi-dev/core";
|
|
3339
3760
|
var ISSUER_RECORD_TTL_MS = 3e4;
|
|
3340
3761
|
var IssuerStateValidator = class _IssuerStateValidator {
|
|
@@ -3352,7 +3773,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3352
3773
|
* `CONTRACT_ADDRESSES` map for the given chain.
|
|
3353
3774
|
*/
|
|
3354
3775
|
static forChain(provider, chainId) {
|
|
3355
|
-
const { issuerRegistry } =
|
|
3776
|
+
const { issuerRegistry } = getContractAddresses10(chainId);
|
|
3356
3777
|
return new _IssuerStateValidator(provider, issuerRegistry);
|
|
3357
3778
|
}
|
|
3358
3779
|
/**
|
|
@@ -3361,7 +3782,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3361
3782
|
*/
|
|
3362
3783
|
invalidate(pointToken) {
|
|
3363
3784
|
if (pointToken) {
|
|
3364
|
-
const key =
|
|
3785
|
+
const key = getAddress12(pointToken);
|
|
3365
3786
|
this.pointTokenIssuerCache.delete(key);
|
|
3366
3787
|
this.stateCache.delete(key);
|
|
3367
3788
|
this.inflight.delete(key);
|
|
@@ -3376,7 +3797,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3376
3797
|
* The issuer field is set at `initialize()` and never changes.
|
|
3377
3798
|
*/
|
|
3378
3799
|
async getIssuerAddressForPointToken(pointToken) {
|
|
3379
|
-
const key =
|
|
3800
|
+
const key = getAddress12(pointToken);
|
|
3380
3801
|
const cached = this.pointTokenIssuerCache.get(key);
|
|
3381
3802
|
if (cached) return cached;
|
|
3382
3803
|
const issuer = await this.provider.readContract({
|
|
@@ -3384,15 +3805,15 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3384
3805
|
abi: POINT_TOKEN_V2_ABI3,
|
|
3385
3806
|
functionName: "issuer"
|
|
3386
3807
|
});
|
|
3387
|
-
this.pointTokenIssuerCache.set(key,
|
|
3388
|
-
return
|
|
3808
|
+
this.pointTokenIssuerCache.set(key, getAddress12(issuer));
|
|
3809
|
+
return getAddress12(issuer);
|
|
3389
3810
|
}
|
|
3390
3811
|
/**
|
|
3391
3812
|
* Read registry record + totalSupply, with 30s cache and in-flight
|
|
3392
3813
|
* deduplication. Does NOT throw on inactive/missing — returns raw state.
|
|
3393
3814
|
*/
|
|
3394
3815
|
async getIssuerState(pointToken) {
|
|
3395
|
-
const tokenAddr =
|
|
3816
|
+
const tokenAddr = getAddress12(pointToken);
|
|
3396
3817
|
const now = Date.now();
|
|
3397
3818
|
const cached = this.stateCache.get(tokenAddr);
|
|
3398
3819
|
if (cached && cached.expiresAt > now) return cached.value;
|
|
@@ -3501,6 +3922,7 @@ export {
|
|
|
3501
3922
|
DefaultPolicyEngine,
|
|
3502
3923
|
FeeManager,
|
|
3503
3924
|
InMemoryCursorStore,
|
|
3925
|
+
IssuerApiAdapter,
|
|
3504
3926
|
IssuerApiHandlers,
|
|
3505
3927
|
IssuerStateError,
|
|
3506
3928
|
IssuerStateValidator,
|