@haven-fi/solauto-sdk 1.0.782 → 1.0.784

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;AAGvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAsB,WAAW,CAC/B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,8BAwBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA4C5C;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,36 @@ 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"));
39
35
  const constants_1 = require("../constants");
40
36
  const generalUtils_1 = require("./generalUtils");
41
37
  const solanaUtils_1 = require("./solanaUtils");
42
- function getPullFeed(conn, mint, wallet) {
38
+ async function getPullFeed(conn, mint, wallet) {
43
39
  const dummyWallet = {
44
40
  publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
45
41
  signTransaction: async (tx) => tx,
46
42
  signAllTransactions: async (txs) => txs,
47
43
  };
48
44
  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));
45
+ const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
46
+ const sbProgram = await anchor_1.Program.at(ON_DEMAND_MAINNET_PID, provider);
47
+ console.log(new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId).toString());
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 feed = await getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
52
+ const gateway = await feed.fetchGatewayUrl();
53
+ const [pullIxs, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
56
54
  const res = await feed.fetchUpdateIx({
55
+ gateway: gateway,
57
56
  chain: "solana",
58
- network: "mainnet-beta",
57
+ network: "mainnet",
59
58
  });
60
59
  if (!res[1] || !res[1][0].value) {
61
60
  throw new Error("Unable to fetch Switchboard pull IX");
62
61
  }
63
62
  return res;
64
63
  }, 3, 200);
65
- if (!pullIx) {
64
+ if (!pullIxs || !pullIxs.length) {
66
65
  throw new Error("Unable to fetch SWB crank IX");
67
66
  }
68
67
  const price = responses[0].value.toNumber();
@@ -74,7 +73,7 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
74
73
  time: (0, generalUtils_1.currentUnixSeconds)(),
75
74
  };
76
75
  return {
77
- tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIx)]),
76
+ tx: (0, umi_1.transactionBuilder)(pullIxs.map((x) => (0, solanaUtils_1.getWrappedInstruction)(signer, x))),
78
77
  lookupTableAddresses: responses
79
78
  .filter((x) => Boolean(x.oracle.lut?.key))
80
79
  .map((x) => x.oracle.lut.key.toString()),
@@ -86,7 +85,7 @@ async function getSwitchboardFeedData(conn, mints) {
86
85
  }
87
86
  const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
88
87
  const results = await Promise.all(mints.map(async (mint) => {
89
- const feed = getPullFeed(conn, mint);
88
+ const feed = await getPullFeed(conn, mint);
90
89
  const result = await feed.loadData();
91
90
  const price = Number(result.result.value) / Math.pow(10, 18);
92
91
  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,12 +19,10 @@ 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
- const payForTransaction = true;
25
+ const payForTransaction = false;
31
26
  const testProgram = false;
32
27
  const lpEnv: ProgramEnv = "Prod";
33
28
 
@@ -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.782",
3
+ "version": "1.0.784",
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.11.0",
25
25
  "axios": "^1.7.8",
26
26
  "big.js": "^6.2.2",
27
27
  "bs58": "^5.0.0",
@@ -6,10 +6,9 @@ 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
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,7 +17,7 @@ import {
18
17
  } from "./generalUtils";
19
18
  import { getWrappedInstruction } from "./solanaUtils";
20
19
 
21
- export function getPullFeed(
20
+ export async function getPullFeed(
22
21
  conn: Connection,
23
22
  mint: PublicKey,
24
23
  wallet?: PublicKey
@@ -37,11 +36,12 @@ export function getPullFeed(
37
36
  dummyWallet,
38
37
  AnchorProvider.defaultOptions()
39
38
  );
40
- const program = new Program(switchboardIdl as Idl, provider);
39
+ const { PullFeed, ON_DEMAND_MAINNET_PID } = OnDemand;
40
+ const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);
41
41
 
42
- const { PullFeed } = OnDemand;
42
+ console.log(new PublicKey(SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId).toString())
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,18 @@ 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 feed = await getPullFeed(
55
+ conn,
56
+ mint,
57
+ toWeb3JsPublicKey(signer.publicKey)
58
+ );
59
+ const gateway = await feed.fetchGatewayUrl();
60
+ const [pullIxs, responses] = await retryWithExponentialBackoff(
56
61
  async () => {
57
62
  const res = await feed.fetchUpdateIx({
63
+ gateway: gateway,
58
64
  chain: "solana",
59
- network: "mainnet-beta",
65
+ network: "mainnet",
60
66
  });
61
67
  if (!res[1] || !res[1][0].value) {
62
68
  throw new Error("Unable to fetch Switchboard pull IX");
@@ -67,7 +73,7 @@ export async function buildSwbSubmitResponseTx(
67
73
  200
68
74
  );
69
75
 
70
- if (!pullIx) {
76
+ if (!pullIxs || !pullIxs.length) {
71
77
  throw new Error("Unable to fetch SWB crank IX");
72
78
  }
73
79
 
@@ -81,7 +87,9 @@ export async function buildSwbSubmitResponseTx(
81
87
  };
82
88
 
83
89
  return {
84
- tx: transactionBuilder([getWrappedInstruction(signer, pullIx!)]),
90
+ tx: transactionBuilder(
91
+ pullIxs.map((x) => getWrappedInstruction(signer, x))
92
+ ),
85
93
  lookupTableAddresses: responses
86
94
  .filter((x) => Boolean(x.oracle.lut?.key))
87
95
  .map((x) => x.oracle.lut!.key.toString()),
@@ -103,7 +111,7 @@ export async function getSwitchboardFeedData(
103
111
 
104
112
  const results = await Promise.all(
105
113
  mints.map(async (mint) => {
106
- const feed = getPullFeed(conn, mint);
114
+ const feed = await getPullFeed(conn, mint);
107
115
  const result = await feed.loadData();
108
116
  const price = Number(result.result.value) / Math.pow(10, 18);
109
117
  const stale =