@haven-fi/solauto-sdk 1.0.793 → 1.0.794

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.
@@ -2,7 +2,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
2
2
  import { Signer } from "@metaplex-foundation/umi";
3
3
  import * as OnDemand from "@switchboard-xyz/on-demand";
4
4
  import { TransactionItemInputs } from "../types";
5
- export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): OnDemand.PullFeed;
5
+ export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): Promise<OnDemand.PullFeed>;
6
6
  export declare function buildSwbSubmitResponseTx(conn: Connection, signer: Signer, mint: PublicKey): Promise<TransactionItemInputs | undefined>;
7
7
  export declare function getSwitchboardFeedData(conn: Connection, mints: PublicKey[]): Promise<{
8
8
  mint: PublicKey;
@@ -1 +1 @@
1
- {"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAoC5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,WAEzD"}
1
+ {"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAsB,WAAW,CAC/B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,8BAyBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAwC5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,WAEzD"}
@@ -49,7 +49,7 @@ const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
49
49
  const constants_1 = require("../constants");
50
50
  const generalUtils_1 = require("./generalUtils");
51
51
  const solanaUtils_1 = require("./solanaUtils");
52
- function getPullFeed(conn, mint, wallet) {
52
+ async function getPullFeed(conn, mint, wallet) {
53
53
  const dummyWallet = {
54
54
  publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
55
55
  signTransaction: async (tx) => tx,
@@ -57,22 +57,24 @@ function getPullFeed(conn, mint, wallet) {
57
57
  };
58
58
  const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
59
59
  const program = new anchor_1.Program(switchboard_json_1.default, provider);
60
- const { PullFeed } = OnDemand;
61
- return new PullFeed(program, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
60
+ const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
61
+ const sbProgram = await anchor_1.Program.at(ON_DEMAND_MAINNET_PID, provider);
62
+ return new PullFeed(sbProgram, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
62
63
  }
63
64
  async function buildSwbSubmitResponseTx(conn, signer, mint) {
64
- const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
65
- const [pullIx, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
65
+ const feed = await getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
66
+ const [pullIxs, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
66
67
  const res = await feed.fetchUpdateIx({
68
+ gateway: await feed.fetchGatewayUrl(),
67
69
  chain: "solana",
68
- network: "mainnet-beta",
70
+ network: "mainnet",
69
71
  });
70
72
  if (!res[1] || !res[1][0].value) {
71
73
  throw new Error("Unable to fetch Switchboard pull IX");
72
74
  }
73
75
  return res;
74
76
  }, 3, 200);
75
- if (!pullIx) {
77
+ if (!pullIxs || !pullIxs.length) {
76
78
  throw new Error("Unable to fetch SWB crank IX");
77
79
  }
78
80
  const price = responses[0].value.toNumber();
@@ -84,10 +86,11 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
84
86
  time: (0, generalUtils_1.currentUnixSeconds)(),
85
87
  };
86
88
  return {
87
- tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIx)]),
89
+ tx: (0, umi_1.transactionBuilder)(pullIxs.map((x) => (0, solanaUtils_1.getWrappedInstruction)(signer, x))),
88
90
  lookupTableAddresses: responses
89
91
  .filter((x) => Boolean(x.oracle.lut?.key))
90
92
  .map((x) => x.oracle.lut.key.toString()),
93
+ orderPrio: -1,
91
94
  };
92
95
  }
93
96
  async function getSwitchboardFeedData(conn, mints) {
@@ -96,7 +99,7 @@ async function getSwitchboardFeedData(conn, mints) {
96
99
  }
97
100
  const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
98
101
  const results = await Promise.all(mints.map(async (mint) => {
99
- const feed = getPullFeed(conn, mint);
102
+ const feed = await getPullFeed(conn, mint);
100
103
  const result = await feed.loadData();
101
104
  const price = Number(result.result.value) / Math.pow(10, 18);
102
105
  const stale = currSlot > result.result.slot.toNumber() + result.maxStaleness;
@@ -48,7 +48,7 @@ export async function main() {
48
48
 
49
49
  await client.initializeExistingSolautoPosition({
50
50
  positionId: 1,
51
- authority: new PublicKey("61rtn5tzVkesapo6Cz83SPoShUfAePSxJsqniuF2wRKC"),
51
+ authority: new PublicKey("R8Nnj1UqK1BRPnfJYj7MvfPUK3GmEzmgh1CwFFtUNsF"),
52
52
  // lpUserAccount: new PublicKey(
53
53
  // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
54
54
  // ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.793",
3
+ "version": "1.0.794",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -12,16 +12,16 @@
12
12
  "test:unit": "ts-mocha -p ./tsconfig.json -t 1000000 tests/unit/**/*.ts"
13
13
  },
14
14
  "dependencies": {
15
- "@coral-xyz/anchor": "^0.30.1",
15
+ "@coral-xyz/anchor": "=0.31.1",
16
16
  "@jup-ag/api": "=6.0.24",
17
17
  "@metaplex-foundation/umi": "^0.9.1",
18
18
  "@metaplex-foundation/umi-bundle-defaults": "^0.9.1",
19
19
  "@metaplex-foundation/umi-signer-wallet-adapters": "^0.9.1",
20
20
  "@metaplex-foundation/umi-web3js-adapters": "^0.9.1",
21
21
  "@solana/spl-token": "^0.4.0",
22
- "@solana/web3.js": "=1.95.8",
23
- "@switchboard-xyz/common": "=3.0.12",
24
- "@switchboard-xyz/on-demand": "=1.2.51",
22
+ "@solana/web3.js": "=1.98.2",
23
+ "@switchboard-xyz/common": "=3.4.1",
24
+ "@switchboard-xyz/on-demand": "=2.14.4",
25
25
  "axios": "^1.7.8",
26
26
  "big.js": "^6.2.2",
27
27
  "bs58": "^5.0.0",
@@ -18,7 +18,7 @@ import {
18
18
  } from "./generalUtils";
19
19
  import { getWrappedInstruction } from "./solanaUtils";
20
20
 
21
- export function getPullFeed(
21
+ export async function getPullFeed(
22
22
  conn: Connection,
23
23
  mint: PublicKey,
24
24
  wallet?: PublicKey
@@ -39,9 +39,11 @@ export function getPullFeed(
39
39
  );
40
40
  const program = new Program(switchboardIdl as Idl, provider);
41
41
 
42
- const { PullFeed } = OnDemand;
42
+ const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
43
+ const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);
44
+
43
45
  return new PullFeed(
44
- program,
46
+ sbProgram,
45
47
  new PublicKey(SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId)
46
48
  );
47
49
  }
@@ -51,12 +53,13 @@ export async function buildSwbSubmitResponseTx(
51
53
  signer: Signer,
52
54
  mint: PublicKey
53
55
  ): Promise<TransactionItemInputs | undefined> {
54
- const feed = getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
55
- const [pullIx, responses] = await retryWithExponentialBackoff(
56
+ const feed = await getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
57
+ const [pullIxs, responses] = await retryWithExponentialBackoff(
56
58
  async () => {
57
59
  const res = await feed.fetchUpdateIx({
60
+ gateway: await feed.fetchGatewayUrl(),
58
61
  chain: "solana",
59
- network: "mainnet-beta",
62
+ network: "mainnet",
60
63
  });
61
64
  if (!res[1] || !res[1][0].value) {
62
65
  throw new Error("Unable to fetch Switchboard pull IX");
@@ -67,7 +70,7 @@ export async function buildSwbSubmitResponseTx(
67
70
  200
68
71
  );
69
72
 
70
- if (!pullIx) {
73
+ if (!pullIxs || !pullIxs.length) {
71
74
  throw new Error("Unable to fetch SWB crank IX");
72
75
  }
73
76
 
@@ -81,10 +84,13 @@ export async function buildSwbSubmitResponseTx(
81
84
  };
82
85
 
83
86
  return {
84
- tx: transactionBuilder([getWrappedInstruction(signer, pullIx!)]),
87
+ tx: transactionBuilder(
88
+ pullIxs.map((x) => getWrappedInstruction(signer, x))
89
+ ),
85
90
  lookupTableAddresses: responses
86
91
  .filter((x) => Boolean(x.oracle.lut?.key))
87
92
  .map((x) => x.oracle.lut!.key.toString()),
93
+ orderPrio: -1,
88
94
  };
89
95
  }
90
96
 
@@ -103,7 +109,7 @@ export async function getSwitchboardFeedData(
103
109
 
104
110
  const results = await Promise.all(
105
111
  mints.map(async (mint) => {
106
- const feed = getPullFeed(conn, mint);
112
+ const feed = await getPullFeed(conn, mint);
107
113
  const result = await feed.loadData();
108
114
  const price = Number(result.result.value) / Math.pow(10, 18);
109
115
  const stale =