@pafi-dev/issuer 0.3.0-beta.4 → 0.3.0-beta.6
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 +21 -479
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -331
- package/dist/index.d.ts +52 -331
- package/dist/index.js +6 -468
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -30,8 +30,6 @@ __export(index_exports, {
|
|
|
30
30
|
IssuerApiHandlers: () => IssuerApiHandlers,
|
|
31
31
|
MemoryPointLedger: () => MemoryPointLedger,
|
|
32
32
|
MemorySessionStore: () => MemorySessionStore,
|
|
33
|
-
MintingGateway: () => MintingGateway,
|
|
34
|
-
MintingGatewayError: () => MintingGatewayError,
|
|
35
33
|
NonceManager: () => NonceManager,
|
|
36
34
|
PAFI_ISSUER_SDK_VERSION: () => PAFI_ISSUER_SDK_VERSION,
|
|
37
35
|
PTRedeemError: () => PTRedeemError,
|
|
@@ -47,8 +45,7 @@ __export(index_exports, {
|
|
|
47
45
|
authenticateRequest: () => authenticateRequest,
|
|
48
46
|
createIssuerService: () => createIssuerService,
|
|
49
47
|
createSubgraphNativeUsdtQuoter: () => createSubgraphNativeUsdtQuoter,
|
|
50
|
-
createSubgraphPoolsProvider: () => createSubgraphPoolsProvider
|
|
51
|
-
encodeExtData: () => import_core4.encodeExtData
|
|
48
|
+
createSubgraphPoolsProvider: () => createSubgraphPoolsProvider
|
|
52
49
|
});
|
|
53
50
|
module.exports = __toCommonJS(index_exports);
|
|
54
51
|
|
|
@@ -636,137 +633,10 @@ var RelayError = class extends Error {
|
|
|
636
633
|
// src/relay/relayService.ts
|
|
637
634
|
var import_viem5 = require("viem");
|
|
638
635
|
var import_core3 = require("@pafi-dev/core");
|
|
639
|
-
var DEFAULT_CONFIRMATION_TIMEOUT_MS = 6e4;
|
|
640
636
|
var RelayService = class {
|
|
641
|
-
relayAddress;
|
|
642
|
-
operatorWallet;
|
|
643
|
-
provider;
|
|
644
|
-
confirmationTimeoutMs;
|
|
645
|
-
simulateBeforeSubmit;
|
|
646
|
-
constructor(config) {
|
|
647
|
-
if (!config.relayAddress) {
|
|
648
|
-
throw new Error("RelayService: relayAddress is required");
|
|
649
|
-
}
|
|
650
|
-
if (!config.operatorWallet) {
|
|
651
|
-
throw new Error("RelayService: operatorWallet is required");
|
|
652
|
-
}
|
|
653
|
-
this.relayAddress = config.relayAddress;
|
|
654
|
-
this.operatorWallet = config.operatorWallet;
|
|
655
|
-
if (config.provider) this.provider = config.provider;
|
|
656
|
-
this.confirmationTimeoutMs = config.confirmationTimeoutMs ?? DEFAULT_CONFIRMATION_TIMEOUT_MS;
|
|
657
|
-
this.simulateBeforeSubmit = config.simulateBeforeSubmit ?? config.provider !== void 0;
|
|
658
|
-
}
|
|
659
|
-
/** Address the operator wallet is broadcasting from (for logging). */
|
|
660
|
-
operatorAddress() {
|
|
661
|
-
return this.operatorWallet.account?.address;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* Build calldata for the Relay `mintAndSwap` function. Kept public so
|
|
665
|
-
* callers (e.g. the MintingGateway) can log or persist the encoded call
|
|
666
|
-
* for audit before broadcasting.
|
|
667
|
-
*/
|
|
668
|
-
encodeCall(params) {
|
|
669
|
-
try {
|
|
670
|
-
return (0, import_core3.encodeMintAndSwap)(params.mint, params.swap);
|
|
671
|
-
} catch (err) {
|
|
672
|
-
throw new RelayError(
|
|
673
|
-
"ENCODE_FAILED",
|
|
674
|
-
`Failed to encode mintAndSwap calldata: ${errorMessage(err)}`,
|
|
675
|
-
err
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
/**
|
|
680
|
-
* Submit a `mintAndSwap` transaction (legacy v0.2 `/claim-and-swap`).
|
|
681
|
-
*
|
|
682
|
-
* @deprecated Since 0.3.0 — replaced by `prepareMint` / `prepareBurn`
|
|
683
|
-
* in the v1.4 sponsored-UserOp flow. Kept for v0.2.x consumers;
|
|
684
|
-
* scheduled removal in 2.0.
|
|
685
|
-
*/
|
|
686
|
-
async submitMintAndSwap(params) {
|
|
687
|
-
if (this.simulateBeforeSubmit && this.provider) {
|
|
688
|
-
const operatorAddr = this.operatorWallet.account?.address;
|
|
689
|
-
if (operatorAddr) {
|
|
690
|
-
try {
|
|
691
|
-
await (0, import_core3.simulateMintAndSwap)(
|
|
692
|
-
this.provider,
|
|
693
|
-
this.relayAddress,
|
|
694
|
-
params.mint,
|
|
695
|
-
params.swap,
|
|
696
|
-
operatorAddr
|
|
697
|
-
);
|
|
698
|
-
} catch (err) {
|
|
699
|
-
const reason = err instanceof import_core3.SimulationError ? err.reason : errorMessage(err);
|
|
700
|
-
throw new RelayError(
|
|
701
|
-
"SIMULATION_FAILED",
|
|
702
|
-
`mintAndSwap would revert: ${reason}`,
|
|
703
|
-
err
|
|
704
|
-
);
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
let txHash;
|
|
709
|
-
try {
|
|
710
|
-
txHash = await this.operatorWallet.writeContract({
|
|
711
|
-
address: this.relayAddress,
|
|
712
|
-
abi: import_core3.relayAbi,
|
|
713
|
-
functionName: "mintAndSwap",
|
|
714
|
-
args: [params.mint, params.swap],
|
|
715
|
-
...this.operatorWallet.account ? { account: this.operatorWallet.account } : {}
|
|
716
|
-
});
|
|
717
|
-
} catch (err) {
|
|
718
|
-
throw new RelayError(
|
|
719
|
-
"SUBMIT_FAILED",
|
|
720
|
-
`Failed to broadcast mintAndSwap: ${errorMessage(err)}`,
|
|
721
|
-
err
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
if (!this.provider) {
|
|
725
|
-
return { txHash };
|
|
726
|
-
}
|
|
727
|
-
try {
|
|
728
|
-
const receipt = await this.provider.waitForTransactionReceipt({
|
|
729
|
-
hash: txHash,
|
|
730
|
-
timeout: this.confirmationTimeoutMs
|
|
731
|
-
});
|
|
732
|
-
if (receipt.status !== "success") {
|
|
733
|
-
throw new RelayError(
|
|
734
|
-
"TX_REVERTED",
|
|
735
|
-
`mintAndSwap reverted on-chain (tx=${txHash})`
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
return {
|
|
739
|
-
txHash,
|
|
740
|
-
blockNumber: receipt.blockNumber,
|
|
741
|
-
gasUsed: receipt.gasUsed,
|
|
742
|
-
status: receipt.status
|
|
743
|
-
};
|
|
744
|
-
} catch (err) {
|
|
745
|
-
if (err instanceof RelayError) throw err;
|
|
746
|
-
throw new RelayError(
|
|
747
|
-
"TIMEOUT",
|
|
748
|
-
`Timed out waiting for mintAndSwap receipt (tx=${txHash}): ${errorMessage(err)}`,
|
|
749
|
-
err
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
// ==========================================================================
|
|
754
|
-
// v1.4 — Sponsored UserOp preparation (sig-gated mint + burn)
|
|
755
|
-
// ==========================================================================
|
|
756
637
|
/**
|
|
757
638
|
* Build an unsigned UserOp for Scenario 1 (Mint) — sig-gated
|
|
758
639
|
* `PointToken.mint(to, amount, deadline, minterSig)`.
|
|
759
|
-
*
|
|
760
|
-
* Flow:
|
|
761
|
-
* 1. Issuer backend signs `MintRequest(to=user, amount, nonce, deadline)`
|
|
762
|
-
* with its minter signer (HSM/KMS) → `minterSig`.
|
|
763
|
-
* 2. Encode `PointToken.mint(user, amount, deadline, minterSig)`.
|
|
764
|
-
* On-chain, `msg.sender` must equal `to` — satisfied by EIP-7702
|
|
765
|
-
* delegating the user EOA to BatchExecutor.
|
|
766
|
-
* 3. Optional PT fee transfer appended after mint (application-level
|
|
767
|
-
* fee recovery since Relayer v2 no longer exists).
|
|
768
|
-
* 4. Return `PartialUserOperation` ready for Bundler gas estimate +
|
|
769
|
-
* Paymaster sponsorship + user signature.
|
|
770
640
|
*/
|
|
771
641
|
async prepareMint(params) {
|
|
772
642
|
if (!params.batchExecutorAddress) {
|
|
@@ -870,12 +740,11 @@ var RelayService = class {
|
|
|
870
740
|
*
|
|
871
741
|
* Two modes:
|
|
872
742
|
* - `mode: 'burn'` — direct `PointToken.burn(from, amount)`; only
|
|
873
|
-
* usable if the
|
|
874
|
-
* v1.4
|
|
743
|
+
* usable if the caller (via EIP-7702) is whitelisted as a burner.
|
|
744
|
+
* Rare in v1.4; kept for admin/operator tools.
|
|
875
745
|
* - `mode: 'burnWithSig'` — `PointToken.burn(from, amount, deadline,
|
|
876
|
-
* burnerSig)`.
|
|
877
|
-
*
|
|
878
|
-
* the user-initiated redeem path in v1.4.
|
|
746
|
+
* burnerSig)`. Caller provides a pre-signed `BurnRequest` + sig
|
|
747
|
+
* bytes (typically from `PTRedeemHandler`).
|
|
879
748
|
*/
|
|
880
749
|
prepareBurn(params) {
|
|
881
750
|
if (!params.pointTokenAddress) {
|
|
@@ -977,252 +846,6 @@ var FeeManager = class {
|
|
|
977
846
|
}
|
|
978
847
|
};
|
|
979
848
|
|
|
980
|
-
// src/gateway/types.ts
|
|
981
|
-
var MintingGatewayError = class extends Error {
|
|
982
|
-
code;
|
|
983
|
-
/**
|
|
984
|
-
* True if the ledger lock was released before this error was thrown,
|
|
985
|
-
* meaning the user can safely retry. False means the funds are still
|
|
986
|
-
* locked (e.g. tx may still land on-chain) and retry would double-spend.
|
|
987
|
-
*/
|
|
988
|
-
safeToRetry;
|
|
989
|
-
cause;
|
|
990
|
-
constructor(code, message, opts) {
|
|
991
|
-
super(message);
|
|
992
|
-
this.name = "MintingGatewayError";
|
|
993
|
-
this.code = code;
|
|
994
|
-
this.safeToRetry = opts.safeToRetry;
|
|
995
|
-
if (opts.cause !== void 0) this.cause = opts.cause;
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
// src/gateway/mintingGateway.ts
|
|
1000
|
-
var import_core4 = require("@pafi-dev/core");
|
|
1001
|
-
var DEFAULT_LOCK_BUFFER_MS = 6e4;
|
|
1002
|
-
var MintingGateway = class {
|
|
1003
|
-
ledger;
|
|
1004
|
-
policy;
|
|
1005
|
-
signer;
|
|
1006
|
-
relayService;
|
|
1007
|
-
now;
|
|
1008
|
-
defaultLockBufferMs;
|
|
1009
|
-
constructor(config) {
|
|
1010
|
-
if (!config.ledger) throw new Error("MintingGateway: ledger required");
|
|
1011
|
-
if (!config.policy) throw new Error("MintingGateway: policy required");
|
|
1012
|
-
if (!config.signer) throw new Error("MintingGateway: signer required");
|
|
1013
|
-
if (!config.relayService)
|
|
1014
|
-
throw new Error("MintingGateway: relayService required");
|
|
1015
|
-
this.ledger = config.ledger;
|
|
1016
|
-
this.policy = config.policy;
|
|
1017
|
-
this.signer = config.signer;
|
|
1018
|
-
this.relayService = config.relayService;
|
|
1019
|
-
this.now = config.now ?? (() => Date.now());
|
|
1020
|
-
this.defaultLockBufferMs = config.defaultLockBufferMs ?? DEFAULT_LOCK_BUFFER_MS;
|
|
1021
|
-
}
|
|
1022
|
-
/**
|
|
1023
|
-
* @deprecated Since 0.3.0 — will be renamed to `processMint()` once
|
|
1024
|
-
* the SC team finalizes Relayer v2 ABI. The new flow drops the
|
|
1025
|
-
* swap steps entirely (no more single-call mint+swap); users swap
|
|
1026
|
-
* separately on PAFI Web. Kept here for v0.2.x consumers. Removed in 2.0.
|
|
1027
|
-
*/
|
|
1028
|
-
async processMintAndCashOut(request) {
|
|
1029
|
-
const { receiverConsent, receiverSignature } = request;
|
|
1030
|
-
if (!receiverConsent || !receiverSignature) {
|
|
1031
|
-
throw new MintingGatewayError(
|
|
1032
|
-
"INVALID_REQUEST",
|
|
1033
|
-
"receiverConsent and receiverSignature are required",
|
|
1034
|
-
{ safeToRetry: true }
|
|
1035
|
-
);
|
|
1036
|
-
}
|
|
1037
|
-
if (receiverConsent.amount <= 0n) {
|
|
1038
|
-
throw new MintingGatewayError(
|
|
1039
|
-
"INVALID_REQUEST",
|
|
1040
|
-
"consent amount must be positive",
|
|
1041
|
-
{ safeToRetry: true }
|
|
1042
|
-
);
|
|
1043
|
-
}
|
|
1044
|
-
if (receiverConsent.originalReceiver !== request.userAddress) {
|
|
1045
|
-
throw new MintingGatewayError(
|
|
1046
|
-
"INVALID_REQUEST",
|
|
1047
|
-
"consent.originalReceiver must equal request.userAddress",
|
|
1048
|
-
{ safeToRetry: true }
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
const nowSec = BigInt(Math.floor(this.now() / 1e3));
|
|
1052
|
-
if (receiverConsent.deadline <= nowSec) {
|
|
1053
|
-
throw new MintingGatewayError(
|
|
1054
|
-
"CONSENT_EXPIRED",
|
|
1055
|
-
"ReceiverConsent deadline has already passed",
|
|
1056
|
-
{ safeToRetry: true }
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1059
|
-
const consentResult = await (0, import_core4.verifyReceiverConsent)(
|
|
1060
|
-
request.domain,
|
|
1061
|
-
receiverConsent,
|
|
1062
|
-
receiverSignature,
|
|
1063
|
-
request.userAddress
|
|
1064
|
-
);
|
|
1065
|
-
if (!consentResult.isValid) {
|
|
1066
|
-
throw new MintingGatewayError(
|
|
1067
|
-
"INVALID_CONSENT_SIGNATURE",
|
|
1068
|
-
`ReceiverConsent signature did not recover to ${request.userAddress}`,
|
|
1069
|
-
{ safeToRetry: true }
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
const policyDecision = await this.policy.evaluate({
|
|
1073
|
-
userAddress: request.userAddress,
|
|
1074
|
-
amount: receiverConsent.amount,
|
|
1075
|
-
pointTokenAddress: request.pointTokenAddress,
|
|
1076
|
-
chainId: request.chainId
|
|
1077
|
-
});
|
|
1078
|
-
if (!policyDecision.approved) {
|
|
1079
|
-
const code = policyDecision.reason?.toLowerCase().includes("insufficient") ? "INSUFFICIENT_BALANCE" : "POLICY_REJECTED";
|
|
1080
|
-
throw new MintingGatewayError(
|
|
1081
|
-
code,
|
|
1082
|
-
policyDecision.reason ?? "Minting request rejected by policy engine",
|
|
1083
|
-
{ safeToRetry: true }
|
|
1084
|
-
);
|
|
1085
|
-
}
|
|
1086
|
-
const lockDurationMs = request.lockDurationMs ?? this.computeLockDurationMs(receiverConsent.deadline);
|
|
1087
|
-
let lockId;
|
|
1088
|
-
try {
|
|
1089
|
-
lockId = await this.ledger.lockForMinting(
|
|
1090
|
-
request.userAddress,
|
|
1091
|
-
receiverConsent.amount,
|
|
1092
|
-
lockDurationMs,
|
|
1093
|
-
request.pointTokenAddress
|
|
1094
|
-
);
|
|
1095
|
-
} catch (err) {
|
|
1096
|
-
throw new MintingGatewayError(
|
|
1097
|
-
"INSUFFICIENT_BALANCE",
|
|
1098
|
-
`Failed to lock ledger balance: ${errorMessage2(err)}`,
|
|
1099
|
-
{ safeToRetry: true, cause: err }
|
|
1100
|
-
);
|
|
1101
|
-
}
|
|
1102
|
-
try {
|
|
1103
|
-
let minterSignature;
|
|
1104
|
-
try {
|
|
1105
|
-
minterSignature = await this.signer.signMintRequest(request.domain, {
|
|
1106
|
-
to: request.userAddress,
|
|
1107
|
-
amount: receiverConsent.amount,
|
|
1108
|
-
nonce: receiverConsent.nonce,
|
|
1109
|
-
deadline: receiverConsent.deadline
|
|
1110
|
-
});
|
|
1111
|
-
} catch (err) {
|
|
1112
|
-
await this.releaseLockSafely(lockId);
|
|
1113
|
-
throw new MintingGatewayError(
|
|
1114
|
-
"SIGNER_FAILED",
|
|
1115
|
-
`Issuer signer failed: ${errorMessage2(err)}`,
|
|
1116
|
-
{ safeToRetry: true, cause: err }
|
|
1117
|
-
);
|
|
1118
|
-
}
|
|
1119
|
-
const mintParams = {
|
|
1120
|
-
pointToken: request.pointTokenAddress,
|
|
1121
|
-
receiver: request.userAddress,
|
|
1122
|
-
amount: receiverConsent.amount,
|
|
1123
|
-
deadline: receiverConsent.deadline,
|
|
1124
|
-
minterSig: minterSignature.serialized,
|
|
1125
|
-
receiverSig: receiverSignature,
|
|
1126
|
-
extData: receiverConsent.extData
|
|
1127
|
-
};
|
|
1128
|
-
const swapParams = {
|
|
1129
|
-
path: request.swapPath,
|
|
1130
|
-
deadline: request.swapDeadline
|
|
1131
|
-
};
|
|
1132
|
-
let relayResult;
|
|
1133
|
-
try {
|
|
1134
|
-
relayResult = await this.relayService.submitMintAndSwap({
|
|
1135
|
-
mint: mintParams,
|
|
1136
|
-
swap: swapParams
|
|
1137
|
-
});
|
|
1138
|
-
} catch (err) {
|
|
1139
|
-
await this.handleRelayFailure(err, lockId);
|
|
1140
|
-
}
|
|
1141
|
-
const result = {
|
|
1142
|
-
txHash: relayResult.txHash,
|
|
1143
|
-
lockId
|
|
1144
|
-
};
|
|
1145
|
-
if (relayResult.blockNumber !== void 0) {
|
|
1146
|
-
result.blockNumber = relayResult.blockNumber;
|
|
1147
|
-
}
|
|
1148
|
-
if (relayResult.gasUsed !== void 0) {
|
|
1149
|
-
result.gasUsed = relayResult.gasUsed;
|
|
1150
|
-
}
|
|
1151
|
-
return result;
|
|
1152
|
-
} catch (err) {
|
|
1153
|
-
if (err instanceof MintingGatewayError) throw err;
|
|
1154
|
-
await this.releaseLockSafely(lockId);
|
|
1155
|
-
throw new MintingGatewayError(
|
|
1156
|
-
"RELAY_SUBMIT_FAILED",
|
|
1157
|
-
`Unexpected error: ${errorMessage2(err)}`,
|
|
1158
|
-
{ safeToRetry: true, cause: err }
|
|
1159
|
-
);
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
// ---------------------------------------------------------------------------
|
|
1163
|
-
// Internals
|
|
1164
|
-
// ---------------------------------------------------------------------------
|
|
1165
|
-
computeLockDurationMs(consentDeadlineSec) {
|
|
1166
|
-
const nowMs = this.now();
|
|
1167
|
-
const deadlineMs = Number(consentDeadlineSec) * 1e3;
|
|
1168
|
-
const remaining = Math.max(0, deadlineMs - nowMs);
|
|
1169
|
-
return remaining + this.defaultLockBufferMs;
|
|
1170
|
-
}
|
|
1171
|
-
/**
|
|
1172
|
-
* Map a RelayError to a MintingGatewayError, releasing the lock only
|
|
1173
|
-
* when the tx definitely did not land. `TX_REVERTED` and `TIMEOUT`
|
|
1174
|
-
* leave the lock in place because the tx may still be in the mempool
|
|
1175
|
-
* or already mined — releasing would enable a double-spend on retry.
|
|
1176
|
-
* Always throws.
|
|
1177
|
-
*/
|
|
1178
|
-
async handleRelayFailure(err, lockId) {
|
|
1179
|
-
if (err instanceof RelayError) {
|
|
1180
|
-
switch (err.code) {
|
|
1181
|
-
case "ENCODE_FAILED":
|
|
1182
|
-
case "SIMULATION_FAILED":
|
|
1183
|
-
case "SUBMIT_FAILED":
|
|
1184
|
-
case "NOT_CONFIGURED":
|
|
1185
|
-
await this.releaseLockSafely(lockId);
|
|
1186
|
-
throw new MintingGatewayError(
|
|
1187
|
-
err.code === "SIMULATION_FAILED" ? "RELAY_SIMULATION_FAILED" : "RELAY_SUBMIT_FAILED",
|
|
1188
|
-
err.message,
|
|
1189
|
-
{ safeToRetry: true, cause: err }
|
|
1190
|
-
);
|
|
1191
|
-
case "TX_REVERTED":
|
|
1192
|
-
throw new MintingGatewayError("RELAY_REVERTED", err.message, {
|
|
1193
|
-
safeToRetry: false,
|
|
1194
|
-
cause: err
|
|
1195
|
-
});
|
|
1196
|
-
case "TIMEOUT":
|
|
1197
|
-
throw new MintingGatewayError("RELAY_TIMEOUT", err.message, {
|
|
1198
|
-
safeToRetry: false,
|
|
1199
|
-
cause: err
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
await this.releaseLockSafely(lockId);
|
|
1204
|
-
throw new MintingGatewayError(
|
|
1205
|
-
"RELAY_SUBMIT_FAILED",
|
|
1206
|
-
`Unexpected relay error: ${errorMessage2(err)}`,
|
|
1207
|
-
{ safeToRetry: true, cause: err }
|
|
1208
|
-
);
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* Release a lock, swallowing any secondary error. We never want a lock
|
|
1212
|
-
* release failure to mask the original error — the lock will auto-expire
|
|
1213
|
-
* via TTL anyway.
|
|
1214
|
-
*/
|
|
1215
|
-
async releaseLockSafely(lockId) {
|
|
1216
|
-
try {
|
|
1217
|
-
await this.ledger.releaseLock(lockId);
|
|
1218
|
-
} catch {
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1222
|
-
function errorMessage2(err) {
|
|
1223
|
-
return err instanceof Error ? err.message : String(err);
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
849
|
// src/indexer/types.ts
|
|
1227
850
|
var InMemoryCursorStore = class {
|
|
1228
851
|
cursor;
|
|
@@ -1567,10 +1190,9 @@ var BurnIndexer = class {
|
|
|
1567
1190
|
|
|
1568
1191
|
// src/api/handlers.ts
|
|
1569
1192
|
var import_viem8 = require("viem");
|
|
1570
|
-
var
|
|
1193
|
+
var import_core4 = require("@pafi-dev/core");
|
|
1571
1194
|
var IssuerApiHandlers = class {
|
|
1572
1195
|
authService;
|
|
1573
|
-
gateway;
|
|
1574
1196
|
ledger;
|
|
1575
1197
|
provider;
|
|
1576
1198
|
/**
|
|
@@ -1589,7 +1211,6 @@ var IssuerApiHandlers = class {
|
|
|
1589
1211
|
poolsProvider;
|
|
1590
1212
|
constructor(config) {
|
|
1591
1213
|
this.authService = config.authService;
|
|
1592
|
-
this.gateway = config.gateway;
|
|
1593
1214
|
this.ledger = config.ledger;
|
|
1594
1215
|
this.provider = config.provider;
|
|
1595
1216
|
const raw = config.pointTokenAddresses && config.pointTokenAddresses.length > 0 ? config.pointTokenAddresses : config.pointTokenAddress ? [config.pointTokenAddress] : [];
|
|
@@ -1713,11 +1334,11 @@ var IssuerApiHandlers = class {
|
|
|
1713
1334
|
);
|
|
1714
1335
|
}
|
|
1715
1336
|
const [mintRequestNonce, receiverConsentNonce, offChainBalance, onChainBalance, minter] = await Promise.all([
|
|
1716
|
-
(0,
|
|
1717
|
-
(0,
|
|
1337
|
+
(0, import_core4.getMintRequestNonce)(this.provider, pointToken, normalizedAuthed),
|
|
1338
|
+
(0, import_core4.getReceiverConsentNonce)(this.provider, pointToken, normalizedAuthed),
|
|
1718
1339
|
this.ledger.getBalance(normalizedAuthed, pointToken),
|
|
1719
|
-
(0,
|
|
1720
|
-
(0,
|
|
1340
|
+
(0, import_core4.getPointTokenBalance)(this.provider, pointToken, normalizedAuthed),
|
|
1341
|
+
(0, import_core4.isMinter)(this.provider, pointToken, normalizedAuthed)
|
|
1721
1342
|
]);
|
|
1722
1343
|
return {
|
|
1723
1344
|
mintRequestNonce,
|
|
@@ -1755,13 +1376,13 @@ var IssuerApiHandlers = class {
|
|
|
1755
1376
|
`handleBuildConsentTypedData: unsupported pointToken ${pointToken}`
|
|
1756
1377
|
);
|
|
1757
1378
|
}
|
|
1758
|
-
const name = await (0,
|
|
1379
|
+
const name = await (0, import_core4.getTokenName)(this.provider, pointToken);
|
|
1759
1380
|
const domain = {
|
|
1760
1381
|
name,
|
|
1761
1382
|
verifyingContract: pointToken,
|
|
1762
1383
|
chainId: this.chainId
|
|
1763
1384
|
};
|
|
1764
|
-
const typedData = (0,
|
|
1385
|
+
const typedData = (0, import_core4.buildReceiverConsentTypedData)(domain, request.receiverConsent);
|
|
1765
1386
|
return {
|
|
1766
1387
|
typedData: {
|
|
1767
1388
|
domain: typedData.domain,
|
|
@@ -1771,54 +1392,11 @@ var IssuerApiHandlers = class {
|
|
|
1771
1392
|
}
|
|
1772
1393
|
};
|
|
1773
1394
|
}
|
|
1774
|
-
/**
|
|
1775
|
-
* `POST /claim-and-swap`
|
|
1776
|
-
*
|
|
1777
|
-
* @deprecated Since 0.3.0 — the single-call mint-then-swap flow is
|
|
1778
|
-
* retired in v1.4. Use the new `handleClaim()` (mint only) and let
|
|
1779
|
-
* the user swap separately on PAFI Web. See
|
|
1780
|
-
* [V1.4_V1.5_OVERVIEW.md §4] for the new scenario model. Will be
|
|
1781
|
-
* removed in 2.0.
|
|
1782
|
-
*
|
|
1783
|
-
* Legacy behavior: the terminal handler forwards the verified
|
|
1784
|
-
* consent to the MintingGateway, which runs the 11-step flow.
|
|
1785
|
-
*/
|
|
1786
|
-
async handleClaimAndSwap(userAddress, request) {
|
|
1787
|
-
if (request.chainId !== this.chainId) {
|
|
1788
|
-
throw new Error(
|
|
1789
|
-
`handleClaimAndSwap: unsupported chainId ${request.chainId}`
|
|
1790
|
-
);
|
|
1791
|
-
}
|
|
1792
|
-
const pointToken = (0, import_viem8.getAddress)(request.pointTokenAddress);
|
|
1793
|
-
if (!this.supportedTokens.has(pointToken)) {
|
|
1794
|
-
throw new Error(
|
|
1795
|
-
`handleClaimAndSwap: unsupported pointToken ${pointToken}`
|
|
1796
|
-
);
|
|
1797
|
-
}
|
|
1798
|
-
const result = await this.gateway.processMintAndCashOut({
|
|
1799
|
-
userAddress: (0, import_viem8.getAddress)(userAddress),
|
|
1800
|
-
pointTokenAddress: pointToken,
|
|
1801
|
-
chainId: request.chainId,
|
|
1802
|
-
domain: request.domain,
|
|
1803
|
-
receiverConsent: request.receiverConsent,
|
|
1804
|
-
receiverSignature: request.receiverSignature,
|
|
1805
|
-
swapPath: request.swapPath,
|
|
1806
|
-
swapDeadline: request.swapDeadline
|
|
1807
|
-
});
|
|
1808
|
-
const response = {
|
|
1809
|
-
txHash: result.txHash,
|
|
1810
|
-
lockId: result.lockId
|
|
1811
|
-
};
|
|
1812
|
-
if (result.blockNumber !== void 0)
|
|
1813
|
-
response.blockNumber = result.blockNumber;
|
|
1814
|
-
if (result.gasUsed !== void 0) response.gasUsed = result.gasUsed;
|
|
1815
|
-
return response;
|
|
1816
|
-
}
|
|
1817
1395
|
};
|
|
1818
1396
|
|
|
1819
1397
|
// src/api/handlers/ptRedeemHandler.ts
|
|
1820
1398
|
var import_viem9 = require("viem");
|
|
1821
|
-
var
|
|
1399
|
+
var import_core5 = require("@pafi-dev/core");
|
|
1822
1400
|
var DEFAULT_REDEEM_LOCK_MS = 15 * 60 * 1e3;
|
|
1823
1401
|
var DEFAULT_SIG_DEADLINE_SEC = 15 * 60;
|
|
1824
1402
|
var PTRedeemError = class extends Error {
|
|
@@ -1874,7 +1452,7 @@ var PTRedeemHandler = class {
|
|
|
1874
1452
|
try {
|
|
1875
1453
|
burnNonce = await this.provider.readContract({
|
|
1876
1454
|
address: this.pointTokenAddress,
|
|
1877
|
-
abi:
|
|
1455
|
+
abi: import_core5.POINT_TOKEN_V2_ABI,
|
|
1878
1456
|
functionName: "burnRequestNonces",
|
|
1879
1457
|
args: [request.userAddress]
|
|
1880
1458
|
});
|
|
@@ -1900,7 +1478,7 @@ var PTRedeemHandler = class {
|
|
|
1900
1478
|
};
|
|
1901
1479
|
let burnerSignature;
|
|
1902
1480
|
try {
|
|
1903
|
-
const sig = await (0,
|
|
1481
|
+
const sig = await (0, import_core5.signBurnRequest)(
|
|
1904
1482
|
this.burnerSignerWallet,
|
|
1905
1483
|
domain,
|
|
1906
1484
|
burnRequest
|
|
@@ -1938,7 +1516,7 @@ var PTRedeemHandler = class {
|
|
|
1938
1516
|
|
|
1939
1517
|
// src/api/handlers/topUpRedemptionHandler.ts
|
|
1940
1518
|
var import_viem10 = require("viem");
|
|
1941
|
-
var
|
|
1519
|
+
var import_core6 = require("@pafi-dev/core");
|
|
1942
1520
|
var TopUpRedemptionError = class extends Error {
|
|
1943
1521
|
constructor(code, message) {
|
|
1944
1522
|
super(message);
|
|
@@ -1967,7 +1545,7 @@ var TopUpRedemptionHandler = class {
|
|
|
1967
1545
|
return { action: "NO_TOP_UP_NEEDED", offChainBalance };
|
|
1968
1546
|
}
|
|
1969
1547
|
const shortfall = request.requiredAmount - offChainBalance;
|
|
1970
|
-
const onChainBalance = await (0,
|
|
1548
|
+
const onChainBalance = await (0, import_core6.getPointTokenBalance)(
|
|
1971
1549
|
this.provider,
|
|
1972
1550
|
this.pointTokenAddress,
|
|
1973
1551
|
request.userAddress
|
|
@@ -2205,7 +1783,7 @@ function toUsdtPerNative(priceFloat, usdtDecimals) {
|
|
|
2205
1783
|
}
|
|
2206
1784
|
|
|
2207
1785
|
// src/balance/balanceAggregator.ts
|
|
2208
|
-
var
|
|
1786
|
+
var import_core7 = require("@pafi-dev/core");
|
|
2209
1787
|
var BalanceAggregator = class {
|
|
2210
1788
|
provider;
|
|
2211
1789
|
ledger;
|
|
@@ -2226,7 +1804,7 @@ var BalanceAggregator = class {
|
|
|
2226
1804
|
async getCombinedBalance(user, pointToken) {
|
|
2227
1805
|
const [offChain, onChain] = await Promise.all([
|
|
2228
1806
|
this.ledger.getBalance(user, pointToken),
|
|
2229
|
-
(0,
|
|
1807
|
+
(0, import_core7.getPointTokenBalance)(this.provider, pointToken, user)
|
|
2230
1808
|
]);
|
|
2231
1809
|
return {
|
|
2232
1810
|
offChain,
|
|
@@ -2476,15 +2054,6 @@ function createIssuerService(config) {
|
|
|
2476
2054
|
if (!config.provider) {
|
|
2477
2055
|
throw new Error("createIssuerService: provider is required");
|
|
2478
2056
|
}
|
|
2479
|
-
if (!config.operatorWallet) {
|
|
2480
|
-
throw new Error("createIssuerService: operatorWallet is required");
|
|
2481
|
-
}
|
|
2482
|
-
if (!config.signer) {
|
|
2483
|
-
throw new Error("createIssuerService: signer is required");
|
|
2484
|
-
}
|
|
2485
|
-
if (!config.relayAddress) {
|
|
2486
|
-
throw new Error("createIssuerService: relayAddress is required");
|
|
2487
|
-
}
|
|
2488
2057
|
if (!config.auth?.jwtSecret) {
|
|
2489
2058
|
throw new Error("createIssuerService: auth.jwtSecret is required");
|
|
2490
2059
|
}
|
|
@@ -2511,18 +2080,7 @@ function createIssuerService(config) {
|
|
|
2511
2080
|
authServiceConfig.jwtExpiresIn = config.auth.jwtExpiresIn;
|
|
2512
2081
|
}
|
|
2513
2082
|
const authService = new AuthService(authServiceConfig);
|
|
2514
|
-
const
|
|
2515
|
-
relayAddress: config.relayAddress,
|
|
2516
|
-
operatorWallet: config.operatorWallet,
|
|
2517
|
-
provider: config.provider
|
|
2518
|
-
};
|
|
2519
|
-
if (config.relay?.simulateBeforeSubmit !== void 0) {
|
|
2520
|
-
relayServiceConfig.simulateBeforeSubmit = config.relay.simulateBeforeSubmit;
|
|
2521
|
-
}
|
|
2522
|
-
if (config.relay?.confirmationTimeoutMs !== void 0) {
|
|
2523
|
-
relayServiceConfig.confirmationTimeoutMs = config.relay.confirmationTimeoutMs;
|
|
2524
|
-
}
|
|
2525
|
-
const relayService = new RelayService(relayServiceConfig);
|
|
2083
|
+
const relayService = new RelayService();
|
|
2526
2084
|
let feeManager;
|
|
2527
2085
|
if (config.fee) {
|
|
2528
2086
|
feeManager = new FeeManager({
|
|
@@ -2530,16 +2088,6 @@ function createIssuerService(config) {
|
|
|
2530
2088
|
provider: config.provider
|
|
2531
2089
|
});
|
|
2532
2090
|
}
|
|
2533
|
-
const gatewayConfig = {
|
|
2534
|
-
ledger,
|
|
2535
|
-
policy,
|
|
2536
|
-
signer: config.signer,
|
|
2537
|
-
relayService
|
|
2538
|
-
};
|
|
2539
|
-
if (config.gateway?.defaultLockBufferMs !== void 0) {
|
|
2540
|
-
gatewayConfig.defaultLockBufferMs = config.gateway.defaultLockBufferMs;
|
|
2541
|
-
}
|
|
2542
|
-
const gateway = new MintingGateway(gatewayConfig);
|
|
2543
2091
|
const indexers = /* @__PURE__ */ new Map();
|
|
2544
2092
|
for (const tokenAddress of tokenAddresses) {
|
|
2545
2093
|
const indexerConfig = {
|
|
@@ -2567,7 +2115,6 @@ function createIssuerService(config) {
|
|
|
2567
2115
|
const firstIndexer = indexers.get(tokenAddresses[0]);
|
|
2568
2116
|
const handlersConfig = {
|
|
2569
2117
|
authService,
|
|
2570
|
-
gateway,
|
|
2571
2118
|
ledger,
|
|
2572
2119
|
provider: config.provider,
|
|
2573
2120
|
pointTokenAddresses: tokenAddresses,
|
|
@@ -2587,10 +2134,8 @@ function createIssuerService(config) {
|
|
|
2587
2134
|
sessionStore,
|
|
2588
2135
|
ledger,
|
|
2589
2136
|
policy,
|
|
2590
|
-
signer: config.signer,
|
|
2591
2137
|
relayService,
|
|
2592
2138
|
feeManager,
|
|
2593
|
-
gateway,
|
|
2594
2139
|
indexers,
|
|
2595
2140
|
indexer: firstIndexer,
|
|
2596
2141
|
handlers
|
|
@@ -2611,8 +2156,6 @@ var PAFI_ISSUER_SDK_VERSION = "0.1.0";
|
|
|
2611
2156
|
IssuerApiHandlers,
|
|
2612
2157
|
MemoryPointLedger,
|
|
2613
2158
|
MemorySessionStore,
|
|
2614
|
-
MintingGateway,
|
|
2615
|
-
MintingGatewayError,
|
|
2616
2159
|
NonceManager,
|
|
2617
2160
|
PAFI_ISSUER_SDK_VERSION,
|
|
2618
2161
|
PTRedeemError,
|
|
@@ -2628,7 +2171,6 @@ var PAFI_ISSUER_SDK_VERSION = "0.1.0";
|
|
|
2628
2171
|
authenticateRequest,
|
|
2629
2172
|
createIssuerService,
|
|
2630
2173
|
createSubgraphNativeUsdtQuoter,
|
|
2631
|
-
createSubgraphPoolsProvider
|
|
2632
|
-
encodeExtData
|
|
2174
|
+
createSubgraphPoolsProvider
|
|
2633
2175
|
});
|
|
2634
2176
|
//# sourceMappingURL=index.cjs.map
|