@haven-fi/solauto-sdk 1.0.386 → 1.0.387

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,7 +19,4 @@ 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
- }>;
25
22
  //# 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;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GAY5E"}
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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getJupSwapTransaction = getJupSwapTransaction;
4
- exports.getJupPriceData = getJupPriceData;
5
4
  const umi_1 = require("@metaplex-foundation/umi");
6
5
  const web3_js_1 = require("@solana/web3.js");
7
6
  const solanaUtils_1 = require("./solanaUtils");
@@ -71,11 +70,3 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
71
70
  swapIx: (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.swapInstruction))),
72
71
  };
73
72
  }
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;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,CA+CnB;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"}
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"}
@@ -11,7 +11,6 @@ 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");
15
14
  async function fetchTokenPrices(mints) {
16
15
  const currentTime = (0, generalUtils_1.currentUnixSeconds)();
17
16
  if (!mints.some((mint) => !(mint.toString() in solautoConstants_1.PRICES) ||
@@ -95,8 +94,12 @@ async function getJupTokenPrices(mints) {
95
94
  if (mints.length == 0) {
96
95
  return [];
97
96
  }
98
- const data = await (0, jupiterUtils_1.getJupPriceData)(mints);
99
- const prices = Object.values(data).map((x) => parseFloat(x.price));
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));
100
103
  return prices;
101
104
  }
102
105
  function safeGetPrice(mint) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.386",
3
+ "version": "1.0.387",
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,18 +140,4 @@ export async function getJupSwapTransaction(
140
140
  )
141
141
  ),
142
142
  };
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
- }
143
+ }
@@ -11,7 +11,6 @@ import {
11
11
  zip,
12
12
  } from "./generalUtils";
13
13
  import { CrossbarClient } from "@switchboard-xyz/on-demand";
14
- import { getJupPriceData } from "./jupiterUtils";
15
14
 
16
15
  export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
17
16
  const currentTime = currentUnixSeconds();
@@ -111,12 +110,12 @@ export async function getSwitchboardPrices(
111
110
  "mainnet",
112
111
  mints.map((x) => SWITCHBOARD_PRICE_FEED_IDS[x.toString()])
113
112
  );
114
-
113
+
115
114
  const p = res.flatMap((x) => x.results[0]);
116
115
  if (p.filter((x) => !x || isNaN(Number(x))).length > 0) {
117
116
  throw new Error("Unable to fetch Switchboard prices");
118
117
  }
119
-
118
+
120
119
  return p;
121
120
  },
122
121
  2,
@@ -130,9 +129,7 @@ export async function getSwitchboardPrices(
130
129
  prices = Array(mints.length).fill(0);
131
130
  }
132
131
 
133
- const missingPrices = zip(mints, prices).filter(
134
- (x) => !x[1] || isNaN(Number(x))
135
- );
132
+ const missingPrices = zip(mints, prices).filter((x) => !x[1] || isNaN(Number(x)));
136
133
  const jupPrices = zip(
137
134
  missingPrices.map((x) => x[0]),
138
135
  await getJupTokenPrices(missingPrices.map((x) => x[0]))
@@ -150,9 +147,17 @@ export async function getJupTokenPrices(mints: PublicKey[]) {
150
147
  return [];
151
148
  }
152
149
 
153
- const data = await getJupPriceData(mints);
154
-
155
- const prices = Object.values(data).map(
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(
156
161
  (x) => parseFloat(x.price as string) as number
157
162
  );
158
163
 
@@ -94,9 +94,12 @@ describe("Solauto Marginfi tests", async () => {
94
94
  // console.log(JSON.stringify(await getJupPriceData([new PublicKey("7JhmUcZrrfhyt5nTSu3AfsrUq2L9992a7AhwdSDxdoL2")], true), null, 2));
95
95
  // console.log(JSON.stringify(await getJupPriceData([new PublicKey(POPCAT)], true), null, 2));
96
96
 
97
- // const accounts = MARGINFI_ACCOUNTS["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"];
97
+ // const tokenMint = NATIVE_MINT.toString();
98
+ // await fetchTokenPrices([new PublicKey(tokenMint)]);
99
+
100
+ // // const accounts = MARGINFI_ACCOUNTS["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"];
98
101
  // const accounts = MARGINFI_ACCOUNTS[DEFAULT_MARGINFI_GROUP];
99
- // const [supplyBank, debtBank] = await safeFetchAllBank(client.umi, [publicKey(accounts[USDC].bank), publicKey(accounts[tokenMint].bank)]);
102
+ // const [supplyBank, debtBank] = await safeFetchAllBank(client.umi, [publicKey(accounts[tokenMint].bank), publicKey(accounts[USDC].bank)]);
100
103
 
101
104
  // console.log(supplyBank, debtBank);
102
105
  // const [maxLtv, liqThreshold] = calcMarginfiMaxLtvAndLiqThreshold(
@@ -116,7 +119,7 @@ describe("Solauto Marginfi tests", async () => {
116
119
  // // getMaxLiqUtilizationRateBps(toBps(maxLtv), toBps(liqThreshold), 0.005)
117
120
  // );
118
121
  // const maxLeverage = getLeverageFactor(
119
- // "Short",
122
+ // "Long",
120
123
  // supplyUsd + debtAdjustmentUsd,
121
124
  // debtAdjustmentUsd
122
125
  // );