@0dotxyz/p0-ts-sdk 2.10.0 → 2.10.1-alpha.0

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.
package/dist/index.js CHANGED
@@ -188,6 +188,7 @@ var TransactionBuildingErrorCode = /* @__PURE__ */ ((TransactionBuildingErrorCod
188
188
  TransactionBuildingErrorCode2["BRIDGE_CONFLICT"] = "BRIDGE_CONFLICT";
189
189
  TransactionBuildingErrorCode2["ORDER_INVALID_TRIGGER"] = "ORDER_INVALID_TRIGGER";
190
190
  TransactionBuildingErrorCode2["ORDER_INVALID_SLIPPAGE"] = "ORDER_INVALID_SLIPPAGE";
191
+ TransactionBuildingErrorCode2["ORDER_CLOSES_DONT_FIT"] = "ORDER_CLOSES_DONT_FIT";
191
192
  TransactionBuildingErrorCode2["COSTLY_POSITION_LIMIT_EXCEEDED"] = "COSTLY_POSITION_LIMIT_EXCEEDED";
192
193
  TransactionBuildingErrorCode2["ACCOUNT_DISABLED"] = "ACCOUNT_DISABLED";
193
194
  return TransactionBuildingErrorCode2;
@@ -356,6 +357,19 @@ var TransactionBuildingError = class _TransactionBuildingError extends Error {
356
357
  { maxSlippagePercent, maxAllowedPercent }
357
358
  );
358
359
  }
360
+ /**
361
+ * Closing the orders an action touches doesn't fit in one transaction: next to the action, or in
362
+ * the one order transaction after a multi-transaction action. Builders throw rather than leave the
363
+ * closes out, since an order on a changed position can still fire: close the orders on their own
364
+ * first, then retry the action.
365
+ */
366
+ static orderClosesDontFit(orderAddresses) {
367
+ return new _TransactionBuildingError(
368
+ "ORDER_CLOSES_DONT_FIT" /* ORDER_CLOSES_DONT_FIT */,
369
+ `Closing ${orderAddresses.length} order(s) doesn't fit in one transaction`,
370
+ { orderAddresses }
371
+ );
372
+ }
359
373
  /**
360
374
  * The marginfi account is disabled (e.g. already transferred to a new account), so it can't act.
361
375
  */
@@ -78559,6 +78573,162 @@ function exceedsCostlyPositionLimit(balances, bankMap, bank) {
78559
78573
  }).length;
78560
78574
  return held >= MAX_COSTLY_POSITIONS;
78561
78575
  }
78576
+ function buildOrderTrigger(params) {
78577
+ const { stopLossUsd, takeProfitUsd } = params;
78578
+ const maxSlippage = percentToMaxSlippageU32(params.maxSlippagePercent);
78579
+ const invalidTrigger = (reason) => TransactionBuildingError.orderInvalidTrigger(
78580
+ reason,
78581
+ takeProfitUsd?.toString(),
78582
+ stopLossUsd?.toString()
78583
+ );
78584
+ if (stopLossUsd && !stopLossUsd.gt(0)) {
78585
+ throw invalidTrigger(`stop-loss threshold (${stopLossUsd}) must be above 0`);
78586
+ }
78587
+ if (takeProfitUsd && !takeProfitUsd.gt(0)) {
78588
+ throw invalidTrigger(`take-profit threshold (${takeProfitUsd}) must be above 0`);
78589
+ }
78590
+ if (stopLossUsd && takeProfitUsd) {
78591
+ if (takeProfitUsd.lte(stopLossUsd)) {
78592
+ throw invalidTrigger(
78593
+ `take-profit threshold (${takeProfitUsd}) must be above stop-loss threshold (${stopLossUsd})`
78594
+ );
78595
+ }
78596
+ return {
78597
+ both: {
78598
+ stopLoss: bigNumberToWrappedI80F48(stopLossUsd),
78599
+ takeProfit: bigNumberToWrappedI80F48(takeProfitUsd),
78600
+ maxSlippage
78601
+ }
78602
+ };
78603
+ }
78604
+ if (stopLossUsd) {
78605
+ return { stopLoss: { threshold: bigNumberToWrappedI80F48(stopLossUsd), maxSlippage } };
78606
+ }
78607
+ if (takeProfitUsd) {
78608
+ return { takeProfit: { threshold: bigNumberToWrappedI80F48(takeProfitUsd), maxSlippage } };
78609
+ }
78610
+ throw invalidTrigger("an order needs a stop-loss threshold, a take-profit threshold, or both");
78611
+ }
78612
+ async function makePlaceOrderIx2(params) {
78613
+ const { program, marginfiAccount, collateralBank, debtBank, trigger, feePayer } = params;
78614
+ const [order] = deriveOrderPda(program.programId, marginfiAccount.address, [
78615
+ collateralBank,
78616
+ debtBank
78617
+ ]);
78618
+ const globalFeeWallet = params.globalFeeWallet ?? (await program.account.feeState.fetch(deriveFeeState(program.programId)[0])).globalFeeWallet;
78619
+ const placeOrderIx = await instructions_default3.makePlaceOrderIx(
78620
+ program,
78621
+ {
78622
+ marginfiAccount: marginfiAccount.address,
78623
+ feePayer: feePayer ?? marginfiAccount.authority,
78624
+ authority: marginfiAccount.authority,
78625
+ order,
78626
+ globalFeeWallet,
78627
+ group: marginfiAccount.group
78628
+ },
78629
+ { bankKeys: [collateralBank, debtBank], trigger: buildOrderTrigger(trigger) }
78630
+ );
78631
+ return { instructions: [placeOrderIx], keys: [] };
78632
+ }
78633
+ async function makeCloseOrderIx2(params) {
78634
+ const { program, marginfiAccount, order, feeRecipient } = params;
78635
+ const closeOrderIx = await instructions_default3.makeCloseOrderIx(program, {
78636
+ marginfiAccount: marginfiAccount.address,
78637
+ authority: marginfiAccount.authority,
78638
+ order,
78639
+ feeRecipient: feeRecipient ?? marginfiAccount.authority,
78640
+ group: marginfiAccount.group
78641
+ });
78642
+ return { instructions: [closeOrderIx], keys: [] };
78643
+ }
78644
+ async function compileOrderTx(params, payerKey, ixs, type) {
78645
+ const blockhash = params.blockhash ?? (await params.connection.getLatestBlockhashAndContext("confirmed")).value.blockhash;
78646
+ return addTransactionMetadata(
78647
+ new VersionedTransaction(
78648
+ new TransactionMessage({
78649
+ instructions: ixs.flatMap((ix) => ix.instructions),
78650
+ payerKey,
78651
+ recentBlockhash: blockhash
78652
+ }).compileToV0Message(params.luts)
78653
+ ),
78654
+ { type, signers: ixs.flatMap((ix) => ix.keys), addressLookupTables: params.luts }
78655
+ );
78656
+ }
78657
+ async function makePlaceOrderTx(params) {
78658
+ const placeIxs = await makePlaceOrderIx2(params);
78659
+ const payerKey = params.feePayer ?? params.marginfiAccount.authority;
78660
+ return compileOrderTx(params, payerKey, [placeIxs], "PLACE_ORDER" /* PLACE_ORDER */);
78661
+ }
78662
+ async function makeCloseOrderTx(params) {
78663
+ const closeIxs = await makeCloseOrderIx2(params);
78664
+ return compileOrderTx(
78665
+ params,
78666
+ params.marginfiAccount.authority,
78667
+ [closeIxs],
78668
+ "CLOSE_ORDER" /* CLOSE_ORDER */
78669
+ );
78670
+ }
78671
+ async function makeUpdateOrderTx(params) {
78672
+ const [order] = deriveOrderPda(params.program.programId, params.marginfiAccount.address, [
78673
+ params.collateralBank,
78674
+ params.debtBank
78675
+ ]);
78676
+ const closeIxs = await makeCloseOrderIx2({ ...params, order, feeRecipient: params.feePayer });
78677
+ const placeIxs = await makePlaceOrderIx2(params);
78678
+ const payerKey = params.feePayer ?? params.marginfiAccount.authority;
78679
+ return compileOrderTx(params, payerKey, [closeIxs, placeIxs], "UPDATE_ORDER" /* UPDATE_ORDER */);
78680
+ }
78681
+ var SEND_PIPELINE_MARGINS = {
78682
+ sizeMargin: PRIORITY_TX_SIZE + BUNDLE_TX_SIZE,
78683
+ maxAccountLocks: MAX_ACCOUNT_LOCKS - 3
78684
+ };
78685
+ async function makeOrderChangesIxs(params) {
78686
+ const { program, marginfiAccount, ordersToClose = [], placeOrder } = params;
78687
+ const wrappers = await Promise.all([
78688
+ ...ordersToClose.map((order) => makeCloseOrderIx2({ program, marginfiAccount, order })),
78689
+ ...placeOrder ? [makePlaceOrderIx2({ ...placeOrder, program, marginfiAccount })] : []
78690
+ ]);
78691
+ return wrappers.flatMap((wrapper) => wrapper.instructions);
78692
+ }
78693
+ async function prependOrderCloses(params, actionIxs, luts) {
78694
+ const { program, marginfiAccount, ordersToClose = [] } = params;
78695
+ if (ordersToClose.length === 0) return actionIxs;
78696
+ const closeIxs = await makeOrderChangesIxs({ program, marginfiAccount, ordersToClose });
78697
+ const withCloses = [...closeIxs, ...actionIxs];
78698
+ if (!fitsInOneTransaction(withCloses, {
78699
+ payerKey: params.authority,
78700
+ luts,
78701
+ ...SEND_PIPELINE_MARGINS
78702
+ })) {
78703
+ throw TransactionBuildingError.orderClosesDontFit(
78704
+ ordersToClose.map((order) => order.toBase58())
78705
+ );
78706
+ }
78707
+ return withCloses;
78708
+ }
78709
+ async function makeOrderChangesTx(params) {
78710
+ const { program, marginfiAccount, ordersToClose = [], placeOrder, luts } = params;
78711
+ const ixs = await makeOrderChangesIxs(params);
78712
+ if (ixs.length === 0) return void 0;
78713
+ if (!fitsInOneTransaction(ixs, {
78714
+ payerKey: marginfiAccount.authority,
78715
+ luts,
78716
+ ...SEND_PIPELINE_MARGINS
78717
+ })) {
78718
+ throw TransactionBuildingError.orderClosesDontFit(
78719
+ ordersToClose.map((order) => order.toBase58())
78720
+ );
78721
+ }
78722
+ let type = "CLOSE_ORDER" /* CLOSE_ORDER */;
78723
+ if (placeOrder) {
78724
+ const [placedOrder] = deriveOrderPda(program.programId, marginfiAccount.address, [
78725
+ placeOrder.collateralBank,
78726
+ placeOrder.debtBank
78727
+ ]);
78728
+ type = ordersToClose.some((order) => order.equals(placedOrder)) ? "UPDATE_ORDER" /* UPDATE_ORDER */ : "PLACE_ORDER" /* PLACE_ORDER */;
78729
+ }
78730
+ return compileOrderTx(params, marginfiAccount.authority, [{ instructions: ixs, keys: [] }], type);
78731
+ }
78562
78732
  var KAMINO_PROGRAM_ID = new PublicKey("KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD");
78563
78733
  var FARMS_PROGRAM_ID2 = new PublicKey("FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr");
78564
78734
  function encodeU642(value) {
@@ -79282,13 +79452,18 @@ async function makeBorrowTx(params) {
79282
79452
  params.bankMetadataMap
79283
79453
  );
79284
79454
  const borrowIxs = await makeBorrowIx3(borrowIxParams);
79455
+ const ixs = await prependOrderCloses(
79456
+ params,
79457
+ [...refreshIntegrationIxs.instructions, ...borrowIxs.instructions],
79458
+ selectedLuts
79459
+ );
79285
79460
  const {
79286
79461
  value: { blockhash }
79287
79462
  } = await connection.getLatestBlockhashAndContext("confirmed");
79288
79463
  const borrowTx = addTransactionMetadata(
79289
79464
  new VersionedTransaction(
79290
79465
  new TransactionMessage({
79291
- instructions: [...refreshIntegrationIxs.instructions, ...borrowIxs.instructions],
79466
+ instructions: ixs,
79292
79467
  payerKey: params.authority,
79293
79468
  recentBlockhash: blockhash
79294
79469
  }).compileToV0Message(selectedLuts)
@@ -79387,9 +79562,14 @@ async function makeDriftDepositTx(params) {
79387
79562
  amount,
79388
79563
  ...depositIxParams
79389
79564
  });
79390
- const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79565
+ const actionIxs = await prependOrderCloses(
79391
79566
  params,
79392
79567
  depositIxs.instructions,
79568
+ selectLutsForBanks(luts, [params.bank])
79569
+ );
79570
+ const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79571
+ params,
79572
+ actionIxs,
79393
79573
  [params.bank.address],
79394
79574
  []
79395
79575
  );
@@ -79530,9 +79710,14 @@ async function makeKaminoDepositTx(params) {
79530
79710
  amount,
79531
79711
  ...depositIxParams
79532
79712
  });
79533
- const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79713
+ const actionIxs = await prependOrderCloses(
79534
79714
  params,
79535
79715
  [...refreshIxs, ...depositIxs.instructions],
79716
+ selectLutsForBanks(luts, [params.bank])
79717
+ );
79718
+ const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79719
+ params,
79720
+ actionIxs,
79536
79721
  [params.bank.address],
79537
79722
  []
79538
79723
  );
@@ -79621,9 +79806,14 @@ async function makeDepositTx(params) {
79621
79806
  throw TransactionBuildingError.costlyPositionLimitExceeded(params.bank.address.toBase58());
79622
79807
  }
79623
79808
  const ixs = await makeDepositIx3(depositIxParams);
79624
- const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79809
+ const actionIxs = await prependOrderCloses(
79625
79810
  params,
79626
79811
  ixs.instructions,
79812
+ selectLutsForBanks(luts, [params.bank])
79813
+ );
79814
+ const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79815
+ params,
79816
+ actionIxs,
79627
79817
  [params.bank.address],
79628
79818
  []
79629
79819
  );
@@ -79713,9 +79903,14 @@ async function makeJuplendDepositTx(params) {
79713
79903
  amount,
79714
79904
  ...depositIxParams
79715
79905
  });
79716
- const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79906
+ const actionIxs = await prependOrderCloses(
79717
79907
  params,
79718
79908
  depositIxs.instructions,
79909
+ selectLutsForBanks(luts, [params.bank])
79910
+ );
79911
+ const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
79912
+ params,
79913
+ actionIxs,
79719
79914
  [params.bank.address],
79720
79915
  []
79721
79916
  );
@@ -80491,13 +80686,18 @@ async function makeDriftWithdrawTx(params) {
80491
80686
  [withdrawIxParams.bank.address],
80492
80687
  params.bankMetadataMap
80493
80688
  );
80689
+ const ixs = await prependOrderCloses(
80690
+ params,
80691
+ [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
80692
+ selectedLuts
80693
+ );
80494
80694
  const {
80495
80695
  value: { blockhash }
80496
80696
  } = await connection.getLatestBlockhashAndContext("confirmed");
80497
80697
  const withdrawTx = addTransactionMetadata(
80498
80698
  new VersionedTransaction(
80499
80699
  new TransactionMessage({
80500
- instructions: [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
80700
+ instructions: ixs,
80501
80701
  payerKey: params.authority,
80502
80702
  recentBlockhash: blockhash
80503
80703
  }).compileToV0Message(selectedLuts)
@@ -80744,13 +80944,18 @@ async function makeWithdrawTx(params) {
80744
80944
  [withdrawIxParams.bank.address],
80745
80945
  params.bankMetadataMap
80746
80946
  );
80947
+ const ixs = await prependOrderCloses(
80948
+ params,
80949
+ [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
80950
+ selectedLuts
80951
+ );
80747
80952
  const {
80748
80953
  value: { blockhash }
80749
80954
  } = await connection.getLatestBlockhashAndContext("confirmed");
80750
80955
  const withdrawTx = addTransactionMetadata(
80751
80956
  new VersionedTransaction(
80752
80957
  new TransactionMessage({
80753
- instructions: [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
80958
+ instructions: ixs,
80754
80959
  payerKey: params.authority,
80755
80960
  recentBlockhash: blockhash
80756
80961
  }).compileToV0Message(selectedLuts)
@@ -80788,13 +80993,18 @@ async function makeKaminoWithdrawTx(params) {
80788
80993
  cTokenAmount: adjustedAmount,
80789
80994
  ...withdrawIxParams
80790
80995
  });
80996
+ const ixs = await prependOrderCloses(
80997
+ params,
80998
+ [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
80999
+ selectedLuts
81000
+ );
80791
81001
  const {
80792
81002
  value: { blockhash }
80793
81003
  } = await connection.getLatestBlockhashAndContext("confirmed");
80794
81004
  const withdrawTx = addTransactionMetadata(
80795
81005
  new VersionedTransaction(
80796
81006
  new TransactionMessage({
80797
- instructions: [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
81007
+ instructions: ixs,
80798
81008
  payerKey: params.authority,
80799
81009
  recentBlockhash: blockhash
80800
81010
  }).compileToV0Message(selectedLuts)
@@ -80918,13 +81128,18 @@ async function makeJuplendWithdrawTx(params) {
80918
81128
  [withdrawIxParams.bank.address],
80919
81129
  params.bankMetadataMap
80920
81130
  );
81131
+ const ixs = await prependOrderCloses(
81132
+ params,
81133
+ [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
81134
+ selectedLuts
81135
+ );
80921
81136
  const {
80922
81137
  value: { blockhash }
80923
81138
  } = await connection.getLatestBlockhashAndContext("confirmed");
80924
81139
  const withdrawTx = addTransactionMetadata(
80925
81140
  new VersionedTransaction(
80926
81141
  new TransactionMessage({
80927
- instructions: [...refreshIntegrationIxs.instructions, ...withdrawIxs.instructions],
81142
+ instructions: ixs,
80928
81143
  payerKey: params.authority,
80929
81144
  recentBlockhash: blockhash
80930
81145
  }).compileToV0Message(selectedLuts)
@@ -80994,10 +81209,15 @@ async function makeRepayIx3({
80994
81209
  async function makeRepayTx(params) {
80995
81210
  const { luts, ...repayIxParams } = params;
80996
81211
  const ixs = await makeRepayIx3(repayIxParams);
81212
+ const actionIxs = await prependOrderCloses(
81213
+ params,
81214
+ ixs.instructions,
81215
+ selectLutsForBanks(luts, [params.bank])
81216
+ );
80997
81217
  const closedBanks = params.repayAll ? [params.bank.address] : [];
80998
81218
  const { instructions: instructions2, luts: selectedLuts } = await appendPremiumRefresh(
80999
81219
  params,
81000
- ixs.instructions,
81220
+ actionIxs,
81001
81221
  [],
81002
81222
  closedBanks
81003
81223
  );
@@ -81064,12 +81284,18 @@ async function makeRepayWithCollatTx(params) {
81064
81284
  payerKey: marginfiAccount.authority,
81065
81285
  luts: addressLookupTableAccounts ?? []
81066
81286
  });
81287
+ const orderTx = await makeOrderChangesTx({
81288
+ ...params,
81289
+ luts: addressLookupTableAccounts ?? [],
81290
+ blockhash
81291
+ });
81067
81292
  const transactions = [...additionalTxs, flashloanTx];
81293
+ if (orderTx) transactions.push(orderTx);
81068
81294
  return {
81069
81295
  transactions,
81070
81296
  swapQuote,
81071
81297
  amountToRepay,
81072
- mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
81298
+ mustBeAtomicBundle: transactions.length > 1
81073
81299
  };
81074
81300
  }
81075
81301
  async function buildRepayWithCollatFlashloanTx({
@@ -83565,7 +83791,8 @@ async function composeBridgedSwap(params) {
83565
83791
  banksMap,
83566
83792
  assetShareValueMultiplierByBank,
83567
83793
  feePayer,
83568
- maxBundleTxs = MAX_BRIDGED_BUNDLE_TXS
83794
+ maxBundleTxs = MAX_BRIDGED_BUNDLE_TXS,
83795
+ reservedTxs = 0
83569
83796
  } = params;
83570
83797
  if (!firstLeg.quoteResponse) return null;
83571
83798
  const projectedAccount = projectAccountAfterFirstLeg(
@@ -83582,7 +83809,7 @@ async function composeBridgedSwap(params) {
83582
83809
  secondLeg.transactions,
83583
83810
  feePayer,
83584
83811
  blockhashOf(firstLeg),
83585
- maxBundleTxs
83812
+ maxBundleTxs - reservedTxs
83586
83813
  );
83587
83814
  if (!transactions) return null;
83588
83815
  return {
@@ -83644,12 +83871,18 @@ async function makeSwapDebtTx(params) {
83644
83871
  luts: addressLookupTableAccounts ?? []
83645
83872
  }
83646
83873
  );
83874
+ const orderTx = await makeOrderChangesTx({
83875
+ ...params,
83876
+ luts: addressLookupTableAccounts ?? [],
83877
+ blockhash
83878
+ });
83647
83879
  const transactions = [...additionalTxs, flashloanTx];
83880
+ if (orderTx) transactions.push(orderTx);
83648
83881
  return {
83649
83882
  transactions,
83650
- actionTxIndex: transactions.length - 1,
83883
+ actionTxIndex: additionalTxs.length,
83651
83884
  quoteResponse: swapQuote,
83652
- mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
83885
+ mustBeAtomicBundle: transactions.length > 1
83653
83886
  };
83654
83887
  }
83655
83888
  async function buildSwapDebtFlashloanTx({
@@ -83856,6 +84089,10 @@ async function tryBridgedDebtSwap(params, bridgeOpts) {
83856
84089
  bridgeTokenSide: "borrow",
83857
84090
  bridgeCandidateMints: bridgeOpts?.bridgeCandidateMints
83858
84091
  });
84092
+ const orderTx = await makeOrderChangesTx({
84093
+ ...params,
84094
+ luts: params.addressLookupTableAccounts ?? []
84095
+ });
83859
84096
  const tokenProgramCache = new Map(bridgeOpts?.tokenProgramByMint);
83860
84097
  return tryBridgeCandidates({
83861
84098
  usableBridgeBanks,
@@ -83909,11 +84146,12 @@ async function tryBridgedDebtSwap(params, bridgeOpts) {
83909
84146
  banksMap: params.bankMap,
83910
84147
  assetShareValueMultiplierByBank: params.assetShareValueMultiplierByBank,
83911
84148
  feePayer: params.overrideInferAccounts?.authority ?? params.marginfiAccount.authority,
83912
- maxBundleTxs: bridgeOpts?.maxBundleTxs
84149
+ maxBundleTxs: bridgeOpts?.maxBundleTxs,
84150
+ reservedTxs: orderTx ? 1 : 0
83913
84151
  });
83914
84152
  if (!result) return null;
83915
84153
  return {
83916
- transactions: result.transactions,
84154
+ transactions: orderTx ? [...result.transactions, orderTx] : result.transactions,
83917
84155
  actionTxIndex: result.transactions.length - 1,
83918
84156
  quoteResponse: mergeBridgeQuotesDebt(result.firstLegQuote, result.secondLegQuote),
83919
84157
  bridgeMint: bridgeBank.mint,
@@ -83992,12 +84230,23 @@ async function makeLoopTx(params) {
83992
84230
  luts: addressLookupTableAccounts ?? []
83993
84231
  }
83994
84232
  );
84233
+ const orderTx = await makeOrderChangesTx({
84234
+ ...params,
84235
+ placeOrder: params.placeOrder && {
84236
+ collateralBank: depositOpts.depositBank.address,
84237
+ debtBank: borrowOpts.borrowBank.address,
84238
+ trigger: params.placeOrder
84239
+ },
84240
+ luts: addressLookupTableAccounts ?? [],
84241
+ blockhash
84242
+ });
83995
84243
  const transactions = [...additionalTxs, flashloanTx];
84244
+ if (orderTx) transactions.push(orderTx);
83996
84245
  return {
83997
84246
  transactions,
83998
- actionTxIndex: transactions.length - 1,
84247
+ actionTxIndex: additionalTxs.length,
83999
84248
  quoteResponse: swapQuote,
84000
- mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
84249
+ mustBeAtomicBundle: transactions.length > 1
84001
84250
  };
84002
84251
  }
84003
84252
  async function buildLoopFlashloanTx(params) {
@@ -84328,6 +84577,15 @@ async function tryBridgedLoop(params, bridgeOpts) {
84328
84577
  const oraclePriceOf = (bank) => params.oraclePrices.get(bank.address.toBase58())?.priceRealtime.price.toNumber() ?? 0;
84329
84578
  const borrowBankPrice = oraclePriceOf(borrowBank);
84330
84579
  if (borrowBankPrice <= 0) return null;
84580
+ const orderTx = await makeOrderChangesTx({
84581
+ ...params,
84582
+ placeOrder: params.placeOrder && {
84583
+ collateralBank: depositBank.address,
84584
+ debtBank: borrowBank.address,
84585
+ trigger: params.placeOrder
84586
+ },
84587
+ luts: params.addressLookupTableAccounts ?? []
84588
+ });
84331
84589
  const tokenProgramCache = new Map(bridgeOpts?.tokenProgramByMint);
84332
84590
  return tryBridgeCandidates({
84333
84591
  usableBridgeBanks,
@@ -84346,6 +84604,9 @@ async function tryBridgedLoop(params, bridgeOpts) {
84346
84604
  );
84347
84605
  const firstLeg = await makeLoopTx({
84348
84606
  ...params,
84607
+ // The order changes run after the second leg, once the loop's final debt exists
84608
+ ordersToClose: void 0,
84609
+ placeOrder: void 0,
84349
84610
  depositOpts: {
84350
84611
  ...params.depositOpts,
84351
84612
  marketPrice: oraclePriceOf(depositBank)
@@ -84383,11 +84644,12 @@ async function tryBridgedLoop(params, bridgeOpts) {
84383
84644
  banksMap: params.bankMap,
84384
84645
  assetShareValueMultiplierByBank: params.assetShareValueMultiplierByBank,
84385
84646
  feePayer: params.overrideInferAccounts?.authority ?? params.marginfiAccount.authority,
84386
- maxBundleTxs: bridgeOpts?.maxBundleTxs
84647
+ maxBundleTxs: bridgeOpts?.maxBundleTxs,
84648
+ reservedTxs: orderTx ? 1 : 0
84387
84649
  });
84388
84650
  if (!result) return null;
84389
84651
  return {
84390
- transactions: result.transactions,
84652
+ transactions: orderTx ? [...result.transactions, orderTx] : result.transactions,
84391
84653
  actionTxIndex: result.transactions.length - 1,
84392
84654
  quoteResponse: mergeBridgeQuotesLoop(result.firstLegQuote, result.secondLegQuote),
84393
84655
  bridgeMint: bridgeBank.mint,
@@ -84443,12 +84705,18 @@ async function makeSwapCollateralTx(params) {
84443
84705
  payerKey: marginfiAccount.authority,
84444
84706
  luts: addressLookupTableAccounts ?? []
84445
84707
  });
84708
+ const orderTx = await makeOrderChangesTx({
84709
+ ...params,
84710
+ luts: addressLookupTableAccounts ?? [],
84711
+ blockhash
84712
+ });
84446
84713
  const transactions = [...additionalTxs, flashloanTx];
84714
+ if (orderTx) transactions.push(orderTx);
84447
84715
  return {
84448
84716
  transactions,
84449
- actionTxIndex: transactions.length - 1,
84717
+ actionTxIndex: additionalTxs.length,
84450
84718
  quoteResponse: swapQuote,
84451
- mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
84719
+ mustBeAtomicBundle: transactions.length > 1
84452
84720
  };
84453
84721
  }
84454
84722
  async function buildSwapCollateralFlashloanTx({
@@ -84809,6 +85077,10 @@ async function tryBridgedCollateralSwap(params, bridgeOpts) {
84809
85077
  bridgeTokenSide: "deposit",
84810
85078
  bridgeCandidateMints: bridgeOpts?.bridgeCandidateMints
84811
85079
  });
85080
+ const orderTx = await makeOrderChangesTx({
85081
+ ...params,
85082
+ luts: params.addressLookupTableAccounts ?? []
85083
+ });
84812
85084
  const tokenProgramCache = new Map(bridgeOpts?.tokenProgramByMint);
84813
85085
  return tryBridgeCandidates({
84814
85086
  usableBridgeBanks,
@@ -84858,11 +85130,12 @@ async function tryBridgedCollateralSwap(params, bridgeOpts) {
84858
85130
  banksMap: params.bankMap,
84859
85131
  assetShareValueMultiplierByBank: params.assetShareValueMultiplierByBank,
84860
85132
  feePayer: params.overrideInferAccounts?.authority ?? params.marginfiAccount.authority,
84861
- maxBundleTxs: bridgeOpts?.maxBundleTxs
85133
+ maxBundleTxs: bridgeOpts?.maxBundleTxs,
85134
+ reservedTxs: orderTx ? 1 : 0
84862
85135
  });
84863
85136
  if (!result) return null;
84864
85137
  return {
84865
- transactions: result.transactions,
85138
+ transactions: orderTx ? [...result.transactions, orderTx] : result.transactions,
84866
85139
  actionTxIndex: result.transactions.length - 1,
84867
85140
  quoteResponse: mergeBridgeQuotes(result.firstLegQuote, result.secondLegQuote),
84868
85141
  bridgeMint: bridgeBank.mint,
@@ -84930,12 +85203,18 @@ async function makeRollPtTx(params) {
84930
85203
  payerKey: marginfiAccount.authority,
84931
85204
  luts: addressLookupTableAccounts ?? []
84932
85205
  });
85206
+ const orderTx = await makeOrderChangesTx({
85207
+ ...params,
85208
+ luts: addressLookupTableAccounts ?? [],
85209
+ blockhash
85210
+ });
84933
85211
  const transactions = [...additionalTxs, flashloanTx];
85212
+ if (orderTx) transactions.push(orderTx);
84934
85213
  return {
84935
85214
  transactions,
84936
- actionTxIndex: transactions.length - 1,
85215
+ actionTxIndex: additionalTxs.length,
84937
85216
  quoteResponse: swapQuote,
84938
- mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
85217
+ mustBeAtomicBundle: transactions.length > 1
84939
85218
  };
84940
85219
  }
84941
85220
  async function buildRollPtFlashloanTx({
@@ -85630,12 +85909,22 @@ async function makeTransferPositionsTx(params) {
85630
85909
  payerKey: accountA.authority,
85631
85910
  luts
85632
85911
  });
85912
+ const sourceOrderTx = await makeOrderChangesTx({ ...params, luts, blockhash });
85913
+ const destinationOrderTx = await makeOrderChangesTx({
85914
+ ...params,
85915
+ marginfiAccount: accountB,
85916
+ ordersToClose: params.destinationOrdersToClose,
85917
+ luts,
85918
+ blockhash
85919
+ });
85633
85920
  const transactions = [...additionalTxs, flashloanTx];
85921
+ if (sourceOrderTx) transactions.push(sourceOrderTx);
85922
+ if (destinationOrderTx) transactions.push(destinationOrderTx);
85634
85923
  return {
85635
85924
  transactions,
85636
85925
  actionTxIndex: additionalTxs.length,
85637
85926
  destinationAccount: accountB,
85638
- mustBeAtomicBundle: refreshIxs.length > 0
85927
+ mustBeAtomicBundle: transactions.length > 1
85639
85928
  };
85640
85929
  }
85641
85930
 
@@ -85758,8 +86047,10 @@ async function makeBulkWithdrawTx(params) {
85758
86047
  if (setupTokens.some((t) => t.mint.equals(NATIVE_MINT))) {
85759
86048
  withdrawIxs.push(makeUnwrapSolIx(authority));
85760
86049
  }
86050
+ const closeIxs = await makeOrderChangesIxs(params);
86051
+ const actionIxs = [...closeIxs, ...withdrawIxs];
85761
86052
  const { blockhash } = await connection.getLatestBlockhash("confirmed");
85762
- const withdrawTxs = splitInstructionsToFitTransactions([], withdrawIxs, {
86053
+ const withdrawTxs = splitInstructionsToFitTransactions([], actionIxs, {
85763
86054
  blockhash,
85764
86055
  payerKey: authority,
85765
86056
  luts: selectedLuts,
@@ -85790,7 +86081,8 @@ async function makeBulkWithdrawTx(params) {
85790
86081
  return {
85791
86082
  transactions: [...additionalTxs, ...withdrawTxs],
85792
86083
  actionTxIndex: additionalTxs.length,
85793
- mustBeAtomicBundle: refreshIxs.length > 0
86084
+ // Order closes must land with every withdraw
86085
+ mustBeAtomicBundle: refreshIxs.length > 0 || closeIxs.length > 0 && withdrawTxs.length > 1
85794
86086
  };
85795
86087
  }
85796
86088
  async function makeBulkRepayTx(params) {
@@ -85837,8 +86129,10 @@ async function makeBulkRepayTx(params) {
85837
86129
  [],
85838
86130
  bankAddresses
85839
86131
  ) : [];
86132
+ const closeIxs = await makeOrderChangesIxs(params);
86133
+ const actionIxs = [...closeIxs, ...repayIxs, ...premiumIxs];
85840
86134
  const { blockhash } = await connection.getLatestBlockhash("confirmed");
85841
- const transactions = splitInstructionsToFitTransactions([], [...repayIxs, ...premiumIxs], {
86135
+ const transactions = splitInstructionsToFitTransactions([], actionIxs, {
85842
86136
  blockhash,
85843
86137
  payerKey: authority,
85844
86138
  luts,
@@ -85853,115 +86147,11 @@ async function makeBulkRepayTx(params) {
85853
86147
  return {
85854
86148
  transactions,
85855
86149
  actionTxIndex: 0,
85856
- // Venue refreshes only count in the pulse's slot, and the pulse must follow every repay
85857
- mustBeAtomicBundle: premiumIxs.length > 0 && transactions.length > 1
86150
+ // Venue refreshes only count in the pulse's slot, and the pulse must follow every repay;
86151
+ // order closes must land with every repay
86152
+ mustBeAtomicBundle: (premiumIxs.length > 0 || closeIxs.length > 0) && transactions.length > 1
85858
86153
  };
85859
86154
  }
85860
- function buildOrderTrigger(params) {
85861
- const { stopLossUsd, takeProfitUsd } = params;
85862
- const maxSlippage = percentToMaxSlippageU32(params.maxSlippagePercent);
85863
- const invalidTrigger = (reason) => TransactionBuildingError.orderInvalidTrigger(
85864
- reason,
85865
- takeProfitUsd?.toString(),
85866
- stopLossUsd?.toString()
85867
- );
85868
- if (stopLossUsd && !stopLossUsd.gt(0)) {
85869
- throw invalidTrigger(`stop-loss threshold (${stopLossUsd}) must be above 0`);
85870
- }
85871
- if (takeProfitUsd && !takeProfitUsd.gt(0)) {
85872
- throw invalidTrigger(`take-profit threshold (${takeProfitUsd}) must be above 0`);
85873
- }
85874
- if (stopLossUsd && takeProfitUsd) {
85875
- if (takeProfitUsd.lte(stopLossUsd)) {
85876
- throw invalidTrigger(
85877
- `take-profit threshold (${takeProfitUsd}) must be above stop-loss threshold (${stopLossUsd})`
85878
- );
85879
- }
85880
- return {
85881
- both: {
85882
- stopLoss: bigNumberToWrappedI80F48(stopLossUsd),
85883
- takeProfit: bigNumberToWrappedI80F48(takeProfitUsd),
85884
- maxSlippage
85885
- }
85886
- };
85887
- }
85888
- if (stopLossUsd) {
85889
- return { stopLoss: { threshold: bigNumberToWrappedI80F48(stopLossUsd), maxSlippage } };
85890
- }
85891
- if (takeProfitUsd) {
85892
- return { takeProfit: { threshold: bigNumberToWrappedI80F48(takeProfitUsd), maxSlippage } };
85893
- }
85894
- throw invalidTrigger("an order needs a stop-loss threshold, a take-profit threshold, or both");
85895
- }
85896
- async function makePlaceOrderIx2(params) {
85897
- const { program, marginfiAccount, collateralBank, debtBank, trigger, feePayer } = params;
85898
- const [order] = deriveOrderPda(program.programId, marginfiAccount.address, [
85899
- collateralBank,
85900
- debtBank
85901
- ]);
85902
- const globalFeeWallet = params.globalFeeWallet ?? (await program.account.feeState.fetch(deriveFeeState(program.programId)[0])).globalFeeWallet;
85903
- const placeOrderIx = await instructions_default3.makePlaceOrderIx(
85904
- program,
85905
- {
85906
- marginfiAccount: marginfiAccount.address,
85907
- feePayer: feePayer ?? marginfiAccount.authority,
85908
- authority: marginfiAccount.authority,
85909
- order,
85910
- globalFeeWallet,
85911
- group: marginfiAccount.group
85912
- },
85913
- { bankKeys: [collateralBank, debtBank], trigger: buildOrderTrigger(trigger) }
85914
- );
85915
- return { instructions: [placeOrderIx], keys: [] };
85916
- }
85917
- async function makeCloseOrderIx2(params) {
85918
- const { program, marginfiAccount, order, feeRecipient } = params;
85919
- const closeOrderIx = await instructions_default3.makeCloseOrderIx(program, {
85920
- marginfiAccount: marginfiAccount.address,
85921
- authority: marginfiAccount.authority,
85922
- order,
85923
- feeRecipient: feeRecipient ?? marginfiAccount.authority,
85924
- group: marginfiAccount.group
85925
- });
85926
- return { instructions: [closeOrderIx], keys: [] };
85927
- }
85928
- async function compileOrderTx(params, payerKey, ixs, type) {
85929
- const blockhash = params.blockhash ?? (await params.connection.getLatestBlockhashAndContext("confirmed")).value.blockhash;
85930
- return addTransactionMetadata(
85931
- new VersionedTransaction(
85932
- new TransactionMessage({
85933
- instructions: ixs.flatMap((ix) => ix.instructions),
85934
- payerKey,
85935
- recentBlockhash: blockhash
85936
- }).compileToV0Message(params.luts)
85937
- ),
85938
- { type, signers: ixs.flatMap((ix) => ix.keys), addressLookupTables: params.luts }
85939
- );
85940
- }
85941
- async function makePlaceOrderTx(params) {
85942
- const placeIxs = await makePlaceOrderIx2(params);
85943
- const payerKey = params.feePayer ?? params.marginfiAccount.authority;
85944
- return compileOrderTx(params, payerKey, [placeIxs], "PLACE_ORDER" /* PLACE_ORDER */);
85945
- }
85946
- async function makeCloseOrderTx(params) {
85947
- const closeIxs = await makeCloseOrderIx2(params);
85948
- return compileOrderTx(
85949
- params,
85950
- params.marginfiAccount.authority,
85951
- [closeIxs],
85952
- "CLOSE_ORDER" /* CLOSE_ORDER */
85953
- );
85954
- }
85955
- async function makeUpdateOrderTx(params) {
85956
- const [order] = deriveOrderPda(params.program.programId, params.marginfiAccount.address, [
85957
- params.collateralBank,
85958
- params.debtBank
85959
- ]);
85960
- const closeIxs = await makeCloseOrderIx2({ ...params, order, feeRecipient: params.feePayer });
85961
- const placeIxs = await makePlaceOrderIx2(params);
85962
- const payerKey = params.feePayer ?? params.marginfiAccount.authority;
85963
- return compileOrderTx(params, payerKey, [closeIxs, placeIxs], "UPDATE_ORDER" /* UPDATE_ORDER */);
85964
- }
85965
86155
 
85966
86156
  // src/services/account/services/account-simulation.service.ts
85967
86157
  async function simulateAccountHealthCacheWithFallback(params) {
@@ -89658,6 +89848,6 @@ var EmodeSettings = class _EmodeSettings {
89658
89848
  }
89659
89849
  };
89660
89850
 
89661
- export { ADDRESS_LOOKUP_TABLE_FOR_GROUP, ADDRESS_LOOKUP_TABLE_FOR_GROUP_NATIVE_STAKE, ADDRESS_LOOKUP_TABLE_FOR_SWAP, AccountFlags, AccountType, AssetTag, BUNDLE_TX_SIZE, Balance, Bank, BankConfig, BankConfigFlag, BankVaultType, DEFAULT_BRIDGE_MINTS, DEFAULT_ORACLE_MAX_AGE, DEFAULT_REPAY_ALL_EXTRA_BUFFER_BPS, DISABLED_FLAG, EMPTY_HEALTH_CACHE, EXECUTION_HEADROOM_SECONDS, EmodeEntryFlags, EmodeFlags, EmodeImpactStatus, EmodeSettings, EmodeTag, FLASHLOAN_ENABLED_FLAG, HOURS_PER_YEAR, HealthCache, HealthCacheFlags, HealthCacheSimulationError, HealthCacheStatus, JUPITER_V6_PROGRAM, JUP_SWAP_LUT_PROGRAM_AUTHORITY_INDEX, KAMINO_MARKET_EMERGENCY_FLAG, LST_MINT, MARGINFI_IDL, MARGINFI_PROGRAM, MARGINFI_PROGRAM_STAGING, MARGINFI_PROGRAM_STAGING_ALT, MARGINFI_SPONSORED_SHARD_ID, MAX_ACCOUNT_LOCKS, MAX_CONFIDENCE_INTERVAL_RATIO, MAX_COSTLY_POSITIONS, MAX_TX_SIZE, MAX_U64, MPL_METADATA_PROGRAM_ID, MarginRequirementType, MarginfiAccount, MarginfiAccountWrapper, MarginfiGroup, OperationalState, OracleSetup, PDA_BANK_EMISSIONS_AUTH_SEED, PDA_BANK_EMISSIONS_VAULT_SEED, PDA_BANK_FEE_STATE_SEED, PDA_BANK_FEE_VAULT_AUTH_SEED, PDA_BANK_FEE_VAULT_SEED, PDA_BANK_INSURANCE_VAULT_AUTH_SEED, PDA_BANK_INSURANCE_VAULT_SEED, PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED, PDA_BANK_LIQUIDITY_VAULT_SEED, PDA_MARGINFI_ACCOUNT_SEED, PDA_ORDER_SEED, PDA_REBALANCE_FEE_POOL_SEED, PREMIUM_ACTIVE_FLAG, PRIORITY_TX_SIZE, PYTH_PRICE_CONF_INTERVALS, PYTH_PUSH_ORACLE_ID, PYTH_SPONSORED_SHARD_ID, PriceBias, Project0Client, RiskTier, SECONDS_PER_YEAR, SINGLE_POOL_PROGRAM_ID, STAKED_ORACLE_DISABLED_FLAG, STAKED_ORACLE_USES_ONRAMP_FLAG, STAKE_CONFIG_ID, STAKE_PROGRAM_ID, SWAP_ADAPTERS, SYSTEM_PROGRAM_ID, SYSVAR_CLOCK_ID, SYSVAR_RENT_ID, SYSVAR_STAKE_HISTORY_ID, SwapProvider, TRANSFER_ACCOUNT_AUTHORITY_FLAG, TransactionArenaKeyMap, TransactionBuildingError, TransactionBuildingErrorCode, TransactionConfigMap, TransactionType, U64_MAX2 as U64_MAX, USDC_DECIMALS, USDC_MINT, USDT_MINT, VENUE_AVAILABLE_LIQUIDITY_BUFFER, WSOL_MINT, ZERO_ORACLE_KEY, accountConflictsWithBridgeBank, accountFlagToBN, addOracleToBanksIx, addTransactionMetadata, adjustPriceComponent, appendPremiumRefresh, aprToApy, apyToApr, balanceToDto, bankConfigRawToDto, bankConfigToBankConfigRaw, bankMetadataMapToDto, bankMetadataToDto, bankRateLimiterRawToDto, bankRawToDto, bigNumberToWrappedI80F48, bpsToPercentile, buildCollateralLegIxs, buildOrderTrigger, calculateApyFromInterest, calculateInterestFromApy, capConfidenceInterval, categorizePythBanks, checkJupiterFeeAccount, checkTitanFeeAccount, chunkedGetRawMultipleAccountInfoOrdered, chunkedGetRawMultipleAccountInfoOrderedWithNulls, chunkedGetRawMultipleAccountInfos, classifyAndValidate, compileFlashloanPrecheck, composeBridgedSwap, composeRemainingAccounts, computeAccountValue, computeAccrualProjectionSeconds, computeActiveEmodePairs, computeAssetHealthComponent, computeAssetUsdValue, computeBalancePremium, computeBalanceUsdValue, computeBankAvailableLiquidity, computeBankBorrowApy, computeBankBorrowCapRemaining, computeBankDepositCapRemaining, computeBankMetrics, computeBankOutflowRateLimit, computeBankPoolSize, computeBankProjectedAvailableLiquidity, computeBankRateLimitRemaining, computeBankSupplyApy, computeBankTotalBorrows, computeBankTotalBorrowsUsd, computeBankTotalDeposits, computeBankTotalDepositsUsd, computeBaseInterestRate, computeBorrowEstimateForRepay, computeClosePositionTokenAmount, computeEmodeImpacts, computeFlashLoanNonSwapBudget, computeFlashloanSwapConstraints, computeFreeCollateralFromBalances, computeFreeCollateralFromCache, computeGroupRateLimitRemainingUsd, computeHealthAccountMetas, computeHealthCacheStatus, computeHealthCheckAccounts, computeHealthComponentsFromBalances, computeHealthComponentsFromCache, computeInterestRates, computeLiabilityHealthComponent, computeLiabilityUsdValue, computeLiquidationPriceForBank, computeLoopingParams, computeLowestEmodeWeights, computeMaxBorrowForBank, computeMaxDepositForBank, computeMaxLeverage, computeMaxWithdrawForBank, computeNetApy, computeOracleMultiplier, computeOracleMultipliers, computeOrderPairNetValue, computePremiumBreakdown, computePremiumImpact, computePremiumRatesByBank, computeProjectedActiveBalancesNoCpi, computeProjectedActiveBanksNoCpi, computePtMultiplier, computeQuantity, computeQuantityUi, computeRateLimitWindowRemainingCapacity, computeRateLimiterRemainingCapacity, computeRemainingCapacity, computeStakedBankMultipliers, computeTvl, computeUsdValue, computeUtilizationRate, computeV0TxSize, computeVenueAvailableLiquidity, configureScopeOracleIx, convertVoteAccCoeffsToBankCoeffs, createActiveEmodePairFromPairs, createEmptyBalance, decodeAccountRaw, decodeBankRaw, decodeInstruction, decodeMultiplierAccount, decompileV0Transaction, deriveBankEmissionsAuth, deriveBankEmissionsVault, deriveBankFeeVault, deriveBankFeeVaultAuthority, deriveBankInsuranceVault, deriveBankInsuranceVaultAuthority, deriveBankLiquidityVault, deriveBankLiquidityVaultAuthority, deriveFeeState, deriveMarginfiAccount, deriveOrderPda, deriveRebalanceFeePool, deserializeInstruction, deserializeLut, deserializeSwapEngineRequest, deserializeSwapEngineResult, dtoToBalance, dtoToBank, dtoToBankConfig, dtoToBankConfigRaw, dtoToBankMetadata, dtoToBankMetadataMap, dtoToBankRateLimiter, dtoToBankRateLimiterRaw, dtoToBankRaw, dtoToEmodeSettings, dtoToEmodeSettingsRaw, dtoToGroup, dtoToHealthCache, dtoToInterestRateConfig, dtoToMarginfiAccount, dtoToOraclePrice, dtoToValidatorStakeGroup, emodeSettingsRawToDto, exceedsCostlyPositionLimit, extractPythOracleKeys, fetchBank, fetchBankIntegrationMetadata, fetchGammaLpVault, fetchGammaWithdrawReceipt, fetchMarginfiAccountActiveBalancesForBank, fetchMarginfiAccountAddresses, fetchMarginfiAccountAddressesHoldingBank, fetchMarginfiAccountData, fetchMultipleBanks, fetchMultiplierAccountStates, fetchMultiplierAccountStatesFromAPI, fetchNativeStakeAccounts, fetchOracleData, fetchOracleMultipliers, fetchOracleMultipliersFromAPI, fetchOracleMultipliersFromChain, fetchOrderFees, fetchOrdersForAccount, fetchProgramForMints, fetchPythOracleData, fetchPythOraclePricesFromAPI, fetchPythOraclePricesFromChain, fetchScopeOracleData, fetchScopeOraclePricesFromAPI, fetchScopeOraclePricesFromChain, fetchStakeAccount, fetchStakePoolActiveStates, fetchStakePoolMev, findRandomAvailableAccountIndex, fitsInOneTransaction, freezeBankConfigIx, generateDummyAccount, getAccountKeys, getActiveAccountFlags, getActiveBalances, getActiveEmodeEntryFlags, getActiveEmodeFlags, getActiveHealthCacheFlags, getAssetQuantity, getAssetShares, getAssetWeight, getBalance, getBalanceUsdValueWithPriceBias, getBankVaultAuthority, getBankVaultSeeds, getBirdeyeFallbackPricesByFeedId, getBirdeyePricesForMints, getConfig, getDriftCTokenMultiplier, getDriftMetadata, getDriftStatesDto, getEffectiveDepositLimit, getEmodePairs, getExactOutEstimate, getFallbackPricesByFeedId, getFallbackPricesForMints, getHealthCacheStatusDescription, getHealthSimulationTransactions, getJupLendFTokenMultiplier, getJupLendMetadata, getJupLendStatesDto, getJupiterReferralFeeAccount, getJupiterSwapIxsForFlashloan, getKaminoCTokenMultiplier, getKaminoMetadata, getKaminoStatesDto, getLiabilityQuantity, getLiabilityShares, getLiabilityWeight, getOracleMultiplierBankInput, getOracleSourceFromBank, getOracleSourceFromOracleSetup, getOracleSourceNameFromKey, getPrice, getPriceWithConfidence, getStakedBankMetadataMap, getSwapAdapter, getSwapIxsForFlashloan, getTitanExactOutEstimate, getTitanSwapIxsForFlashloan, getTotalAccountKeys, getTotalAssetQuantity, getTotalLiabilityQuantity, getTxSize, getValidatorVoteAccountByBank, getWritableAccountKeys, groupToDto, hasAccountFlag, hasEmodeEntryFlag, hasEmodeFlag, hasHealthCacheFlag, healthCacheToDto, isBorrowLimitActive, isBridgeConflictError, isCostlyBank, isDecomposableSwapError, isDepositIx, isDepositLimitActive, isFlashloan, isGroupRateLimiterEnabled, isStandardBorrowable, isStandardDepositable, isV0Tx, isWeightedPrice, isWholePosition, makeAccountTransferToNewAccountTx, makeAddPermissionlessStakedBankIx, makeBeginFlashLoanIx3 as makeBeginFlashLoanIx, makeBorrowIx3 as makeBorrowIx, makeBorrowTx, makeBridgedLoopTx, makeBridgedSwapCollateralTx, makeBridgedSwapDebtTx, makeBulkRepayTx, makeBulkWithdrawTx, makeBundleTipIx, makeCloseMarginfiAccountIx, makeCloseMarginfiAccountTx, makeCloseOrderIx2 as makeCloseOrderIx, makeCloseOrderTx, makeCreateAccountIxWithProjection, makeCreateAccountTxWithProjection, makeCreateMarginfiAccountIx, makeCreateMarginfiAccountTx, makeDepositIx3 as makeDepositIx, makeDepositTx, makeDriftDepositIx3 as makeDriftDepositIx, makeDriftDepositTx, makeDriftWithdrawIx3 as makeDriftWithdrawIx, makeDriftWithdrawTx, makeEndFlashLoanIx3 as makeEndFlashLoanIx, makeFlashLoanTx, makeJuplendDepositIx2 as makeJuplendDepositIx, makeJuplendDepositTx, makeJuplendWithdrawIx2 as makeJuplendWithdrawIx, makeJuplendWithdrawTx, makeKaminoDepositIx3 as makeKaminoDepositIx, makeKaminoDepositTx, makeKaminoWithdrawIx3 as makeKaminoWithdrawIx, makeKaminoWithdrawTx, makeLoopTx, makeMergeStakeAccountsTx, makeMintStakedLstIx, makeMintStakedLstTx, makePlaceOrderIx2 as makePlaceOrderIx, makePlaceOrderTx, makePoolAddBankIx2 as makePoolAddBankIx, makePoolConfigureBankGovIx2 as makePoolConfigureBankGovIx, makePoolConfigureBankIx2 as makePoolConfigureBankIx, makePreludeTxs, makePremiumRefreshIxs, makePriorityFeeIx, makePriorityFeeMicroIx, makePulseHealthIx3 as makePulseHealthIx, makeRedeemStakedLstIx, makeRedeemStakedLstTx, makeRefreshIntegrationBanksIxs, makeRefreshKaminoBanksIxs, makeRepayIx3 as makeRepayIx, makeRepayTx, makeRepayWithCollatTx, makeRollPtTx, makeSetupIx, makeSwapCollateralTx, makeSwapDebtTx, makeTransferPositionsTx, makeTxPriorityIx, makeUnwrapSolIx, makeUpdateDriftMarketIxs, makeUpdateJupLendRateIxs, makeUpdateOrderTx, makeVaultCompleteWithdrawalIx, makeVaultCompleteWithdrawalTx, makeVaultDepositIx, makeVaultDepositTx, makeVaultDepositWithSwapTx, makeVaultWithdrawIx, makeVaultWithdrawTx, makeVersionedTransaction, makeWithdrawIx3 as makeWithdrawIx, makeWithdrawTx, makeWrapSolIxs, mapJupiterQuoteToSwapQuoteResult, mapPythBanksToOraclePrices, marginfiAccountToDto, maxSlippageU32ToPercent, mergeBridgeQuotes, mergeBridgeQuotesDebt, mergeBridgeQuotesLoop, nativeToUi, needsPremiumRefresh, oraclePriceToDto, parseBalanceRaw, parseBankConfigRaw, parseBankRateLimiterRaw, parseBankRaw, parseEmodeSettingsRaw, parseEmodeTag, parseHealthCacheRaw, parseMarginfiAccountRaw, parseOperationalState, parseOracleSetup, parseOrderRaw, parseOraclePriceData as parsePriceInfo, parseRiskTier, parseRpcPythPriceData, patchDepositAmount, percentToMaxSlippageU32, rateFromU32, requireBank, requireTokenProgram, resolveAmount, resolveBridgeCandidateBanks, resolveOrderLegs, resolvePinnedSwapRoute, resolveTokenProgramForMint, resolveVaultTokenProgram, runSwapEngine, selectLutsForAccountAction, selectLutsForBanks, selectSwapBridges, serializeBankConfigOpt, serializeInstruction, serializeInterestRateConfig, serializeLut, serializeOperationalState, serializeOracleSetup, serializeOracleSetupToIndex, serializeRiskTier, serializeSwapEngineRequest, serializeSwapEngineResult, setOraclePriceIx, sharedBridgeLegContext, shortenAddress, simulateAccountHealthCache, simulateAccountHealthCacheWithFallback, simulateBundle, splitInstructionsToFitTransactions, swapEngineProvidersFromOpts, swapEngineQuoteFieldsFromOpts, toBankConfigDto, toBankDto, toBankRateLimiterDto, toBigNumber, toEmodeSettingsDto, toInterestRateConfigDto, toJupiterConfig, toNumber, tryBridgeCandidates, uiToNative, uiToNativeBigNumber, validatorStakeGroupToDto, withKaminoReserveEmergency, wrappedI80F48toBigNumber };
89851
+ export { ADDRESS_LOOKUP_TABLE_FOR_GROUP, ADDRESS_LOOKUP_TABLE_FOR_GROUP_NATIVE_STAKE, ADDRESS_LOOKUP_TABLE_FOR_SWAP, AccountFlags, AccountType, AssetTag, BUNDLE_TX_SIZE, Balance, Bank, BankConfig, BankConfigFlag, BankVaultType, DEFAULT_BRIDGE_MINTS, DEFAULT_ORACLE_MAX_AGE, DEFAULT_REPAY_ALL_EXTRA_BUFFER_BPS, DISABLED_FLAG, EMPTY_HEALTH_CACHE, EXECUTION_HEADROOM_SECONDS, EmodeEntryFlags, EmodeFlags, EmodeImpactStatus, EmodeSettings, EmodeTag, FLASHLOAN_ENABLED_FLAG, HOURS_PER_YEAR, HealthCache, HealthCacheFlags, HealthCacheSimulationError, HealthCacheStatus, JUPITER_V6_PROGRAM, JUP_SWAP_LUT_PROGRAM_AUTHORITY_INDEX, KAMINO_MARKET_EMERGENCY_FLAG, LST_MINT, MARGINFI_IDL, MARGINFI_PROGRAM, MARGINFI_PROGRAM_STAGING, MARGINFI_PROGRAM_STAGING_ALT, MARGINFI_SPONSORED_SHARD_ID, MAX_ACCOUNT_LOCKS, MAX_CONFIDENCE_INTERVAL_RATIO, MAX_COSTLY_POSITIONS, MAX_TX_SIZE, MAX_U64, MPL_METADATA_PROGRAM_ID, MarginRequirementType, MarginfiAccount, MarginfiAccountWrapper, MarginfiGroup, OperationalState, OracleSetup, PDA_BANK_EMISSIONS_AUTH_SEED, PDA_BANK_EMISSIONS_VAULT_SEED, PDA_BANK_FEE_STATE_SEED, PDA_BANK_FEE_VAULT_AUTH_SEED, PDA_BANK_FEE_VAULT_SEED, PDA_BANK_INSURANCE_VAULT_AUTH_SEED, PDA_BANK_INSURANCE_VAULT_SEED, PDA_BANK_LIQUIDITY_VAULT_AUTH_SEED, PDA_BANK_LIQUIDITY_VAULT_SEED, PDA_MARGINFI_ACCOUNT_SEED, PDA_ORDER_SEED, PDA_REBALANCE_FEE_POOL_SEED, PREMIUM_ACTIVE_FLAG, PRIORITY_TX_SIZE, PYTH_PRICE_CONF_INTERVALS, PYTH_PUSH_ORACLE_ID, PYTH_SPONSORED_SHARD_ID, PriceBias, Project0Client, RiskTier, SECONDS_PER_YEAR, SINGLE_POOL_PROGRAM_ID, STAKED_ORACLE_DISABLED_FLAG, STAKED_ORACLE_USES_ONRAMP_FLAG, STAKE_CONFIG_ID, STAKE_PROGRAM_ID, SWAP_ADAPTERS, SYSTEM_PROGRAM_ID, SYSVAR_CLOCK_ID, SYSVAR_RENT_ID, SYSVAR_STAKE_HISTORY_ID, SwapProvider, TRANSFER_ACCOUNT_AUTHORITY_FLAG, TransactionArenaKeyMap, TransactionBuildingError, TransactionBuildingErrorCode, TransactionConfigMap, TransactionType, U64_MAX2 as U64_MAX, USDC_DECIMALS, USDC_MINT, USDT_MINT, VENUE_AVAILABLE_LIQUIDITY_BUFFER, WSOL_MINT, ZERO_ORACLE_KEY, accountConflictsWithBridgeBank, accountFlagToBN, addOracleToBanksIx, addTransactionMetadata, adjustPriceComponent, appendPremiumRefresh, aprToApy, apyToApr, balanceToDto, bankConfigRawToDto, bankConfigToBankConfigRaw, bankMetadataMapToDto, bankMetadataToDto, bankRateLimiterRawToDto, bankRawToDto, bigNumberToWrappedI80F48, bpsToPercentile, buildCollateralLegIxs, buildOrderTrigger, calculateApyFromInterest, calculateInterestFromApy, capConfidenceInterval, categorizePythBanks, checkJupiterFeeAccount, checkTitanFeeAccount, chunkedGetRawMultipleAccountInfoOrdered, chunkedGetRawMultipleAccountInfoOrderedWithNulls, chunkedGetRawMultipleAccountInfos, classifyAndValidate, compileFlashloanPrecheck, composeBridgedSwap, composeRemainingAccounts, computeAccountValue, computeAccrualProjectionSeconds, computeActiveEmodePairs, computeAssetHealthComponent, computeAssetUsdValue, computeBalancePremium, computeBalanceUsdValue, computeBankAvailableLiquidity, computeBankBorrowApy, computeBankBorrowCapRemaining, computeBankDepositCapRemaining, computeBankMetrics, computeBankOutflowRateLimit, computeBankPoolSize, computeBankProjectedAvailableLiquidity, computeBankRateLimitRemaining, computeBankSupplyApy, computeBankTotalBorrows, computeBankTotalBorrowsUsd, computeBankTotalDeposits, computeBankTotalDepositsUsd, computeBaseInterestRate, computeBorrowEstimateForRepay, computeClosePositionTokenAmount, computeEmodeImpacts, computeFlashLoanNonSwapBudget, computeFlashloanSwapConstraints, computeFreeCollateralFromBalances, computeFreeCollateralFromCache, computeGroupRateLimitRemainingUsd, computeHealthAccountMetas, computeHealthCacheStatus, computeHealthCheckAccounts, computeHealthComponentsFromBalances, computeHealthComponentsFromCache, computeInterestRates, computeLiabilityHealthComponent, computeLiabilityUsdValue, computeLiquidationPriceForBank, computeLoopingParams, computeLowestEmodeWeights, computeMaxBorrowForBank, computeMaxDepositForBank, computeMaxLeverage, computeMaxWithdrawForBank, computeNetApy, computeOracleMultiplier, computeOracleMultipliers, computeOrderPairNetValue, computePremiumBreakdown, computePremiumImpact, computePremiumRatesByBank, computeProjectedActiveBalancesNoCpi, computeProjectedActiveBanksNoCpi, computePtMultiplier, computeQuantity, computeQuantityUi, computeRateLimitWindowRemainingCapacity, computeRateLimiterRemainingCapacity, computeRemainingCapacity, computeStakedBankMultipliers, computeTvl, computeUsdValue, computeUtilizationRate, computeV0TxSize, computeVenueAvailableLiquidity, configureScopeOracleIx, convertVoteAccCoeffsToBankCoeffs, createActiveEmodePairFromPairs, createEmptyBalance, decodeAccountRaw, decodeBankRaw, decodeInstruction, decodeMultiplierAccount, decompileV0Transaction, deriveBankEmissionsAuth, deriveBankEmissionsVault, deriveBankFeeVault, deriveBankFeeVaultAuthority, deriveBankInsuranceVault, deriveBankInsuranceVaultAuthority, deriveBankLiquidityVault, deriveBankLiquidityVaultAuthority, deriveFeeState, deriveMarginfiAccount, deriveOrderPda, deriveRebalanceFeePool, deserializeInstruction, deserializeLut, deserializeSwapEngineRequest, deserializeSwapEngineResult, dtoToBalance, dtoToBank, dtoToBankConfig, dtoToBankConfigRaw, dtoToBankMetadata, dtoToBankMetadataMap, dtoToBankRateLimiter, dtoToBankRateLimiterRaw, dtoToBankRaw, dtoToEmodeSettings, dtoToEmodeSettingsRaw, dtoToGroup, dtoToHealthCache, dtoToInterestRateConfig, dtoToMarginfiAccount, dtoToOraclePrice, dtoToValidatorStakeGroup, emodeSettingsRawToDto, exceedsCostlyPositionLimit, extractPythOracleKeys, fetchBank, fetchBankIntegrationMetadata, fetchGammaLpVault, fetchGammaWithdrawReceipt, fetchMarginfiAccountActiveBalancesForBank, fetchMarginfiAccountAddresses, fetchMarginfiAccountAddressesHoldingBank, fetchMarginfiAccountData, fetchMultipleBanks, fetchMultiplierAccountStates, fetchMultiplierAccountStatesFromAPI, fetchNativeStakeAccounts, fetchOracleData, fetchOracleMultipliers, fetchOracleMultipliersFromAPI, fetchOracleMultipliersFromChain, fetchOrderFees, fetchOrdersForAccount, fetchProgramForMints, fetchPythOracleData, fetchPythOraclePricesFromAPI, fetchPythOraclePricesFromChain, fetchScopeOracleData, fetchScopeOraclePricesFromAPI, fetchScopeOraclePricesFromChain, fetchStakeAccount, fetchStakePoolActiveStates, fetchStakePoolMev, findRandomAvailableAccountIndex, fitsInOneTransaction, freezeBankConfigIx, generateDummyAccount, getAccountKeys, getActiveAccountFlags, getActiveBalances, getActiveEmodeEntryFlags, getActiveEmodeFlags, getActiveHealthCacheFlags, getAssetQuantity, getAssetShares, getAssetWeight, getBalance, getBalanceUsdValueWithPriceBias, getBankVaultAuthority, getBankVaultSeeds, getBirdeyeFallbackPricesByFeedId, getBirdeyePricesForMints, getConfig, getDriftCTokenMultiplier, getDriftMetadata, getDriftStatesDto, getEffectiveDepositLimit, getEmodePairs, getExactOutEstimate, getFallbackPricesByFeedId, getFallbackPricesForMints, getHealthCacheStatusDescription, getHealthSimulationTransactions, getJupLendFTokenMultiplier, getJupLendMetadata, getJupLendStatesDto, getJupiterReferralFeeAccount, getJupiterSwapIxsForFlashloan, getKaminoCTokenMultiplier, getKaminoMetadata, getKaminoStatesDto, getLiabilityQuantity, getLiabilityShares, getLiabilityWeight, getOracleMultiplierBankInput, getOracleSourceFromBank, getOracleSourceFromOracleSetup, getOracleSourceNameFromKey, getPrice, getPriceWithConfidence, getStakedBankMetadataMap, getSwapAdapter, getSwapIxsForFlashloan, getTitanExactOutEstimate, getTitanSwapIxsForFlashloan, getTotalAccountKeys, getTotalAssetQuantity, getTotalLiabilityQuantity, getTxSize, getValidatorVoteAccountByBank, getWritableAccountKeys, groupToDto, hasAccountFlag, hasEmodeEntryFlag, hasEmodeFlag, hasHealthCacheFlag, healthCacheToDto, isBorrowLimitActive, isBridgeConflictError, isCostlyBank, isDecomposableSwapError, isDepositIx, isDepositLimitActive, isFlashloan, isGroupRateLimiterEnabled, isStandardBorrowable, isStandardDepositable, isV0Tx, isWeightedPrice, isWholePosition, makeAccountTransferToNewAccountTx, makeAddPermissionlessStakedBankIx, makeBeginFlashLoanIx3 as makeBeginFlashLoanIx, makeBorrowIx3 as makeBorrowIx, makeBorrowTx, makeBridgedLoopTx, makeBridgedSwapCollateralTx, makeBridgedSwapDebtTx, makeBulkRepayTx, makeBulkWithdrawTx, makeBundleTipIx, makeCloseMarginfiAccountIx, makeCloseMarginfiAccountTx, makeCloseOrderIx2 as makeCloseOrderIx, makeCloseOrderTx, makeCreateAccountIxWithProjection, makeCreateAccountTxWithProjection, makeCreateMarginfiAccountIx, makeCreateMarginfiAccountTx, makeDepositIx3 as makeDepositIx, makeDepositTx, makeDriftDepositIx3 as makeDriftDepositIx, makeDriftDepositTx, makeDriftWithdrawIx3 as makeDriftWithdrawIx, makeDriftWithdrawTx, makeEndFlashLoanIx3 as makeEndFlashLoanIx, makeFlashLoanTx, makeJuplendDepositIx2 as makeJuplendDepositIx, makeJuplendDepositTx, makeJuplendWithdrawIx2 as makeJuplendWithdrawIx, makeJuplendWithdrawTx, makeKaminoDepositIx3 as makeKaminoDepositIx, makeKaminoDepositTx, makeKaminoWithdrawIx3 as makeKaminoWithdrawIx, makeKaminoWithdrawTx, makeLoopTx, makeMergeStakeAccountsTx, makeMintStakedLstIx, makeMintStakedLstTx, makeOrderChangesIxs, makeOrderChangesTx, makePlaceOrderIx2 as makePlaceOrderIx, makePlaceOrderTx, makePoolAddBankIx2 as makePoolAddBankIx, makePoolConfigureBankGovIx2 as makePoolConfigureBankGovIx, makePoolConfigureBankIx2 as makePoolConfigureBankIx, makePreludeTxs, makePremiumRefreshIxs, makePriorityFeeIx, makePriorityFeeMicroIx, makePulseHealthIx3 as makePulseHealthIx, makeRedeemStakedLstIx, makeRedeemStakedLstTx, makeRefreshIntegrationBanksIxs, makeRefreshKaminoBanksIxs, makeRepayIx3 as makeRepayIx, makeRepayTx, makeRepayWithCollatTx, makeRollPtTx, makeSetupIx, makeSwapCollateralTx, makeSwapDebtTx, makeTransferPositionsTx, makeTxPriorityIx, makeUnwrapSolIx, makeUpdateDriftMarketIxs, makeUpdateJupLendRateIxs, makeUpdateOrderTx, makeVaultCompleteWithdrawalIx, makeVaultCompleteWithdrawalTx, makeVaultDepositIx, makeVaultDepositTx, makeVaultDepositWithSwapTx, makeVaultWithdrawIx, makeVaultWithdrawTx, makeVersionedTransaction, makeWithdrawIx3 as makeWithdrawIx, makeWithdrawTx, makeWrapSolIxs, mapJupiterQuoteToSwapQuoteResult, mapPythBanksToOraclePrices, marginfiAccountToDto, maxSlippageU32ToPercent, mergeBridgeQuotes, mergeBridgeQuotesDebt, mergeBridgeQuotesLoop, nativeToUi, needsPremiumRefresh, oraclePriceToDto, parseBalanceRaw, parseBankConfigRaw, parseBankRateLimiterRaw, parseBankRaw, parseEmodeSettingsRaw, parseEmodeTag, parseHealthCacheRaw, parseMarginfiAccountRaw, parseOperationalState, parseOracleSetup, parseOrderRaw, parseOraclePriceData as parsePriceInfo, parseRiskTier, parseRpcPythPriceData, patchDepositAmount, percentToMaxSlippageU32, prependOrderCloses, rateFromU32, requireBank, requireTokenProgram, resolveAmount, resolveBridgeCandidateBanks, resolveOrderLegs, resolvePinnedSwapRoute, resolveTokenProgramForMint, resolveVaultTokenProgram, runSwapEngine, selectLutsForAccountAction, selectLutsForBanks, selectSwapBridges, serializeBankConfigOpt, serializeInstruction, serializeInterestRateConfig, serializeLut, serializeOperationalState, serializeOracleSetup, serializeOracleSetupToIndex, serializeRiskTier, serializeSwapEngineRequest, serializeSwapEngineResult, setOraclePriceIx, sharedBridgeLegContext, shortenAddress, simulateAccountHealthCache, simulateAccountHealthCacheWithFallback, simulateBundle, splitInstructionsToFitTransactions, swapEngineProvidersFromOpts, swapEngineQuoteFieldsFromOpts, toBankConfigDto, toBankDto, toBankRateLimiterDto, toBigNumber, toEmodeSettingsDto, toInterestRateConfigDto, toJupiterConfig, toNumber, tryBridgeCandidates, uiToNative, uiToNativeBigNumber, validatorStakeGroupToDto, withKaminoReserveEmergency, wrappedI80F48toBigNumber };
89662
89852
  //# sourceMappingURL=index.js.map
89663
89853
  //# sourceMappingURL=index.js.map