@haven-fi/solauto-sdk 1.0.303 → 1.0.304

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.
Files changed (50) hide show
  1. package/dist/clients/solautoMarginfiClient.d.ts +1 -2
  2. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
  3. package/dist/clients/solautoMarginfiClient.js +22 -26
  4. package/dist/transactions/transactionUtils.d.ts.map +1 -1
  5. package/dist/transactions/transactionUtils.js +4 -3
  6. package/dist/transactions/transactionsManager.d.ts.map +1 -1
  7. package/dist/transactions/transactionsManager.js +15 -0
  8. package/dist/utils/generalUtils.d.ts +2 -6
  9. package/dist/utils/generalUtils.d.ts.map +1 -1
  10. package/dist/utils/generalUtils.js +0 -91
  11. package/dist/utils/index.d.ts +2 -0
  12. package/dist/utils/index.d.ts.map +1 -1
  13. package/dist/utils/index.js +2 -0
  14. package/dist/utils/jupiterUtils.d.ts.map +1 -1
  15. package/dist/utils/jupiterUtils.js +10 -2
  16. package/dist/utils/marginfiUtils.d.ts +2 -2
  17. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  18. package/dist/utils/marginfiUtils.js +13 -12
  19. package/dist/utils/priceUtils.d.ts +12 -0
  20. package/dist/utils/priceUtils.d.ts.map +1 -0
  21. package/dist/utils/priceUtils.js +97 -0
  22. package/dist/utils/solanaUtils.d.ts.map +1 -1
  23. package/dist/utils/solanaUtils.js +1 -1
  24. package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
  25. package/dist/utils/solauto/generalUtils.js +2 -1
  26. package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
  27. package/dist/utils/solauto/rebalanceUtils.js +5 -4
  28. package/dist/utils/switchboardUtils.d.ts +7 -0
  29. package/dist/utils/switchboardUtils.d.ts.map +1 -0
  30. package/dist/utils/switchboardUtils.js +41 -0
  31. package/local/createISMAccounts.ts +59 -0
  32. package/local/updateMarginfiLUT.ts +0 -1
  33. package/local/updateSolautoLUT.ts +38 -7
  34. package/package.json +2 -1
  35. package/src/clients/solautoMarginfiClient.ts +17 -28
  36. package/src/constants/README.md +0 -2
  37. package/src/transactions/transactionUtils.ts +8 -3
  38. package/src/transactions/transactionsManager.ts +33 -2
  39. package/src/utils/generalUtils.ts +2 -152
  40. package/src/utils/index.ts +3 -1
  41. package/src/utils/jupiterUtils.ts +13 -3
  42. package/src/utils/marginfiUtils.ts +5 -16
  43. package/src/utils/priceUtils.ts +154 -0
  44. package/src/utils/solanaUtils.ts +1 -2
  45. package/src/utils/solauto/generalUtils.ts +3 -2
  46. package/src/utils/solauto/rebalanceUtils.ts +2 -1
  47. package/src/utils/switchboardUtils.ts +66 -0
  48. package/tests/transactions/solautoMarginfi.ts +38 -35
  49. package/tests/unit/rebalanceCalculations.ts +6 -5
  50. package/local/createSolautoManagerAccount.ts +0 -48
@@ -8,13 +8,14 @@ import {
8
8
  } from "../../src/generated";
9
9
  import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
10
10
  import {
11
+ getLiqUtilzationRateBps,
11
12
  maxBoostToBps,
12
13
  maxRepayFromBps,
13
14
  maxRepayToBps,
14
15
  toBaseUnit,
15
16
  } from "../../src/utils/numberUtils";
16
17
  import { NATIVE_MINT } from "@solana/spl-token";
17
- import { consoleLog, fetchTokenPrices } from "../../src/utils/generalUtils";
18
+ import { consoleLog } from "../../src/utils/generalUtils";
18
19
  import {
19
20
  TransactionItem,
20
21
  TransactionsManager,
@@ -32,7 +33,7 @@ describe("Solauto Marginfi tests", async () => {
32
33
  const signer = setupTest();
33
34
  // const signer = setupTest("solauto-manager");
34
35
 
35
- const payForTransactions = false;
36
+ const payForTransactions = true;
36
37
  const testProgram = true;
37
38
  const positionId = 3;
38
39
 
@@ -55,42 +56,49 @@ describe("Solauto Marginfi tests", async () => {
55
56
  // marginfiAccount: new PublicKey(
56
57
  // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
57
58
  // ),
58
- marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
59
- supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
60
- debtMint: new PublicKey(USDC),
59
+ // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
60
+ // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
61
+ // debtMint: new PublicKey(USDC),
61
62
  });
62
63
 
63
64
  const transactionItems: TransactionItem[] = [];
64
65
  const settingParams: SolautoSettingsParametersInpArgs = {
65
- boostToBps: 6900,
66
+ boostToBps: maxBoostToBps(
67
+ client.solautoPositionState?.maxLtvBps ?? 0,
68
+ client.solautoPositionState?.liqThresholdBps ?? 0
69
+ ),
66
70
  boostGap: 50,
67
- repayToBps: 7000,
71
+ repayToBps: maxRepayToBps(
72
+ client.solautoPositionState?.maxLtvBps ?? 0,
73
+ client.solautoPositionState?.liqThresholdBps ?? 0
74
+ ),
68
75
  repayGap: 50,
69
76
  automation: none(),
70
77
  targetBoostToBps: none(),
71
78
  };
72
-
73
- if (client.solautoPositionData === null) {
74
- transactionItems.push(
75
- new TransactionItem(async () => {
76
- return {
77
- tx: client.openPosition(settingParams),
78
- };
79
- }, "open position")
80
- );
81
-
82
- // const initialSupplyUsd = 150;
83
- transactionItems.push(
84
- new TransactionItem(async () => {
85
- // const [supplyPrice] = await fetchTokenPrices(client.connection, [supply]);
86
- return {
87
- tx: client.protocolInteraction(
88
- solautoAction("Deposit", [toBaseUnit(200, supplyDecimals)])
89
- ),
90
- };
91
- }, "deposit")
92
- );
93
- }
79
+ console.log(settingParams);
80
+
81
+ // if (client.solautoPositionData === null) {
82
+ // transactionItems.push(
83
+ // new TransactionItem(async () => {
84
+ // return {
85
+ // tx: client.openPosition(settingParams),
86
+ // };
87
+ // }, "open position")
88
+ // );
89
+
90
+ // const initialSupplyUsd = 150;
91
+ // transactionItems.push(
92
+ // new TransactionItem(async () => {
93
+ // // const [supplyPrice] = await fetchTokenPrices([supply]);
94
+ // return {
95
+ // tx: client.protocolInteraction(
96
+ // solautoAction("Deposit", [toBaseUnit(300, supplyDecimals)])
97
+ // ),
98
+ // };
99
+ // }, "deposit")
100
+ // );
101
+ // }
94
102
 
95
103
  // const maxLtvBps = client.solautoPositionState!.maxLtvBps;
96
104
  // const liqThresholdBps = client.solautoPositionState!.liqThresholdBps;
@@ -104,10 +112,6 @@ describe("Solauto Marginfi tests", async () => {
104
112
  // positionId: client.positionId,
105
113
  // settingParams: some({
106
114
  // ...settingParams,
107
- // boostToBps: maxBoostTo,
108
- // boostGap: 50,
109
- // repayToBps: maxRepayTo,
110
- // repayGap: maxRepayFrom - maxRepayTo
111
115
  // }),
112
116
  // dca: null,
113
117
  // }),
@@ -119,7 +123,7 @@ describe("Solauto Marginfi tests", async () => {
119
123
  transactionItems.push(
120
124
  new TransactionItem(
121
125
  async (attemptNum) =>
122
- await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
126
+ await buildSolautoRebalanceTransaction(client, 3000, attemptNum),
123
127
  "rebalance"
124
128
  )
125
129
  );
@@ -160,6 +164,5 @@ describe("Solauto Marginfi tests", async () => {
160
164
  ).clientSend(transactionItems);
161
165
 
162
166
  console.log(statuses);
163
-
164
167
  });
165
168
  });
@@ -31,13 +31,14 @@ import {
31
31
  getUpdatedValueFromAutomation,
32
32
  positionStateWithLatestPrices,
33
33
  } from "../../src/utils/solauto/generalUtils";
34
+ import { currentUnixSeconds } from "../../src/utils/generalUtils";
35
+ import { USDC } from "../../src/constants/tokenConstants";
34
36
  import {
35
- currentUnixSeconds,
37
+ buildHeliusApiUrl,
36
38
  fetchTokenPrices,
39
+ getSolanaRpcConnection,
37
40
  safeGetPrice,
38
- } from "../../src/utils/generalUtils";
39
- import { USDC } from "../../src/constants/tokenConstants";
40
- import { buildHeliusApiUrl, getSolanaRpcConnection } from "../../src/utils";
41
+ } from "../../src/utils";
41
42
 
42
43
  const signer = setupTest(undefined, true);
43
44
  const [conn, _] = getSolanaRpcConnection(
@@ -287,7 +288,7 @@ describe("Rebalance tests", async () => {
287
288
  let supplyPrice: number, debtPrice: number;
288
289
 
289
290
  before(async () => {
290
- [supplyPrice, debtPrice] = await fetchTokenPrices(conn, [
291
+ [supplyPrice, debtPrice] = await fetchTokenPrices([
291
292
  NATIVE_MINT,
292
293
  new PublicKey(USDC),
293
294
  ]);
@@ -1,48 +0,0 @@
1
- import {
2
- createSignerFromKeypair,
3
- publicKey,
4
- signerIdentity,
5
- transactionBuilder,
6
- } from "@metaplex-foundation/umi";
7
- import {
8
- buildHeliusApiUrl,
9
- getSolanaRpcConnection,
10
- sendSingleOptimizedTransaction,
11
- } from "../src/utils/solanaUtils";
12
- import { marginfiAccountInitialize } from "../src/marginfi-sdk";
13
- import { DEFAULT_MARGINFI_GROUP } from "../src/constants";
14
- import { getSecretKey } from "./shared";
15
- import { updateSolautoLut } from "./updateSolautoLUT";
16
-
17
- async function create() {
18
- let [connection, umi] = getSolanaRpcConnection(buildHeliusApiUrl(process.env.HELIUS_API_KEY!));
19
-
20
- const secretKey = getSecretKey("solauto-manager");
21
- const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
22
- const signer = createSignerFromKeypair(umi, signerKeypair);
23
-
24
- umi = umi.use(signerIdentity(signer));
25
-
26
- const marginfiAccount = createSignerFromKeypair(
27
- umi,
28
- umi.eddsa.generateKeypair()
29
- );
30
- console.log(marginfiAccount.publicKey);
31
-
32
- const tx = marginfiAccountInitialize(umi, {
33
- marginfiAccount,
34
- marginfiGroup: publicKey(DEFAULT_MARGINFI_GROUP),
35
- authority: signer,
36
- feePayer: signer,
37
- });
38
-
39
- await sendSingleOptimizedTransaction(
40
- umi,
41
- connection,
42
- transactionBuilder().add(tx)
43
- );
44
-
45
- await updateSolautoLut([marginfiAccount.publicKey.toString()]);
46
- }
47
-
48
- create();