@haven-fi/solauto-sdk 1.0.784 → 1.0.785
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/idls/switchboard.json +1949 -0
- package/dist/utils/switchboardUtils.d.ts +1 -1
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +14 -13
- package/local/txSandbox.ts +2 -2
- package/package.json +5 -5
- package/src/idls/switchboard.json +1949 -0
- package/src/utils/switchboardUtils.ts +12 -20
@@ -6,9 +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, Program } from "@coral-xyz/anchor";
|
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";
|
12
13
|
import { PRICES, SWITCHBOARD_PRICE_FEED_IDS } from "../constants";
|
13
14
|
import { TransactionItemInputs } from "../types";
|
14
15
|
import {
|
@@ -17,7 +18,7 @@ import {
|
|
17
18
|
} from "./generalUtils";
|
18
19
|
import { getWrappedInstruction } from "./solanaUtils";
|
19
20
|
|
20
|
-
export
|
21
|
+
export function getPullFeed(
|
21
22
|
conn: Connection,
|
22
23
|
mint: PublicKey,
|
23
24
|
wallet?: PublicKey
|
@@ -36,12 +37,11 @@ export async function getPullFeed(
|
|
36
37
|
dummyWallet,
|
37
38
|
AnchorProvider.defaultOptions()
|
38
39
|
);
|
39
|
-
const
|
40
|
-
const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);
|
40
|
+
const program = new Program(switchboardIdl as Idl, provider);
|
41
41
|
|
42
|
-
|
42
|
+
const { PullFeed } = OnDemand;
|
43
43
|
return new PullFeed(
|
44
|
-
|
44
|
+
program,
|
45
45
|
new PublicKey(SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId)
|
46
46
|
);
|
47
47
|
}
|
@@ -51,18 +51,12 @@ export async function buildSwbSubmitResponseTx(
|
|
51
51
|
signer: Signer,
|
52
52
|
mint: PublicKey
|
53
53
|
): Promise<TransactionItemInputs | undefined> {
|
54
|
-
const feed =
|
55
|
-
|
56
|
-
mint,
|
57
|
-
toWeb3JsPublicKey(signer.publicKey)
|
58
|
-
);
|
59
|
-
const gateway = await feed.fetchGatewayUrl();
|
60
|
-
const [pullIxs, responses] = await retryWithExponentialBackoff(
|
54
|
+
const feed = getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
|
55
|
+
const [pullIx, responses] = await retryWithExponentialBackoff(
|
61
56
|
async () => {
|
62
57
|
const res = await feed.fetchUpdateIx({
|
63
|
-
gateway: gateway,
|
64
58
|
chain: "solana",
|
65
|
-
network: "mainnet",
|
59
|
+
network: "mainnet-beta",
|
66
60
|
});
|
67
61
|
if (!res[1] || !res[1][0].value) {
|
68
62
|
throw new Error("Unable to fetch Switchboard pull IX");
|
@@ -73,7 +67,7 @@ export async function buildSwbSubmitResponseTx(
|
|
73
67
|
200
|
74
68
|
);
|
75
69
|
|
76
|
-
if (!
|
70
|
+
if (!pullIx) {
|
77
71
|
throw new Error("Unable to fetch SWB crank IX");
|
78
72
|
}
|
79
73
|
|
@@ -87,9 +81,7 @@ export async function buildSwbSubmitResponseTx(
|
|
87
81
|
};
|
88
82
|
|
89
83
|
return {
|
90
|
-
tx: transactionBuilder(
|
91
|
-
pullIxs.map((x) => getWrappedInstruction(signer, x))
|
92
|
-
),
|
84
|
+
tx: transactionBuilder([getWrappedInstruction(signer, pullIx!)]),
|
93
85
|
lookupTableAddresses: responses
|
94
86
|
.filter((x) => Boolean(x.oracle.lut?.key))
|
95
87
|
.map((x) => x.oracle.lut!.key.toString()),
|
@@ -111,7 +103,7 @@ export async function getSwitchboardFeedData(
|
|
111
103
|
|
112
104
|
const results = await Promise.all(
|
113
105
|
mints.map(async (mint) => {
|
114
|
-
const feed =
|
106
|
+
const feed = getPullFeed(conn, mint);
|
115
107
|
const result = await feed.loadData();
|
116
108
|
const price = Number(result.result.value) / Math.pow(10, 18);
|
117
109
|
const stale =
|