@pafi-dev/issuer 0.11.1 → 0.12.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 CHANGED
@@ -1571,7 +1571,7 @@ var BurnIndexer = class {
1571
1571
  // src/api/handlers.ts
1572
1572
  var import_viem6 = require("viem");
1573
1573
  var import_core6 = require("@pafi-dev/core");
1574
- var IssuerApiHandlers = class {
1574
+ var IssuerApiHandlers = class _IssuerApiHandlers {
1575
1575
  authService;
1576
1576
  ledger;
1577
1577
  provider;
@@ -1587,6 +1587,14 @@ var IssuerApiHandlers = class {
1587
1587
  poolsProvider;
1588
1588
  redemption;
1589
1589
  rateLimiter;
1590
+ mintFeeWrapperAddress;
1591
+ /**
1592
+ * Per-token feeBps cache. Refreshed on /config when stale. feeBps
1593
+ * changes only when ops calls `wrapper.setRecipients`, so 5-min TTL
1594
+ * is more than safe for FE display purposes.
1595
+ */
1596
+ feeBpsCache = /* @__PURE__ */ new Map();
1597
+ static FEE_BPS_TTL_MS = 5 * 60 * 1e3;
1590
1598
  constructor(config) {
1591
1599
  this.authService = config.authService;
1592
1600
  this.ledger = config.ledger;
@@ -1606,6 +1614,9 @@ var IssuerApiHandlers = class {
1606
1614
  if (config.feeManager) this.feeManager = config.feeManager;
1607
1615
  if (config.poolsProvider) this.poolsProvider = config.poolsProvider;
1608
1616
  if (config.redemption) this.redemption = config.redemption;
1617
+ if (config.mintFeeWrapperAddress) {
1618
+ this.mintFeeWrapperAddress = (0, import_viem6.getAddress)(config.mintFeeWrapperAddress);
1619
+ }
1609
1620
  }
1610
1621
  // =========================================================================
1611
1622
  // Public handlers (no auth required)
@@ -1705,13 +1716,58 @@ var IssuerApiHandlers = class {
1705
1716
  ...this.contracts,
1706
1717
  pointTokens: Array.from(this.supportedTokens)
1707
1718
  };
1719
+ if (this.mintFeeWrapperAddress) {
1720
+ contracts.mintFeeWrapper = this.mintFeeWrapperAddress;
1721
+ }
1708
1722
  const response = {
1709
1723
  chainId: this.chainId,
1710
1724
  contracts
1711
1725
  };
1726
+ if (this.mintFeeWrapperAddress) {
1727
+ const byToken = await this.resolveFeeBpsByToken(
1728
+ this.mintFeeWrapperAddress
1729
+ );
1730
+ if (byToken) response.mintFeeBpsByToken = byToken;
1731
+ }
1712
1732
  if (this.pafiWebUrl) response.pafiWebUrl = this.pafiWebUrl;
1713
1733
  return response;
1714
1734
  }
1735
+ /**
1736
+ * Read `totalFeeBps(pointToken)` for every supported PointToken from
1737
+ * the wrapper. Cached per-token for 5 minutes. Returns `undefined`
1738
+ * (caller drops the field) if every read fails — FE must treat
1739
+ * "field missing" as "fee unknown, do not display".
1740
+ */
1741
+ async resolveFeeBpsByToken(wrapper) {
1742
+ const now = Date.now();
1743
+ const out = {};
1744
+ let anyFresh = false;
1745
+ await Promise.all(
1746
+ Array.from(this.supportedTokens).map(async (token) => {
1747
+ const cached = this.feeBpsCache.get(token);
1748
+ if (cached && cached.expiresAt > now) {
1749
+ out[token.toLowerCase()] = cached.value;
1750
+ anyFresh = true;
1751
+ return;
1752
+ }
1753
+ try {
1754
+ const bps = await (0, import_core6.getMintFeeBps)(this.provider, wrapper, token);
1755
+ this.feeBpsCache.set(token, {
1756
+ value: bps,
1757
+ expiresAt: now + _IssuerApiHandlers.FEE_BPS_TTL_MS
1758
+ });
1759
+ out[token.toLowerCase()] = bps;
1760
+ anyFresh = true;
1761
+ } catch {
1762
+ if (cached) {
1763
+ out[token.toLowerCase()] = cached.value;
1764
+ anyFresh = true;
1765
+ }
1766
+ }
1767
+ })
1768
+ );
1769
+ return anyFresh ? out : void 0;
1770
+ }
1715
1771
  /** `GET /gas-fee` — quoted in USDT (6-decimal base units). */
1716
1772
  async handleGasFee() {
1717
1773
  if (!this.feeManager) {
@@ -4415,6 +4471,9 @@ function createIssuerService(config) {
4415
4471
  pafiHook: chainAddresses.pafiHook,
4416
4472
  ...config.contracts
4417
4473
  };
4474
+ if (resolvedWrapperAddress !== void 0) {
4475
+ resolvedContracts.mintFeeWrapper = resolvedWrapperAddress;
4476
+ }
4418
4477
  let redemption;
4419
4478
  if (config.redemption) {
4420
4479
  const policyConfig = {
@@ -4445,6 +4504,9 @@ function createIssuerService(config) {
4445
4504
  if (feeManager) handlersConfig.feeManager = feeManager;
4446
4505
  if (config.poolsProvider) handlersConfig.poolsProvider = config.poolsProvider;
4447
4506
  if (redemption) handlersConfig.redemption = redemption;
4507
+ if (resolvedWrapperAddress !== void 0) {
4508
+ handlersConfig.mintFeeWrapperAddress = resolvedWrapperAddress;
4509
+ }
4448
4510
  const handlers = new IssuerApiHandlers(handlersConfig);
4449
4511
  if (config.indexer?.autoStart) {
4450
4512
  for (const idx of indexers.values()) {
@@ -4658,7 +4720,7 @@ var MemoryRedemptionHistoryStore = class {
4658
4720
  };
4659
4721
 
4660
4722
  // src/index.ts
4661
- var PAFI_ISSUER_SDK_VERSION = true ? "0.11.0" : "dev";
4723
+ var PAFI_ISSUER_SDK_VERSION = true ? "0.12.1" : "dev";
4662
4724
  // Annotate the CommonJS export names for ESM import in node:
4663
4725
  0 && (module.exports = {
4664
4726
  AdapterMisconfiguredError,