@pafi-dev/issuer 0.10.2 → 0.11.1
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 +71 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -3
- package/dist/index.d.ts +51 -3
- package/dist/index.js +71 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,7 +2643,7 @@ var PTClaimError = class extends import_core.PafiSdkError {
|
|
|
2592
2643
|
this.details = details;
|
|
2593
2644
|
}
|
|
2594
2645
|
};
|
|
2595
|
-
function
|
|
2646
|
+
function isNoWrapper2(address) {
|
|
2596
2647
|
if (!address) return true;
|
|
2597
2648
|
const lower = address.toLowerCase();
|
|
2598
2649
|
return lower === "0x0000000000000000000000000000000000000000" || lower === "0x000000000000000000000000000000000000dead";
|
|
@@ -2637,7 +2688,7 @@ var PTClaimHandler = class {
|
|
|
2637
2688
|
const { batchExecutor: batchExecutorAddress } = chainAddresses;
|
|
2638
2689
|
const wrapperOverride = this.cfg.mintFeeWrapperAddress;
|
|
2639
2690
|
const wrapperFromSdk = chainAddresses.mintFeeWrapper;
|
|
2640
|
-
const resolvedWrapper = wrapperOverride !== void 0 ?
|
|
2691
|
+
const resolvedWrapper = wrapperOverride !== void 0 ? isNoWrapper2(wrapperOverride) ? void 0 : wrapperOverride : isNoWrapper2(wrapperFromSdk) ? void 0 : wrapperFromSdk;
|
|
2641
2692
|
const lockId = await this.cfg.ledger.lockForMinting(
|
|
2642
2693
|
request.userAddress,
|
|
2643
2694
|
request.amount,
|
|
@@ -4324,6 +4375,9 @@ function createIssuerService(config) {
|
|
|
4324
4375
|
provider: config.provider
|
|
4325
4376
|
});
|
|
4326
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;
|
|
4327
4381
|
const indexers = /* @__PURE__ */ new Map();
|
|
4328
4382
|
for (const tokenAddress of tokenAddresses) {
|
|
4329
4383
|
const indexerConfig = {
|
|
@@ -4331,6 +4385,9 @@ function createIssuerService(config) {
|
|
|
4331
4385
|
pointTokenAddress: tokenAddress,
|
|
4332
4386
|
ledger
|
|
4333
4387
|
};
|
|
4388
|
+
if (resolvedWrapperAddress !== void 0) {
|
|
4389
|
+
indexerConfig.mintFeeWrapperAddress = resolvedWrapperAddress;
|
|
4390
|
+
}
|
|
4334
4391
|
if (config.indexer?.fromBlock !== void 0) {
|
|
4335
4392
|
indexerConfig.fromBlock = config.indexer.fromBlock;
|
|
4336
4393
|
}
|
|
@@ -4601,7 +4658,7 @@ var MemoryRedemptionHistoryStore = class {
|
|
|
4601
4658
|
};
|
|
4602
4659
|
|
|
4603
4660
|
// src/index.ts
|
|
4604
|
-
var PAFI_ISSUER_SDK_VERSION = true ? "0.
|
|
4661
|
+
var PAFI_ISSUER_SDK_VERSION = true ? "0.11.0" : "dev";
|
|
4605
4662
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4606
4663
|
0 && (module.exports = {
|
|
4607
4664
|
AdapterMisconfiguredError,
|