@haven-fi/solauto-sdk 1.0.778 → 1.0.779
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.
@@ -1,7 +1,5 @@
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
2
|
import { Instruction } from "@jup-ag/api";
|
3
3
|
export declare function jupIxToSolanaIx(instruction: Instruction): TransactionInstruction;
|
4
|
-
export declare function getJupPriceData(mints: PublicKey[]): Promise<
|
5
|
-
[key: string]: any;
|
6
|
-
}>;
|
4
|
+
export declare function getJupPriceData(mints: PublicKey[]): Promise<any>;
|
7
5
|
//# sourceMappingURL=jupiterUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,GACvB,sBAAsB,CAUxB;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE
|
1
|
+
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,GACvB,sBAAsB,CAUxB;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,gBAsCvD"}
|
@@ -16,18 +16,21 @@ function jupIxToSolanaIx(instruction) {
|
|
16
16
|
});
|
17
17
|
}
|
18
18
|
async function getJupPriceData(mints) {
|
19
|
-
const
|
19
|
+
const batches = (0, generalUtils_1.getBatches)(mints, 5); // batches is now PublicKey[][]
|
20
|
+
const results = await Promise.all(batches.map((batch) => (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
20
21
|
const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
|
21
|
-
|
22
|
+
batch.map((x) => x.toString()).join(",") +
|
22
23
|
"&showExtraInfo=true")).json();
|
23
24
|
const result = res.data;
|
24
|
-
if (!result ||
|
25
|
+
if (!result || typeof result !== "object") {
|
25
26
|
throw new Error("Failed to get token prices using Jupiter");
|
26
27
|
}
|
27
28
|
const trueData = Object.entries(result).reduce((acc, [key, val]) => !val?.extraInfo?.quotedPrice?.sellAt
|
28
29
|
? { ...acc, [key]: { ...val, price: "0" } }
|
29
30
|
: { ...acc, [key]: val }, {});
|
30
31
|
return trueData;
|
31
|
-
}, 3);
|
32
|
-
|
32
|
+
}, 3)));
|
33
|
+
// Merge all batch results into one object
|
34
|
+
const mergedResults = Object.assign({}, ...results);
|
35
|
+
return mergedResults;
|
33
36
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
2
|
import { Instruction } from "@jup-ag/api";
|
3
|
-
import { retryWithExponentialBackoff } from "./generalUtils";
|
3
|
+
import { getBatches, retryWithExponentialBackoff } from "./generalUtils";
|
4
4
|
|
5
5
|
export function jupIxToSolanaIx(
|
6
6
|
instruction: Instruction
|
@@ -17,31 +17,41 @@ export function jupIxToSolanaIx(
|
|
17
17
|
}
|
18
18
|
|
19
19
|
export async function getJupPriceData(mints: PublicKey[]) {
|
20
|
-
const
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
20
|
+
const batches = getBatches(mints, 5); // batches is now PublicKey[][]
|
21
|
+
|
22
|
+
const results = await Promise.all(
|
23
|
+
batches.map((batch) =>
|
24
|
+
retryWithExponentialBackoff(async () => {
|
25
|
+
const res = await (
|
26
|
+
await fetch(
|
27
|
+
"https://api.jup.ag/price/v2?ids=" +
|
28
|
+
batch.map((x) => x.toString()).join(",") +
|
29
|
+
"&showExtraInfo=true"
|
30
|
+
)
|
31
|
+
).json();
|
32
|
+
|
33
|
+
const result = res.data;
|
34
|
+
if (!result || typeof result !== "object") {
|
35
|
+
throw new Error("Failed to get token prices using Jupiter");
|
36
|
+
}
|
37
|
+
|
38
|
+
const trueData: { [key: string]: any } = Object.entries(
|
39
|
+
result as { [key: string]: any }
|
40
|
+
).reduce(
|
41
|
+
(acc, [key, val]) =>
|
42
|
+
!val?.extraInfo?.quotedPrice?.sellAt
|
43
|
+
? { ...acc, [key]: { ...val, price: "0" } }
|
44
|
+
: { ...acc, [key]: val },
|
45
|
+
{}
|
46
|
+
);
|
47
|
+
|
48
|
+
return trueData;
|
49
|
+
}, 3)
|
50
|
+
)
|
51
|
+
);
|
52
|
+
|
53
|
+
// Merge all batch results into one object
|
54
|
+
const mergedResults = Object.assign({}, ...results);
|
55
|
+
|
56
|
+
return mergedResults;
|
47
57
|
}
|