@haven-fi/solauto-sdk 1.0.325 → 1.0.327
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/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +16 -6
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +9 -2
- package/local/{createFeeAccounts.ts → createTokenAccounts.ts} +10 -6
- package/package.json +2 -2
- package/src/utils/jitoUtils.ts +17 -8
- package/src/utils/switchboardUtils.ts +14 -6
- package/tests/unit/accounts.ts +52 -25
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,MAAM,iBAAiB,CAAC;AAGlE,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAK9C,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwB,MAAM,iBAAiB,CAAC;AAGlE,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAK9C,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AAuHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,YAAY,CAAC,EAAE,OAAO,EACtB,kBAAkB,GAAE,kBAA2C,GAC9D,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA8C/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -85,12 +85,22 @@ async function pollBundleStatus(bundleId, interval = 1000, timeout = 40000) {
|
|
85
85
|
return [];
|
86
86
|
}
|
87
87
|
async function sendJitoBundle(transactions) {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
let resp;
|
89
|
+
try {
|
90
|
+
resp = await axios_1.default.post(`${solautoConstants_1.JITO_BLOCK_ENGINE}/api/v1/bundles`, {
|
91
|
+
jsonrpc: "2.0",
|
92
|
+
id: 1,
|
93
|
+
method: "sendBundle",
|
94
|
+
params: [transactions],
|
95
|
+
});
|
96
|
+
}
|
97
|
+
catch (e) {
|
98
|
+
if (e.response) {
|
99
|
+
console.error("Jito send bundle error:", e.response.data);
|
100
|
+
console.error("Jito send bundle error:", e.response.data.error);
|
101
|
+
throw e;
|
102
|
+
}
|
103
|
+
}
|
94
104
|
const bundleId = resp.data.result;
|
95
105
|
(0, generalUtils_1.consoleLog)("Bundle ID:", bundleId);
|
96
106
|
return bundleId ? await pollBundleStatus(bundleId) : [];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAkB,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAOtE,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,YAsBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,E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CAyBnB"}
|
@@ -61,6 +61,13 @@ async function getSwitchboardPrices(mints) {
|
|
61
61
|
return [];
|
62
62
|
}
|
63
63
|
const crossbar = new on_demand_1.CrossbarClient("https://crossbar.switchboard.xyz");
|
64
|
-
const results = await (0, generalUtils_1.retryWithExponentialBackoff)(async () =>
|
65
|
-
|
64
|
+
const results = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
65
|
+
const res = await crossbar.simulateSolanaFeeds("mainnet", mints.map((x) => switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[x.toString()]));
|
66
|
+
const prices = res.flatMap((x) => x.results[0]);
|
67
|
+
if (prices.find((x) => x === -Infinity || !Number.isFinite(x))) {
|
68
|
+
throw new Error("Unable to fetch Switchboard prices");
|
69
|
+
}
|
70
|
+
return prices;
|
71
|
+
}, 8, 250);
|
72
|
+
return results;
|
66
73
|
}
|
@@ -1,5 +1,9 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
ALL_SUPPORTED_TOKENS,
|
4
|
+
SOLAUTO_FEES_WALLET,
|
5
|
+
SOLAUTO_MANAGER,
|
6
|
+
} from "../src/constants";
|
3
7
|
import {
|
4
8
|
buildHeliusApiUrl,
|
5
9
|
createAssociatedTokenAccountUmiIx,
|
@@ -16,12 +20,12 @@ import {
|
|
16
20
|
transactionBuilder,
|
17
21
|
} from "@metaplex-foundation/umi";
|
18
22
|
|
19
|
-
async function
|
23
|
+
async function createTokenAccounts(wallet: PublicKey) {
|
20
24
|
let [connection, umi] = getSolanaRpcConnection(
|
21
25
|
buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
|
22
26
|
);
|
23
27
|
|
24
|
-
const secretKey = getSecretKey(
|
28
|
+
const secretKey = getSecretKey();
|
25
29
|
const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
|
26
30
|
const signer = createSignerFromKeypair(umi, signerKeypair);
|
27
31
|
|
@@ -29,7 +33,7 @@ async function create() {
|
|
29
33
|
|
30
34
|
const tokenAccounts = await umi.rpc.getAccounts(
|
31
35
|
ALL_SUPPORTED_TOKENS.map((x) =>
|
32
|
-
publicKey(getTokenAccount(
|
36
|
+
publicKey(getTokenAccount(wallet, new PublicKey(x)))
|
33
37
|
)
|
34
38
|
);
|
35
39
|
|
@@ -37,7 +41,7 @@ async function create() {
|
|
37
41
|
if (!accounts[0].exists) {
|
38
42
|
const tx = createAssociatedTokenAccountUmiIx(
|
39
43
|
signer,
|
40
|
-
|
44
|
+
wallet,
|
41
45
|
new PublicKey(accounts[1])
|
42
46
|
);
|
43
47
|
await sendSingleOptimizedTransaction(
|
@@ -49,4 +53,4 @@ async function create() {
|
|
49
53
|
}
|
50
54
|
}
|
51
55
|
|
52
|
-
|
56
|
+
createTokenAccounts(SOLAUTO_FEES_WALLET);
|
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.327",
|
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",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"update-lut:solauto": "npx ts-node local/updateSolautoLUT.ts",
|
15
15
|
"update-lut:marginfi": "npx ts-node local/updateMarginfiLUT.ts",
|
16
16
|
"create-ism-accounts": "npx ts-node local/createISMAccounts.ts",
|
17
|
-
"create-
|
17
|
+
"create-token-accounts": "npx ts-node local/createTokenAccounts.ts"
|
18
18
|
},
|
19
19
|
"dependencies": {
|
20
20
|
"@coral-xyz/anchor": "^0.30.1",
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -127,15 +127,24 @@ async function pollBundleStatus(
|
|
127
127
|
}
|
128
128
|
|
129
129
|
async function sendJitoBundle(transactions: string[]): Promise<string[]> {
|
130
|
-
|
131
|
-
|
132
|
-
{
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
130
|
+
let resp: any;
|
131
|
+
try {
|
132
|
+
resp = await axios.post<{ result: string }>(
|
133
|
+
`${JITO_BLOCK_ENGINE}/api/v1/bundles`,
|
134
|
+
{
|
135
|
+
jsonrpc: "2.0",
|
136
|
+
id: 1,
|
137
|
+
method: "sendBundle",
|
138
|
+
params: [transactions],
|
139
|
+
}
|
140
|
+
);
|
141
|
+
} catch (e: any) {
|
142
|
+
if (e.response) {
|
143
|
+
console.error("Jito send bundle error:", e.response.data);
|
144
|
+
console.error("Jito send bundle error:", e.response.data.error);
|
145
|
+
throw e;
|
137
146
|
}
|
138
|
-
|
147
|
+
}
|
139
148
|
|
140
149
|
const bundleId = resp.data.result;
|
141
150
|
consoleLog("Bundle ID:", bundleId);
|
@@ -14,7 +14,7 @@ import {
|
|
14
14
|
fromWeb3JsInstruction,
|
15
15
|
toWeb3JsPublicKey,
|
16
16
|
} from "@metaplex-foundation/umi-web3js-adapters";
|
17
|
-
import { retryWithExponentialBackoff } from "./generalUtils";
|
17
|
+
import { retryWithExponentialBackoff, zip } from "./generalUtils";
|
18
18
|
|
19
19
|
export function getPullFeed(
|
20
20
|
conn: Connection,
|
@@ -108,14 +108,22 @@ export async function getSwitchboardPrices(
|
|
108
108
|
|
109
109
|
const crossbar = new CrossbarClient("https://crossbar.switchboard.xyz");
|
110
110
|
const results = await retryWithExponentialBackoff(
|
111
|
-
async () =>
|
112
|
-
await crossbar.simulateSolanaFeeds(
|
111
|
+
async () => {
|
112
|
+
const res = await crossbar.simulateSolanaFeeds(
|
113
113
|
"mainnet",
|
114
114
|
mints.map((x) => SWITCHBOARD_PRICE_FEED_IDS[x.toString()])
|
115
|
-
)
|
115
|
+
);
|
116
|
+
|
117
|
+
const prices = res.flatMap((x) => x.results[0]);
|
118
|
+
if (prices.find((x) => x === -Infinity || !Number.isFinite(x))) {
|
119
|
+
throw new Error("Unable to fetch Switchboard prices");
|
120
|
+
}
|
121
|
+
|
122
|
+
return prices;
|
123
|
+
},
|
116
124
|
8,
|
117
|
-
|
125
|
+
250
|
118
126
|
);
|
119
127
|
|
120
|
-
return results
|
128
|
+
return results;
|
121
129
|
}
|
package/tests/unit/accounts.ts
CHANGED
@@ -9,42 +9,69 @@ import {
|
|
9
9
|
} from "../../src/utils/solanaUtils";
|
10
10
|
import { publicKey } from "@metaplex-foundation/umi";
|
11
11
|
import { assert } from "chai";
|
12
|
-
import {
|
13
|
-
|
12
|
+
import {
|
13
|
+
getAllMarginfiAccountsByAuthority,
|
14
|
+
getTokenAccount,
|
15
|
+
} from "../../src/utils";
|
16
|
+
import {
|
17
|
+
MARGINFI_ACCOUNTS,
|
18
|
+
SOLAUTO_FEES_WALLET,
|
19
|
+
SOLAUTO_MANAGER,
|
20
|
+
} from "../../src/constants";
|
14
21
|
import { PublicKey } from "@solana/web3.js";
|
15
22
|
import { safeFetchAllMarginfiAccount } from "../../src/marginfi-sdk";
|
23
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
);
|
25
|
+
async function hasTokenAccounts(wallet: PublicKey) {
|
26
|
+
let [_, umi] = getSolanaRpcConnection(
|
27
|
+
buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
|
28
|
+
);
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
30
|
+
const tokenAccounts = await umi.rpc.getAccounts(
|
31
|
+
ALL_SUPPORTED_TOKENS.map((x) =>
|
32
|
+
publicKey(getTokenAccount(wallet, new PublicKey(x)))
|
33
|
+
)
|
34
|
+
);
|
35
|
+
for (let i = 0; i < tokenAccounts.length; i++) {
|
36
|
+
console.log(tokenAccounts[i].publicKey.toString());
|
37
|
+
if (!tokenAccounts[i].exists) {
|
38
|
+
console.log(
|
39
|
+
`Missing ${wallet.toString()} TA for `,
|
40
|
+
TOKEN_INFO[ALL_SUPPORTED_TOKENS[i].toString()].ticker
|
41
|
+
);
|
36
42
|
}
|
37
|
-
|
43
|
+
}
|
44
|
+
assert(tokenAccounts.filter((x) => !x.exists).length === 0);
|
45
|
+
}
|
46
|
+
|
47
|
+
describe("Assert Solauto fee token accounts are created", async () => {
|
48
|
+
it("all Solauto fee token accounts created", async () => {
|
49
|
+
await hasTokenAccounts(SOLAUTO_FEES_WALLET);
|
38
50
|
});
|
39
51
|
|
40
52
|
it("ISM accounts for every supported Marginfi group", async () => {
|
41
|
-
let [
|
53
|
+
let [_, umi] = getSolanaRpcConnection(
|
42
54
|
buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
|
43
55
|
);
|
44
56
|
|
45
|
-
const
|
46
|
-
|
47
|
-
|
57
|
+
const ismAccounts = await getAllMarginfiAccountsByAuthority(
|
58
|
+
umi,
|
59
|
+
SOLAUTO_MANAGER,
|
60
|
+
undefined,
|
61
|
+
false
|
62
|
+
);
|
63
|
+
const ismData = await safeFetchAllMarginfiAccount(
|
64
|
+
umi,
|
65
|
+
ismAccounts.map((x) => publicKey(x.marginfiAccount))
|
66
|
+
);
|
67
|
+
const supportedMarginfiGroups = Object.keys(MARGINFI_ACCOUNTS).map(
|
68
|
+
(x) => new PublicKey(x)
|
69
|
+
);
|
70
|
+
const missingIsmAccounts = supportedMarginfiGroups.filter(
|
71
|
+
(group) => !ismData.find((x) => group.equals(toWeb3JsPublicKey(x.group)))
|
72
|
+
);
|
48
73
|
|
74
|
+
console.log("Missing ISM accounts", missingIsmAccounts);
|
75
|
+
assert(missingIsmAccounts.length === 0);
|
49
76
|
});
|
50
77
|
});
|