@haven-fi/solauto-sdk 1.0.623 → 1.0.625

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 (130) hide show
  1. package/dist/constants/{generalAccounts.d.ts → generalConstants.d.ts} +3 -1
  2. package/dist/constants/generalConstants.d.ts.map +1 -0
  3. package/dist/constants/{generalAccounts.js → generalConstants.js} +4 -1
  4. package/dist/constants/index.d.ts +6 -5
  5. package/dist/constants/index.d.ts.map +1 -1
  6. package/dist/constants/index.js +2 -1
  7. package/dist/constants/marginfiAccounts.d.ts +4 -1
  8. package/dist/constants/marginfiAccounts.d.ts.map +1 -1
  9. package/dist/constants/marginfiAccounts.js +7 -5
  10. package/dist/constants/solautoConstants.d.ts +0 -3
  11. package/dist/constants/solautoConstants.d.ts.map +1 -1
  12. package/dist/constants/solautoConstants.js +3 -8
  13. package/dist/services/flashLoans/flProviderAggregator.d.ts +3 -3
  14. package/dist/services/flashLoans/flProviderAggregator.d.ts.map +1 -1
  15. package/dist/services/flashLoans/flProviderAggregator.js +5 -5
  16. package/dist/services/flashLoans/flProviderBase.d.ts +4 -3
  17. package/dist/services/flashLoans/flProviderBase.d.ts.map +1 -1
  18. package/dist/services/flashLoans/flProviderBase.js +3 -2
  19. package/dist/services/flashLoans/marginfiFlProvider.d.ts +2 -2
  20. package/dist/services/flashLoans/marginfiFlProvider.d.ts.map +1 -1
  21. package/dist/services/flashLoans/marginfiFlProvider.js +5 -26
  22. package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
  23. package/dist/services/rebalance/rebalanceSwapManager.js +1 -1
  24. package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
  25. package/dist/services/rebalance/rebalanceTxBuilder.js +4 -4
  26. package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
  27. package/dist/services/rebalance/solautoFees.d.ts.map +1 -1
  28. package/dist/services/rebalance/solautoFees.js +4 -2
  29. package/dist/services/solauto/solautoClient.d.ts +4 -3
  30. package/dist/services/solauto/solautoClient.d.ts.map +1 -1
  31. package/dist/services/solauto/solautoClient.js +21 -24
  32. package/dist/services/solauto/solautoMarginfiClient.d.ts +3 -4
  33. package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
  34. package/dist/services/solauto/solautoMarginfiClient.js +19 -20
  35. package/dist/services/solauto/txHandler.d.ts +4 -2
  36. package/dist/services/solauto/txHandler.d.ts.map +1 -1
  37. package/dist/services/solauto/txHandler.js +4 -6
  38. package/dist/services/swap/jupSwapManager.d.ts +1 -1
  39. package/dist/services/swap/jupSwapManager.d.ts.map +1 -1
  40. package/dist/services/swap/jupSwapManager.js +7 -10
  41. package/dist/services/transactions/transactionUtils.d.ts +2 -3
  42. package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
  43. package/dist/services/transactions/transactionUtils.js +43 -46
  44. package/dist/services/transactions/transactionsManager.d.ts +2 -3
  45. package/dist/services/transactions/transactionsManager.d.ts.map +1 -1
  46. package/dist/services/transactions/transactionsManager.js +16 -20
  47. package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
  48. package/dist/solautoPosition/marginfiSolautoPositionEx.js +1 -1
  49. package/dist/solautoPosition/solautoPositionEx.d.ts +1 -1
  50. package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
  51. package/dist/solautoPosition/solautoPositionEx.js +1 -1
  52. package/dist/solautoPosition/utils.d.ts +2 -2
  53. package/dist/solautoPosition/utils.d.ts.map +1 -1
  54. package/dist/solautoPosition/utils.js +2 -2
  55. package/dist/types/solauto.d.ts +1 -0
  56. package/dist/types/solauto.d.ts.map +1 -1
  57. package/dist/utils/generalUtils.d.ts +2 -0
  58. package/dist/utils/generalUtils.d.ts.map +1 -1
  59. package/dist/utils/generalUtils.js +9 -1
  60. package/dist/utils/index.d.ts +1 -0
  61. package/dist/utils/index.d.ts.map +1 -1
  62. package/dist/utils/index.js +1 -0
  63. package/dist/utils/jitoUtils.d.ts.map +1 -1
  64. package/dist/utils/jitoUtils.js +7 -8
  65. package/dist/utils/jupiterUtils.d.ts.map +1 -1
  66. package/dist/utils/marginfiUtils.d.ts +7 -3
  67. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  68. package/dist/utils/marginfiUtils.js +50 -19
  69. package/dist/utils/numberUtils.d.ts.map +1 -1
  70. package/dist/utils/priceUtils.d.ts.map +1 -1
  71. package/dist/utils/priceUtils.js +13 -15
  72. package/dist/utils/solanaUtils.d.ts +3 -5
  73. package/dist/utils/solanaUtils.d.ts.map +1 -1
  74. package/dist/utils/solanaUtils.js +7 -15
  75. package/dist/utils/solautoUtils.d.ts +3 -3
  76. package/dist/utils/solautoUtils.d.ts.map +1 -1
  77. package/dist/utils/solautoUtils.js +5 -5
  78. package/dist/utils/stringUtils.d.ts.map +1 -1
  79. package/dist/utils/stringUtils.js +3 -3
  80. package/dist/utils/switchboardUtils.d.ts +1 -1
  81. package/dist/utils/switchboardUtils.d.ts.map +1 -1
  82. package/dist/utils/switchboardUtils.js +4 -4
  83. package/local/createISMAccounts.ts +29 -12
  84. package/local/createTokenAccounts.ts +12 -11
  85. package/local/logPositions.ts +5 -5
  86. package/local/shared.ts +16 -10
  87. package/local/txSandbox.ts +5 -5
  88. package/local/updateMarginfiLUT.ts +35 -41
  89. package/local/updateSolautoLUT.ts +11 -13
  90. package/package.json +1 -1
  91. package/src/constants/{generalAccounts.ts → generalConstants.ts} +6 -1
  92. package/src/constants/index.ts +6 -5
  93. package/src/constants/marginfiAccounts.ts +15 -6
  94. package/src/constants/solautoConstants.ts +2 -10
  95. package/src/services/flashLoans/flProviderAggregator.ts +9 -7
  96. package/src/services/flashLoans/flProviderBase.ts +5 -4
  97. package/src/services/flashLoans/marginfiFlProvider.ts +6 -37
  98. package/src/services/rebalance/rebalanceSwapManager.ts +1 -1
  99. package/src/services/rebalance/rebalanceTxBuilder.ts +5 -5
  100. package/src/services/rebalance/rebalanceValues.ts +1 -1
  101. package/src/services/rebalance/solautoFees.ts +3 -4
  102. package/src/services/solauto/solautoClient.ts +9 -15
  103. package/src/services/solauto/solautoMarginfiClient.ts +21 -23
  104. package/src/services/solauto/txHandler.ts +10 -9
  105. package/src/services/swap/jupSwapManager.ts +7 -6
  106. package/src/services/transactions/transactionUtils.ts +17 -18
  107. package/src/services/transactions/transactionsManager.ts +23 -22
  108. package/src/solautoPosition/marginfiSolautoPositionEx.ts +1 -2
  109. package/src/solautoPosition/solautoPositionEx.ts +5 -5
  110. package/src/solautoPosition/utils.ts +7 -7
  111. package/src/types/solauto.ts +2 -0
  112. package/src/utils/generalUtils.ts +9 -1
  113. package/src/utils/index.ts +1 -0
  114. package/src/utils/jitoUtils.ts +17 -14
  115. package/src/utils/jupiterUtils.ts +1 -1
  116. package/src/utils/marginfiUtils.ts +56 -14
  117. package/src/utils/numberUtils.ts +0 -1
  118. package/src/utils/priceUtils.ts +7 -5
  119. package/src/utils/solanaUtils.ts +24 -32
  120. package/src/utils/solautoUtils.ts +13 -13
  121. package/src/utils/stringUtils.ts +3 -3
  122. package/src/utils/switchboardUtils.ts +4 -4
  123. package/tests/transactions/shared.ts +9 -14
  124. package/tests/transactions/solautoMarginfi.ts +13 -3
  125. package/tests/unit/accounts.ts +14 -17
  126. package/tests/unit/lookupTables.ts +5 -5
  127. package/tests/unit/rebalanceCalculations.ts +17 -11
  128. package/README.md +0 -3
  129. package/dist/constants/generalAccounts.d.ts.map +0 -1
  130. package/src/constants/README.md +0 -7
@@ -1,16 +1,30 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { publicKey, Umi } from "@metaplex-foundation/umi";
2
+ import { Program, publicKey, Umi } from "@metaplex-foundation/umi";
3
3
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
4
+ import { ProgramEnv, MarginfiAssetAccounts } from "../types";
5
+ import { PositionState, PositionTokenState } from "../generated";
6
+ import {
7
+ DEFAULT_MARGINFI_GROUP,
8
+ MARGINFI_ACCOUNTS,
9
+ ALL_SUPPORTED_TOKENS,
10
+ MARGINFI_PROD_PROGRAM,
11
+ MARGINFI_STAGING_PROGRAM,
12
+ TOKEN_INFO,
13
+ USD_DECIMALS,
14
+ } from "../constants";
4
15
  import {
5
16
  Bank,
6
17
  deserializeMarginfiAccount,
7
18
  getMarginfiAccountSize,
8
- MARGINFI_PROGRAM_ID,
19
+ getMarginfiErrorFromCode,
20
+ getMarginfiErrorFromName,
9
21
  MarginfiAccount,
10
22
  OracleSetup,
11
23
  safeFetchBank,
12
24
  safeFetchMarginfiAccount,
13
25
  } from "../marginfi-sdk";
26
+ import { ContextUpdates } from "./solautoUtils";
27
+ import { fetchTokenPrices, safeGetPrice } from "./priceUtils";
14
28
  import { currentUnixSeconds } from "./generalUtils";
15
29
  import {
16
30
  bytesToI80F48,
@@ -20,16 +34,44 @@ import {
20
34
  toBaseUnit,
21
35
  toBps,
22
36
  } from "./numberUtils";
23
- import {
24
- DEFAULT_MARGINFI_GROUP,
25
- MARGINFI_ACCOUNTS,
26
- } from "../constants/marginfiAccounts";
27
- import { MarginfiAssetAccounts } from "../types/accounts";
28
- import { PositionState, PositionTokenState } from "../generated";
29
- import { USD_DECIMALS } from "../constants/generalAccounts";
30
- import { ContextUpdates } from "./solautoUtils";
31
- import { ALL_SUPPORTED_TOKENS, TOKEN_INFO } from "../constants";
32
- import { fetchTokenPrices, safeGetPrice } from "./priceUtils";
37
+
38
+ export function getMarginfiProgram(env: ProgramEnv) {
39
+ return env === "Prod" ? MARGINFI_PROD_PROGRAM : MARGINFI_STAGING_PROGRAM;
40
+ }
41
+
42
+ export function isMarginfiProgram(programId: PublicKey) {
43
+ return (
44
+ programId.equals(MARGINFI_PROD_PROGRAM) ||
45
+ programId.equals(MARGINFI_STAGING_PROGRAM)
46
+ );
47
+ }
48
+
49
+ export function createDynamicMarginfiProgram(env?: ProgramEnv): Program {
50
+ return {
51
+ name: "marginfi",
52
+ publicKey: publicKey(getMarginfiProgram(env ?? "Prod")),
53
+ getErrorFromCode(code: number, cause?: Error) {
54
+ return getMarginfiErrorFromCode(code, this, cause);
55
+ },
56
+ getErrorFromName(name: string, cause?: Error) {
57
+ return getMarginfiErrorFromName(name, this, cause);
58
+ },
59
+ isOnCluster() {
60
+ return true;
61
+ },
62
+ };
63
+ }
64
+
65
+ export function umiWithMarginfiProgram(umi: Umi, marginfiEnv?: ProgramEnv) {
66
+ return umi.use({
67
+ install(umi) {
68
+ umi.programs.add(
69
+ createDynamicMarginfiProgram(marginfiEnv ?? "Prod"),
70
+ false
71
+ );
72
+ },
73
+ });
74
+ }
33
75
 
34
76
  interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {
35
77
  mint: PublicKey;
@@ -149,7 +191,7 @@ export async function getEmptyMarginfiAccountsByAuthority(
149
191
  authority: PublicKey
150
192
  ): Promise<MarginfiAccount[]> {
151
193
  const marginfiAccounts = await umi.rpc.getProgramAccounts(
152
- MARGINFI_PROGRAM_ID,
194
+ umi.programs.get("marginfi").publicKey,
153
195
  {
154
196
  commitment: "confirmed",
155
197
  filters: [
@@ -187,7 +229,7 @@ export async function getAllMarginfiAccountsByAuthority(
187
229
  { marginfiAccount: PublicKey; supplyMint?: PublicKey; debtMint?: PublicKey }[]
188
230
  > {
189
231
  const marginfiAccounts = await umi.rpc.getProgramAccounts(
190
- MARGINFI_PROGRAM_ID,
232
+ umi.programs.get("marginfi").publicKey,
191
233
  {
192
234
  commitment: "confirmed",
193
235
  dataSlice: {
@@ -1,6 +1,5 @@
1
1
  import { BASIS_POINTS, MIN_REPAY_GAP_BPS, USD_DECIMALS } from "../constants";
2
2
  import { PositionState } from "../generated";
3
- import { tokenInfo } from "./generalUtils";
4
3
 
5
4
  export function calcNetWorthUsd(state?: PositionState) {
6
5
  return fromRoundedUsdValue(state?.netWorth.baseAmountUsdValue ?? BigInt(0));
@@ -1,16 +1,18 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { PublicKey as UmiPublicKey } from "@metaplex-foundation/umi";
3
- import { PYTH_PRICE_FEED_IDS } from "../constants/pythConstants";
4
- import { fromBaseUnit, toBaseUnit, toBps } from "./numberUtils";
5
- import { PRICES } from "../constants/solautoConstants";
6
- import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants/switchboardConstants";
3
+ import * as SwbCommon from "@switchboard-xyz/common";
4
+ import {
5
+ PYTH_PRICE_FEED_IDS,
6
+ PRICES,
7
+ SWITCHBOARD_PRICE_FEED_IDS,
8
+ } from "../constants";
9
+ import { fromBaseUnit, toBaseUnit } from "./numberUtils";
7
10
  import {
8
11
  consoleLog,
9
12
  currentUnixSeconds,
10
13
  retryWithExponentialBackoff,
11
14
  zip,
12
15
  } from "./generalUtils";
13
- import * as SwbCommon from "@switchboard-xyz/common";
14
16
  import { getJupPriceData } from "./jupiterUtils";
15
17
 
16
18
  export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
@@ -1,19 +1,4 @@
1
1
  import bs58 from "bs58";
2
- import {
3
- AddressLookupTableInput,
4
- Signer,
5
- TransactionBuilder,
6
- Umi,
7
- WrappedInstruction,
8
- publicKey,
9
- transactionBuilder,
10
- } from "@metaplex-foundation/umi";
11
- import {
12
- fromWeb3JsInstruction,
13
- toWeb3JsPublicKey,
14
- toWeb3JsTransaction,
15
- } from "@metaplex-foundation/umi-web3js-adapters";
16
- import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
17
2
  import {
18
3
  AddressLookupTableAccount,
19
4
  BlockhashWithExpiryBlockHeight,
@@ -32,6 +17,26 @@ import {
32
17
  createCloseAccountInstruction,
33
18
  createTransferInstruction,
34
19
  } from "@solana/spl-token";
20
+ import {
21
+ AddressLookupTableInput,
22
+ Signer,
23
+ TransactionBuilder,
24
+ Umi,
25
+ WrappedInstruction,
26
+ publicKey,
27
+ transactionBuilder,
28
+ } from "@metaplex-foundation/umi";
29
+ import {
30
+ fromWeb3JsInstruction,
31
+ toWeb3JsPublicKey,
32
+ toWeb3JsTransaction,
33
+ } from "@metaplex-foundation/umi-web3js-adapters";
34
+ import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
35
+ import { PriorityFeeSetting, ProgramEnv, TransactionRunType } from "../types";
36
+ import {
37
+ getLendingAccountEndFlashloanInstructionDataSerializer,
38
+ getLendingAccountStartFlashloanInstructionDataSerializer,
39
+ } from "../marginfi-sdk";
35
40
  import { getTokenAccount } from "./accountUtils";
36
41
  import {
37
42
  arraysAreEqual,
@@ -39,34 +44,21 @@ import {
39
44
  customRpcCall,
40
45
  retryWithExponentialBackoff,
41
46
  } from "./generalUtils";
42
- import {
43
- getLendingAccountEndFlashloanInstructionDataSerializer,
44
- getLendingAccountStartFlashloanInstructionDataSerializer,
45
- } from "../marginfi-sdk";
46
- import { PriorityFeeSetting, TransactionRunType } from "../types";
47
- import { SOLAUTO_PROD_PROGRAM } from "../constants";
48
47
  import { createDynamicSolautoProgram } from "./solautoUtils";
49
-
50
- export function buildHeliusApiUrl(heliusApiKey: string) {
51
- return `https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`;
52
- }
53
-
54
- export function buildIronforgeApiUrl(ironforgeApiKey: string) {
55
- return `https://rpc.ironforge.network/mainnet?apiKey=${ironforgeApiKey}`;
56
- }
48
+ import { createDynamicMarginfiProgram } from "./marginfiUtils";
57
49
 
58
50
  export function getSolanaRpcConnection(
59
51
  rpcUrl: string,
60
- programId: PublicKey = SOLAUTO_PROD_PROGRAM,
61
- wsEndpoint?: string
52
+ programId?: PublicKey,
53
+ lpEnv?: ProgramEnv
62
54
  ): [Connection, Umi] {
63
55
  const connection = new Connection(rpcUrl, {
64
56
  commitment: "confirmed",
65
- wsEndpoint: wsEndpoint,
66
57
  });
67
58
  const umi = createUmi(connection).use({
68
59
  install(umi) {
69
60
  umi.programs.add(createDynamicSolautoProgram(programId), false);
61
+ umi.programs.add(createDynamicMarginfiProgram(lpEnv), false);
70
62
  },
71
63
  });
72
64
  return [connection, umi];
@@ -1,5 +1,7 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Program, publicKey, Umi } from "@metaplex-foundation/umi";
3
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
4
+ import { QuoteResponse } from "@jup-ag/api";
3
5
  import {
4
6
  AutomationSettings,
5
7
  DCASettings,
@@ -17,21 +19,15 @@ import {
17
19
  getSolautoPositionAccountDataSerializer,
18
20
  getSolautoPositionSize,
19
21
  } from "../generated";
20
- import { getReferralState } from "./accountUtils";
21
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
22
- import { ALL_SUPPORTED_TOKENS } from "../constants";
23
- import {
24
- findMarginfiAccounts,
25
- getAllMarginfiAccountsByAuthority,
26
- } from "./marginfiUtils";
27
- import { SolautoPositionDetails } from "../types/solauto";
28
- import { QuoteResponse } from "@jup-ag/api";
29
- import { createSolautoSettings } from "../solautoPosition";
22
+ import { ALL_SUPPORTED_TOKENS, SOLAUTO_PROD_PROGRAM } from "../constants";
23
+ import { SolautoPositionDetails } from "../types";
30
24
  import {
31
25
  SolautoClient,
32
26
  SolautoMarginfiClient,
33
27
  TxHandlerProps,
34
28
  } from "../services";
29
+ import { createSolautoSettings } from "../solautoPosition";
30
+ import { getReferralState } from "./accountUtils";
35
31
  import {
36
32
  calcTotalDebt,
37
33
  calcTotalSupply,
@@ -41,11 +37,15 @@ import {
41
37
  toRoundedUsdValue,
42
38
  } from "./numberUtils";
43
39
  import { fetchTokenPrices } from "./priceUtils";
40
+ import {
41
+ findMarginfiAccounts,
42
+ getAllMarginfiAccountsByAuthority,
43
+ } from "./marginfiUtils";
44
44
 
45
- export function createDynamicSolautoProgram(programId: PublicKey): Program {
45
+ export function createDynamicSolautoProgram(programId?: PublicKey): Program {
46
46
  return {
47
47
  name: "solauto",
48
- publicKey: publicKey(programId),
48
+ publicKey: publicKey(programId ?? SOLAUTO_PROD_PROGRAM),
49
49
  getErrorFromCode(code: number, cause?: Error) {
50
50
  return getSolautoErrorFromCode(code, this, cause);
51
51
  },
@@ -471,4 +471,4 @@ export function hasLastRebalance(rebalanceType: SolautoRebalanceType) {
471
471
  SolautoRebalanceType.DoubleRebalanceWithFL,
472
472
  SolautoRebalanceType.FLSwapThenRebalance,
473
473
  ].includes(rebalanceType);
474
- }
474
+ }
@@ -1,14 +1,14 @@
1
+ import { PublicKey } from "@solana/web3.js";
1
2
  import { NATIVE_MINT } from "@solana/spl-token";
2
3
  import { WBTC, WETH } from "../constants";
3
- import { PublicKey } from "@solana/web3.js";
4
4
  import { tokenInfo } from "./generalUtils";
5
5
 
6
6
  export const StrategyTypes = ["Long", "Short", "Ratio"] as const;
7
7
  export type StrategyType = (typeof StrategyTypes)[number];
8
8
 
9
9
  const MAJORS_PRIO = {
10
- [WBTC.toString()]: 0,
11
- [WETH.toString()]: 1,
10
+ [WBTC]: 0,
11
+ [WETH]: 1,
12
12
  [NATIVE_MINT.toString()]: 2,
13
13
  };
14
14
 
@@ -1,16 +1,16 @@
1
- import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
2
- import switchboardIdl from "../idls/switchboard.json";
3
1
  import {
4
2
  Connection,
5
3
  PublicKey,
6
4
  Transaction,
7
5
  VersionedTransaction,
8
6
  } from "@solana/web3.js";
9
- import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants/switchboardConstants";
10
- import { TransactionItemInputs } from "../types";
11
7
  import { Signer, transactionBuilder } from "@metaplex-foundation/umi";
12
8
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
9
+ import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
13
10
  import * as OnDemand from "@switchboard-xyz/on-demand";
11
+ import switchboardIdl from "../idls/switchboard.json";
12
+ import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants";
13
+ import { TransactionItemInputs } from "../types";
14
14
  import { retryWithExponentialBackoff } from "./generalUtils";
15
15
  import { getWrappedInstruction } from "./solanaUtils";
16
16
 
@@ -1,10 +1,12 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { NATIVE_MINT } from "@solana/spl-token";
1
3
  import { Signer } from "@metaplex-foundation/umi";
2
4
  import {
3
- buildIronforgeApiUrl,
4
5
  consoleLog,
5
6
  fetchTokenPrices,
6
7
  getClient,
7
8
  LendingPlatform,
9
+ LOCAL_IRONFORGE_API_URL,
8
10
  maxBoostToBps,
9
11
  maxRepayToBps,
10
12
  RebalanceTxBuilder,
@@ -17,8 +19,6 @@ import {
17
19
  TransactionsManager,
18
20
  USDC,
19
21
  } from "../../src";
20
- import { PublicKey } from "@solana/web3.js";
21
- import { NATIVE_MINT } from "@solana/spl-token";
22
22
 
23
23
  export async function e2eTransactionTest(
24
24
  signer: Signer,
@@ -28,7 +28,7 @@ export async function e2eTransactionTest(
28
28
  ) {
29
29
  const client = getClient(lendingPlatform, {
30
30
  signer,
31
- rpcUrl: buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!),
31
+ rpcUrl: LOCAL_IRONFORGE_API_URL,
32
32
  programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
33
33
  });
34
34
 
@@ -72,7 +72,10 @@ export async function e2eTransactionTest(
72
72
  return {
73
73
  tx: client.protocolInteractionIx(
74
74
  solautoAction("Deposit", [
75
- toBaseUnit(supplyUsd / supplyPrice, client.pos.supplyMintInfo().decimals),
75
+ toBaseUnit(
76
+ supplyUsd / supplyPrice,
77
+ client.pos.supplyMintInfo().decimals
78
+ ),
76
79
  ])
77
80
  ),
78
81
  };
@@ -120,15 +123,7 @@ export async function e2eTransactionTest(
120
123
  )
121
124
  );
122
125
 
123
- const txManager = new TransactionsManager(
124
- client,
125
- undefined,
126
- "only-simulate",
127
- undefined,
128
- true,
129
- undefined,
130
- { totalRetries: 5 }
131
- );
126
+ const txManager = new TransactionsManager(client, undefined, "only-simulate");
132
127
  const statuses = await txManager.clientSend(transactionItems);
133
128
 
134
129
  consoleLog(statuses);
@@ -1,6 +1,6 @@
1
1
  import { describe, it } from "mocha";
2
- import { setupTest } from "../shared";
3
2
  import { LendingPlatform } from "../../src";
3
+ import { setupTest } from "../shared";
4
4
  import { e2eTransactionTest } from "./shared";
5
5
 
6
6
  describe("Solauto Marginfi tests", async () => {
@@ -8,10 +8,20 @@ describe("Solauto Marginfi tests", async () => {
8
8
  const testProgram = true;
9
9
 
10
10
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
11
- await e2eTransactionTest(signer, testProgram, LendingPlatform.Marginfi, false);
11
+ await e2eTransactionTest(
12
+ signer,
13
+ testProgram,
14
+ LendingPlatform.Marginfi,
15
+ false
16
+ );
12
17
  });
13
18
 
14
19
  it("open - deposit - borrow - fl rebalance to 0 - withdraw - close", async () => {
15
- await e2eTransactionTest(signer, testProgram, LendingPlatform.Marginfi, true);
20
+ await e2eTransactionTest(
21
+ signer,
22
+ testProgram,
23
+ LendingPlatform.Marginfi,
24
+ true
25
+ );
16
26
  });
17
27
  });
@@ -1,29 +1,25 @@
1
1
  import { describe, it } from "mocha";
2
+ import { assert } from "chai";
3
+ import { PublicKey } from "@solana/web3.js";
4
+ import { publicKey } from "@metaplex-foundation/umi";
5
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
2
6
  import {
3
7
  ALL_SUPPORTED_TOKENS,
4
8
  TOKEN_INFO,
5
- } from "../../src/constants/tokenConstants";
9
+ MARGINFI_ACCOUNTS,
10
+ SOLAUTO_FEES_WALLET,
11
+ SOLAUTO_MANAGER,
12
+ LOCAL_IRONFORGE_API_URL,
13
+ } from "../../src/constants";
6
14
  import {
7
- buildHeliusApiUrl,
8
15
  getSolanaRpcConnection,
9
- } from "../../src/utils/solanaUtils";
10
- import { publicKey } from "@metaplex-foundation/umi";
11
- import { assert } from "chai";
12
- import {
13
16
  getEmptyMarginfiAccountsByAuthority,
14
17
  getTokenAccount,
15
18
  } from "../../src/utils";
16
- import {
17
- MARGINFI_ACCOUNTS,
18
- SOLAUTO_FEES_WALLET,
19
- SOLAUTO_MANAGER,
20
- } from "../../src/constants";
21
- import { PublicKey } from "@solana/web3.js";
22
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
23
19
 
24
20
  async function hasTokenAccounts(wallet: PublicKey) {
25
21
  let [_, umi] = getSolanaRpcConnection(
26
- buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
22
+ LOCAL_IRONFORGE_API_URL
27
23
  );
28
24
 
29
25
  const tokenAccounts = await umi.rpc.getAccounts(
@@ -50,18 +46,19 @@ describe("Assert Solauto fee token accounts are created", async () => {
50
46
 
51
47
  it("ISM accounts for every supported Marginfi group", async () => {
52
48
  let [_, umi] = getSolanaRpcConnection(
53
- buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
49
+ LOCAL_IRONFORGE_API_URL
54
50
  );
55
51
 
56
52
  const ismAccounts = await getEmptyMarginfiAccountsByAuthority(
57
53
  umi,
58
- SOLAUTO_MANAGER,
54
+ SOLAUTO_MANAGER
59
55
  );
60
56
  const supportedMarginfiGroups = Object.keys(MARGINFI_ACCOUNTS).map(
61
57
  (x) => new PublicKey(x)
62
58
  );
63
59
  const missingIsmAccounts = supportedMarginfiGroups.filter(
64
- (group) => !ismAccounts.find((x) => group.equals(toWeb3JsPublicKey(x.group)))
60
+ (group) =>
61
+ !ismAccounts.find((x) => group.equals(toWeb3JsPublicKey(x.group)))
65
62
  );
66
63
 
67
64
  console.log("Missing ISM accounts", missingIsmAccounts);
@@ -1,18 +1,18 @@
1
1
  import { describe, it } from "mocha";
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import {
4
+ LOCAL_IRONFORGE_API_URL,
4
5
  MARGINFI_ACCOUNTS,
5
6
  MARGINFI_ACCOUNTS_LOOKUP_TABLE,
6
- } from "../../src/constants/marginfiAccounts";
7
+ SOLAUTO_MANAGER,
8
+ } from "../../src/constants";
7
9
  import {
8
- buildIronforgeApiUrl,
9
10
  getEmptyMarginfiAccountsByAuthority,
10
11
  getSolanaRpcConnection,
11
- SOLAUTO_MANAGER,
12
- } from "../../src";
12
+ } from "../../src/utils";
13
13
 
14
14
  const [conn, umi] = getSolanaRpcConnection(
15
- buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!)
15
+ LOCAL_IRONFORGE_API_URL
16
16
  );
17
17
 
18
18
  describe("Assert lookup tables up-to-date", async () => {
@@ -1,24 +1,30 @@
1
1
  import { describe, it, before } from "mocha";
2
+ import { assert } from "chai";
2
3
  import { PublicKey } from "@solana/web3.js";
3
4
  import { NATIVE_MINT } from "@solana/spl-token";
4
- import { assert } from "chai";
5
- import { setupTest } from "../shared";
6
5
  import { publicKey } from "@metaplex-foundation/umi";
6
+ import { setupTest } from "../shared";
7
7
  import {
8
8
  LendingPlatform,
9
9
  SolautoSettingsParameters,
10
10
  } from "../../src/generated";
11
- import { fromBps, getLiqUtilzationRateBps } from "../../src/utils/numberUtils";
12
- import { getClient } from "../../src/utils/solautoUtils";
13
- import { USDC } from "../../src/constants/tokenConstants";
14
- import { buildIronforgeApiUrl, fetchTokenPrices, safeGetPrice } from "../../src/utils";
15
11
  import {
16
- createFakePositionState,
12
+ fromBps,
13
+ getLiqUtilzationRateBps,
14
+ getClient,
15
+ fetchTokenPrices,
16
+ safeGetPrice,
17
+ } from "../../src/utils";
18
+ import { LOCAL_IRONFORGE_API_URL, USDC } from "../../src/constants";
19
+ import {
17
20
  getRebalanceValues,
18
- MarginfiSolautoPositionEx,
19
21
  SolautoClient,
20
- } from "../../src";
21
- import { SolautoFeesBps } from "../../src/services/rebalance/solautoFees";
22
+ SolautoFeesBps,
23
+ } from "../../src/services";
24
+ import {
25
+ createFakePositionState,
26
+ MarginfiSolautoPositionEx,
27
+ } from "../../src/solautoPosition";
22
28
 
23
29
  const signer = setupTest(undefined, true);
24
30
 
@@ -58,7 +64,7 @@ async function getFakePosition(
58
64
  ): Promise<SolautoClient> {
59
65
  const client = getClient(LendingPlatform.Marginfi, {
60
66
  signer,
61
- rpcUrl: buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!),
67
+ rpcUrl: LOCAL_IRONFORGE_API_URL,
62
68
  });
63
69
  await client.initialize({
64
70
  positionId: 1,
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Solauto SDK
2
-
3
- TODO
@@ -1 +0,0 @@
1
- {"version":3,"file":"generalAccounts.d.ts","sourceRoot":"","sources":["../../src/constants/generalAccounts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAO,MAAM,YAAY,IAAI,CAAC;AAC9B,eAAO,MAAM,mBAAmB,WAAgE,CAAC;AACjG,eAAO,MAAM,eAAe,WAA+D,CAAC"}
@@ -1,7 +0,0 @@
1
- Instructions for supporting new token:
2
-
3
- - add public key to tokenConstants.ts
4
- - add price feed in pythConstants.ts for it
5
- - create ATA for solauto fees wallet
6
- - `pnpm update-solauto-lut`
7
- - `pnpm test:ts:unit`