@pafi-dev/issuer 0.5.32 → 0.5.33
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 +209 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +383 -113
- package/dist/index.d.ts +383 -113
- package/dist/index.js +200 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ __export(index_exports, {
|
|
|
30
30
|
IssuerApiHandlers: () => IssuerApiHandlers,
|
|
31
31
|
IssuerStateError: () => IssuerStateError,
|
|
32
32
|
IssuerStateValidator: () => IssuerStateValidator,
|
|
33
|
+
LockNotFoundError: () => LockNotFoundError,
|
|
33
34
|
MemorySessionStore: () => MemorySessionStore,
|
|
34
35
|
NonceManager: () => NonceManager,
|
|
35
36
|
PAFI_ISSUER_SDK_VERSION: () => PAFI_ISSUER_SDK_VERSION,
|
|
@@ -48,7 +49,12 @@ __export(index_exports, {
|
|
|
48
49
|
createNativePtQuoter: () => createNativePtQuoter,
|
|
49
50
|
createSubgraphNativeUsdtQuoter: () => createSubgraphNativeUsdtQuoter,
|
|
50
51
|
createSubgraphPoolsProvider: () => createSubgraphPoolsProvider,
|
|
51
|
-
|
|
52
|
+
handleClaimStatus: () => handleClaimStatus,
|
|
53
|
+
handleRedeemStatus: () => handleRedeemStatus,
|
|
54
|
+
mergePaymasterFields: () => mergePaymasterFields,
|
|
55
|
+
prepareMobileUserOp: () => prepareMobileUserOp,
|
|
56
|
+
serializeEntryToJsonRpc: () => serializeEntryToJsonRpc,
|
|
57
|
+
serializeUserOpTypedData: () => serializeUserOpTypedData
|
|
52
58
|
});
|
|
53
59
|
module.exports = __toCommonJS(index_exports);
|
|
54
60
|
|
|
@@ -1637,6 +1643,106 @@ var TopUpRedemptionHandler = class {
|
|
|
1637
1643
|
}
|
|
1638
1644
|
};
|
|
1639
1645
|
|
|
1646
|
+
// src/api/statusHandlers.ts
|
|
1647
|
+
var LockNotFoundError = class extends Error {
|
|
1648
|
+
code = "LOCK_NOT_FOUND";
|
|
1649
|
+
constructor() {
|
|
1650
|
+
super("Lock not found or does not belong to authenticated user");
|
|
1651
|
+
this.name = "LockNotFoundError";
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
async function handleClaimStatus(params) {
|
|
1655
|
+
if (!params.ledger.getMintLock) {
|
|
1656
|
+
throw new Error(
|
|
1657
|
+
"handleClaimStatus: ledger does not implement `getMintLock` \u2014 implement the optional method on `IPointLedger` or write a custom status handler."
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
const lock = await params.ledger.getMintLock(
|
|
1661
|
+
params.lockId,
|
|
1662
|
+
params.userAddress
|
|
1663
|
+
);
|
|
1664
|
+
if (!lock || lock.userAddress.toLowerCase() !== params.userAddress.toLowerCase()) {
|
|
1665
|
+
throw new LockNotFoundError();
|
|
1666
|
+
}
|
|
1667
|
+
let status = lock.status;
|
|
1668
|
+
let txHash = lock.txHash ?? null;
|
|
1669
|
+
if (status === "PENDING" && lock.userOpHash && params.pafiBackendClient) {
|
|
1670
|
+
try {
|
|
1671
|
+
const receipt = await params.pafiBackendClient.getUserOpReceipt(
|
|
1672
|
+
lock.userOpHash
|
|
1673
|
+
);
|
|
1674
|
+
if (receipt) {
|
|
1675
|
+
status = receipt.success ? "MINTED" : "FAILED";
|
|
1676
|
+
txHash = receipt.txHash;
|
|
1677
|
+
await params.ledger.updateMintStatus(lock.lockId, status, receipt.txHash).catch((err) => {
|
|
1678
|
+
params.onWarning?.(
|
|
1679
|
+
`handleClaimStatus: ledger updateMintStatus failed for lock ${lock.lockId}: ${err}`
|
|
1680
|
+
);
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
} catch (err) {
|
|
1684
|
+
params.onWarning?.(
|
|
1685
|
+
`handleClaimStatus: bundler-receipt fallback failed for lock ${lock.lockId}: ${err}`
|
|
1686
|
+
);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
return {
|
|
1690
|
+
lockId: lock.lockId,
|
|
1691
|
+
status,
|
|
1692
|
+
txHash,
|
|
1693
|
+
amount: lock.amount.toString(),
|
|
1694
|
+
createdAt: new Date(lock.createdAt).toISOString(),
|
|
1695
|
+
expiresAt: new Date(lock.expiresAt).toISOString()
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
async function handleRedeemStatus(params) {
|
|
1699
|
+
if (!params.ledger.getPendingCredit) {
|
|
1700
|
+
throw new Error(
|
|
1701
|
+
"handleRedeemStatus: ledger does not implement `getPendingCredit` \u2014 implement the optional method on `IPointLedger` or write a custom status handler."
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
const credit = await params.ledger.getPendingCredit(
|
|
1705
|
+
params.lockId,
|
|
1706
|
+
params.userAddress
|
|
1707
|
+
);
|
|
1708
|
+
if (!credit || credit.userAddress.toLowerCase() !== params.userAddress.toLowerCase()) {
|
|
1709
|
+
throw new LockNotFoundError();
|
|
1710
|
+
}
|
|
1711
|
+
let status = credit.status;
|
|
1712
|
+
let txHash = credit.txHash ?? null;
|
|
1713
|
+
if (status === "PENDING" && credit.userOpHash && params.pafiBackendClient) {
|
|
1714
|
+
try {
|
|
1715
|
+
const receipt = await params.pafiBackendClient.getUserOpReceipt(
|
|
1716
|
+
credit.userOpHash
|
|
1717
|
+
);
|
|
1718
|
+
if (receipt && receipt.success) {
|
|
1719
|
+
status = "RESOLVED";
|
|
1720
|
+
txHash = receipt.txHash;
|
|
1721
|
+
if (params.ledger.resolveCreditByBurnTx) {
|
|
1722
|
+
await params.ledger.resolveCreditByBurnTx(credit.lockId, receipt.txHash).catch((err) => {
|
|
1723
|
+
params.onWarning?.(
|
|
1724
|
+
`handleRedeemStatus: resolveCreditByBurnTx failed for lock ${credit.lockId}: ${err}`
|
|
1725
|
+
);
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
} catch (err) {
|
|
1730
|
+
params.onWarning?.(
|
|
1731
|
+
`handleRedeemStatus: bundler-receipt fallback failed for lock ${credit.lockId}: ${err}`
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
return {
|
|
1736
|
+
lockId: credit.lockId,
|
|
1737
|
+
status,
|
|
1738
|
+
txHash,
|
|
1739
|
+
amount: credit.amount.toString(),
|
|
1740
|
+
createdAt: new Date(credit.createdAt).toISOString(),
|
|
1741
|
+
expiresAt: new Date(credit.expiresAt).toISOString(),
|
|
1742
|
+
resolvedAt: credit.resolvedAt ? new Date(credit.resolvedAt).toISOString() : null
|
|
1743
|
+
};
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1640
1746
|
// src/pools/subgraphPoolsProvider.ts
|
|
1641
1747
|
var import_viem9 = require("viem");
|
|
1642
1748
|
var import_core6 = require("@pafi-dev/core");
|
|
@@ -2416,9 +2522,99 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
|
2416
2522
|
);
|
|
2417
2523
|
}
|
|
2418
2524
|
|
|
2525
|
+
// src/userop-store/prepareUserOp.ts
|
|
2526
|
+
var import_core10 = require("@pafi-dev/core");
|
|
2527
|
+
function serializeUserOpTypedData(td) {
|
|
2528
|
+
return {
|
|
2529
|
+
domain: td.domain,
|
|
2530
|
+
types: td.types,
|
|
2531
|
+
primaryType: td.primaryType,
|
|
2532
|
+
message: {
|
|
2533
|
+
sender: td.message.sender,
|
|
2534
|
+
nonce: `0x${td.message.nonce.toString(16)}`,
|
|
2535
|
+
initCode: td.message.initCode,
|
|
2536
|
+
callData: td.message.callData,
|
|
2537
|
+
accountGasLimits: td.message.accountGasLimits,
|
|
2538
|
+
preVerificationGas: `0x${td.message.preVerificationGas.toString(
|
|
2539
|
+
16
|
|
2540
|
+
)}`,
|
|
2541
|
+
gasFees: td.message.gasFees,
|
|
2542
|
+
paymasterAndData: td.message.paymasterAndData
|
|
2543
|
+
}
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
function mergePaymasterFields(userOp, paymasterFields) {
|
|
2547
|
+
if (!paymasterFields) return userOp;
|
|
2548
|
+
const merged = {
|
|
2549
|
+
...userOp
|
|
2550
|
+
};
|
|
2551
|
+
for (const [k, v] of Object.entries(paymasterFields)) {
|
|
2552
|
+
if (v !== void 0) merged[k] = v;
|
|
2553
|
+
}
|
|
2554
|
+
return merged;
|
|
2555
|
+
}
|
|
2556
|
+
async function prepareMobileUserOp(params) {
|
|
2557
|
+
const userOp = mergePaymasterFields(
|
|
2558
|
+
params.partialUserOp,
|
|
2559
|
+
params.paymasterFields
|
|
2560
|
+
);
|
|
2561
|
+
const userOpHash = (0, import_core10.computeUserOpHash)(userOp, params.chainId);
|
|
2562
|
+
const typedData = serializeUserOpTypedData(
|
|
2563
|
+
(0, import_core10.buildUserOpTypedData)(userOp, params.chainId)
|
|
2564
|
+
);
|
|
2565
|
+
let fallback;
|
|
2566
|
+
let fallbackEntry;
|
|
2567
|
+
if (params.partialUserOpFallback) {
|
|
2568
|
+
const fallbackUserOp = {
|
|
2569
|
+
...params.partialUserOpFallback,
|
|
2570
|
+
maxFeePerGas: userOp.maxFeePerGas,
|
|
2571
|
+
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas
|
|
2572
|
+
};
|
|
2573
|
+
const fallbackHash = (0, import_core10.computeUserOpHash)(fallbackUserOp, params.chainId);
|
|
2574
|
+
const fallbackTypedData = serializeUserOpTypedData(
|
|
2575
|
+
(0, import_core10.buildUserOpTypedData)(fallbackUserOp, params.chainId)
|
|
2576
|
+
);
|
|
2577
|
+
fallback = {
|
|
2578
|
+
userOp: fallbackUserOp,
|
|
2579
|
+
userOpHash: fallbackHash,
|
|
2580
|
+
typedData: fallbackTypedData
|
|
2581
|
+
};
|
|
2582
|
+
fallbackEntry = {
|
|
2583
|
+
callData: fallbackUserOp.callData,
|
|
2584
|
+
callGasLimit: fallbackUserOp.callGasLimit.toString(),
|
|
2585
|
+
verificationGasLimit: fallbackUserOp.verificationGasLimit.toString(),
|
|
2586
|
+
preVerificationGas: fallbackUserOp.preVerificationGas.toString(),
|
|
2587
|
+
userOpHash: fallbackHash
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
const entry = {
|
|
2591
|
+
sender: userOp.sender,
|
|
2592
|
+
nonce: userOp.nonce.toString(),
|
|
2593
|
+
callData: userOp.callData,
|
|
2594
|
+
callGasLimit: userOp.callGasLimit.toString(),
|
|
2595
|
+
verificationGasLimit: userOp.verificationGasLimit.toString(),
|
|
2596
|
+
preVerificationGas: userOp.preVerificationGas.toString(),
|
|
2597
|
+
maxFeePerGas: userOp.maxFeePerGas.toString(),
|
|
2598
|
+
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas.toString(),
|
|
2599
|
+
paymaster: userOp.paymaster,
|
|
2600
|
+
paymasterVerificationGasLimit: userOp.paymasterVerificationGasLimit?.toString(),
|
|
2601
|
+
paymasterPostOpGasLimit: userOp.paymasterPostOpGasLimit?.toString(),
|
|
2602
|
+
paymasterData: userOp.paymasterData,
|
|
2603
|
+
chainId: params.chainId,
|
|
2604
|
+
userOpHash,
|
|
2605
|
+
fallback: fallbackEntry
|
|
2606
|
+
};
|
|
2607
|
+
await params.store.save(params.lockId, entry, params.ttlSeconds);
|
|
2608
|
+
return {
|
|
2609
|
+
sponsored: { userOp, userOpHash, typedData },
|
|
2610
|
+
fallback,
|
|
2611
|
+
entry
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2419
2615
|
// src/issuer-state/validator.ts
|
|
2420
2616
|
var import_viem12 = require("viem");
|
|
2421
|
-
var
|
|
2617
|
+
var import_core11 = require("@pafi-dev/core");
|
|
2422
2618
|
|
|
2423
2619
|
// src/issuer-state/types.ts
|
|
2424
2620
|
var IssuerStateError = class extends Error {
|
|
@@ -2449,7 +2645,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
2449
2645
|
* `CONTRACT_ADDRESSES` map for the given chain.
|
|
2450
2646
|
*/
|
|
2451
2647
|
static forChain(provider, chainId) {
|
|
2452
|
-
const { issuerRegistry } = (0,
|
|
2648
|
+
const { issuerRegistry } = (0, import_core11.getContractAddresses)(chainId);
|
|
2453
2649
|
return new _IssuerStateValidator(provider, issuerRegistry);
|
|
2454
2650
|
}
|
|
2455
2651
|
/**
|
|
@@ -2478,7 +2674,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
2478
2674
|
if (cached) return cached;
|
|
2479
2675
|
const issuer = await this.provider.readContract({
|
|
2480
2676
|
address: key,
|
|
2481
|
-
abi:
|
|
2677
|
+
abi: import_core11.POINT_TOKEN_V2_ABI,
|
|
2482
2678
|
functionName: "issuer"
|
|
2483
2679
|
});
|
|
2484
2680
|
this.pointTokenIssuerCache.set(key, (0, import_viem12.getAddress)(issuer));
|
|
@@ -2559,13 +2755,13 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
2559
2755
|
const [issuerTuple, totalSupply] = await Promise.all([
|
|
2560
2756
|
this.provider.readContract({
|
|
2561
2757
|
address: this.registryAddress,
|
|
2562
|
-
abi:
|
|
2758
|
+
abi: import_core11.issuerRegistryGetIssuerFlatAbi,
|
|
2563
2759
|
functionName: "getIssuer",
|
|
2564
2760
|
args: [issuerAddr]
|
|
2565
2761
|
}),
|
|
2566
2762
|
this.provider.readContract({
|
|
2567
2763
|
address: tokenAddr,
|
|
2568
|
-
abi:
|
|
2764
|
+
abi: import_core11.POINT_TOKEN_V2_ABI,
|
|
2569
2765
|
functionName: "totalSupply"
|
|
2570
2766
|
})
|
|
2571
2767
|
]);
|
|
@@ -2600,6 +2796,7 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
2600
2796
|
IssuerApiHandlers,
|
|
2601
2797
|
IssuerStateError,
|
|
2602
2798
|
IssuerStateValidator,
|
|
2799
|
+
LockNotFoundError,
|
|
2603
2800
|
MemorySessionStore,
|
|
2604
2801
|
NonceManager,
|
|
2605
2802
|
PAFI_ISSUER_SDK_VERSION,
|
|
@@ -2618,6 +2815,11 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
2618
2815
|
createNativePtQuoter,
|
|
2619
2816
|
createSubgraphNativeUsdtQuoter,
|
|
2620
2817
|
createSubgraphPoolsProvider,
|
|
2621
|
-
|
|
2818
|
+
handleClaimStatus,
|
|
2819
|
+
handleRedeemStatus,
|
|
2820
|
+
mergePaymasterFields,
|
|
2821
|
+
prepareMobileUserOp,
|
|
2822
|
+
serializeEntryToJsonRpc,
|
|
2823
|
+
serializeUserOpTypedData
|
|
2622
2824
|
});
|
|
2623
2825
|
//# sourceMappingURL=index.cjs.map
|