@haven-fi/solauto-sdk 1.0.779 → 1.0.781
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.
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +6 -12
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +8 -3
- package/local/txSandbox.ts +38 -26
- package/package.json +1 -1
- package/src/utils/jupiterUtils.ts +6 -19
- package/src/utils/priceUtils.ts +8 -3
@@ -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,
|
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,gBAyBvD"}
|
@@ -16,21 +16,15 @@ function jupIxToSolanaIx(instruction) {
|
|
16
16
|
});
|
17
17
|
}
|
18
18
|
async function getJupPriceData(mints) {
|
19
|
-
const batches = (0, generalUtils_1.getBatches)(mints,
|
19
|
+
const batches = (0, generalUtils_1.getBatches)(mints, 50);
|
20
20
|
const results = await Promise.all(batches.map((batch) => (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
21
|
-
const res = await (await fetch("https://api.jup.ag/price/
|
22
|
-
batch.map((x) => x.toString()).join(",")
|
23
|
-
|
24
|
-
const result = res.data;
|
25
|
-
if (!result || typeof result !== "object") {
|
21
|
+
const res = await (await fetch("https://lite-api.jup.ag/price/v3?ids=" +
|
22
|
+
batch.map((x) => x.toString()).join(","))).json();
|
23
|
+
if (!res || typeof res !== "object") {
|
26
24
|
throw new Error("Failed to get token prices using Jupiter");
|
27
25
|
}
|
28
|
-
|
29
|
-
|
30
|
-
: { ...acc, [key]: val }, {});
|
31
|
-
return trueData;
|
32
|
-
}, 3)));
|
33
|
-
// Merge all batch results into one object
|
26
|
+
return res;
|
27
|
+
}, 4)));
|
34
28
|
const mergedResults = Object.assign({}, ...results);
|
35
29
|
return mergedResults;
|
36
30
|
}
|
@@ -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;AAgBrE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,UAAU,WAAW;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,EAAE,EAClB,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC,CA4CnB;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,CAAC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CAAC,CAAC,CAsBtC;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,EACnD,SAAS,GAAE,SAA8B,EACzC,SAAS,CAAC,EAAE,SAAS,GACpB,MAAM,GAAG,SAAS,CAyBpB"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -151,10 +151,15 @@ async function getJupTokenPrices(mints) {
|
|
151
151
|
return {};
|
152
152
|
}
|
153
153
|
const data = getSortedPriceData(await (0, jupiterUtils_1.getJupPriceData)(mints), mints);
|
154
|
-
const prices = Object.fromEntries(
|
154
|
+
const prices = Object.fromEntries(mints.map((mint) => [
|
155
155
|
mint,
|
156
|
-
|
157
|
-
|
156
|
+
data !== null &&
|
157
|
+
typeof data === "object" &&
|
158
|
+
typeof data[mint.toString()] === "object" &&
|
159
|
+
"usdPrice" in data[mint.toString()]
|
160
|
+
? {
|
161
|
+
realtimePrice: parseFloat(data[mint.toString()].usdPrice),
|
162
|
+
}
|
158
163
|
: { realtimePrice: 0 },
|
159
164
|
]));
|
160
165
|
return prices;
|
package/local/txSandbox.ts
CHANGED
@@ -4,13 +4,16 @@ import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
|
4
4
|
import {
|
5
5
|
ClientTransactionsManager,
|
6
6
|
consoleLog,
|
7
|
+
fetchTokenPrices,
|
7
8
|
getBatches,
|
8
9
|
getClient,
|
10
|
+
getJupTokenPrices,
|
9
11
|
getPositionExBulk,
|
10
12
|
getSolanaRpcConnection,
|
11
13
|
getSolautoManagedPositions,
|
12
14
|
LendingPlatform,
|
13
15
|
LOCAL_IRONFORGE_API_URL,
|
16
|
+
POPCAT,
|
14
17
|
PriceType,
|
15
18
|
PriorityFeeSetting,
|
16
19
|
ProgramEnv,
|
@@ -19,8 +22,10 @@ import {
|
|
19
22
|
SOLAUTO_TEST_PROGRAM,
|
20
23
|
SolautoClient,
|
21
24
|
TransactionItem,
|
25
|
+
USDC,
|
22
26
|
} from "../src";
|
23
27
|
import { getSecretKey } from "./shared";
|
28
|
+
import { NATIVE_MINT } from "@solana/spl-token";
|
24
29
|
|
25
30
|
const payForTransaction = true;
|
26
31
|
const testProgram = false;
|
@@ -38,32 +43,39 @@ const signer = createSignerFromKeypair(
|
|
38
43
|
);
|
39
44
|
|
40
45
|
export async function main() {
|
41
|
-
const client = getClient(LendingPlatform.Marginfi, {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
});
|
48
|
-
|
49
|
-
await client.initializeExistingSolautoPosition({
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
});
|
56
|
-
|
57
|
-
const transactionItems = [rebalance(client)];
|
58
|
-
|
59
|
-
const txManager = new ClientTransactionsManager({
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
});
|
65
|
-
const statuses = await txManager.send(transactionItems);
|
66
|
-
consoleLog(statuses);
|
46
|
+
// const client = getClient(LendingPlatform.Marginfi, {
|
47
|
+
// signer,
|
48
|
+
// showLogs: true,
|
49
|
+
// rpcUrl: LOCAL_IRONFORGE_API_URL,
|
50
|
+
// programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
|
51
|
+
// lpEnv,
|
52
|
+
// });
|
53
|
+
|
54
|
+
// await client.initializeExistingSolautoPosition({
|
55
|
+
// positionId: 1,
|
56
|
+
// authority: new PublicKey("61rtn5tzVkesapo6Cz83SPoShUfAePSxJsqniuF2wRKC"),
|
57
|
+
// // lpUserAccount: new PublicKey(
|
58
|
+
// // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
59
|
+
// // ),
|
60
|
+
// });
|
61
|
+
|
62
|
+
// const transactionItems = [rebalance(client)];
|
63
|
+
|
64
|
+
// const txManager = new ClientTransactionsManager({
|
65
|
+
// txHandler: client,
|
66
|
+
// txRunType: payForTransaction ? "normal" : "only-simulate",
|
67
|
+
// priorityFeeSetting: PriorityFeeSetting.Default,
|
68
|
+
// retryConfig: { totalRetries: 2 },
|
69
|
+
// });
|
70
|
+
// const statuses = await txManager.send(transactionItems);
|
71
|
+
// consoleLog(statuses);
|
72
|
+
|
73
|
+
const mints =
|
74
|
+
"HMQ9EEaLkVCS2R7bRDSKDUT8hzHg2qszG7y6HTfTuT5y,bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1,7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr,EkvNF86bV1SnMtpHXMZMnNnoXMEERs1LNc8jvcTX2RnK,7z2ze7zaSaRhLh6GyTC5VhRsdbHTS8RfsDfDiE7qKzhB,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,BaLL4pwZ3J9T8NtTe7wtfHLYW6fR8RCSY9mDTowKqmXm,BAvLBcZHaZV39PL3EBpSiiuQ1Nov3sBk3QLZoJpipump,F3yxnd4LL4N7ybFzjnDRBMc4d26dTAEviTjd6he3Qppj,Eyina3Cy5auLDYNCxPmqjwPTzxmTtpM2UWz5pE8s2Rnk,BALL1o7LFnCjsw38aE4pDvhbg3nmMeBbJKh3JU51HCr9,So11111111111111111111111111111111111111112"
|
75
|
+
.split(",")
|
76
|
+
.map((x) => new PublicKey(x));
|
77
|
+
|
78
|
+
console.log(await fetchTokenPrices(mints));
|
67
79
|
}
|
68
80
|
|
69
81
|
async function refreshAll() {
|
package/package.json
CHANGED
@@ -17,40 +17,27 @@ export function jupIxToSolanaIx(
|
|
17
17
|
}
|
18
18
|
|
19
19
|
export async function getJupPriceData(mints: PublicKey[]) {
|
20
|
-
const batches = getBatches(mints,
|
20
|
+
const batches = getBatches(mints, 50);
|
21
21
|
|
22
22
|
const results = await Promise.all(
|
23
23
|
batches.map((batch) =>
|
24
24
|
retryWithExponentialBackoff(async () => {
|
25
25
|
const res = await (
|
26
26
|
await fetch(
|
27
|
-
"https://api.jup.ag/price/
|
28
|
-
batch.map((x) => x.toString()).join(",")
|
29
|
-
"&showExtraInfo=true"
|
27
|
+
"https://lite-api.jup.ag/price/v3?ids=" +
|
28
|
+
batch.map((x) => x.toString()).join(",")
|
30
29
|
)
|
31
30
|
).json();
|
32
31
|
|
33
|
-
|
34
|
-
if (!result || typeof result !== "object") {
|
32
|
+
if (!res || typeof res !== "object") {
|
35
33
|
throw new Error("Failed to get token prices using Jupiter");
|
36
34
|
}
|
37
35
|
|
38
|
-
|
39
|
-
|
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)
|
36
|
+
return res;
|
37
|
+
}, 4)
|
50
38
|
)
|
51
39
|
);
|
52
40
|
|
53
|
-
// Merge all batch results into one object
|
54
41
|
const mergedResults = Object.assign({}, ...results);
|
55
42
|
|
56
43
|
return mergedResults;
|
package/src/utils/priceUtils.ts
CHANGED
@@ -212,10 +212,15 @@ export async function getJupTokenPrices(
|
|
212
212
|
const data = getSortedPriceData(await getJupPriceData(mints), mints);
|
213
213
|
|
214
214
|
const prices: Record<string, PriceResult> = Object.fromEntries(
|
215
|
-
|
215
|
+
mints.map((mint) => [
|
216
216
|
mint,
|
217
|
-
|
218
|
-
|
217
|
+
data !== null &&
|
218
|
+
typeof data === "object" &&
|
219
|
+
typeof data[mint.toString()] === "object" &&
|
220
|
+
"usdPrice" in data[mint.toString()]
|
221
|
+
? {
|
222
|
+
realtimePrice: parseFloat(data[mint.toString()].usdPrice as string),
|
223
|
+
}
|
219
224
|
: { realtimePrice: 0 },
|
220
225
|
])
|
221
226
|
);
|