veilix-sdk 0.0.4 → 0.0.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.
@@ -3660,7 +3660,7 @@ var WITHDRAW_CIRCUIT_SHA256 = {
3660
3660
  zkey: "64a4d915099f6fe6bfa06e151c254843be8773c7991c742260019dc5184e5d82"
3661
3661
  };
3662
3662
  var CIRCUIT_CDN_PACKAGE = "veilix-sdk";
3663
- var CIRCUIT_CDN_VERSION = "0.0.3";
3663
+ var CIRCUIT_CDN_VERSION = "0.0.4";
3664
3664
  function resolveCircuitPathsFromBase(base) {
3665
3665
  const root = base.endsWith("/") ? base : `${base}/`;
3666
3666
  return {
@@ -12575,6 +12575,52 @@ function formatNoteForDisplay(note, segmentLen = 8) {
12575
12575
  (p) => p.length > segmentLen * 2 ? p.slice(0, segmentLen) + "\u2026" + p.slice(-segmentLen) : p
12576
12576
  ).join("-");
12577
12577
  }
12578
+ async function readOracleGatewayUrls(queue) {
12579
+ const oracleKeys = await queue.fetchOracleKeys();
12580
+ if (oracleKeys.length === 0) return [];
12581
+ const rows = await sb.Oracle.loadMany(queue.program, oracleKeys);
12582
+ return rows.map(
12583
+ (row) => row ? Buffer.from(row.gatewayUri).toString("utf8").replace(/\0+$/, "").trim() : ""
12584
+ ).filter((url) => url.length > 0);
12585
+ }
12586
+ async function firstHealthyGatewayUrl(urls) {
12587
+ try {
12588
+ return await Promise.any(
12589
+ urls.map(async (url) => {
12590
+ const response = await fetch(`${url.replace(/\/$/, "")}/gateway/api/v1/test`, {
12591
+ signal: AbortSignal.timeout(8e3)
12592
+ });
12593
+ if (!response.ok) {
12594
+ throw new Error(`gateway ${url} returned ${response.status}`);
12595
+ }
12596
+ return url;
12597
+ })
12598
+ );
12599
+ } catch (error) {
12600
+ const reason = error instanceof Error ? error.message : "unknown error";
12601
+ throw new Error(`veilix-sdk: no healthy Switchboard gateway (${reason})`);
12602
+ }
12603
+ }
12604
+ function crossbarForQueue(queue) {
12605
+ const client = new CrossbarClient("https://crossbar.switchboard.xyz");
12606
+ const fetchGateway = client.fetchGateway.bind(client);
12607
+ client.fetchGateway = async (network) => {
12608
+ try {
12609
+ return await fetchGateway(network);
12610
+ } catch (error) {
12611
+ const message = error instanceof Error ? error.message : "";
12612
+ if (!message.includes("No gateways available")) {
12613
+ throw error;
12614
+ }
12615
+ const urls = await readOracleGatewayUrls(queue);
12616
+ if (urls.length === 0) {
12617
+ throw error;
12618
+ }
12619
+ return new sb.Gateway(await firstHealthyGatewayUrl(urls));
12620
+ }
12621
+ };
12622
+ return client;
12623
+ }
12578
12624
  function getRangeRiskScoreJob(address) {
12579
12625
  return OracleJob.fromObject({
12580
12626
  tasks: [
@@ -12603,7 +12649,7 @@ async function getOracleQuote(payer, addressToCheck) {
12603
12649
  solanaRPCUrl: rpcUrl,
12604
12650
  queueAddress: getDepositQueueAddress()
12605
12651
  });
12606
- const crossbarClient = CrossbarClient.default();
12652
+ const crossbarClient = crossbarForQueue(queue);
12607
12653
  const feed = {
12608
12654
  name: "Risk Score",
12609
12655
  jobs: [getRangeRiskScoreJob(addressToCheck)],
@@ -12627,7 +12673,7 @@ function getProgramId() {
12627
12673
  }
12628
12674
  return _programId;
12629
12675
  }
12630
- var CONFIG_SEED = Buffer.from("veilix-config");
12676
+ var CONFIG_SEED = Buffer.from("config");
12631
12677
  function getPoolPDA(denominationLamports) {
12632
12678
  const buf = Buffer.alloc(8);
12633
12679
  buf.writeBigUInt64BE(BigInt(denominationLamports));