@0dotxyz/p0-ts-sdk 2.5.5-alpha.6 → 2.5.5-alpha.8

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.cjs CHANGED
@@ -65603,6 +65603,34 @@ async function getTitanExactOutViaHttpProxy(params) {
65603
65603
  }
65604
65604
 
65605
65605
  // src/services/account/utils/swap.utils.ts
65606
+ function resolvePinnedSwapRoute(swapIxs, expectedInAmountNative) {
65607
+ const { quoteResponse } = swapIxs;
65608
+ const expectedIn = new BN9__default.default(expectedInAmountNative);
65609
+ let minOut;
65610
+ try {
65611
+ minOut = new BN9__default.default(quoteResponse.otherAmountThreshold);
65612
+ } catch {
65613
+ minOut = new BN9__default.default(0);
65614
+ }
65615
+ if (minOut.lten(0)) {
65616
+ throw new Error(
65617
+ `Pinned swap route (swapOpts.swapIxs) has no usable min-out: quoteResponse.otherAmountThreshold is "${quoteResponse.otherAmountThreshold}". The min-out sizes the follow-up amount (e.g. the loop's deposit) \u2014 without it the flow would deposit zero collateral and fail init health.`
65618
+ );
65619
+ }
65620
+ const pinnedIn = new BN9__default.default(quoteResponse.inAmount);
65621
+ if (!pinnedIn.eq(expectedIn)) {
65622
+ throw new Error(
65623
+ `Pinned swap route (swapOpts.swapIxs) was quoted for a different input amount than the flow will swap: quote inAmount=${pinnedIn.toString()}, flow swap input=${expectedIn.toString()} (native units). Re-quote the pinned route for the exact flow amount.`
65624
+ );
65625
+ }
65626
+ return {
65627
+ swapInstructions: swapIxs.instructions,
65628
+ setupInstructions: [],
65629
+ lookupTables: swapIxs.lookupTables,
65630
+ quoteResponse,
65631
+ outputAmountNative: minOut
65632
+ };
65633
+ }
65606
65634
  function getSwapProviderFn({
65607
65635
  attemptProvider,
65608
65636
  maxSwapTotalAccounts,
@@ -65709,16 +65737,12 @@ var getSwapIxsForFlashloan = async (params) => {
65709
65737
  maxSwapTotalAccounts
65710
65738
  } = params;
65711
65739
  if (swapOpts.swapIxs) {
65740
+ const pinned = resolvePinnedSwapRoute(swapOpts.swapIxs, amount);
65712
65741
  return {
65713
- swapInstructions: swapOpts.swapIxs.instructions,
65714
- setupInstructions: [],
65715
- addressLookupTableAddresses: swapOpts.swapIxs.lookupTables,
65716
- quoteResponse: {
65717
- inAmount: String(amount),
65718
- outAmount: "0",
65719
- otherAmountThreshold: "0",
65720
- slippageBps: 0
65721
- }
65742
+ swapInstructions: pinned.swapInstructions,
65743
+ setupInstructions: pinned.setupInstructions,
65744
+ addressLookupTableAddresses: pinned.lookupTables,
65745
+ quoteResponse: pinned.quoteResponse
65722
65746
  };
65723
65747
  }
65724
65748
  const provider = swapOpts.swapConfig?.provider ?? "JUPITER" /* JUPITER */;
@@ -66397,7 +66421,12 @@ async function makeRepayWithCollatTx(params) {
66397
66421
  );
66398
66422
  }
66399
66423
  const transactions = [...additionalTxs, flashloanTx];
66400
- return { transactions, swapQuote, amountToRepay };
66424
+ return {
66425
+ transactions,
66426
+ swapQuote,
66427
+ amountToRepay,
66428
+ mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
66429
+ };
66401
66430
  }
66402
66431
  async function buildRepayWithCollatFlashloanTx({
66403
66432
  program,
@@ -68582,7 +68611,8 @@ async function makeSwapDebtTx(params) {
68582
68611
  return {
68583
68612
  transactions,
68584
68613
  actionTxIndex: transactions.length - 1,
68585
- quoteResponse: swapQuote
68614
+ quoteResponse: swapQuote,
68615
+ mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
68586
68616
  };
68587
68617
  }
68588
68618
  async function buildSwapDebtFlashloanTx({
@@ -68770,6 +68800,7 @@ async function makeBridgedSwapDebtTx(params) {
68770
68800
  return await makeSwapDebtTx(directParams);
68771
68801
  } catch (directError) {
68772
68802
  if (!isDecomposableSwapError(directError)) throw directError;
68803
+ if (directParams.swapOpts.swapIxs) throw directError;
68773
68804
  const bridged = await tryBridgedDebtSwap(directParams, bridgeOpts);
68774
68805
  if (bridged) return bridged;
68775
68806
  throw directError;
@@ -68848,7 +68879,8 @@ async function tryBridgedDebtSwap(params, bridgeOpts) {
68848
68879
  transactions: result.transactions,
68849
68880
  actionTxIndex: result.transactions.length - 1,
68850
68881
  quoteResponse: mergeBridgeQuotesDebt(result.firstLegQuote, result.secondLegQuote),
68851
- bridgeMint: bridgeBank.mint
68882
+ bridgeMint: bridgeBank.mint,
68883
+ mustBeAtomicBundle: true
68852
68884
  };
68853
68885
  }
68854
68886
  });
@@ -68957,7 +68989,8 @@ async function makeLoopTx(params) {
68957
68989
  return {
68958
68990
  transactions,
68959
68991
  actionTxIndex: transactions.length - 1,
68960
- quoteResponse: swapQuote
68992
+ quoteResponse: swapQuote,
68993
+ mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
68961
68994
  };
68962
68995
  }
68963
68996
  async function buildLoopFlashloanTx(params) {
@@ -69187,17 +69220,13 @@ async function buildDepositIxs(params, amountUi) {
69187
69220
  async function runLoopSwapEngine(descriptor, params) {
69188
69221
  const { connection, swapOpts, marginfiAccount, swapEngineRunner } = params;
69189
69222
  if (swapOpts.swapIxs) {
69223
+ const pinned = resolvePinnedSwapRoute(swapOpts.swapIxs, descriptor.inAmountNative);
69190
69224
  return {
69191
- swapInstructions: swapOpts.swapIxs.instructions,
69192
- setupInstructions: [],
69193
- swapLuts: swapOpts.swapIxs.lookupTables,
69194
- quoteResponse: {
69195
- inAmount: String(descriptor.inAmountNative),
69196
- outAmount: "0",
69197
- otherAmountThreshold: "0",
69198
- slippageBps: 0
69199
- },
69200
- outputAmountNative: new BN9__default.default(0)
69225
+ swapInstructions: pinned.swapInstructions,
69226
+ setupInstructions: pinned.setupInstructions,
69227
+ swapLuts: pinned.lookupTables,
69228
+ quoteResponse: pinned.quoteResponse,
69229
+ outputAmountNative: pinned.outputAmountNative
69201
69230
  };
69202
69231
  }
69203
69232
  const runEngine = swapEngineRunner ?? runSwapEngine;
@@ -69272,6 +69301,7 @@ async function makeBridgedLoopTx(params) {
69272
69301
  return await makeLoopTx(loopParams);
69273
69302
  } catch (directError) {
69274
69303
  if (!isDecomposableSwapError(directError)) throw directError;
69304
+ if (loopParams.swapOpts.swapIxs) throw directError;
69275
69305
  const bridged = await tryBridgedLoop(loopParams, bridgeOpts);
69276
69306
  if (bridged) return bridged;
69277
69307
  throw directError;
@@ -69353,7 +69383,8 @@ async function tryBridgedLoop(params, bridgeOpts) {
69353
69383
  transactions: result.transactions,
69354
69384
  actionTxIndex: result.transactions.length - 1,
69355
69385
  quoteResponse: mergeBridgeQuotesLoop(result.firstLegQuote, result.secondLegQuote),
69356
- bridgeMint: bridgeBank.mint
69386
+ bridgeMint: bridgeBank.mint,
69387
+ mustBeAtomicBundle: true
69357
69388
  };
69358
69389
  }
69359
69390
  });
@@ -69449,7 +69480,8 @@ async function makeSwapCollateralTx(params) {
69449
69480
  return {
69450
69481
  transactions,
69451
69482
  actionTxIndex: transactions.length - 1,
69452
- quoteResponse: swapQuote
69483
+ quoteResponse: swapQuote,
69484
+ mustBeAtomicBundle: refreshIntegrationIxs.instructions.length > 0
69453
69485
  };
69454
69486
  }
69455
69487
  async function buildSwapCollateralFlashloanTx({
@@ -69789,6 +69821,7 @@ async function makeBridgedSwapCollateralTx(params) {
69789
69821
  return await makeSwapCollateralTx(directParams);
69790
69822
  } catch (directError) {
69791
69823
  if (!isDecomposableSwapError(directError)) throw directError;
69824
+ if (directParams.swapOpts.swapIxs) throw directError;
69792
69825
  const bridged = await tryBridgedCollateralSwap(directParams, bridgeOpts);
69793
69826
  if (bridged) return bridged;
69794
69827
  throw directError;
@@ -69862,7 +69895,8 @@ async function tryBridgedCollateralSwap(params, bridgeOpts) {
69862
69895
  transactions: result.transactions,
69863
69896
  actionTxIndex: result.transactions.length - 1,
69864
69897
  quoteResponse: mergeBridgeQuotes(result.firstLegQuote, result.secondLegQuote),
69865
- bridgeMint: bridgeBank.mint
69898
+ bridgeMint: bridgeBank.mint,
69899
+ mustBeAtomicBundle: true
69866
69900
  };
69867
69901
  }
69868
69902
  });
@@ -76922,6 +76956,7 @@ exports.requireBank = requireBank;
76922
76956
  exports.requireTokenProgram = requireTokenProgram;
76923
76957
  exports.resolveAmount = resolveAmount;
76924
76958
  exports.resolveBridgeCandidateBanks = resolveBridgeCandidateBanks;
76959
+ exports.resolvePinnedSwapRoute = resolvePinnedSwapRoute;
76925
76960
  exports.resolveTokenProgramForMint = resolveTokenProgramForMint;
76926
76961
  exports.runSwapEngine = runSwapEngine;
76927
76962
  exports.selectLutsForAccountAction = selectLutsForAccountAction;