@haven-fi/solauto-sdk 1.0.25 → 1.0.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/dist/clients/solautoClient.d.ts +4 -4
  2. package/dist/clients/solautoClient.d.ts.map +1 -1
  3. package/dist/clients/solautoClient.js +25 -23
  4. package/dist/clients/solautoMarginfiClient.d.ts +1 -0
  5. package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
  6. package/dist/clients/solautoMarginfiClient.js +84 -23
  7. package/dist/generated/instructions/closePosition.d.ts +4 -4
  8. package/dist/generated/instructions/closePosition.d.ts.map +1 -1
  9. package/dist/generated/instructions/closePosition.js +8 -8
  10. package/dist/generated/instructions/marginfiProtocolInteraction.d.ts +2 -2
  11. package/dist/generated/instructions/marginfiProtocolInteraction.d.ts.map +1 -1
  12. package/dist/generated/instructions/marginfiProtocolInteraction.js +4 -4
  13. package/dist/generated/instructions/marginfiRebalance.d.ts +2 -0
  14. package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
  15. package/dist/generated/instructions/marginfiRebalance.js +17 -7
  16. package/dist/transactions/transactionUtils.d.ts.map +1 -1
  17. package/dist/transactions/transactionUtils.js +111 -21
  18. package/dist/transactions/transactionsManager.d.ts.map +1 -1
  19. package/dist/transactions/transactionsManager.js +6 -2
  20. package/dist/types/solauto.d.ts +13 -0
  21. package/dist/types/solauto.d.ts.map +1 -0
  22. package/dist/types/solauto.js +2 -0
  23. package/dist/utils/jupiterUtils.d.ts.map +1 -1
  24. package/dist/utils/jupiterUtils.js +1 -0
  25. package/dist/utils/marginfiUtils.d.ts +5 -1
  26. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  27. package/dist/utils/marginfiUtils.js +8 -2
  28. package/dist/utils/solauto/generalUtils.d.ts +1 -5
  29. package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
  30. package/dist/utils/solauto/generalUtils.js +6 -2
  31. package/dist/utils/solauto/rebalanceUtils.js +2 -1
  32. package/package.json +1 -1
  33. package/src/clients/solautoClient.ts +33 -31
  34. package/src/clients/solautoMarginfiClient.ts +89 -31
  35. package/src/generated/instructions/closePosition.ts +12 -12
  36. package/src/generated/instructions/marginfiProtocolInteraction.ts +6 -6
  37. package/src/generated/instructions/marginfiRebalance.ts +19 -7
  38. package/src/transactions/transactionUtils.ts +140 -36
  39. package/src/transactions/transactionsManager.ts +8 -6
  40. package/src/types/solauto.ts +14 -0
  41. package/src/utils/jupiterUtils.ts +1 -0
  42. package/src/utils/marginfiUtils.ts +11 -3
  43. package/src/utils/solauto/generalUtils.ts +21 -12
  44. package/src/utils/solauto/rebalanceUtils.ts +2 -2
  45. package/tests/transactions/solautoMarginfi.ts +44 -25
  46. package/tests/unit/lookupTables.ts +4 -3
@@ -62,6 +62,7 @@ export async function getJupSwapTransaction(
62
62
  : swapDetails.exactIn
63
63
  ? "ExactIn"
64
64
  : undefined,
65
+ slippageBps: 10
65
66
  });
66
67
 
67
68
  const finalPriceSlippageBps = Math.round(
@@ -88,7 +88,9 @@ export async function getAllMarginfiAccountsByAuthority(
88
88
  umi: Umi,
89
89
  authority: PublicKey,
90
90
  compatibleWithSolauto?: boolean
91
- ): Promise<PublicKey[]> {
91
+ ): Promise<
92
+ { marginfiAccount: PublicKey; supplyMint?: PublicKey; debtMint?: PublicKey }[]
93
+ > {
92
94
  const marginfiAccounts = await umi.rpc.getProgramAccounts(
93
95
  MARGINFI_PROGRAM_ID,
94
96
  {
@@ -123,9 +125,15 @@ export async function getAllMarginfiAccountsByAuthority(
123
125
  );
124
126
  return positionStates
125
127
  .filter((x) => x.state !== undefined)
126
- .map((x) => toWeb3JsPublicKey(x.publicKey));
128
+ .map((x) => ({
129
+ marginfiAccount: toWeb3JsPublicKey(x.publicKey),
130
+ supplyMint: toWeb3JsPublicKey(x.state!.supply.mint),
131
+ debtMint: toWeb3JsPublicKey(x.state!.debt.mint),
132
+ }));
127
133
  } else {
128
- return marginfiAccounts.map((x) => toWeb3JsPublicKey(x.publicKey));
134
+ return marginfiAccounts.map((x) => ({
135
+ marginfiAccount: toWeb3JsPublicKey(x.publicKey),
136
+ }));
129
137
  }
130
138
  }
131
139
 
@@ -27,6 +27,10 @@ import {
27
27
  getAllMarginfiAccountsByAuthority,
28
28
  getMarginfiAccountPositionState,
29
29
  } from "../marginfiUtils";
30
+ import {
31
+ SelfManagedPositionDetails,
32
+ SolautoPositionDetails,
33
+ } from "../../types/solauto";
30
34
 
31
35
  function newPeriodsPassed(
32
36
  automation: AutomationSettings,
@@ -278,12 +282,6 @@ export async function getReferralsByUser(
278
282
  return accounts.map((x) => toWeb3JsPublicKey(x.publicKey));
279
283
  }
280
284
 
281
- export interface SolautoPositionDetails {
282
- positionId: number;
283
- lendingPlatform: LendingPlatform;
284
- protocolAccount?: PublicKey;
285
- }
286
-
287
285
  export async function getAllPositionsByAuthority(
288
286
  umi: Umi,
289
287
  user: PublicKey
@@ -295,16 +293,27 @@ export async function getAllPositionsByAuthority(
295
293
  ...solautoManagedPositions.map((x) => ({
296
294
  positionId: x.positionId,
297
295
  lendingPlatform: x.lendingPlatform,
296
+ selfManaged: false,
298
297
  }))
299
298
  );
300
299
 
301
- const marginfiPositions = await getAllMarginfiAccountsByAuthority(umi, user, true);
300
+ const marginfiPositions = await getAllMarginfiAccountsByAuthority(
301
+ umi,
302
+ user,
303
+ true
304
+ );
302
305
  allPositions.push(
303
- ...marginfiPositions.map((pubkey) => ({
304
- positionId: 0,
305
- lendingPlatform: LendingPlatform.Marginfi,
306
- protocolAccount: pubkey,
307
- }))
306
+ ...marginfiPositions.map(
307
+ (x) =>
308
+ ({
309
+ positionId: 0,
310
+ selfManaged: true,
311
+ lendingPlatform: LendingPlatform.Marginfi,
312
+ protocolAccount: x.marginfiAccount,
313
+ supplyMint: x.supplyMint,
314
+ debtMint: x.debtMint,
315
+ }) as SelfManagedPositionDetails
316
+ )
308
317
  );
309
318
 
310
319
  // TODO support other platforms
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { SolautoClient } from "../../clients/solautoClient";
3
- import { PositionTokenUsage } from "../../generated";
3
+ import { FeeType, PositionTokenUsage } from "../../generated";
4
4
  import {
5
5
  eligibleForNextAutomationPeriod,
6
6
  getAdjustedSettingsFromAutomation,
@@ -188,7 +188,7 @@ export function getRebalanceValues(
188
188
  if (increasingLeverage) {
189
189
  adjustmentFeeBps = getSolautoFeesBps(
190
190
  client.referredByState !== undefined,
191
- client.solautoPositionData!.feeType
191
+ client.solautoPositionData?.feeType ?? FeeType.Small
192
192
  ).total;
193
193
  }
194
194
 
@@ -25,7 +25,7 @@ describe("Solauto Marginfi tests", async () => {
25
25
 
26
26
  const payForTransactions = false;
27
27
  const useJitoBundle = false;
28
- const positionId = 1;
28
+ const positionId = 0;
29
29
 
30
30
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
31
31
  const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
@@ -45,6 +45,11 @@ describe("Solauto Marginfi tests", async () => {
45
45
  {
46
46
  signer,
47
47
  positionId,
48
+ marginfiAccount: new PublicKey(
49
+ "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
50
+ ),
51
+ supplyMint: NATIVE_MINT,
52
+ debtMint: new PublicKey(USDC_MINT),
48
53
  }
49
54
  );
50
55
 
@@ -58,29 +63,29 @@ describe("Solauto Marginfi tests", async () => {
58
63
  targetBoostToBps: none(),
59
64
  };
60
65
 
61
- if (client.solautoPositionData === null) {
62
- transactionItems.push(
63
- new TransactionItem(async () => {
64
- return {
65
- tx: client.openPosition(settingParams),
66
- };
67
- }, "open position")
68
- );
66
+ // if (client.solautoPositionData === null) {
67
+ // transactionItems.push(
68
+ // new TransactionItem(async () => {
69
+ // return {
70
+ // tx: client.openPosition(),
71
+ // };
72
+ // }, "open position")
73
+ // );
69
74
 
70
- const initialSupplyUsd = 50;
71
- transactionItems.push(
72
- new TransactionItem(async () => {
73
- const [supplyPrice] = await getTokenPrices([supply]);
74
- return {
75
- tx: client.protocolInteraction(
76
- solautoAction("Deposit", [
77
- toBaseUnit(initialSupplyUsd / supplyPrice, supplyDecimals),
78
- ])
79
- ),
80
- };
81
- }, "deposit")
82
- );
83
- }
75
+ // const initialSupplyUsd = 50;
76
+ // transactionItems.push(
77
+ // new TransactionItem(async () => {
78
+ // const [supplyPrice] = await getTokenPrices([supply]);
79
+ // return {
80
+ // tx: client.protocolInteraction(
81
+ // solautoAction("Deposit", [
82
+ // toBaseUnit(initialSupplyUsd / supplyPrice, supplyDecimals),
83
+ // ])
84
+ // ),
85
+ // };
86
+ // }, "deposit")
87
+ // );
88
+ // }
84
89
 
85
90
  // transactionItems.push(
86
91
  // new TransactionItem(
@@ -101,10 +106,24 @@ describe("Solauto Marginfi tests", async () => {
101
106
  // )
102
107
  // );
103
108
 
109
+ // const initialSupplyUsd = 50;
110
+ // transactionItems.push(
111
+ // new TransactionItem(async () => {
112
+ // const [supplyPrice] = await getTokenPrices([supply]);
113
+ // return {
114
+ // tx: client.protocolInteraction(
115
+ // solautoAction("Deposit", [
116
+ // toBaseUnit(initialSupplyUsd / supplyPrice, supplyDecimals),
117
+ // ])
118
+ // ),
119
+ // };
120
+ // }, "deposit")
121
+ // );
122
+
104
123
  transactionItems.push(
105
124
  new TransactionItem(
106
125
  async (attemptNum) =>
107
- await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
126
+ await buildSolautoRebalanceTransaction(client, 5000, attemptNum),
108
127
  "rebalance"
109
128
  )
110
129
  );
@@ -141,7 +160,7 @@ describe("Solauto Marginfi tests", async () => {
141
160
  transactionItems,
142
161
  undefined,
143
162
  !payForTransactions,
144
- useJitoBundle,
163
+ useJitoBundle
145
164
  ).send();
146
165
  });
147
166
  });
@@ -1,14 +1,15 @@
1
1
  import { describe, it } from 'mocha';
2
- import { PublicKey } from "@solana/web3.js";
2
+ import { clusterApiUrl, Connection, PublicKey } from "@solana/web3.js";
3
3
  import {
4
4
  MARGINFI_ACCOUNTS,
5
5
  MARGINFI_ACCOUNTS_LOOKUP_TABLE,
6
6
  } from "../../src/constants/marginfiAccounts";
7
- import { CONNECTION } from "../../src/constants/solautoConstants";
7
+
8
+ const conn = new Connection(clusterApiUrl("mainnet-beta"), "confirmed");
8
9
 
9
10
  describe("Assert lookup tables up-to-date", async () => {
10
11
  it("marginfi accounts LUT should have everything", async () => {
11
- const lookupTable = await CONNECTION.getAddressLookupTable(
12
+ const lookupTable = await conn.getAddressLookupTable(
12
13
  new PublicKey(MARGINFI_ACCOUNTS_LOOKUP_TABLE)
13
14
  );
14
15
  if (lookupTable === null) {