@haven-fi/solauto-sdk 1.0.781 → 1.0.783

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.
@@ -24,7 +24,7 @@ async function getJupPriceData(mints) {
24
24
  throw new Error("Failed to get token prices using Jupiter");
25
25
  }
26
26
  return res;
27
- }, 4)));
27
+ }, 6, 250)));
28
28
  const mergedResults = Object.assign({}, ...results);
29
29
  return mergedResults;
30
30
  }
@@ -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,8BAuBnB;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"}
@@ -22,9 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.getPullFeed = getPullFeed;
30
27
  exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
@@ -35,34 +32,37 @@ const umi_1 = require("@metaplex-foundation/umi");
35
32
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
36
33
  const anchor_1 = require("@coral-xyz/anchor");
37
34
  const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
38
- const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
35
+ const SwbCommon = __importStar(require("@switchboard-xyz/common"));
39
36
  const constants_1 = require("../constants");
40
37
  const generalUtils_1 = require("./generalUtils");
41
38
  const solanaUtils_1 = require("./solanaUtils");
42
- function getPullFeed(conn, mint, wallet) {
39
+ async function getPullFeed(conn, mint, wallet) {
43
40
  const dummyWallet = {
44
41
  publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
45
42
  signTransaction: async (tx) => tx,
46
43
  signAllTransactions: async (txs) => txs,
47
44
  };
48
45
  const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
49
- const program = new anchor_1.Program(switchboard_json_1.default, provider);
50
- const { PullFeed } = OnDemand;
51
- return new PullFeed(program, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
46
+ const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
47
+ const sbProgram = await anchor_1.Program.at(ON_DEMAND_MAINNET_PID, provider);
48
+ return new PullFeed(sbProgram, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
52
49
  }
53
50
  async function buildSwbSubmitResponseTx(conn, signer, mint) {
54
- const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
55
- const [pullIx, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
51
+ const { CrossbarClient } = SwbCommon;
52
+ const crossbar = CrossbarClient.default();
53
+ const feed = await getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
54
+ const [pullIxs, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
56
55
  const res = await feed.fetchUpdateIx({
56
+ gateway: crossbar.crossbarUrl,
57
57
  chain: "solana",
58
- network: "mainnet-beta",
58
+ network: "mainnet",
59
59
  });
60
60
  if (!res[1] || !res[1][0].value) {
61
61
  throw new Error("Unable to fetch Switchboard pull IX");
62
62
  }
63
63
  return res;
64
64
  }, 3, 200);
65
- if (!pullIx) {
65
+ if (!pullIxs || !pullIxs.length) {
66
66
  throw new Error("Unable to fetch SWB crank IX");
67
67
  }
68
68
  const price = responses[0].value.toNumber();
@@ -74,7 +74,7 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
74
74
  time: (0, generalUtils_1.currentUnixSeconds)(),
75
75
  };
76
76
  return {
77
- tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIx)]),
77
+ tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIxs[0])]),
78
78
  lookupTableAddresses: responses
79
79
  .filter((x) => Boolean(x.oracle.lut?.key))
80
80
  .map((x) => x.oracle.lut.key.toString()),
@@ -86,7 +86,7 @@ async function getSwitchboardFeedData(conn, mints) {
86
86
  }
87
87
  const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
88
88
  const results = await Promise.all(mints.map(async (mint) => {
89
- const feed = getPullFeed(conn, mint);
89
+ const feed = await getPullFeed(conn, mint);
90
90
  const result = await feed.loadData();
91
91
  const price = Number(result.result.value) / Math.pow(10, 18);
92
92
  const stale = currSlot > result.result.slot.toNumber() + result.maxStaleness;
@@ -4,16 +4,13 @@ import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
4
4
  import {
5
5
  ClientTransactionsManager,
6
6
  consoleLog,
7
- fetchTokenPrices,
8
7
  getBatches,
9
8
  getClient,
10
- getJupTokenPrices,
11
9
  getPositionExBulk,
12
10
  getSolanaRpcConnection,
13
11
  getSolautoManagedPositions,
14
12
  LendingPlatform,
15
13
  LOCAL_IRONFORGE_API_URL,
16
- POPCAT,
17
14
  PriceType,
18
15
  PriorityFeeSetting,
19
16
  ProgramEnv,
@@ -22,10 +19,8 @@ import {
22
19
  SOLAUTO_TEST_PROGRAM,
23
20
  SolautoClient,
24
21
  TransactionItem,
25
- USDC,
26
22
  } from "../src";
27
23
  import { getSecretKey } from "./shared";
28
- import { NATIVE_MINT } from "@solana/spl-token";
29
24
 
30
25
  const payForTransaction = true;
31
26
  const testProgram = false;
@@ -43,39 +38,32 @@ const signer = createSignerFromKeypair(
43
38
  );
44
39
 
45
40
  export async function main() {
46
- // const client = getClient(LendingPlatform.Marginfi, {
47
- // signer,
48
- // showLogs: true,
49
- // rpcUrl: LOCAL_IRONFORGE_API_URL,
50
- // programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
51
- // lpEnv,
52
- // });
53
-
54
- // await client.initializeExistingSolautoPosition({
55
- // positionId: 1,
56
- // authority: new PublicKey("61rtn5tzVkesapo6Cz83SPoShUfAePSxJsqniuF2wRKC"),
57
- // // lpUserAccount: new PublicKey(
58
- // // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
59
- // // ),
60
- // });
61
-
62
- // const transactionItems = [rebalance(client)];
63
-
64
- // const txManager = new ClientTransactionsManager({
65
- // txHandler: client,
66
- // txRunType: payForTransaction ? "normal" : "only-simulate",
67
- // priorityFeeSetting: PriorityFeeSetting.Default,
68
- // retryConfig: { totalRetries: 2 },
69
- // });
70
- // const statuses = await txManager.send(transactionItems);
71
- // consoleLog(statuses);
72
-
73
- const mints =
74
- "HMQ9EEaLkVCS2R7bRDSKDUT8hzHg2qszG7y6HTfTuT5y,bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1,7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr,EkvNF86bV1SnMtpHXMZMnNnoXMEERs1LNc8jvcTX2RnK,7z2ze7zaSaRhLh6GyTC5VhRsdbHTS8RfsDfDiE7qKzhB,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,BaLL4pwZ3J9T8NtTe7wtfHLYW6fR8RCSY9mDTowKqmXm,BAvLBcZHaZV39PL3EBpSiiuQ1Nov3sBk3QLZoJpipump,F3yxnd4LL4N7ybFzjnDRBMc4d26dTAEviTjd6he3Qppj,Eyina3Cy5auLDYNCxPmqjwPTzxmTtpM2UWz5pE8s2Rnk,BALL1o7LFnCjsw38aE4pDvhbg3nmMeBbJKh3JU51HCr9,So11111111111111111111111111111111111111112"
75
- .split(",")
76
- .map((x) => new PublicKey(x));
77
-
78
- console.log(await fetchTokenPrices(mints));
41
+ const client = getClient(LendingPlatform.Marginfi, {
42
+ signer,
43
+ showLogs: true,
44
+ rpcUrl: LOCAL_IRONFORGE_API_URL,
45
+ programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
46
+ lpEnv,
47
+ });
48
+
49
+ await client.initializeExistingSolautoPosition({
50
+ positionId: 1,
51
+ authority: new PublicKey("HLdUMx3kdM2QDQfHFaDw1QUwLXtRytyaBYm7C1DPG9uX"),
52
+ // lpUserAccount: new PublicKey(
53
+ // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
54
+ // ),
55
+ });
56
+
57
+ const transactionItems = [rebalance(client)];
58
+
59
+ const txManager = new ClientTransactionsManager({
60
+ txHandler: client,
61
+ txRunType: payForTransaction ? "normal" : "only-simulate",
62
+ priorityFeeSetting: PriorityFeeSetting.Default,
63
+ retryConfig: { totalRetries: 2 },
64
+ });
65
+ const statuses = await txManager.send(transactionItems);
66
+ consoleLog(statuses);
79
67
  }
80
68
 
81
69
  async function refreshAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.781",
3
+ "version": "1.0.783",
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.95.8",
23
23
  "@switchboard-xyz/common": "=3.0.12",
24
- "@switchboard-xyz/on-demand": "=1.2.51",
24
+ "@switchboard-xyz/on-demand": "=2.4.1",
25
25
  "axios": "^1.7.8",
26
26
  "big.js": "^6.2.2",
27
27
  "bs58": "^5.0.0",
@@ -34,7 +34,7 @@ export async function getJupPriceData(mints: PublicKey[]) {
34
34
  }
35
35
 
36
36
  return res;
37
- }, 4)
37
+ }, 6, 250)
38
38
  )
39
39
  );
40
40
 
@@ -6,10 +6,10 @@ import {
6
6
  } from "@solana/web3.js";
7
7
  import { Signer, transactionBuilder } from "@metaplex-foundation/umi";
8
8
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
9
- import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
9
+ import { AnchorProvider, Program } from "@coral-xyz/anchor";
10
10
  import * as OnDemand from "@switchboard-xyz/on-demand";
11
+ import * as SwbCommon from "@switchboard-xyz/common";
11
12
  import Big from "big.js";
12
- import switchboardIdl from "../idls/switchboard.json";
13
13
  import { PRICES, SWITCHBOARD_PRICE_FEED_IDS } from "../constants";
14
14
  import { TransactionItemInputs } from "../types";
15
15
  import {
@@ -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
@@ -37,11 +37,11 @@ export function getPullFeed(
37
37
  dummyWallet,
38
38
  AnchorProvider.defaultOptions()
39
39
  );
40
- const program = new Program(switchboardIdl as Idl, provider);
40
+ const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
41
+ const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);
41
42
 
42
- const { PullFeed } = OnDemand;
43
43
  return new PullFeed(
44
- program,
44
+ sbProgram,
45
45
  new PublicKey(SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId)
46
46
  );
47
47
  }
@@ -51,12 +51,16 @@ export async function buildSwbSubmitResponseTx(
51
51
  signer: Signer,
52
52
  mint: PublicKey
53
53
  ): Promise<TransactionItemInputs | undefined> {
54
- const feed = getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
55
- const [pullIx, responses] = await retryWithExponentialBackoff(
54
+ const { CrossbarClient } = SwbCommon;
55
+ const crossbar = CrossbarClient.default();
56
+
57
+ const feed = await getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
58
+ const [pullIxs, responses] = await retryWithExponentialBackoff(
56
59
  async () => {
57
60
  const res = await feed.fetchUpdateIx({
61
+ gateway: crossbar.crossbarUrl,
58
62
  chain: "solana",
59
- network: "mainnet-beta",
63
+ network: "mainnet",
60
64
  });
61
65
  if (!res[1] || !res[1][0].value) {
62
66
  throw new Error("Unable to fetch Switchboard pull IX");
@@ -67,7 +71,7 @@ export async function buildSwbSubmitResponseTx(
67
71
  200
68
72
  );
69
73
 
70
- if (!pullIx) {
74
+ if (!pullIxs || !pullIxs.length) {
71
75
  throw new Error("Unable to fetch SWB crank IX");
72
76
  }
73
77
 
@@ -81,7 +85,7 @@ export async function buildSwbSubmitResponseTx(
81
85
  };
82
86
 
83
87
  return {
84
- tx: transactionBuilder([getWrappedInstruction(signer, pullIx!)]),
88
+ tx: transactionBuilder([getWrappedInstruction(signer, pullIxs[0])]),
85
89
  lookupTableAddresses: responses
86
90
  .filter((x) => Boolean(x.oracle.lut?.key))
87
91
  .map((x) => x.oracle.lut!.key.toString()),
@@ -103,7 +107,7 @@ export async function getSwitchboardFeedData(
103
107
 
104
108
  const results = await Promise.all(
105
109
  mints.map(async (mint) => {
106
- const feed = getPullFeed(conn, mint);
110
+ const feed = await getPullFeed(conn, mint);
107
111
  const result = await feed.loadData();
108
112
  const price = Number(result.result.value) / Math.pow(10, 18);
109
113
  const stale =