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

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 */;
@@ -68770,6 +68794,7 @@ async function makeBridgedSwapDebtTx(params) {
68770
68794
  return await makeSwapDebtTx(directParams);
68771
68795
  } catch (directError) {
68772
68796
  if (!isDecomposableSwapError(directError)) throw directError;
68797
+ if (directParams.swapOpts.swapIxs) throw directError;
68773
68798
  const bridged = await tryBridgedDebtSwap(directParams, bridgeOpts);
68774
68799
  if (bridged) return bridged;
68775
68800
  throw directError;
@@ -69187,17 +69212,13 @@ async function buildDepositIxs(params, amountUi) {
69187
69212
  async function runLoopSwapEngine(descriptor, params) {
69188
69213
  const { connection, swapOpts, marginfiAccount, swapEngineRunner } = params;
69189
69214
  if (swapOpts.swapIxs) {
69215
+ const pinned = resolvePinnedSwapRoute(swapOpts.swapIxs, descriptor.inAmountNative);
69190
69216
  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)
69217
+ swapInstructions: pinned.swapInstructions,
69218
+ setupInstructions: pinned.setupInstructions,
69219
+ swapLuts: pinned.lookupTables,
69220
+ quoteResponse: pinned.quoteResponse,
69221
+ outputAmountNative: pinned.outputAmountNative
69201
69222
  };
69202
69223
  }
69203
69224
  const runEngine = swapEngineRunner ?? runSwapEngine;
@@ -69272,6 +69293,7 @@ async function makeBridgedLoopTx(params) {
69272
69293
  return await makeLoopTx(loopParams);
69273
69294
  } catch (directError) {
69274
69295
  if (!isDecomposableSwapError(directError)) throw directError;
69296
+ if (loopParams.swapOpts.swapIxs) throw directError;
69275
69297
  const bridged = await tryBridgedLoop(loopParams, bridgeOpts);
69276
69298
  if (bridged) return bridged;
69277
69299
  throw directError;
@@ -69789,6 +69811,7 @@ async function makeBridgedSwapCollateralTx(params) {
69789
69811
  return await makeSwapCollateralTx(directParams);
69790
69812
  } catch (directError) {
69791
69813
  if (!isDecomposableSwapError(directError)) throw directError;
69814
+ if (directParams.swapOpts.swapIxs) throw directError;
69792
69815
  const bridged = await tryBridgedCollateralSwap(directParams, bridgeOpts);
69793
69816
  if (bridged) return bridged;
69794
69817
  throw directError;
@@ -76922,6 +76945,7 @@ exports.requireBank = requireBank;
76922
76945
  exports.requireTokenProgram = requireTokenProgram;
76923
76946
  exports.resolveAmount = resolveAmount;
76924
76947
  exports.resolveBridgeCandidateBanks = resolveBridgeCandidateBanks;
76948
+ exports.resolvePinnedSwapRoute = resolvePinnedSwapRoute;
76925
76949
  exports.resolveTokenProgramForMint = resolveTokenProgramForMint;
76926
76950
  exports.runSwapEngine = runSwapEngine;
76927
76951
  exports.selectLutsForAccountAction = selectLutsForAccountAction;