@haven-fi/solauto-sdk 1.0.804 → 1.0.806

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,10 @@ 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): Promise<OnDemand.PullFeed>;
5
+ export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): Promise<{
6
+ gateway: OnDemand.Gateway;
7
+ feed: OnDemand.PullFeed;
8
+ }>;
6
9
  export declare function buildSwbSubmitResponseTx(conn: Connection, signer: Signer, mint: PublicKey): Promise<TransactionItemInputs | undefined>;
7
10
  export declare function getSwitchboardFeedData(conn: Connection, mints: PublicKey[]): Promise<{
8
11
  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;AAQjD,wBAAsB,WAAW,CAC/B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,8BA2BnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA8C5C;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;AAGvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AASjD,wBAAsB,WAAW,CAC/B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS;;;GAkCnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAmD5C;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"}
@@ -45,6 +45,7 @@ const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
45
45
  const constants_1 = require("../constants");
46
46
  const generalUtils_1 = require("./generalUtils");
47
47
  const solanaUtils_1 = require("./solanaUtils");
48
+ const common_1 = require("@switchboard-xyz/common");
48
49
  async function getPullFeed(conn, mint, wallet) {
49
50
  const dummyWallet = {
50
51
  publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
@@ -53,19 +54,25 @@ async function getPullFeed(conn, mint, wallet) {
53
54
  };
54
55
  const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
55
56
  (0, generalUtils_1.consoleLog)("Pulling SWB program...");
56
- const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
57
+ const { PullFeed, Queue, ON_DEMAND_MAINNET_PID } = OnDemand;
57
58
  const sbProgram = await anchor_1.Program.at(ON_DEMAND_MAINNET_PID, provider);
59
+ const crossbar = new common_1.CrossbarClient("https://integrator-crossbar.mrgn.app/");
60
+ const queue = await Queue.loadDefault(sbProgram);
61
+ const gateway = await queue.fetchGatewayFromCrossbar(crossbar);
58
62
  (0, generalUtils_1.consoleLog)("Pulled SWB program!");
59
63
  (0, generalUtils_1.consoleLog)("Feed id:", constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId);
60
- return new PullFeed(sbProgram, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
64
+ return {
65
+ gateway,
66
+ feed: new PullFeed(sbProgram, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId)),
67
+ };
61
68
  }
62
69
  async function buildSwbSubmitResponseTx(conn, signer, mint) {
63
- const feed = await getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
64
- const gateway = await feed.fetchGatewayUrl();
70
+ const { feed, gateway } = await getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
71
+ // Try to replicate locally in the lambda docker container
65
72
  (0, generalUtils_1.consoleLog)("Fetching crank IX...");
66
73
  const [pullIxs, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
67
74
  const res = await feed.fetchUpdateIx({
68
- gateway,
75
+ gateway: gateway.endpoint(),
69
76
  chain: "solana",
70
77
  network: "mainnet-beta",
71
78
  });
@@ -93,7 +100,7 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
93
100
  lookupTableAddresses: responses
94
101
  .filter((x) => Boolean(x.oracle.lut?.key))
95
102
  .map((x) => x.oracle.lut.key.toString()),
96
- orderPrio: -1,
103
+ orderPrio: -2,
97
104
  };
98
105
  }
99
106
  async function getSwitchboardFeedData(conn, mints) {
@@ -102,7 +109,7 @@ async function getSwitchboardFeedData(conn, mints) {
102
109
  }
103
110
  const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
104
111
  const results = await Promise.all(mints.map(async (mint) => {
105
- const feed = await getPullFeed(conn, mint);
112
+ const { feed } = await getPullFeed(conn, mint);
106
113
  const result = await feed.loadData();
107
114
  const price = Number(result.result.value) / Math.pow(10, 18);
108
115
  const stale = currSlot > result.result.slot.toNumber() + result.maxStaleness;
@@ -12,7 +12,9 @@ import {
12
12
  getPositionExBulk,
13
13
  getSolanaRpcConnection,
14
14
  getSolautoManagedPositions,
15
+ H_SOL,
15
16
  JITO_SOL,
17
+ JUP_SOL,
16
18
  LendingPlatform,
17
19
  LOCAL_IRONFORGE_API_URL,
18
20
  openSolautoPosition,
@@ -67,7 +69,10 @@ export async function main() {
67
69
  ];
68
70
  // const transactionItems = [
69
71
  // new TransactionItem(
70
- // async () => await buildSwbSubmitResponseTx(conn, signer, new PublicKey(NATIVE_MINT))
72
+ // async () => await buildSwbSubmitResponseTx(conn, signer, new PublicKey(NATIVE_MINT)),
73
+ // // async () => await buildSwbSubmitResponseTx(conn, signer, new PublicKey(JUP_SOL)),
74
+ // // async () => await buildSwbSubmitResponseTx(conn, signer, new PublicKey(JITO_SOL))
75
+ // // async () => await buildSwbSubmitResponseTx(conn, signer, new PublicKey(H_SOL))
71
76
  // ),
72
77
  // ];
73
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.804",
3
+ "version": "1.0.806",
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",
@@ -21,7 +21,7 @@
21
21
  "@solana/spl-token": "^0.4.0",
22
22
  "@solana/web3.js": "=1.98.2",
23
23
  "@switchboard-xyz/common": "=3.4.1",
24
- "@switchboard-xyz/on-demand": "=2.16.3",
24
+ "@switchboard-xyz/on-demand": "=2.17.4",
25
25
  "axios": "^1.7.8",
26
26
  "big.js": "^6.2.2",
27
27
  "bs58": "^5.0.0",
@@ -9,7 +9,6 @@ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
9
9
  import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
10
10
  import * as OnDemand from "@switchboard-xyz/on-demand";
11
11
  import Big from "big.js";
12
- import switchboardIdl from "../idls/switchboard.json";
13
12
  import { PRICES, SWITCHBOARD_PRICE_FEED_IDS } from "../constants";
14
13
  import { TransactionItemInputs } from "../types";
15
14
  import {
@@ -18,6 +17,7 @@ import {
18
17
  retryWithExponentialBackoff,
19
18
  } from "./generalUtils";
20
19
  import { getWrappedInstruction } from "./solanaUtils";
20
+ import { CrossbarClient } from "@switchboard-xyz/common";
21
21
 
22
22
  export async function getPullFeed(
23
23
  conn: Connection,
@@ -40,15 +40,22 @@ export async function getPullFeed(
40
40
  );
41
41
 
42
42
  consoleLog("Pulling SWB program...");
43
- const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
43
+ const { PullFeed, Queue, ON_DEMAND_MAINNET_PID } = OnDemand;
44
44
  const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);
45
45
 
46
+ const crossbar = new CrossbarClient("https://integrator-crossbar.mrgn.app/");
47
+ const queue = await Queue.loadDefault(sbProgram);
48
+ const gateway = await queue.fetchGatewayFromCrossbar(crossbar as any);
49
+
46
50
  consoleLog("Pulled SWB program!");
47
51
  consoleLog("Feed id:", SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId);
48
- return new PullFeed(
49
- sbProgram,
50
- new PublicKey(SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId)
51
- );
52
+ return {
53
+ gateway,
54
+ feed: new PullFeed(
55
+ sbProgram,
56
+ new PublicKey(SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId)
57
+ ),
58
+ };
52
59
  }
53
60
 
54
61
  export async function buildSwbSubmitResponseTx(
@@ -56,14 +63,19 @@ export async function buildSwbSubmitResponseTx(
56
63
  signer: Signer,
57
64
  mint: PublicKey
58
65
  ): Promise<TransactionItemInputs | undefined> {
59
- const feed = await getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
66
+ const { feed, gateway } = await getPullFeed(
67
+ conn,
68
+ mint,
69
+ toWeb3JsPublicKey(signer.publicKey)
70
+ );
71
+
72
+ // Try to replicate locally in the lambda docker container
60
73
 
61
- const gateway = await feed.fetchGatewayUrl();
62
74
  consoleLog("Fetching crank IX...");
63
75
  const [pullIxs, responses] = await retryWithExponentialBackoff(
64
76
  async () => {
65
77
  const res = await feed.fetchUpdateIx({
66
- gateway,
78
+ gateway: gateway.endpoint(),
67
79
  chain: "solana",
68
80
  network: "mainnet-beta",
69
81
  });
@@ -99,7 +111,7 @@ export async function buildSwbSubmitResponseTx(
99
111
  lookupTableAddresses: responses
100
112
  .filter((x) => Boolean(x.oracle.lut?.key))
101
113
  .map((x) => x.oracle.lut!.key.toString()),
102
- orderPrio: -1,
114
+ orderPrio: -2,
103
115
  };
104
116
  }
105
117
 
@@ -118,7 +130,7 @@ export async function getSwitchboardFeedData(
118
130
 
119
131
  const results = await Promise.all(
120
132
  mints.map(async (mint) => {
121
- const feed = await getPullFeed(conn, mint);
133
+ const { feed } = await getPullFeed(conn, mint);
122
134
  const result = await feed.loadData();
123
135
  const price = Number(result.result.value) / Math.pow(10, 18);
124
136
  const stale =