@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,7 +1,16 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { ALL_SUPPORTED_TOKENS, SOLAUTO_FEES_WALLET } from "../src/constants";
3
2
  import {
4
- buildHeliusApiUrl,
3
+ createSignerFromKeypair,
4
+ publicKey,
5
+ signerIdentity,
6
+ transactionBuilder,
7
+ } from "@metaplex-foundation/umi";
8
+ import {
9
+ ALL_SUPPORTED_TOKENS,
10
+ LOCAL_IRONFORGE_API_URL,
11
+ SOLAUTO_FEES_WALLET,
12
+ } from "../src/constants";
13
+ import {
5
14
  createAssociatedTokenAccountUmiIx,
6
15
  getSolanaRpcConnection,
7
16
  getTokenAccount,
@@ -9,17 +18,9 @@ import {
9
18
  zip,
10
19
  } from "../src/utils";
11
20
  import { getSecretKey } from "./shared";
12
- import {
13
- createSignerFromKeypair,
14
- publicKey,
15
- signerIdentity,
16
- transactionBuilder,
17
- } from "@metaplex-foundation/umi";
18
21
 
19
22
  async function createTokenAccounts(wallet: PublicKey) {
20
- let [connection, umi] = getSolanaRpcConnection(
21
- buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
22
- );
23
+ let [connection, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
23
24
 
24
25
  const secretKey = getSecretKey();
25
26
  const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
@@ -1,15 +1,15 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import path from "path";
3
+ import { config } from "dotenv";
1
4
  import {
2
- buildIronforgeApiUrl,
3
5
  fetchTokenPrices,
4
6
  getPositionExBulk,
5
7
  getSolanaRpcConnection,
6
8
  getSolautoManagedPositions,
9
+ LOCAL_IRONFORGE_API_URL,
7
10
  safeGetPrice,
8
11
  SOLAUTO_PROD_PROGRAM,
9
12
  } from "../src";
10
- import { PublicKey } from "@solana/web3.js";
11
- import path from "path";
12
- import { config } from "dotenv";
13
13
 
14
14
  config({ path: path.join(__dirname, ".env") });
15
15
 
@@ -78,7 +78,7 @@ export function formatNumber(
78
78
 
79
79
  async function main(filterWhitelist: boolean) {
80
80
  const [_, umi] = getSolanaRpcConnection(
81
- buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!),
81
+ LOCAL_IRONFORGE_API_URL,
82
82
  SOLAUTO_PROD_PROGRAM
83
83
  );
84
84
 
package/local/shared.ts CHANGED
@@ -9,10 +9,10 @@ import {
9
9
  PublicKey,
10
10
  } from "@solana/web3.js";
11
11
  import {
12
- buildHeliusApiUrl,
13
12
  getSolanaRpcConnection,
14
- } from "../src/utils/solanaUtils";
15
- import { getBatches } from "../src";
13
+ getBatches,
14
+ buildIronforgeApiUrl,
15
+ } from "../src";
16
16
 
17
17
  function loadSecretKey(keypairPath: string) {
18
18
  const secretKey = JSON.parse(fs.readFileSync(keypairPath, "utf8"));
@@ -27,7 +27,7 @@ export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
27
27
 
28
28
  const keypair = Keypair.fromSecretKey(getSecretKey("solauto-fees"));
29
29
  const [connection, _] = getSolanaRpcConnection(
30
- buildHeliusApiUrl(process.env.HELIUS_API_KEY ?? "")
30
+ buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY ?? "")
31
31
  );
32
32
 
33
33
  export async function createAndSendV0Tx(
@@ -89,14 +89,21 @@ async function addAddressesIfNeeded(
89
89
  }
90
90
  }
91
91
 
92
+ const CACHE: { [key: string]: string[] } = {};
93
+
92
94
  export async function updateLookupTable(
93
95
  accounts: string[],
94
96
  lookupTableAddress?: PublicKey
95
97
  ) {
96
- let lookupTable = lookupTableAddress
97
- ? await connection.getAddressLookupTable(lookupTableAddress)
98
- : null;
99
- if (lookupTable === null) {
98
+ if (lookupTableAddress && !(lookupTableAddress.toString() in CACHE)) {
99
+ const lookupTable =
100
+ await connection.getAddressLookupTable(lookupTableAddress);
101
+ CACHE[lookupTableAddress.toString()] = (
102
+ lookupTable?.value?.state?.addresses ?? []
103
+ ).map((x) => x.toString());
104
+ }
105
+
106
+ if (!lookupTableAddress) {
100
107
  const [createLutIx, addr] = AddressLookupTableProgram.createLookupTable({
101
108
  authority: keypair.publicKey,
102
109
  payer: keypair.publicKey,
@@ -107,8 +114,7 @@ export async function updateLookupTable(
107
114
  await createAndSendV0Tx([createLutIx], keypair);
108
115
  }
109
116
 
110
- const existingAccounts =
111
- lookupTable?.value?.state.addresses.map((x) => x.toString()) ?? [];
117
+ const existingAccounts = CACHE[lookupTableAddress.toString()];
112
118
  console.log("Existing accounts: ", existingAccounts.length);
113
119
 
114
120
  await addAddressesIfNeeded(lookupTableAddress!, existingAccounts, accounts);
@@ -1,10 +1,12 @@
1
1
  import { Keypair, PublicKey } from "@solana/web3.js";
2
+ import { createSignerFromKeypair } from "@metaplex-foundation/umi";
3
+ import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
2
4
  import {
3
- buildIronforgeApiUrl,
4
5
  consoleLog,
5
6
  getClient,
6
7
  getSolanaRpcConnection,
7
8
  LendingPlatform,
9
+ LOCAL_IRONFORGE_API_URL,
8
10
  PriorityFeeSetting,
9
11
  RebalanceTxBuilder,
10
12
  SOLAUTO_PROD_PROGRAM,
@@ -13,15 +15,13 @@ import {
13
15
  TransactionsManager,
14
16
  } from "../src";
15
17
  import { getSecretKey } from "./shared";
16
- import { createSignerFromKeypair } from "@metaplex-foundation/umi";
17
- import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
18
18
 
19
19
  const payForTransaction = false;
20
20
  const testProgram = true;
21
21
 
22
22
  export async function main() {
23
23
  const [, umi] = getSolanaRpcConnection(
24
- buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!),
24
+ LOCAL_IRONFORGE_API_URL,
25
25
  testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM
26
26
  );
27
27
 
@@ -33,7 +33,7 @@ export async function main() {
33
33
  const client = getClient(LendingPlatform.Marginfi, {
34
34
  signer,
35
35
  showLogs: true,
36
- rpcUrl: buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!),
36
+ rpcUrl: LOCAL_IRONFORGE_API_URL,
37
37
  programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
38
38
  });
39
39
 
@@ -1,20 +1,4 @@
1
1
  import { Keypair, PublicKey } from "@solana/web3.js";
2
- import { MARGINFI_ACCOUNTS_LOOKUP_TABLE } from "../src/constants/marginfiAccounts";
3
- import {
4
- MARGINFI_ACCOUNTS,
5
- DEFAULT_MARGINFI_GROUP,
6
- } from "../src/constants/marginfiAccounts";
7
- import {
8
- MARGINFI_PROGRAM_ID,
9
- marginfiAccountInitialize,
10
- } from "../src/marginfi-sdk";
11
- import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
12
- import {
13
- buildIronforgeApiUrl,
14
- getEmptyMarginfiAccountsByAuthority,
15
- getSolanaRpcConnection,
16
- SOLAUTO_MANAGER,
17
- } from "../src";
18
2
  import {
19
3
  createSignerFromKeypair,
20
4
  publicKey,
@@ -25,10 +9,22 @@ import {
25
9
  toWeb3JsInstruction,
26
10
  toWeb3JsKeypair,
27
11
  } from "@metaplex-foundation/umi-web3js-adapters";
12
+ import {
13
+ MARGINFI_ACCOUNTS_LOOKUP_TABLE,
14
+ MARGINFI_ACCOUNTS,
15
+ DEFAULT_MARGINFI_GROUP,
16
+ getEmptyMarginfiAccountsByAuthority,
17
+ getSolanaRpcConnection,
18
+ SOLAUTO_MANAGER,
19
+ marginfiAccountInitialize,
20
+ LOCAL_IRONFORGE_API_URL,
21
+ MARGINFI_PROD_PROGRAM,
22
+ } from "../src";
23
+ import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
28
24
 
29
25
  const LOOKUP_TABLE_ADDRESS = new PublicKey(MARGINFI_ACCOUNTS_LOOKUP_TABLE);
30
26
  let [, umi] = getSolanaRpcConnection(
31
- buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!)
27
+ LOCAL_IRONFORGE_API_URL
32
28
  );
33
29
  umi = umi.use(
34
30
  signerIdentity(
@@ -68,45 +64,43 @@ async function addImfiAccounts() {
68
64
  SOLAUTO_MANAGER
69
65
  );
70
66
 
67
+ const iMfiAccountsPerGrp = 2;
71
68
  for (const group in MARGINFI_ACCOUNTS) {
72
69
  const emptyAccs = imfiAccounts.filter((x) => x.group.toString() === group);
73
- if (emptyAccs.length > 0) {
70
+ if (emptyAccs.length >= iMfiAccountsPerGrp) {
74
71
  await updateLookupTable(
75
72
  emptyAccs.map((x) => x.publicKey.toString()),
76
73
  LOOKUP_TABLE_ADDRESS
77
74
  );
78
75
  } else {
79
- console.log("Creating Imfi account for group:", group);
80
- const iMfiAccountKeypair = umi.eddsa.generateKeypair();
81
- const iMfiAccount = createSignerFromKeypair(umi, iMfiAccountKeypair);
82
- const umiIx = marginfiAccountInitialize(umi, {
83
- marginfiAccount: iMfiAccount,
84
- marginfiGroup: publicKey(group),
85
- authority: solautoManager,
86
- feePayer: solautoManager,
87
- });
88
- const ix = toWeb3JsInstruction(umiIx.getInstructions()[0]);
89
- await createAndSendV0Tx([ix], solautoManagerKeypair, [
90
- toWeb3JsKeypair(iMfiAccountKeypair),
91
- ]);
92
- await updateLookupTable(
93
- [iMfiAccount.publicKey.toString()],
94
- LOOKUP_TABLE_ADDRESS
95
- );
76
+ for (let i = 0; i < iMfiAccountsPerGrp - emptyAccs.length; i++) {
77
+ console.log("Creating Imfi account for group:", group);
78
+ const iMfiAccountKeypair = umi.eddsa.generateKeypair();
79
+ const iMfiAccount = createSignerFromKeypair(umi, iMfiAccountKeypair);
80
+ const umiIx = marginfiAccountInitialize(umi, {
81
+ marginfiAccount: iMfiAccount,
82
+ marginfiGroup: publicKey(group),
83
+ authority: solautoManager,
84
+ feePayer: solautoManager,
85
+ });
86
+ const ix = toWeb3JsInstruction(umiIx.getInstructions()[0]);
87
+ await createAndSendV0Tx([ix], solautoManagerKeypair, [
88
+ toWeb3JsKeypair(iMfiAccountKeypair),
89
+ ]);
90
+ await updateLookupTable(
91
+ [iMfiAccount.publicKey.toString()],
92
+ LOOKUP_TABLE_ADDRESS
93
+ );
94
+ }
96
95
  }
97
96
  }
98
97
  }
99
98
 
100
99
  updateLookupTable(
101
- [DEFAULT_MARGINFI_GROUP, MARGINFI_PROGRAM_ID],
100
+ [DEFAULT_MARGINFI_GROUP, MARGINFI_PROD_PROGRAM.toString()], // TODO
102
101
  LOOKUP_TABLE_ADDRESS
103
102
  );
104
103
 
105
104
  addBanks().then((x) => x);
106
105
 
107
106
  addImfiAccounts().then((x) => x);
108
-
109
- // TODO: get rid of these lookup tables
110
- // EoEVYjz3MnsX6fKyxrwJkRhzMCHKjj6dvnjTCHoZLMc7
111
- // AuoepJfrCrkQF2PeUAgpnnJybRoiff82cNdwXTqyjjvm
112
- // Bno3JybASPc1jNBZ9rnrdKVvbhk6UNMvSsYvgtitq3zb
@@ -1,23 +1,21 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { getTokenAccounts } from "../src/utils/accountUtils";
3
2
  import {
4
3
  SOLAUTO_FEES_WALLET,
5
4
  SOLAUTO_MANAGER,
6
- } from "../src/constants/generalAccounts";
7
- import { ALL_SUPPORTED_TOKENS } from "../src/constants/tokenConstants";
8
- import { updateLookupTable } from "./shared";
9
- import {
10
5
  SOLAUTO_LUT,
11
6
  STANDARD_LUT_ACCOUNTS,
12
- } from "../src/constants/solautoConstants";
13
- import {
14
- buildHeliusApiUrl,
7
+ SWITCHBOARD_PRICE_FEED_IDS,
8
+ ALL_SUPPORTED_TOKENS,
15
9
  getAllMarginfiAccountsByAuthority,
16
10
  getSolanaRpcConnection,
17
- } from "../src/utils";
18
- import { SWITCHBOARD_PRICE_FEED_IDS } from "../src/constants/switchboardConstants";
11
+ getTokenAccounts,
12
+ LOCAL_IRONFORGE_API_URL,
13
+ } from "../src";
14
+ import { updateLookupTable } from "./shared";
19
15
 
20
- const LOOKUP_TABLE_ADDRESS = Boolean(SOLAUTO_LUT) ? new PublicKey(SOLAUTO_LUT) : undefined;
16
+ const LOOKUP_TABLE_ADDRESS = Boolean(SOLAUTO_LUT)
17
+ ? new PublicKey(SOLAUTO_LUT)
18
+ : undefined;
21
19
  const solautoManagerTokenAccounts = getTokenAccounts(
22
20
  SOLAUTO_MANAGER,
23
21
  ALL_SUPPORTED_TOKENS.map((x) => new PublicKey(x))
@@ -29,7 +27,7 @@ const solautoFeeWalletTokenAccounts = getTokenAccounts(
29
27
 
30
28
  export async function updateSolautoLut(additionalAccounts?: string[]) {
31
29
  const [_, umi] = getSolanaRpcConnection(
32
- buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
30
+ LOCAL_IRONFORGE_API_URL
33
31
  );
34
32
  const ismAccounts = await getAllMarginfiAccountsByAuthority(
35
33
  umi,
@@ -43,7 +41,7 @@ export async function updateSolautoLut(additionalAccounts?: string[]) {
43
41
  ...solautoManagerTokenAccounts.map((x) => x.toString()),
44
42
  ...solautoFeeWalletTokenAccounts.map((x) => x.toString()),
45
43
  ...ismAccounts.map((x) => x.marginfiAccount.toString()),
46
- ...Object.values(SWITCHBOARD_PRICE_FEED_IDS).map(x => x.feedId),
44
+ ...Object.values(SWITCHBOARD_PRICE_FEED_IDS).map((x) => x.feedId),
47
45
  ...(additionalAccounts ?? []),
48
46
  ],
49
47
  LOOKUP_TABLE_ADDRESS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.623",
3
+ "version": "1.0.625",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -1,5 +1,10 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
+ import { buildIronforgeApiUrl } from "../utils";
2
3
 
3
4
  export const USD_DECIMALS = 9;
4
5
  export const SOLAUTO_FEES_WALLET = new PublicKey("AprYCPiVeKMCgjQ2ZufwChMzvQ5kFjJo2ekTLSkXsQDm");
5
- export const SOLAUTO_MANAGER = new PublicKey("MNGRcX4nc7quPdzBbNKJ4ScK5EE73JnwJVGxuJXhHCY");
6
+ export const SOLAUTO_MANAGER = new PublicKey("MNGRcX4nc7quPdzBbNKJ4ScK5EE73JnwJVGxuJXhHCY");
7
+
8
+ export const LOCAL_IRONFORGE_API_URL = buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!);
9
+
10
+ export const BASIS_POINTS = 10000;
@@ -1,5 +1,6 @@
1
- export * from './generalAccounts';
2
- export * from './marginfiAccounts';
3
- export * from './pythConstants';
4
- export * from './solautoConstants';
5
- export * from './tokenConstants';
1
+ export * from "./generalConstants";
2
+ export * from "./marginfiAccounts";
3
+ export * from "./pythConstants";
4
+ export * from "./solautoConstants";
5
+ export * from "./switchboardConstants";
6
+ export * from "./tokenConstants";
@@ -1,14 +1,19 @@
1
+ import { PublicKey } from "@solana/web3.js";
1
2
  import { NATIVE_MINT } from "@solana/spl-token";
2
3
  import * as tokens from "./tokenConstants";
3
4
  import { MarginfiAssetAccounts } from "../types/accounts";
4
- import { PublicKey } from "@solana/web3.js";
5
5
  import { SWITCHBOARD_PRICE_FEED_IDS } from "./switchboardConstants";
6
6
 
7
+ export const MARGINFI_PROD_PROGRAM = new PublicKey(
8
+ "MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA"
9
+ );
10
+ export const MARGINFI_STAGING_PROGRAM = new PublicKey(
11
+ "stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct"
12
+ );
13
+
7
14
  export const DEFAULT_MARGINFI_GROUP =
8
15
  "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
9
16
 
10
- export const DEFAULT_PUBKEY = PublicKey.default.toString();
11
-
12
17
  const USDC_PRICE_ORACLE = "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX";
13
18
 
14
19
  export const MARGINFI_ACCOUNTS: {
@@ -149,7 +154,8 @@ export const MARGINFI_ACCOUNTS: {
149
154
  bank: "3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM",
150
155
  liquidityVault: "863K9YPVT3xbUGFZevrQJLqMux3UdRkwNQ6usAp4hJyy",
151
156
  vaultAuthority: "Qsv2rnNRdv59AwRU3YmGPMCTdKT41CDAKyYAr4srCJR",
152
- priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.RETARDIO.toString()].feedId,
157
+ priceOracle:
158
+ SWITCHBOARD_PRICE_FEED_IDS[tokens.RETARDIO.toString()].feedId,
153
159
  },
154
160
  [tokens.USDC]: {
155
161
  bank: "6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5",
@@ -184,9 +190,12 @@ export const MARGINFI_ACCOUNTS: {
184
190
  liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
185
191
  vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
186
192
  priceOracle: USDC_PRICE_ORACLE,
187
- }
188
- }
193
+ },
194
+ },
189
195
  };
190
196
 
191
197
  export const MARGINFI_ACCOUNTS_LOOKUP_TABLE =
192
198
  "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
199
+
200
+ export const MARGINFI_STAGING_ACCOUNTS_LOOKUP_TABLE =
201
+ "EoEVYjz3MnsX6fKyxrwJkRhzMCHKjj6dvnjTCHoZLMc7";
@@ -9,9 +9,8 @@ import {
9
9
  ASSOCIATED_TOKEN_PROGRAM_ID,
10
10
  TOKEN_PROGRAM_ID,
11
11
  } from "@solana/spl-token";
12
- import { SOLAUTO_MANAGER } from "./generalAccounts";
12
+ import { SOLAUTO_MANAGER } from "./generalConstants";
13
13
  import { JUPITER_PROGRAM_ID } from "../jupiter-sdk";
14
- import { HNT, JLP, JTO, JUP, PYTH, WETH } from "./tokenConstants";
15
14
 
16
15
  export const SOLAUTO_PROD_PROGRAM = new PublicKey(
17
16
  "AutoyKBRaHSBHy9RsmXCZMy6nNFAg5FYijrvZyQcNLV"
@@ -22,8 +21,6 @@ export const SOLAUTO_TEST_PROGRAM = new PublicKey(
22
21
 
23
22
  (globalThis as any).SHOW_LOGS = false;
24
23
 
25
- export const BASIS_POINTS = 10000;
26
-
27
24
  export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
28
25
  export const MIN_REPAY_GAP_BPS = 50;
29
26
  export const MIN_BOOST_GAP_BPS = 50;
@@ -33,8 +30,6 @@ export const REFERRER_PERCENTAGE = 0.15;
33
30
 
34
31
  export const PRICES: { [key: string]: { price: number; time: number } } = {};
35
32
 
36
- export const JITO_BLOCK_ENGINE = "https://mainnet.block-engine.jito.wtf";
37
-
38
33
  export const JITO_TIP_ACCOUNTS = [
39
34
  "96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
40
35
  "HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
@@ -59,7 +54,4 @@ export const STANDARD_LUT_ACCOUNTS = [
59
54
  SYSVAR_RENT_PUBKEY,
60
55
  SYSVAR_INSTRUCTIONS_PUBKEY,
61
56
  JUPITER_PROGRAM_ID,
62
- ].map((x) => x.toString());
63
-
64
- // TODO:
65
- export const BROKEN_TOKENS = [JUP, JLP, WETH, HNT, JTO, PYTH];
57
+ ].map((x) => x.toString());
@@ -1,10 +1,10 @@
1
- import { FlProviderBase } from "./flProviderBase";
2
1
  import { PublicKey } from "@solana/web3.js";
3
- import { FlashLoanDetails, FlashLoanRequirements } from "../../types";
4
2
  import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
3
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
4
+ import { FlProviderBase } from "./flProviderBase";
5
+ import { FlashLoanDetails, ProgramEnv } from "../../types";
5
6
  import { TokenType } from "../../generated";
6
7
  import { MarginfiFlProvider } from "./marginfiFlProvider";
7
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
8
8
 
9
9
  export class FlProviderAggregator extends FlProviderBase {
10
10
  private marginfiFlProvider!: MarginfiFlProvider;
@@ -14,15 +14,17 @@ export class FlProviderAggregator extends FlProviderBase {
14
14
  signer: Signer,
15
15
  authority: PublicKey,
16
16
  supplyMint: PublicKey,
17
- debtMint: PublicKey
17
+ debtMint: PublicKey,
18
+ programEnv?: ProgramEnv
18
19
  ) {
19
- super(umi, signer, authority, supplyMint, debtMint);
20
+ super(umi, signer, authority, supplyMint, debtMint, programEnv);
20
21
  this.marginfiFlProvider = new MarginfiFlProvider(
21
22
  umi,
22
23
  signer,
23
24
  authority,
24
25
  supplyMint,
25
- debtMint
26
+ debtMint,
27
+ programEnv
26
28
  );
27
29
  }
28
30
 
@@ -60,7 +62,7 @@ export class FlProviderAggregator extends FlProviderBase {
60
62
  }
61
63
 
62
64
  flFeeBps(source: TokenType, signerFlashLoan?: boolean): number {
63
- return this.flProvider(source).flFeeBps(source);
65
+ return this.flProvider(source).flFeeBps(source, signerFlashLoan);
64
66
  }
65
67
 
66
68
  flashBorrow(
@@ -1,10 +1,11 @@
1
+ import { PublicKey } from "@solana/web3.js";
1
2
  import {
2
3
  Signer,
3
4
  transactionBuilder,
4
5
  TransactionBuilder,
5
6
  Umi,
6
7
  } from "@metaplex-foundation/umi";
7
- import { PublicKey } from "@solana/web3.js";
8
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
8
9
  import {
9
10
  fromBaseUnit,
10
11
  getTokenAccount,
@@ -13,8 +14,7 @@ import {
13
14
  tokenInfo,
14
15
  } from "../../utils";
15
16
  import { TokenType } from "../../generated";
16
- import { FlashLoanDetails } from "../../types";
17
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
17
+ import { FlashLoanDetails, ProgramEnv } from "../../types";
18
18
 
19
19
  export abstract class FlProviderBase {
20
20
  protected flSigners: Signer[] = [];
@@ -24,7 +24,8 @@ export abstract class FlProviderBase {
24
24
  protected signer: Signer,
25
25
  protected authority: PublicKey,
26
26
  protected supplyMint: PublicKey,
27
- protected debtMint: PublicKey
27
+ protected debtMint: PublicKey,
28
+ protected programEnv: ProgramEnv = "Prod"
28
29
  ) {}
29
30
 
30
31
  abstract initialize(): Promise<void>;
@@ -1,3 +1,4 @@
1
+ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js";
1
2
  import {
2
3
  AccountMeta,
3
4
  createSignerFromKeypair,
@@ -6,6 +7,7 @@ import {
6
7
  transactionBuilder,
7
8
  TransactionBuilder,
8
9
  } from "@metaplex-foundation/umi";
10
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
9
11
  import { MARGINFI_ACCOUNTS } from "../../constants";
10
12
  import {
11
13
  Bank,
@@ -19,7 +21,6 @@ import {
19
21
  safeFetchAllBank,
20
22
  } from "../../marginfi-sdk";
21
23
  import { FlProviderBase } from "./flProviderBase";
22
- import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js";
23
24
  import {
24
25
  bytesToI80F48,
25
26
  consoleLog,
@@ -34,9 +35,8 @@ import {
34
35
  toBps,
35
36
  tokenInfo,
36
37
  } from "../../utils";
37
- import { TokenType } from "../../generated";
38
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
39
38
  import { FlashLoanDetails } from "../../types";
39
+ import { TokenType } from "../../generated";
40
40
 
41
41
  interface IMFIAccount {
42
42
  signer?: Signer;
@@ -116,7 +116,6 @@ export class MarginfiFlProvider extends FlProviderBase {
116
116
  (x) => x.group.toString() == this.liquidityBank(sources[0]).group
117
117
  );
118
118
 
119
- // TODO: instead of picking first compatibleMarginfiAccoutn, pick one where we already have it in the marginfi Lut
120
119
  const signer =
121
120
  compatibleMarginfiAccounts.length > 0
122
121
  ? undefined
@@ -291,13 +290,13 @@ export class MarginfiFlProvider extends FlProviderBase {
291
290
  const iMfiAccount = this.iMfiAccount(flashLoan.liquiditySource)!;
292
291
 
293
292
  const remainingAccounts: AccountMeta[] = [];
294
- let includedFlashLoanToken = false;
293
+ let flBankHadPrevBalance = false;
295
294
 
296
295
  if (iMfiAccount?.accountData) {
297
296
  iMfiAccount.accountData.lendingAccount.balances.forEach(async (x) => {
298
297
  if (x.active) {
299
298
  if (x.bankPk.toString() === bank.publicKey.toString()) {
300
- includedFlashLoanToken = true;
299
+ flBankHadPrevBalance = true;
301
300
  }
302
301
 
303
302
  // TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
@@ -324,35 +323,12 @@ export class MarginfiFlProvider extends FlProviderBase {
324
323
  }
325
324
  });
326
325
  }
327
- if (!includedFlashLoanToken) {
328
- remainingAccounts.push(
329
- ...[
330
- {
331
- pubkey: bank.publicKey,
332
- isSigner: false,
333
- isWritable: false,
334
- },
335
- {
336
- pubkey: publicKey(associatedBankAccs.priceOracle),
337
- isSigner: false,
338
- isWritable: false,
339
- },
340
- ]
341
- );
342
- }
343
-
344
- const closeBalances = remainingAccounts
345
- .filter(
346
- (x, index) =>
347
- index % 2 === 0 && x.pubkey.toString() !== bank.publicKey.toString()
348
- )
349
- .map((x) => toWeb3JsPublicKey(x.pubkey));
350
326
 
351
327
  return transactionBuilder()
352
328
  .add(
353
329
  lendingAccountRepay(this.umi, {
354
330
  amount: flashLoan.baseUnitAmount,
355
- repayAll: false,
331
+ repayAll: !flBankHadPrevBalance,
356
332
  bank: bank.publicKey,
357
333
  bankLiquidityVault: publicKey(associatedBankAccs.liquidityVault),
358
334
  marginfiAccount: publicKey(iMfiAccount.accountPk),
@@ -366,13 +342,6 @@ export class MarginfiFlProvider extends FlProviderBase {
366
342
  ),
367
343
  })
368
344
  )
369
- .add(
370
- closeBalances.length
371
- ? closeBalances.map((bank) =>
372
- this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup)
373
- )
374
- : []
375
- )
376
345
  .add(
377
346
  lendingAccountEndFlashloan(this.umi, {
378
347
  marginfiAccount: publicKey(iMfiAccount.accountPk),
@@ -1,4 +1,5 @@
1
1
  import { QuoteResponse } from "@jup-ag/api";
2
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
2
3
  import { FlashLoanRequirements } from "../../types";
3
4
  import { SolautoClient } from "../solauto";
4
5
  import { JupSwapManager, SwapParams, SwapInput } from "../swap";
@@ -13,7 +14,6 @@ import {
13
14
  toBaseUnit,
14
15
  tokenInfo,
15
16
  } from "../../utils";
16
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
17
17
 
18
18
  export class RebalanceSwapManager {
19
19
  public swapParams!: SwapParams;
@@ -1,3 +1,6 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
3
+ import { transactionBuilder } from "@metaplex-foundation/umi";
1
4
  import { SolautoClient } from "../solauto";
2
5
  import {
3
6
  FlashLoanRequirements,
@@ -14,8 +17,6 @@ import {
14
17
  safeGetPrice,
15
18
  tokenInfo,
16
19
  } from "../../utils";
17
- import { getRebalanceValues, RebalanceValues } from "./rebalanceValues";
18
- import { SolautoFeesBps } from "./solautoFees";
19
20
  import {
20
21
  PositionTokenState,
21
22
  RebalanceDirection,
@@ -25,10 +26,9 @@ import {
25
26
  TokenBalanceChangeType,
26
27
  TokenType,
27
28
  } from "../../generated";
28
- import { PublicKey } from "@solana/web3.js";
29
+ import { getRebalanceValues, RebalanceValues } from "./rebalanceValues";
30
+ import { SolautoFeesBps } from "./solautoFees";
29
31
  import { RebalanceSwapManager } from "./rebalanceSwapManager";
30
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
31
- import { transactionBuilder } from "@metaplex-foundation/umi";
32
32
 
33
33
  export class RebalanceTxBuilder {
34
34
  private values!: RebalanceValues;