@pafi-dev/issuer 0.10.1 → 0.11.0
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 +81 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -10
- package/dist/index.d.ts +65 -10
- package/dist/index.js +81 -17
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -1155,13 +1155,23 @@ var import_viem4 = require("viem");
|
|
|
1155
1155
|
var TRANSFER_EVENT = (0, import_viem4.parseAbiItem)(
|
|
1156
1156
|
"event Transfer(address indexed from, address indexed to, uint256 value)"
|
|
1157
1157
|
);
|
|
1158
|
+
var MINT_WITH_FEE_EVENT = (0, import_viem4.parseAbiItem)(
|
|
1159
|
+
"event MintWithFee(address indexed pointToken, address indexed to, uint256 grossAmount, uint256 netAmount, uint256 feeAmount)"
|
|
1160
|
+
);
|
|
1158
1161
|
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
1162
|
+
var DEAD_ADDRESS = "0x000000000000000000000000000000000000dEaD";
|
|
1159
1163
|
var DEFAULT_CONFIRMATIONS = 3;
|
|
1160
1164
|
var DEFAULT_BATCH_SIZE = 2000n;
|
|
1161
1165
|
var DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
1166
|
+
function isNoWrapper(addr) {
|
|
1167
|
+
if (!addr) return true;
|
|
1168
|
+
const checksummed = (0, import_viem4.getAddress)(addr);
|
|
1169
|
+
return checksummed === ZERO_ADDRESS || checksummed === DEAD_ADDRESS;
|
|
1170
|
+
}
|
|
1162
1171
|
var PointIndexer = class {
|
|
1163
1172
|
provider;
|
|
1164
1173
|
pointTokenAddress;
|
|
1174
|
+
mintFeeWrapperAddress;
|
|
1165
1175
|
ledger;
|
|
1166
1176
|
cursorStore;
|
|
1167
1177
|
startBlock;
|
|
@@ -1177,7 +1187,8 @@ var PointIndexer = class {
|
|
|
1177
1187
|
throw new Error("PointIndexer: pointTokenAddress required");
|
|
1178
1188
|
if (!config.ledger) throw new Error("PointIndexer: ledger required");
|
|
1179
1189
|
this.provider = config.provider;
|
|
1180
|
-
this.pointTokenAddress = config.pointTokenAddress;
|
|
1190
|
+
this.pointTokenAddress = (0, import_viem4.getAddress)(config.pointTokenAddress);
|
|
1191
|
+
this.mintFeeWrapperAddress = isNoWrapper(config.mintFeeWrapperAddress) ? void 0 : (0, import_viem4.getAddress)(config.mintFeeWrapperAddress);
|
|
1181
1192
|
this.ledger = config.ledger;
|
|
1182
1193
|
this.cursorStore = config.cursorStore ?? new InMemoryCursorStore();
|
|
1183
1194
|
this.startBlock = config.fromBlock ?? 0n;
|
|
@@ -1260,14 +1271,7 @@ var PointIndexer = class {
|
|
|
1260
1271
|
let cursor = from;
|
|
1261
1272
|
while (cursor <= to) {
|
|
1262
1273
|
const chunkEnd = cursor + this.batchSize - 1n > to ? to : cursor + this.batchSize - 1n;
|
|
1263
|
-
const
|
|
1264
|
-
address: this.pointTokenAddress,
|
|
1265
|
-
event: TRANSFER_EVENT,
|
|
1266
|
-
args: { from: ZERO_ADDRESS },
|
|
1267
|
-
fromBlock: cursor,
|
|
1268
|
-
toBlock: chunkEnd
|
|
1269
|
-
});
|
|
1270
|
-
const events = this.decodeMintEvents(logs);
|
|
1274
|
+
const events = this.mintFeeWrapperAddress ? await this.fetchWrapperMintEvents(cursor, chunkEnd) : await this.fetchTransferMintEvents(cursor, chunkEnd);
|
|
1271
1275
|
events.sort((a, b) => {
|
|
1272
1276
|
if (a.blockNumber !== b.blockNumber) {
|
|
1273
1277
|
return a.blockNumber < b.blockNumber ? -1 : 1;
|
|
@@ -1282,9 +1286,53 @@ var PointIndexer = class {
|
|
|
1282
1286
|
}
|
|
1283
1287
|
}
|
|
1284
1288
|
// -------------------------------------------------------------------------
|
|
1285
|
-
//
|
|
1289
|
+
// Event fetching — two modes (wrapper vs direct)
|
|
1286
1290
|
// -------------------------------------------------------------------------
|
|
1287
|
-
|
|
1291
|
+
/**
|
|
1292
|
+
* Wrapper mode (v1.6): listen for `MintWithFee` on the wrapper,
|
|
1293
|
+
* filtered to events for THIS pointToken only. The event's `to` field
|
|
1294
|
+
* is the actual end user, and `grossAmount` matches the lock amount.
|
|
1295
|
+
*/
|
|
1296
|
+
async fetchWrapperMintEvents(fromBlock, toBlock) {
|
|
1297
|
+
const logs = await this.provider.getLogs({
|
|
1298
|
+
address: this.mintFeeWrapperAddress,
|
|
1299
|
+
event: MINT_WITH_FEE_EVENT,
|
|
1300
|
+
args: { pointToken: this.pointTokenAddress },
|
|
1301
|
+
fromBlock,
|
|
1302
|
+
toBlock
|
|
1303
|
+
});
|
|
1304
|
+
const out = [];
|
|
1305
|
+
for (const log of logs) {
|
|
1306
|
+
const args = log.args;
|
|
1307
|
+
if (!args.pointToken || !args.to || args.grossAmount === void 0 || log.blockNumber === null || log.transactionHash === null) {
|
|
1308
|
+
continue;
|
|
1309
|
+
}
|
|
1310
|
+
if ((0, import_viem4.getAddress)(args.pointToken) !== this.pointTokenAddress) continue;
|
|
1311
|
+
out.push({
|
|
1312
|
+
to: (0, import_viem4.getAddress)(args.to),
|
|
1313
|
+
amount: args.grossAmount,
|
|
1314
|
+
blockNumber: log.blockNumber,
|
|
1315
|
+
txHash: log.transactionHash,
|
|
1316
|
+
logIndex: log.logIndex ?? 0
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
return out;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Direct mode (legacy / chains without wrapper): listen for
|
|
1323
|
+
* `Transfer(from=0x0 → to)` on the PointToken itself.
|
|
1324
|
+
*/
|
|
1325
|
+
async fetchTransferMintEvents(fromBlock, toBlock) {
|
|
1326
|
+
const logs = await this.provider.getLogs({
|
|
1327
|
+
address: this.pointTokenAddress,
|
|
1328
|
+
event: TRANSFER_EVENT,
|
|
1329
|
+
args: { from: ZERO_ADDRESS },
|
|
1330
|
+
fromBlock,
|
|
1331
|
+
toBlock
|
|
1332
|
+
});
|
|
1333
|
+
return this.decodeTransferMintEvents(logs);
|
|
1334
|
+
}
|
|
1335
|
+
decodeTransferMintEvents(logs) {
|
|
1288
1336
|
const out = [];
|
|
1289
1337
|
for (const log of logs) {
|
|
1290
1338
|
const args = log.args;
|
|
@@ -1301,6 +1349,9 @@ var PointIndexer = class {
|
|
|
1301
1349
|
}
|
|
1302
1350
|
return out;
|
|
1303
1351
|
}
|
|
1352
|
+
// -------------------------------------------------------------------------
|
|
1353
|
+
// Finalization
|
|
1354
|
+
// -------------------------------------------------------------------------
|
|
1304
1355
|
/**
|
|
1305
1356
|
* Finalize a single mint event: match it to a PENDING lock in the
|
|
1306
1357
|
* ledger, then call `deductBalance` (which also resolves the lock in
|
|
@@ -2592,6 +2643,11 @@ var PTClaimError = class extends import_core.PafiSdkError {
|
|
|
2592
2643
|
this.details = details;
|
|
2593
2644
|
}
|
|
2594
2645
|
};
|
|
2646
|
+
function isNoWrapper2(address) {
|
|
2647
|
+
if (!address) return true;
|
|
2648
|
+
const lower = address.toLowerCase();
|
|
2649
|
+
return lower === "0x0000000000000000000000000000000000000000" || lower === "0x000000000000000000000000000000000000dead";
|
|
2650
|
+
}
|
|
2595
2651
|
var DEFAULT_LOCK_MS = 15 * 60 * 1e3;
|
|
2596
2652
|
var DEFAULT_SIG_DEADLINE_SEC2 = 15 * 60;
|
|
2597
2653
|
var PTClaimHandler = class {
|
|
@@ -2628,9 +2684,11 @@ var PTClaimHandler = class {
|
|
|
2628
2684
|
);
|
|
2629
2685
|
}
|
|
2630
2686
|
}
|
|
2631
|
-
const
|
|
2632
|
-
|
|
2633
|
-
|
|
2687
|
+
const chainAddresses = (0, import_core11.getContractAddresses)(request.chainId);
|
|
2688
|
+
const { batchExecutor: batchExecutorAddress } = chainAddresses;
|
|
2689
|
+
const wrapperOverride = this.cfg.mintFeeWrapperAddress;
|
|
2690
|
+
const wrapperFromSdk = chainAddresses.mintFeeWrapper;
|
|
2691
|
+
const resolvedWrapper = wrapperOverride !== void 0 ? isNoWrapper2(wrapperOverride) ? void 0 : wrapperOverride : isNoWrapper2(wrapperFromSdk) ? void 0 : wrapperFromSdk;
|
|
2634
2692
|
const lockId = await this.cfg.ledger.lockForMinting(
|
|
2635
2693
|
request.userAddress,
|
|
2636
2694
|
request.amount,
|
|
@@ -2659,7 +2717,7 @@ var PTClaimHandler = class {
|
|
|
2659
2717
|
domain,
|
|
2660
2718
|
mintRequestNonce: request.mintRequestNonce,
|
|
2661
2719
|
deadline: signatureDeadline,
|
|
2662
|
-
mintFeeWrapperAddress:
|
|
2720
|
+
mintFeeWrapperAddress: resolvedWrapper
|
|
2663
2721
|
// No feeAmount/feeRecipient — RelayService auto-resolves.
|
|
2664
2722
|
});
|
|
2665
2723
|
} catch (err) {
|
|
@@ -2682,7 +2740,7 @@ var PTClaimHandler = class {
|
|
|
2682
2740
|
mintRequestNonce: request.mintRequestNonce,
|
|
2683
2741
|
deadline: signatureDeadline,
|
|
2684
2742
|
feeAmount: 0n,
|
|
2685
|
-
mintFeeWrapperAddress:
|
|
2743
|
+
mintFeeWrapperAddress: resolvedWrapper
|
|
2686
2744
|
});
|
|
2687
2745
|
} catch (err) {
|
|
2688
2746
|
throw new PTClaimError(
|
|
@@ -4317,6 +4375,9 @@ function createIssuerService(config) {
|
|
|
4317
4375
|
provider: config.provider
|
|
4318
4376
|
});
|
|
4319
4377
|
}
|
|
4378
|
+
const sdkWrapperAddress = (0, import_core19.getContractAddresses)(config.chainId).mintFeeWrapper;
|
|
4379
|
+
const wrapperOverride = config.indexer?.mintFeeWrapperAddress;
|
|
4380
|
+
const resolvedWrapperAddress = wrapperOverride !== void 0 ? wrapperOverride : sdkWrapperAddress;
|
|
4320
4381
|
const indexers = /* @__PURE__ */ new Map();
|
|
4321
4382
|
for (const tokenAddress of tokenAddresses) {
|
|
4322
4383
|
const indexerConfig = {
|
|
@@ -4324,6 +4385,9 @@ function createIssuerService(config) {
|
|
|
4324
4385
|
pointTokenAddress: tokenAddress,
|
|
4325
4386
|
ledger
|
|
4326
4387
|
};
|
|
4388
|
+
if (resolvedWrapperAddress !== void 0) {
|
|
4389
|
+
indexerConfig.mintFeeWrapperAddress = resolvedWrapperAddress;
|
|
4390
|
+
}
|
|
4327
4391
|
if (config.indexer?.fromBlock !== void 0) {
|
|
4328
4392
|
indexerConfig.fromBlock = config.indexer.fromBlock;
|
|
4329
4393
|
}
|
|
@@ -4594,7 +4658,7 @@ var MemoryRedemptionHistoryStore = class {
|
|
|
4594
4658
|
};
|
|
4595
4659
|
|
|
4596
4660
|
// src/index.ts
|
|
4597
|
-
var PAFI_ISSUER_SDK_VERSION = true ? "0.
|
|
4661
|
+
var PAFI_ISSUER_SDK_VERSION = true ? "0.11.0" : "dev";
|
|
4598
4662
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4599
4663
|
0 && (module.exports = {
|
|
4600
4664
|
AdapterMisconfiguredError,
|