@haven-fi/solauto-sdk 1.0.387 → 1.0.388

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.
@@ -19,4 +19,7 @@ export interface JupSwapTransaction {
19
19
  swapIx: TransactionBuilder;
20
20
  }
21
21
  export declare function getJupSwapTransaction(signer: Signer, swapDetails: JupSwapDetails, attemptNum?: number): Promise<JupSwapTransaction>;
22
+ export declare function getJupPriceData(mints: PublicKey[], extraInfo?: boolean): Promise<{
23
+ [key: string]: any;
24
+ }>;
22
25
  //# sourceMappingURL=jupiterUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAsF7B"}
1
+ {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAsF7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GAY5E"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getJupSwapTransaction = getJupSwapTransaction;
4
+ exports.getJupPriceData = getJupPriceData;
4
5
  const umi_1 = require("@metaplex-foundation/umi");
5
6
  const web3_js_1 = require("@solana/web3.js");
6
7
  const solanaUtils_1 = require("./solanaUtils");
@@ -70,3 +71,11 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
70
71
  swapIx: (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.swapInstruction))),
71
72
  };
72
73
  }
74
+ async function getJupPriceData(mints, extraInfo) {
75
+ const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
76
+ const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
77
+ mints.map((x) => x.toString()).join(",") + (extraInfo ? "&showExtraInfo=true" : ""))).json();
78
+ return res;
79
+ }, 6);
80
+ return data.data;
81
+ }
@@ -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;AAarE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CA6CnB;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"}
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;AAcrE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CA6CnB;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAYzD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB"}
@@ -11,6 +11,7 @@ const solautoConstants_1 = require("../constants/solautoConstants");
11
11
  const switchboardConstants_1 = require("../constants/switchboardConstants");
12
12
  const generalUtils_1 = require("./generalUtils");
13
13
  const on_demand_1 = require("@switchboard-xyz/on-demand");
14
+ const jupiterUtils_1 = require("./jupiterUtils");
14
15
  async function fetchTokenPrices(mints) {
15
16
  const currentTime = (0, generalUtils_1.currentUnixSeconds)();
16
17
  if (!mints.some((mint) => !(mint.toString() in solautoConstants_1.PRICES) ||
@@ -94,12 +95,8 @@ async function getJupTokenPrices(mints) {
94
95
  if (mints.length == 0) {
95
96
  return [];
96
97
  }
97
- const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
98
- const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
99
- mints.map((x) => x.toString()).join(","))).json();
100
- return res;
101
- }, 6);
102
- const prices = Object.values(data.data).map((x) => parseFloat(x.price));
98
+ const data = await (0, jupiterUtils_1.getJupPriceData)(mints);
99
+ const prices = Object.values(data).map((x) => parseFloat(x.price));
103
100
  return prices;
104
101
  }
105
102
  function safeGetPrice(mint) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.387",
3
+ "version": "1.0.388",
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",
@@ -140,4 +140,18 @@ export async function getJupSwapTransaction(
140
140
  )
141
141
  ),
142
142
  };
143
- }
143
+ }
144
+
145
+ export async function getJupPriceData(mints: PublicKey[], extraInfo?: boolean) {
146
+ const data = await retryWithExponentialBackoff(async () => {
147
+ const res = await (
148
+ await fetch(
149
+ "https://api.jup.ag/price/v2?ids=" +
150
+ mints.map((x) => x.toString()).join(",") + (extraInfo ? "&showExtraInfo=true" : "")
151
+ )
152
+ ).json();
153
+ return res;
154
+ }, 6);
155
+
156
+ return data.data as { [key: string]: any };
157
+ }
@@ -11,6 +11,7 @@ import {
11
11
  zip,
12
12
  } from "./generalUtils";
13
13
  import { CrossbarClient } from "@switchboard-xyz/on-demand";
14
+ import { getJupPriceData } from "./jupiterUtils";
14
15
 
15
16
  export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
16
17
  const currentTime = currentUnixSeconds();
@@ -147,17 +148,9 @@ export async function getJupTokenPrices(mints: PublicKey[]) {
147
148
  return [];
148
149
  }
149
150
 
150
- const data = await retryWithExponentialBackoff(async () => {
151
- const res = await (
152
- await fetch(
153
- "https://api.jup.ag/price/v2?ids=" +
154
- mints.map((x) => x.toString()).join(",")
155
- )
156
- ).json();
157
- return res;
158
- }, 6);
159
-
160
- const prices = Object.values(data.data as { [key: string]: any }).map(
151
+ const data = await getJupPriceData(mints);
152
+
153
+ const prices = Object.values(data).map(
161
154
  (x) => parseFloat(x.price as string) as number
162
155
  );
163
156