@haven-fi/solauto-sdk 1.0.722 → 1.0.723

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.
@@ -78,7 +78,7 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
78
78
  }
79
79
  get supplyUsdWithdrawable() {
80
80
  const deposits = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityUsedBaseUnit)(this.supplyBank, true), this.supplyMintInfo.decimals);
81
- const borrows = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityAvailableBaseUnit)(this.supplyBank, false), this.supplyMintInfo.decimals);
81
+ const borrows = (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityUsedBaseUnit)(this.supplyBank, false), this.supplyMintInfo.decimals);
82
82
  return Math.min((deposits - borrows), this.totalSupply) * this.supplyPrice();
83
83
  }
84
84
  async refreshPositionState(priceType) {
@@ -92,12 +92,10 @@ async function main(filterWhitelist: boolean, programEnv: ProgramEnv = "Prod") {
92
92
  );
93
93
  }
94
94
 
95
- const positionsEx = (
96
- await getPositionExBulk(
97
- umi,
98
- positions.map((x) => new PublicKey(x.publicKey!))
99
- )
100
- ).sort((a, b) => a.netWorthUsd() - b.netWorthUsd());
95
+ const positionsEx = await getPositionExBulk(
96
+ umi,
97
+ positions.map((x) => new PublicKey(x.publicKey!))
98
+ );
101
99
 
102
100
  const tokensUsed = Array.from(
103
101
  new Set(
@@ -114,7 +112,10 @@ async function main(filterWhitelist: boolean, programEnv: ProgramEnv = "Prod") {
114
112
  let unhealthyPositions = 0;
115
113
  let awaitingBoostPositions = 0;
116
114
 
117
- for (const pos of positionsEx) {
115
+ const sortedPositions = positionsEx.sort(
116
+ (a, b) => a.netWorthUsd() - b.netWorthUsd()
117
+ );
118
+ for (const pos of sortedPositions) {
118
119
  const actionToTake = pos.eligibleForRebalance(0);
119
120
 
120
121
  const repayFrom = pos.settings!.repayToBps + pos.settings!.repayGap;
@@ -54,16 +54,20 @@ export async function main() {
54
54
  // ),
55
55
  });
56
56
 
57
- const transactionItems = [rebalance(client, undefined, 300)];
57
+ await client.pos.refreshPositionState();
58
58
 
59
- const txManager = new ClientTransactionsManager({
60
- txHandler: client,
61
- txRunType: payForTransaction ? "normal" : "only-simulate",
62
- priorityFeeSetting: PriorityFeeSetting.Default,
63
- retryConfig: { totalRetries: 2 },
64
- });
65
- const statuses = await txManager.send(transactionItems);
66
- consoleLog(statuses);
59
+ console.log(client.pos.supplyUsdWithdrawable);
60
+
61
+ // const transactionItems = [rebalance(client)];
62
+
63
+ // const txManager = new ClientTransactionsManager({
64
+ // txHandler: client,
65
+ // txRunType: payForTransaction ? "normal" : "only-simulate",
66
+ // priorityFeeSetting: PriorityFeeSetting.Default,
67
+ // retryConfig: { totalRetries: 2 },
68
+ // });
69
+ // const statuses = await txManager.send(transactionItems);
70
+ // consoleLog(statuses);
67
71
  }
68
72
 
69
73
  async function refreshAll() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.722",
3
+ "version": "1.0.723",
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",
@@ -135,7 +135,7 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
135
135
  this.supplyMintInfo.decimals
136
136
  );
137
137
  const borrows = fromBaseUnit(
138
- getBankLiquidityAvailableBaseUnit(this.supplyBank, false),
138
+ getBankLiquidityUsedBaseUnit(this.supplyBank, false),
139
139
  this.supplyMintInfo.decimals
140
140
  );
141
141
  return Math.min((deposits - borrows), this.totalSupply) * this.supplyPrice()!;