@haven-fi/solauto-sdk 1.0.667 → 1.0.668

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.
@@ -8,6 +8,8 @@
8
8
 
9
9
  import {
10
10
  Context,
11
+ Option,
12
+ OptionOrNullable,
11
13
  Pda,
12
14
  PublicKey,
13
15
  Signer,
@@ -17,7 +19,9 @@ import {
17
19
  import {
18
20
  Serializer,
19
21
  array,
22
+ bool,
20
23
  mapSerializer,
24
+ option,
21
25
  struct,
22
26
  u64,
23
27
  u8,
@@ -43,10 +47,12 @@ export type LendingAccountDepositInstructionAccounts = {
43
47
  export type LendingAccountDepositInstructionData = {
44
48
  discriminator: Array<number>;
45
49
  amount: bigint;
50
+ depositUpToLimit: Option<boolean>;
46
51
  };
47
52
 
48
53
  export type LendingAccountDepositInstructionDataArgs = {
49
54
  amount: number | bigint;
55
+ depositUpToLimit: OptionOrNullable<boolean>;
50
56
  };
51
57
 
52
58
  export function getLendingAccountDepositInstructionDataSerializer(): Serializer<
@@ -62,6 +68,7 @@ export function getLendingAccountDepositInstructionDataSerializer(): Serializer<
62
68
  [
63
69
  ['discriminator', array(u8(), { size: 8 })],
64
70
  ['amount', u64()],
71
+ ['depositUpToLimit', option(bool())],
65
72
  ],
66
73
  { description: 'LendingAccountDepositInstructionData' }
67
74
  ),
@@ -259,7 +259,6 @@ export class SolautoMarginfiClient extends SolautoClient {
259
259
  switch (args.__kind) {
260
260
  case "Deposit": {
261
261
  return lendingAccountDeposit(this.umi, {
262
- amount: args.fields[0],
263
262
  signer: this.signer,
264
263
  signerTokenAccount: publicKey(this.signerSupplyTa),
265
264
  marginfiAccount: publicKey(this.marginfiAccountPk),
@@ -268,6 +267,8 @@ export class SolautoMarginfiClient extends SolautoClient {
268
267
  bankLiquidityVault: publicKey(
269
268
  this.marginfiSupplyAccounts.liquidityVault
270
269
  ),
270
+ amount: args.fields[0],
271
+ depositUpToLimit: true,
271
272
  });
272
273
  }
273
274
  case "Borrow": {
@@ -417,6 +417,7 @@ function getSolautoActions(umi: Umi, tx: TransactionBuilder): SolautoAction[] {
417
417
  serializer
418
418
  .serialize({
419
419
  amount: 0,
420
+ depositUpToLimit: true
420
421
  })
421
422
  .slice(0, 8)
422
423
  );
@@ -223,11 +223,14 @@ export function addTxOptimizations(
223
223
  : transactionBuilder();
224
224
 
225
225
  const allOptimizations = tx.prepend(computePriceIx).prepend(computeLimitIx);
226
- const oneOptimization = tx.prepend(computePriceIx);
226
+ const withCuPrice = tx.prepend(computePriceIx);
227
+ const withCuLimit = tx.prepend(computeLimitIx);
227
228
  if (allOptimizations.fitsInOneTransaction(umi)) {
228
229
  return allOptimizations;
229
- } else if (oneOptimization.fitsInOneTransaction(umi)) {
230
- return oneOptimization;
230
+ } else if (withCuPrice.fitsInOneTransaction(umi)) {
231
+ return withCuPrice;
232
+ } else if (withCuLimit.fitsInOneTransaction(umi)) {
233
+ return withCuLimit;
231
234
  } else {
232
235
  return tx;
233
236
  }
@@ -448,7 +451,7 @@ export async function sendSingleOptimizedTransaction(
448
451
 
449
452
  const blockhash = await connection.getLatestBlockhash("confirmed");
450
453
 
451
- let computeUnitLimit = undefined;
454
+ let cuLimit = undefined;
452
455
  if (txType !== "skip-simulation") {
453
456
  const simulationResult = await retryWithExponentialBackoff(
454
457
  async () =>
@@ -461,28 +464,20 @@ export async function sendSingleOptimizedTransaction(
461
464
  ),
462
465
  3
463
466
  );
464
- computeUnitLimit = Math.round(simulationResult.value.unitsConsumed! * 1.15);
465
- consoleLog("Compute unit limit: ", computeUnitLimit);
467
+ cuLimit = Math.round(simulationResult.value.unitsConsumed! * 1.15);
468
+ consoleLog("Compute unit limit: ", cuLimit);
466
469
  }
467
470
 
468
471
  let cuPrice: number | undefined;
469
472
  if (prioritySetting !== PriorityFeeSetting.None) {
470
473
  cuPrice = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
471
- if (!cuPrice) {
472
- cuPrice = 1_000_000;
473
- }
474
- cuPrice = Math.min(cuPrice, 100 * 1_000_000);
474
+ cuPrice = Math.min(cuPrice ?? 0, 100 * 1_000_000);
475
475
  consoleLog("Compute unit price: ", cuPrice);
476
476
  }
477
477
 
478
478
  if (txType !== "only-simulate") {
479
479
  onAwaitingSign?.();
480
- const signedTx = await assembleFinalTransaction(
481
- umi,
482
- tx,
483
- cuPrice,
484
- computeUnitLimit
485
- )
480
+ const signedTx = await assembleFinalTransaction(umi, tx, cuPrice, cuLimit)
486
481
  .setBlockhash(blockhash)
487
482
  .buildAndSign(umi);
488
483
  const txSig = await spamSendTransactionUntilConfirmed(
@@ -5,7 +5,7 @@ import { e2eTransactionTest } from "./shared";
5
5
 
6
6
  describe("Solauto Marginfi tests", async () => {
7
7
  const signer = setupTest();
8
- const testProgram = true;
8
+ const testProgram = false;
9
9
 
10
10
  it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
11
11
  await e2eTransactionTest(