@haven-fi/solauto-sdk 1.0.690 → 1.0.692

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;AA8BrB,qBAAa,kBAAkB;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IATvB,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;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA;IAGhC,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IAwEpB,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;IAQ3B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,2BAA2B,CAAC;IACpC,OAAO,CAAC,YAAY,CAAC;IATvB,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;gBAGxC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,YAAA,EACpC,YAAY,CAAC,EAAE,OAAO,YAAA;IAGhC,OAAO,CAAC,0BAA0B;IAclC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,oBAAoB;IAwC5B,OAAO,CAAC,iCAAiC;YAgC3B,qBAAqB;IA0CnC,OAAO,CAAC,mBAAmB;IAwB3B,OAAO,CAAC,gBAAgB;IA+BxB,OAAO,CAAC,yBAAyB;YAqBnB,mBAAmB;YAyBnB,sBAAsB;YAyBtB,mBAAmB;IA8EpB,gBAAgB,CAC3B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;CAe9C"}
@@ -200,6 +200,12 @@ class RebalanceTxBuilder {
200
200
  };
201
201
  (0, utils_1.consoleLog)("Rebalance details:", rebalanceDetails);
202
202
  (0, utils_1.consoleLog)("Prices:", (0, utils_1.safeGetPrice)(this.client.pos.supplyMint, this.priceType), (0, utils_1.safeGetPrice)(this.client.pos.debtMint, this.priceType));
203
+ // TODO: remove me
204
+ if ((0, utils_1.isMarginfiPosition)(this.client.pos)) {
205
+ const weightedAssets = this.values.endResult.supplyUsd * (0, utils_1.bytesToI80F48)(this.client.pos.supplyBank.config.assetWeightInit.value);
206
+ const weightedLiabs = this.values.endResult.debtUsd * (0, utils_1.bytesToI80F48)(this.client.pos.debtBank.config.assetWeightInit.value);
207
+ (0, utils_1.consoleLog)("Weighted assets & liabs:", weightedAssets, weightedLiabs);
208
+ }
203
209
  const firstRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PreSwap, rebalanceDetails);
204
210
  const lastRebalance = this.client.rebalanceIx(generated_1.RebalanceStep.PostSwap, rebalanceDetails);
205
211
  if (!flashLoanDetails) {
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA2BjE,OAAO,EAAE,qBAAqB,EAAyB,MAAM,aAAa,CAAC;AAwL3E,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAyF7B;AA+LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO;;;;EA8G/B"}
1
+ {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAiBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4BjE,OAAO,EAAE,qBAAqB,EAAyB,MAAM,aAAa,CAAC;AAwL3E,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAyF7B;AA+LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO;;;;EAuH/B"}
@@ -212,7 +212,7 @@ function getSolautoActions(umi, tx) {
212
212
  const discriminator = (0, utils_1.uint8ArrayToBigInt)(serializer
213
213
  .serialize({
214
214
  amount: 0,
215
- depositUpToLimit: true
215
+ depositUpToLimit: true,
216
216
  })
217
217
  .slice(0, 8));
218
218
  const [data, _] = serializer.deserialize(x.data);
@@ -347,17 +347,20 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
347
347
  let errIxIdx;
348
348
  let errCode;
349
349
  let errName;
350
- const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
350
+ // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
351
+ const getComputeIxs = (txIdx) => (0, utils_1.addTxOptimizations)(umi, txs[txIdx], 1, !simulationSuccessful ? 1 : undefined).getInstructions().length - txs[txIdx].getInstructions().length;
351
352
  try {
352
353
  if (error instanceof types_1.BundleSimulationError) {
353
354
  errTxIdx = error.details.transactionIdx;
354
- errIxIdx = error.details.instructionIdx - computeIxs;
355
+ errIxIdx =
356
+ error.details.instructionIdx -
357
+ getComputeIxs(error.details.transactionIdx);
355
358
  errCode = error.details.errorCode;
356
359
  }
357
360
  else if (typeof error === "object" &&
358
361
  error["InstructionError"]) {
359
362
  const err = error["InstructionError"];
360
- errIxIdx = err[0] - computeIxs;
363
+ errIxIdx = err[0] - getComputeIxs(0);
361
364
  errCode =
362
365
  typeof err[1] === "object" && "Custom" in err[1]
363
366
  ? err[1]["Custom"]
@@ -5,8 +5,8 @@ import { LendingPlatform, PriceType } from "../generated";
5
5
  export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
6
6
  lendingPlatform: LendingPlatform;
7
7
  maxLtvPriceType: PriceType;
8
- private supplyBank;
9
- private debtBank;
8
+ supplyBank: Bank | null;
9
+ debtBank: Bank | null;
10
10
  private getBankAccounts;
11
11
  getBanks(): Promise<Bank[]>;
12
12
  priceOracles(): Promise<PublicKey[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAoB,MAAM,iBAAiB,CAAC;AAezD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAC3C,eAAe,YAAiB;IAEhC,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CA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C,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,eAAe,cAElB;IAED,IAAI,aAAa,cAEhB;IAED,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BjE"}
@@ -10,6 +10,7 @@ import {
10
10
  getBatches,
11
11
  getClient,
12
12
  getLiqUtilzationRateBps,
13
+ getMaxLiqUtilizationRateBps,
13
14
  getPositionExBulk,
14
15
  getSolanaRpcConnection,
15
16
  getSolautoManagedPositions,
@@ -98,6 +99,7 @@ export async function main() {
98
99
  23.530695876 * debtWeight
99
100
  );
100
101
  console.log(client.pos.maxBoostToBps);
102
+ console.log(getMaxLiqUtilizationRateBps(client.pos.state.maxLtvBps, client.pos.state.liqThresholdBps, 0));
101
103
 
102
104
  // const debtBank = await fetchBank(
103
105
  // umi,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.690",
3
+ "version": "1.0.692",
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",
@@ -8,6 +8,7 @@ import {
8
8
  TransactionItemInputs,
9
9
  } from "../../types";
10
10
  import {
11
+ bytesToI80F48,
11
12
  consoleLog,
12
13
  fromBaseUnit,
13
14
  fromBps,
@@ -15,6 +16,7 @@ import {
15
16
  getTokenAccount,
16
17
  hasFirstRebalance,
17
18
  hasLastRebalance,
19
+ isMarginfiPosition,
18
20
  safeGetPrice,
19
21
  tokenInfo,
20
22
  } from "../../utils";
@@ -345,6 +347,12 @@ export class RebalanceTxBuilder {
345
347
  safeGetPrice(this.client.pos.supplyMint, this.priceType),
346
348
  safeGetPrice(this.client.pos.debtMint, this.priceType)
347
349
  );
350
+ // TODO: remove me
351
+ if (isMarginfiPosition(this.client.pos)) {
352
+ const weightedAssets = this.values.endResult.supplyUsd * bytesToI80F48(this.client.pos.supplyBank!.config.assetWeightInit.value);
353
+ const weightedLiabs = this.values.endResult.debtUsd * bytesToI80F48(this.client.pos.debtBank!.config.assetWeightInit.value);
354
+ consoleLog("Weighted assets & liabs:", weightedAssets, weightedLiabs);
355
+ }
348
356
 
349
357
  const firstRebalance = this.client.rebalanceIx(
350
358
  RebalanceStep.PreSwap,
@@ -40,6 +40,7 @@ import {
40
40
  getTokenAccount,
41
41
  getTokenAccountData,
42
42
  isMarginfiClient,
43
+ addTxOptimizations,
43
44
  } from "../../utils";
44
45
  import {
45
46
  createMarginfiProgram,
@@ -417,7 +418,7 @@ function getSolautoActions(umi: Umi, tx: TransactionBuilder): SolautoAction[] {
417
418
  serializer
418
419
  .serialize({
419
420
  amount: 0,
420
- depositUpToLimit: true
421
+ depositUpToLimit: true,
421
422
  })
422
423
  .slice(0, 8)
423
424
  );
@@ -614,12 +615,21 @@ export function getErrorInfo(
614
615
  let errCode: number | undefined;
615
616
  let errName: string | undefined;
616
617
 
617
- const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
618
+ // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
619
+ const getComputeIxs = (txIdx: number) =>
620
+ addTxOptimizations(
621
+ umi,
622
+ txs[txIdx],
623
+ 1,
624
+ !simulationSuccessful ? 1 : undefined
625
+ ).getInstructions().length - txs[txIdx].getInstructions().length;
618
626
 
619
627
  try {
620
628
  if (error instanceof BundleSimulationError) {
621
629
  errTxIdx = error.details.transactionIdx;
622
- errIxIdx = error.details.instructionIdx - computeIxs;
630
+ errIxIdx =
631
+ error.details.instructionIdx -
632
+ getComputeIxs(error.details.transactionIdx);
623
633
  errCode = error.details.errorCode;
624
634
  } else if (
625
635
  typeof error === "object" &&
@@ -627,7 +637,7 @@ export function getErrorInfo(
627
637
  ) {
628
638
  const err = (error as any)["InstructionError"];
629
639
 
630
- errIxIdx = err[0] - computeIxs;
640
+ errIxIdx = err[0] - getComputeIxs(0);
631
641
  errCode =
632
642
  typeof err[1] === "object" && "Custom" in err[1]
633
643
  ? err[1]["Custom"]
@@ -21,8 +21,8 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
21
21
  lendingPlatform = LendingPlatform.Marginfi;
22
22
  maxLtvPriceType = PriceType.Ema;
23
23
 
24
- private supplyBank: Bank | null = null;
25
- private debtBank: Bank | null = null;
24
+ public supplyBank: Bank | null = null;
25
+ public debtBank: Bank | null = null;
26
26
 
27
27
  private getBankAccounts(mint: PublicKey) {
28
28
  const group = this.lpPoolAccount.toString();