@pafi-dev/issuer 0.5.42 → 0.5.43
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 +148 -287
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -191
- package/dist/index.d.ts +46 -191
- package/dist/index.js +77 -216
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -34,10 +34,11 @@ __export(index_exports, {
|
|
|
34
34
|
IssuerStateError: () => IssuerStateError,
|
|
35
35
|
IssuerStateValidator: () => IssuerStateValidator,
|
|
36
36
|
LockNotFoundError: () => LockNotFoundError,
|
|
37
|
+
MemoryPendingUserOpStore: () => MemoryPendingUserOpStore,
|
|
37
38
|
MemorySessionStore: () => MemorySessionStore,
|
|
38
39
|
NonceManager: () => NonceManager,
|
|
39
40
|
PAFI_ISSUER_SDK_VERSION: () => PAFI_ISSUER_SDK_VERSION,
|
|
40
|
-
PAFI_SUBGRAPH_URL: () =>
|
|
41
|
+
PAFI_SUBGRAPH_URL: () => import_core14.PAFI_SUBGRAPH_URL,
|
|
41
42
|
PTClaimError: () => PTClaimError,
|
|
42
43
|
PTClaimHandler: () => PTClaimHandler,
|
|
43
44
|
PTRedeemError: () => PTRedeemError,
|
|
@@ -54,8 +55,6 @@ __export(index_exports, {
|
|
|
54
55
|
RelayService: () => RelayService,
|
|
55
56
|
SwapError: () => SwapError,
|
|
56
57
|
SwapHandler: () => SwapHandler,
|
|
57
|
-
TopUpRedemptionError: () => TopUpRedemptionError,
|
|
58
|
-
TopUpRedemptionHandler: () => TopUpRedemptionHandler,
|
|
59
58
|
authenticateRequest: () => authenticateRequest,
|
|
60
59
|
createIssuerService: () => createIssuerService,
|
|
61
60
|
createNativePtQuoter: () => createNativePtQuoter,
|
|
@@ -640,15 +639,13 @@ var RelayService = class {
|
|
|
640
639
|
});
|
|
641
640
|
}
|
|
642
641
|
/**
|
|
643
|
-
* Build an unsigned UserOp for Scenario 2 (Burn/Redeem)
|
|
642
|
+
* Build an unsigned UserOp for Scenario 2 (Burn/Redeem) — sig-gated
|
|
643
|
+
* `PointToken.burn(from, amount, deadline, burnerSig)`. Caller
|
|
644
|
+
* provides a pre-signed `BurnRequest` + sig bytes (typically from
|
|
645
|
+
* `PTRedeemHandler`).
|
|
644
646
|
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* usable if the caller (via EIP-7702) is whitelisted as a burner.
|
|
648
|
-
* Rare in v1.4; kept for admin/operator tools.
|
|
649
|
-
* - `mode: 'burnWithSig'` — `PointToken.burn(from, amount, deadline,
|
|
650
|
-
* burnerSig)`. Caller provides a pre-signed `BurnRequest` + sig
|
|
651
|
-
* bytes (typically from `PTRedeemHandler`).
|
|
647
|
+
* Direct burn (no sig) was dropped in v1.4 — every burn now goes
|
|
648
|
+
* through the issuer-signed `BurnRequest` path.
|
|
652
649
|
*/
|
|
653
650
|
async prepareBurn(params) {
|
|
654
651
|
if (!params.pointTokenAddress) {
|
|
@@ -660,29 +657,24 @@ var RelayService = class {
|
|
|
660
657
|
"prepareBurn: batchExecutorAddress required"
|
|
661
658
|
);
|
|
662
659
|
}
|
|
660
|
+
if (!params.burnRequest || !params.burnerSignature) {
|
|
661
|
+
throw new RelayError(
|
|
662
|
+
"ENCODE_FAILED",
|
|
663
|
+
"prepareBurn: burnRequest + burnerSignature required"
|
|
664
|
+
);
|
|
665
|
+
}
|
|
663
666
|
let burnCallData;
|
|
664
667
|
try {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
params.burnRequest.deadline,
|
|
676
|
-
params.burnerSignature
|
|
677
|
-
]
|
|
678
|
-
});
|
|
679
|
-
} else {
|
|
680
|
-
burnCallData = (0, import_viem3.encodeFunctionData)({
|
|
681
|
-
abi: import_core2.POINT_TOKEN_V2_ABI,
|
|
682
|
-
functionName: "burn",
|
|
683
|
-
args: [params.userAddress, params.amount]
|
|
684
|
-
});
|
|
685
|
-
}
|
|
668
|
+
burnCallData = (0, import_viem3.encodeFunctionData)({
|
|
669
|
+
abi: import_core2.POINT_TOKEN_V2_ABI,
|
|
670
|
+
functionName: "burn",
|
|
671
|
+
args: [
|
|
672
|
+
params.burnRequest.from,
|
|
673
|
+
params.burnRequest.amount,
|
|
674
|
+
params.burnRequest.deadline,
|
|
675
|
+
params.burnerSignature
|
|
676
|
+
]
|
|
677
|
+
});
|
|
686
678
|
} catch (err) {
|
|
687
679
|
throw new RelayError(
|
|
688
680
|
"ENCODE_FAILED",
|
|
@@ -1150,7 +1142,6 @@ var IssuerApiHandlers = class {
|
|
|
1150
1142
|
pafiWebUrl;
|
|
1151
1143
|
feeManager;
|
|
1152
1144
|
poolsProvider;
|
|
1153
|
-
claim;
|
|
1154
1145
|
constructor(config) {
|
|
1155
1146
|
this.authService = config.authService;
|
|
1156
1147
|
this.ledger = config.ledger;
|
|
@@ -1168,7 +1159,6 @@ var IssuerApiHandlers = class {
|
|
|
1168
1159
|
if (config.pafiWebUrl) this.pafiWebUrl = config.pafiWebUrl;
|
|
1169
1160
|
if (config.feeManager) this.feeManager = config.feeManager;
|
|
1170
1161
|
if (config.poolsProvider) this.poolsProvider = config.poolsProvider;
|
|
1171
|
-
if (config.claim) this.claim = config.claim;
|
|
1172
1162
|
}
|
|
1173
1163
|
// =========================================================================
|
|
1174
1164
|
// Public handlers (no auth required)
|
|
@@ -1302,91 +1292,9 @@ var IssuerApiHandlers = class {
|
|
|
1302
1292
|
isMinter: minter
|
|
1303
1293
|
};
|
|
1304
1294
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
* Policy gate + ledger lock + MintRequest signing in a single atomic
|
|
1309
|
-
* step. Returns an unsigned UserOp the frontend attaches paymaster data
|
|
1310
|
-
* to and submits via EIP-7702 + Bundler.
|
|
1311
|
-
*
|
|
1312
|
-
* Order of operations:
|
|
1313
|
-
* 1. Validate request fields.
|
|
1314
|
-
* 2. policy.evaluate() — throws if denied; cannot be bypassed.
|
|
1315
|
-
* 3. ledger.lockForMinting() — reserves the balance.
|
|
1316
|
-
* 4. Read on-chain mintRequestNonce + token name in parallel.
|
|
1317
|
-
* 5. relayService.prepareMint() — sign MintRequest + encode UserOp.
|
|
1318
|
-
* 6. On any error after step 3, release the lock before re-throwing.
|
|
1319
|
-
*/
|
|
1320
|
-
async handleClaim(userAddress, request) {
|
|
1321
|
-
if (!this.claim) {
|
|
1322
|
-
throw new Error("handleClaim: claim is not configured on this issuer");
|
|
1323
|
-
}
|
|
1324
|
-
if (request.chainId !== this.chainId) {
|
|
1325
|
-
throw new Error(`handleClaim: unsupported chainId ${request.chainId}`);
|
|
1326
|
-
}
|
|
1327
|
-
const pointToken = (0, import_viem6.getAddress)(request.pointTokenAddress);
|
|
1328
|
-
if (!this.supportedTokens.has(pointToken)) {
|
|
1329
|
-
throw new Error(`handleClaim: unsupported pointToken ${pointToken}`);
|
|
1330
|
-
}
|
|
1331
|
-
if (request.amount <= 0n) {
|
|
1332
|
-
throw new Error("handleClaim: amount must be positive");
|
|
1333
|
-
}
|
|
1334
|
-
const nowSecs = BigInt(Math.floor(Date.now() / 1e3));
|
|
1335
|
-
if (request.deadline <= nowSecs) {
|
|
1336
|
-
throw new Error("handleClaim: deadline is in the past");
|
|
1337
|
-
}
|
|
1338
|
-
const { policy, relayService, issuerSignerWallet, batchExecutorAddress } = this.claim;
|
|
1339
|
-
const lockDurationMs = this.claim.lockDurationMs ?? 15 * 60 * 1e3;
|
|
1340
|
-
const normalizedUser = (0, import_viem6.getAddress)(userAddress);
|
|
1341
|
-
const decision = await policy.evaluate({
|
|
1342
|
-
userAddress: normalizedUser,
|
|
1343
|
-
amount: request.amount,
|
|
1344
|
-
pointTokenAddress: pointToken,
|
|
1345
|
-
chainId: this.chainId
|
|
1346
|
-
});
|
|
1347
|
-
if (!decision.approved) {
|
|
1348
|
-
throw new Error(`handleClaim: policy denied \u2014 ${decision.reason ?? "no reason given"}`);
|
|
1349
|
-
}
|
|
1350
|
-
const lockId = await this.ledger.lockForMinting(
|
|
1351
|
-
normalizedUser,
|
|
1352
|
-
request.amount,
|
|
1353
|
-
lockDurationMs,
|
|
1354
|
-
pointToken
|
|
1355
|
-
);
|
|
1356
|
-
try {
|
|
1357
|
-
const [mintRequestNonce, tokenName] = await Promise.all([
|
|
1358
|
-
(0, import_core3.getMintRequestNonce)(this.provider, pointToken, normalizedUser),
|
|
1359
|
-
(0, import_core3.getTokenName)(this.provider, pointToken)
|
|
1360
|
-
]);
|
|
1361
|
-
const domain = {
|
|
1362
|
-
name: tokenName,
|
|
1363
|
-
verifyingContract: pointToken,
|
|
1364
|
-
chainId: this.chainId
|
|
1365
|
-
};
|
|
1366
|
-
const userOp = await relayService.prepareMint({
|
|
1367
|
-
userAddress: normalizedUser,
|
|
1368
|
-
aaNonce: request.aaNonce,
|
|
1369
|
-
batchExecutorAddress,
|
|
1370
|
-
pointTokenAddress: pointToken,
|
|
1371
|
-
amount: request.amount,
|
|
1372
|
-
issuerSignerWallet,
|
|
1373
|
-
domain,
|
|
1374
|
-
mintRequestNonce,
|
|
1375
|
-
deadline: request.deadline,
|
|
1376
|
-
feeAmount: request.feeAmount,
|
|
1377
|
-
feeRecipient: request.feeRecipient
|
|
1378
|
-
});
|
|
1379
|
-
return {
|
|
1380
|
-
lockId,
|
|
1381
|
-
userOp,
|
|
1382
|
-
expiresInSeconds: Math.floor(lockDurationMs / 1e3)
|
|
1383
|
-
};
|
|
1384
|
-
} catch (err) {
|
|
1385
|
-
await this.ledger.releaseLock(lockId).catch(() => {
|
|
1386
|
-
});
|
|
1387
|
-
throw err;
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1295
|
+
// Note: legacy `handleClaim` (sync sponsored-claim returning calls[]) was
|
|
1296
|
+
// removed in 0.5.43 — callers should use `PTClaimHandler` directly or
|
|
1297
|
+
// wire `IssuerApiAdapter.claim()` which composes the full flow.
|
|
1390
1298
|
};
|
|
1391
1299
|
|
|
1392
1300
|
// src/api/handlers/ptRedeemHandler.ts
|
|
@@ -1625,70 +1533,6 @@ var PTRedeemHandler = class {
|
|
|
1625
1533
|
}
|
|
1626
1534
|
};
|
|
1627
1535
|
|
|
1628
|
-
// src/api/handlers/topUpRedemptionHandler.ts
|
|
1629
|
-
var import_viem8 = require("viem");
|
|
1630
|
-
var import_core5 = require("@pafi-dev/core");
|
|
1631
|
-
var TopUpRedemptionError = class extends Error {
|
|
1632
|
-
constructor(code, message) {
|
|
1633
|
-
super(message);
|
|
1634
|
-
this.code = code;
|
|
1635
|
-
this.name = "TopUpRedemptionError";
|
|
1636
|
-
}
|
|
1637
|
-
code;
|
|
1638
|
-
};
|
|
1639
|
-
var TopUpRedemptionHandler = class {
|
|
1640
|
-
ledger;
|
|
1641
|
-
ptRedeemHandler;
|
|
1642
|
-
provider;
|
|
1643
|
-
pointTokenAddress;
|
|
1644
|
-
constructor(config) {
|
|
1645
|
-
this.ledger = config.ledger;
|
|
1646
|
-
this.ptRedeemHandler = config.ptRedeemHandler;
|
|
1647
|
-
this.provider = config.provider;
|
|
1648
|
-
this.pointTokenAddress = (0, import_viem8.getAddress)(config.pointTokenAddress);
|
|
1649
|
-
}
|
|
1650
|
-
async handle(request) {
|
|
1651
|
-
if ((0, import_viem8.getAddress)(request.authenticatedAddress) !== (0, import_viem8.getAddress)(request.userAddress)) {
|
|
1652
|
-
throw new TopUpRedemptionError(
|
|
1653
|
-
"UNAUTHORIZED",
|
|
1654
|
-
`userAddress (${request.userAddress}) does not match authenticated session (${request.authenticatedAddress})`
|
|
1655
|
-
);
|
|
1656
|
-
}
|
|
1657
|
-
const offChainBalance = await this.ledger.getBalance(
|
|
1658
|
-
request.userAddress,
|
|
1659
|
-
this.pointTokenAddress
|
|
1660
|
-
);
|
|
1661
|
-
if (offChainBalance >= request.requiredAmount) {
|
|
1662
|
-
return { action: "NO_TOP_UP_NEEDED", offChainBalance };
|
|
1663
|
-
}
|
|
1664
|
-
const shortfall = request.requiredAmount - offChainBalance;
|
|
1665
|
-
const onChainBalance = await (0, import_core5.getPointTokenBalance)(
|
|
1666
|
-
this.provider,
|
|
1667
|
-
this.pointTokenAddress,
|
|
1668
|
-
request.userAddress
|
|
1669
|
-
);
|
|
1670
|
-
if (onChainBalance < shortfall) {
|
|
1671
|
-
return {
|
|
1672
|
-
action: "INSUFFICIENT_ONCHAIN",
|
|
1673
|
-
offChainBalance,
|
|
1674
|
-
onChainBalance,
|
|
1675
|
-
shortfall
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
const redeem = await this.ptRedeemHandler.handle({
|
|
1679
|
-
authenticatedAddress: request.authenticatedAddress,
|
|
1680
|
-
userAddress: request.userAddress,
|
|
1681
|
-
amount: shortfall,
|
|
1682
|
-
aaNonce: request.aaNonce
|
|
1683
|
-
});
|
|
1684
|
-
return {
|
|
1685
|
-
action: "TOP_UP_STARTED",
|
|
1686
|
-
shortfall,
|
|
1687
|
-
redeem
|
|
1688
|
-
};
|
|
1689
|
-
}
|
|
1690
|
-
};
|
|
1691
|
-
|
|
1692
1536
|
// src/api/statusHandlers.ts
|
|
1693
1537
|
var LockNotFoundError = class extends PafiSdkError {
|
|
1694
1538
|
code = "LOCK_NOT_FOUND";
|
|
@@ -1790,11 +1634,11 @@ async function handleRedeemStatus(params) {
|
|
|
1790
1634
|
}
|
|
1791
1635
|
|
|
1792
1636
|
// src/api/mobileHandlers.ts
|
|
1793
|
-
var
|
|
1794
|
-
var
|
|
1637
|
+
var import_viem8 = require("viem");
|
|
1638
|
+
var import_core7 = require("@pafi-dev/core");
|
|
1795
1639
|
|
|
1796
1640
|
// src/userop-store/serialize.ts
|
|
1797
|
-
var
|
|
1641
|
+
var import_core5 = require("@pafi-dev/core");
|
|
1798
1642
|
function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
1799
1643
|
if (variant === "fallback") {
|
|
1800
1644
|
if (!entry.fallback) {
|
|
@@ -1802,7 +1646,7 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
|
1802
1646
|
"serializeEntryToJsonRpc: variant=fallback requested but the stored entry has no `fallback` branch \u2014 caller should resubmit with variant='sponsored' or re-prepare with a fee configured."
|
|
1803
1647
|
);
|
|
1804
1648
|
}
|
|
1805
|
-
return (0,
|
|
1649
|
+
return (0, import_core5.serializeUserOpToJsonRpc)(
|
|
1806
1650
|
{
|
|
1807
1651
|
sender: entry.sender,
|
|
1808
1652
|
nonce: BigInt(entry.nonce),
|
|
@@ -1817,7 +1661,7 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
|
1817
1661
|
signature
|
|
1818
1662
|
);
|
|
1819
1663
|
}
|
|
1820
|
-
return (0,
|
|
1664
|
+
return (0, import_core5.serializeUserOpToJsonRpc)(
|
|
1821
1665
|
{
|
|
1822
1666
|
sender: entry.sender,
|
|
1823
1667
|
nonce: BigInt(entry.nonce),
|
|
@@ -1836,8 +1680,35 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
|
1836
1680
|
);
|
|
1837
1681
|
}
|
|
1838
1682
|
|
|
1683
|
+
// src/userop-store/memoryStore.ts
|
|
1684
|
+
var MemoryPendingUserOpStore = class {
|
|
1685
|
+
entries = /* @__PURE__ */ new Map();
|
|
1686
|
+
now;
|
|
1687
|
+
constructor(now = () => Date.now()) {
|
|
1688
|
+
this.now = now;
|
|
1689
|
+
}
|
|
1690
|
+
async save(lockId, entry, ttlSeconds) {
|
|
1691
|
+
this.entries.set(lockId, {
|
|
1692
|
+
entry,
|
|
1693
|
+
expiresAt: this.now() + ttlSeconds * 1e3
|
|
1694
|
+
});
|
|
1695
|
+
}
|
|
1696
|
+
async get(lockId) {
|
|
1697
|
+
const hit = this.entries.get(lockId);
|
|
1698
|
+
if (!hit) return null;
|
|
1699
|
+
if (hit.expiresAt <= this.now()) {
|
|
1700
|
+
this.entries.delete(lockId);
|
|
1701
|
+
return null;
|
|
1702
|
+
}
|
|
1703
|
+
return hit.entry;
|
|
1704
|
+
}
|
|
1705
|
+
async delete(lockId) {
|
|
1706
|
+
this.entries.delete(lockId);
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1839
1710
|
// src/userop-store/prepareUserOp.ts
|
|
1840
|
-
var
|
|
1711
|
+
var import_core6 = require("@pafi-dev/core");
|
|
1841
1712
|
function serializeUserOpTypedData(td) {
|
|
1842
1713
|
return {
|
|
1843
1714
|
domain: td.domain,
|
|
@@ -1872,9 +1743,9 @@ async function prepareMobileUserOp(params) {
|
|
|
1872
1743
|
params.partialUserOp,
|
|
1873
1744
|
params.paymasterFields
|
|
1874
1745
|
);
|
|
1875
|
-
const userOpHash = (0,
|
|
1746
|
+
const userOpHash = (0, import_core6.computeUserOpHash)(userOp, params.chainId);
|
|
1876
1747
|
const typedData = serializeUserOpTypedData(
|
|
1877
|
-
(0,
|
|
1748
|
+
(0, import_core6.buildUserOpTypedData)(userOp, params.chainId)
|
|
1878
1749
|
);
|
|
1879
1750
|
let fallback;
|
|
1880
1751
|
let fallbackEntry;
|
|
@@ -1884,9 +1755,9 @@ async function prepareMobileUserOp(params) {
|
|
|
1884
1755
|
maxFeePerGas: userOp.maxFeePerGas,
|
|
1885
1756
|
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas
|
|
1886
1757
|
};
|
|
1887
|
-
const fallbackHash = (0,
|
|
1758
|
+
const fallbackHash = (0, import_core6.computeUserOpHash)(fallbackUserOp, params.chainId);
|
|
1888
1759
|
const fallbackTypedData = serializeUserOpTypedData(
|
|
1889
|
-
(0,
|
|
1760
|
+
(0, import_core6.buildUserOpTypedData)(fallbackUserOp, params.chainId)
|
|
1890
1761
|
);
|
|
1891
1762
|
fallback = {
|
|
1892
1763
|
userOp: fallbackUserOp,
|
|
@@ -2020,7 +1891,7 @@ async function handleMobilePrepare(params) {
|
|
|
2020
1891
|
params.provider.estimateFeesPerGas(),
|
|
2021
1892
|
params.provider.getCode({ address: params.userAddress })
|
|
2022
1893
|
]);
|
|
2023
|
-
const needsDelegation = (0,
|
|
1894
|
+
const needsDelegation = (0, import_core7.parseEip7702DelegatedAddress)(userCode) === null;
|
|
2024
1895
|
const sponsoredOp = {
|
|
2025
1896
|
...params.partialUserOp,
|
|
2026
1897
|
maxFeePerGas: fees.maxFeePerGas ?? params.partialUserOp.maxFeePerGas ?? 0n,
|
|
@@ -2054,7 +1925,7 @@ async function handleMobileSubmit(params) {
|
|
|
2054
1925
|
if (!entry) {
|
|
2055
1926
|
throw new PendingUserOpNotFoundError(params.lockId);
|
|
2056
1927
|
}
|
|
2057
|
-
if ((0,
|
|
1928
|
+
if ((0, import_viem8.getAddress)(entry.sender) !== (0, import_viem8.getAddress)(params.authenticatedAddress)) {
|
|
2058
1929
|
throw new PendingUserOpForbiddenError(params.lockId);
|
|
2059
1930
|
}
|
|
2060
1931
|
const variant = params.variant ?? "sponsored";
|
|
@@ -2062,7 +1933,7 @@ async function handleMobileSubmit(params) {
|
|
|
2062
1933
|
const result = await relayUserOp({
|
|
2063
1934
|
client: params.pafiBackendClient,
|
|
2064
1935
|
userOp: userOpJson,
|
|
2065
|
-
entryPoint: params.entryPoint ??
|
|
1936
|
+
entryPoint: params.entryPoint ?? import_core7.ENTRY_POINT_V08
|
|
2066
1937
|
});
|
|
2067
1938
|
await params.bindUserOpHash(params.lockId, result.userOpHash);
|
|
2068
1939
|
await params.store.delete(params.lockId);
|
|
@@ -2070,8 +1941,8 @@ async function handleMobileSubmit(params) {
|
|
|
2070
1941
|
}
|
|
2071
1942
|
|
|
2072
1943
|
// src/api/handlers/ptClaimHandler.ts
|
|
2073
|
-
var
|
|
2074
|
-
var
|
|
1944
|
+
var import_viem9 = require("viem");
|
|
1945
|
+
var import_core8 = require("@pafi-dev/core");
|
|
2075
1946
|
|
|
2076
1947
|
// src/issuer-state/types.ts
|
|
2077
1948
|
var IssuerStateError = class extends PafiSdkError {
|
|
@@ -2111,7 +1982,7 @@ var PTClaimHandler = class {
|
|
|
2111
1982
|
};
|
|
2112
1983
|
}
|
|
2113
1984
|
async handle(request) {
|
|
2114
|
-
if ((0,
|
|
1985
|
+
if ((0, import_viem9.getAddress)(request.authenticatedAddress) !== (0, import_viem9.getAddress)(request.userAddress)) {
|
|
2115
1986
|
throw new PTClaimError(
|
|
2116
1987
|
"VALIDATION_FAILED",
|
|
2117
1988
|
`userAddress (${request.userAddress}) does not match authenticated session (${request.authenticatedAddress})`
|
|
@@ -2134,7 +2005,7 @@ var PTClaimHandler = class {
|
|
|
2134
2005
|
);
|
|
2135
2006
|
}
|
|
2136
2007
|
}
|
|
2137
|
-
const { batchExecutor: batchExecutorAddress } = (0,
|
|
2008
|
+
const { batchExecutor: batchExecutorAddress } = (0, import_core8.getContractAddresses)(
|
|
2138
2009
|
request.chainId
|
|
2139
2010
|
);
|
|
2140
2011
|
const lockId = await this.cfg.ledger.lockForMinting(
|
|
@@ -2194,8 +2065,8 @@ var PTClaimHandler = class {
|
|
|
2194
2065
|
);
|
|
2195
2066
|
}
|
|
2196
2067
|
}
|
|
2197
|
-
const calls = (0,
|
|
2198
|
-
const callsFallback = fallback ? (0,
|
|
2068
|
+
const calls = (0, import_core8.decodeBatchExecuteCalls)(userOp.callData);
|
|
2069
|
+
const callsFallback = fallback ? (0, import_core8.decodeBatchExecuteCalls)(fallback.callData) : void 0;
|
|
2199
2070
|
return {
|
|
2200
2071
|
userOp,
|
|
2201
2072
|
fallback,
|
|
@@ -2210,7 +2081,7 @@ var PTClaimHandler = class {
|
|
|
2210
2081
|
};
|
|
2211
2082
|
|
|
2212
2083
|
// src/api/handlers/swapHandler.ts
|
|
2213
|
-
var
|
|
2084
|
+
var import_core9 = require("@pafi-dev/core");
|
|
2214
2085
|
var SwapError = class extends PafiSdkError {
|
|
2215
2086
|
httpStatus = "unprocessable";
|
|
2216
2087
|
code;
|
|
@@ -2236,7 +2107,7 @@ var SwapHandler = class {
|
|
|
2236
2107
|
throw new SwapError("INVALID_AMOUNT", "amountIn must be positive");
|
|
2237
2108
|
}
|
|
2238
2109
|
const slippageBps = request.slippageBps ?? this.cfg.defaultSlippageBps;
|
|
2239
|
-
const { usdt, pafiFeeRecipient, universalRouter } = (0,
|
|
2110
|
+
const { usdt, pafiFeeRecipient, universalRouter } = (0, import_core9.getContractAddresses)(
|
|
2240
2111
|
request.chainId
|
|
2241
2112
|
);
|
|
2242
2113
|
const poolsResponse = await this.cfg.poolsProvider({
|
|
@@ -2251,7 +2122,7 @@ var SwapHandler = class {
|
|
|
2251
2122
|
}
|
|
2252
2123
|
let fallbackQuote;
|
|
2253
2124
|
try {
|
|
2254
|
-
fallbackQuote = await (0,
|
|
2125
|
+
fallbackQuote = await (0, import_core9.findBestQuote)(
|
|
2255
2126
|
this.cfg.provider,
|
|
2256
2127
|
request.chainId,
|
|
2257
2128
|
request.pointTokenAddress,
|
|
@@ -2282,7 +2153,7 @@ var SwapHandler = class {
|
|
|
2282
2153
|
let sponsoredPath = fallbackQuote.bestRoute.path;
|
|
2283
2154
|
if (feeAmount > 0n) {
|
|
2284
2155
|
try {
|
|
2285
|
-
const sponsoredQuote = await (0,
|
|
2156
|
+
const sponsoredQuote = await (0, import_core9.findBestQuote)(
|
|
2286
2157
|
this.cfg.provider,
|
|
2287
2158
|
request.chainId,
|
|
2288
2159
|
request.pointTokenAddress,
|
|
@@ -2300,7 +2171,7 @@ var SwapHandler = class {
|
|
|
2300
2171
|
}
|
|
2301
2172
|
}
|
|
2302
2173
|
const minAmountOutSponsored = estimatedUsdtOutSponsored * BigInt(1e4 - slippageBps) / 10000n;
|
|
2303
|
-
const sponsoredOp = (0,
|
|
2174
|
+
const sponsoredOp = (0, import_core9.buildSwapWithGasDeduction)({
|
|
2304
2175
|
userAddress: request.userAddress,
|
|
2305
2176
|
aaNonce: request.aaNonce,
|
|
2306
2177
|
pointTokenAddress: request.pointTokenAddress,
|
|
@@ -2313,7 +2184,7 @@ var SwapHandler = class {
|
|
|
2313
2184
|
gasFeePt: feeAmount,
|
|
2314
2185
|
feeRecipient: pafiFeeRecipient
|
|
2315
2186
|
});
|
|
2316
|
-
const fallbackOp = feeAmount > 0n ? (0,
|
|
2187
|
+
const fallbackOp = feeAmount > 0n ? (0, import_core9.buildSwapWithGasDeduction)({
|
|
2317
2188
|
userAddress: request.userAddress,
|
|
2318
2189
|
aaNonce: request.aaNonce,
|
|
2319
2190
|
pointTokenAddress: request.pointTokenAddress,
|
|
@@ -2335,14 +2206,14 @@ var SwapHandler = class {
|
|
|
2335
2206
|
estimatedUsdtOutFallback: fallbackOp ? estimatedUsdtOutFallback : void 0,
|
|
2336
2207
|
minAmountOutFallback: fallbackOp ? minAmountOutFallback : void 0,
|
|
2337
2208
|
deadline,
|
|
2338
|
-
calls: (0,
|
|
2339
|
-
callsFallback: fallbackOp ? (0,
|
|
2209
|
+
calls: (0, import_core9.decodeBatchExecuteCalls)(sponsoredOp.callData),
|
|
2210
|
+
callsFallback: fallbackOp ? (0, import_core9.decodeBatchExecuteCalls)(fallbackOp.callData) : void 0
|
|
2340
2211
|
};
|
|
2341
2212
|
}
|
|
2342
2213
|
};
|
|
2343
2214
|
|
|
2344
2215
|
// src/api/handlers/perpDepositHandler.ts
|
|
2345
|
-
var
|
|
2216
|
+
var import_core10 = require("@pafi-dev/core");
|
|
2346
2217
|
var PerpDepositError = class extends PafiSdkError {
|
|
2347
2218
|
httpStatus = "unprocessable";
|
|
2348
2219
|
code;
|
|
@@ -2366,26 +2237,26 @@ var PerpDepositHandler = class {
|
|
|
2366
2237
|
if (request.amount <= 0n) {
|
|
2367
2238
|
throw new PerpDepositError("INVALID_AMOUNT", "amount must be positive");
|
|
2368
2239
|
}
|
|
2369
|
-
const brokerHash =
|
|
2370
|
-
const tokenHash =
|
|
2371
|
-
const vault =
|
|
2240
|
+
const brokerHash = import_core10.BROKER_HASHES[request.brokerId];
|
|
2241
|
+
const tokenHash = import_core10.TOKEN_HASHES.USDC;
|
|
2242
|
+
const vault = import_core10.ORDERLY_VAULT_ADDRESSES[request.chainId];
|
|
2372
2243
|
if (!vault) {
|
|
2373
2244
|
throw new PerpDepositError(
|
|
2374
2245
|
"PERP_DEPOSIT_UNAVAILABLE",
|
|
2375
2246
|
`no Orderly Vault for chainId ${request.chainId}`
|
|
2376
2247
|
);
|
|
2377
2248
|
}
|
|
2378
|
-
const { orderlyRelay: relayAddress, pafiFeeRecipient } = (0,
|
|
2249
|
+
const { orderlyRelay: relayAddress, pafiFeeRecipient } = (0, import_core10.getContractAddresses)(request.chainId);
|
|
2379
2250
|
const [usdcAddress, brokerAllowed] = await Promise.all([
|
|
2380
2251
|
this.cfg.provider.readContract({
|
|
2381
2252
|
address: vault,
|
|
2382
|
-
abi:
|
|
2253
|
+
abi: import_core10.ORDERLY_VAULT_ABI,
|
|
2383
2254
|
functionName: "getAllowedToken",
|
|
2384
2255
|
args: [tokenHash]
|
|
2385
2256
|
}),
|
|
2386
2257
|
this.cfg.provider.readContract({
|
|
2387
2258
|
address: vault,
|
|
2388
|
-
abi:
|
|
2259
|
+
abi: import_core10.ORDERLY_VAULT_ABI,
|
|
2389
2260
|
functionName: "getAllowedBroker",
|
|
2390
2261
|
args: [brokerHash]
|
|
2391
2262
|
})
|
|
@@ -2396,7 +2267,7 @@ var PerpDepositHandler = class {
|
|
|
2396
2267
|
`broker "${request.brokerId}" is not whitelisted on Orderly Vault`
|
|
2397
2268
|
);
|
|
2398
2269
|
}
|
|
2399
|
-
const accountId = (0,
|
|
2270
|
+
const accountId = (0, import_core10.computeAccountId)(request.userAddress, brokerHash);
|
|
2400
2271
|
const requestForQuote = {
|
|
2401
2272
|
token: usdcAddress,
|
|
2402
2273
|
receiver: request.userAddress,
|
|
@@ -2407,7 +2278,7 @@ var PerpDepositHandler = class {
|
|
|
2407
2278
|
const [relayTokenFee, ptGasFee] = await Promise.all([
|
|
2408
2279
|
this.cfg.provider.readContract({
|
|
2409
2280
|
address: relayAddress,
|
|
2410
|
-
abi:
|
|
2281
|
+
abi: import_core10.ORDERLY_RELAY_ABI,
|
|
2411
2282
|
functionName: "quoteTokenFee",
|
|
2412
2283
|
args: [requestForQuote]
|
|
2413
2284
|
}),
|
|
@@ -2427,7 +2298,7 @@ var PerpDepositHandler = class {
|
|
|
2427
2298
|
totalAmount: request.amount,
|
|
2428
2299
|
maxFee
|
|
2429
2300
|
};
|
|
2430
|
-
const sponsoredOp = (0,
|
|
2301
|
+
const sponsoredOp = (0, import_core10.buildPerpDepositViaRelay)({
|
|
2431
2302
|
userAddress: request.userAddress,
|
|
2432
2303
|
aaNonce: request.aaNonce,
|
|
2433
2304
|
relayAddress,
|
|
@@ -2436,7 +2307,7 @@ var PerpDepositHandler = class {
|
|
|
2436
2307
|
gasFeePt: ptGasFee,
|
|
2437
2308
|
gasFeePtRecipient: pafiFeeRecipient
|
|
2438
2309
|
});
|
|
2439
|
-
const fallbackOp = ptGasFee > 0n ? (0,
|
|
2310
|
+
const fallbackOp = ptGasFee > 0n ? (0, import_core10.buildPerpDepositViaRelay)({
|
|
2440
2311
|
userAddress: request.userAddress,
|
|
2441
2312
|
aaNonce: request.aaNonce,
|
|
2442
2313
|
relayAddress,
|
|
@@ -2453,22 +2324,22 @@ var PerpDepositHandler = class {
|
|
|
2453
2324
|
brokerHash,
|
|
2454
2325
|
usdcAddress,
|
|
2455
2326
|
relayAddress,
|
|
2456
|
-
calls: (0,
|
|
2457
|
-
callsFallback: fallbackOp ? (0,
|
|
2327
|
+
calls: (0, import_core10.decodeBatchExecuteCalls)(sponsoredOp.callData),
|
|
2328
|
+
callsFallback: fallbackOp ? (0, import_core10.decodeBatchExecuteCalls)(fallbackOp.callData) : void 0
|
|
2458
2329
|
};
|
|
2459
2330
|
}
|
|
2460
2331
|
};
|
|
2461
2332
|
|
|
2462
2333
|
// src/api/delegateHandler.ts
|
|
2463
|
-
var
|
|
2334
|
+
var import_core11 = require("@pafi-dev/core");
|
|
2464
2335
|
var DEFAULT_DELEGATE_GAS = {
|
|
2465
2336
|
callGasLimit: 100000n,
|
|
2466
2337
|
verificationGasLimit: 150000n,
|
|
2467
2338
|
preVerificationGas: 50000n
|
|
2468
2339
|
};
|
|
2469
2340
|
async function handleDelegateSubmit(params) {
|
|
2470
|
-
const { batchExecutor } = (0,
|
|
2471
|
-
const callData = (0,
|
|
2341
|
+
const { batchExecutor } = (0, import_core11.getContractAddresses)(params.chainId);
|
|
2342
|
+
const callData = (0, import_core11.encodeBatchExecute)([]);
|
|
2472
2343
|
const userOp = {
|
|
2473
2344
|
sender: params.userAddress,
|
|
2474
2345
|
nonce: params.aaNonce,
|
|
@@ -2491,7 +2362,7 @@ async function handleDelegateSubmit(params) {
|
|
|
2491
2362
|
...userOp,
|
|
2492
2363
|
...paymasterFields ?? {}
|
|
2493
2364
|
};
|
|
2494
|
-
const userOpJson = (0,
|
|
2365
|
+
const userOpJson = (0, import_core11.serializeUserOpToJsonRpc)(
|
|
2495
2366
|
{
|
|
2496
2367
|
sender: merged.sender,
|
|
2497
2368
|
nonce: merged.nonce,
|
|
@@ -2510,7 +2381,7 @@ async function handleDelegateSubmit(params) {
|
|
|
2510
2381
|
// is the user's "consent"; no separate AA signature is needed.
|
|
2511
2382
|
"0x"
|
|
2512
2383
|
);
|
|
2513
|
-
const authorization = (0,
|
|
2384
|
+
const authorization = (0, import_core11.buildEip7702Authorization)({
|
|
2514
2385
|
chainId: params.chainId,
|
|
2515
2386
|
address: batchExecutor,
|
|
2516
2387
|
nonce: params.delegationNonce,
|
|
@@ -2519,7 +2390,7 @@ async function handleDelegateSubmit(params) {
|
|
|
2519
2390
|
const result = await relayUserOp({
|
|
2520
2391
|
client: params.pafiBackendClient,
|
|
2521
2392
|
userOp: userOpJson,
|
|
2522
|
-
entryPoint:
|
|
2393
|
+
entryPoint: import_core11.ENTRY_POINT_V08,
|
|
2523
2394
|
eip7702Auth: authorization
|
|
2524
2395
|
});
|
|
2525
2396
|
return {
|
|
@@ -2530,7 +2401,7 @@ async function handleDelegateSubmit(params) {
|
|
|
2530
2401
|
}
|
|
2531
2402
|
|
|
2532
2403
|
// src/api/quoteHelper.ts
|
|
2533
|
-
var
|
|
2404
|
+
var import_core12 = require("@pafi-dev/core");
|
|
2534
2405
|
var DEFAULT_DEADLINE_SECONDS = 300;
|
|
2535
2406
|
async function quotePointTokenToUsdt(params) {
|
|
2536
2407
|
const now = params.now ?? (() => Date.now());
|
|
@@ -2554,11 +2425,11 @@ async function quotePointTokenToUsdt(params) {
|
|
|
2554
2425
|
quoteError: "QUOTE_UNAVAILABLE"
|
|
2555
2426
|
};
|
|
2556
2427
|
}
|
|
2557
|
-
const { usdt: usdtAddress } = (0,
|
|
2428
|
+
const { usdt: usdtAddress } = (0, import_core12.getContractAddresses)(params.chainId);
|
|
2558
2429
|
let estimatedUsdtOut = 0n;
|
|
2559
2430
|
let gasEstimate = 0n;
|
|
2560
2431
|
try {
|
|
2561
|
-
const best = await (0,
|
|
2432
|
+
const best = await (0, import_core12.findBestQuote)(
|
|
2562
2433
|
params.provider,
|
|
2563
2434
|
params.chainId,
|
|
2564
2435
|
params.pointTokenAddress,
|
|
@@ -2620,8 +2491,8 @@ function createSdkErrorMapper(factories) {
|
|
|
2620
2491
|
}
|
|
2621
2492
|
|
|
2622
2493
|
// src/api/issuerApiAdapter.ts
|
|
2623
|
-
var
|
|
2624
|
-
var
|
|
2494
|
+
var import_viem10 = require("viem");
|
|
2495
|
+
var import_core13 = require("@pafi-dev/core");
|
|
2625
2496
|
var IssuerApiAdapter = class {
|
|
2626
2497
|
cfg;
|
|
2627
2498
|
constructor(config) {
|
|
@@ -2642,7 +2513,7 @@ var IssuerApiAdapter = class {
|
|
|
2642
2513
|
async pools(authenticatedAddress, chainId, pointTokenAddress) {
|
|
2643
2514
|
const result = await this.cfg.issuerService.api.handlePools(
|
|
2644
2515
|
authenticatedAddress,
|
|
2645
|
-
{ chainId, pointTokenAddress: (0,
|
|
2516
|
+
{ chainId, pointTokenAddress: (0, import_viem10.getAddress)(pointTokenAddress) }
|
|
2646
2517
|
);
|
|
2647
2518
|
return { pools: result.pools };
|
|
2648
2519
|
}
|
|
@@ -2651,8 +2522,8 @@ var IssuerApiAdapter = class {
|
|
|
2651
2522
|
authenticatedAddress,
|
|
2652
2523
|
{
|
|
2653
2524
|
chainId,
|
|
2654
|
-
userAddress: (0,
|
|
2655
|
-
pointTokenAddress: (0,
|
|
2525
|
+
userAddress: (0, import_viem10.getAddress)(userAddress),
|
|
2526
|
+
pointTokenAddress: (0, import_viem10.getAddress)(pointTokenAddress)
|
|
2656
2527
|
}
|
|
2657
2528
|
);
|
|
2658
2529
|
return {
|
|
@@ -2670,13 +2541,13 @@ var IssuerApiAdapter = class {
|
|
|
2670
2541
|
this.cfg.issuerService.api.handleGasFee(),
|
|
2671
2542
|
this.cfg.issuerService.api.handlePools(authenticatedAddress, {
|
|
2672
2543
|
chainId,
|
|
2673
|
-
pointTokenAddress: (0,
|
|
2544
|
+
pointTokenAddress: (0, import_viem10.getAddress)(pointTokenAddress)
|
|
2674
2545
|
})
|
|
2675
2546
|
]);
|
|
2676
2547
|
const quote = await quotePointTokenToUsdt({
|
|
2677
2548
|
provider: this.cfg.provider,
|
|
2678
2549
|
chainId,
|
|
2679
|
-
pointTokenAddress: (0,
|
|
2550
|
+
pointTokenAddress: (0, import_viem10.getAddress)(pointTokenAddress),
|
|
2680
2551
|
pointAmount,
|
|
2681
2552
|
pools: poolsResult.pools,
|
|
2682
2553
|
gasFeeUsdt: gasFeeResult.gasFeeUsdt
|
|
@@ -2700,7 +2571,7 @@ var IssuerApiAdapter = class {
|
|
|
2700
2571
|
"ptClaimHandler",
|
|
2701
2572
|
"claim"
|
|
2702
2573
|
);
|
|
2703
|
-
const pointTokenAddress = (0,
|
|
2574
|
+
const pointTokenAddress = (0, import_viem10.getAddress)(input.pointTokenAddress);
|
|
2704
2575
|
const result = await ptClaimHandler.handle({
|
|
2705
2576
|
authenticatedAddress: input.authenticatedAddress,
|
|
2706
2577
|
userAddress: input.authenticatedAddress,
|
|
@@ -2741,8 +2612,8 @@ var IssuerApiAdapter = class {
|
|
|
2741
2612
|
"burn"
|
|
2742
2613
|
);
|
|
2743
2614
|
return {
|
|
2744
|
-
calls: (0,
|
|
2745
|
-
callsFallback: response.fallback ? (0,
|
|
2615
|
+
calls: (0, import_core13.decodeBatchExecuteCalls)(response.userOp.callData),
|
|
2616
|
+
callsFallback: response.fallback ? (0, import_core13.decodeBatchExecuteCalls)(response.fallback.userOp.callData) : void 0,
|
|
2746
2617
|
feeAmount: response.feeAmount.toString(),
|
|
2747
2618
|
lockId: response.lockId,
|
|
2748
2619
|
lockIdFallback: response.fallback?.lockId,
|
|
@@ -2762,7 +2633,7 @@ var IssuerApiAdapter = class {
|
|
|
2762
2633
|
const result = await swapHandler.handle({
|
|
2763
2634
|
userAddress: input.authenticatedAddress,
|
|
2764
2635
|
chainId: input.chainId,
|
|
2765
|
-
pointTokenAddress: (0,
|
|
2636
|
+
pointTokenAddress: (0, import_viem10.getAddress)(input.pointTokenAddress),
|
|
2766
2637
|
amountIn: input.amountIn,
|
|
2767
2638
|
aaNonce: input.aaNonce,
|
|
2768
2639
|
slippageBps: input.slippageBps
|
|
@@ -2825,7 +2696,7 @@ var IssuerApiAdapter = class {
|
|
|
2825
2696
|
"ptClaimHandler",
|
|
2826
2697
|
"claimPrepare"
|
|
2827
2698
|
);
|
|
2828
|
-
const pointTokenAddress = (0,
|
|
2699
|
+
const pointTokenAddress = (0, import_viem10.getAddress)(input.pointTokenAddress);
|
|
2829
2700
|
const claimResult = await ptClaimHandler.handle({
|
|
2830
2701
|
authenticatedAddress: input.authenticatedAddress,
|
|
2831
2702
|
userAddress: input.authenticatedAddress,
|
|
@@ -2871,7 +2742,7 @@ var IssuerApiAdapter = class {
|
|
|
2871
2742
|
}
|
|
2872
2743
|
async redeemPrepare(input) {
|
|
2873
2744
|
this.assertRedeemHandler();
|
|
2874
|
-
const pointTokenAddress = (0,
|
|
2745
|
+
const pointTokenAddress = (0, import_viem10.getAddress)(input.pointTokenAddress);
|
|
2875
2746
|
const redeemResponse = await this.cfg.ptRedeemHandler.handle({
|
|
2876
2747
|
userAddress: input.authenticatedAddress,
|
|
2877
2748
|
authenticatedAddress: input.authenticatedAddress,
|
|
@@ -2935,23 +2806,23 @@ var IssuerApiAdapter = class {
|
|
|
2935
2806
|
}
|
|
2936
2807
|
// ------------------------------ Delegate endpoints -----------------------
|
|
2937
2808
|
async delegateStatus(authenticatedAddress, chainId) {
|
|
2938
|
-
const { batchExecutor } = (0,
|
|
2809
|
+
const { batchExecutor } = (0, import_core13.getContractAddresses)(chainId);
|
|
2939
2810
|
const code = await this.cfg.provider.getCode({
|
|
2940
2811
|
address: authenticatedAddress
|
|
2941
2812
|
});
|
|
2942
2813
|
return {
|
|
2943
|
-
isDelegated: (0,
|
|
2814
|
+
isDelegated: (0, import_core13.parseEip7702DelegatedAddress)(code) !== null,
|
|
2944
2815
|
batchExecutorAddress: batchExecutor
|
|
2945
2816
|
};
|
|
2946
2817
|
}
|
|
2947
2818
|
async delegatePrepare(authenticatedAddress, chainId) {
|
|
2948
|
-
const { batchExecutor } = (0,
|
|
2819
|
+
const { batchExecutor } = (0, import_core13.getContractAddresses)(chainId);
|
|
2949
2820
|
const accountNonce = BigInt(
|
|
2950
2821
|
await this.cfg.provider.getTransactionCount({
|
|
2951
2822
|
address: authenticatedAddress
|
|
2952
2823
|
})
|
|
2953
2824
|
);
|
|
2954
|
-
const authorizationHash = (0,
|
|
2825
|
+
const authorizationHash = (0, import_core13.computeAuthorizationHash)(
|
|
2955
2826
|
chainId,
|
|
2956
2827
|
batchExecutor,
|
|
2957
2828
|
accountNonce
|
|
@@ -2984,7 +2855,7 @@ var IssuerApiAdapter = class {
|
|
|
2984
2855
|
*/
|
|
2985
2856
|
async buildSponsorAuth(authenticatedAddress, callData, chainId, scenario) {
|
|
2986
2857
|
if (!this.cfg.pafiIssuerId) return void 0;
|
|
2987
|
-
return (0,
|
|
2858
|
+
return (0, import_core13.buildAndSignSponsorAuth)({
|
|
2988
2859
|
userAddress: authenticatedAddress,
|
|
2989
2860
|
callData,
|
|
2990
2861
|
chainId,
|
|
@@ -3033,8 +2904,8 @@ var IssuerApiAdapter = class {
|
|
|
3033
2904
|
};
|
|
3034
2905
|
|
|
3035
2906
|
// src/pools/subgraphPoolsProvider.ts
|
|
3036
|
-
var
|
|
3037
|
-
var
|
|
2907
|
+
var import_viem11 = require("viem");
|
|
2908
|
+
var import_core14 = require("@pafi-dev/core");
|
|
3038
2909
|
var DEFAULT_CACHE_TTL_MS = 3e4;
|
|
3039
2910
|
var POOL_QUERY = `
|
|
3040
2911
|
query GetPoolForPointToken($id: ID!) {
|
|
@@ -3052,7 +2923,7 @@ var POOL_QUERY = `
|
|
|
3052
2923
|
}
|
|
3053
2924
|
`;
|
|
3054
2925
|
function createSubgraphPoolsProvider(config = {}) {
|
|
3055
|
-
const subgraphUrl = config.subgraphUrl ??
|
|
2926
|
+
const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
|
|
3056
2927
|
try {
|
|
3057
2928
|
const parsed = new URL(subgraphUrl);
|
|
3058
2929
|
if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
|
|
@@ -3134,7 +3005,7 @@ async function fetchPoolsFromSubgraph(fetchImpl, subgraphUrl, pointTokenAddress)
|
|
|
3134
3005
|
return [];
|
|
3135
3006
|
}
|
|
3136
3007
|
const { pool } = token;
|
|
3137
|
-
if (!(0,
|
|
3008
|
+
if (!(0, import_viem11.isAddress)(pool.hooks)) {
|
|
3138
3009
|
console.error(
|
|
3139
3010
|
"[PAFI] SubgraphPoolsProvider: invalid hooks address in response:",
|
|
3140
3011
|
pool.hooks,
|
|
@@ -3142,7 +3013,7 @@ async function fetchPoolsFromSubgraph(fetchImpl, subgraphUrl, pointTokenAddress)
|
|
|
3142
3013
|
);
|
|
3143
3014
|
return [];
|
|
3144
3015
|
}
|
|
3145
|
-
if (!(0,
|
|
3016
|
+
if (!(0, import_viem11.isAddress)(pool.token0.id) || !(0, import_viem11.isAddress)(pool.token1.id)) {
|
|
3146
3017
|
console.error(
|
|
3147
3018
|
"[PAFI] SubgraphPoolsProvider: invalid token address in response \u2014 skipping pool"
|
|
3148
3019
|
);
|
|
@@ -3184,7 +3055,7 @@ var PRICE_QUERY = `
|
|
|
3184
3055
|
}
|
|
3185
3056
|
`;
|
|
3186
3057
|
function createSubgraphNativeUsdtQuoter(config = {}) {
|
|
3187
|
-
const subgraphUrl = config.subgraphUrl ??
|
|
3058
|
+
const subgraphUrl = config.subgraphUrl ?? import_core14.PAFI_SUBGRAPH_URL;
|
|
3188
3059
|
try {
|
|
3189
3060
|
const parsed = new URL(subgraphUrl);
|
|
3190
3061
|
if (process.env.NODE_ENV === "production" && parsed.protocol !== "https:") {
|
|
@@ -3292,8 +3163,8 @@ function toUsdtPerNative(priceFloat, usdtDecimals) {
|
|
|
3292
3163
|
}
|
|
3293
3164
|
|
|
3294
3165
|
// src/pools/nativePtQuoter.ts
|
|
3295
|
-
var
|
|
3296
|
-
var CHAINLINK_ABI = (0,
|
|
3166
|
+
var import_viem12 = require("viem");
|
|
3167
|
+
var CHAINLINK_ABI = (0, import_viem12.parseAbi)([
|
|
3297
3168
|
"function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)"
|
|
3298
3169
|
]);
|
|
3299
3170
|
var CHAINLINK_MAX_AGE_S = 3600n;
|
|
@@ -3314,7 +3185,7 @@ function createNativePtQuoter(config) {
|
|
|
3314
3185
|
provider,
|
|
3315
3186
|
pointTokenAddress,
|
|
3316
3187
|
chainlinkFeedAddress = "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70",
|
|
3317
|
-
subgraphUrl =
|
|
3188
|
+
subgraphUrl = import_core14.PAFI_SUBGRAPH_URL,
|
|
3318
3189
|
cacheTtlMs = 3e4,
|
|
3319
3190
|
fallbackEthPriceUsd = 3e3,
|
|
3320
3191
|
fallbackPtPriceUsdt = 0.1,
|
|
@@ -3396,7 +3267,7 @@ function parseBigDecimalTo18(s) {
|
|
|
3396
3267
|
}
|
|
3397
3268
|
|
|
3398
3269
|
// src/balance/balanceAggregator.ts
|
|
3399
|
-
var
|
|
3270
|
+
var import_core15 = require("@pafi-dev/core");
|
|
3400
3271
|
var BalanceAggregator = class {
|
|
3401
3272
|
provider;
|
|
3402
3273
|
ledger;
|
|
@@ -3417,7 +3288,7 @@ var BalanceAggregator = class {
|
|
|
3417
3288
|
async getCombinedBalance(user, pointToken) {
|
|
3418
3289
|
const [offChain, onChain] = await Promise.all([
|
|
3419
3290
|
this.ledger.getBalance(user, pointToken),
|
|
3420
|
-
(0,
|
|
3291
|
+
(0, import_core15.getPointTokenBalance)(this.provider, pointToken, user)
|
|
3421
3292
|
]);
|
|
3422
3293
|
return {
|
|
3423
3294
|
offChain,
|
|
@@ -3650,8 +3521,8 @@ var PafiBackendClient = class {
|
|
|
3650
3521
|
};
|
|
3651
3522
|
|
|
3652
3523
|
// src/config.ts
|
|
3653
|
-
var
|
|
3654
|
-
var
|
|
3524
|
+
var import_viem13 = require("viem");
|
|
3525
|
+
var import_core16 = require("@pafi-dev/core");
|
|
3655
3526
|
function createIssuerService(config) {
|
|
3656
3527
|
if (!config.provider) {
|
|
3657
3528
|
throw new Error("createIssuerService: provider is required");
|
|
@@ -3671,7 +3542,7 @@ function createIssuerService(config) {
|
|
|
3671
3542
|
"createIssuerService: at least one of pointTokenAddress / pointTokenAddresses is required"
|
|
3672
3543
|
);
|
|
3673
3544
|
}
|
|
3674
|
-
const tokenAddresses = rawAddresses.map((a) => (0,
|
|
3545
|
+
const tokenAddresses = rawAddresses.map((a) => (0, import_viem13.getAddress)(a));
|
|
3675
3546
|
const ledger = config.ledger;
|
|
3676
3547
|
const sessionStore = config.sessionStore ?? new MemorySessionStore();
|
|
3677
3548
|
const policy = config.policy ?? new DefaultPolicyEngine({ ledger });
|
|
@@ -3721,7 +3592,7 @@ function createIssuerService(config) {
|
|
|
3721
3592
|
indexers.set(tokenAddress, new PointIndexer(indexerConfig));
|
|
3722
3593
|
}
|
|
3723
3594
|
const firstIndexer = indexers.get(tokenAddresses[0]);
|
|
3724
|
-
const chainAddresses = (0,
|
|
3595
|
+
const chainAddresses = (0, import_core16.getContractAddresses)(config.chainId);
|
|
3725
3596
|
const resolvedContracts = {
|
|
3726
3597
|
batchExecutor: chainAddresses.batchExecutor,
|
|
3727
3598
|
usdt: chainAddresses.usdt,
|
|
@@ -3740,15 +3611,6 @@ function createIssuerService(config) {
|
|
|
3740
3611
|
};
|
|
3741
3612
|
if (feeManager) handlersConfig.feeManager = feeManager;
|
|
3742
3613
|
if (config.poolsProvider) handlersConfig.poolsProvider = config.poolsProvider;
|
|
3743
|
-
if (config.claim) {
|
|
3744
|
-
handlersConfig.claim = {
|
|
3745
|
-
policy,
|
|
3746
|
-
relayService,
|
|
3747
|
-
issuerSignerWallet: config.claim.issuerSignerWallet,
|
|
3748
|
-
batchExecutorAddress: config.claim.batchExecutorAddress ?? chainAddresses.batchExecutor,
|
|
3749
|
-
lockDurationMs: config.claim.lockDurationMs
|
|
3750
|
-
};
|
|
3751
|
-
}
|
|
3752
3614
|
const handlers = new IssuerApiHandlers(handlersConfig);
|
|
3753
3615
|
if (config.indexer?.autoStart) {
|
|
3754
3616
|
for (const idx of indexers.values()) {
|
|
@@ -3769,8 +3631,8 @@ function createIssuerService(config) {
|
|
|
3769
3631
|
}
|
|
3770
3632
|
|
|
3771
3633
|
// src/issuer-state/validator.ts
|
|
3772
|
-
var
|
|
3773
|
-
var
|
|
3634
|
+
var import_viem14 = require("viem");
|
|
3635
|
+
var import_core17 = require("@pafi-dev/core");
|
|
3774
3636
|
var ISSUER_RECORD_TTL_MS = 3e4;
|
|
3775
3637
|
var IssuerStateValidator = class _IssuerStateValidator {
|
|
3776
3638
|
constructor(provider, registryAddress) {
|
|
@@ -3787,7 +3649,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3787
3649
|
* `CONTRACT_ADDRESSES` map for the given chain.
|
|
3788
3650
|
*/
|
|
3789
3651
|
static forChain(provider, chainId) {
|
|
3790
|
-
const { issuerRegistry } = (0,
|
|
3652
|
+
const { issuerRegistry } = (0, import_core17.getContractAddresses)(chainId);
|
|
3791
3653
|
return new _IssuerStateValidator(provider, issuerRegistry);
|
|
3792
3654
|
}
|
|
3793
3655
|
/**
|
|
@@ -3796,7 +3658,7 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3796
3658
|
*/
|
|
3797
3659
|
invalidate(pointToken) {
|
|
3798
3660
|
if (pointToken) {
|
|
3799
|
-
const key = (0,
|
|
3661
|
+
const key = (0, import_viem14.getAddress)(pointToken);
|
|
3800
3662
|
this.pointTokenIssuerCache.delete(key);
|
|
3801
3663
|
this.stateCache.delete(key);
|
|
3802
3664
|
this.inflight.delete(key);
|
|
@@ -3811,23 +3673,23 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3811
3673
|
* The issuer field is set at `initialize()` and never changes.
|
|
3812
3674
|
*/
|
|
3813
3675
|
async getIssuerAddressForPointToken(pointToken) {
|
|
3814
|
-
const key = (0,
|
|
3676
|
+
const key = (0, import_viem14.getAddress)(pointToken);
|
|
3815
3677
|
const cached = this.pointTokenIssuerCache.get(key);
|
|
3816
3678
|
if (cached) return cached;
|
|
3817
3679
|
const issuer = await this.provider.readContract({
|
|
3818
3680
|
address: key,
|
|
3819
|
-
abi:
|
|
3681
|
+
abi: import_core17.POINT_TOKEN_V2_ABI,
|
|
3820
3682
|
functionName: "issuer"
|
|
3821
3683
|
});
|
|
3822
|
-
this.pointTokenIssuerCache.set(key, (0,
|
|
3823
|
-
return (0,
|
|
3684
|
+
this.pointTokenIssuerCache.set(key, (0, import_viem14.getAddress)(issuer));
|
|
3685
|
+
return (0, import_viem14.getAddress)(issuer);
|
|
3824
3686
|
}
|
|
3825
3687
|
/**
|
|
3826
3688
|
* Read registry record + totalSupply, with 30s cache and in-flight
|
|
3827
3689
|
* deduplication. Does NOT throw on inactive/missing — returns raw state.
|
|
3828
3690
|
*/
|
|
3829
3691
|
async getIssuerState(pointToken) {
|
|
3830
|
-
const tokenAddr = (0,
|
|
3692
|
+
const tokenAddr = (0, import_viem14.getAddress)(pointToken);
|
|
3831
3693
|
const now = Date.now();
|
|
3832
3694
|
const cached = this.stateCache.get(tokenAddr);
|
|
3833
3695
|
if (cached && cached.expiresAt > now) return cached.value;
|
|
@@ -3897,13 +3759,13 @@ var IssuerStateValidator = class _IssuerStateValidator {
|
|
|
3897
3759
|
const [issuerTuple, totalSupply] = await Promise.all([
|
|
3898
3760
|
this.provider.readContract({
|
|
3899
3761
|
address: this.registryAddress,
|
|
3900
|
-
abi:
|
|
3762
|
+
abi: import_core17.issuerRegistryGetIssuerFlatAbi,
|
|
3901
3763
|
functionName: "getIssuer",
|
|
3902
3764
|
args: [issuerAddr]
|
|
3903
3765
|
}),
|
|
3904
3766
|
this.provider.readContract({
|
|
3905
3767
|
address: tokenAddr,
|
|
3906
|
-
abi:
|
|
3768
|
+
abi: import_core17.POINT_TOKEN_V2_ABI,
|
|
3907
3769
|
functionName: "totalSupply"
|
|
3908
3770
|
})
|
|
3909
3771
|
]);
|
|
@@ -3942,6 +3804,7 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
3942
3804
|
IssuerStateError,
|
|
3943
3805
|
IssuerStateValidator,
|
|
3944
3806
|
LockNotFoundError,
|
|
3807
|
+
MemoryPendingUserOpStore,
|
|
3945
3808
|
MemorySessionStore,
|
|
3946
3809
|
NonceManager,
|
|
3947
3810
|
PAFI_ISSUER_SDK_VERSION,
|
|
@@ -3962,8 +3825,6 @@ var PAFI_ISSUER_SDK_VERSION = "0.4.0";
|
|
|
3962
3825
|
RelayService,
|
|
3963
3826
|
SwapError,
|
|
3964
3827
|
SwapHandler,
|
|
3965
|
-
TopUpRedemptionError,
|
|
3966
|
-
TopUpRedemptionHandler,
|
|
3967
3828
|
authenticateRequest,
|
|
3968
3829
|
createIssuerService,
|
|
3969
3830
|
createNativePtQuoter,
|