@haven-fi/solauto-sdk 1.0.624 → 1.0.626

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 +12 -4
  8. package/dist/constants/marginfiAccounts.d.ts.map +1 -1
  9. package/dist/constants/marginfiAccounts.js +62 -8
  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 +6 -6
  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 +22 -24
  32. package/dist/services/solauto/solautoMarginfiClient.d.ts +5 -5
  33. package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
  34. package/dist/services/solauto/solautoMarginfiClient.js +22 -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 +6 -5
  49. package/dist/solautoPosition/solautoPositionEx.d.ts +4 -2
  50. package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
  51. package/dist/solautoPosition/solautoPositionEx.js +12 -5
  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 +13 -4
  67. package/dist/utils/marginfiUtils.d.ts.map +1 -1
  68. package/dist/utils/marginfiUtils.js +78 -22
  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 +40 -49
  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 +88 -10
  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 +9 -8
  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 +10 -15
  103. package/src/services/solauto/solautoMarginfiClient.ts +26 -30
  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 +7 -8
  109. package/src/solautoPosition/solautoPositionEx.ts +21 -10
  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 +105 -28
  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 +1 @@
1
- {"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAEtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAIvD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsB5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D"}
1
+ {"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAGvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAIjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsB5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D"}
@@ -29,13 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getPullFeed = getPullFeed;
30
30
  exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
31
31
  exports.getSwitchboardFeedData = getSwitchboardFeedData;
32
- const anchor_1 = require("@coral-xyz/anchor");
33
- const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
34
32
  const web3_js_1 = require("@solana/web3.js");
35
- const switchboardConstants_1 = require("../constants/switchboardConstants");
36
33
  const umi_1 = require("@metaplex-foundation/umi");
37
34
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
35
+ const anchor_1 = require("@coral-xyz/anchor");
38
36
  const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
37
+ const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
38
+ const constants_1 = require("../constants");
39
39
  const generalUtils_1 = require("./generalUtils");
40
40
  const solanaUtils_1 = require("./solanaUtils");
41
41
  function getPullFeed(conn, mint, wallet) {
@@ -47,7 +47,7 @@ function getPullFeed(conn, mint, wallet) {
47
47
  const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
48
48
  const program = new anchor_1.Program(switchboard_json_1.default, provider);
49
49
  const { PullFeed } = OnDemand;
50
- return new PullFeed(program, new web3_js_1.PublicKey(switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
50
+ return new PullFeed(program, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
51
51
  }
52
52
  async function buildSwbSubmitResponseTx(conn, signer, mint) {
53
53
  const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
@@ -5,18 +5,24 @@ import {
5
5
  transactionBuilder,
6
6
  } from "@metaplex-foundation/umi";
7
7
  import {
8
- buildHeliusApiUrl,
9
8
  getSolanaRpcConnection,
10
9
  sendSingleOptimizedTransaction,
11
- } from "../src/utils/solanaUtils";
12
- import { marginfiAccountInitialize, safeFetchAllMarginfiAccount } from "../src/marginfi-sdk";
13
- import { MARGINFI_ACCOUNTS, SOLAUTO_MANAGER } from "../src/constants";
14
- import { getSecretKey } from "./shared";
10
+ getAllMarginfiAccountsByAuthority,
11
+ } from "../src/utils";
12
+ import {
13
+ marginfiAccountInitialize,
14
+ safeFetchAllMarginfiAccount,
15
+ } from "../src/marginfi-sdk";
16
+ import {
17
+ LOCAL_IRONFORGE_API_URL,
18
+ MARGINFI_ACCOUNTS,
19
+ SOLAUTO_MANAGER,
20
+ } from "../src/constants";
15
21
  import { updateSolautoLut } from "./updateSolautoLUT";
16
- import { getAllMarginfiAccountsByAuthority } from "../src/utils";
22
+ import { getSecretKey } from "./shared";
17
23
 
18
24
  async function createIntermediarySolautoManagerAccounts() {
19
- let [connection, umi] = getSolanaRpcConnection(buildHeliusApiUrl(process.env.HELIUS_API_KEY!));
25
+ let [connection, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
20
26
 
21
27
  const secretKey = getSecretKey("solauto-manager");
22
28
  const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
@@ -24,13 +30,24 @@ async function createIntermediarySolautoManagerAccounts() {
24
30
 
25
31
  umi = umi.use(signerIdentity(signer));
26
32
 
27
- const accounts = await getAllMarginfiAccountsByAuthority(umi, SOLAUTO_MANAGER, undefined, false);
28
- const data = await safeFetchAllMarginfiAccount(umi, accounts.map(x => publicKey(x.marginfiAccount)));
29
- const existingMarginfiGroups = data.map(x => x.group.toString());
33
+ const accounts = await getAllMarginfiAccountsByAuthority(
34
+ umi,
35
+ SOLAUTO_MANAGER,
36
+ undefined,
37
+ false
38
+ );
39
+ const data = await safeFetchAllMarginfiAccount(
40
+ umi,
41
+ accounts.map((x) => publicKey(x.marginfiAccount))
42
+ );
43
+ const existingMarginfiGroups = data.map((x) => x.group.toString());
30
44
 
31
45
  for (const group of Object.keys(MARGINFI_ACCOUNTS)) {
32
46
  if (existingMarginfiGroups.includes(group.toString())) {
33
- console.log("Already have Solauto Manager Marginfi Account for group:", group);
47
+ console.log(
48
+ "Already have Solauto Manager Marginfi Account for group:",
49
+ group
50
+ );
34
51
  continue;
35
52
  }
36
53
 
@@ -45,7 +62,7 @@ async function createIntermediarySolautoManagerAccounts() {
45
62
  authority: signer,
46
63
  feePayer: signer,
47
64
  });
48
-
65
+
49
66
  await sendSingleOptimizedTransaction(
50
67
  umi,
51
68
  connection,
@@ -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
- 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";
1
+ import { Keypair } from "@solana/web3.js";
18
2
  import {
19
3
  createSignerFromKeypair,
20
4
  publicKey,
@@ -25,11 +9,20 @@ import {
25
9
  toWeb3JsInstruction,
26
10
  toWeb3JsKeypair,
27
11
  } from "@metaplex-foundation/umi-web3js-adapters";
12
+ import {
13
+ getEmptyMarginfiAccountsByAuthority,
14
+ getSolanaRpcConnection,
15
+ SOLAUTO_MANAGER,
16
+ marginfiAccountInitialize,
17
+ LOCAL_IRONFORGE_API_URL,
18
+ getMarginfiAccounts,
19
+ } from "../src";
20
+ import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
28
21
 
29
- const LOOKUP_TABLE_ADDRESS = new PublicKey(MARGINFI_ACCOUNTS_LOOKUP_TABLE);
30
- let [, umi] = getSolanaRpcConnection(
31
- buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY!)
32
- );
22
+ const mfiAccounts = getMarginfiAccounts("Prod");
23
+
24
+ const LOOKUP_TABLE_ADDRESS = mfiAccounts.lookupTable;
25
+ let [, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
33
26
  umi = umi.use(
34
27
  signerIdentity(
35
28
  createSignerFromKeypair(umi, umi.eddsa.generateKeypair()),
@@ -45,9 +38,9 @@ const solautoManager = createSignerFromKeypair(
45
38
  );
46
39
 
47
40
  async function addBanks() {
48
- for (const group in MARGINFI_ACCOUNTS) {
49
- for (const key in MARGINFI_ACCOUNTS[group]) {
50
- const accounts = MARGINFI_ACCOUNTS[group][key];
41
+ for (const group in mfiAccounts.bankAccounts) {
42
+ for (const key in mfiAccounts.bankAccounts[group]) {
43
+ const accounts = mfiAccounts.bankAccounts[group][key];
51
44
  await updateLookupTable(
52
45
  [
53
46
  group,
@@ -68,45 +61,43 @@ async function addImfiAccounts() {
68
61
  SOLAUTO_MANAGER
69
62
  );
70
63
 
71
- for (const group in MARGINFI_ACCOUNTS) {
64
+ const iMfiAccountsPerGrp = 2;
65
+ for (const group in mfiAccounts.bankAccounts) {
72
66
  const emptyAccs = imfiAccounts.filter((x) => x.group.toString() === group);
73
- if (emptyAccs.length > 0) {
67
+ if (emptyAccs.length >= iMfiAccountsPerGrp) {
74
68
  await updateLookupTable(
75
69
  emptyAccs.map((x) => x.publicKey.toString()),
76
70
  LOOKUP_TABLE_ADDRESS
77
71
  );
78
72
  } 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
- );
73
+ for (let i = 0; i < iMfiAccountsPerGrp - emptyAccs.length; i++) {
74
+ console.log("Creating Imfi account for group:", group);
75
+ const iMfiAccountKeypair = umi.eddsa.generateKeypair();
76
+ const iMfiAccount = createSignerFromKeypair(umi, iMfiAccountKeypair);
77
+ const umiIx = marginfiAccountInitialize(umi, {
78
+ marginfiAccount: iMfiAccount,
79
+ marginfiGroup: publicKey(group),
80
+ authority: solautoManager,
81
+ feePayer: solautoManager,
82
+ });
83
+ const ix = toWeb3JsInstruction(umiIx.getInstructions()[0]);
84
+ await createAndSendV0Tx([ix], solautoManagerKeypair, [
85
+ toWeb3JsKeypair(iMfiAccountKeypair),
86
+ ]);
87
+ await updateLookupTable(
88
+ [iMfiAccount.publicKey.toString()],
89
+ LOOKUP_TABLE_ADDRESS
90
+ );
91
+ }
96
92
  }
97
93
  }
98
94
  }
99
95
 
100
96
  updateLookupTable(
101
- [DEFAULT_MARGINFI_GROUP, MARGINFI_PROGRAM_ID],
97
+ [mfiAccounts.defaultGroup.toString(), mfiAccounts.program.toString()],
102
98
  LOOKUP_TABLE_ADDRESS
103
99
  );
104
100
 
105
101
  addBanks().then((x) => x);
106
102
 
107
103
  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.624",
3
+ "version": "1.0.626",
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,20 +1,54 @@
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
+ import { ProgramEnv } from "../types";
6
7
 
7
- export const DEFAULT_MARGINFI_GROUP =
8
+ export const MARGINFI_PROD_PROGRAM = new PublicKey(
9
+ "MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA"
10
+ );
11
+ export const MARGINFI_STAGING_PROGRAM = new PublicKey(
12
+ "stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct"
13
+ );
14
+
15
+ const PROD_DEFAULT_MARGINFI_GROUP =
8
16
  "4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
9
17
 
10
- export const DEFAULT_PUBKEY = PublicKey.default.toString();
18
+ const STAGING_DEFAULT_MARGINFI_GROUP =
19
+ "FCPfpHA69EbS8f9KKSreTRkXbzFpunsKuYf5qNmnJjpo";
11
20
 
12
21
  const USDC_PRICE_ORACLE = "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX";
13
22
 
14
- export const MARGINFI_ACCOUNTS: {
23
+ export type MarginfiAccountsMap = {
15
24
  [group: string]: { [token: string]: MarginfiAssetAccounts };
16
- } = {
17
- [DEFAULT_MARGINFI_GROUP.toString()]: {
25
+ };
26
+
27
+ const MARGINFI_STAGING_ACCOUNTS: MarginfiAccountsMap = {
28
+ [STAGING_DEFAULT_MARGINFI_GROUP]: {
29
+ [NATIVE_MINT.toString()]: {
30
+ bank: "3evdJSa25nsUiZzEUzd92UNa13TPRJrje1dRyiQP5Lhp",
31
+ liquidityVault: "FVXESa7wCd1tf3o9LGroBc3Ym8Gpcq1HdsLek6oo7Ykv",
32
+ vaultAuthority: "DuYk1WGq8UsjW5ThLtaehFLrnJeupTjtF7TaPzja9LBQ",
33
+ priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE",
34
+ },
35
+ [tokens.USDC]: {
36
+ bank: "Ek5JSFJFD8QgXM6rPDCzf31XhDp1q3xezaWYSkJWqbqc",
37
+ liquidityVault: "6n7xXMni5WJKUMb4Vm5Zis6UaUtGF5xEGmagZNVWWoKB",
38
+ vaultAuthority: "9mXNyA5yS4WSTpYUa5gi3yBrSJWWM7XNPNDWRzWGjdVe",
39
+ priceOracle: USDC_PRICE_ORACLE,
40
+ },
41
+ [tokens.USDT]: {
42
+ bank: "4WFCsVXwfnQvZG52VvPwae7CtL13PUFVWdjkw5YCRBo6",
43
+ liquidityVault: "BFSyniKfXU9rHqUvHLKeZMivQsAKWTE7HZ1fW6vZcvJp",
44
+ vaultAuthority: "Fgxe3SUMzcNuLtT9Xkv8QhhWXCmu4VxynzUMwCF4HvJd",
45
+ priceOracle: "HT2PLQBcG5EiCcNSaMHAjSgd9F98ecpATbk4Sk5oYuM",
46
+ },
47
+ },
48
+ };
49
+
50
+ const MARGINFI_PROD_ACCOUNTS: MarginfiAccountsMap = {
51
+ [PROD_DEFAULT_MARGINFI_GROUP.toString()]: {
18
52
  [NATIVE_MINT.toString()]: {
19
53
  bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
20
54
  liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
@@ -149,7 +183,8 @@ export const MARGINFI_ACCOUNTS: {
149
183
  bank: "3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM",
150
184
  liquidityVault: "863K9YPVT3xbUGFZevrQJLqMux3UdRkwNQ6usAp4hJyy",
151
185
  vaultAuthority: "Qsv2rnNRdv59AwRU3YmGPMCTdKT41CDAKyYAr4srCJR",
152
- priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.RETARDIO.toString()].feedId,
186
+ priceOracle:
187
+ SWITCHBOARD_PRICE_FEED_IDS[tokens.RETARDIO.toString()].feedId,
153
188
  },
154
189
  [tokens.USDC]: {
155
190
  bank: "6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5",
@@ -184,9 +219,52 @@ export const MARGINFI_ACCOUNTS: {
184
219
  liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
185
220
  vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
186
221
  priceOracle: USDC_PRICE_ORACLE,
187
- }
188
- }
222
+ },
223
+ },
189
224
  };
190
225
 
191
- export const MARGINFI_ACCOUNTS_LOOKUP_TABLE =
226
+ const MARGINFI_PROD_ACCOUNTS_LOOKUP_TABLE =
192
227
  "GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
228
+
229
+ const MARGINFI_STAGING_ACCOUNTS_LOOKUP_TABLE =
230
+ "EoEVYjz3MnsX6fKyxrwJkRhzMCHKjj6dvnjTCHoZLMc7";
231
+
232
+ export interface MarginfiProgramAccounts {
233
+ program: PublicKey;
234
+ defaultGroup: PublicKey;
235
+ lookupTable: PublicKey;
236
+ bankAccounts: MarginfiAccountsMap;
237
+ }
238
+
239
+ export function getMarginfiAccounts(
240
+ programEnv?: ProgramEnv,
241
+ marginfiGroup?: PublicKey
242
+ ): MarginfiProgramAccounts {
243
+ if (programEnv === undefined) {
244
+ if (Boolean(marginfiGroup)) {
245
+ programEnv = Object.keys(MARGINFI_PROD_ACCOUNTS).includes(
246
+ marginfiGroup!.toString()
247
+ )
248
+ ? "Prod"
249
+ : "Staging";
250
+ } else {
251
+ programEnv = "Prod";
252
+ }
253
+ }
254
+
255
+ if (programEnv === "Prod") {
256
+ return {
257
+ program: MARGINFI_PROD_PROGRAM,
258
+ defaultGroup: new PublicKey(PROD_DEFAULT_MARGINFI_GROUP),
259
+ lookupTable: new PublicKey(MARGINFI_PROD_ACCOUNTS_LOOKUP_TABLE),
260
+ bankAccounts: MARGINFI_PROD_ACCOUNTS,
261
+ };
262
+ } else {
263
+ return {
264
+ program: MARGINFI_STAGING_PROGRAM,
265
+ defaultGroup: new PublicKey(STAGING_DEFAULT_MARGINFI_GROUP),
266
+ lookupTable: new PublicKey(MARGINFI_STAGING_ACCOUNTS_LOOKUP_TABLE),
267
+ bankAccounts: MARGINFI_STAGING_ACCOUNTS,
268
+ };
269
+ }
270
+ }
@@ -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());