@tradeport/sui-trading-sdk 0.4.65 → 0.4.66

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.mjs CHANGED
@@ -142,16 +142,6 @@ var TRADEPORT_NFT_STRATEGY_PACKAGE_ID = "0xb7386fc8c6e64ea2b0079e293592b57e98498
142
142
  var TRADEPORT_NFT_STRATEGY_MANAGER_ID = "0xfb58ee62b3a62a8150f871da950dfdf923cd0d97b153caf99b5219cd4ddda5bd";
143
143
  var TRADEPORT_POOL_REGISTRY_ID = "0xcd0a614c4cbbf173f59dee2602c43a1717f283215ed7a0bb1d55d786af16fbcd";
144
144
  var TRADEPORT_POOL_VERSIONED_ID = "0x0309b66202e9aaf470081fffee7ffc0fbd50e3b7400d4f56fd06502e4dbbd676";
145
- var DexConstants = {
146
- commission: "0x24f5f2258ef80c0a3243088199faeb95ad50516ca1517dbd93be398d759057bb",
147
- commissionManager: "0xd19a03d4ec3d12b0ce407b54eb676cc0f8e1403621deda77d9677bfcb9d738c1",
148
- poolsToExclude: [
149
- "0x3addbbc82866c0bbd93e51b6e2d75c0a4faaf270cc0e281d8f4de5df48bebfa4",
150
- "0x19d614f421046cae90f5a3a976816063478f648087a12adc74e90ebd54dfaf19",
151
- "0x514c74e28a9720366abc4a65a5688f47c72e784dbf035844d3f59059bfaed056",
152
- "0x0854de4e9d64716b757b2f6f22258467f59cc1b4bc0cc64c70086549faaddedf"
153
- ]
154
- };
155
145
  var USDC_COIN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
156
146
  var COLLECTION_IDS_WITH_ZERO_COMMISSION = [
157
147
  ""
@@ -1425,6 +1415,14 @@ var getTransferPolicyRuleNamesFromSuiObject = async ({
1425
1415
  return ruleNames;
1426
1416
  };
1427
1417
 
1418
+ // src/helpers/kiosk/upgradeKioskRulesPackageId.ts
1419
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
1420
+ var KIOSK_RULES_ORIGINAL_PACKAGE_ID = normalizeSuiAddress(
1421
+ "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879"
1422
+ );
1423
+ var KIOSK_RULES_UPGRADED_PACKAGE_ID = "0xdfb4f1d4e43e0c3ad834dcd369f0d39005c872e118c9dc1c5da9765bb93ee5f3";
1424
+ var upgradeKioskRulesPackageId = (packageId) => normalizeSuiAddress(packageId) === KIOSK_RULES_ORIGINAL_PACKAGE_ID ? KIOSK_RULES_UPGRADED_PACKAGE_ID : packageId;
1425
+
1428
1426
  // src/helpers/kiosk/getRulePackageId.ts
1429
1427
  var getRulePackageId = async ({
1430
1428
  transferPolicies,
@@ -1458,7 +1456,7 @@ var getRulePackageId = async ({
1458
1456
  if (!rulePackageId) {
1459
1457
  rulePackageId = rule?.split("::")?.[0];
1460
1458
  }
1461
- return addHexPrefix(rulePackageId);
1459
+ return upgradeKioskRulesPackageId(addHexPrefix(rulePackageId));
1462
1460
  };
1463
1461
 
1464
1462
  // src/helpers/kiosk/isBluemoveKioskBid.ts
@@ -1695,6 +1693,7 @@ var getTransferPoliciesToResolve = async ({
1695
1693
  if (!rulePackageId) {
1696
1694
  rulePackageId = ruleData?.rule?.split("::")?.[0];
1697
1695
  }
1696
+ rulePackageId = upgradeKioskRulesPackageId(rulePackageId);
1698
1697
  const moduleName = ruleData?.rule?.split("::")?.[1];
1699
1698
  if (originByteRuleModules.includes(moduleName)) {
1700
1699
  throw new Error(
@@ -3582,16 +3581,6 @@ var getCollectionChainState = async (collectionId) => {
3582
3581
  });
3583
3582
  return res?.collections?.[0]?.chain_state;
3584
3583
  };
3585
- var getCollectionChainStateByFtType = async (ftType) => {
3586
- const res = await gqlChainRequest({
3587
- chain: "sui",
3588
- query: fetchCollectionChainStateByFtType,
3589
- variables: {
3590
- ftType
3591
- }
3592
- });
3593
- return res?.collections_by_ft_type?.[0]?.chain_state;
3594
- };
3595
3584
 
3596
3585
  // src/methods/applyFtStrategy/applyFtStrategy.ts
3597
3586
  async function applyFtStrategy({
@@ -3626,12 +3615,105 @@ async function applyFtStrategy({
3626
3615
  return tx;
3627
3616
  }
3628
3617
 
3618
+ // src/methods/applyNftStrategy/applyNftStrategy.ts
3619
+ import { Transaction as Transaction5 } from "@mysten/sui/transactions";
3620
+
3621
+ // src/graphql/queries/fetchCollectionFloorListingForMarket.ts
3622
+ import { gql as gql13 } from "graphql-request";
3623
+ var fetchCollectionFloorListingsForMarket = gql13`
3624
+ query fetchCollectionFloorListingsForMarket(
3625
+ $collectionId: uuid!
3626
+ $marketAddress: String!
3627
+ $totalPrice: numeric
3628
+ ) {
3629
+ listings(
3630
+ where: {
3631
+ collection_id: { _eq: $collectionId }
3632
+ listed: { _eq: true }
3633
+ market_name: { _eq: "tradeport" }
3634
+ seller: { _neq: $marketAddress }
3635
+ nonce: { _like: "1::0x%" }
3636
+ price: { _lte: $totalPrice }
3637
+ }
3638
+ order_by: [{ price: asc_nulls_last }, { block_height: asc }, { tx_index: asc }]
3639
+ ) {
3640
+ id
3641
+ price
3642
+ nft {
3643
+ token_id
3644
+ delegated_owner
3645
+ }
3646
+ }
3647
+ }
3648
+ `;
3649
+
3650
+ // src/methods/applyNftStrategy/applyNftStrategy.ts
3651
+ async function applyTradeportNftStrategy({
3652
+ collectionId,
3653
+ strategyFtType,
3654
+ tx: existingTx
3655
+ }) {
3656
+ const tx = existingTx ?? new Transaction5();
3657
+ const chainState = await getCollectionChainState(collectionId);
3658
+ const nftStrategies = chainState?.nft_strategies ?? {};
3659
+ const nftStrategyKeys = Object.keys(nftStrategies);
3660
+ if (nftStrategyKeys.length === 0) {
3661
+ throw new Error("No NFT strategies found for collection");
3662
+ }
3663
+ strategyFtType = strategyFtType ?? nftStrategyKeys[0];
3664
+ if (!nftStrategyKeys.includes(strategyFtType)) {
3665
+ throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
3666
+ }
3667
+ const transferPolicy = getNativeKioskTransferPolicies(chainState?.transfer_policies ?? [])?.at(0);
3668
+ if (!transferPolicy) {
3669
+ throw new Error("No transfer policy found for collection");
3670
+ }
3671
+ const nftType = chainState?.nft_type;
3672
+ let suiBalance = BigInt(
3673
+ nftStrategies[strategyFtType].sui_balance ?? 0n
3674
+ );
3675
+ const result = await gqlChainRequest({
3676
+ chain: "sui",
3677
+ query: fetchCollectionFloorListingsForMarket,
3678
+ variables: {
3679
+ collectionId,
3680
+ marketAddress: TRADEPORT_NFT_STRATEGY_MANAGER_ID,
3681
+ totalPrice: suiBalance.toString()
3682
+ }
3683
+ });
3684
+ if ((result?.listings?.length ?? 0) === 0) {
3685
+ throw new Error(
3686
+ `No floor listing found for collection with price bellow or equal to ${suiBalance} MIST`
3687
+ );
3688
+ }
3689
+ for (const floorListing of result.listings) {
3690
+ suiBalance -= BigInt(floorListing.price);
3691
+ if (suiBalance < 0n) {
3692
+ break;
3693
+ }
3694
+ tx.moveCall({
3695
+ target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_tradeport_nft_strategy_confirm_request`,
3696
+ typeArguments: [nftType, strategyFtType],
3697
+ arguments: [
3698
+ tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
3699
+ tx.object(nftStrategies[strategyFtType].kiosk_id),
3700
+ tx.object(TRADEPORT_LISTINGS_STORE),
3701
+ tx.object(TRADEPORT_ORDERBOOK_STORE),
3702
+ tx.object(floorListing.nft.delegated_owner),
3703
+ tx.object(floorListing.nft.token_id),
3704
+ tx.object(transferPolicy.id)
3705
+ ]
3706
+ });
3707
+ }
3708
+ return tx;
3709
+ }
3710
+
3629
3711
  // src/methods/buyListings/buyListings.ts
3630
3712
  import { Transaction as Transaction7 } from "@mysten/sui/transactions";
3631
3713
 
3632
3714
  // src/graphql/queries/fetchListingsById.ts
3633
- import { gql as gql13 } from "graphql-request";
3634
- var fetchListingsById = gql13`
3715
+ import { gql as gql14 } from "graphql-request";
3716
+ var fetchListingsById = gql14`
3635
3717
  query fetchListingsById($listingIds: [uuid!]) {
3636
3718
  listings(where: { id: { _in: $listingIds } }) {
3637
3719
  id
@@ -3670,29 +3752,6 @@ var addThirdPartyTxFee = async (tx, price) => {
3670
3752
  );
3671
3753
  };
3672
3754
 
3673
- // src/helpers/deserializeOrCreateTxBlock.ts
3674
- import { Transaction as Transaction5 } from "@mysten/sui/transactions";
3675
- var deserializeOrCreateTxBlock = ({
3676
- existingTx
3677
- }) => {
3678
- if (typeof existingTx === "string") {
3679
- return Transaction5.from(existingTx);
3680
- }
3681
- return existingTx ?? new Transaction5();
3682
- };
3683
-
3684
- // src/helpers/extractSwapResultCoin.ts
3685
- var extractSwapResultCoinFromTxBlock = (txBlock) => {
3686
- if (!txBlock) return void 0;
3687
- const tx = typeof txBlock === "string" ? JSON.parse(txBlock) : txBlock?.getData();
3688
- const commands = tx.commands ?? [];
3689
- const index = commands.findIndex(
3690
- (cmd) => cmd?.MoveCall?.module === "universal_router" && cmd?.MoveCall?.function === "settle"
3691
- );
3692
- if (index === -1) return void 0;
3693
- return { $kind: "Result", Result: index };
3694
- };
3695
-
3696
3755
  // src/helpers/kiosk/preProcessSharedBulkBuyingData.ts
3697
3756
  import { bcs as bcs2 } from "@mysten/sui/bcs";
3698
3757
  import { Transaction as Transaction6 } from "@mysten/sui/transactions";
@@ -3798,8 +3857,8 @@ var preProcessSharedBulkBuyingData = async ({
3798
3857
  import { bcs as bcs3 } from "@mysten/sui/bcs";
3799
3858
 
3800
3859
  // src/graphql/queries/fetchCommissionByListingId.ts
3801
- import { gql as gql14 } from "graphql-request";
3802
- var fetchCommissionByNftContractId = gql14`
3860
+ import { gql as gql15 } from "graphql-request";
3861
+ var fetchCommissionByNftContractId = gql15`
3803
3862
  query fetchCommissionByNftContractId($nftContractId: uuid!) {
3804
3863
  commissions(where: { contract_id: { _eq: $nftContractId } }) {
3805
3864
  is_custodial
@@ -4549,8 +4608,7 @@ var buyListings = async ({
4549
4608
  throw new Error("No listings found");
4550
4609
  }
4551
4610
  const listingsForTracking = [];
4552
- const tx = deserializeOrCreateTxBlock({ existingTx });
4553
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
4611
+ const tx = existingTx ?? new Transaction7();
4554
4612
  const tocenTokenIds = [];
4555
4613
  let tocenNftType = "";
4556
4614
  let tocenTotalPrice = 0;
@@ -4595,7 +4653,7 @@ var buyListings = async ({
4595
4653
  sellerKiosk: listing.nft?.chain_state?.kiosk_id,
4596
4654
  collectionId: listing?.nft?.collection_id,
4597
4655
  nftContractId: listing?.nft?.contract_id,
4598
- coinToSplit: swapResultCoin ? swapResultCoin : coinToSplit,
4656
+ coinToSplit,
4599
4657
  marketFeeDecimalPercent,
4600
4658
  beforeResolveKioskTransferRequest,
4601
4659
  sharedKioskState,
@@ -4644,9 +4702,6 @@ var buyListings = async ({
4644
4702
  });
4645
4703
  }
4646
4704
  sharedKioskState?.kioskTx?.finalize();
4647
- if (swapResultCoin) {
4648
- tx.transferObjects([swapResultCoin], walletAddress);
4649
- }
4650
4705
  if (tocenTokenIds?.length > 0) {
4651
4706
  addTocenBuyTxHandler({
4652
4707
  tx,
@@ -4655,7 +4710,7 @@ var buyListings = async ({
4655
4710
  price: tocenTotalPrice
4656
4711
  });
4657
4712
  }
4658
- return Transaction7.from(tx);
4713
+ return tx;
4659
4714
  };
4660
4715
 
4661
4716
  // src/methods/cancelMultiBid/cancelMultiBid.ts
@@ -4779,8 +4834,8 @@ async function cancelMultiBid({ multiBidId }) {
4779
4834
  import { Transaction as Transaction9 } from "@mysten/sui/transactions";
4780
4835
 
4781
4836
  // src/graphql/queries/fetchAccountKiosks.ts
4782
- import { gql as gql15 } from "graphql-request";
4783
- var fetchAccountKiosks = gql15`
4837
+ import { gql as gql16 } from "graphql-request";
4838
+ var fetchAccountKiosks = gql16`
4784
4839
  query fetchAccountKiosks($accountAddress: String!) {
4785
4840
  kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
4786
4841
  id
@@ -5249,17 +5304,22 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
5249
5304
  return Transaction10.from(tx);
5250
5305
  };
5251
5306
 
5307
+ // src/methods/createMultiBid/createMultiBid.ts
5308
+ import { Transaction as Transaction12 } from "@mysten/sui/transactions";
5309
+
5252
5310
  // src/methods/updateMultiBid/updateMultiBid.ts
5311
+ import { Transaction as Transaction11 } from "@mysten/sui/transactions";
5253
5312
  async function updateMultiBid({
5313
+ walletAddress,
5254
5314
  multiBidId,
5255
5315
  name,
5256
5316
  amount,
5257
5317
  amountToWithdraw,
5258
5318
  tx: existingTx,
5259
- multiBidChainId
5260
- }) {
5261
- const tx = deserializeOrCreateTxBlock({ existingTx });
5262
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
5319
+ multiBidChainId,
5320
+ coinToSplit
5321
+ }, context) {
5322
+ const tx = existingTx ?? new Transaction11();
5263
5323
  if (!multiBidChainId) {
5264
5324
  const { chain_id: chainId, cancelled_at } = (await gqlChainRequest({
5265
5325
  chain: "sui",
@@ -5274,7 +5334,7 @@ async function updateMultiBid({
5274
5334
  }
5275
5335
  multiBidChainId = chainId;
5276
5336
  }
5277
- const [coin] = tx.splitCoins(swapResultCoin ? swapResultCoin : tx.gas, [amount ?? 0n]);
5337
+ const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [amount ?? 0n]);
5278
5338
  tx.moveCall({
5279
5339
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::update_multi_bid`,
5280
5340
  arguments: [
@@ -5295,7 +5355,7 @@ async function createMultiBid({
5295
5355
  amount,
5296
5356
  tx: existingTx
5297
5357
  }) {
5298
- const tx = deserializeOrCreateTxBlock({ existingTx });
5358
+ const tx = existingTx ?? new Transaction12();
5299
5359
  const multiBidChainId = tx.moveCall({
5300
5360
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
5301
5361
  arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.option("string", name)]
@@ -5313,7 +5373,11 @@ async function createMultiBid({
5313
5373
  }
5314
5374
 
5315
5375
  // src/methods/listNfts/listNfts.ts
5316
- import { Transaction as Transaction12 } from "@mysten/sui/transactions";
5376
+ import { Transaction as Transaction13 } from "@mysten/sui/transactions";
5377
+
5378
+ // src/helpers/isExpiredListing.ts
5379
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
5380
+ var isExpiredListing = (listing, walletAddress) => listing.nonce && listing.seller && normalizeSuiAddress2(listing.seller) === normalizeSuiAddress2(walletAddress);
5317
5381
 
5318
5382
  // src/helpers/validateMinFloorPrice.ts
5319
5383
  function validateMinFloorPrice({ transferPolicies, listPrice }) {
@@ -5642,328 +5706,16 @@ async function relistNft({
5642
5706
  }
5643
5707
  }
5644
5708
 
5645
- // src/methods/swapCoins/swapCoins.ts
5646
- import {
5647
- AggregatorQuoter,
5648
- CoinProvider,
5649
- Protocol,
5650
- TradeBuilder
5651
- } from "@flowx-finance/sdk";
5652
- import { coinWithBalance, Transaction as Transaction11 } from "@mysten/sui/transactions";
5653
- import { normalizeStructTag as normalizeStructTag2, normalizeSuiAddress, SUI_TYPE_ARG } from "@mysten/sui/utils";
5654
- import ms from "ms";
5655
-
5656
- // src/utils/pureValues.ts
5657
- var toDecimalValue = (value, decimals) => {
5658
- if (!value || decimals === void 0) return new bigNumberConfig_default(0);
5659
- return new bigNumberConfig_default(value).div(10 ** decimals);
5660
- };
5661
- var toPureValue = (value, decimals) => {
5662
- if (!value || decimals === void 0) return new bigNumberConfig_default(0);
5663
- return new bigNumberConfig_default(new bigNumberConfig_default(value).multipliedBy(10 ** decimals).toFixed(0));
5664
- };
5665
-
5666
- // src/methods/swapCoins/swapCoins.ts
5667
- async function swapCoins({
5668
- walletAddress,
5669
- coinInType,
5670
- coinInAmount,
5671
- coinOutType,
5672
- slippage = 1e3,
5673
- // 0.1%
5674
- ttl = "5m",
5675
- excludeSources = [Protocol.STEAMM, Protocol.BOLT],
5676
- routes,
5677
- commission,
5678
- tx: existingTx
5679
- }, { suiClient, defiRouterUrl }) {
5680
- const inAmount = BigInt(coinInAmount);
5681
- const tx = existingTx ?? new Transaction11();
5682
- coinInType = normalizeStructTag2(coinInType);
5683
- coinOutType = normalizeStructTag2(coinOutType);
5684
- walletAddress = normalizeSuiAddress(walletAddress);
5685
- tx.setSenderIfNotSet(normalizeSuiAddress(walletAddress));
5686
- if (inAmount === 0n) {
5687
- const zeroCoin = tx.moveCall({
5688
- target: "0x2::coin::zero",
5689
- typeArguments: [coinOutType]
5690
- });
5691
- return {
5692
- tx,
5693
- coinOut: zeroCoin
5694
- };
5695
- }
5696
- if (coinInType === coinOutType) {
5697
- const getCoin = coinWithBalance({
5698
- type: coinInType,
5699
- balance: inAmount
5700
- });
5701
- return {
5702
- tx,
5703
- coinOut: getCoin(tx)
5704
- };
5705
- }
5706
- const types = await getAffectedNftAndFtTypes(coinInType, coinOutType);
5707
- const { feeAndReward, amountToSwap } = calculateSwapAmounts(types.length, inAmount);
5708
- if (!routes) {
5709
- routes = (await buildSwapRoutes(
5710
- {
5711
- walletAddress,
5712
- coinInType,
5713
- coinOutType,
5714
- amountToSwap,
5715
- excludeSources,
5716
- commission
5717
- },
5718
- { defiRouterUrl }
5719
- )).routes;
5720
- }
5721
- const tradeBuilder = new TradeBuilder("mainnet", routes);
5722
- if (commission) {
5723
- tradeBuilder.commission(commission);
5724
- }
5725
- const trade = tradeBuilder.sender(walletAddress).slippage(slippage).deadline(Date.now() + ms(ttl)).build();
5726
- const coinOut = await trade.swap({ client: suiClient, tx });
5727
- let suiFeeAndRewardCoin;
5728
- if (coinInType === normalizeStructTag2(SUI_TYPE_ARG)) {
5729
- suiFeeAndRewardCoin = tx.splitCoins(tx.gas, [
5730
- tx.pure.u64(feeAndReward)
5731
- ])[0];
5732
- } else {
5733
- const suiFeeAndRewardRoutes = await buildSwapRoutes(
5734
- {
5735
- walletAddress,
5736
- coinInType,
5737
- coinOutType: SUI_TYPE_ARG,
5738
- amountToSwap: feeAndReward,
5739
- excludeSources
5740
- },
5741
- { defiRouterUrl }
5742
- );
5743
- const suiFeeTradeBuilder = new TradeBuilder("mainnet", suiFeeAndRewardRoutes.routes);
5744
- const suiFeeTrade = suiFeeTradeBuilder.sender(walletAddress).slippage(slippage).deadline(Date.now() + ms(ttl)).build();
5745
- suiFeeAndRewardCoin = await suiFeeTrade.swap({ client: suiClient, tx });
5746
- }
5747
- if (types.length > 0) {
5748
- if (types.length > 2) {
5749
- throw new Error("Unexpected affected types count greater than 2");
5750
- }
5751
- let usedSuiCoin = suiFeeAndRewardCoin;
5752
- if (types.length === 2) {
5753
- const suiFeeAndRewardCoinBalance = tx.moveCall({
5754
- target: "0x2::coin::value",
5755
- typeArguments: [SUI_TYPE_ARG],
5756
- arguments: [suiFeeAndRewardCoin]
5757
- });
5758
- const halfSuiCoinAmount = tx.moveCall({
5759
- target: "0x2::math::divide_and_round_up",
5760
- arguments: [suiFeeAndRewardCoinBalance, tx.pure.u64(2)]
5761
- });
5762
- const [coin] = tx.splitCoins(usedSuiCoin, [halfSuiCoinAmount]);
5763
- usedSuiCoin = coin;
5764
- }
5765
- for (const data of types) {
5766
- const { nftType, ftType, type } = data;
5767
- switch (type) {
5768
- case "liquidNft": {
5769
- tx.moveCall({
5770
- target: `${DexConstants.commission}::commission::pay`,
5771
- arguments: [
5772
- tx.object(DexConstants.commissionManager),
5773
- tx.pure.string("swap"),
5774
- usedSuiCoin,
5775
- tx.pure.option("string", nftType)
5776
- ],
5777
- typeArguments: [SUI_TYPE_ARG]
5778
- });
5779
- break;
5780
- }
5781
- case "nftStrategy": {
5782
- const suiFeeAndRewardCoinBalance = tx.moveCall({
5783
- target: "0x2::coin::value",
5784
- typeArguments: [SUI_TYPE_ARG],
5785
- arguments: [usedSuiCoin]
5786
- });
5787
- const feeAmount = tx.moveCall({
5788
- target: "0x2::math::divide_and_round_up",
5789
- arguments: [suiFeeAndRewardCoinBalance, tx.pure.u64(4)]
5790
- });
5791
- const [feeCoin] = tx.splitCoins(usedSuiCoin, [feeAmount]);
5792
- tx.moveCall({
5793
- target: `${DexConstants.commission}::commission::pay`,
5794
- arguments: [
5795
- tx.object(DexConstants.commissionManager),
5796
- tx.pure.string("swap"),
5797
- feeCoin,
5798
- tx.pure.option("string", void 0)
5799
- ],
5800
- typeArguments: [SUI_TYPE_ARG]
5801
- });
5802
- tx.moveCall({
5803
- target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::reward_strategy`,
5804
- arguments: [
5805
- tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
5806
- usedSuiCoin
5807
- // 3/4 retained coin for reward
5808
- ],
5809
- typeArguments: [nftType, ftType]
5810
- });
5811
- break;
5812
- }
5813
- default: {
5814
- throw new Error(`Unexpected type ${type}`);
5815
- }
5816
- }
5817
- usedSuiCoin = suiFeeAndRewardCoin;
5818
- }
5819
- } else {
5820
- tx.moveCall({
5821
- target: `${DexConstants.commission}::commission::pay`,
5822
- arguments: [
5823
- tx.object(DexConstants.commissionManager),
5824
- tx.pure.string("swap"),
5825
- suiFeeAndRewardCoin,
5826
- tx.pure.option("string", void 0)
5827
- ],
5828
- typeArguments: [SUI_TYPE_ARG]
5829
- });
5830
- }
5831
- return {
5832
- tx,
5833
- coinOut
5834
- };
5835
- }
5836
- async function calculateAmountToSwap({
5837
- coinInType,
5838
- coinOutType,
5839
- coinInAmount
5840
- }) {
5841
- const types = await getAffectedNftAndFtTypes(coinInType, coinOutType);
5842
- const { amountToSwap } = calculateSwapAmounts(types.length, BigInt(coinInAmount));
5843
- return amountToSwap;
5844
- }
5845
- async function calculateSwapInputAmountWithSlippage({
5846
- coinInType,
5847
- coinOutType,
5848
- coinOutAmount,
5849
- slippage = 0
5850
- }) {
5851
- if (coinInType === coinOutType) {
5852
- return new bigNumberConfig_default(coinOutAmount);
5853
- }
5854
- const provider = new CoinProvider("mainnet");
5855
- const coinQueryResult = await provider.getCoins({
5856
- limit: 2,
5857
- coinTypes: [coinInType, coinOutType]
5858
- });
5859
- const coinIn = coinQueryResult?.find(
5860
- (coin) => normalizeStructTag2(coin.coinType) === normalizeStructTag2(coinInType)
5861
- );
5862
- const coinOut = coinQueryResult?.find(
5863
- (coin) => normalizeStructTag2(coin.coinType) === normalizeStructTag2(coinOutType)
5864
- );
5865
- const exchangeRate = new bigNumberConfig_default(coinOut.derivedPriceInUSD ?? 0)?.gt(0) ? new bigNumberConfig_default(coinIn?.derivedPriceInUSD ?? 1)?.div(coinOut?.derivedPriceInUSD ?? 1) : new bigNumberConfig_default(0);
5866
- const amountSell = toDecimalValue(coinOutAmount.toString(), coinOut?.decimals).div(exchangeRate);
5867
- const slippageMultiplier = 1 + parseInt(slippage.toString() || "0", 10) / 1e6;
5868
- const amountWithSlippage = amountSell.times(slippageMultiplier);
5869
- const coinInAmount = toPureValue(amountWithSlippage, coinIn?.decimals);
5870
- return coinInAmount;
5871
- }
5872
- async function buildSwapRoutes(options, { defiRouterUrl }) {
5873
- const aggregatorQuoter = new AggregatorQuoter("mainnet");
5874
- const routes = await aggregatorQuoter.getRoutes({
5875
- tokenIn: options.coinInType,
5876
- tokenOut: options.coinOutType,
5877
- amountIn: options.amountToSwap.toString(),
5878
- commission: options.commission,
5879
- excludeSources: options.excludeSources
5880
- });
5881
- if (defiRouterUrl && options.walletAddress) {
5882
- await makeDefiRouterRequest(`${defiRouterUrl}/start`, {
5883
- walletId: options.walletAddress,
5884
- coinTypeIn: options.coinInType,
5885
- coinTypeOut: options.coinOutType,
5886
- amountIn: options.amountToSwap.toString()
5887
- });
5888
- }
5889
- return routes;
5890
- }
5891
- function calculateSwapAmounts(affectedTypesCount, inAmount) {
5892
- const feeAndReward = affectedTypesCount > 0 ? BigInt(affectedTypesCount) * inAmount / 25n : inAmount / 100n;
5893
- const amountToSwap = inAmount - feeAndReward;
5894
- if (amountToSwap <= 0n) {
5895
- throw new Error("Amount to swap is too small");
5896
- }
5897
- return { feeAndReward, amountToSwap };
5898
- }
5899
- async function getAffectedNftAndFtTypes(coinInType, coinOutType) {
5900
- const normalizedSuiType = normalizeStructTag2(SUI_TYPE_ARG);
5901
- const coinTypes = [coinInType, coinOutType].filter((type) => type !== normalizedSuiType);
5902
- const types = await Promise.all(
5903
- coinTypes.map(async (type) => {
5904
- const chainState = await getCollectionChainStateByFtType(type);
5905
- return chainState ? {
5906
- nftType: chainState.nft_type,
5907
- ftType: type,
5908
- type: chainState.ft_type ? "liquidNft" : "nftStrategy"
5909
- } : void 0;
5910
- })
5911
- );
5912
- return types.filter(Boolean);
5913
- }
5914
- async function makeDefiRouterRequest(url, body, defaultResponse = void 0) {
5915
- try {
5916
- const response = await fetch(url, {
5917
- method: "POST",
5918
- headers: { "Content-Type": "application/json" },
5919
- body: JSON.stringify(body)
5920
- });
5921
- if (!response.ok) {
5922
- console.warn(`DeFi router request failed with status ${response.status}`);
5923
- return defaultResponse;
5924
- }
5925
- if (response.headers.get("Content-Type")?.includes("application/json")) {
5926
- return await response.json();
5927
- }
5928
- return defaultResponse;
5929
- } catch (error) {
5930
- console.warn(`DeFi router request error: ${error.message}`);
5931
- return defaultResponse;
5932
- }
5933
- }
5934
-
5935
5709
  // src/methods/sponsorNftListing/addSponsorNftListingTx.ts
5710
+ import { coinWithBalance } from "@mysten/sui/transactions";
5936
5711
  var addSponsorListingTx = async ({
5937
5712
  tx,
5938
5713
  nftTokenId,
5939
5714
  nftType,
5940
- suiClient,
5941
- walletAddress,
5942
- sponsorOptions,
5943
- defiRouterUrl
5715
+ sponsorOptions
5944
5716
  }) => {
5945
- const coinInAmount = sponsorOptions?.coinInAmount ?? await calculateSwapInputAmountWithSlippage({
5946
- coinInType: sponsorOptions?.coinInType,
5947
- coinOutType: USDC_COIN_TYPE,
5948
- coinOutAmount: new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString(),
5949
- slippage: sponsorOptions?.slippage
5950
- });
5951
- const { coinOut } = await swapCoins(
5952
- {
5953
- walletAddress,
5954
- coinInType: sponsorOptions?.coinInType,
5955
- coinInAmount: coinInAmount.toString(),
5956
- coinOutType: USDC_COIN_TYPE,
5957
- slippage: sponsorOptions?.slippage,
5958
- tx
5959
- },
5960
- { suiClient, defiRouterUrl }
5961
- );
5962
- const [sponsorFeeCoin] = tx.splitCoins(coinOut, [
5963
- tx.pure.u64(
5964
- new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString()
5965
- )
5966
- ]);
5717
+ const totalFee = new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString();
5718
+ const sponsorCoin = sponsorOptions.coinToSplit ? tx.splitCoins(sponsorOptions.coinToSplit, [tx.pure.u64(totalFee)])[0] : coinWithBalance({ type: USDC_COIN_TYPE, balance: BigInt(totalFee) });
5967
5719
  tx.moveCall({
5968
5720
  target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::add_sponsored_listing`,
5969
5721
  arguments: [
@@ -5971,19 +5723,14 @@ var addSponsorListingTx = async ({
5971
5723
  tx.object.clock(),
5972
5724
  tx.pure.id(nftTokenId),
5973
5725
  tx.pure.u64(sponsorOptions?.numOfPeriods),
5974
- tx.object(sponsorFeeCoin)
5726
+ tx.object(sponsorCoin)
5975
5727
  ],
5976
5728
  typeArguments: [nftType]
5977
5729
  });
5978
- tx.transferObjects([coinOut], walletAddress);
5979
5730
  };
5980
5731
 
5981
- // src/helpers/isExpiredListing.ts
5982
- import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
5983
- var isExpiredListing = (listing, walletAddress) => listing.nonce && listing.seller && normalizeSuiAddress2(listing.seller) === normalizeSuiAddress2(walletAddress);
5984
-
5985
5732
  // src/methods/listNfts/listNfts.ts
5986
- var listNfts = async ({ nfts, walletAddress }, context) => {
5733
+ var listNfts = async ({ nfts, walletAddress, tx: existingTx }, context) => {
5987
5734
  const res = await gqlChainRequest({
5988
5735
  chain: "sui",
5989
5736
  query: fetchNftsWithListingsById,
@@ -5993,7 +5740,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5993
5740
  throw new Error("No nfts found");
5994
5741
  }
5995
5742
  const nftsForTracking = [];
5996
- const tx = new Transaction12();
5743
+ const tx = existingTx ?? new Transaction13();
5997
5744
  const sharedKioskState = {
5998
5745
  kioskTx: void 0
5999
5746
  };
@@ -6043,12 +5790,9 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
6043
5790
  if (inputNft?.sponsorOptions?.shouldSponsor) {
6044
5791
  await addSponsorListingTx({
6045
5792
  tx,
6046
- suiClient: context.suiClient,
6047
5793
  nftTokenId: nft?.token_id,
6048
5794
  nftType,
6049
- walletAddress,
6050
- sponsorOptions: inputNft?.sponsorOptions,
6051
- defiRouterUrl: context.defiRouterUrl
5795
+ sponsorOptions: inputNft?.sponsorOptions
6052
5796
  });
6053
5797
  }
6054
5798
  nftsForTracking.push({
@@ -6061,15 +5805,15 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
6061
5805
  });
6062
5806
  }
6063
5807
  sharedKioskState?.kioskTx?.finalize();
6064
- return tx instanceof Transaction12 ? tx : Transaction12.from(tx);
5808
+ return tx;
6065
5809
  };
6066
5810
 
6067
5811
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
6068
- import { Transaction as Transaction13 } from "@mysten/sui/transactions";
5812
+ import { Transaction as Transaction14 } from "@mysten/sui/transactions";
6069
5813
 
6070
5814
  // src/graphql/queries/fetchNftsByKioskId.ts
6071
- import { gql as gql16 } from "graphql-request";
6072
- var fetchNftsByKioskId = gql16`
5815
+ import { gql as gql17 } from "graphql-request";
5816
+ var fetchNftsByKioskId = gql17`
6073
5817
  query fetchNftsByKioskId($jsonFilter: jsonb) {
6074
5818
  nfts(where: { chain_state: { _contains: $jsonFilter } }) {
6075
5819
  id
@@ -6090,7 +5834,7 @@ var fetchNftsByKioskId = gql16`
6090
5834
  }
6091
5835
  }
6092
5836
  `;
6093
- var fetchBulkNftsByKioskId = gql16`
5837
+ var fetchBulkNftsByKioskId = gql17`
6094
5838
  query fetchNftsByKioskId($where: nfts_bool_exp) {
6095
5839
  nfts(where: $where) {
6096
5840
  id
@@ -6113,8 +5857,8 @@ var fetchBulkNftsByKioskId = gql16`
6113
5857
  `;
6114
5858
 
6115
5859
  // src/graphql/queries/fetchTransferPoliciesByType.ts
6116
- import { gql as gql17 } from "graphql-request";
6117
- var fetchTransferPoliciesByType = gql17`
5860
+ import { gql as gql18 } from "graphql-request";
5861
+ var fetchTransferPoliciesByType = gql18`
6118
5862
  query fetchTransferPoliciesByType($type: String!) {
6119
5863
  transfer_policies_by_type(type: $type) {
6120
5864
  id
@@ -6273,7 +6017,7 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
6273
6017
 
6274
6018
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
6275
6019
  async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
6276
- const tx = new Transaction13();
6020
+ const tx = new Transaction14();
6277
6021
  const res = await gqlChainRequest({
6278
6022
  chain: "sui",
6279
6023
  query: fetchKiosksByOwner,
@@ -6439,15 +6183,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
6439
6183
  }
6440
6184
  }
6441
6185
  sharedKioskState?.kioskTx?.finalize();
6442
- return Transaction13.from(tx);
6186
+ return Transaction14.from(tx);
6443
6187
  }
6444
6188
 
6445
6189
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6446
- import { Transaction as Transaction14 } from "@mysten/sui/transactions";
6190
+ import { Transaction as Transaction15 } from "@mysten/sui/transactions";
6447
6191
 
6448
6192
  // src/graphql/queries/fetchCollectionsById.ts
6449
- import { gql as gql18 } from "graphql-request";
6450
- var fetchCollectionsById = gql18`
6193
+ import { gql as gql19 } from "graphql-request";
6194
+ var fetchCollectionsById = gql19`
6451
6195
  query fetchCollectionsById($collectionIds: [uuid!]) {
6452
6196
  collections(where: { id: { _in: $collectionIds } }) {
6453
6197
  id
@@ -6457,7 +6201,7 @@ var fetchCollectionsById = gql18`
6457
6201
  }
6458
6202
  }
6459
6203
  `;
6460
- var fetchCollectionsByIdWithOneNft = gql18`
6204
+ var fetchCollectionsByIdWithOneNft = gql19`
6461
6205
  query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
6462
6206
  collections(where: { id: { _in: $collectionIds } }) {
6463
6207
  id
@@ -6475,7 +6219,7 @@ var fetchCollectionsByIdWithOneNft = gql18`
6475
6219
  }
6476
6220
  }
6477
6221
  `;
6478
- var fetchCollectionsBySlug = gql18`
6222
+ var fetchCollectionsBySlug = gql19`
6479
6223
  query fetchCollectionsBySlug($slug: String!) {
6480
6224
  collections(where: { slug: { _eq: $slug } }) {
6481
6225
  id
@@ -6597,8 +6341,8 @@ function isDynamicCollection(collectionId) {
6597
6341
  }
6598
6342
 
6599
6343
  // src/graphql/queries/fetchCollectionFloorListings.ts
6600
- import { gql as gql19 } from "graphql-request";
6601
- var fetchCollectionFloorListings = gql19`
6344
+ import { gql as gql20 } from "graphql-request";
6345
+ var fetchCollectionFloorListings = gql20`
6602
6346
  query fetchCollectionFloorListings($collectionId: uuid!) {
6603
6347
  listings(
6604
6348
  where: { collection_id: { _eq: $collectionId }, listed: { _eq: true }, nft: {} }
@@ -6657,7 +6401,14 @@ async function addOriginByteCollectionBidTx({
6657
6401
  }
6658
6402
 
6659
6403
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6660
- var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6404
+ var placeCollectionBids = async ({
6405
+ collections,
6406
+ walletAddress,
6407
+ multiBidId,
6408
+ multiBidChainId,
6409
+ tx: existingTx,
6410
+ coinToSplit
6411
+ }, context) => {
6661
6412
  const res = await gqlChainRequest({
6662
6413
  chain: "sui",
6663
6414
  query: fetchCollectionsByIdWithOneNft,
@@ -6667,8 +6418,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6667
6418
  throw new Error("No collection found");
6668
6419
  }
6669
6420
  const collectionsForTracking = [];
6670
- const tx = deserializeOrCreateTxBlock({ existingTx });
6671
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
6421
+ const tx = existingTx ?? new Transaction15();
6672
6422
  for (const collection of res.collections) {
6673
6423
  const nftType = getNftType({
6674
6424
  collectionId: collection?.id,
@@ -6688,7 +6438,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6688
6438
  multiBidId,
6689
6439
  multiBidChainId,
6690
6440
  expireAt: collections?.find((c) => c.id === collection?.id)?.expireAt,
6691
- coinToSplit: swapResultCoin
6441
+ coinToSplit
6692
6442
  };
6693
6443
  const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
6694
6444
  if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
@@ -6715,17 +6465,13 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6715
6465
  bidder: walletAddress
6716
6466
  });
6717
6467
  }
6718
- if (swapResultCoin) {
6719
- tx.transferObjects([swapResultCoin], walletAddress);
6720
- }
6721
- return Transaction14.from(tx);
6468
+ return tx;
6722
6469
  };
6723
6470
 
6724
6471
  // src/methods/placeNftBids/placeNftBids.ts
6725
- import { Transaction as Transaction15 } from "@mysten/sui/transactions";
6726
- var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6727
- const tx = deserializeOrCreateTxBlock({ existingTx });
6728
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
6472
+ import { Transaction as Transaction16 } from "@mysten/sui/transactions";
6473
+ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx, coinToSplit }, context) => {
6474
+ const tx = existingTx ?? new Transaction16();
6729
6475
  const res = await gqlChainRequest({
6730
6476
  chain: "sui",
6731
6477
  query: fetchNftsById,
@@ -6759,7 +6505,7 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6759
6505
  multiBidId,
6760
6506
  multiBidChainId,
6761
6507
  expireAt: bid?.expireAt,
6762
- coinToSplit: swapResultCoin
6508
+ coinToSplit
6763
6509
  };
6764
6510
  await addTradePortPlaceNftBidTxHandler(txData);
6765
6511
  nftsForTracking.push({
@@ -6769,14 +6515,11 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6769
6515
  bidder: walletAddress
6770
6516
  });
6771
6517
  }
6772
- if (swapResultCoin) {
6773
- tx.transferObjects([swapResultCoin], walletAddress);
6774
- }
6775
- return Transaction15.from(tx);
6518
+ return tx;
6776
6519
  };
6777
6520
 
6778
6521
  // src/methods/removeCollectionBids/removeCollectionBids.ts
6779
- import { Transaction as Transaction16 } from "@mysten/sui/transactions";
6522
+ import { Transaction as Transaction17 } from "@mysten/sui/transactions";
6780
6523
 
6781
6524
  // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
6782
6525
  import { normalizeSuiObjectId as normalizeSuiObjectId7 } from "@mysten/sui/utils";
@@ -6884,7 +6627,7 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6884
6627
  throw new Error("No bids found");
6885
6628
  }
6886
6629
  const bidsForTracking = [];
6887
- const tx = existingTx ? Transaction16.from(existingTx) : new Transaction16();
6630
+ const tx = existingTx ? Transaction17.from(existingTx) : new Transaction17();
6888
6631
  for (const bid of res.bids) {
6889
6632
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6890
6633
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6932,11 +6675,11 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6932
6675
  bidder: bid?.bidder
6933
6676
  });
6934
6677
  }
6935
- return Transaction16.from(tx);
6678
+ return Transaction17.from(tx);
6936
6679
  };
6937
6680
 
6938
6681
  // src/methods/removeNftBids/removeNftBids.ts
6939
- import { Transaction as Transaction17 } from "@mysten/sui/transactions";
6682
+ import { Transaction as Transaction18 } from "@mysten/sui/transactions";
6940
6683
  var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6941
6684
  const res = await gqlChainRequest({
6942
6685
  chain: "sui",
@@ -6947,7 +6690,7 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6947
6690
  throw new Error("No bids found");
6948
6691
  }
6949
6692
  const bidsForTracking = [];
6950
- const tx = existingTx ? Transaction17.from(existingTx) : new Transaction17();
6693
+ const tx = existingTx ? Transaction18.from(existingTx) : new Transaction18();
6951
6694
  for (const bid of res.bids) {
6952
6695
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6953
6696
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6992,11 +6735,61 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6992
6735
  bidder: bid?.bidder
6993
6736
  });
6994
6737
  }
6995
- return Transaction17.from(tx);
6738
+ return Transaction18.from(tx);
6739
+ };
6740
+
6741
+ // src/methods/sponsorNftListing/sponsorNftListing.ts
6742
+ import { Transaction as Transaction19 } from "@mysten/sui/transactions";
6743
+
6744
+ // src/graphql/queries/fetchNftCollectionChainState.ts
6745
+ import { gql as gql21 } from "graphql-request";
6746
+ var fetchNftCollectionChainState = gql21`
6747
+ query fetchNftCollectionChainState($nftTokenId: String!) {
6748
+ nfts(where: { token_id: { _eq: $nftTokenId } }) {
6749
+ collection {
6750
+ id
6751
+ chain_state
6752
+ }
6753
+ }
6754
+ }
6755
+ `;
6756
+
6757
+ // src/methods/sponsorNftListing/sponsorNftListing.ts
6758
+ var sponsorNftListing = async ({
6759
+ tx: existingTx,
6760
+ nftTokenId,
6761
+ options
6762
+ }) => {
6763
+ const res = await gqlChainRequest({
6764
+ chain: "sui",
6765
+ query: fetchNftCollectionChainState,
6766
+ variables: { nftTokenId }
6767
+ });
6768
+ if (res?.nfts?.length === 0) {
6769
+ throw new Error(`No nft found with token id ${nftTokenId}`);
6770
+ }
6771
+ const nft = res?.nfts?.[0];
6772
+ const nftType = getNftType({
6773
+ collectionId: nft?.collection?.id,
6774
+ collectionChainState: nft?.collection?.chain_state,
6775
+ nft
6776
+ });
6777
+ const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
6778
+ if (isOriginByteCollection(transferPolicies)) {
6779
+ throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
6780
+ }
6781
+ const tx = existingTx ?? new Transaction19();
6782
+ await addSponsorListingTx({
6783
+ tx,
6784
+ nftTokenId,
6785
+ nftType,
6786
+ sponsorOptions: options
6787
+ });
6788
+ return tx;
6996
6789
  };
6997
6790
 
6998
6791
  // src/methods/transferNfts/transferNfts.ts
6999
- import { Transaction as Transaction18 } from "@mysten/sui/transactions";
6792
+ import { Transaction as Transaction20 } from "@mysten/sui/transactions";
7000
6793
  var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context) => {
7001
6794
  if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
7002
6795
  throw new Error("Cannot transfer to self");
@@ -7014,7 +6807,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
7014
6807
  }
7015
6808
  const nftsForTracking = [];
7016
6809
  const nftsToTransferDirectly = [];
7017
- const tx = new Transaction18();
6810
+ const tx = new Transaction20();
7018
6811
  const sharedKioskState = {
7019
6812
  kioskTx: void 0
7020
6813
  };
@@ -7117,11 +6910,11 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
7117
6910
  context.suiClient
7118
6911
  );
7119
6912
  sharedKioskState?.kioskTx?.finalize();
7120
- return Transaction18.from(tx);
6913
+ return Transaction20.from(tx);
7121
6914
  };
7122
6915
 
7123
6916
  // src/methods/unlistListings/unlistListings.ts
7124
- import { Transaction as Transaction19 } from "@mysten/sui/transactions";
6917
+ import { Transaction as Transaction21 } from "@mysten/sui/transactions";
7125
6918
  var unlistListings = async ({ listingIds, walletAddress }, context) => {
7126
6919
  const res = await gqlChainRequest({
7127
6920
  chain: "sui",
@@ -7132,7 +6925,7 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
7132
6925
  throw new Error("No listings found");
7133
6926
  }
7134
6927
  const listingsForTracking = [];
7135
- const tx = new Transaction19();
6928
+ const tx = new Transaction21();
7136
6929
  const sharedKioskState = {
7137
6930
  kioskTx: void 0
7138
6931
  };
@@ -7201,12 +6994,12 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
7201
6994
  });
7202
6995
  }
7203
6996
  sharedKioskState?.kioskTx?.finalize();
7204
- return Transaction19.from(tx);
6997
+ return Transaction21.from(tx);
7205
6998
  };
7206
6999
 
7207
7000
  // src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts
7208
7001
  import { KioskTransaction as KioskTransaction2 } from "@mysten/kiosk";
7209
- import { Transaction as Transaction20 } from "@mysten/sui/transactions";
7002
+ import { Transaction as Transaction22 } from "@mysten/sui/transactions";
7210
7003
  async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7211
7004
  const res = await gqlChainRequest({
7212
7005
  chain: "sui",
@@ -7226,7 +7019,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7226
7019
  if (kiosksWithProfit.length === 0) {
7227
7020
  throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
7228
7021
  }
7229
- const tx = new Transaction20();
7022
+ const tx = new Transaction22();
7230
7023
  try {
7231
7024
  for (const kiosk of kiosksWithProfit) {
7232
7025
  let kioskTx;
@@ -7272,149 +7065,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7272
7065
  } catch (err) {
7273
7066
  console.log("err", err);
7274
7067
  }
7275
- return Transaction20.from(tx);
7276
- }
7277
-
7278
- // src/methods/sponsorNftListing/sponsorNftListing.ts
7279
- import { Transaction as Transaction21 } from "@mysten/sui/transactions";
7280
-
7281
- // src/graphql/queries/fetchNftCollectionChainState.ts
7282
- import { gql as gql20 } from "graphql-request";
7283
- var fetchNftCollectionChainState = gql20`
7284
- query fetchNftCollectionChainState($nftTokenId: String!) {
7285
- nfts(where: { token_id: { _eq: $nftTokenId } }) {
7286
- collection {
7287
- id
7288
- chain_state
7289
- }
7290
- }
7291
- }
7292
- `;
7293
-
7294
- // src/methods/sponsorNftListing/sponsorNftListing.ts
7295
- var sponsorNftListing = async ({ nftTokenId, walletAddress, options }, context) => {
7296
- const res = await gqlChainRequest({
7297
- chain: "sui",
7298
- query: fetchNftCollectionChainState,
7299
- variables: { nftTokenId }
7300
- });
7301
- if (res?.nfts?.length === 0) {
7302
- throw new Error(`No nft found with token id ${nftTokenId}`);
7303
- }
7304
- const nft = res?.nfts?.[0];
7305
- const nftType = getNftType({
7306
- collectionId: nft?.collection?.id,
7307
- collectionChainState: nft?.collection?.chain_state,
7308
- nft
7309
- });
7310
- const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
7311
- if (isOriginByteCollection(transferPolicies)) {
7312
- throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
7313
- }
7314
- const tx = new Transaction21();
7315
- await addSponsorListingTx({
7316
- tx,
7317
- suiClient: context.suiClient,
7318
- nftTokenId,
7319
- nftType,
7320
- walletAddress,
7321
- sponsorOptions: options,
7322
- defiRouterUrl: context.defiRouterUrl
7323
- });
7324
- return tx instanceof Transaction21 ? tx : Transaction21.from(tx);
7325
- };
7326
-
7327
- // src/methods/applyNftStrategy/applyNftStrategy.ts
7328
- import { Transaction as Transaction22 } from "@mysten/sui/transactions";
7329
-
7330
- // src/graphql/queries/fetchCollectionFloorListingForMarket.ts
7331
- import { gql as gql21 } from "graphql-request";
7332
- var fetchCollectionFloorListingsForMarket = gql21`
7333
- query fetchCollectionFloorListingsForMarket(
7334
- $collectionId: uuid!
7335
- $marketAddress: String!
7336
- $totalPrice: numeric
7337
- ) {
7338
- listings(
7339
- where: {
7340
- collection_id: { _eq: $collectionId }
7341
- listed: { _eq: true }
7342
- market_name: { _eq: "tradeport" }
7343
- seller: { _neq: $marketAddress }
7344
- nonce: { _like: "1::0x%" }
7345
- price: { _lte: $totalPrice }
7346
- }
7347
- order_by: [{ price: asc_nulls_last }, { block_height: asc }, { tx_index: asc }]
7348
- ) {
7349
- id
7350
- price
7351
- nft {
7352
- token_id
7353
- delegated_owner
7354
- }
7355
- }
7356
- }
7357
- `;
7358
-
7359
- // src/methods/applyNftStrategy/applyNftStrategy.ts
7360
- async function applyTradeportNftStrategy({
7361
- collectionId,
7362
- strategyFtType,
7363
- tx: existingTx
7364
- }) {
7365
- const tx = existingTx ?? new Transaction22();
7366
- const chainState = await getCollectionChainState(collectionId);
7367
- const nftStrategies = chainState?.nft_strategies ?? {};
7368
- const nftStrategyKeys = Object.keys(nftStrategies);
7369
- if (nftStrategyKeys.length === 0) {
7370
- throw new Error("No NFT strategies found for collection");
7371
- }
7372
- strategyFtType = strategyFtType ?? nftStrategyKeys[0];
7373
- if (!nftStrategyKeys.includes(strategyFtType)) {
7374
- throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
7375
- }
7376
- const transferPolicy = getNativeKioskTransferPolicies(chainState?.transfer_policies ?? [])?.at(0);
7377
- if (!transferPolicy) {
7378
- throw new Error("No transfer policy found for collection");
7379
- }
7380
- const nftType = chainState?.nft_type;
7381
- let suiBalance = BigInt(
7382
- nftStrategies[strategyFtType].sui_balance ?? 0n
7383
- );
7384
- const result = await gqlChainRequest({
7385
- chain: "sui",
7386
- query: fetchCollectionFloorListingsForMarket,
7387
- variables: {
7388
- collectionId,
7389
- marketAddress: TRADEPORT_NFT_STRATEGY_MANAGER_ID,
7390
- totalPrice: suiBalance.toString()
7391
- }
7392
- });
7393
- if ((result?.listings?.length ?? 0) === 0) {
7394
- throw new Error(
7395
- `No floor listing found for collection with price bellow or equal to ${suiBalance} MIST`
7396
- );
7397
- }
7398
- for (const floorListing of result.listings) {
7399
- suiBalance -= BigInt(floorListing.price);
7400
- if (suiBalance < 0n) {
7401
- break;
7402
- }
7403
- tx.moveCall({
7404
- target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_tradeport_nft_strategy_confirm_request`,
7405
- typeArguments: [nftType, strategyFtType],
7406
- arguments: [
7407
- tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
7408
- tx.object(nftStrategies[strategyFtType].kiosk_id),
7409
- tx.object(TRADEPORT_LISTINGS_STORE),
7410
- tx.object(TRADEPORT_ORDERBOOK_STORE),
7411
- tx.object(floorListing.nft.delegated_owner),
7412
- tx.object(floorListing.nft.token_id),
7413
- tx.object(transferPolicy.id)
7414
- ]
7415
- });
7416
- }
7417
- return tx;
7068
+ return Transaction22.from(tx);
7418
7069
  }
7419
7070
 
7420
7071
  // src/SuiTradingClient.ts
@@ -7424,14 +7075,14 @@ var SuiTradingClient = class {
7424
7075
  apiKey,
7425
7076
  apiVercelId,
7426
7077
  apiUrl,
7427
- defiRouterUrl,
7078
+ tradeportRouterUrl,
7428
7079
  suiNodeUrl,
7429
7080
  graphQLClient
7430
7081
  }) {
7431
7082
  this.allowedApiUsersForUnsharedKiosksMigration = ["tradeport.xyz", "mercato.xyz"];
7432
7083
  this.apiUser = apiUser;
7433
7084
  this.apiKey = apiKey;
7434
- this.defiRouterUrl = defiRouterUrl ?? "https://api.indexer.xyz/router";
7085
+ this.tradeportRouterUrl = tradeportRouterUrl;
7435
7086
  this.suiClient = createSuiClient_default(suiNodeUrl ?? getFullnodeUrl("mainnet"));
7436
7087
  this.kioskClient = createKioskClient_default(this.suiClient);
7437
7088
  if (graphQLClient) {
@@ -7445,31 +7096,31 @@ var SuiTradingClient = class {
7445
7096
  ...apiVercelId && { "x-vercel-id": apiVercelId }
7446
7097
  });
7447
7098
  }
7448
- async buyListings({ listingIds, walletAddress, tx }) {
7099
+ async buyListings(args) {
7449
7100
  const context = {
7450
7101
  apiUser: this.apiUser,
7451
7102
  apiKey: this.apiKey,
7452
- defiRouterUrl: this.defiRouterUrl,
7103
+ tradeportRouterUrl: this.tradeportRouterUrl,
7453
7104
  suiClient: this.suiClient,
7454
7105
  kioskClient: this.kioskClient
7455
7106
  };
7456
- return buyListings({ listingIds, walletAddress, tx }, context);
7107
+ return buyListings(args, context);
7457
7108
  }
7458
- async listNfts({ nfts, walletAddress }) {
7109
+ async listNfts({ nfts, walletAddress, tx }) {
7459
7110
  const context = {
7460
7111
  apiUser: this.apiUser,
7461
7112
  apiKey: this.apiKey,
7462
- defiRouterUrl: this.defiRouterUrl,
7113
+ tradeportRouterUrl: this.tradeportRouterUrl,
7463
7114
  suiClient: this.suiClient,
7464
7115
  kioskClient: this.kioskClient
7465
7116
  };
7466
- return listNfts({ nfts, walletAddress }, context);
7117
+ return listNfts({ nfts, walletAddress, tx }, context);
7467
7118
  }
7468
7119
  async unlistListings({ listingIds, walletAddress }) {
7469
7120
  const context = {
7470
7121
  apiUser: this.apiUser,
7471
7122
  apiKey: this.apiKey,
7472
- defiRouterUrl: this.defiRouterUrl,
7123
+ tradeportRouterUrl: this.tradeportRouterUrl,
7473
7124
  suiClient: this.suiClient,
7474
7125
  kioskClient: this.kioskClient
7475
7126
  };
@@ -7479,7 +7130,7 @@ var SuiTradingClient = class {
7479
7130
  const context = {
7480
7131
  apiUser: this.apiUser,
7481
7132
  apiKey: this.apiKey,
7482
- defiRouterUrl: this.defiRouterUrl,
7133
+ tradeportRouterUrl: this.tradeportRouterUrl,
7483
7134
  suiClient: this.suiClient,
7484
7135
  kioskClient: this.kioskClient
7485
7136
  };
@@ -7488,7 +7139,7 @@ var SuiTradingClient = class {
7488
7139
  async removeNftBids({ bidIds, tx }) {
7489
7140
  const context = {
7490
7141
  apiUser: this.apiUser,
7491
- defiRouterUrl: this.defiRouterUrl,
7142
+ tradeportRouterUrl: this.tradeportRouterUrl,
7492
7143
  apiKey: this.apiKey,
7493
7144
  suiClient: this.suiClient,
7494
7145
  kioskClient: this.kioskClient
@@ -7499,7 +7150,7 @@ var SuiTradingClient = class {
7499
7150
  const context = {
7500
7151
  apiUser: this.apiUser,
7501
7152
  apiKey: this.apiKey,
7502
- defiRouterUrl: this.defiRouterUrl,
7153
+ tradeportRouterUrl: this.tradeportRouterUrl,
7503
7154
  suiClient: this.suiClient,
7504
7155
  kioskClient: this.kioskClient
7505
7156
  };
@@ -7518,7 +7169,7 @@ var SuiTradingClient = class {
7518
7169
  const context = {
7519
7170
  apiUser: this.apiUser,
7520
7171
  apiKey: this.apiKey,
7521
- defiRouterUrl: this.defiRouterUrl,
7172
+ tradeportRouterUrl: this.tradeportRouterUrl,
7522
7173
  suiClient: this.suiClient,
7523
7174
  kioskClient: this.kioskClient
7524
7175
  };
@@ -7544,7 +7195,7 @@ var SuiTradingClient = class {
7544
7195
  const context = {
7545
7196
  apiUser: this.apiUser,
7546
7197
  apiKey: this.apiKey,
7547
- defiRouterUrl: this.defiRouterUrl,
7198
+ tradeportRouterUrl: this.tradeportRouterUrl,
7548
7199
  suiClient: this.suiClient,
7549
7200
  kioskClient: this.kioskClient
7550
7201
  };
@@ -7620,7 +7271,7 @@ var SuiTradingClient = class {
7620
7271
  const context = {
7621
7272
  apiUser: this.apiUser,
7622
7273
  apiKey: this.apiKey,
7623
- defiRouterUrl: this.defiRouterUrl,
7274
+ tradeportRouterUrl: this.tradeportRouterUrl,
7624
7275
  suiClient: this.suiClient,
7625
7276
  kioskClient: this.kioskClient
7626
7277
  };
@@ -7630,7 +7281,7 @@ var SuiTradingClient = class {
7630
7281
  const context = {
7631
7282
  apiUser: this.apiUser,
7632
7283
  apiKey: this.apiKey,
7633
- defiRouterUrl: this.defiRouterUrl,
7284
+ tradeportRouterUrl: this.tradeportRouterUrl,
7634
7285
  suiClient: this.suiClient,
7635
7286
  kioskClient: this.kioskClient
7636
7287
  };
@@ -7640,7 +7291,7 @@ var SuiTradingClient = class {
7640
7291
  const context = {
7641
7292
  apiUser: this.apiUser,
7642
7293
  apiKey: this.apiKey,
7643
- defiRouterUrl: this.defiRouterUrl,
7294
+ tradeportRouterUrl: this.tradeportRouterUrl,
7644
7295
  suiClient: this.suiClient,
7645
7296
  kioskClient: this.kioskClient
7646
7297
  };
@@ -7656,7 +7307,7 @@ var SuiTradingClient = class {
7656
7307
  const context = {
7657
7308
  apiUser: this.apiUser,
7658
7309
  apiKey: this.apiKey,
7659
- defiRouterUrl: this.defiRouterUrl,
7310
+ tradeportRouterUrl: this.tradeportRouterUrl,
7660
7311
  suiClient: this.suiClient,
7661
7312
  kioskClient: this.kioskClient
7662
7313
  };
@@ -7676,7 +7327,7 @@ var SuiTradingClient = class {
7676
7327
  const context = {
7677
7328
  apiUser: this.apiUser,
7678
7329
  apiKey: this.apiKey,
7679
- defiRouterUrl: this.defiRouterUrl,
7330
+ tradeportRouterUrl: this.tradeportRouterUrl,
7680
7331
  suiClient: this.suiClient,
7681
7332
  kioskClient: this.kioskClient
7682
7333
  };
@@ -7689,7 +7340,7 @@ var SuiTradingClient = class {
7689
7340
  const context = {
7690
7341
  apiUser: this.apiUser,
7691
7342
  apiKey: this.apiKey,
7692
- defiRouterUrl: this.defiRouterUrl,
7343
+ tradeportRouterUrl: this.tradeportRouterUrl,
7693
7344
  suiClient: this.suiClient,
7694
7345
  kioskClient: this.kioskClient
7695
7346
  };
@@ -7702,17 +7353,13 @@ var SuiTradingClient = class {
7702
7353
  return cancelMultiBid(args);
7703
7354
  }
7704
7355
  async updateMultiBid(args) {
7705
- return updateMultiBid(args);
7356
+ return updateMultiBid(args, {
7357
+ suiClient: this.suiClient,
7358
+ tradeportRouterUrl: this.tradeportRouterUrl
7359
+ });
7706
7360
  }
7707
7361
  async sponsorNftListing(args) {
7708
- const context = {
7709
- apiUser: this.apiUser,
7710
- apiKey: this.apiKey,
7711
- defiRouterUrl: this.defiRouterUrl,
7712
- suiClient: this.suiClient,
7713
- kioskClient: this.kioskClient
7714
- };
7715
- return sponsorNftListing(args, context);
7362
+ return sponsorNftListing(args);
7716
7363
  }
7717
7364
  async applyFtStrategy(args) {
7718
7365
  return applyFtStrategy(args);
@@ -7720,15 +7367,6 @@ var SuiTradingClient = class {
7720
7367
  async applyTradeportNftStrategy(args) {
7721
7368
  return applyTradeportNftStrategy(args);
7722
7369
  }
7723
- async swapCoins(args) {
7724
- return swapCoins(args, { suiClient: this.suiClient, defiRouterUrl: this.defiRouterUrl });
7725
- }
7726
- async buildSwapRoutes(args) {
7727
- return buildSwapRoutes(args, { defiRouterUrl: this.defiRouterUrl });
7728
- }
7729
- async calculateAmountToSwap(args) {
7730
- return calculateAmountToSwap(args);
7731
- }
7732
7370
  };
7733
7371
  var SuiTradingClient_default = SuiTradingClient;
7734
7372
  export {