@pafi-dev/issuer 0.5.32 → 0.5.34
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 +287 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +462 -100
- package/dist/index.d.ts +462 -100
- package/dist/index.js +274 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,8 @@ __export(index_exports, {
|
|
|
23
23
|
AuthError: () => AuthError,
|
|
24
24
|
AuthService: () => AuthService,
|
|
25
25
|
BalanceAggregator: () => BalanceAggregator,
|
|
26
|
+
BundlerNotConfiguredError: () => BundlerNotConfiguredError,
|
|
27
|
+
BundlerRejectedError: () => BundlerRejectedError,
|
|
26
28
|
BurnIndexer: () => BurnIndexer,
|
|
27
29
|
DefaultPolicyEngine: () => DefaultPolicyEngine,
|
|
28
30
|
FeeManager: () => FeeManager,
|
|
@@ -30,6 +32,7 @@ __export(index_exports, {
|
|
|
30
32
|
IssuerApiHandlers: () => IssuerApiHandlers,
|
|
31
33
|
IssuerStateError: () => IssuerStateError,
|
|
32
34
|
IssuerStateValidator: () => IssuerStateValidator,
|
|
35
|
+
LockNotFoundError: () => LockNotFoundError,
|
|
33
36
|
MemorySessionStore: () => MemorySessionStore,
|
|
34
37
|
NonceManager: () => NonceManager,
|
|
35
38
|
PAFI_ISSUER_SDK_VERSION: () => PAFI_ISSUER_SDK_VERSION,
|
|
@@ -48,7 +51,14 @@ __export(index_exports, {
|
|
|
48
51
|
createNativePtQuoter: () => createNativePtQuoter,
|
|
49
52
|
createSubgraphNativeUsdtQuoter: () => createSubgraphNativeUsdtQuoter,
|
|
50
53
|
createSubgraphPoolsProvider: () => createSubgraphPoolsProvider,
|
|
51
|
-
|
|
54
|
+
handleClaimStatus: () => handleClaimStatus,
|
|
55
|
+
handleRedeemStatus: () => handleRedeemStatus,
|
|
56
|
+
mergePaymasterFields: () => mergePaymasterFields,
|
|
57
|
+
prepareMobileUserOp: () => prepareMobileUserOp,
|
|
58
|
+
relayUserOp: () => relayUserOp,
|
|
59
|
+
requestPaymaster: () => requestPaymaster,
|
|
60
|
+
serializeEntryToJsonRpc: () => serializeEntryToJsonRpc,
|
|
61
|
+
serializeUserOpTypedData: () => serializeUserOpTypedData
|
|
52
62
|
});
|
|
53
63
|
module.exports = __toCommonJS(index_exports);
|
|
54
64
|
|
|
@@ -1637,6 +1647,106 @@ var TopUpRedemptionHandler = class {
|
|
|
1637
1647
|
}
|
|
1638
1648
|
};
|
|
1639
1649
|
|
|
1650
|
+
// src/api/statusHandlers.ts
|
|
1651
|
+
var LockNotFoundError = class extends Error {
|
|
1652
|
+
code = "LOCK_NOT_FOUND";
|
|
1653
|
+
constructor() {
|
|
1654
|
+
super("Lock not found or does not belong to authenticated user");
|
|
1655
|
+
this.name = "LockNotFoundError";
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
async function handleClaimStatus(params) {
|
|
1659
|
+
if (!params.ledger.getMintLock) {
|
|
1660
|
+
throw new Error(
|
|
1661
|
+
"handleClaimStatus: ledger does not implement `getMintLock` \u2014 implement the optional method on `IPointLedger` or write a custom status handler."
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
const lock = await params.ledger.getMintLock(
|
|
1665
|
+
params.lockId,
|
|
1666
|
+
params.userAddress
|
|
1667
|
+
);
|
|
1668
|
+
if (!lock || lock.userAddress.toLowerCase() !== params.userAddress.toLowerCase()) {
|
|
1669
|
+
throw new LockNotFoundError();
|
|
1670
|
+
}
|
|
1671
|
+
let status = lock.status;
|
|
1672
|
+
let txHash = lock.txHash ?? null;
|
|
1673
|
+
if (status === "PENDING" && lock.userOpHash && params.pafiBackendClient) {
|
|
1674
|
+
try {
|
|
1675
|
+
const receipt = await params.pafiBackendClient.getUserOpReceipt(
|
|
1676
|
+
lock.userOpHash
|
|
1677
|
+
);
|
|
1678
|
+
if (receipt) {
|
|
1679
|
+
status = receipt.success ? "MINTED" : "FAILED";
|
|
1680
|
+
txHash = receipt.txHash;
|
|
1681
|
+
await params.ledger.updateMintStatus(lock.lockId, status, receipt.txHash).catch((err) => {
|
|
1682
|
+
params.onWarning?.(
|
|
1683
|
+
`handleClaimStatus: ledger updateMintStatus failed for lock ${lock.lockId}: ${err}`
|
|
1684
|
+
);
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
} catch (err) {
|
|
1688
|
+
params.onWarning?.(
|
|
1689
|
+
`handleClaimStatus: bundler-receipt fallback failed for lock ${lock.lockId}: ${err}`
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return {
|
|
1694
|
+
lockId: lock.lockId,
|
|
1695
|
+
status,
|
|
1696
|
+
txHash,
|
|
1697
|
+
amount: lock.amount.toString(),
|
|
1698
|
+
createdAt: new Date(lock.createdAt).toISOString(),
|
|
1699
|
+
expiresAt: new Date(lock.expiresAt).toISOString()
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
async function handleRedeemStatus(params) {
|
|
1703
|
+
if (!params.ledger.getPendingCredit) {
|
|
1704
|
+
throw new Error(
|
|
1705
|
+
"handleRedeemStatus: ledger does not implement `getPendingCredit` \u2014 implement the optional method on `IPointLedger` or write a custom status handler."
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
const credit = await params.ledger.getPendingCredit(
|
|
1709
|
+
params.lockId,
|
|
1710
|
+
params.userAddress
|
|
1711
|
+
);
|
|
1712
|
+
if (!credit || credit.userAddress.toLowerCase() !== params.userAddress.toLowerCase()) {
|
|
1713
|
+
throw new LockNotFoundError();
|
|
1714
|
+
}
|
|
1715
|
+
let status = credit.status;
|
|
1716
|
+
let txHash = credit.txHash ?? null;
|
|
1717
|
+
if (status === "PENDING" && credit.userOpHash && params.pafiBackendClient) {
|
|
1718
|
+
try {
|
|
1719
|
+
const receipt = await params.pafiBackendClient.getUserOpReceipt(
|
|
1720
|
+
credit.userOpHash
|
|
1721
|
+
);
|
|
1722
|
+
if (receipt && receipt.success) {
|
|
1723
|
+
status = "RESOLVED";
|
|
1724
|
+
txHash = receipt.txHash;
|
|
1725
|
+
if (params.ledger.resolveCreditByBurnTx) {
|
|
1726
|
+
await params.ledger.resolveCreditByBurnTx(credit.lockId, receipt.txHash).catch((err) => {
|
|
1727
|
+
params.onWarning?.(
|
|
1728
|
+
`handleRedeemStatus: resolveCreditByBurnTx failed for lock ${credit.lockId}: ${err}`
|
|
1729
|
+
);
|
|
1730
|
+
});
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
} catch (err) {
|
|
1734
|
+
params.onWarning?.(
|
|
1735
|
+
`handleRedeemStatus: bundler-receipt fallback failed for lock ${credit.lockId}: ${err}`
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
return {
|
|
1740
|
+
lockId: credit.lockId,
|
|
1741
|
+
status,
|
|
1742
|
+
txHash,
|
|
1743
|
+
amount: credit.amount.toString(),
|
|
1744
|
+
createdAt: new Date(credit.createdAt).toISOString(),
|
|
1745
|
+
expiresAt: new Date(credit.expiresAt).toISOString(),
|
|
1746
|
+
resolvedAt: credit.resolvedAt ? new Date(credit.resolvedAt).toISOString() : null
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1640
1750
|
// src/pools/subgraphPoolsProvider.ts
|
|
1641
1751
|
var import_viem9 = require("viem");
|
|
1642
1752
|
var import_core6 = require("@pafi-dev/core");
|
|
@@ -2254,6 +2364,76 @@ var PafiBackendClient = class {
|
|
|
2254
2364
|
}
|
|
2255
2365
|
};
|
|
2256
2366
|
|
|
2367
|
+
// src/pafi-backend/helpers.ts
|
|
2368
|
+
var BundlerNotConfiguredError = class extends Error {
|
|
2369
|
+
code = "BUNDLER_NOT_CONFIGURED";
|
|
2370
|
+
constructor() {
|
|
2371
|
+
super(
|
|
2372
|
+
"PAFI backend client not configured \u2014 set PAFI_BACKEND_URL, PAFI_ISSUER_ID, PAFI_API_KEY to enable mobile submit."
|
|
2373
|
+
);
|
|
2374
|
+
this.name = "BundlerNotConfiguredError";
|
|
2375
|
+
}
|
|
2376
|
+
};
|
|
2377
|
+
var BundlerRejectedError = class extends Error {
|
|
2378
|
+
code = "BUNDLER_REJECTED";
|
|
2379
|
+
cause;
|
|
2380
|
+
constructor(message, cause) {
|
|
2381
|
+
super(message);
|
|
2382
|
+
this.name = "BundlerRejectedError";
|
|
2383
|
+
this.cause = cause;
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
async function requestPaymaster(params) {
|
|
2387
|
+
if (!params.client) return void 0;
|
|
2388
|
+
const fn = params.functionName ?? defaultFunctionForScenario(params.scenario);
|
|
2389
|
+
try {
|
|
2390
|
+
return await params.client.requestSponsorship({
|
|
2391
|
+
chainId: params.chainId,
|
|
2392
|
+
scenario: params.scenario,
|
|
2393
|
+
userOp: params.userOp,
|
|
2394
|
+
target: {
|
|
2395
|
+
contract: params.pointTokenAddress,
|
|
2396
|
+
function: fn,
|
|
2397
|
+
pointToken: params.pointTokenAddress
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
} catch (err) {
|
|
2401
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2402
|
+
params.onWarning?.(`Paymaster sponsorship declined: ${msg}`);
|
|
2403
|
+
return void 0;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
function defaultFunctionForScenario(scenario) {
|
|
2407
|
+
switch (scenario) {
|
|
2408
|
+
case "mint":
|
|
2409
|
+
return "mint";
|
|
2410
|
+
case "burn":
|
|
2411
|
+
return "burn";
|
|
2412
|
+
case "swap":
|
|
2413
|
+
return "swap";
|
|
2414
|
+
case "perp-deposit":
|
|
2415
|
+
return "deposit";
|
|
2416
|
+
default:
|
|
2417
|
+
return scenario;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
async function relayUserOp(params) {
|
|
2421
|
+
if (!params.client) {
|
|
2422
|
+
throw new BundlerNotConfiguredError();
|
|
2423
|
+
}
|
|
2424
|
+
try {
|
|
2425
|
+
const result = await params.client.relayUserOperation({
|
|
2426
|
+
userOp: params.userOp,
|
|
2427
|
+
entryPoint: params.entryPoint,
|
|
2428
|
+
eip7702Auth: params.eip7702Auth
|
|
2429
|
+
});
|
|
2430
|
+
return { userOpHash: result.userOpHash };
|
|
2431
|
+
} catch (err) {
|
|
2432
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2433
|
+
throw new BundlerRejectedError(msg, err);
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2257
2437
|
// src/config.ts
|
|
2258
2438
|
var import_viem11 = require("viem");
|
|
2259
2439
|
var import_core8 = require("@pafi-dev/core");
|
|
@@ -2416,9 +2596,99 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
|
2416
2596
|
);
|
|
2417
2597
|
}
|
|
2418
2598
|
|
|
2599
|
+
// src/userop-store/prepareUserOp.ts
|
|
2600
|
+
var import_core10 = require("@pafi-dev/core");
|
|
2601
|
+
function serializeUserOpTypedData(td) {
|
|
2602
|
+
return {
|
|
2603
|
+
domain: td.domain,
|
|
2604
|
+
types: td.types,
|
|
2605
|
+
primaryType: td.primaryType,
|
|
2606
|
+
message: {
|
|
2607
|
+
sender: td.message.sender,
|
|
2608
|
+
nonce: `0x${td.message.nonce.toString(16)}`,
|
|
2609
|
+
initCode: td.message.initCode,
|
|
2610
|
+
callData: td.message.callData,
|
|
2611
|
+
accountGasLimits: td.message.accountGasLimits,
|
|
2612
|
+
preVerificationGas: `0x${td.message.preVerificationGas.toString(
|
|
2613
|
+
16
|
|
2614
|
+
)}`,
|
|
2615
|
+
gasFees: td.message.gasFees,
|
|
2616
|
+
paymasterAndData: td.message.paymasterAndData
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
}
|
|
2620
|
+
function mergePaymasterFields(userOp, paymasterFields) {
|
|
2621
|
+
if (!paymasterFields) return userOp;
|
|
2622
|
+
const merged = {
|
|
2623
|
+
...userOp
|
|
2624
|
+
};
|
|
2625
|
+
for (const [k, v] of Object.entries(paymasterFields)) {
|
|
2626
|
+
if (v !== void 0) merged[k] = v;
|
|
2627
|
+
}
|
|
2628
|
+
return merged;
|
|
2629
|
+
}
|
|
2630
|
+
async function prepareMobileUserOp(params) {
|
|
2631
|
+
const userOp = mergePaymasterFields(
|
|
2632
|
+
params.partialUserOp,
|
|
2633
|
+
params.paymasterFields
|
|
2634
|
+
);
|
|
2635
|
+
const userOpHash = (0, import_core10.computeUserOpHash)(userOp, params.chainId);
|
|
2636
|
+
const typedData = serializeUserOpTypedData(
|
|
2637
|
+
(0, import_core10.buildUserOpTypedData)(userOp, params.chainId)
|
|
2638
|
+
);
|
|
2639
|
+
let fallback;
|
|
2640
|
+
let fallbackEntry;
|
|
2641
|
+
if (params.partialUserOpFallback) {
|
|
2642
|
+
const fallbackUserOp = {
|
|
2643
|
+
...params.partialUserOpFallback,
|
|
2644
|
+
maxFeePerGas: userOp.maxFeePerGas,
|
|
2645
|
+
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas
|
|
2646
|
+
};
|
|
2647
|
+
const fallbackHash = (0, import_core10.computeUserOpHash)(fallbackUserOp, params.chainId);
|
|
2648
|
+
const fallbackTypedData = serializeUserOpTypedData(
|
|
2649
|
+
(0, import_core10.buildUserOpTypedData)(fallbackUserOp, params.chainId)
|
|
2650
|
+
);
|
|
2651
|
+
fallback = {
|
|
2652
|
+
userOp: fallbackUserOp,
|
|
2653
|
+
userOpHash: fallbackHash,
|
|
2654
|
+
typedData: fallbackTypedData
|
|
2655
|
+
};
|
|
2656
|
+
fallbackEntry = {
|
|
2657
|
+
callData: fallbackUserOp.callData,
|
|
2658
|
+
callGasLimit: fallbackUserOp.callGasLimit.toString(),
|
|
2659
|
+
verificationGasLimit: fallbackUserOp.verificationGasLimit.toString(),
|
|
2660
|
+
preVerificationGas: fallbackUserOp.preVerificationGas.toString(),
|
|
2661
|
+
userOpHash: fallbackHash
|
|
2662
|
+
};
|
|
2663
|
+
}
|
|
2664
|
+
const entry = {
|
|
2665
|
+
sender: userOp.sender,
|
|
2666
|
+
nonce: userOp.nonce.toString(),
|
|
2667
|
+
callData: userOp.callData,
|
|
2668
|
+
callGasLimit: userOp.callGasLimit.toString(),
|
|
2669
|
+
verificationGasLimit: userOp.verificationGasLimit.toString(),
|
|
2670
|
+
preVerificationGas: userOp.preVerificationGas.toString(),
|
|
2671
|
+
maxFeePerGas: userOp.maxFeePerGas.toString(),
|
|
2672
|
+
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas.toString(),
|
|
2673
|
+
paymaster: userOp.paymaster,
|
|
2674
|
+
paymasterVerificationGasLimit: userOp.paymasterVerificationGasLimit?.toString(),
|
|
2675
|
+
paymasterPostOpGasLimit: userOp.paymasterPostOpGasLimit?.toString(),
|
|
2676
|
+
paymasterData: userOp.paymasterData,
|
|
2677
|
+
chainId: params.chainId,
|
|
2678
|
+
userOpHash,
|
|
2679
|
+
fallback: fallbackEntry
|
|
2680
|
+
};
|
|
2681
|
+
await params.store.save(params.lockId, entry, params.ttlSeconds);
|
|
2682
|
+
return {
|
|
2683
|
+
sponsored: { userOp, userOpHash, typedData },
|
|
2684
|
+
fallback,
|
|
2685
|
+
entry
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2419
2689
|
// src/issuer-state/validator.ts
|
|
2420
2690
|
var import_viem12 = require("viem");
|
|
2421
|
-
var
|
|
2691
|
+
var import_core11 = require("@pafi-dev/core");
|
|
2422
2692
|
|
|
2423
2693
|
// src/issuer-state/types.ts
|
|
2424
2694
|
var IssuerStateError = class extends Error {
|
|
@@ -2449,7 +2719,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
2449
2719
|
* `CONTRACT_ADDRESSES` map for the given chain.
|
|
2450
2720
|
*/
|
|
2451
2721
|
static forChain(provider, chainId) {
|
|
2452
|
-
const { issuerRegistry } = (0,
|
|
2722
|
+
const { issuerRegistry } = (0, import_core11.getContractAddresses)(chainId);
|
|
2453
2723
|
return new _IssuerStateValidator(provider, issuerRegistry);
|
|
2454
2724
|
}
|
|
2455
2725
|
/**
|
|
@@ -2478,7 +2748,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
2478
2748
|
if (cached) return cached;
|
|
2479
2749
|
const issuer = await this.provider.readContract({
|
|
2480
2750
|
address: key,
|
|
2481
|
-
abi:
|
|
2751
|
+
abi: import_core11.POINT_TOKEN_V2_ABI,
|
|
2482
2752
|
functionName: "issuer"
|
|
2483
2753
|
});
|
|
2484
2754
|
this.pointTokenIssuerCache.set(key, (0, import_viem12.getAddress)(issuer));
|
|
@@ -2559,13 +2829,13 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
2559
2829
|
const [issuerTuple, totalSupply] = await Promise.all([
|
|
2560
2830
|
this.provider.readContract({
|
|
2561
2831
|
address: this.registryAddress,
|
|
2562
|
-
abi:
|
|
2832
|
+
abi: import_core11.issuerRegistryGetIssuerFlatAbi,
|
|
2563
2833
|
functionName: "getIssuer",
|
|
2564
2834
|
args: [issuerAddr]
|
|
2565
2835
|
}),
|
|
2566
2836
|
this.provider.readContract({
|
|
2567
2837
|
address: tokenAddr,
|
|
2568
|
-
abi:
|
|
2838
|
+
abi: import_core11.POINT_TOKEN_V2_ABI,
|
|
2569
2839
|
functionName: "totalSupply"
|
|
2570
2840
|
})
|
|
2571
2841
|
]);
|
|
@@ -2593,6 +2863,8 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
2593
2863
|
AuthError,
|
|
2594
2864
|
AuthService,
|
|
2595
2865
|
BalanceAggregator,
|
|
2866
|
+
BundlerNotConfiguredError,
|
|
2867
|
+
BundlerRejectedError,
|
|
2596
2868
|
BurnIndexer,
|
|
2597
2869
|
DefaultPolicyEngine,
|
|
2598
2870
|
FeeManager,
|
|
@@ -2600,6 +2872,7 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
2600
2872
|
IssuerApiHandlers,
|
|
2601
2873
|
IssuerStateError,
|
|
2602
2874
|
IssuerStateValidator,
|
|
2875
|
+
LockNotFoundError,
|
|
2603
2876
|
MemorySessionStore,
|
|
2604
2877
|
NonceManager,
|
|
2605
2878
|
PAFI_ISSUER_SDK_VERSION,
|
|
@@ -2618,6 +2891,13 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
2618
2891
|
createNativePtQuoter,
|
|
2619
2892
|
createSubgraphNativeUsdtQuoter,
|
|
2620
2893
|
createSubgraphPoolsProvider,
|
|
2621
|
-
|
|
2894
|
+
handleClaimStatus,
|
|
2895
|
+
handleRedeemStatus,
|
|
2896
|
+
mergePaymasterFields,
|
|
2897
|
+
prepareMobileUserOp,
|
|
2898
|
+
relayUserOp,
|
|
2899
|
+
requestPaymaster,
|
|
2900
|
+
serializeEntryToJsonRpc,
|
|
2901
|
+
serializeUserOpTypedData
|
|
2622
2902
|
});
|
|
2623
2903
|
//# sourceMappingURL=index.cjs.map
|