@haven-fi/solauto-sdk 1.0.331 → 1.0.333
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 +9 -9
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +3 -0
- 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 +43 -31
- package/src/utils/jitoUtils.ts +4 -0
- 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,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,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAXpB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,UAAU,GAAE,OAAe,EAC3B,aAAa,CAAC,EAAE,aAAa,YAAA,EAC7B,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAY;YAQpB,uBAAuB;IAwCrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,mBAAmB;
|
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,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,aAAa,CAAC;IACtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAXpB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,UAAU,GAAE,OAAe,EAC3B,aAAa,CAAC,EAAE,aAAa,YAAA,EAC7B,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAY;YAQpB,uBAAuB;IAwCrC,OAAO,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;YAmE7B,qBAAqB;YAuDrB,cAAc;YAqCd,eAAe;CAmD9B"}
|
@@ -244,9 +244,9 @@ class TransactionsManager {
|
|
244
244
|
}
|
245
245
|
return this.priorityFeeSetting;
|
246
246
|
}
|
247
|
-
updateStatusForSets(itemSets) {
|
248
|
-
itemSets.forEach((itemSet) => {
|
249
|
-
this.updateStatus(itemSet.name(),
|
247
|
+
updateStatusForSets(itemSets, status, attemptNum, txSigs, simulationSuccessful, moreInfo) {
|
248
|
+
itemSets.forEach((itemSet, i) => {
|
249
|
+
this.updateStatus(itemSet.name(), status, attemptNum, txSigs !== undefined ? txSigs[i] : undefined, simulationSuccessful, moreInfo);
|
250
250
|
});
|
251
251
|
}
|
252
252
|
async updateLut(tx, newLut) {
|
@@ -316,7 +316,7 @@ class TransactionsManager {
|
|
316
316
|
}
|
317
317
|
this.txHandler.log("Transaction items:", items.length);
|
318
318
|
const itemSets = await this.assembleTransactionSets(items);
|
319
|
-
this.updateStatusForSets(itemSets);
|
319
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Queued, 0);
|
320
320
|
this.txHandler.log("Initial item sets:", itemSets.length);
|
321
321
|
if (this.txType === "only-simulate" && itemSets.length > 1) {
|
322
322
|
this.txHandler.log("Only simulate and more than 1 transaction. Skipping...");
|
@@ -342,23 +342,23 @@ class TransactionsManager {
|
|
342
342
|
for (let i = 0; i < itemSets.length; i++) {
|
343
343
|
await itemSets[i].refetchAll(attemptNum);
|
344
344
|
}
|
345
|
-
itemSets = await this.assembleTransactionSets(itemSets.flatMap(x => x.items));
|
345
|
+
itemSets = await this.assembleTransactionSets(itemSets.flatMap((x) => x.items));
|
346
346
|
}
|
347
347
|
let transactions = [];
|
348
348
|
for (const set of itemSets) {
|
349
349
|
transactions.push(await set.getSingleTransaction());
|
350
350
|
}
|
351
|
-
|
351
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum);
|
352
352
|
const txSigs = await (0, jitoUtils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.signer, transactions, false, this.priorityFeeSetting);
|
353
353
|
if (Boolean(txSigs) && txSigs.length > 0) {
|
354
|
-
|
354
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Successful, attemptNum, txSigs);
|
355
355
|
}
|
356
356
|
else {
|
357
|
-
|
357
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Failed, attemptNum, txSigs, true);
|
358
358
|
throw new Error("Unknown error");
|
359
359
|
}
|
360
360
|
}, this.retries, this.retryDelay, this.errorsToThrow).catch((e) => {
|
361
|
-
|
361
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Failed, num, undefined, true, e.message);
|
362
362
|
throw e;
|
363
363
|
});
|
364
364
|
}
|
@@ -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;AAsHD,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,
|
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;AAsHD,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,CAkD/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -115,6 +115,9 @@ async function sendJitoBundledTransactions(umi, signer, txs, simulateOnly, prior
|
|
115
115
|
: undefined;
|
116
116
|
let builtTxs = await umiToVersionedTransactions(umi, signer, txs, true, // false if simulating first and rebuilding later
|
117
117
|
feeEstimates);
|
118
|
+
for (let i = 0; i < txs.length; i++) {
|
119
|
+
(0, generalUtils_1.consoleLog)("Transaction", i, txs[i].getInstructions());
|
120
|
+
}
|
118
121
|
// const simulationResults = await simulateJitoBundle(umi, builtTxs);
|
119
122
|
if (!simulateOnly) {
|
120
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
@@ -358,9 +358,23 @@ export class TransactionsManager {
|
|
358
358
|
return this.priorityFeeSetting;
|
359
359
|
}
|
360
360
|
|
361
|
-
private updateStatusForSets(
|
362
|
-
itemSets
|
363
|
-
|
361
|
+
private updateStatusForSets(
|
362
|
+
itemSets: TransactionSet[],
|
363
|
+
status: TransactionStatus,
|
364
|
+
attemptNum: number,
|
365
|
+
txSigs?: string[],
|
366
|
+
simulationSuccessful?: boolean,
|
367
|
+
moreInfo?: string
|
368
|
+
) {
|
369
|
+
itemSets.forEach((itemSet, i) => {
|
370
|
+
this.updateStatus(
|
371
|
+
itemSet.name(),
|
372
|
+
status,
|
373
|
+
attemptNum,
|
374
|
+
txSigs !== undefined ? txSigs[i] : undefined,
|
375
|
+
simulationSuccessful,
|
376
|
+
moreInfo
|
377
|
+
);
|
364
378
|
});
|
365
379
|
}
|
366
380
|
|
@@ -488,7 +502,7 @@ export class TransactionsManager {
|
|
488
502
|
|
489
503
|
this.txHandler.log("Transaction items:", items.length);
|
490
504
|
const itemSets = await this.assembleTransactionSets(items);
|
491
|
-
this.updateStatusForSets(itemSets);
|
505
|
+
this.updateStatusForSets(itemSets, TransactionStatus.Queued, 0);
|
492
506
|
this.txHandler.log("Initial item sets:", itemSets.length);
|
493
507
|
|
494
508
|
if (this.txType === "only-simulate" && itemSets.length > 1) {
|
@@ -522,7 +536,9 @@ export class TransactionsManager {
|
|
522
536
|
for (let i = 0; i < itemSets.length; i++) {
|
523
537
|
await itemSets[i].refetchAll(attemptNum);
|
524
538
|
}
|
525
|
-
itemSets = await this.assembleTransactionSets(
|
539
|
+
itemSets = await this.assembleTransactionSets(
|
540
|
+
itemSets.flatMap((x) => x.items)
|
541
|
+
);
|
526
542
|
}
|
527
543
|
|
528
544
|
let transactions = [];
|
@@ -530,8 +546,10 @@ export class TransactionsManager {
|
|
530
546
|
transactions.push(await set.getSingleTransaction());
|
531
547
|
}
|
532
548
|
|
533
|
-
|
534
|
-
|
549
|
+
this.updateStatusForSets(
|
550
|
+
itemSets,
|
551
|
+
TransactionStatus.Processing,
|
552
|
+
attemptNum
|
535
553
|
);
|
536
554
|
const txSigs = await sendJitoBundledTransactions(
|
537
555
|
this.txHandler.umi,
|
@@ -541,23 +559,19 @@ export class TransactionsManager {
|
|
541
559
|
this.priorityFeeSetting
|
542
560
|
);
|
543
561
|
if (Boolean(txSigs) && txSigs!.length > 0) {
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
txSigs![i]
|
550
|
-
)
|
562
|
+
this.updateStatusForSets(
|
563
|
+
itemSets,
|
564
|
+
TransactionStatus.Successful,
|
565
|
+
attemptNum,
|
566
|
+
txSigs
|
551
567
|
);
|
552
568
|
} else {
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
true,
|
560
|
-
)
|
569
|
+
this.updateStatusForSets(
|
570
|
+
itemSets,
|
571
|
+
TransactionStatus.Failed,
|
572
|
+
attemptNum,
|
573
|
+
txSigs,
|
574
|
+
true
|
561
575
|
);
|
562
576
|
throw new Error("Unknown error");
|
563
577
|
}
|
@@ -566,15 +580,13 @@ export class TransactionsManager {
|
|
566
580
|
this.retryDelay,
|
567
581
|
this.errorsToThrow
|
568
582
|
).catch((e: Error) => {
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
e.message
|
577
|
-
)
|
583
|
+
this.updateStatusForSets(
|
584
|
+
itemSets,
|
585
|
+
TransactionStatus.Failed,
|
586
|
+
num,
|
587
|
+
undefined,
|
588
|
+
true,
|
589
|
+
e.message
|
578
590
|
);
|
579
591
|
throw e;
|
580
592
|
});
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -184,6 +184,10 @@ export async function sendJitoBundledTransactions(
|
|
184
184
|
feeEstimates
|
185
185
|
);
|
186
186
|
|
187
|
+
for (let i = 0; i < txs.length; i++) {
|
188
|
+
consoleLog("Transaction", i, txs[i].getInstructions());
|
189
|
+
}
|
190
|
+
|
187
191
|
// const simulationResults = await simulateJitoBundle(umi, builtTxs);
|
188
192
|
|
189
193
|
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
|
+
}
|