@haven-fi/solauto-sdk 1.0.535 → 1.0.536

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.
@@ -24,7 +24,7 @@ export interface JupSwapTransaction {
24
24
  swapIx: TransactionBuilder;
25
25
  }
26
26
  export declare function getJupSwapTransaction(signer: Signer, swapDetails: JupSwapDetails, attemptNum?: number): Promise<JupSwapTransaction>;
27
- export declare function getJupPriceData(mints: PublicKey[], extraInfo?: boolean): Promise<{
27
+ export declare function getJupPriceData(mints: PublicKey[], extraInfo?: boolean, mayIncludeSpamTokens?: boolean): Promise<{
28
28
  [key: string]: any;
29
29
  }>;
30
30
  //# 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;AAUrB,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,iBAAiB,EAAE,SAAS,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B;AAgBD,wBAAsB,WAAW,CAAC,WAAW,EAAE,YAAY,0BAsB1D;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,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B,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,CAmF7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,EAAE,OAAO;;GA6B5G"}
@@ -85,7 +85,7 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
85
85
  swapIx: (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.swapInstruction))),
86
86
  };
87
87
  }
88
- async function getJupPriceData(mints, extraInfo) {
88
+ async function getJupPriceData(mints, extraInfo, mayIncludeSpamTokens) {
89
89
  const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
90
90
  const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
91
91
  mints.map((x) => x.toString()).join(",") +
@@ -98,7 +98,7 @@ async function getJupPriceData(mints, extraInfo) {
98
98
  Boolean(Object.values(result)
99
99
  .map((x) => parseFloat(x.price))
100
100
  .filter((x) => x <= 0).length);
101
- if (invalidValues) {
101
+ if (invalidValues && !mayIncludeSpamTokens) {
102
102
  throw new Error("Invalid price values");
103
103
  }
104
104
  return result;
@@ -4,7 +4,7 @@ import { QuoteGetSwapModeEnum } from "@jup-ag/api";
4
4
  export declare function fetchTokenPrices(mints: PublicKey[]): Promise<number[]>;
5
5
  export declare function getPythPrices(mints: PublicKey[]): Promise<number[]>;
6
6
  export declare function getSwitchboardPrices(mints: PublicKey[]): Promise<number[]>;
7
- export declare function getJupTokenPrices(mints: PublicKey[]): Promise<number[]>;
7
+ export declare function getJupTokenPrices(mints: PublicKey[], mayIncludeSpamTokens?: boolean): Promise<number[]>;
8
8
  export declare function safeGetPrice(mint: PublicKey | UmiPublicKey | undefined): number | undefined;
9
9
  export declare function getPriceImpact(inputMint: PublicKey, outputMint: PublicKey, amount: bigint, swapMode: QuoteGetSwapModeEnum): Promise<{
10
10
  priceImpact: number;
@@ -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,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,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,CAgDnB;AAED,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,qBAQzD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,oBAAoB;;;GAc/B"}
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,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0C5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAoDnB;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,EAClB,oBAAoB,CAAC,EAAE,OAAO,qBAa/B;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,oBAAoB;;;GAc/B"}
@@ -44,12 +44,15 @@ async function fetchTokenPrices(mints) {
44
44
  }
45
45
  const pythMints = mints.filter((x) => x.toString() in pythConstants_1.PYTH_PRICE_FEED_IDS);
46
46
  const switchboardMints = mints.filter((x) => x.toString() in switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS);
47
- const [pythData, switchboardData] = await Promise.all([
47
+ const otherMints = mints.filter((x) => !pythMints.includes(x) && !switchboardMints.includes(x));
48
+ console.log(mints.length, otherMints.length);
49
+ const [pythData, switchboardData, jupData] = await Promise.all([
48
50
  (0, generalUtils_1.zip)(pythMints, await getPythPrices(pythMints)),
49
51
  (0, generalUtils_1.zip)(switchboardMints, await getSwitchboardPrices(switchboardMints)),
52
+ (0, generalUtils_1.zip)(otherMints, await getJupTokenPrices(otherMints, true)),
50
53
  ]);
51
54
  const prices = mints.map((mint) => {
52
- const item = [...pythData, ...switchboardData].find((data) => data[0].equals(mint));
55
+ const item = [...pythData, ...switchboardData, ...jupData].find((data) => data[0].equals(mint));
53
56
  return item ? item[1] : 0;
54
57
  });
55
58
  for (var i = 0; i < mints.length; i++) {
@@ -102,7 +105,7 @@ async function getSwitchboardPrices(mints) {
102
105
  if (p.filter((x) => !x || isNaN(Number(x)) || Number(x) < 0).length > 0) {
103
106
  throw new Error("Unable to fetch Switchboard prices");
104
107
  }
105
- return p;
108
+ return p.map((x) => typeof x === "string" ? parseFloat(x) : Number(x));
106
109
  }, 2, 350);
107
110
  }
108
111
  catch {
@@ -111,17 +114,19 @@ async function getSwitchboardPrices(mints) {
111
114
  if (prices.length === 0) {
112
115
  prices = Array(mints.length).fill(0);
113
116
  }
114
- const missingPrices = (0, generalUtils_1.zip)(mints, prices).filter((x) => !x[1] || isNaN(Number(x)));
117
+ const missingPrices = (0, generalUtils_1.zip)(mints, prices).filter((x) => !x[1] || isNaN(Number(x[1])));
115
118
  const jupPrices = (0, generalUtils_1.zip)(missingPrices.map((x) => x[0]), await getJupTokenPrices(missingPrices.map((x) => x[0])));
116
119
  prices = prices.map((x, i) => x ? x : jupPrices.find((y) => y[0].toString() === mints[i].toString())[1]);
117
120
  return prices;
118
121
  }
119
- async function getJupTokenPrices(mints) {
122
+ async function getJupTokenPrices(mints, mayIncludeSpamTokens) {
120
123
  if (mints.length == 0) {
121
124
  return [];
122
125
  }
123
- const data = await (0, jupiterUtils_1.getJupPriceData)(mints);
124
- return Object.values(data).map((x) => parseFloat(x.price));
126
+ const data = await (0, jupiterUtils_1.getJupPriceData)(mints, false, mayIncludeSpamTokens);
127
+ return Object.values(data).map((x) => x !== null && typeof x === "object" && "price" in x
128
+ ? parseFloat(x.price)
129
+ : 0);
125
130
  }
126
131
  function safeGetPrice(mint) {
127
132
  if (mint && mint?.toString() in solautoConstants_1.PRICES) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.535",
3
+ "version": "1.0.536",
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",
@@ -171,7 +171,7 @@ export async function getJupSwapTransaction(
171
171
  };
172
172
  }
173
173
 
174
- export async function getJupPriceData(mints: PublicKey[], extraInfo?: boolean) {
174
+ export async function getJupPriceData(mints: PublicKey[], extraInfo?: boolean, mayIncludeSpamTokens?: boolean) {
175
175
  const data = await retryWithExponentialBackoff(async () => {
176
176
  const res = await (
177
177
  await fetch(
@@ -185,14 +185,14 @@ export async function getJupPriceData(mints: PublicKey[], extraInfo?: boolean) {
185
185
  throw new Error("Failed to get token prices using Jupiter");
186
186
  }
187
187
 
188
- const invalidValues =
188
+ const invalidValues =
189
189
  Boolean(Object.values(result).filter((x) => x === null).length) ||
190
190
  Boolean(
191
191
  Object.values(result)
192
192
  .map((x) => parseFloat((x as any).price))
193
193
  .filter((x) => x <= 0).length
194
194
  );
195
- if (invalidValues) {
195
+ if (invalidValues && !mayIncludeSpamTokens) {
196
196
  throw new Error("Invalid price values");
197
197
  }
198
198
 
@@ -30,14 +30,19 @@ export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
30
30
  const switchboardMints = mints.filter(
31
31
  (x) => x.toString() in SWITCHBOARD_PRICE_FEED_IDS
32
32
  );
33
+ const otherMints = mints.filter(
34
+ (x) => !pythMints.includes(x) && !switchboardMints.includes(x)
35
+ );
36
+ console.log(mints.length, otherMints.length);
33
37
 
34
- const [pythData, switchboardData] = await Promise.all([
38
+ const [pythData, switchboardData, jupData] = await Promise.all([
35
39
  zip(pythMints, await getPythPrices(pythMints)),
36
40
  zip(switchboardMints, await getSwitchboardPrices(switchboardMints)),
41
+ zip(otherMints, await getJupTokenPrices(otherMints, true)),
37
42
  ]);
38
43
 
39
44
  const prices = mints.map((mint) => {
40
- const item = [...pythData, ...switchboardData].find((data) =>
45
+ const item = [...pythData, ...switchboardData, ...jupData].find((data) =>
41
46
  data[0].equals(mint)
42
47
  );
43
48
  return item ? item[1] : 0;
@@ -115,11 +120,15 @@ export async function getSwitchboardPrices(
115
120
  );
116
121
 
117
122
  const p = res.flatMap((x) => x.results[0]);
118
- if (p.filter((x) => !x || isNaN(Number(x)) || Number(x) < 0).length > 0) {
123
+ if (
124
+ p.filter((x) => !x || isNaN(Number(x)) || Number(x) < 0).length > 0
125
+ ) {
119
126
  throw new Error("Unable to fetch Switchboard prices");
120
127
  }
121
128
 
122
- return p;
129
+ return p.map((x) =>
130
+ typeof x === "string" ? parseFloat(x) : Number(x)
131
+ );
123
132
  },
124
133
  2,
125
134
  350
@@ -133,7 +142,7 @@ export async function getSwitchboardPrices(
133
142
  }
134
143
 
135
144
  const missingPrices = zip(mints, prices).filter(
136
- (x) => !x[1] || isNaN(Number(x))
145
+ (x) => !x[1] || isNaN(Number(x[1]))
137
146
  );
138
147
  const jupPrices = zip(
139
148
  missingPrices.map((x) => x[0]),
@@ -147,14 +156,21 @@ export async function getSwitchboardPrices(
147
156
  return prices;
148
157
  }
149
158
 
150
- export async function getJupTokenPrices(mints: PublicKey[]) {
159
+ export async function getJupTokenPrices(
160
+ mints: PublicKey[],
161
+ mayIncludeSpamTokens?: boolean
162
+ ) {
151
163
  if (mints.length == 0) {
152
164
  return [];
153
165
  }
154
166
 
155
- const data = await getJupPriceData(mints);
167
+ const data = await getJupPriceData(mints, false, mayIncludeSpamTokens);
156
168
 
157
- return Object.values(data).map((x) => parseFloat(x.price as string));
169
+ return Object.values(data).map((x) =>
170
+ x !== null && typeof x === "object" && "price" in x
171
+ ? parseFloat(x.price as string)
172
+ : 0
173
+ );
158
174
  }
159
175
 
160
176
  export function safeGetPrice(
@@ -18,7 +18,7 @@ import {
18
18
  maxRepayToBps,
19
19
  toBaseUnit,
20
20
  } from "../../src/utils/numberUtils";
21
- import { NATIVE_MINT } from "@solana/spl-token";
21
+ import { NATIVE_MINT, TOKEN_PROGRAM_ID } from "@solana/spl-token";
22
22
  import {
23
23
  TransactionItem,
24
24
  TransactionsManager,
@@ -34,14 +34,26 @@ import {
34
34
  } from "../../src/constants";
35
35
  import {
36
36
  buildHeliusApiUrl,
37
+ fetchTokenPrices,
37
38
  getAllPositionsByAuthority,
38
39
  getQnComputeUnitPriceEstimate,
39
40
  getSolautoManagedPositions,
40
41
  getSolautoPositionAccount,
42
+ getTokenAccount,
41
43
  retryWithExponentialBackoff,
42
44
  } from "../../src/utils";
43
45
  import { PriorityFeeSetting } from "../../src/types";
44
- import { buildIronforgeApiUrl, fromBaseUnit, tokenInfo, USD_DECIMALS } from "../../dist";
46
+ import {
47
+ ALL_SUPPORTED_TOKENS,
48
+ buildIronforgeApiUrl,
49
+ fromBaseUnit,
50
+ tokenInfo,
51
+ USD_DECIMALS,
52
+ } from "../../dist";
53
+ import {
54
+ RawAccount as TokenAccountData,
55
+ AccountLayout as SplTokenAccountLayout,
56
+ } from "@solana/spl-token";
45
57
 
46
58
  describe("Solauto Marginfi tests", async () => {
47
59
  const signer = setupTest();
@@ -62,18 +74,38 @@ describe("Solauto Marginfi tests", async () => {
62
74
  const supplyDecimals = 6;
63
75
  const debtDecimals = 6;
64
76
 
65
- await client.initialize({
66
- signer,
67
- positionId,
68
- // authority: new PublicKey("FKYQs7KgRvaKQHxXwb8HKfoBcFdSxLL3JvHWpPdVQ16v"),
69
- // new: true,
70
- // marginfiAccount: new PublicKey(
71
- // ""
72
- // ),
73
- // marginfiGroup: new PublicKey(""),
74
- // supplyMint: new PublicKey(""),
75
- // debtMint: new PublicKey(USDC),
76
- });
77
+ // await client.initialize({
78
+ // signer,
79
+ // positionId,
80
+ // // authority: new PublicKey("FKYQs7KgRvaKQHxXwb8HKfoBcFdSxLL3JvHWpPdVQ16v"),
81
+ // // new: true,
82
+ // // marginfiAccount: new PublicKey(
83
+ // // ""
84
+ // // ),
85
+ // // marginfiGroup: new PublicKey(""),
86
+ // // supplyMint: new PublicKey(""),
87
+ // // debtMint: new PublicKey(USDC),
88
+ // });
89
+
90
+ const tokenAccounts = (
91
+ await client.connection.getTokenAccountsByOwner(
92
+ new PublicKey("He4ka5Q3N1UvZikZvykdi47xyk5PoVP2tcQL5sVp31Sz"),
93
+ { programId: TOKEN_PROGRAM_ID },
94
+ { commitment: "confirmed" }
95
+ )
96
+ ).value;
97
+
98
+ const tokenAccountsData = tokenAccounts
99
+ .map(
100
+ (x) => SplTokenAccountLayout.decode(x.account.data) as TokenAccountData
101
+ )
102
+ .filter((x) => Boolean(x));
103
+
104
+ console.log(tokenAccountsData);
105
+ console.log(tokenAccountsData.length);
106
+
107
+ console.log(await fetchTokenPrices(tokenAccountsData.map((x) => x.mint)));
108
+ return;
77
109
 
78
110
  const transactionItems: TransactionItem[] = [];
79
111
  // const settingParams: SolautoSettingsParametersInpArgs = {