@haven-fi/solauto-sdk 1.0.783 → 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.
@@ -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):
|
5
|
+
export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): 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,
|
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"}
|
@@ -22,6 +22,9 @@ 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
|
+
};
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
29
|
exports.getPullFeed = getPullFeed;
|
27
30
|
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
@@ -32,37 +35,34 @@ const umi_1 = require("@metaplex-foundation/umi");
|
|
32
35
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
33
36
|
const anchor_1 = require("@coral-xyz/anchor");
|
34
37
|
const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
|
35
|
-
const
|
38
|
+
const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
|
36
39
|
const constants_1 = require("../constants");
|
37
40
|
const generalUtils_1 = require("./generalUtils");
|
38
41
|
const solanaUtils_1 = require("./solanaUtils");
|
39
|
-
|
42
|
+
function getPullFeed(conn, mint, wallet) {
|
40
43
|
const dummyWallet = {
|
41
44
|
publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
|
42
45
|
signTransaction: async (tx) => tx,
|
43
46
|
signAllTransactions: async (txs) => txs,
|
44
47
|
};
|
45
48
|
const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
|
46
|
-
const
|
47
|
-
const
|
48
|
-
return new PullFeed(
|
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));
|
49
52
|
}
|
50
53
|
async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
51
|
-
const
|
52
|
-
const
|
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 () => {
|
54
|
+
const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
|
55
|
+
const [pullIx, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
55
56
|
const res = await feed.fetchUpdateIx({
|
56
|
-
gateway: crossbar.crossbarUrl,
|
57
57
|
chain: "solana",
|
58
|
-
network: "mainnet",
|
58
|
+
network: "mainnet-beta",
|
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 (!
|
65
|
+
if (!pullIx) {
|
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,
|
77
|
+
tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIx)]),
|
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 =
|
89
|
+
const feed = 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;
|
package/local/txSandbox.ts
CHANGED
@@ -48,7 +48,7 @@ export async function main() {
|
|
48
48
|
|
49
49
|
await client.initializeExistingSolautoPosition({
|
50
50
|
positionId: 1,
|
51
|
-
authority: new PublicKey("
|
51
|
+
authority: new PublicKey("61rtn5tzVkesapo6Cz83SPoShUfAePSxJsqniuF2wRKC"),
|
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.
|
3
|
+
"version": "1.0.785",
|
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": "=2.
|
24
|
+
"@switchboard-xyz/on-demand": "=1.2.51",
|
25
25
|
"axios": "^1.7.8",
|
26
26
|
"big.js": "^6.2.2",
|
27
27
|
"bs58": "^5.0.0",
|
@@ -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, 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
|
-
import * as SwbCommon from "@switchboard-xyz/common";
|
12
11
|
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
|
21
|
+
export function getPullFeed(
|
22
22
|
conn: Connection,
|
23
23
|
mint: PublicKey,
|
24
24
|
wallet?: PublicKey
|
@@ -37,11 +37,11 @@ export async function getPullFeed(
|
|
37
37
|
dummyWallet,
|
38
38
|
AnchorProvider.defaultOptions()
|
39
39
|
);
|
40
|
-
const
|
41
|
-
const sbProgram = await Program.at(ON_DEMAND_MAINNET_PID, provider);
|
40
|
+
const program = new Program(switchboardIdl as Idl, provider);
|
42
41
|
|
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,16 +51,12 @@ export async function buildSwbSubmitResponseTx(
|
|
51
51
|
signer: Signer,
|
52
52
|
mint: PublicKey
|
53
53
|
): Promise<TransactionItemInputs | undefined> {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
const feed = await getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
|
58
|
-
const [pullIxs, responses] = await retryWithExponentialBackoff(
|
54
|
+
const feed = getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
|
55
|
+
const [pullIx, responses] = await retryWithExponentialBackoff(
|
59
56
|
async () => {
|
60
57
|
const res = await feed.fetchUpdateIx({
|
61
|
-
gateway: crossbar.crossbarUrl,
|
62
58
|
chain: "solana",
|
63
|
-
network: "mainnet",
|
59
|
+
network: "mainnet-beta",
|
64
60
|
});
|
65
61
|
if (!res[1] || !res[1][0].value) {
|
66
62
|
throw new Error("Unable to fetch Switchboard pull IX");
|
@@ -71,7 +67,7 @@ export async function buildSwbSubmitResponseTx(
|
|
71
67
|
200
|
72
68
|
);
|
73
69
|
|
74
|
-
if (!
|
70
|
+
if (!pullIx) {
|
75
71
|
throw new Error("Unable to fetch SWB crank IX");
|
76
72
|
}
|
77
73
|
|
@@ -85,7 +81,7 @@ export async function buildSwbSubmitResponseTx(
|
|
85
81
|
};
|
86
82
|
|
87
83
|
return {
|
88
|
-
tx: transactionBuilder([getWrappedInstruction(signer,
|
84
|
+
tx: transactionBuilder([getWrappedInstruction(signer, pullIx!)]),
|
89
85
|
lookupTableAddresses: responses
|
90
86
|
.filter((x) => Boolean(x.oracle.lut?.key))
|
91
87
|
.map((x) => x.oracle.lut!.key.toString()),
|
@@ -107,7 +103,7 @@ export async function getSwitchboardFeedData(
|
|
107
103
|
|
108
104
|
const results = await Promise.all(
|
109
105
|
mints.map(async (mint) => {
|
110
|
-
const feed =
|
106
|
+
const feed = getPullFeed(conn, mint);
|
111
107
|
const result = await feed.loadData();
|
112
108
|
const price = Number(result.result.value) / Math.pow(10, 18);
|
113
109
|
const stale =
|