@haven-fi/solauto-sdk 1.0.778 → 1.0.780

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;;GA4BvD"}
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,gBA2BvD"}
@@ -16,18 +16,16 @@ function jupIxToSolanaIx(instruction) {
16
16
  });
17
17
  }
18
18
  async function getJupPriceData(mints) {
19
- const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
20
- const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
21
- mints.map((x) => x.toString()).join(",") +
22
- "&showExtraInfo=true")).json();
23
- const result = res.data;
24
- if (!result || result === null || typeof result !== "object") {
19
+ const batches = (0, generalUtils_1.getBatches)(mints, 50);
20
+ console.log(batches.length);
21
+ const results = await Promise.all(batches.map((batch) => (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
22
+ const res = await (await fetch("https://lite-api.jup.ag/price/v3?ids=" +
23
+ batch.map((x) => x.toString()).join(","))).json();
24
+ if (!res || typeof res !== "object") {
25
25
  throw new Error("Failed to get token prices using Jupiter");
26
26
  }
27
- const trueData = Object.entries(result).reduce((acc, [key, val]) => !val?.extraInfo?.quotedPrice?.sellAt
28
- ? { ...acc, [key]: { ...val, price: "0" } }
29
- : { ...acc, [key]: val }, {});
30
- return trueData;
31
- }, 3);
32
- return data;
27
+ return res;
28
+ }, 4)));
29
+ const mergedResults = Object.assign({}, ...results);
30
+ return mergedResults;
33
31
  }
@@ -153,8 +153,8 @@ async function getJupTokenPrices(mints) {
153
153
  const data = getSortedPriceData(await (0, jupiterUtils_1.getJupPriceData)(mints), mints);
154
154
  const prices = Object.fromEntries(Object.entries(data).map(([mint, x]) => [
155
155
  mint,
156
- x !== null && typeof x === "object" && "price" in x
157
- ? { realtimePrice: parseFloat(x.price) }
156
+ x !== null && typeof x === "object" && "usdPrice" in x
157
+ ? { realtimePrice: parseFloat(x.usdPrice) }
158
158
  : { realtimePrice: 0 },
159
159
  ]));
160
160
  return prices;
@@ -6,11 +6,13 @@ import {
6
6
  consoleLog,
7
7
  getBatches,
8
8
  getClient,
9
+ getJupTokenPrices,
9
10
  getPositionExBulk,
10
11
  getSolanaRpcConnection,
11
12
  getSolautoManagedPositions,
12
13
  LendingPlatform,
13
14
  LOCAL_IRONFORGE_API_URL,
15
+ POPCAT,
14
16
  PriceType,
15
17
  PriorityFeeSetting,
16
18
  ProgramEnv,
@@ -19,8 +21,10 @@ import {
19
21
  SOLAUTO_TEST_PROGRAM,
20
22
  SolautoClient,
21
23
  TransactionItem,
24
+ USDC,
22
25
  } from "../src";
23
26
  import { getSecretKey } from "./shared";
27
+ import { NATIVE_MINT } from "@solana/spl-token";
24
28
 
25
29
  const payForTransaction = true;
26
30
  const testProgram = false;
@@ -38,32 +42,40 @@ const signer = createSignerFromKeypair(
38
42
  );
39
43
 
40
44
  export async function main() {
41
- const client = getClient(LendingPlatform.Marginfi, {
42
- signer,
43
- showLogs: true,
44
- rpcUrl: LOCAL_IRONFORGE_API_URL,
45
- programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
46
- lpEnv,
47
- });
45
+ // const client = getClient(LendingPlatform.Marginfi, {
46
+ // signer,
47
+ // showLogs: true,
48
+ // rpcUrl: LOCAL_IRONFORGE_API_URL,
49
+ // programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
50
+ // lpEnv,
51
+ // });
48
52
 
49
- await client.initializeExistingSolautoPosition({
50
- positionId: 1,
51
- authority: new PublicKey("61rtn5tzVkesapo6Cz83SPoShUfAePSxJsqniuF2wRKC"),
52
- // lpUserAccount: new PublicKey(
53
- // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
54
- // ),
55
- });
53
+ // await client.initializeExistingSolautoPosition({
54
+ // positionId: 1,
55
+ // authority: new PublicKey("61rtn5tzVkesapo6Cz83SPoShUfAePSxJsqniuF2wRKC"),
56
+ // // lpUserAccount: new PublicKey(
57
+ // // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
58
+ // // ),
59
+ // });
56
60
 
57
- const transactionItems = [rebalance(client)];
61
+ // const transactionItems = [rebalance(client)];
58
62
 
59
- const txManager = new ClientTransactionsManager({
60
- txHandler: client,
61
- txRunType: payForTransaction ? "normal" : "only-simulate",
62
- priorityFeeSetting: PriorityFeeSetting.Default,
63
- retryConfig: { totalRetries: 2 },
64
- });
65
- const statuses = await txManager.send(transactionItems);
66
- consoleLog(statuses);
63
+ // const txManager = new ClientTransactionsManager({
64
+ // txHandler: client,
65
+ // txRunType: payForTransaction ? "normal" : "only-simulate",
66
+ // priorityFeeSetting: PriorityFeeSetting.Default,
67
+ // retryConfig: { totalRetries: 2 },
68
+ // });
69
+ // const statuses = await txManager.send(transactionItems);
70
+ // consoleLog(statuses);
71
+
72
+ console.log(
73
+ await getJupTokenPrices([
74
+ NATIVE_MINT,
75
+ new PublicKey(USDC),
76
+ new PublicKey(POPCAT),
77
+ ])
78
+ );
67
79
  }
68
80
 
69
81
  async function refreshAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.778",
3
+ "version": "1.0.780",
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",
@@ -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,30 @@ export function jupIxToSolanaIx(
17
17
  }
18
18
 
19
19
  export async function getJupPriceData(mints: PublicKey[]) {
20
- const data = await retryWithExponentialBackoff(async () => {
21
- const res = await (
22
- await fetch(
23
- "https://api.jup.ag/price/v2?ids=" +
24
- mints.map((x) => x.toString()).join(",") +
25
- "&showExtraInfo=true"
26
- )
27
- ).json();
28
- const result = res.data;
29
- if (!result || result === null || typeof result !== "object") {
30
- throw new Error("Failed to get token prices using Jupiter");
31
- }
32
-
33
- const trueData: { [key: string]: any } = Object.entries(
34
- result as { [key: string]: any }
35
- ).reduce(
36
- (acc, [key, val]) =>
37
- !val?.extraInfo?.quotedPrice?.sellAt
38
- ? { ...acc, [key]: { ...val, price: "0" } }
39
- : { ...acc, [key]: val },
40
- {}
41
- );
42
-
43
- return trueData;
44
- }, 3);
45
-
46
- return data;
20
+ const batches = getBatches(mints, 50);
21
+
22
+ console.log(batches.length);
23
+
24
+ const results = await Promise.all(
25
+ batches.map((batch) =>
26
+ retryWithExponentialBackoff(async () => {
27
+ const res = await (
28
+ await fetch(
29
+ "https://lite-api.jup.ag/price/v3?ids=" +
30
+ batch.map((x) => x.toString()).join(",")
31
+ )
32
+ ).json();
33
+
34
+ if (!res || typeof res !== "object") {
35
+ throw new Error("Failed to get token prices using Jupiter");
36
+ }
37
+
38
+ return res;
39
+ }, 4)
40
+ )
41
+ );
42
+
43
+ const mergedResults = Object.assign({}, ...results);
44
+
45
+ return mergedResults;
47
46
  }
@@ -214,8 +214,8 @@ export async function getJupTokenPrices(
214
214
  const prices: Record<string, PriceResult> = Object.fromEntries(
215
215
  Object.entries(data).map(([mint, x]) => [
216
216
  mint,
217
- x !== null && typeof x === "object" && "price" in x
218
- ? { realtimePrice: parseFloat(x.price as string) }
217
+ x !== null && typeof x === "object" && "usdPrice" in x
218
+ ? { realtimePrice: parseFloat(x.usdPrice as string) }
219
219
  : { realtimePrice: 0 },
220
220
  ])
221
221
  );