@haven-fi/solauto-sdk 1.0.677 → 1.0.679

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.
@@ -1 +1 @@
1
- {"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAgCrB,qBAAa,kBAAkB;IAS3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IATtC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,QAAQ,CAAC,CAAS;gBAGhB,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA;IAG9C,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAyC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAwBnB,sBAAsB;YAyBtB,mBAAmB;IAmEpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
1
+ {"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAGL,qBAAqB,EACtB,MAAM,aAAa,CAAC;AAgCrB,qBAAa,kBAAkB;IAS3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IATtC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,WAAW,CAAwB;IAC3C,OAAO,CAAC,cAAc,CAAC,CAAwB;IAC/C,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,QAAQ,CAAC,CAAS;gBAGhB,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA;IAG9C,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IA2C5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA2CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAwBnB,sBAAsB;YAyBtB,mBAAmB;IAmEpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
@@ -29,12 +29,14 @@ class RebalanceTxBuilder {
29
29
  getFlLiquiditySource(supplyLiquidityAvailable, debtLiquidityAvailable) {
30
30
  const debtAdjustmentUsd = Math.abs(this.values.debtAdjustmentUsd);
31
31
  const insufficientLiquidity = (amountNeededUsd, liquidityAvailable, tokenMint) => {
32
- return (amountNeededUsd >
33
- (0, utils_1.fromBaseUnit)(liquidityAvailable, (0, utils_1.tokenInfo)(tokenMint).decimals) *
34
- ((0, utils_1.safeGetPrice)(tokenMint) ?? 0) *
35
- 0.95);
32
+ const liquidityUsd = (0, utils_1.fromBaseUnit)(liquidityAvailable, (0, utils_1.tokenInfo)(tokenMint).decimals) *
33
+ ((0, utils_1.safeGetPrice)(tokenMint) ?? 0);
34
+ (0, utils_1.consoleLog)(liquidityUsd);
35
+ return amountNeededUsd > liquidityUsd * 0.95;
36
36
  };
37
+ (0, utils_1.consoleLog)("Supply liquidity available:", supplyLiquidityAvailable);
37
38
  const insufficientSupplyLiquidity = insufficientLiquidity(debtAdjustmentUsd, supplyLiquidityAvailable, this.client.pos.supplyMint);
39
+ (0, utils_1.consoleLog)("Debt liquidity available:", debtLiquidityAvailable);
38
40
  const insufficientDebtLiquidity = insufficientLiquidity(debtAdjustmentUsd, debtLiquidityAvailable, this.client.pos.debtMint);
39
41
  let useDebtLiquidity = this.values.rebalanceDirection === generated_1.RebalanceDirection.Boost ||
40
42
  insufficientSupplyLiquidity;
@@ -70,6 +72,7 @@ class RebalanceTxBuilder {
70
72
  }
71
73
  const stdFlLiquiditySource = this.getFlLiquiditySource(this.client.flProvider.liquidityAvailable(generated_1.TokenType.Supply), this.client.flProvider.liquidityAvailable(generated_1.TokenType.Debt));
72
74
  if ((attemptNum ?? 0) >= 3 || stdFlLiquiditySource === undefined) {
75
+ (0, utils_1.consoleLog)("Checking signer liquidity");
73
76
  const { supplyBalance, debtBalance } = await this.client.signerBalances();
74
77
  const signerFlLiquiditySource = this.getFlLiquiditySource(supplyBalance, debtBalance);
75
78
  if (signerFlLiquiditySource) {
@@ -149,7 +149,7 @@ class SolautoPositionEx {
149
149
  return ((0, utils_1.currentUnixSeconds)() - Number(this.state.lastRefreshed) > 60 * 60 * 24 * 7);
150
150
  }
151
151
  canRefreshPositionState() {
152
- if ((0, utils_1.currentUnixSeconds)() - Number(this.state.lastRefreshed) > 3 ||
152
+ if ((0, utils_1.currentUnixSeconds)() - Number(this.state.lastRefreshed) > 5 ||
153
153
  this.contextUpdates?.positionUpdates()) {
154
154
  return true;
155
155
  }
@@ -1,32 +1,36 @@
1
1
  import { Keypair, PublicKey } from "@solana/web3.js";
2
- import { createSignerFromKeypair, publicKey } from "@metaplex-foundation/umi";
2
+ import { createSignerFromKeypair } from "@metaplex-foundation/umi";
3
3
  import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
4
4
  import {
5
5
  consoleLog,
6
- fetchBank,
6
+ fromBaseUnit,
7
7
  getBatches,
8
8
  getClient,
9
9
  getPositionExBulk,
10
10
  getSolanaRpcConnection,
11
11
  getSolautoManagedPositions,
12
- isMarginfiPosition,
13
12
  LendingPlatform,
14
13
  LOCAL_IRONFORGE_API_URL,
14
+ openSolautoPosition,
15
15
  PriceType,
16
16
  PriorityFeeSetting,
17
17
  ProgramEnv,
18
18
  rebalance,
19
- safeFetchBank,
20
19
  SOLAUTO_PROD_PROGRAM,
21
20
  SOLAUTO_TEST_PROGRAM,
22
21
  SolautoClient,
22
+ tokenInfo,
23
23
  TransactionItem,
24
24
  TransactionsManager,
25
+ USDC,
26
+ deposit,
27
+ toBaseUnit,
28
+ RETARDIO,
25
29
  } from "../src";
26
30
  import { getSecretKey } from "./shared";
27
31
 
28
32
  const payForTransaction = true;
29
- const testProgram = false;
33
+ const testProgram = true;
30
34
  const lpEnv: ProgramEnv = "Prod";
31
35
 
32
36
  let [, umi] = getSolanaRpcConnection(
@@ -50,53 +54,38 @@ export async function main() {
50
54
  });
51
55
 
52
56
  await client.initialize({
53
- positionId: 4,
54
- authority: new PublicKey("EBhRj7jbF2EVE21i19JSuCX1BAbnZFYhoKW64HnaZ3kf"),
57
+ positionId: 2,
58
+ supplyMint: new PublicKey(USDC),
59
+ debtMint: new PublicKey(RETARDIO),
60
+ lpPoolAccount: new PublicKey("EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm")
61
+ // authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
55
62
  // lpUserAccount: new PublicKey(
56
63
  // "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
57
64
  // ),
58
65
  });
59
66
 
60
67
  const transactionItems = [
61
- new TransactionItem(
62
- async () => ({ tx: client.refreshIx(PriceType.Realtime) }),
63
- `refresh`
64
- ),
68
+ openSolautoPosition(client, {
69
+ boostGap: 250,
70
+ boostToBps: 8681,
71
+ repayGap: 250,
72
+ repayToBps: 8681,
73
+ }),
74
+ deposit(client, toBaseUnit(4.5, tokenInfo(new PublicKey(USDC)).decimals)),
75
+ rebalance(client, 8500),
65
76
  ];
66
77
 
67
- const bank = await fetchBank(
68
- umi,
69
- publicKey("E4td8i8PT2BZkMygzW4MGHCv2KPPs57dvz5W2ZXf9Twu")
70
- );
71
-
72
- console.log(
73
- client.pos.supplyLiquidityDepositable,
74
- client.pos.supplyLiquidityUsdDepositable
78
+ const txManager = new TransactionsManager(
79
+ client,
80
+ undefined,
81
+ payForTransaction ? "normal" : "only-simulate",
82
+ PriorityFeeSetting.High,
83
+ false,
84
+ undefined,
85
+ { totalRetries: 5 }
75
86
  );
76
- console.log(client.pos.eligibleForRebalance());
77
- console.log(client.pos.state.supply.amountCanBeUsed);
78
-
79
- if (isMarginfiPosition(client.pos)) {
80
- client.pos.updateSupplyLiquidityDepositable([bank]);
81
- }
82
- console.log(
83
- client.pos.supplyLiquidityDepositable,
84
- client.pos.supplyLiquidityUsdDepositable
85
- );
86
- console.log(client.pos.eligibleForRebalance());
87
- console.log(client.pos.state.supply.amountCanBeUsed);
88
-
89
- // const txManager = new TransactionsManager(
90
- // client,
91
- // undefined,
92
- // payForTransaction ? "normal" : "only-simulate",
93
- // PriorityFeeSetting.High,
94
- // true,
95
- // undefined,
96
- // { totalRetries: 5 }
97
- // );
98
- // const statuses = await txManager.clientSend(transactionItems);
99
- // consoleLog(statuses);
87
+ const statuses = await txManager.clientSend(transactionItems);
88
+ consoleLog(statuses);
100
89
  }
101
90
 
102
91
  async function refreshAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.677",
3
+ "version": "1.0.679",
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",
@@ -90,19 +90,21 @@ export class RebalanceTxBuilder {
90
90
  liquidityAvailable: bigint,
91
91
  tokenMint: PublicKey
92
92
  ) => {
93
- return (
94
- amountNeededUsd >
93
+ const liquidityUsd =
95
94
  fromBaseUnit(liquidityAvailable, tokenInfo(tokenMint).decimals) *
96
- (safeGetPrice(tokenMint) ?? 0) *
97
- 0.95
98
- );
95
+ (safeGetPrice(tokenMint) ?? 0);
96
+ consoleLog(liquidityUsd);
97
+ return amountNeededUsd > liquidityUsd * 0.95;
99
98
  };
100
99
 
100
+ consoleLog("Supply liquidity available:", supplyLiquidityAvailable);
101
101
  const insufficientSupplyLiquidity = insufficientLiquidity(
102
102
  debtAdjustmentUsd,
103
103
  supplyLiquidityAvailable,
104
104
  this.client.pos.supplyMint
105
105
  );
106
+
107
+ consoleLog("Debt liquidity available:", debtLiquidityAvailable);
106
108
  const insufficientDebtLiquidity = insufficientLiquidity(
107
109
  debtAdjustmentUsd,
108
110
  debtLiquidityAvailable,
@@ -172,6 +174,7 @@ export class RebalanceTxBuilder {
172
174
  );
173
175
 
174
176
  if ((attemptNum ?? 0) >= 3 || stdFlLiquiditySource === undefined) {
177
+ consoleLog("Checking signer liquidity");
175
178
  const { supplyBalance, debtBalance } = await this.client.signerBalances();
176
179
  const signerFlLiquiditySource = this.getFlLiquiditySource(
177
180
  supplyBalance,
@@ -304,7 +304,7 @@ export abstract class SolautoPositionEx {
304
304
 
305
305
  protected canRefreshPositionState() {
306
306
  if (
307
- currentUnixSeconds() - Number(this.state.lastRefreshed) > 3 ||
307
+ currentUnixSeconds() - Number(this.state.lastRefreshed) > 5 ||
308
308
  this.contextUpdates?.positionUpdates()
309
309
  ) {
310
310
  return true;