@haven-fi/solauto-sdk 1.0.778 → 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.
- package/dist/utils/jupiterUtils.d.ts +1 -3
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +10 -12
- package/dist/utils/priceUtils.js +2 -2
- package/local/txSandbox.ts +35 -23
- package/package.json +1 -1
- package/src/utils/jupiterUtils.ts +27 -28
- package/src/utils/priceUtils.ts +2 -2
@@ -1,7 +1,5 @@
|
|
1
1
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
2
|
import { Instruction } from "@jup-ag/api";
|
3
3
|
export declare function jupIxToSolanaIx(instruction: Instruction): TransactionInstruction;
|
4
|
-
export declare function getJupPriceData(mints: PublicKey[]): Promise<
|
5
|
-
[key: string]: any;
|
6
|
-
}>;
|
4
|
+
export declare function getJupPriceData(mints: PublicKey[]): Promise<any>;
|
7
5
|
//# sourceMappingURL=jupiterUtils.d.ts.map
|
@@ -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,gBA2BvD"}
|
@@ -16,18 +16,16 @@ function jupIxToSolanaIx(instruction) {
|
|
16
16
|
});
|
17
17
|
}
|
18
18
|
async function getJupPriceData(mints) {
|
19
|
-
const
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
if (!
|
19
|
+
const batches = (0, generalUtils_1.getBatches)(mints, 50);
|
20
|
+
console.log(batches.length);
|
21
|
+
const results = await Promise.all(batches.map((batch) => (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
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") {
|
25
25
|
throw new Error("Failed to get token prices using Jupiter");
|
26
26
|
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}, 3);
|
32
|
-
return data;
|
27
|
+
return res;
|
28
|
+
}, 4)));
|
29
|
+
const mergedResults = Object.assign({}, ...results);
|
30
|
+
return mergedResults;
|
33
31
|
}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -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" && "
|
157
|
-
? { realtimePrice: parseFloat(x.
|
156
|
+
x !== null && typeof x === "object" && "usdPrice" in x
|
157
|
+
? { realtimePrice: parseFloat(x.usdPrice) }
|
158
158
|
: { realtimePrice: 0 },
|
159
159
|
]));
|
160
160
|
return prices;
|
package/local/txSandbox.ts
CHANGED
@@ -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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
2
|
import { Instruction } from "@jup-ag/api";
|
3
|
-
import { retryWithExponentialBackoff } from "./generalUtils";
|
3
|
+
import { getBatches, retryWithExponentialBackoff } from "./generalUtils";
|
4
4
|
|
5
5
|
export function jupIxToSolanaIx(
|
6
6
|
instruction: Instruction
|
@@ -17,31 +17,30 @@ export function jupIxToSolanaIx(
|
|
17
17
|
}
|
18
18
|
|
19
19
|
export async function getJupPriceData(mints: PublicKey[]) {
|
20
|
-
const
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
return data;
|
20
|
+
const batches = getBatches(mints, 50);
|
21
|
+
|
22
|
+
console.log(batches.length);
|
23
|
+
|
24
|
+
const results = await Promise.all(
|
25
|
+
batches.map((batch) =>
|
26
|
+
retryWithExponentialBackoff(async () => {
|
27
|
+
const res = await (
|
28
|
+
await fetch(
|
29
|
+
"https://lite-api.jup.ag/price/v3?ids=" +
|
30
|
+
batch.map((x) => x.toString()).join(",")
|
31
|
+
)
|
32
|
+
).json();
|
33
|
+
|
34
|
+
if (!res || typeof res !== "object") {
|
35
|
+
throw new Error("Failed to get token prices using Jupiter");
|
36
|
+
}
|
37
|
+
|
38
|
+
return res;
|
39
|
+
}, 4)
|
40
|
+
)
|
41
|
+
);
|
42
|
+
|
43
|
+
const mergedResults = Object.assign({}, ...results);
|
44
|
+
|
45
|
+
return mergedResults;
|
47
46
|
}
|
package/src/utils/priceUtils.ts
CHANGED
@@ -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" && "
|
218
|
-
? { realtimePrice: parseFloat(x.
|
217
|
+
x !== null && typeof x === "object" && "usdPrice" in x
|
218
|
+
? { realtimePrice: parseFloat(x.usdPrice as string) }
|
219
219
|
: { realtimePrice: 0 },
|
220
220
|
])
|
221
221
|
);
|