@tradeport/sui-trading-sdk 0.4.39 → 0.4.40

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.
Files changed (34) hide show
  1. package/dist/index.d.mts +19 -2
  2. package/dist/index.d.ts +19 -2
  3. package/dist/index.js +310 -160
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +270 -130
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +7 -4
  8. package/src/SuiTradingClient.ts +18 -4
  9. package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +1 -1
  10. package/src/helpers/kiosk/kioskTxWrapper.ts +3 -3
  11. package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +1 -1
  12. package/src/helpers/kiosk/resolveRoyaltyRule.ts +5 -0
  13. package/src/helpers/kiosk/resolveTransferPolicies.ts +3 -0
  14. package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +12 -4
  15. package/src/helpers/swap/swap.ts +147 -0
  16. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +1 -1
  17. package/src/methods/acceptNftBids/acceptNftBids.ts +1 -1
  18. package/src/methods/buyListings/addBuyListingTxs.ts +5 -0
  19. package/src/methods/buyListings/buyListings.ts +20 -7
  20. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +1 -1
  21. package/src/methods/claimNfts/claimNfts.ts +1 -1
  22. package/src/methods/createMultiBid/createMultiBid.ts +6 -7
  23. package/src/methods/listNfts/listNfts.ts +1 -1
  24. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +1 -1
  25. package/src/methods/placeCollectionBids/placeCollectionBids.ts +28 -8
  26. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +8 -7
  27. package/src/methods/placeNftBids/placeNftBids.ts +27 -8
  28. package/src/methods/removeCollectionBids/removeCollectionBids.ts +1 -1
  29. package/src/methods/removeNftBids/removeNftBids.ts +1 -1
  30. package/src/methods/transferNfts/transferNfts.ts +1 -1
  31. package/src/methods/unlistListings/unlistListings.ts +1 -2
  32. package/src/methods/updateMultiBid/updateMultiBid.ts +35 -4
  33. package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +3 -3
  34. package/src/helpers/extractSwapResultCoin.ts +0 -17
package/dist/index.mjs CHANGED
@@ -106,7 +106,7 @@ var fetchCollectionBidsAtSamePrice = gql3`
106
106
  `;
107
107
 
108
108
  // src/methods/acceptCollectionBid/acceptCollectionBid.ts
109
- import { Transaction as Transaction2 } from "@mysten/sui/transactions";
109
+ import { Transaction as Transaction3 } from "@mysten/sui/transactions";
110
110
 
111
111
  // src/constants.ts
112
112
  var MYSTEN_TRANFER_POLICY_RULES_PACKAGE_ID = "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879";
@@ -1514,7 +1514,7 @@ var kioskTxWrapper = async ({
1514
1514
  variables: { kioskId: personalKiosk.id }
1515
1515
  })).personalCap.id;
1516
1516
  kioskTx = new KioskTransaction({
1517
- transactionBlock: tx,
1517
+ transaction: tx,
1518
1518
  kioskClient,
1519
1519
  cap: {
1520
1520
  isPersonal: true,
@@ -1531,7 +1531,7 @@ var kioskTxWrapper = async ({
1531
1531
  variables: { kioskId: kiosks[0].id }
1532
1532
  })).ownerCap?.id;
1533
1533
  kioskTx = new KioskTransaction({
1534
- transactionBlock: tx,
1534
+ transaction: tx,
1535
1535
  kioskClient,
1536
1536
  cap: {
1537
1537
  isPersonal: false,
@@ -1542,7 +1542,7 @@ var kioskTxWrapper = async ({
1542
1542
  }
1543
1543
  });
1544
1544
  } else {
1545
- kioskTx = new KioskTransaction({ transactionBlock: tx, kioskClient });
1545
+ kioskTx = new KioskTransaction({ transaction: tx, kioskClient });
1546
1546
  kioskTx.createPersonal(true);
1547
1547
  }
1548
1548
  if (shouldUseSharedKioskTx && sharedKioskState) {
@@ -1719,10 +1719,87 @@ function resolvePersonalKioskRule({ tx, packageId, nftType, kiosk, transferReque
1719
1719
  });
1720
1720
  }
1721
1721
 
1722
+ // src/helpers/swap/swap.ts
1723
+ import { AggregatorQuoter, Protocol, TradeBuilder } from "@flowx-finance/sdk";
1724
+ import { Transaction } from "@mysten/sui/transactions";
1725
+ import { normalizeStructTag as normalizeStructTag2, normalizeSuiAddress } from "@mysten/sui/utils";
1726
+ import ms from "ms";
1727
+ var aggregatorQuoter = new AggregatorQuoter("mainnet");
1728
+ var suiCointType = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
1729
+ async function createBuyTransaction(client, walletAddress, suiAmount, options) {
1730
+ const transaction = options?.transaction ?? new Transaction();
1731
+ transaction.setSender(normalizeSuiAddress(walletAddress));
1732
+ const {
1733
+ coinType,
1734
+ coinAmount = 0n,
1735
+ slippage = 1,
1736
+ ttl = "15m",
1737
+ excludeSources = [Protocol.STEAMM]
1738
+ } = options ?? {};
1739
+ if (!coinType || normalizeStructTag2(coinType) === suiCointType) {
1740
+ const [coin] = transaction.splitCoins(transaction.gas, [suiAmount]);
1741
+ return {
1742
+ transaction,
1743
+ suiCoin: coin
1744
+ };
1745
+ }
1746
+ const { routes } = await aggregatorQuoter.getRoutes({
1747
+ tokenIn: coinType,
1748
+ tokenOut: suiCointType,
1749
+ amountIn: coinAmount.toString(),
1750
+ excludeSources
1751
+ });
1752
+ const tradeBuilder = new TradeBuilder("mainnet", routes);
1753
+ const trade = tradeBuilder.sender(normalizeSuiAddress(walletAddress)).slippage(slippage).deadline(Date.now() + ms(ttl)).build();
1754
+ const swappedSuiCoin = await trade.swap({
1755
+ client,
1756
+ tx: transaction
1757
+ });
1758
+ if (!swappedSuiCoin) {
1759
+ throw new Error("Swap did not return a valid SUI coin.");
1760
+ }
1761
+ return { transaction, suiCoin: swappedSuiCoin };
1762
+ }
1763
+ async function handleSwapSetup(client, walletAddress, transaction, swapAndPayOptions) {
1764
+ if (!swapAndPayOptions?.coinType || !swapAndPayOptions?.coinAmount) {
1765
+ return { transaction };
1766
+ }
1767
+ const { transaction: updatedTx, suiCoin } = await createBuyTransaction(
1768
+ client,
1769
+ walletAddress,
1770
+ BigInt(swapAndPayOptions.coinAmount),
1771
+ {
1772
+ transaction,
1773
+ coinType: swapAndPayOptions.coinType,
1774
+ coinAmount: BigInt(swapAndPayOptions.coinAmount),
1775
+ slippage: swapAndPayOptions.slippage,
1776
+ ttl: swapAndPayOptions.ttl,
1777
+ excludeSources: swapAndPayOptions.excludeSources
1778
+ }
1779
+ );
1780
+ return {
1781
+ transaction: updatedTx,
1782
+ swapResultCoin: suiCoin
1783
+ };
1784
+ }
1785
+ function handleSwapCleanup(transaction, swapResultCoin, walletAddress) {
1786
+ if (swapResultCoin) {
1787
+ transaction.transferObjects([swapResultCoin], walletAddress);
1788
+ }
1789
+ }
1790
+ function mergeSwapCoinWithSuiBalance(transaction, coinToMergeInto, amountToSplitFromGas) {
1791
+ if (coinToMergeInto && amountToSplitFromGas && amountToSplitFromGas > 0n) {
1792
+ const [coinFromSuiBalance] = transaction.splitCoins(transaction.gas, [
1793
+ transaction.pure.u64(amountToSplitFromGas)
1794
+ ]);
1795
+ transaction.mergeCoins(coinToMergeInto, [coinFromSuiBalance]);
1796
+ }
1797
+ }
1798
+
1722
1799
  // src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts
1723
1800
  import { bcs } from "@mysten/sui/bcs";
1724
1801
  import {
1725
- Transaction
1802
+ Transaction as Transaction2
1726
1803
  } from "@mysten/sui/transactions";
1727
1804
  async function getKioskCollectionRoyaltyFeeAmount({
1728
1805
  tx,
@@ -1742,7 +1819,7 @@ async function getKioskCollectionRoyaltyFeeAmount({
1742
1819
  console.warn("Price is undefined or 0");
1743
1820
  return void 0;
1744
1821
  }
1745
- const feeTx = new Transaction();
1822
+ const feeTx = new Transaction2();
1746
1823
  feeTx.moveCall({
1747
1824
  target: `${royaltyRulePackageId}::${royaltyRuleModule}::fee_amount`,
1748
1825
  arguments: [feeTx.object(transferPolicyId), feeTx.pure.u64(price)],
@@ -1781,7 +1858,8 @@ async function resolveRoyaltyRule({
1781
1858
  nftType,
1782
1859
  price,
1783
1860
  coinToSplit,
1784
- royaltyFeeAmount
1861
+ royaltyFeeAmount,
1862
+ amountToSplitFromSuiBalance
1785
1863
  }) {
1786
1864
  let feeAmount = royaltyFeeAmount;
1787
1865
  if (!feeAmount) {
@@ -1796,6 +1874,7 @@ async function resolveRoyaltyRule({
1796
1874
  nftType
1797
1875
  });
1798
1876
  }
1877
+ mergeSwapCoinWithSuiBalance(tx, coinToSplit, amountToSplitFromSuiBalance);
1799
1878
  const feeCoin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [feeAmount]);
1800
1879
  tx.moveCall({
1801
1880
  target: `${packageId}::${moduleName}::pay`,
@@ -1823,7 +1902,8 @@ var resolveTransferPolicies = async ({
1823
1902
  coinToSplit,
1824
1903
  beforeResolveKioskTransferRequest,
1825
1904
  transferPoliciesToResolve,
1826
- royaltyFeeAmount
1905
+ royaltyFeeAmount,
1906
+ amountToSplitFromSuiBalance
1827
1907
  }) => {
1828
1908
  const policies = transferPoliciesToResolve ?? await getTransferPoliciesToResolve({
1829
1909
  transferPolicies,
@@ -1873,7 +1953,8 @@ var resolveTransferPolicies = async ({
1873
1953
  nftType: policy.isCustom && policy.type ? policy.type : nftType,
1874
1954
  price,
1875
1955
  coinToSplit,
1876
- royaltyFeeAmount
1956
+ royaltyFeeAmount,
1957
+ amountToSplitFromSuiBalance
1877
1958
  });
1878
1959
  break;
1879
1960
  case "floor_price_rule":
@@ -1924,8 +2005,12 @@ var takeLockedNftFromKiosk = async ({
1924
2005
  const [purchase_cap] = tx.moveCall({
1925
2006
  target: "0x2::kiosk::list_with_purchase_cap",
1926
2007
  arguments: [
1927
- tx.object("value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk),
1928
- tx.object("value" in kioskTx.kioskCap ? kioskTx.kioskCap.value : kioskTx.kioskCap),
2008
+ tx.object(
2009
+ "value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk
2010
+ ),
2011
+ tx.object(
2012
+ "value" in kioskTx.kioskCap ? kioskTx.kioskCap.value : kioskTx.kioskCap
2013
+ ),
1929
2014
  tx.pure.address(nftTokenId),
1930
2015
  tx.pure.u64(0)
1931
2016
  ],
@@ -1939,7 +2024,9 @@ var takeLockedNftFromKiosk = async ({
1939
2024
  const [nft, transferRequest] = tx.moveCall({
1940
2025
  target: "0x2::kiosk::purchase_with_cap",
1941
2026
  arguments: [
1942
- tx.object("value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk),
2027
+ tx.object(
2028
+ "value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk
2029
+ ),
1943
2030
  purchase_cap,
1944
2031
  zeroCoin
1945
2032
  ],
@@ -2202,7 +2289,7 @@ var lockNftInsideKioskIfNotLocked = async ({
2202
2289
  takenNftId = "value" in takenNft ? takenNft.value : takenNft;
2203
2290
  }
2204
2291
  kioskTx.lock({
2205
- itemId: takenNftId ?? nftTokenId,
2292
+ item: takenNftId ?? nftTokenId,
2206
2293
  itemType: nftType,
2207
2294
  policy: transferPolicyId
2208
2295
  });
@@ -3149,7 +3236,7 @@ var acceptCollectionBid = async ({
3149
3236
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
3150
3237
  }
3151
3238
  const bidsForTracking = [];
3152
- const tx = existingTx ?? new Transaction2();
3239
+ const tx = existingTx ?? new Transaction3();
3153
3240
  const sharedKioskState = {
3154
3241
  kioskTx: kioskTx ?? void 0
3155
3242
  };
@@ -3219,11 +3306,11 @@ var acceptCollectionBid = async ({
3219
3306
  bidder: bid?.bidder
3220
3307
  });
3221
3308
  sharedKioskState?.kioskTx?.finalize();
3222
- return Transaction2.from(tx);
3309
+ return tx instanceof Transaction3 ? tx : Transaction3.from(tx);
3223
3310
  };
3224
3311
 
3225
3312
  // src/methods/acceptNftBids/acceptNftBids.ts
3226
- import { Transaction as Transaction3 } from "@mysten/sui/transactions";
3313
+ import { Transaction as Transaction4 } from "@mysten/sui/transactions";
3227
3314
 
3228
3315
  // src/graphql/queries/fetchBidsById.ts
3229
3316
  import { gql as gql11 } from "graphql-request";
@@ -3280,7 +3367,7 @@ var acceptNftBids = async ({
3280
3367
  throw new Error("No bids found");
3281
3368
  }
3282
3369
  const bidsForTracking = [];
3283
- const tx = existingTx ?? new Transaction3();
3370
+ const tx = existingTx ?? new Transaction4();
3284
3371
  const sharedKioskState = {
3285
3372
  kioskTx: kioskTx ?? void 0
3286
3373
  };
@@ -3353,15 +3440,15 @@ var acceptNftBids = async ({
3353
3440
  });
3354
3441
  }
3355
3442
  sharedKioskState?.kioskTx?.finalize();
3356
- return Transaction3.from(tx);
3443
+ return tx instanceof Transaction4 ? tx : Transaction4.from(tx);
3357
3444
  };
3358
3445
 
3359
3446
  // src/methods/buyAndExerciseLongLocks/buyAndExerciseLongLocks.ts
3360
- import { Transaction as Transaction6 } from "@mysten/sui/transactions";
3447
+ import { Transaction as Transaction7 } from "@mysten/sui/transactions";
3361
3448
 
3362
3449
  // src/methods/buyLocks/buyLocks.ts
3363
3450
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID2 } from "@mysten/sui.js/utils";
3364
- import { Transaction as Transaction4 } from "@mysten/sui/transactions";
3451
+ import { Transaction as Transaction5 } from "@mysten/sui/transactions";
3365
3452
 
3366
3453
  // src/helpers/calculatePremium.ts
3367
3454
  function calculatePremium(price) {
@@ -3499,7 +3586,7 @@ var getNativeKioskTransferPoliciesByNftType = async (nftType) => {
3499
3586
 
3500
3587
  // src/methods/buyLocks/buyLocks.ts
3501
3588
  async function buyLocks({ lockIds, transaction }, context) {
3502
- const tx = transaction ?? new Transaction4();
3589
+ const tx = transaction ?? new Transaction5();
3503
3590
  for (const lockId of lockIds) {
3504
3591
  const lock = await getLockById(lockId);
3505
3592
  if (!lock) {
@@ -3541,9 +3628,9 @@ async function buyLocks({ lockIds, transaction }, context) {
3541
3628
 
3542
3629
  // src/methods/exerciseLongLocks/exerciseLongLocks.ts
3543
3630
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID3 } from "@mysten/sui.js/utils";
3544
- import { Transaction as Transaction5 } from "@mysten/sui/transactions";
3631
+ import { Transaction as Transaction6 } from "@mysten/sui/transactions";
3545
3632
  async function exerciseLongLocks({ walletAddress, transaction, locks }, context) {
3546
- const tx = transaction ?? new Transaction5();
3633
+ const tx = transaction ?? new Transaction6();
3547
3634
  for (const { id: lockId, bidId } of locks) {
3548
3635
  const lock = await getLockById(lockId);
3549
3636
  if (!transaction && lock.state !== "bought") {
@@ -3695,18 +3782,18 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
3695
3782
 
3696
3783
  // src/methods/buyAndExerciseLongLocks/buyAndExerciseLongLocks.ts
3697
3784
  async function buyAndExerciseLongLocks({ walletAddress, locks, tx: existingTx }, context) {
3698
- const transaction = existingTx ?? new Transaction6();
3785
+ const transaction = existingTx ?? new Transaction7();
3699
3786
  await buyLocks({ lockIds: locks?.map((lock) => lock?.id), transaction }, context);
3700
3787
  await exerciseLongLocks({ locks, walletAddress, transaction }, context);
3701
3788
  return transaction;
3702
3789
  }
3703
3790
 
3704
3791
  // src/methods/buyAndExerciseShortLocks/buyAndExerciseShortLocks.ts
3705
- import { Transaction as Transaction11 } from "@mysten/sui/transactions";
3792
+ import { Transaction as Transaction12 } from "@mysten/sui/transactions";
3706
3793
 
3707
3794
  // src/methods/exerciseShortLocks/exerciseShortLocks.ts
3708
3795
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID4 } from "@mysten/sui.js/utils";
3709
- import { Transaction as Transaction10 } from "@mysten/sui/transactions";
3796
+ import { Transaction as Transaction11 } from "@mysten/sui/transactions";
3710
3797
 
3711
3798
  // src/graphql/queries/fetchListingsById.ts
3712
3799
  import { gql as gql14 } from "graphql-request";
@@ -3739,7 +3826,7 @@ var fetchListingsById = gql14`
3739
3826
  `;
3740
3827
 
3741
3828
  // src/methods/buyListings/buyListings.ts
3742
- import { Transaction as Transaction9 } from "@mysten/sui/transactions";
3829
+ import { Transaction as Transaction10 } from "@mysten/sui/transactions";
3743
3830
 
3744
3831
  // src/helpers/addThirdPartyTxFee.ts
3745
3832
  var addThirdPartyTxFee = async (tx, price) => {
@@ -3753,31 +3840,19 @@ var addThirdPartyTxFee = async (tx, price) => {
3753
3840
  };
3754
3841
 
3755
3842
  // src/helpers/deserializeOrCreateTxBlock.ts
3756
- import { Transaction as Transaction7 } from "@mysten/sui/transactions";
3843
+ import { Transaction as Transaction8 } from "@mysten/sui/transactions";
3757
3844
  var deserializeOrCreateTxBlock = ({
3758
3845
  existingTx
3759
3846
  }) => {
3760
3847
  if (typeof existingTx === "string") {
3761
- return Transaction7.from(existingTx);
3848
+ return Transaction8.from(existingTx);
3762
3849
  }
3763
- return existingTx ?? new Transaction7();
3764
- };
3765
-
3766
- // src/helpers/extractSwapResultCoin.ts
3767
- var extractSwapResultCoinFromTxBlock = (txBlock) => {
3768
- if (!txBlock) return void 0;
3769
- const tx = typeof txBlock === "string" ? JSON.parse(txBlock) : txBlock?.getData();
3770
- const commands = tx.commands ?? [];
3771
- const index = commands.findIndex(
3772
- (cmd) => cmd?.MoveCall?.module === "universal_router" && cmd?.MoveCall?.function === "settle"
3773
- );
3774
- if (index === -1) return void 0;
3775
- return { $kind: "Result", Result: index };
3850
+ return existingTx ?? new Transaction8();
3776
3851
  };
3777
3852
 
3778
3853
  // src/helpers/kiosk/preProcessSharedBulkBuyingData.ts
3779
3854
  import { bcs as bcs2 } from "@mysten/sui/bcs";
3780
- import { Transaction as Transaction8 } from "@mysten/sui/transactions";
3855
+ import { Transaction as Transaction9 } from "@mysten/sui/transactions";
3781
3856
  var preProcessSharedBulkBuyingData = async ({
3782
3857
  listings,
3783
3858
  suiClient,
@@ -3827,7 +3902,7 @@ var preProcessSharedBulkBuyingData = async ({
3827
3902
  (policy) => policy.moduleName === "royalty_rule" || policy.moduleName === "kiosk_royalty_rule"
3828
3903
  );
3829
3904
  if (royaltyRuleToResolve?.rulePackageId && royaltyRuleToResolve?.moduleName) {
3830
- const feeTx = new Transaction8();
3905
+ const feeTx = new Transaction9();
3831
3906
  for (const listing of tradeportKioskListings) {
3832
3907
  feeTx.moveCall({
3833
3908
  target: `${royaltyRuleToResolve.rulePackageId}::${royaltyRuleToResolve.moduleName}::fee_amount`,
@@ -3968,7 +4043,8 @@ var addTradeportKioskBuyTx = async ({
3968
4043
  coinToSplit,
3969
4044
  beforeResolveKioskTransferRequest,
3970
4045
  sharedBulkBuyingDataByNftType,
3971
- collectionId
4046
+ collectionId,
4047
+ amountToSplitFromSuiBalance
3972
4048
  }) => {
3973
4049
  let commissionFeeAmount = sharedBulkBuyingDataByNftType?.[nftType]?.commissionFeeAmountsByListingId?.[listingId] ?? 0;
3974
4050
  if (!commissionFeeAmount) {
@@ -3984,6 +4060,7 @@ var addTradeportKioskBuyTx = async ({
3984
4060
  if (commissionFeeAmount === 0) {
3985
4061
  commissionFeeAmount = getMarketFeePrice({ price, collectionId });
3986
4062
  }
4063
+ mergeSwapCoinWithSuiBalance(tx, coinToSplit, amountToSplitFromSuiBalance);
3987
4064
  const coin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [
3988
4065
  tx.pure.u64(price + commissionFeeAmount)
3989
4066
  ]);
@@ -4013,7 +4090,8 @@ var addTradeportKioskBuyTx = async ({
4013
4090
  coinToSplit,
4014
4091
  beforeResolveKioskTransferRequest,
4015
4092
  transferPoliciesToResolve: sharedBulkBuyingDataByNftType?.[nftType]?.transferPoliciesToResolve,
4016
- royaltyFeeAmount: sharedBulkBuyingDataByNftType?.[nftType]?.royaltyFeeAmountsByListingId?.[listingId]
4093
+ royaltyFeeAmount: sharedBulkBuyingDataByNftType?.[nftType]?.royaltyFeeAmountsByListingId?.[listingId],
4094
+ amountToSplitFromSuiBalance
4017
4095
  });
4018
4096
  destroyZeroCoin({ tx, coin });
4019
4097
  };
@@ -4417,7 +4495,8 @@ var buyListings = async ({
4417
4495
  tx: existingTx,
4418
4496
  kioskTx,
4419
4497
  coinToSplit,
4420
- beforeResolveKioskTransferRequest
4498
+ beforeResolveKioskTransferRequest,
4499
+ swapAndPayOptions
4421
4500
  }, context, marketFeeDecimalPercent) => {
4422
4501
  const res = await gqlChainRequest({
4423
4502
  chain: "sui",
@@ -4428,8 +4507,14 @@ var buyListings = async ({
4428
4507
  throw new Error("No listings found");
4429
4508
  }
4430
4509
  const listingsForTracking = [];
4431
- const tx = deserializeOrCreateTxBlock({ existingTx });
4432
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
4510
+ let tx = deserializeOrCreateTxBlock({ existingTx });
4511
+ const { transaction: updatedTx, swapResultCoin } = await handleSwapSetup(
4512
+ context.suiClient,
4513
+ walletAddress,
4514
+ tx,
4515
+ swapAndPayOptions
4516
+ );
4517
+ tx = updatedTx;
4433
4518
  const tocenTokenIds = [];
4434
4519
  let tocenNftType = "";
4435
4520
  let tocenTotalPrice = 0;
@@ -4478,7 +4563,8 @@ var buyListings = async ({
4478
4563
  marketFeeDecimalPercent,
4479
4564
  beforeResolveKioskTransferRequest,
4480
4565
  sharedKioskState,
4481
- sharedBulkBuyingDataByNftType
4566
+ sharedBulkBuyingDataByNftType,
4567
+ amountToSplitFromSuiBalance: BigInt(swapAndPayOptions?.amountToSplitFromSuiBalance ?? 0n)
4482
4568
  };
4483
4569
  switch (listing?.market_name) {
4484
4570
  case "tradeport":
@@ -4523,9 +4609,7 @@ var buyListings = async ({
4523
4609
  });
4524
4610
  }
4525
4611
  sharedKioskState?.kioskTx?.finalize();
4526
- if (swapResultCoin) {
4527
- tx.transferObjects([swapResultCoin], walletAddress);
4528
- }
4612
+ handleSwapCleanup(tx, swapResultCoin, walletAddress);
4529
4613
  if (tocenTokenIds?.length > 0) {
4530
4614
  addTocenBuyTxHandler({
4531
4615
  tx,
@@ -4534,12 +4618,12 @@ var buyListings = async ({
4534
4618
  price: tocenTotalPrice
4535
4619
  });
4536
4620
  }
4537
- return Transaction9.from(tx);
4621
+ return tx instanceof Transaction10 ? tx : Transaction10.from(tx);
4538
4622
  };
4539
4623
 
4540
4624
  // src/methods/exerciseShortLocks/exerciseShortLocks.ts
4541
4625
  async function exerciseShortLocks({ walletAddress, transaction, locks }, context) {
4542
- const tx = transaction ?? new Transaction10();
4626
+ const tx = transaction ?? new Transaction11();
4543
4627
  for (const { id: lockId, listingId, nftId: nftIdArg } of locks) {
4544
4628
  const lock = await getLockById(lockId);
4545
4629
  if (!transaction && lock.state !== "bought") {
@@ -4677,7 +4761,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
4677
4761
 
4678
4762
  // src/methods/buyAndExerciseShortLocks/buyAndExerciseShortLocks.ts
4679
4763
  async function buyAndExerciseShortLocks({ walletAddress, locks, tx: existingTx }, context) {
4680
- const transaction = existingTx ?? new Transaction11();
4764
+ const transaction = existingTx ?? new Transaction12();
4681
4765
  await buyLocks({ lockIds: locks?.map((lock) => lock?.id), transaction }, context);
4682
4766
  await exerciseShortLocks({ locks, walletAddress, transaction }, context);
4683
4767
  return transaction;
@@ -4685,9 +4769,9 @@ async function buyAndExerciseShortLocks({ walletAddress, locks, tx: existingTx }
4685
4769
 
4686
4770
  // src/methods/cancelLocks/cancelLocks.ts
4687
4771
  import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID5 } from "@mysten/sui.js/utils";
4688
- import { Transaction as Transaction12 } from "@mysten/sui/transactions";
4772
+ import { Transaction as Transaction13 } from "@mysten/sui/transactions";
4689
4773
  async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context) {
4690
- const tx = existingTx ?? new Transaction12();
4774
+ const tx = existingTx ?? new Transaction13();
4691
4775
  for (const lockId of lockIds) {
4692
4776
  const lock = await getLockById(lockId);
4693
4777
  if (!lock) {
@@ -4719,7 +4803,7 @@ async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context)
4719
4803
  }
4720
4804
 
4721
4805
  // src/methods/cancelMultiBid/cancelMultiBid.ts
4722
- import { Transaction as Transaction13 } from "@mysten/sui/transactions";
4806
+ import { Transaction as Transaction14 } from "@mysten/sui/transactions";
4723
4807
 
4724
4808
  // src/methods/removeNftBids/addRemoveNftBidTxs.ts
4725
4809
  import { normalizeSuiObjectId as normalizeSuiObjectId4 } from "@mysten/sui/utils";
@@ -4821,7 +4905,7 @@ async function cancelMultiBid({ multiBidId }) {
4821
4905
  if (cancelled_at) {
4822
4906
  throw new Error(`MultiBid ${multiBidId} already cancelled`);
4823
4907
  }
4824
- const tx = new Transaction13();
4908
+ const tx = new Transaction14();
4825
4909
  if (bids.length > 1022) {
4826
4910
  throw new Error(`Too many bids to cancel in one transaction`);
4827
4911
  }
@@ -4836,7 +4920,7 @@ async function cancelMultiBid({ multiBidId }) {
4836
4920
  }
4837
4921
 
4838
4922
  // src/methods/cancelNftTransfers/cancelNftTransfers.ts
4839
- import { Transaction as Transaction14 } from "@mysten/sui/transactions";
4923
+ import { Transaction as Transaction15 } from "@mysten/sui/transactions";
4840
4924
 
4841
4925
  // src/graphql/queries/fetchAccountKiosks.ts
4842
4926
  import { gql as gql16 } from "graphql-request";
@@ -4890,7 +4974,7 @@ var cancelNftTransfers = async ({ nftIds, walletAddress }, context) => {
4890
4974
  throw new Error("No nfts found");
4891
4975
  }
4892
4976
  const nftsForTracking = [];
4893
- const tx = new Transaction14();
4977
+ const tx = new Transaction15();
4894
4978
  const sharedKioskState = {
4895
4979
  kioskTx: void 0
4896
4980
  };
@@ -4934,11 +5018,11 @@ var cancelNftTransfers = async ({ nftIds, walletAddress }, context) => {
4934
5018
  });
4935
5019
  }
4936
5020
  sharedKioskState?.kioskTx?.finalize();
4937
- return Transaction14.from(tx);
5021
+ return tx instanceof Transaction15 ? tx : Transaction15.from(tx);
4938
5022
  };
4939
5023
 
4940
5024
  // src/methods/claimNfts/claimNfts.ts
4941
- import { Transaction as Transaction15 } from "@mysten/sui/transactions";
5025
+ import { Transaction as Transaction16 } from "@mysten/sui/transactions";
4942
5026
 
4943
5027
  // src/helpers/splitCoins.ts
4944
5028
  var splitCoins = ({ tx, amounts }) => {
@@ -5163,7 +5247,7 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
5163
5247
  throw new Error("No nfts found");
5164
5248
  }
5165
5249
  const nftsForTracking = [];
5166
- const tx = existingTx ?? new Transaction15();
5250
+ const tx = existingTx ?? new Transaction16();
5167
5251
  const sharedKioskState = {
5168
5252
  kioskTx: void 0
5169
5253
  };
@@ -5306,11 +5390,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
5306
5390
  }
5307
5391
  }
5308
5392
  sharedKioskState?.kioskTx?.finalize();
5309
- return Transaction15.from(tx);
5393
+ return tx instanceof Transaction16 ? tx : Transaction16.from(tx);
5310
5394
  };
5311
5395
 
5312
5396
  // src/methods/createLongLocks/createLongLocks.ts
5313
- import { Transaction as Transaction16 } from "@mysten/sui/transactions";
5397
+ import { Transaction as Transaction17 } from "@mysten/sui/transactions";
5314
5398
 
5315
5399
  // src/graphql/queries/fetchActiveLockStateByNftId.ts
5316
5400
  import { gql as gql17 } from "graphql-request";
@@ -5341,7 +5425,7 @@ var getActiveLockStateByNftId = async (nftId) => {
5341
5425
  // src/methods/createLongLocks/createLongLocks.ts
5342
5426
  async function createLongLocks({ walletAddress, nfts }, context) {
5343
5427
  const expireIn = 7 * 24 * 3600 * 1e3;
5344
- const tx = new Transaction16();
5428
+ const tx = new Transaction17();
5345
5429
  for (const argNft of nfts) {
5346
5430
  const existingLock = await getActiveLockStateByNftId(argNft.id);
5347
5431
  if (existingLock) {
@@ -5410,10 +5494,23 @@ async function updateMultiBid({
5410
5494
  amount,
5411
5495
  amountToWithdraw,
5412
5496
  tx: existingTx,
5413
- multiBidChainId
5497
+ multiBidChainId,
5498
+ swapAndPayOptions,
5499
+ suiClient,
5500
+ walletAddress
5414
5501
  }) {
5415
- const tx = deserializeOrCreateTxBlock({ existingTx });
5416
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
5502
+ let tx = deserializeOrCreateTxBlock({ existingTx });
5503
+ let swapResultCoin;
5504
+ if (suiClient) {
5505
+ const { transaction: updatedTx, swapResultCoin: coin2 } = await handleSwapSetup(
5506
+ suiClient,
5507
+ walletAddress,
5508
+ tx,
5509
+ swapAndPayOptions
5510
+ );
5511
+ tx = updatedTx;
5512
+ swapResultCoin = coin2;
5513
+ }
5417
5514
  if (!multiBidChainId) {
5418
5515
  const { chain_id: chainId, cancelled_at } = (await gqlChainRequest({
5419
5516
  chain: "sui",
@@ -5428,6 +5525,11 @@ async function updateMultiBid({
5428
5525
  }
5429
5526
  multiBidChainId = chainId;
5430
5527
  }
5528
+ mergeSwapCoinWithSuiBalance(
5529
+ tx,
5530
+ swapResultCoin,
5531
+ BigInt(swapAndPayOptions?.amountToSplitFromSuiBalance ?? 0n)
5532
+ );
5431
5533
  const [coin] = tx.splitCoins(swapResultCoin ? swapResultCoin : tx.gas, [amount ?? 0n]);
5432
5534
  tx.moveCall({
5433
5535
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::update_multi_bid`,
@@ -5439,16 +5541,14 @@ async function updateMultiBid({
5439
5541
  tx.pure.option("u64", amountToWithdraw)
5440
5542
  ]
5441
5543
  });
5544
+ if (suiClient) {
5545
+ handleSwapCleanup(tx, swapResultCoin, walletAddress);
5546
+ }
5442
5547
  return tx;
5443
5548
  }
5444
5549
 
5445
5550
  // src/methods/createMultiBid/createMultiBid.ts
5446
- async function createMultiBid({
5447
- walletAddress,
5448
- name,
5449
- amount,
5450
- tx: existingTx
5451
- }) {
5551
+ async function createMultiBid({ walletAddress, name, amount, tx: existingTx }, context) {
5452
5552
  const tx = deserializeOrCreateTxBlock({ existingTx });
5453
5553
  const multiBidChainId = tx.moveCall({
5454
5554
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
@@ -5460,17 +5560,18 @@ async function createMultiBid({
5460
5560
  multiBidChainId,
5461
5561
  amount,
5462
5562
  name,
5463
- tx
5563
+ tx,
5564
+ suiClient: context.suiClient
5464
5565
  });
5465
5566
  }
5466
5567
  return { multiBidChainId, tx };
5467
5568
  }
5468
5569
 
5469
5570
  // src/methods/createShortLocks/createShortLocks.ts
5470
- import { Transaction as Transaction17 } from "@mysten/sui/transactions";
5571
+ import { Transaction as Transaction18 } from "@mysten/sui/transactions";
5471
5572
  async function createShortLocks({ nfts }, context) {
5472
5573
  const expireIn = 7 * 24 * 3600 * 1e3;
5473
- const tx = new Transaction17();
5574
+ const tx = new Transaction18();
5474
5575
  for (const argNft of nfts) {
5475
5576
  const premium = calculatePremium(BigInt(argNft.priceInMist));
5476
5577
  if (!argNft.type) {
@@ -5508,8 +5609,8 @@ async function createShortLocks({ nfts }, context) {
5508
5609
  }
5509
5610
 
5510
5611
  // src/methods/listNfts/listNfts.ts
5511
- import { Transaction as Transaction18 } from "@mysten/sui/transactions";
5512
- import { normalizeSuiAddress } from "@mysten/sui/utils";
5612
+ import { Transaction as Transaction19 } from "@mysten/sui/transactions";
5613
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
5513
5614
 
5514
5615
  // src/methods/listNfts/addListTxs.ts
5515
5616
  async function addOriginByteListTx({
@@ -5839,7 +5940,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5839
5940
  throw new Error("No nfts found");
5840
5941
  }
5841
5942
  const nftsForTracking = [];
5842
- const tx = new Transaction18();
5943
+ const tx = new Transaction19();
5843
5944
  const sharedKioskState = {
5844
5945
  kioskTx: void 0
5845
5946
  };
@@ -5854,7 +5955,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5854
5955
  });
5855
5956
  const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
5856
5957
  if (nft?.listed || nft.listings.some(
5857
- (listing) => listing.nonce && listing.seller && normalizeSuiAddress(listing.seller) === normalizeSuiAddress(walletAddress)
5958
+ (listing) => listing.nonce && listing.seller && normalizeSuiAddress2(listing.seller) === normalizeSuiAddress2(walletAddress)
5858
5959
  )) {
5859
5960
  await relistNft({
5860
5961
  tx,
@@ -5892,11 +5993,11 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5892
5993
  });
5893
5994
  }
5894
5995
  sharedKioskState?.kioskTx?.finalize();
5895
- return Transaction18.from(tx);
5996
+ return tx instanceof Transaction19 ? tx : Transaction19.from(tx);
5896
5997
  };
5897
5998
 
5898
5999
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5899
- import { Transaction as Transaction19 } from "@mysten/sui/transactions";
6000
+ import { Transaction as Transaction20 } from "@mysten/sui/transactions";
5900
6001
 
5901
6002
  // src/graphql/queries/fetchNftsByKioskId.ts
5902
6003
  import { gql as gql18 } from "graphql-request";
@@ -6099,7 +6200,7 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
6099
6200
 
6100
6201
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
6101
6202
  async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
6102
- const tx = new Transaction19();
6203
+ const tx = new Transaction20();
6103
6204
  const res = await gqlChainRequest({
6104
6205
  chain: "sui",
6105
6206
  query: fetchKiosksByOwner,
@@ -6265,11 +6366,11 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
6265
6366
  }
6266
6367
  }
6267
6368
  sharedKioskState?.kioskTx?.finalize();
6268
- return Transaction19.from(tx);
6369
+ return tx instanceof Transaction20 ? tx : Transaction20.from(tx);
6269
6370
  }
6270
6371
 
6271
6372
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6272
- import { Transaction as Transaction20 } from "@mysten/sui/transactions";
6373
+ import { Transaction as Transaction21 } from "@mysten/sui/transactions";
6273
6374
 
6274
6375
  // src/graphql/queries/fetchCollectionsById.ts
6275
6376
  import { gql as gql19 } from "graphql-request";
@@ -6324,7 +6425,8 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
6324
6425
  collectionId,
6325
6426
  bcsHex,
6326
6427
  expireAt,
6327
- coinToSplit
6428
+ coinToSplit,
6429
+ amountToSplitFromSuiBalance
6328
6430
  } = txData;
6329
6431
  let bcs4;
6330
6432
  if (nftTokenId && isDynamicCollection(collectionId)) {
@@ -6378,6 +6480,7 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
6378
6480
  }
6379
6481
  txWithState.hasCancelBidTransactions.set(multiBidChainId, true);
6380
6482
  }
6483
+ mergeSwapCoinWithSuiBalance(tx, coinToSplit, amountToSplitFromSuiBalance);
6381
6484
  const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [
6382
6485
  multiBidChainId ? 0n : price + fee + royalty
6383
6486
  ]);
@@ -6483,7 +6586,14 @@ async function addOriginByteCollectionBidTx({
6483
6586
  }
6484
6587
 
6485
6588
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6486
- var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6589
+ var placeCollectionBids = async ({
6590
+ collections,
6591
+ walletAddress,
6592
+ multiBidId,
6593
+ multiBidChainId,
6594
+ tx: existingTx,
6595
+ swapAndPayOptions
6596
+ }, context) => {
6487
6597
  const res = await gqlChainRequest({
6488
6598
  chain: "sui",
6489
6599
  query: fetchCollectionsByIdWithOneNft,
@@ -6493,8 +6603,14 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6493
6603
  throw new Error("No collection found");
6494
6604
  }
6495
6605
  const collectionsForTracking = [];
6496
- const tx = deserializeOrCreateTxBlock({ existingTx });
6497
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
6606
+ let tx = deserializeOrCreateTxBlock({ existingTx });
6607
+ const { transaction: updatedTx, swapResultCoin } = await handleSwapSetup(
6608
+ context.suiClient,
6609
+ walletAddress,
6610
+ tx,
6611
+ swapAndPayOptions
6612
+ );
6613
+ tx = updatedTx;
6498
6614
  for (const collection of res.collections) {
6499
6615
  const nftType = getNftType({
6500
6616
  collectionId: collection?.id,
@@ -6514,7 +6630,8 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6514
6630
  multiBidId,
6515
6631
  multiBidChainId,
6516
6632
  expireAt: collections?.find((c) => c.id === collection?.id)?.expireAt,
6517
- coinToSplit: swapResultCoin
6633
+ coinToSplit: swapResultCoin,
6634
+ amountToSplitFromSuiBalance: BigInt(swapAndPayOptions?.amountToSplitFromSuiBalance ?? 0n)
6518
6635
  };
6519
6636
  const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
6520
6637
  if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
@@ -6541,17 +6658,28 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6541
6658
  bidder: walletAddress
6542
6659
  });
6543
6660
  }
6544
- if (swapResultCoin) {
6545
- tx.transferObjects([swapResultCoin], walletAddress);
6546
- }
6547
- return Transaction20.from(tx);
6661
+ handleSwapCleanup(tx, swapResultCoin, walletAddress);
6662
+ return tx instanceof Transaction21 ? tx : Transaction21.from(tx);
6548
6663
  };
6549
6664
 
6550
6665
  // src/methods/placeNftBids/placeNftBids.ts
6551
- import { Transaction as Transaction21 } from "@mysten/sui/transactions";
6552
- var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6553
- const tx = deserializeOrCreateTxBlock({ existingTx });
6554
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
6666
+ import { Transaction as Transaction22 } from "@mysten/sui/transactions";
6667
+ var placeNftBids = async ({
6668
+ bids,
6669
+ walletAddress,
6670
+ multiBidId,
6671
+ multiBidChainId,
6672
+ tx: existingTx,
6673
+ swapAndPayOptions
6674
+ }, context) => {
6675
+ let tx = deserializeOrCreateTxBlock({ existingTx });
6676
+ const { transaction: updatedTx, swapResultCoin } = await handleSwapSetup(
6677
+ context.suiClient,
6678
+ walletAddress,
6679
+ tx,
6680
+ swapAndPayOptions
6681
+ );
6682
+ tx = updatedTx;
6555
6683
  const res = await gqlChainRequest({
6556
6684
  chain: "sui",
6557
6685
  query: fetchNftsById,
@@ -6585,7 +6713,8 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6585
6713
  multiBidId,
6586
6714
  multiBidChainId,
6587
6715
  expireAt: bid?.expireAt,
6588
- coinToSplit: swapResultCoin
6716
+ coinToSplit: swapResultCoin,
6717
+ amountToSplitFromSuiBalance: BigInt(swapAndPayOptions?.amountToSplitFromSuiBalance ?? 0n)
6589
6718
  };
6590
6719
  await addTradePortPlaceNftBidTxHandler(txData);
6591
6720
  nftsForTracking.push({
@@ -6595,14 +6724,12 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6595
6724
  bidder: walletAddress
6596
6725
  });
6597
6726
  }
6598
- if (swapResultCoin) {
6599
- tx.transferObjects([swapResultCoin], walletAddress);
6600
- }
6601
- return Transaction21.from(tx);
6727
+ handleSwapCleanup(tx, swapResultCoin, walletAddress);
6728
+ return tx instanceof Transaction22 ? tx : Transaction22.from(tx);
6602
6729
  };
6603
6730
 
6604
6731
  // src/methods/removeCollectionBids/removeCollectionBids.ts
6605
- import { Transaction as Transaction22 } from "@mysten/sui/transactions";
6732
+ import { Transaction as Transaction23 } from "@mysten/sui/transactions";
6606
6733
 
6607
6734
  // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
6608
6735
  import { normalizeSuiObjectId as normalizeSuiObjectId6 } from "@mysten/sui/utils";
@@ -6710,7 +6837,7 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6710
6837
  throw new Error("No bids found");
6711
6838
  }
6712
6839
  const bidsForTracking = [];
6713
- const tx = existingTx ? Transaction22.from(existingTx) : new Transaction22();
6840
+ const tx = existingTx ? Transaction23.from(existingTx) : new Transaction23();
6714
6841
  for (const bid of res.bids) {
6715
6842
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6716
6843
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6758,11 +6885,11 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6758
6885
  bidder: bid?.bidder
6759
6886
  });
6760
6887
  }
6761
- return Transaction22.from(tx);
6888
+ return tx instanceof Transaction23 ? tx : Transaction23.from(tx);
6762
6889
  };
6763
6890
 
6764
6891
  // src/methods/removeNftBids/removeNftBids.ts
6765
- import { Transaction as Transaction23 } from "@mysten/sui/transactions";
6892
+ import { Transaction as Transaction24 } from "@mysten/sui/transactions";
6766
6893
  var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6767
6894
  const res = await gqlChainRequest({
6768
6895
  chain: "sui",
@@ -6773,7 +6900,7 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6773
6900
  throw new Error("No bids found");
6774
6901
  }
6775
6902
  const bidsForTracking = [];
6776
- const tx = existingTx ? Transaction23.from(existingTx) : new Transaction23();
6903
+ const tx = existingTx ? Transaction24.from(existingTx) : new Transaction24();
6777
6904
  for (const bid of res.bids) {
6778
6905
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6779
6906
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6818,11 +6945,11 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6818
6945
  bidder: bid?.bidder
6819
6946
  });
6820
6947
  }
6821
- return Transaction23.from(tx);
6948
+ return tx instanceof Transaction24 ? tx : Transaction24.from(tx);
6822
6949
  };
6823
6950
 
6824
6951
  // src/methods/transferNfts/transferNfts.ts
6825
- import { Transaction as Transaction24 } from "@mysten/sui/transactions";
6952
+ import { Transaction as Transaction25 } from "@mysten/sui/transactions";
6826
6953
  var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context) => {
6827
6954
  if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
6828
6955
  throw new Error("Cannot transfer to self");
@@ -6840,7 +6967,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6840
6967
  }
6841
6968
  const nftsForTracking = [];
6842
6969
  const nftsToTransferDirectly = [];
6843
- const tx = new Transaction24();
6970
+ const tx = new Transaction25();
6844
6971
  const sharedKioskState = {
6845
6972
  kioskTx: void 0
6846
6973
  };
@@ -6943,11 +7070,11 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6943
7070
  context.suiClient
6944
7071
  );
6945
7072
  sharedKioskState?.kioskTx?.finalize();
6946
- return Transaction24.from(tx);
7073
+ return tx instanceof Transaction25 ? tx : Transaction25.from(tx);
6947
7074
  };
6948
7075
 
6949
7076
  // src/methods/unlistListings/unlistListings.ts
6950
- import { Transaction as Transaction25 } from "@mysten/sui/transactions";
7077
+ import { Transaction as Transaction26 } from "@mysten/sui/transactions";
6951
7078
  var unlistListings = async ({ listingIds, walletAddress }, context) => {
6952
7079
  const res = await gqlChainRequest({
6953
7080
  chain: "sui",
@@ -6958,7 +7085,7 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
6958
7085
  throw new Error("No listings found");
6959
7086
  }
6960
7087
  const listingsForTracking = [];
6961
- const tx = new Transaction25();
7088
+ const tx = new Transaction26();
6962
7089
  const sharedKioskState = {
6963
7090
  kioskTx: void 0
6964
7091
  };
@@ -7027,12 +7154,12 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
7027
7154
  });
7028
7155
  }
7029
7156
  sharedKioskState?.kioskTx?.finalize();
7030
- return Transaction25.from(tx);
7157
+ return tx instanceof Transaction26 ? tx : Transaction26.from(tx);
7031
7158
  };
7032
7159
 
7033
7160
  // src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts
7034
7161
  import { KioskTransaction as KioskTransaction2 } from "@mysten/kiosk";
7035
- import { Transaction as Transaction26 } from "@mysten/sui/transactions";
7162
+ import { Transaction as Transaction27 } from "@mysten/sui/transactions";
7036
7163
  async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7037
7164
  const res = await gqlChainRequest({
7038
7165
  chain: "sui",
@@ -7052,7 +7179,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7052
7179
  if (kiosksWithProfit.length === 0) {
7053
7180
  throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
7054
7181
  }
7055
- const tx = new Transaction26();
7182
+ const tx = new Transaction27();
7056
7183
  try {
7057
7184
  for (const kiosk of kiosksWithProfit) {
7058
7185
  let kioskTx;
@@ -7063,7 +7190,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7063
7190
  variables: { kioskId: kiosk.id }
7064
7191
  })).personalCap?.id;
7065
7192
  kioskTx = new KioskTransaction2({
7066
- transactionBlock: tx,
7193
+ transaction: tx,
7067
7194
  kioskClient: context.kioskClient,
7068
7195
  cap: {
7069
7196
  isPersonal: true,
@@ -7080,7 +7207,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7080
7207
  variables: { kioskId: kiosk.id }
7081
7208
  })).ownerCap?.id;
7082
7209
  kioskTx = new KioskTransaction2({
7083
- transactionBlock: tx,
7210
+ transaction: tx,
7084
7211
  kioskClient: context.kioskClient,
7085
7212
  cap: {
7086
7213
  isPersonal: false,
@@ -7098,7 +7225,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7098
7225
  } catch (err) {
7099
7226
  console.log("err", err);
7100
7227
  }
7101
- return Transaction26.from(tx);
7228
+ return tx instanceof Transaction27 ? tx : Transaction27.from(tx);
7102
7229
  }
7103
7230
 
7104
7231
  // src/SuiTradingClient.ts
@@ -7117,14 +7244,19 @@ var SuiTradingClient = class {
7117
7244
  "x-api-key": apiKey
7118
7245
  });
7119
7246
  }
7120
- async buyListings({ listingIds, walletAddress, tx }) {
7247
+ async buyListings({
7248
+ listingIds,
7249
+ walletAddress,
7250
+ tx,
7251
+ swapAndPayOptions
7252
+ }) {
7121
7253
  const context = {
7122
7254
  apiUser: this.apiUser,
7123
7255
  apiKey: this.apiKey,
7124
7256
  suiClient: this.suiClient,
7125
7257
  kioskClient: this.kioskClient
7126
7258
  };
7127
- return buyListings({ listingIds, walletAddress, tx }, context);
7259
+ return buyListings({ listingIds, walletAddress, tx, swapAndPayOptions }, context);
7128
7260
  }
7129
7261
  async listNfts({ nfts, walletAddress }) {
7130
7262
  const context = {
@@ -7179,7 +7311,8 @@ var SuiTradingClient = class {
7179
7311
  multiBidId,
7180
7312
  multiBidChainId,
7181
7313
  expireAt,
7182
- tx
7314
+ tx,
7315
+ swapAndPayOptions
7183
7316
  }) {
7184
7317
  const context = {
7185
7318
  apiUser: this.apiUser,
@@ -7200,7 +7333,8 @@ var SuiTradingClient = class {
7200
7333
  walletAddress,
7201
7334
  multiBidId,
7202
7335
  multiBidChainId,
7203
- tx
7336
+ tx,
7337
+ swapAndPayOptions
7204
7338
  },
7205
7339
  context
7206
7340
  );
@@ -7426,13 +7560,19 @@ var SuiTradingClient = class {
7426
7560
  return migrateNftsFromUnsharedToSharedKiosks(args, context);
7427
7561
  }
7428
7562
  async createMultiBid(args) {
7429
- return createMultiBid(args);
7563
+ const context = {
7564
+ apiUser: this.apiUser,
7565
+ apiKey: this.apiKey,
7566
+ suiClient: this.suiClient,
7567
+ kioskClient: this.kioskClient
7568
+ };
7569
+ return createMultiBid(args, context);
7430
7570
  }
7431
7571
  async cancelMultiBid(args) {
7432
7572
  return cancelMultiBid(args);
7433
7573
  }
7434
7574
  async updateMultiBid(args) {
7435
- return updateMultiBid(args);
7575
+ return updateMultiBid({ ...args, suiClient: this.suiClient });
7436
7576
  }
7437
7577
  };
7438
7578
  var SuiTradingClient_default = SuiTradingClient;