@haven-fi/solauto-sdk 1.0.664 → 1.0.666

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.
@@ -7,7 +7,9 @@ import {
7
7
  getSolanaRpcConnection,
8
8
  getSolautoManagedPositions,
9
9
  LOCAL_IRONFORGE_API_URL,
10
+ ProgramEnv,
10
11
  SOLAUTO_PROD_PROGRAM,
12
+ SOLAUTO_TEST_PROGRAM,
11
13
  } from "../src";
12
14
 
13
15
  config({ path: path.join(__dirname, ".env") });
@@ -75,10 +77,10 @@ export function formatNumber(
75
77
  }
76
78
  }
77
79
 
78
- async function main(filterWhitelist: boolean) {
80
+ async function main(filterWhitelist: boolean, programEnv: ProgramEnv = "Prod") {
79
81
  const [_, umi] = getSolanaRpcConnection(
80
82
  LOCAL_IRONFORGE_API_URL,
81
- SOLAUTO_PROD_PROGRAM
83
+ programEnv === "Prod" ? SOLAUTO_PROD_PROGRAM : SOLAUTO_TEST_PROGRAM
82
84
  );
83
85
 
84
86
  let positions = await getSolautoManagedPositions(umi);
@@ -161,5 +163,21 @@ async function main(filterWhitelist: boolean) {
161
163
  console.log(`Total net worth: $${formatNumber(netWorth, 2, 10000, 2)}`);
162
164
  }
163
165
 
164
- const filterWhitelist = true;
165
- main(filterWhitelist).then((x) => x);
166
+ const args = process.argv.slice(2); // Skip the first 2 (node + script path)
167
+
168
+ const parsedArgs: Record<string, string | boolean> = {};
169
+ for (const arg of args) {
170
+ if (arg.startsWith("--")) {
171
+ const [key, val] = arg.replace(/^--/, "").split("=");
172
+ parsedArgs[key] = val ?? true;
173
+ }
174
+ }
175
+
176
+ console.log("Parsed flags:", parsedArgs);
177
+
178
+ const filterWhitelist =
179
+ "filter" in parsedArgs ? parsedArgs["filter"] === "true" : true;
180
+ const programEnv =
181
+ "env" in parsedArgs ? (parsedArgs["env"] as ProgramEnv) : undefined;
182
+
183
+ main(filterWhitelist, programEnv).then((x) => x);
@@ -2,7 +2,6 @@ import { Keypair, PublicKey } from "@solana/web3.js";
2
2
  import { createSignerFromKeypair } from "@metaplex-foundation/umi";
3
3
  import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
4
4
  import {
5
- borrow,
6
5
  consoleLog,
7
6
  getClient,
8
7
  getSolanaRpcConnection,
@@ -13,11 +12,7 @@ import {
13
12
  rebalance,
14
13
  SOLAUTO_PROD_PROGRAM,
15
14
  SOLAUTO_TEST_PROGRAM,
16
- toBaseUnit,
17
- tokenInfo,
18
15
  TransactionsManager,
19
- USDC,
20
- WBTC,
21
16
  } from "../src";
22
17
  import { getSecretKey } from "./shared";
23
18
 
@@ -34,7 +29,7 @@ export async function main() {
34
29
 
35
30
  const signer = createSignerFromKeypair(
36
31
  umi,
37
- fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey()))
32
+ fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey("solauto-manager")))
38
33
  );
39
34
 
40
35
  const client = getClient(LendingPlatform.Marginfi, {
@@ -46,30 +41,27 @@ export async function main() {
46
41
  });
47
42
 
48
43
  await client.initialize({
49
- positionId: 2,
50
- // authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
51
- lpUserAccount: new PublicKey(
52
- "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
53
- ),
44
+ positionId: 1,
45
+ authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
46
+ // lpUserAccount: new PublicKey(
47
+ // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
48
+ // ),
54
49
  });
55
50
 
51
+ const transactionItems = [rebalance(client)];
56
52
 
57
- // const transactionItems = [
58
- // rebalance(client, 300),
59
- // ];
60
-
61
- // const txManager = new TransactionsManager(
62
- // client,
63
- // undefined,
64
- // payForTransaction ? "normal" : "only-simulate",
65
- // PriorityFeeSetting.Min,
66
- // true,
67
- // undefined,
68
- // { totalRetries: 5 }
69
- // );
70
- // const statuses = await txManager.clientSend(transactionItems);
53
+ const txManager = new TransactionsManager(
54
+ client,
55
+ undefined,
56
+ payForTransaction ? "normal" : "only-simulate",
57
+ PriorityFeeSetting.Min,
58
+ true,
59
+ undefined,
60
+ { totalRetries: 5 }
61
+ );
62
+ const statuses = await txManager.clientSend(transactionItems);
71
63
 
72
- // consoleLog(statuses);
64
+ consoleLog(statuses);
73
65
  }
74
66
 
75
67
  main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.664",
3
+ "version": "1.0.666",
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",
@@ -14,10 +14,10 @@
14
14
  "dependencies": {
15
15
  "@coral-xyz/anchor": "^0.30.1",
16
16
  "@jup-ag/api": "=6.0.24",
17
- "@metaplex-foundation/umi": "=0.9.1",
18
- "@metaplex-foundation/umi-bundle-defaults": "=0.9.1",
19
- "@metaplex-foundation/umi-signer-wallet-adapters": "=0.9.1",
20
- "@metaplex-foundation/umi-web3js-adapters": "=0.9.1",
17
+ "@metaplex-foundation/umi": "^0.9.1",
18
+ "@metaplex-foundation/umi-bundle-defaults": "^0.9.1",
19
+ "@metaplex-foundation/umi-signer-wallet-adapters": "^0.9.1",
20
+ "@metaplex-foundation/umi-web3js-adapters": "^0.9.1",
21
21
  "@solana/spl-token": "^0.4.0",
22
22
  "@solana/web3.js": "=1.95.8",
23
23
  "@switchboard-xyz/common": "=3.0.12",
@@ -21,7 +21,6 @@ export const SOLAUTO_TEST_PROGRAM = new PublicKey(
21
21
 
22
22
  (globalThis as any).SHOW_LOGS = false;
23
23
 
24
- export const MIN_POSITION_STATE_FRESHNESS_SECS = 5;
25
24
  export const MIN_REPAY_GAP_BPS = 50;
26
25
  export const MIN_BOOST_GAP_BPS = 50;
27
26
  export const MIN_USD_SUPPORTED_POSITION = 1000;
@@ -22,7 +22,6 @@ import {
22
22
  updatePosition,
23
23
  } from "../../generated";
24
24
  import {
25
- getSolautoPositionAccount,
26
25
  getTokenAccount,
27
26
  getWalletSplBalances,
28
27
  getWrappedInstruction,
@@ -47,7 +47,6 @@ import {
47
47
  lendingAccountWithdraw,
48
48
  marginfiAccountInitialize,
49
49
  safeFetchAllMarginfiAccount,
50
- safeFetchMarginfiAccount,
51
50
  } from "../../marginfi-sdk";
52
51
  import { SolautoClient, SolautoClientArgs } from "./solautoClient";
53
52
 
@@ -2,7 +2,6 @@ import bs58 from "bs58";
2
2
  import {
3
3
  PublicKey,
4
4
  TransactionExpiredBlockheightExceededError,
5
- VersionedTransaction,
6
5
  } from "@solana/web3.js";
7
6
  import {
8
7
  AddressLookupTableInput,
@@ -45,7 +45,7 @@ import {
45
45
  getRebalanceValues,
46
46
  SolautoFeesBps,
47
47
  } from "../services/rebalance";
48
- import { MIN_POSITION_STATE_FRESHNESS_SECS, TokenInfo } from "../constants";
48
+ import { TokenInfo } from "../constants";
49
49
 
50
50
  export interface PositionCustomArgs {
51
51
  lendingPlatform: LendingPlatform;
@@ -285,9 +285,7 @@ export abstract class SolautoPositionEx {
285
285
  eligibleForRebalance(
286
286
  bpsDistanceThreshold: number = 0
287
287
  ): RebalanceAction | undefined {
288
- return this.rebalanceHelper.eligibleForRebalance(
289
- bpsDistanceThreshold
290
- );
288
+ return this.rebalanceHelper.eligibleForRebalance(bpsDistanceThreshold);
291
289
  }
292
290
 
293
291
  eligibleForRefresh(): boolean {
@@ -477,7 +475,6 @@ class PositionRebalanceHelper {
477
475
  const realtimeLiqUtilRateBps = this.pos.liqUtilizationRateBps(
478
476
  PriceType.Realtime
479
477
  );
480
- const emaLiqUtilRateBps = this.pos.liqUtilizationRateBps(PriceType.Ema);
481
478
 
482
479
  if (
483
480
  this.pos.repayFromBps - realtimeLiqUtilRateBps <=
@@ -485,12 +482,11 @@ class PositionRebalanceHelper {
485
482
  ) {
486
483
  return "repay";
487
484
  } else if (
488
- (realtimeLiqUtilRateBps - this.pos.boostFromBps <= bpsDistanceThreshold ||
489
- emaLiqUtilRateBps - this.pos.boostFromBps <= bpsDistanceThreshold) &&
490
- this.validBoostFromHere()
485
+ realtimeLiqUtilRateBps - this.pos.boostFromBps <= bpsDistanceThreshold &&
486
+ this.validBoostFromHere() &&
487
+ this.sufficientLiquidityToBoost()
491
488
  ) {
492
- const sufficientLiquidity = this.sufficientLiquidityToBoost();
493
- return sufficientLiquidity ? "boost" : undefined;
489
+ return "boost";
494
490
  }
495
491
 
496
492
  return undefined;
@@ -1,76 +0,0 @@
1
- import {
2
- createSignerFromKeypair,
3
- publicKey,
4
- signerIdentity,
5
- transactionBuilder,
6
- } from "@metaplex-foundation/umi";
7
- import {
8
- getSolanaRpcConnection,
9
- sendSingleOptimizedTransaction,
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";
21
- import { updateSolautoLut } from "./updateSolautoLUT";
22
- import { getSecretKey } from "./shared";
23
-
24
- async function createIntermediarySolautoManagerAccounts() {
25
- let [connection, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
26
-
27
- const secretKey = getSecretKey("solauto-manager");
28
- const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
29
- const signer = createSignerFromKeypair(umi, signerKeypair);
30
-
31
- umi = umi.use(signerIdentity(signer));
32
-
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());
44
-
45
- for (const group of Object.keys(MARGINFI_ACCOUNTS)) {
46
- if (existingMarginfiGroups.includes(group.toString())) {
47
- console.log(
48
- "Already have Solauto Manager Marginfi Account for group:",
49
- group
50
- );
51
- continue;
52
- }
53
-
54
- const marginfiAccount = createSignerFromKeypair(
55
- umi,
56
- umi.eddsa.generateKeypair()
57
- );
58
-
59
- const tx = marginfiAccountInitialize(umi, {
60
- marginfiAccount,
61
- marginfiGroup: publicKey(group),
62
- authority: signer,
63
- feePayer: signer,
64
- });
65
-
66
- await sendSingleOptimizedTransaction(
67
- umi,
68
- connection,
69
- transactionBuilder().add(tx)
70
- );
71
-
72
- await updateSolautoLut([marginfiAccount.publicKey.toString()]);
73
- }
74
- }
75
-
76
- createIntermediarySolautoManagerAccounts();