@pafi-dev/core 0.9.5 → 0.9.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.js CHANGED
@@ -68,7 +68,7 @@ import {
68
68
  verifyBurnRequest,
69
69
  verifyMintRequest,
70
70
  verifyReceiverConsent
71
- } from "./chunk-XNVVZVK6.js";
71
+ } from "./chunk-HJYHGCMT.js";
72
72
  import {
73
73
  pointTokenAbi
74
74
  } from "./chunk-UCO5DXD6.js";
@@ -1210,15 +1210,24 @@ async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fall
1210
1210
  const pool = json.data?.pafiToken?.pool;
1211
1211
  if (!pool) throw new Error("pafiToken or pool not found");
1212
1212
  const isPtToken0 = pool.token0.id.toLowerCase() === pointTokenAddress.toLowerCase();
1213
- const priceStr = isPtToken0 ? pool.token0Price : pool.token1Price;
1214
- if (!priceStr || Number(priceStr) <= 0) {
1215
- throw new Error(`invalid pool price from subgraph: ${priceStr}`);
1213
+ let ptPerUsdtHumanStr;
1214
+ if (isPtToken0) {
1215
+ const usdtPerPtHuman = Number(pool.token0Price);
1216
+ if (!Number.isFinite(usdtPerPtHuman) || usdtPerPtHuman <= 0) {
1217
+ throw new Error(`invalid pool token0Price from subgraph: ${pool.token0Price}`);
1218
+ }
1219
+ ptPerUsdtHumanStr = (1 / usdtPerPtHuman).toFixed(18);
1220
+ } else {
1221
+ ptPerUsdtHumanStr = pool.token1Price;
1222
+ if (!ptPerUsdtHumanStr || Number(ptPerUsdtHumanStr) <= 0) {
1223
+ throw new Error(`invalid pool token1Price from subgraph: ${ptPerUsdtHumanStr}`);
1224
+ }
1216
1225
  }
1217
- const raw = parseBigDecimalTo18(priceStr);
1218
- if (raw === 0n) {
1219
- throw new Error(`pool price parsed to zero: ${priceStr}`);
1226
+ const ptPerUsdt18dec = parseBigDecimalTo18(ptPerUsdtHumanStr);
1227
+ if (ptPerUsdt18dec === 0n) {
1228
+ throw new Error(`pool price parsed to zero: ${ptPerUsdtHumanStr}`);
1220
1229
  }
1221
- return 10n ** 24n / raw;
1230
+ return ptPerUsdt18dec;
1222
1231
  } catch (err) {
1223
1232
  const reason = err instanceof Error ? err.message : String(err);
1224
1233
  if (fallbackPtPriceUsdt === null) {