@0dotxyz/p0-ts-sdk 1.2.2 → 1.2.4-alpha.0

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
@@ -1,7 +1,7 @@
1
1
  import { PublicKey, SolanaJSONRPCError, ComputeBudgetProgram, SystemProgram, TransactionMessage, VersionedTransaction, Transaction, AddressLookupTableAccount, SYSVAR_RENT_PUBKEY, StakeProgram, TransactionInstruction, LAMPORTS_PER_SOL, SYSVAR_INSTRUCTIONS_PUBKEY } from '@solana/web3.js';
2
2
  import { object, string, enums, array, assert } from 'superstruct';
3
3
  import BigNumber10, { BigNumber } from 'bignumber.js';
4
- import BN11, { BN } from 'bn.js';
4
+ import BN11 from 'bn.js';
5
5
  import { Decimal } from 'decimal.js';
6
6
  import { BorshCoder, BorshAccountsCoder, BorshInstructionCoder, AnchorProvider, Program } from '@coral-xyz/anchor';
7
7
  import { struct, u32, u8 } from '@solana/buffer-layout';
@@ -11,7 +11,7 @@ import { deserialize } from 'borsh';
11
11
  import * as borsh from '@coral-xyz/borsh';
12
12
  import { struct as struct$1, bool, publicKey as publicKey$1, array as array$1, u64 as u64$1, u8 as u8$1, u32 as u32$1, u128 } from '@coral-xyz/borsh';
13
13
  import { SwapApi, Configuration, createJupiterApiClient } from '@jup-ag/api';
14
- import { AnchorUtils, PullFeed, Gateway } from '@switchboard-xyz/on-demand';
14
+ import { AnchorUtils, PullFeed } from '@switchboard-xyz/on-demand';
15
15
  import { CrossbarClient } from '@switchboard-xyz/common';
16
16
 
17
17
  // src/config.ts
@@ -44848,16 +44848,22 @@ async function makeUpdateSwbFeedIx(props) {
44848
44848
  `[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
44849
44849
  )
44850
44850
  );
44851
- const swbProgram = await AnchorUtils.loadProgramFromConnection(props.connection);
44851
+ const dummyWallet = {
44852
+ publicKey: props.feePayer,
44853
+ signTransaction: async (tx) => tx,
44854
+ signAllTransactions: async (txs) => txs
44855
+ };
44856
+ const swbProgram = await AnchorUtils.loadProgramFromConnection(props.connection, dummyWallet);
44852
44857
  const pullFeedInstances = uniqueOracles.map((oracle) => {
44853
44858
  const pullFeed = new PullFeed(swbProgram, oracle.key);
44854
44859
  if (oracle.price?.switchboardData) {
44855
44860
  const swbData = oracle.price?.switchboardData;
44856
- pullFeed.data = {
44861
+ pullFeed.configs = {
44857
44862
  queue: new PublicKey(swbData.queue),
44858
- feedHash: new Uint8Array(Buffer.from(swbData.feedHash, "hex")),
44859
- maxVariance: new BN(swbData.maxVariance),
44860
- minResponses: swbData.minResponses
44863
+ feedHash: Buffer.from(swbData.feedHash, "hex"),
44864
+ maxVariance: Number(swbData.maxVariance),
44865
+ minResponses: swbData.minResponses,
44866
+ minSampleSize: swbData.minResponses
44861
44867
  };
44862
44868
  }
44863
44869
  return pullFeed;
@@ -44869,31 +44875,47 @@ async function makeUpdateSwbFeedIx(props) {
44869
44875
  const crossbarClient = new CrossbarClient(
44870
44876
  process.env.NEXT_PUBLIC_SWITCHBOARD_CROSSSBAR_API || "https://integrator-crossbar.prod.mrgn.app"
44871
44877
  );
44872
- const gatewayUrls = await crossbarClient.fetchGateways("mainnet");
44873
- if (!gatewayUrls || gatewayUrls.length === 0) {
44874
- throw new Error(`No gateways available for mainnet`);
44875
- }
44876
- console.log(`[makeUpdateSwbFeedIx] Fetched ${gatewayUrls.length} gateways`);
44877
- const gatewayUrl = gatewayUrls[0];
44878
- if (!gatewayUrl) {
44879
- throw new Error(`Invalid gateway URL received formainnet`);
44878
+ const onChainDatas = await PullFeed.loadMany(swbProgram, pullFeedInstances);
44879
+ for (let i = 0; i < pullFeedInstances.length; i++) {
44880
+ const feed = pullFeedInstances[i];
44881
+ const onChainData = onChainDatas[i];
44882
+ const configHash = feed.configs?.feedHash ? Buffer.from(feed.configs.feedHash).toString("hex") : "none";
44883
+ const onChainHash = onChainData?.feedHash ? Buffer.from(onChainData.feedHash).toString("hex") : "none";
44884
+ console.log(
44885
+ `[makeUpdateSwbFeedIx] Feed ${feed.pubkey.toBase58()} | configs.feedHash: ${configHash} | onChain.feedHash: ${onChainHash} | loaded: ${!!onChainData}`
44886
+ );
44880
44887
  }
44881
- const gateway = new Gateway(swbProgram, gatewayUrl);
44882
- console.log(
44883
- `[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds via gateway: ${gateway.gatewayUrl}`
44884
- );
44888
+ console.log(`[makeUpdateSwbFeedIx] Fetching update ix for ${pullFeedInstances.length} feeds`);
44885
44889
  console.log(
44886
44890
  `[makeUpdateSwbFeedIx] pullFeedInstances:`,
44887
- pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasData: !!f.data }))
44891
+ pullFeedInstances.map((f) => ({ key: f.pubkey.toBase58(), hasConfigs: !!f.configs }))
44888
44892
  );
44889
44893
  const [pullIx, luts] = await PullFeed.fetchUpdateManyIx(swbProgram, {
44890
44894
  feeds: pullFeedInstances,
44891
- gateway: gateway.gatewayUrl,
44892
44895
  numSignatures: 1,
44893
- payer: props.feePayer,
44894
- crossbarClient
44896
+ crossbarClient,
44897
+ payer: props.feePayer
44895
44898
  });
44896
44899
  console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
44900
+ const feedPubkeySet = new Set(pullFeedInstances.map((f) => f.pubkey.toBase58()));
44901
+ if (pullIx.length >= 2) {
44902
+ const submitIx = pullIx[1];
44903
+ const defaultKey = PublicKey.default.toBase58();
44904
+ const presentFeedKeys = new Set(
44905
+ submitIx.keys.filter((k) => feedPubkeySet.has(k.pubkey.toBase58())).map((k) => k.pubkey.toBase58())
44906
+ );
44907
+ const missingFeedKeys = pullFeedInstances.map((f) => f.pubkey).filter((pk) => !presentFeedKeys.has(pk.toBase58()));
44908
+ let missingIdx = 0;
44909
+ for (const key of submitIx.keys) {
44910
+ if (key.pubkey.toBase58() === defaultKey && missingIdx < missingFeedKeys.length) {
44911
+ console.log(
44912
+ `[makeUpdateSwbFeedIx] Replacing PublicKey.default with ${missingFeedKeys[missingIdx].toBase58()}`
44913
+ );
44914
+ key.pubkey = missingFeedKeys[missingIdx];
44915
+ missingIdx++;
44916
+ }
44917
+ }
44918
+ }
44897
44919
  return { instructions: pullIx, luts };
44898
44920
  }
44899
44921