@haven-fi/solauto-sdk 1.0.779 → 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 +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,gBAsCvD"}
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,21 +16,16 @@ function jupIxToSolanaIx(instruction) {
16
16
  });
17
17
  }
18
18
  async function getJupPriceData(mints) {
19
- const batches = (0, generalUtils_1.getBatches)(mints, 5); // batches is now PublicKey[][]
19
+ const batches = (0, generalUtils_1.getBatches)(mints, 50);
20
+ console.log(batches.length);
20
21
  const results = await Promise.all(batches.map((batch) => (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
21
- const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
22
- batch.map((x) => x.toString()).join(",") +
23
- "&showExtraInfo=true")).json();
24
- const result = res.data;
25
- if (!result || typeof result !== "object") {
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") {
26
25
  throw new Error("Failed to get token prices using Jupiter");
27
26
  }
28
- const trueData = Object.entries(result).reduce((acc, [key, val]) => !val?.extraInfo?.quotedPrice?.sellAt
29
- ? { ...acc, [key]: { ...val, price: "0" } }
30
- : { ...acc, [key]: val }, {});
31
- return trueData;
32
- }, 3)));
33
- // Merge all batch results into one object
27
+ return res;
28
+ }, 4)));
34
29
  const mergedResults = Object.assign({}, ...results);
35
30
  return mergedResults;
36
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.779",
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",
@@ -17,40 +17,29 @@ export function jupIxToSolanaIx(
17
17
  }
18
18
 
19
19
  export async function getJupPriceData(mints: PublicKey[]) {
20
- const batches = getBatches(mints, 5); // batches is now PublicKey[][]
20
+ const batches = getBatches(mints, 50);
21
+
22
+ console.log(batches.length);
21
23
 
22
24
  const results = await Promise.all(
23
25
  batches.map((batch) =>
24
26
  retryWithExponentialBackoff(async () => {
25
27
  const res = await (
26
28
  await fetch(
27
- "https://api.jup.ag/price/v2?ids=" +
28
- batch.map((x) => x.toString()).join(",") +
29
- "&showExtraInfo=true"
29
+ "https://lite-api.jup.ag/price/v3?ids=" +
30
+ batch.map((x) => x.toString()).join(",")
30
31
  )
31
32
  ).json();
32
33
 
33
- const result = res.data;
34
- if (!result || typeof result !== "object") {
34
+ if (!res || typeof res !== "object") {
35
35
  throw new Error("Failed to get token prices using Jupiter");
36
36
  }
37
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)
38
+ return res;
39
+ }, 4)
50
40
  )
51
41
  );
52
42
 
53
- // Merge all batch results into one object
54
43
  const mergedResults = Object.assign({}, ...results);
55
44
 
56
45
  return mergedResults;
@@ -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
  );