@blazephoenix/sdk 1.2.0 → 1.2.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
@@ -4768,7 +4768,8 @@ var CHAINS = {
4768
4768
  explorer: "https://robinhoodchain.blockscout.com",
4769
4769
  weth: "0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73",
4770
4770
  usdc: "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
4771
- blockTime: 2
4771
+ blockTime: 0.104
4772
+ // measured ~0.104 s/block
4772
4773
  }
4773
4774
  };
4774
4775
  var ALIASES = {
@@ -4833,7 +4834,7 @@ function urlTransport(url, o) {
4833
4834
  throw new BlazeError("bad_request", `refusing RPC URL "${redact(url)}": use https:// or wss:// (http/ws only for localhost)`);
4834
4835
  }
4835
4836
  const u = url.trim();
4836
- return u.startsWith("ws") ? viem.webSocket(u, { timeout: o.timeoutMs, retryCount: o.retries }) : viem.http(u, { timeout: o.timeoutMs, retryCount: o.retries, batch: o.batch });
4837
+ return u.startsWith("ws") ? viem.webSocket(u, { timeout: o.timeoutMs, retryCount: o.retries }) : viem.http(u, { timeout: o.timeoutMs, retryCount: o.retries, batch: o.batch, fetchOptions: { redirect: "error" } });
4837
4838
  }
4838
4839
  function redact(url) {
4839
4840
  try {
@@ -4981,6 +4982,9 @@ function scrubCause(c, depth = 0) {
4981
4982
  out.name = c.name;
4982
4983
  return out;
4983
4984
  }
4985
+ function untrustedText(t, max = 120) {
4986
+ return (t ?? "").replace(/[^\x20-\x7e]+/g, " ").replace(/\s+/g, " ").trim().slice(0, max);
4987
+ }
4984
4988
  var BlazeError = class extends Error {
4985
4989
  code;
4986
4990
  details;
@@ -5812,6 +5816,20 @@ var BlazePhoenix = class {
5812
5816
  if (typeof req.amountIn === "bigint") v = req.amountIn;
5813
5817
  else if (INT.test(String(req.amountIn).trim())) v = BigInt(String(req.amountIn).trim());
5814
5818
  else throw new BlazeError("bad_request", 'amountIn must be an integer in base units \u2014 use `amount` for human units ("1.5")');
5819
+ if (req.amount !== void 0 && req.amount !== null && req.amount !== "") {
5820
+ const d = await this.decimalsOf(client, chainId, tIn).catch((e) => {
5821
+ throw new BlazeError("bad_request", "amount and amountIn are both set and the decimals could not be read to compare them \u2014 pass only one", { cause: e });
5822
+ });
5823
+ let human;
5824
+ try {
5825
+ human = toBaseUnits(req.amount, d);
5826
+ } catch (e) {
5827
+ throw new BlazeError("bad_request", e.message);
5828
+ }
5829
+ if (human !== v) {
5830
+ throw new BlazeError("bad_request", `amount and amountIn disagree (${human} vs ${v} base units): pass only one`);
5831
+ }
5832
+ }
5815
5833
  } else if (req.amount !== void 0) {
5816
5834
  const d = await this.decimalsOf(client, chainId, tIn).catch((e) => {
5817
5835
  throw new BlazeError("bad_request", `could not read decimals of ${tIn.address} on your RPC \u2014 pass amountIn in base units`, { cause: e });
@@ -5919,13 +5937,15 @@ var BlazePhoenix = class {
5919
5937
  args: [tIn.address, tOut.address, amountIn],
5920
5938
  ...req.blockNumber !== void 0 ? { blockNumber: req.blockNumber } : {}
5921
5939
  });
5940
+ const net = featuresOf(ctx.dep.version).previewAndEncode ? exactOut : exactOut - (exactOut * BigInt(FEE_BPS) + 9999n) / 10000n;
5922
5941
  return {
5923
5942
  chainId: ctx.chainId,
5924
5943
  version: ctx.dep.version,
5925
5944
  tokenIn: tIn.address,
5926
5945
  tokenOut: tOut.address,
5927
5946
  amountIn,
5928
- exactOut,
5947
+ exactOut: net,
5948
+ quoterOut: exactOut,
5929
5949
  route,
5930
5950
  quotedAt: Date.now()
5931
5951
  };
@@ -6190,7 +6210,7 @@ var BlazePhoenix = class {
6190
6210
  } catch (e) {
6191
6211
  if (isTransportError(e)) throw new BlazeError("rpc_error", `simulation: your RPC failed (${e?.message?.split("\n")[0]})`, { cause: e });
6192
6212
  const d = decodeBlazeError(e);
6193
- return { ok: false, error: d ?? { contract: "unknown", name: "revert", reason: e?.message?.split("\n")[0] ?? "execution reverted" } };
6213
+ return { ok: false, error: d ?? { contract: "unknown", name: "revert", reason: untrustedText(e?.message?.split("\n")[0]) || "execution reverted" } };
6194
6214
  }
6195
6215
  }
6196
6216
  /**