@pafi-dev/issuer 0.5.36 → 0.5.38
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 +199 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +151 -2
- package/dist/index.d.ts +151 -2
- package/dist/index.js +195 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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: () =>
|
|
39
|
+
PAFI_SUBGRAPH_URL: () => import_core14.PAFI_SUBGRAPH_URL,
|
|
40
40
|
PTClaimError: () => PTClaimError,
|
|
41
41
|
PTClaimHandler: () => PTClaimHandler,
|
|
42
42
|
PTRedeemError: () => PTRedeemError,
|
|
@@ -56,14 +56,17 @@ __export(index_exports, {
|
|
|
56
56
|
authenticateRequest: () => authenticateRequest,
|
|
57
57
|
createIssuerService: () => createIssuerService,
|
|
58
58
|
createNativePtQuoter: () => createNativePtQuoter,
|
|
59
|
+
createSdkErrorMapper: () => createSdkErrorMapper,
|
|
59
60
|
createSubgraphNativeUsdtQuoter: () => createSubgraphNativeUsdtQuoter,
|
|
60
61
|
createSubgraphPoolsProvider: () => createSubgraphPoolsProvider,
|
|
61
62
|
handleClaimStatus: () => handleClaimStatus,
|
|
63
|
+
handleDelegateSubmit: () => handleDelegateSubmit,
|
|
62
64
|
handleMobilePrepare: () => handleMobilePrepare,
|
|
63
65
|
handleMobileSubmit: () => handleMobileSubmit,
|
|
64
66
|
handleRedeemStatus: () => handleRedeemStatus,
|
|
65
67
|
mergePaymasterFields: () => mergePaymasterFields,
|
|
66
68
|
prepareMobileUserOp: () => prepareMobileUserOp,
|
|
69
|
+
quotePointTokenToUsdt: () => quotePointTokenToUsdt,
|
|
67
70
|
relayUserOp: () => relayUserOp,
|
|
68
71
|
requestPaymaster: () => requestPaymaster,
|
|
69
72
|
serializeEntryToJsonRpc: () => serializeEntryToJsonRpc,
|
|
@@ -2409,9 +2412,188 @@ var PerpDepositHandler = class {
|
|
|
2409
2412
|
}
|
|
2410
2413
|
};
|
|
2411
2414
|
|
|
2415
|
+
// src/api/delegateHandler.ts
|
|
2416
|
+
var import_core12 = require("@pafi-dev/core");
|
|
2417
|
+
var DEFAULT_DELEGATE_GAS = {
|
|
2418
|
+
callGasLimit: 100000n,
|
|
2419
|
+
verificationGasLimit: 150000n,
|
|
2420
|
+
preVerificationGas: 50000n
|
|
2421
|
+
};
|
|
2422
|
+
async function handleDelegateSubmit(params) {
|
|
2423
|
+
const { batchExecutor } = (0, import_core12.getContractAddresses)(params.chainId);
|
|
2424
|
+
const callData = (0, import_core12.encodeBatchExecute)([]);
|
|
2425
|
+
const userOp = {
|
|
2426
|
+
sender: params.userAddress,
|
|
2427
|
+
nonce: params.aaNonce,
|
|
2428
|
+
callData,
|
|
2429
|
+
callGasLimit: params.gasLimits?.callGasLimit ?? DEFAULT_DELEGATE_GAS.callGasLimit,
|
|
2430
|
+
verificationGasLimit: params.gasLimits?.verificationGasLimit ?? DEFAULT_DELEGATE_GAS.verificationGasLimit,
|
|
2431
|
+
preVerificationGas: params.gasLimits?.preVerificationGas ?? DEFAULT_DELEGATE_GAS.preVerificationGas,
|
|
2432
|
+
maxFeePerGas: params.fees.maxFeePerGas ?? 0n,
|
|
2433
|
+
maxPriorityFeePerGas: params.fees.maxPriorityFeePerGas ?? 0n
|
|
2434
|
+
};
|
|
2435
|
+
const paymasterFields = await requestPaymaster({
|
|
2436
|
+
client: params.pafiBackendClient,
|
|
2437
|
+
chainId: params.chainId,
|
|
2438
|
+
scenario: "delegate",
|
|
2439
|
+
userOp,
|
|
2440
|
+
pointTokenAddress: batchExecutor,
|
|
2441
|
+
onWarning: params.onWarning
|
|
2442
|
+
});
|
|
2443
|
+
const merged = {
|
|
2444
|
+
...userOp,
|
|
2445
|
+
...paymasterFields ?? {}
|
|
2446
|
+
};
|
|
2447
|
+
const userOpJson = (0, import_core12.serializeUserOpToJsonRpc)(
|
|
2448
|
+
{
|
|
2449
|
+
sender: merged.sender,
|
|
2450
|
+
nonce: merged.nonce,
|
|
2451
|
+
callData: merged.callData,
|
|
2452
|
+
callGasLimit: merged.callGasLimit,
|
|
2453
|
+
verificationGasLimit: merged.verificationGasLimit,
|
|
2454
|
+
preVerificationGas: merged.preVerificationGas,
|
|
2455
|
+
maxFeePerGas: merged.maxFeePerGas,
|
|
2456
|
+
maxPriorityFeePerGas: merged.maxPriorityFeePerGas,
|
|
2457
|
+
paymaster: paymasterFields?.paymaster,
|
|
2458
|
+
paymasterVerificationGasLimit: paymasterFields?.paymasterVerificationGasLimit,
|
|
2459
|
+
paymasterPostOpGasLimit: paymasterFields?.paymasterPostOpGasLimit,
|
|
2460
|
+
paymasterData: paymasterFields?.paymasterData
|
|
2461
|
+
},
|
|
2462
|
+
// Delegation UserOp is submitted unsigned — the EIP-7702 authorization
|
|
2463
|
+
// is the user's "consent"; no separate AA signature is needed.
|
|
2464
|
+
"0x"
|
|
2465
|
+
);
|
|
2466
|
+
const authorization = (0, import_core12.buildEip7702Authorization)({
|
|
2467
|
+
chainId: params.chainId,
|
|
2468
|
+
address: batchExecutor,
|
|
2469
|
+
nonce: params.delegationNonce,
|
|
2470
|
+
authSig: params.authSig
|
|
2471
|
+
});
|
|
2472
|
+
const result = await relayUserOp({
|
|
2473
|
+
client: params.pafiBackendClient,
|
|
2474
|
+
userOp: userOpJson,
|
|
2475
|
+
entryPoint: import_core12.ENTRY_POINT_V08,
|
|
2476
|
+
eip7702Auth: authorization
|
|
2477
|
+
});
|
|
2478
|
+
return {
|
|
2479
|
+
userOpHash: result.userOpHash,
|
|
2480
|
+
isSponsored: !!paymasterFields,
|
|
2481
|
+
authorization
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
// src/api/quoteHelper.ts
|
|
2486
|
+
var import_core13 = require("@pafi-dev/core");
|
|
2487
|
+
var DEFAULT_DEADLINE_SECONDS = 300;
|
|
2488
|
+
async function quotePointTokenToUsdt(params) {
|
|
2489
|
+
const now = params.now ?? (() => Date.now());
|
|
2490
|
+
const suggestedDeadline = Math.floor(now() / 1e3) + (params.deadlineSeconds ?? DEFAULT_DEADLINE_SECONDS);
|
|
2491
|
+
if (params.pointAmount === 0n) {
|
|
2492
|
+
return {
|
|
2493
|
+
estimatedUsdtOut: 0n,
|
|
2494
|
+
netUsdtOut: 0n,
|
|
2495
|
+
exchangeRate: "0.00000000",
|
|
2496
|
+
gasEstimate: 0n,
|
|
2497
|
+
suggestedDeadline
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
if (params.pools.length === 0) {
|
|
2501
|
+
return {
|
|
2502
|
+
estimatedUsdtOut: 0n,
|
|
2503
|
+
netUsdtOut: 0n,
|
|
2504
|
+
exchangeRate: "0.00000000",
|
|
2505
|
+
gasEstimate: 0n,
|
|
2506
|
+
suggestedDeadline,
|
|
2507
|
+
quoteError: "QUOTE_UNAVAILABLE"
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
const { usdt: usdtAddress } = (0, import_core13.getContractAddresses)(params.chainId);
|
|
2511
|
+
let estimatedUsdtOut = 0n;
|
|
2512
|
+
let gasEstimate = 0n;
|
|
2513
|
+
try {
|
|
2514
|
+
const best = await (0, import_core13.findBestQuote)(
|
|
2515
|
+
params.provider,
|
|
2516
|
+
params.chainId,
|
|
2517
|
+
params.pointTokenAddress,
|
|
2518
|
+
usdtAddress,
|
|
2519
|
+
params.pointAmount,
|
|
2520
|
+
params.pools
|
|
2521
|
+
);
|
|
2522
|
+
estimatedUsdtOut = best.bestRoute.amountOut;
|
|
2523
|
+
gasEstimate = best.bestRoute.gasEstimate;
|
|
2524
|
+
} catch {
|
|
2525
|
+
return {
|
|
2526
|
+
estimatedUsdtOut: 0n,
|
|
2527
|
+
netUsdtOut: 0n,
|
|
2528
|
+
exchangeRate: "0.00000000",
|
|
2529
|
+
gasEstimate: 0n,
|
|
2530
|
+
suggestedDeadline,
|
|
2531
|
+
quoteError: "QUOTE_UNAVAILABLE"
|
|
2532
|
+
};
|
|
2533
|
+
}
|
|
2534
|
+
const netUsdtOut = estimatedUsdtOut > params.gasFeeUsdt ? estimatedUsdtOut - params.gasFeeUsdt : 0n;
|
|
2535
|
+
const quoteError = estimatedUsdtOut > 0n && netUsdtOut === 0n ? "AMOUNT_TOO_SMALL_FOR_GAS" : void 0;
|
|
2536
|
+
const rateNum = estimatedUsdtOut > 0n ? Number(
|
|
2537
|
+
estimatedUsdtOut * 1000000n * 10n ** 18n / params.pointAmount
|
|
2538
|
+
) / 1e6 : 0;
|
|
2539
|
+
const exchangeRate = rateNum.toFixed(8);
|
|
2540
|
+
return {
|
|
2541
|
+
estimatedUsdtOut,
|
|
2542
|
+
netUsdtOut,
|
|
2543
|
+
exchangeRate,
|
|
2544
|
+
gasEstimate,
|
|
2545
|
+
suggestedDeadline,
|
|
2546
|
+
...quoteError ? { quoteError } : {}
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
// src/api/errorMapper.ts
|
|
2551
|
+
function createSdkErrorMapper(factories) {
|
|
2552
|
+
return (err) => {
|
|
2553
|
+
if (err instanceof PendingUserOpNotFoundError) {
|
|
2554
|
+
throw factories.notFound({
|
|
2555
|
+
code: err.code,
|
|
2556
|
+
message: err.message,
|
|
2557
|
+
safeToRetry: false
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
if (err instanceof BundlerNotConfiguredError) {
|
|
2561
|
+
throw factories.serviceUnavailable({
|
|
2562
|
+
code: err.code,
|
|
2563
|
+
message: err.message,
|
|
2564
|
+
safeToRetry: false
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
if (err instanceof IssuerStateError) {
|
|
2568
|
+
throw factories.unprocessable({
|
|
2569
|
+
code: err.code,
|
|
2570
|
+
message: err.message,
|
|
2571
|
+
details: err.details,
|
|
2572
|
+
safeToRetry: err.code === "MINT_CAP_EXCEEDED"
|
|
2573
|
+
});
|
|
2574
|
+
}
|
|
2575
|
+
if (err instanceof PerpDepositError) {
|
|
2576
|
+
throw factories.unprocessable({
|
|
2577
|
+
code: err.code,
|
|
2578
|
+
message: err.message,
|
|
2579
|
+
safeToRetry: err.code === "RELAY_FEE_EXCEEDS_AMOUNT"
|
|
2580
|
+
});
|
|
2581
|
+
}
|
|
2582
|
+
if (err instanceof PTClaimError || err instanceof PTRedeemError || err instanceof SwapError || err instanceof BundlerRejectedError) {
|
|
2583
|
+
throw factories.unprocessable({
|
|
2584
|
+
code: err.code,
|
|
2585
|
+
message: err.message,
|
|
2586
|
+
details: "details" in err ? err.details : void 0,
|
|
2587
|
+
safeToRetry: false
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
throw err;
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2412
2594
|
// src/pools/subgraphPoolsProvider.ts
|
|
2413
2595
|
var import_viem10 = require("viem");
|
|
2414
|
-
var
|
|
2596
|
+
var import_core14 = require("@pafi-dev/core");
|
|
2415
2597
|
var DEFAULT_CACHE_TTL_MS = 3e4;
|
|
2416
2598
|
var POOL_QUERY = `
|
|
2417
2599
|
query GetPoolForPointToken($id: ID!) {
|
|
@@ -2429,7 +2611,7 @@ var POOL_QUERY = `
|
|
|
2429
2611
|
}
|
|
2430
2612
|
`;
|
|
2431
2613
|
function createSubgraphPoolsProvider(config = {}) {
|
|
2432
|
-
const subgraphUrl = config.subgraphUrl ??
|
|
2614
|
+
const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
|
|
2433
2615
|
try {
|
|
2434
2616
|
const parsed = new URL(subgraphUrl);
|
|
2435
2617
|
if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
|
|
@@ -2561,7 +2743,7 @@ var PRICE_QUERY = `
|
|
|
2561
2743
|
}
|
|
2562
2744
|
`;
|
|
2563
2745
|
function createSubgraphNativeUsdtQuoter(config = {}) {
|
|
2564
|
-
const subgraphUrl = config.subgraphUrl ??
|
|
2746
|
+
const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
|
|
2565
2747
|
try {
|
|
2566
2748
|
const parsed = new URL(subgraphUrl);
|
|
2567
2749
|
if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
|
|
@@ -2691,7 +2873,7 @@ function createNativePtQuoter(config) {
|
|
|
2691
2873
|
provider,
|
|
2692
2874
|
pointTokenAddress,
|
|
2693
2875
|
chainlinkFeedAddress = "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70",
|
|
2694
|
-
subgraphUrl =
|
|
2876
|
+
subgraphUrl = import_core14.PAFI_SUBGRAPH_URL,
|
|
2695
2877
|
cacheTtlMs = 3e4,
|
|
2696
2878
|
fallbackEthPriceUsd = 3e3,
|
|
2697
2879
|
fallbackPtPriceUsdt = 0.1,
|
|
@@ -2773,7 +2955,7 @@ function parseBigDecimalTo18(s) {
|
|
|
2773
2955
|
}
|
|
2774
2956
|
|
|
2775
2957
|
// src/balance/balanceAggregator.ts
|
|
2776
|
-
var
|
|
2958
|
+
var import_core15 = require("@pafi-dev/core");
|
|
2777
2959
|
var BalanceAggregator = class {
|
|
2778
2960
|
provider;
|
|
2779
2961
|
ledger;
|
|
@@ -2794,7 +2976,7 @@ var BalanceAggregator = class {
|
|
|
2794
2976
|
async getCombinedBalance(user, pointToken) {
|
|
2795
2977
|
const [offChain, onChain] = await Promise.all([
|
|
2796
2978
|
this.ledger.getBalance(user, pointToken),
|
|
2797
|
-
(0,
|
|
2979
|
+
(0, import_core15.getPointTokenBalance)(this.provider, pointToken, user)
|
|
2798
2980
|
]);
|
|
2799
2981
|
return {
|
|
2800
2982
|
offChain,
|
|
@@ -3028,7 +3210,7 @@ var PafiBackendClient = class {
|
|
|
3028
3210
|
|
|
3029
3211
|
// src/config.ts
|
|
3030
3212
|
var import_viem12 = require("viem");
|
|
3031
|
-
var
|
|
3213
|
+
var import_core16 = require("@pafi-dev/core");
|
|
3032
3214
|
function createIssuerService(config) {
|
|
3033
3215
|
if (!config.provider) {
|
|
3034
3216
|
throw new Error("createIssuerService: provider is required");
|
|
@@ -3098,7 +3280,7 @@ function createIssuerService(config) {
|
|
|
3098
3280
|
indexers.set(tokenAddress, new PointIndexer(indexerConfig));
|
|
3099
3281
|
}
|
|
3100
3282
|
const firstIndexer = indexers.get(tokenAddresses[0]);
|
|
3101
|
-
const chainAddresses = (0,
|
|
3283
|
+
const chainAddresses = (0, import_core16.getContractAddresses)(config.chainId);
|
|
3102
3284
|
const resolvedContracts = {
|
|
3103
3285
|
batchExecutor: chainAddresses.batchExecutor,
|
|
3104
3286
|
usdt: chainAddresses.usdt,
|
|
@@ -3147,7 +3329,7 @@ function createIssuerService(config) {
|
|
|
3147
3329
|
|
|
3148
3330
|
// src/issuer-state/validator.ts
|
|
3149
3331
|
var import_viem13 = require("viem");
|
|
3150
|
-
var
|
|
3332
|
+
var import_core17 = require("@pafi-dev/core");
|
|
3151
3333
|
var ISSUER_RECORD_TTL_MS = 3e4;
|
|
3152
3334
|
var IssuerStateValidator = class _IssuerStateValidator {
|
|
3153
3335
|
constructor(provider, registryAddress) {
|
|
@@ -3164,7 +3346,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3164
3346
|
* `CONTRACT_ADDRESSES` map for the given chain.
|
|
3165
3347
|
*/
|
|
3166
3348
|
static forChain(provider, chainId) {
|
|
3167
|
-
const { issuerRegistry } = (0,
|
|
3349
|
+
const { issuerRegistry } = (0, import_core17.getContractAddresses)(chainId);
|
|
3168
3350
|
return new _IssuerStateValidator(provider, issuerRegistry);
|
|
3169
3351
|
}
|
|
3170
3352
|
/**
|
|
@@ -3193,7 +3375,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3193
3375
|
if (cached) return cached;
|
|
3194
3376
|
const issuer = await this.provider.readContract({
|
|
3195
3377
|
address: key,
|
|
3196
|
-
abi:
|
|
3378
|
+
abi: import_core17.POINT_TOKEN_V2_ABI,
|
|
3197
3379
|
functionName: "issuer"
|
|
3198
3380
|
});
|
|
3199
3381
|
this.pointTokenIssuerCache.set(key, (0, import_viem13.getAddress)(issuer));
|
|
@@ -3274,13 +3456,13 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3274
3456
|
const [issuerTuple, totalSupply] = await Promise.all([
|
|
3275
3457
|
this.provider.readContract({
|
|
3276
3458
|
address: this.registryAddress,
|
|
3277
|
-
abi:
|
|
3459
|
+
abi: import_core17.issuerRegistryGetIssuerFlatAbi,
|
|
3278
3460
|
functionName: "getIssuer",
|
|
3279
3461
|
args: [issuerAddr]
|
|
3280
3462
|
}),
|
|
3281
3463
|
this.provider.readContract({
|
|
3282
3464
|
address: tokenAddr,
|
|
3283
|
-
abi:
|
|
3465
|
+
abi: import_core17.POINT_TOKEN_V2_ABI,
|
|
3284
3466
|
functionName: "totalSupply"
|
|
3285
3467
|
})
|
|
3286
3468
|
]);
|
|
@@ -3341,14 +3523,17 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
3341
3523
|
authenticateRequest,
|
|
3342
3524
|
createIssuerService,
|
|
3343
3525
|
createNativePtQuoter,
|
|
3526
|
+
createSdkErrorMapper,
|
|
3344
3527
|
createSubgraphNativeUsdtQuoter,
|
|
3345
3528
|
createSubgraphPoolsProvider,
|
|
3346
3529
|
handleClaimStatus,
|
|
3530
|
+
handleDelegateSubmit,
|
|
3347
3531
|
handleMobilePrepare,
|
|
3348
3532
|
handleMobileSubmit,
|
|
3349
3533
|
handleRedeemStatus,
|
|
3350
3534
|
mergePaymasterFields,
|
|
3351
3535
|
prepareMobileUserOp,
|
|
3536
|
+
quotePointTokenToUsdt,
|
|
3352
3537
|
relayUserOp,
|
|
3353
3538
|
requestPaymaster,
|
|
3354
3539
|
serializeEntryToJsonRpc,
|