@haven-fi/solauto-sdk 1.0.332 → 1.0.334
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/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +13 -6
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +4 -4
- package/dist/utils/priceUtils.d.ts +2 -1
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +28 -9
- package/dist/utils/switchboardUtils.d.ts +0 -1
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +0 -16
- package/package.json +1 -1
- package/src/transactions/transactionsManager.ts +27 -16
- package/src/utils/jitoUtils.ts +3 -5
- package/src/utils/priceUtils.ts +51 -12
- package/src/utils/switchboardUtils.ts +1 -30
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAW7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,W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CAAC,YAAY;YA6CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,mBAAmB;YAoBb,SAAS;IAgBV,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IA4FzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YAmCxB,6BAA6B;
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAW7D,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAMjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IARtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACjB,WAAW,EAAE,OAAO,CAAS;gBAG3B,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAKV,OAAO,CAAC,UAAU,EAAE,MAAM;IAMhC,cAAc,IAAI,MAAM,EAAE;CAY3B;AAyFD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM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eAAe;CAmD9B"}
|
@@ -349,14 +349,21 @@ class TransactionsManager {
|
|
349
349
|
transactions.push(await set.getSingleTransaction());
|
350
350
|
}
|
351
351
|
this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum);
|
352
|
-
|
353
|
-
|
354
|
-
|
352
|
+
let txSigs;
|
353
|
+
let error;
|
354
|
+
try {
|
355
|
+
txSigs = await (0, jitoUtils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.signer, transactions, false, this.priorityFeeSetting);
|
355
356
|
}
|
356
|
-
|
357
|
-
|
358
|
-
|
357
|
+
catch (e) {
|
358
|
+
error = e.message;
|
359
|
+
}
|
360
|
+
if (error || !Boolean(txSigs) || txSigs?.length === 0) {
|
361
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Failed, attemptNum, txSigs, true, error);
|
362
|
+
if (error) {
|
363
|
+
throw new Error(error ? error : "Unknown error");
|
364
|
+
}
|
359
365
|
}
|
366
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Successful, attemptNum, txSigs);
|
360
367
|
}, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
|
361
368
|
this.updateStatusForSets(itemSets, TransactionStatus.Failed, num, undefined, true, e.message);
|
362
369
|
throw e;
|
@@ -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;AAwHD,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
@@ -95,8 +95,11 @@ async function sendJitoBundle(transactions) {
|
|
95
95
|
});
|
96
96
|
}
|
97
97
|
catch (e) {
|
98
|
-
if (e.response) {
|
98
|
+
if (e.response.data.error) {
|
99
99
|
console.error("Jito send bundle error:", e.response.data.error);
|
100
|
+
throw new Error(e.response.data.error.message);
|
101
|
+
}
|
102
|
+
else {
|
100
103
|
throw e;
|
101
104
|
}
|
102
105
|
}
|
@@ -115,9 +118,6 @@ async function sendJitoBundledTransactions(umi, signer, txs, simulateOnly, prior
|
|
115
118
|
: undefined;
|
116
119
|
let builtTxs = await umiToVersionedTransactions(umi, signer, txs, true, // false if simulating first and rebuilding later
|
117
120
|
feeEstimates);
|
118
|
-
for (let i = 0; i < txs.length; i++) {
|
119
|
-
(0, generalUtils_1.consoleLog)("Transaction", i, txs[i].getInstructions());
|
120
|
-
}
|
121
121
|
// const simulationResults = await simulateJitoBundle(umi, builtTxs);
|
122
122
|
if (!simulateOnly) {
|
123
123
|
// let builtTxs = await umiToVersionedTransactions(
|
@@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { PublicKey as UmiPublicKey } from "@metaplex-foundation/umi";
|
3
3
|
export declare function fetchTokenPrices(mints: PublicKey[]): Promise<number[]>;
|
4
4
|
export declare function getPythPrices(mints: PublicKey[]): Promise<number[]>;
|
5
|
-
export declare function
|
5
|
+
export declare function getSwitchboardPrices(mints: PublicKey[]): Promise<number[]>;
|
6
6
|
export declare function getJupTokenPrices(mints: PublicKey[]): Promise<number[]>;
|
7
|
+
export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | undefined): number | undefined;
|
7
8
|
//# sourceMappingURL=priceUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAarE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAuC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAmCnB;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAoBzD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.fetchTokenPrices = fetchTokenPrices;
|
4
4
|
exports.getPythPrices = getPythPrices;
|
5
|
-
exports.
|
5
|
+
exports.getSwitchboardPrices = getSwitchboardPrices;
|
6
6
|
exports.getJupTokenPrices = getJupTokenPrices;
|
7
|
+
exports.safeGetPrice = safeGetPrice;
|
7
8
|
const pythConstants_1 = require("../constants/pythConstants");
|
8
9
|
const numberUtils_1 = require("./numberUtils");
|
9
10
|
const solautoConstants_1 = require("../constants/solautoConstants");
|
10
11
|
const switchboardConstants_1 = require("../constants/switchboardConstants");
|
11
12
|
const generalUtils_1 = require("./generalUtils");
|
12
|
-
const
|
13
|
+
const on_demand_1 = require("@switchboard-xyz/on-demand");
|
13
14
|
async function fetchTokenPrices(mints) {
|
14
15
|
const currentTime = (0, generalUtils_1.currentUnixSeconds)();
|
15
16
|
if (!mints.some((mint) => !(mint.toString() in solautoConstants_1.PRICES) ||
|
@@ -20,8 +21,9 @@ async function fetchTokenPrices(mints) {
|
|
20
21
|
const switchboardMints = mints.filter((x) => x.toString() in switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS);
|
21
22
|
const [pythData, switchboardData] = await Promise.all([
|
22
23
|
(0, generalUtils_1.zip)(pythMints, await getPythPrices(pythMints)),
|
23
|
-
(0, generalUtils_1.zip)(switchboardMints, await
|
24
|
+
(0, generalUtils_1.zip)(switchboardMints, await getSwitchboardPrices(switchboardMints)),
|
24
25
|
]);
|
26
|
+
(0, generalUtils_1.consoleLog)([...pythData, ...switchboardData]);
|
25
27
|
const prices = mints.map((mint) => {
|
26
28
|
const item = [...pythData, ...switchboardData].find((data) => data[0].equals(mint));
|
27
29
|
return item ? item[1] : 0;
|
@@ -62,22 +64,39 @@ async function getPythPrices(mints) {
|
|
62
64
|
}, 5, 200);
|
63
65
|
return prices;
|
64
66
|
}
|
65
|
-
function
|
66
|
-
if (
|
67
|
-
return
|
67
|
+
async function getSwitchboardPrices(mints) {
|
68
|
+
if (mints.length === 0) {
|
69
|
+
return [];
|
68
70
|
}
|
69
|
-
|
71
|
+
const crossbar = new on_demand_1.CrossbarClient("https://crossbar.switchboard.xyz");
|
72
|
+
let prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
73
|
+
const res = await crossbar.simulateSolanaFeeds("mainnet", mints.map((x) => switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[x.toString()]));
|
74
|
+
const prices = res.flatMap((x) => x.results[0]);
|
75
|
+
if (prices.find((x) => !x || x === -Infinity)) {
|
76
|
+
throw new Error("Unable to fetch Switchboard prices");
|
77
|
+
}
|
78
|
+
return prices;
|
79
|
+
}, 8, 250);
|
80
|
+
const missingPrices = (0, generalUtils_1.zip)(mints, prices).filter((x) => !x[1]);
|
81
|
+
const jupPrices = (0, generalUtils_1.zip)(missingPrices.map((x) => x[0]), await getJupTokenPrices(missingPrices.map((x) => x[0])));
|
82
|
+
prices = prices.map((x, i) => x ? x : jupPrices.find((y) => y[0].toString() === mints[i].toString())[1]);
|
83
|
+
return prices;
|
70
84
|
}
|
71
|
-
// LEGACY, NOT USED
|
72
85
|
async function getJupTokenPrices(mints) {
|
73
86
|
if (mints.length == 0) {
|
74
87
|
return [];
|
75
88
|
}
|
76
89
|
const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
77
90
|
const res = (await fetch("https://api.jup.ag/price/v2?ids=" +
|
78
|
-
mints.map((x) => x.toString()).join(",")
|
91
|
+
mints.map((x) => x.toString()).join(","))).json();
|
79
92
|
return res;
|
80
93
|
}, 6);
|
81
94
|
const prices = Object.values(data.data).map((x) => parseFloat(x.price));
|
82
95
|
return prices;
|
83
96
|
}
|
97
|
+
function safeGetPrice(mint) {
|
98
|
+
if (mint && mint?.toString() in solautoConstants_1.PRICES) {
|
99
|
+
return solautoConstants_1.PRICES[mint.toString()].price;
|
100
|
+
}
|
101
|
+
return undefined;
|
102
|
+
}
|
@@ -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,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsB5C;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
|
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,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsB5C;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"}
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getPullFeed = getPullFeed;
|
7
7
|
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
8
8
|
exports.getSwitchboardFeedData = getSwitchboardFeedData;
|
9
|
-
exports.getSwitchboardPrices = getSwitchboardPrices;
|
10
9
|
const anchor_1 = require("@coral-xyz/anchor");
|
11
10
|
const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
|
12
11
|
const web3_js_1 = require("@solana/web3.js");
|
@@ -56,18 +55,3 @@ async function getSwitchboardFeedData(conn, mints) {
|
|
56
55
|
}));
|
57
56
|
return results;
|
58
57
|
}
|
59
|
-
async function getSwitchboardPrices(mints) {
|
60
|
-
if (mints.length === 0) {
|
61
|
-
return [];
|
62
|
-
}
|
63
|
-
const crossbar = new on_demand_1.CrossbarClient("https://crossbar.switchboard.xyz");
|
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 || x === -Infinity)) {
|
68
|
-
throw new Error("Unable to fetch Switchboard prices");
|
69
|
-
}
|
70
|
-
return prices;
|
71
|
-
}, 8, 250);
|
72
|
-
return results;
|
73
|
-
}
|
package/package.json
CHANGED
@@ -551,30 +551,41 @@ export class TransactionsManager {
|
|
551
551
|
TransactionStatus.Processing,
|
552
552
|
attemptNum
|
553
553
|
);
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
TransactionStatus.Successful,
|
565
|
-
attemptNum,
|
566
|
-
txSigs
|
554
|
+
|
555
|
+
let txSigs: string[] | undefined;
|
556
|
+
let error: string | undefined;
|
557
|
+
try {
|
558
|
+
txSigs = await sendJitoBundledTransactions(
|
559
|
+
this.txHandler.umi,
|
560
|
+
this.txHandler.signer,
|
561
|
+
transactions,
|
562
|
+
false,
|
563
|
+
this.priorityFeeSetting
|
567
564
|
);
|
568
|
-
}
|
565
|
+
} catch (e: any) {
|
566
|
+
error = e.message;
|
567
|
+
}
|
568
|
+
|
569
|
+
if (error || !Boolean(txSigs) || txSigs?.length === 0) {
|
569
570
|
this.updateStatusForSets(
|
570
571
|
itemSets,
|
571
572
|
TransactionStatus.Failed,
|
572
573
|
attemptNum,
|
573
574
|
txSigs,
|
574
|
-
true
|
575
|
+
true,
|
576
|
+
error
|
575
577
|
);
|
576
|
-
|
578
|
+
if (error) {
|
579
|
+
throw new Error(error ? error : "Unknown error");
|
580
|
+
}
|
577
581
|
}
|
582
|
+
|
583
|
+
this.updateStatusForSets(
|
584
|
+
itemSets,
|
585
|
+
TransactionStatus.Successful,
|
586
|
+
attemptNum,
|
587
|
+
txSigs
|
588
|
+
);
|
578
589
|
},
|
579
590
|
this.retries,
|
580
591
|
this.retryDelay,
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -139,8 +139,10 @@ async function sendJitoBundle(transactions: string[]): Promise<string[]> {
|
|
139
139
|
}
|
140
140
|
);
|
141
141
|
} catch (e: any) {
|
142
|
-
if (e.response) {
|
142
|
+
if (e.response.data.error) {
|
143
143
|
console.error("Jito send bundle error:", e.response.data.error);
|
144
|
+
throw new Error(e.response.data.error.message);
|
145
|
+
} else {
|
144
146
|
throw e;
|
145
147
|
}
|
146
148
|
}
|
@@ -184,10 +186,6 @@ export async function sendJitoBundledTransactions(
|
|
184
186
|
feeEstimates
|
185
187
|
);
|
186
188
|
|
187
|
-
for (let i = 0; i < txs.length; i++) {
|
188
|
-
consoleLog("Transaction", i, txs[i].getInstructions());
|
189
|
-
}
|
190
|
-
|
191
189
|
// const simulationResults = await simulateJitoBundle(umi, builtTxs);
|
192
190
|
|
193
191
|
if (!simulateOnly) {
|
package/src/utils/priceUtils.ts
CHANGED
@@ -5,15 +5,14 @@ import { fromBaseUnit, toBaseUnit } from "./numberUtils";
|
|
5
5
|
import { PRICES } from "../constants/solautoConstants";
|
6
6
|
import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants/switchboardConstants";
|
7
7
|
import {
|
8
|
+
consoleLog,
|
8
9
|
currentUnixSeconds,
|
9
10
|
retryWithExponentialBackoff,
|
10
11
|
zip,
|
11
12
|
} from "./generalUtils";
|
12
|
-
import {
|
13
|
+
import { CrossbarClient } from "@switchboard-xyz/on-demand";
|
13
14
|
|
14
|
-
export async function fetchTokenPrices(
|
15
|
-
mints: PublicKey[]
|
16
|
-
): Promise<number[]> {
|
15
|
+
export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
|
17
16
|
const currentTime = currentUnixSeconds();
|
18
17
|
if (
|
19
18
|
!mints.some(
|
@@ -35,6 +34,8 @@ export async function fetchTokenPrices(
|
|
35
34
|
zip(switchboardMints, await getSwitchboardPrices(switchboardMints)),
|
36
35
|
]);
|
37
36
|
|
37
|
+
consoleLog([...pythData, ...switchboardData]);
|
38
|
+
|
38
39
|
const prices = mints.map((mint) => {
|
39
40
|
const item = [...pythData, ...switchboardData].find((data) =>
|
40
41
|
data[0].equals(mint)
|
@@ -94,16 +95,45 @@ export async function getPythPrices(mints: PublicKey[]) {
|
|
94
95
|
return prices;
|
95
96
|
}
|
96
97
|
|
97
|
-
export function
|
98
|
-
|
99
|
-
): number
|
100
|
-
if (
|
101
|
-
return
|
98
|
+
export async function getSwitchboardPrices(
|
99
|
+
mints: PublicKey[]
|
100
|
+
): Promise<number[]> {
|
101
|
+
if (mints.length === 0) {
|
102
|
+
return [];
|
102
103
|
}
|
103
|
-
|
104
|
+
|
105
|
+
const crossbar = new CrossbarClient("https://crossbar.switchboard.xyz");
|
106
|
+
let prices = await retryWithExponentialBackoff(
|
107
|
+
async () => {
|
108
|
+
const res = await crossbar.simulateSolanaFeeds(
|
109
|
+
"mainnet",
|
110
|
+
mints.map((x) => SWITCHBOARD_PRICE_FEED_IDS[x.toString()])
|
111
|
+
);
|
112
|
+
|
113
|
+
const prices = res.flatMap((x) => x.results[0]);
|
114
|
+
if (prices.find((x) => !x || x === -Infinity)) {
|
115
|
+
throw new Error("Unable to fetch Switchboard prices");
|
116
|
+
}
|
117
|
+
|
118
|
+
return prices;
|
119
|
+
},
|
120
|
+
8,
|
121
|
+
250
|
122
|
+
);
|
123
|
+
|
124
|
+
const missingPrices = zip(mints, prices).filter((x) => !x[1]);
|
125
|
+
const jupPrices = zip(
|
126
|
+
missingPrices.map((x) => x[0]),
|
127
|
+
await getJupTokenPrices(missingPrices.map((x) => x[0]))
|
128
|
+
);
|
129
|
+
|
130
|
+
prices = prices.map((x, i) =>
|
131
|
+
x ? x : jupPrices.find((y) => y[0].toString() === mints[i].toString())![1]
|
132
|
+
);
|
133
|
+
|
134
|
+
return prices;
|
104
135
|
}
|
105
136
|
|
106
|
-
// LEGACY, NOT USED
|
107
137
|
export async function getJupTokenPrices(mints: PublicKey[]) {
|
108
138
|
if (mints.length == 0) {
|
109
139
|
return [];
|
@@ -113,7 +143,7 @@ export async function getJupTokenPrices(mints: PublicKey[]) {
|
|
113
143
|
const res = (
|
114
144
|
await fetch(
|
115
145
|
"https://api.jup.ag/price/v2?ids=" +
|
116
|
-
mints.map((x) => x.toString()).join(",")
|
146
|
+
mints.map((x) => x.toString()).join(",")
|
117
147
|
)
|
118
148
|
).json();
|
119
149
|
return res;
|
@@ -125,3 +155,12 @@ export async function getJupTokenPrices(mints: PublicKey[]) {
|
|
125
155
|
|
126
156
|
return prices;
|
127
157
|
}
|
158
|
+
|
159
|
+
export function safeGetPrice(
|
160
|
+
mint: PublicKey | UmiPublicKey | undefined
|
161
|
+
): number | undefined {
|
162
|
+
if (mint && mint?.toString() in PRICES) {
|
163
|
+
return PRICES[mint!.toString()].price;
|
164
|
+
}
|
165
|
+
return undefined;
|
166
|
+
}
|
@@ -97,33 +97,4 @@ export async function getSwitchboardFeedData(
|
|
97
97
|
);
|
98
98
|
|
99
99
|
return results;
|
100
|
-
}
|
101
|
-
|
102
|
-
export async function getSwitchboardPrices(
|
103
|
-
mints: PublicKey[]
|
104
|
-
): Promise<number[]> {
|
105
|
-
if (mints.length === 0) {
|
106
|
-
return [];
|
107
|
-
}
|
108
|
-
|
109
|
-
const crossbar = new CrossbarClient("https://crossbar.switchboard.xyz");
|
110
|
-
const results = await retryWithExponentialBackoff(
|
111
|
-
async () => {
|
112
|
-
const res = await crossbar.simulateSolanaFeeds(
|
113
|
-
"mainnet",
|
114
|
-
mints.map((x) => SWITCHBOARD_PRICE_FEED_IDS[x.toString()])
|
115
|
-
);
|
116
|
-
|
117
|
-
const prices = res.flatMap((x) => x.results[0]);
|
118
|
-
if (prices.find((x) => !x || x === -Infinity)) {
|
119
|
-
throw new Error("Unable to fetch Switchboard prices");
|
120
|
-
}
|
121
|
-
|
122
|
-
return prices;
|
123
|
-
},
|
124
|
-
8,
|
125
|
-
250
|
126
|
-
);
|
127
|
-
|
128
|
-
return results;
|
129
|
-
}
|
100
|
+
}
|