@tradeport/sui-trading-sdk 0.4.62 → 0.4.64

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
  ""
@@ -3582,16 +3572,6 @@ var getCollectionChainState = async (collectionId) => {
3582
3572
  });
3583
3573
  return res?.collections?.[0]?.chain_state;
3584
3574
  };
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
3575
 
3596
3576
  // src/methods/applyFtStrategy/applyFtStrategy.ts
3597
3577
  async function applyFtStrategy({
@@ -3626,12 +3606,105 @@ async function applyFtStrategy({
3626
3606
  return tx;
3627
3607
  }
3628
3608
 
3609
+ // src/methods/applyNftStrategy/applyNftStrategy.ts
3610
+ import { Transaction as Transaction5 } from "@mysten/sui/transactions";
3611
+
3612
+ // src/graphql/queries/fetchCollectionFloorListingForMarket.ts
3613
+ import { gql as gql13 } from "graphql-request";
3614
+ var fetchCollectionFloorListingsForMarket = gql13`
3615
+ query fetchCollectionFloorListingsForMarket(
3616
+ $collectionId: uuid!
3617
+ $marketAddress: String!
3618
+ $totalPrice: numeric
3619
+ ) {
3620
+ listings(
3621
+ where: {
3622
+ collection_id: { _eq: $collectionId }
3623
+ listed: { _eq: true }
3624
+ market_name: { _eq: "tradeport" }
3625
+ seller: { _neq: $marketAddress }
3626
+ nonce: { _like: "1::0x%" }
3627
+ price: { _lte: $totalPrice }
3628
+ }
3629
+ order_by: [{ price: asc_nulls_last }, { block_height: asc }, { tx_index: asc }]
3630
+ ) {
3631
+ id
3632
+ price
3633
+ nft {
3634
+ token_id
3635
+ delegated_owner
3636
+ }
3637
+ }
3638
+ }
3639
+ `;
3640
+
3641
+ // src/methods/applyNftStrategy/applyNftStrategy.ts
3642
+ async function applyTradeportNftStrategy({
3643
+ collectionId,
3644
+ strategyFtType,
3645
+ tx: existingTx
3646
+ }) {
3647
+ const tx = existingTx ?? new Transaction5();
3648
+ const chainState = await getCollectionChainState(collectionId);
3649
+ const nftStrategies = chainState?.nft_strategies ?? {};
3650
+ const nftStrategyKeys = Object.keys(nftStrategies);
3651
+ if (nftStrategyKeys.length === 0) {
3652
+ throw new Error("No NFT strategies found for collection");
3653
+ }
3654
+ strategyFtType = strategyFtType ?? nftStrategyKeys[0];
3655
+ if (!nftStrategyKeys.includes(strategyFtType)) {
3656
+ throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
3657
+ }
3658
+ const transferPolicy = getNativeKioskTransferPolicies(chainState?.transfer_policies ?? [])?.at(0);
3659
+ if (!transferPolicy) {
3660
+ throw new Error("No transfer policy found for collection");
3661
+ }
3662
+ const nftType = chainState?.nft_type;
3663
+ let suiBalance = BigInt(
3664
+ nftStrategies[strategyFtType].sui_balance ?? 0n
3665
+ );
3666
+ const result = await gqlChainRequest({
3667
+ chain: "sui",
3668
+ query: fetchCollectionFloorListingsForMarket,
3669
+ variables: {
3670
+ collectionId,
3671
+ marketAddress: TRADEPORT_NFT_STRATEGY_MANAGER_ID,
3672
+ totalPrice: suiBalance.toString()
3673
+ }
3674
+ });
3675
+ if ((result?.listings?.length ?? 0) === 0) {
3676
+ throw new Error(
3677
+ `No floor listing found for collection with price bellow or equal to ${suiBalance} MIST`
3678
+ );
3679
+ }
3680
+ for (const floorListing of result.listings) {
3681
+ suiBalance -= BigInt(floorListing.price);
3682
+ if (suiBalance < 0n) {
3683
+ break;
3684
+ }
3685
+ tx.moveCall({
3686
+ target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_tradeport_nft_strategy_confirm_request`,
3687
+ typeArguments: [nftType, strategyFtType],
3688
+ arguments: [
3689
+ tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
3690
+ tx.object(nftStrategies[strategyFtType].kiosk_id),
3691
+ tx.object(TRADEPORT_LISTINGS_STORE),
3692
+ tx.object(TRADEPORT_ORDERBOOK_STORE),
3693
+ tx.object(floorListing.nft.delegated_owner),
3694
+ tx.object(floorListing.nft.token_id),
3695
+ tx.object(transferPolicy.id)
3696
+ ]
3697
+ });
3698
+ }
3699
+ return tx;
3700
+ }
3701
+
3629
3702
  // src/methods/buyListings/buyListings.ts
3630
3703
  import { Transaction as Transaction7 } from "@mysten/sui/transactions";
3631
3704
 
3632
3705
  // src/graphql/queries/fetchListingsById.ts
3633
- import { gql as gql13 } from "graphql-request";
3634
- var fetchListingsById = gql13`
3706
+ import { gql as gql14 } from "graphql-request";
3707
+ var fetchListingsById = gql14`
3635
3708
  query fetchListingsById($listingIds: [uuid!]) {
3636
3709
  listings(where: { id: { _in: $listingIds } }) {
3637
3710
  id
@@ -3670,29 +3743,6 @@ var addThirdPartyTxFee = async (tx, price) => {
3670
3743
  );
3671
3744
  };
3672
3745
 
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
3746
  // src/helpers/kiosk/preProcessSharedBulkBuyingData.ts
3697
3747
  import { bcs as bcs2 } from "@mysten/sui/bcs";
3698
3748
  import { Transaction as Transaction6 } from "@mysten/sui/transactions";
@@ -3798,8 +3848,8 @@ var preProcessSharedBulkBuyingData = async ({
3798
3848
  import { bcs as bcs3 } from "@mysten/sui/bcs";
3799
3849
 
3800
3850
  // src/graphql/queries/fetchCommissionByListingId.ts
3801
- import { gql as gql14 } from "graphql-request";
3802
- var fetchCommissionByNftContractId = gql14`
3851
+ import { gql as gql15 } from "graphql-request";
3852
+ var fetchCommissionByNftContractId = gql15`
3803
3853
  query fetchCommissionByNftContractId($nftContractId: uuid!) {
3804
3854
  commissions(where: { contract_id: { _eq: $nftContractId } }) {
3805
3855
  is_custodial
@@ -4549,8 +4599,7 @@ var buyListings = async ({
4549
4599
  throw new Error("No listings found");
4550
4600
  }
4551
4601
  const listingsForTracking = [];
4552
- const tx = deserializeOrCreateTxBlock({ existingTx });
4553
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
4602
+ const tx = existingTx ?? new Transaction7();
4554
4603
  const tocenTokenIds = [];
4555
4604
  let tocenNftType = "";
4556
4605
  let tocenTotalPrice = 0;
@@ -4595,7 +4644,7 @@ var buyListings = async ({
4595
4644
  sellerKiosk: listing.nft?.chain_state?.kiosk_id,
4596
4645
  collectionId: listing?.nft?.collection_id,
4597
4646
  nftContractId: listing?.nft?.contract_id,
4598
- coinToSplit: swapResultCoin ? swapResultCoin : coinToSplit,
4647
+ coinToSplit,
4599
4648
  marketFeeDecimalPercent,
4600
4649
  beforeResolveKioskTransferRequest,
4601
4650
  sharedKioskState,
@@ -4644,9 +4693,6 @@ var buyListings = async ({
4644
4693
  });
4645
4694
  }
4646
4695
  sharedKioskState?.kioskTx?.finalize();
4647
- if (swapResultCoin) {
4648
- tx.transferObjects([swapResultCoin], walletAddress);
4649
- }
4650
4696
  if (tocenTokenIds?.length > 0) {
4651
4697
  addTocenBuyTxHandler({
4652
4698
  tx,
@@ -4655,7 +4701,7 @@ var buyListings = async ({
4655
4701
  price: tocenTotalPrice
4656
4702
  });
4657
4703
  }
4658
- return Transaction7.from(tx);
4704
+ return tx;
4659
4705
  };
4660
4706
 
4661
4707
  // src/methods/cancelMultiBid/cancelMultiBid.ts
@@ -4779,8 +4825,8 @@ async function cancelMultiBid({ multiBidId }) {
4779
4825
  import { Transaction as Transaction9 } from "@mysten/sui/transactions";
4780
4826
 
4781
4827
  // src/graphql/queries/fetchAccountKiosks.ts
4782
- import { gql as gql15 } from "graphql-request";
4783
- var fetchAccountKiosks = gql15`
4828
+ import { gql as gql16 } from "graphql-request";
4829
+ var fetchAccountKiosks = gql16`
4784
4830
  query fetchAccountKiosks($accountAddress: String!) {
4785
4831
  kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
4786
4832
  id
@@ -5249,17 +5295,22 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
5249
5295
  return Transaction10.from(tx);
5250
5296
  };
5251
5297
 
5298
+ // src/methods/createMultiBid/createMultiBid.ts
5299
+ import { Transaction as Transaction12 } from "@mysten/sui/transactions";
5300
+
5252
5301
  // src/methods/updateMultiBid/updateMultiBid.ts
5302
+ import { Transaction as Transaction11 } from "@mysten/sui/transactions";
5253
5303
  async function updateMultiBid({
5304
+ walletAddress,
5254
5305
  multiBidId,
5255
5306
  name,
5256
5307
  amount,
5257
5308
  amountToWithdraw,
5258
5309
  tx: existingTx,
5259
- multiBidChainId
5260
- }) {
5261
- const tx = deserializeOrCreateTxBlock({ existingTx });
5262
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
5310
+ multiBidChainId,
5311
+ coinToSplit
5312
+ }, context) {
5313
+ const tx = existingTx ?? new Transaction11();
5263
5314
  if (!multiBidChainId) {
5264
5315
  const { chain_id: chainId, cancelled_at } = (await gqlChainRequest({
5265
5316
  chain: "sui",
@@ -5274,7 +5325,7 @@ async function updateMultiBid({
5274
5325
  }
5275
5326
  multiBidChainId = chainId;
5276
5327
  }
5277
- const [coin] = tx.splitCoins(swapResultCoin ? swapResultCoin : tx.gas, [amount ?? 0n]);
5328
+ const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [amount ?? 0n]);
5278
5329
  tx.moveCall({
5279
5330
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::update_multi_bid`,
5280
5331
  arguments: [
@@ -5295,7 +5346,7 @@ async function createMultiBid({
5295
5346
  amount,
5296
5347
  tx: existingTx
5297
5348
  }) {
5298
- const tx = deserializeOrCreateTxBlock({ existingTx });
5349
+ const tx = existingTx ?? new Transaction12();
5299
5350
  const multiBidChainId = tx.moveCall({
5300
5351
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
5301
5352
  arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.option("string", name)]
@@ -5313,7 +5364,11 @@ async function createMultiBid({
5313
5364
  }
5314
5365
 
5315
5366
  // src/methods/listNfts/listNfts.ts
5316
- import { Transaction as Transaction12 } from "@mysten/sui/transactions";
5367
+ import { Transaction as Transaction13 } from "@mysten/sui/transactions";
5368
+
5369
+ // src/helpers/isExpiredListing.ts
5370
+ import { normalizeSuiAddress } from "@mysten/sui/utils";
5371
+ var isExpiredListing = (listing, walletAddress) => listing.nonce && listing.seller && normalizeSuiAddress(listing.seller) === normalizeSuiAddress(walletAddress);
5317
5372
 
5318
5373
  // src/helpers/validateMinFloorPrice.ts
5319
5374
  function validateMinFloorPrice({ transferPolicies, listPrice }) {
@@ -5642,328 +5697,16 @@ async function relistNft({
5642
5697
  }
5643
5698
  }
5644
5699
 
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
5700
  // src/methods/sponsorNftListing/addSponsorNftListingTx.ts
5701
+ import { coinWithBalance } from "@mysten/sui/transactions";
5936
5702
  var addSponsorListingTx = async ({
5937
5703
  tx,
5938
5704
  nftTokenId,
5939
5705
  nftType,
5940
- suiClient,
5941
- walletAddress,
5942
- sponsorOptions,
5943
- defiRouterUrl
5706
+ sponsorOptions
5944
5707
  }) => {
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
- ]);
5708
+ const totalFee = new bigNumberConfig_default(sponsorOptions?.usdcFeeAmountPerPeriod)?.times(sponsorOptions?.numOfPeriods).toString();
5709
+ const sponsorCoin = sponsorOptions.coinToSplit ? tx.splitCoins(sponsorOptions.coinToSplit, [tx.pure.u64(totalFee)])[0] : coinWithBalance({ type: USDC_COIN_TYPE, balance: BigInt(totalFee) });
5967
5710
  tx.moveCall({
5968
5711
  target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::add_sponsored_listing`,
5969
5712
  arguments: [
@@ -5971,19 +5714,14 @@ var addSponsorListingTx = async ({
5971
5714
  tx.object.clock(),
5972
5715
  tx.pure.id(nftTokenId),
5973
5716
  tx.pure.u64(sponsorOptions?.numOfPeriods),
5974
- tx.object(sponsorFeeCoin)
5717
+ tx.object(sponsorCoin)
5975
5718
  ],
5976
5719
  typeArguments: [nftType]
5977
5720
  });
5978
- tx.transferObjects([coinOut], walletAddress);
5979
5721
  };
5980
5722
 
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
5723
  // src/methods/listNfts/listNfts.ts
5986
- var listNfts = async ({ nfts, walletAddress }, context) => {
5724
+ var listNfts = async ({ nfts, walletAddress, tx: existingTx }, context) => {
5987
5725
  const res = await gqlChainRequest({
5988
5726
  chain: "sui",
5989
5727
  query: fetchNftsWithListingsById,
@@ -5993,7 +5731,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5993
5731
  throw new Error("No nfts found");
5994
5732
  }
5995
5733
  const nftsForTracking = [];
5996
- const tx = new Transaction12();
5734
+ const tx = existingTx ?? new Transaction13();
5997
5735
  const sharedKioskState = {
5998
5736
  kioskTx: void 0
5999
5737
  };
@@ -6043,12 +5781,9 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
6043
5781
  if (inputNft?.sponsorOptions?.shouldSponsor) {
6044
5782
  await addSponsorListingTx({
6045
5783
  tx,
6046
- suiClient: context.suiClient,
6047
5784
  nftTokenId: nft?.token_id,
6048
5785
  nftType,
6049
- walletAddress,
6050
- sponsorOptions: inputNft?.sponsorOptions,
6051
- defiRouterUrl: context.defiRouterUrl
5786
+ sponsorOptions: inputNft?.sponsorOptions
6052
5787
  });
6053
5788
  }
6054
5789
  nftsForTracking.push({
@@ -6061,15 +5796,15 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
6061
5796
  });
6062
5797
  }
6063
5798
  sharedKioskState?.kioskTx?.finalize();
6064
- return tx instanceof Transaction12 ? tx : Transaction12.from(tx);
5799
+ return tx;
6065
5800
  };
6066
5801
 
6067
5802
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
6068
- import { Transaction as Transaction13 } from "@mysten/sui/transactions";
5803
+ import { Transaction as Transaction14 } from "@mysten/sui/transactions";
6069
5804
 
6070
5805
  // src/graphql/queries/fetchNftsByKioskId.ts
6071
- import { gql as gql16 } from "graphql-request";
6072
- var fetchNftsByKioskId = gql16`
5806
+ import { gql as gql17 } from "graphql-request";
5807
+ var fetchNftsByKioskId = gql17`
6073
5808
  query fetchNftsByKioskId($jsonFilter: jsonb) {
6074
5809
  nfts(where: { chain_state: { _contains: $jsonFilter } }) {
6075
5810
  id
@@ -6090,7 +5825,7 @@ var fetchNftsByKioskId = gql16`
6090
5825
  }
6091
5826
  }
6092
5827
  `;
6093
- var fetchBulkNftsByKioskId = gql16`
5828
+ var fetchBulkNftsByKioskId = gql17`
6094
5829
  query fetchNftsByKioskId($where: nfts_bool_exp) {
6095
5830
  nfts(where: $where) {
6096
5831
  id
@@ -6113,8 +5848,8 @@ var fetchBulkNftsByKioskId = gql16`
6113
5848
  `;
6114
5849
 
6115
5850
  // src/graphql/queries/fetchTransferPoliciesByType.ts
6116
- import { gql as gql17 } from "graphql-request";
6117
- var fetchTransferPoliciesByType = gql17`
5851
+ import { gql as gql18 } from "graphql-request";
5852
+ var fetchTransferPoliciesByType = gql18`
6118
5853
  query fetchTransferPoliciesByType($type: String!) {
6119
5854
  transfer_policies_by_type(type: $type) {
6120
5855
  id
@@ -6273,7 +6008,7 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
6273
6008
 
6274
6009
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
6275
6010
  async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
6276
- const tx = new Transaction13();
6011
+ const tx = new Transaction14();
6277
6012
  const res = await gqlChainRequest({
6278
6013
  chain: "sui",
6279
6014
  query: fetchKiosksByOwner,
@@ -6439,15 +6174,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
6439
6174
  }
6440
6175
  }
6441
6176
  sharedKioskState?.kioskTx?.finalize();
6442
- return Transaction13.from(tx);
6177
+ return Transaction14.from(tx);
6443
6178
  }
6444
6179
 
6445
6180
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6446
- import { Transaction as Transaction14 } from "@mysten/sui/transactions";
6181
+ import { Transaction as Transaction15 } from "@mysten/sui/transactions";
6447
6182
 
6448
6183
  // src/graphql/queries/fetchCollectionsById.ts
6449
- import { gql as gql18 } from "graphql-request";
6450
- var fetchCollectionsById = gql18`
6184
+ import { gql as gql19 } from "graphql-request";
6185
+ var fetchCollectionsById = gql19`
6451
6186
  query fetchCollectionsById($collectionIds: [uuid!]) {
6452
6187
  collections(where: { id: { _in: $collectionIds } }) {
6453
6188
  id
@@ -6457,7 +6192,7 @@ var fetchCollectionsById = gql18`
6457
6192
  }
6458
6193
  }
6459
6194
  `;
6460
- var fetchCollectionsByIdWithOneNft = gql18`
6195
+ var fetchCollectionsByIdWithOneNft = gql19`
6461
6196
  query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
6462
6197
  collections(where: { id: { _in: $collectionIds } }) {
6463
6198
  id
@@ -6475,7 +6210,7 @@ var fetchCollectionsByIdWithOneNft = gql18`
6475
6210
  }
6476
6211
  }
6477
6212
  `;
6478
- var fetchCollectionsBySlug = gql18`
6213
+ var fetchCollectionsBySlug = gql19`
6479
6214
  query fetchCollectionsBySlug($slug: String!) {
6480
6215
  collections(where: { slug: { _eq: $slug } }) {
6481
6216
  id
@@ -6597,8 +6332,8 @@ function isDynamicCollection(collectionId) {
6597
6332
  }
6598
6333
 
6599
6334
  // src/graphql/queries/fetchCollectionFloorListings.ts
6600
- import { gql as gql19 } from "graphql-request";
6601
- var fetchCollectionFloorListings = gql19`
6335
+ import { gql as gql20 } from "graphql-request";
6336
+ var fetchCollectionFloorListings = gql20`
6602
6337
  query fetchCollectionFloorListings($collectionId: uuid!) {
6603
6338
  listings(
6604
6339
  where: { collection_id: { _eq: $collectionId }, listed: { _eq: true }, nft: {} }
@@ -6657,7 +6392,14 @@ async function addOriginByteCollectionBidTx({
6657
6392
  }
6658
6393
 
6659
6394
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6660
- var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6395
+ var placeCollectionBids = async ({
6396
+ collections,
6397
+ walletAddress,
6398
+ multiBidId,
6399
+ multiBidChainId,
6400
+ tx: existingTx,
6401
+ coinToSplit
6402
+ }, context) => {
6661
6403
  const res = await gqlChainRequest({
6662
6404
  chain: "sui",
6663
6405
  query: fetchCollectionsByIdWithOneNft,
@@ -6667,8 +6409,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6667
6409
  throw new Error("No collection found");
6668
6410
  }
6669
6411
  const collectionsForTracking = [];
6670
- const tx = deserializeOrCreateTxBlock({ existingTx });
6671
- const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
6412
+ const tx = existingTx ?? new Transaction15();
6672
6413
  for (const collection of res.collections) {
6673
6414
  const nftType = getNftType({
6674
6415
  collectionId: collection?.id,
@@ -6688,7 +6429,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6688
6429
  multiBidId,
6689
6430
  multiBidChainId,
6690
6431
  expireAt: collections?.find((c) => c.id === collection?.id)?.expireAt,
6691
- coinToSplit: swapResultCoin
6432
+ coinToSplit
6692
6433
  };
6693
6434
  const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
6694
6435
  if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
@@ -6715,17 +6456,13 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6715
6456
  bidder: walletAddress
6716
6457
  });
6717
6458
  }
6718
- if (swapResultCoin) {
6719
- tx.transferObjects([swapResultCoin], walletAddress);
6720
- }
6721
- return Transaction14.from(tx);
6459
+ return tx;
6722
6460
  };
6723
6461
 
6724
6462
  // 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);
6463
+ import { Transaction as Transaction16 } from "@mysten/sui/transactions";
6464
+ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx, coinToSplit }, context) => {
6465
+ const tx = existingTx ?? new Transaction16();
6729
6466
  const res = await gqlChainRequest({
6730
6467
  chain: "sui",
6731
6468
  query: fetchNftsById,
@@ -6759,7 +6496,7 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6759
6496
  multiBidId,
6760
6497
  multiBidChainId,
6761
6498
  expireAt: bid?.expireAt,
6762
- coinToSplit: swapResultCoin
6499
+ coinToSplit
6763
6500
  };
6764
6501
  await addTradePortPlaceNftBidTxHandler(txData);
6765
6502
  nftsForTracking.push({
@@ -6769,14 +6506,11 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6769
6506
  bidder: walletAddress
6770
6507
  });
6771
6508
  }
6772
- if (swapResultCoin) {
6773
- tx.transferObjects([swapResultCoin], walletAddress);
6774
- }
6775
- return Transaction15.from(tx);
6509
+ return tx;
6776
6510
  };
6777
6511
 
6778
6512
  // src/methods/removeCollectionBids/removeCollectionBids.ts
6779
- import { Transaction as Transaction16 } from "@mysten/sui/transactions";
6513
+ import { Transaction as Transaction17 } from "@mysten/sui/transactions";
6780
6514
 
6781
6515
  // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
6782
6516
  import { normalizeSuiObjectId as normalizeSuiObjectId7 } from "@mysten/sui/utils";
@@ -6884,7 +6618,7 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6884
6618
  throw new Error("No bids found");
6885
6619
  }
6886
6620
  const bidsForTracking = [];
6887
- const tx = existingTx ? Transaction16.from(existingTx) : new Transaction16();
6621
+ const tx = existingTx ? Transaction17.from(existingTx) : new Transaction17();
6888
6622
  for (const bid of res.bids) {
6889
6623
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6890
6624
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6932,11 +6666,11 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6932
6666
  bidder: bid?.bidder
6933
6667
  });
6934
6668
  }
6935
- return Transaction16.from(tx);
6669
+ return Transaction17.from(tx);
6936
6670
  };
6937
6671
 
6938
6672
  // src/methods/removeNftBids/removeNftBids.ts
6939
- import { Transaction as Transaction17 } from "@mysten/sui/transactions";
6673
+ import { Transaction as Transaction18 } from "@mysten/sui/transactions";
6940
6674
  var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6941
6675
  const res = await gqlChainRequest({
6942
6676
  chain: "sui",
@@ -6947,7 +6681,7 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6947
6681
  throw new Error("No bids found");
6948
6682
  }
6949
6683
  const bidsForTracking = [];
6950
- const tx = existingTx ? Transaction17.from(existingTx) : new Transaction17();
6684
+ const tx = existingTx ? Transaction18.from(existingTx) : new Transaction18();
6951
6685
  for (const bid of res.bids) {
6952
6686
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6953
6687
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6992,11 +6726,61 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6992
6726
  bidder: bid?.bidder
6993
6727
  });
6994
6728
  }
6995
- return Transaction17.from(tx);
6729
+ return Transaction18.from(tx);
6730
+ };
6731
+
6732
+ // src/methods/sponsorNftListing/sponsorNftListing.ts
6733
+ import { Transaction as Transaction19 } from "@mysten/sui/transactions";
6734
+
6735
+ // src/graphql/queries/fetchNftCollectionChainState.ts
6736
+ import { gql as gql21 } from "graphql-request";
6737
+ var fetchNftCollectionChainState = gql21`
6738
+ query fetchNftCollectionChainState($nftTokenId: String!) {
6739
+ nfts(where: { token_id: { _eq: $nftTokenId } }) {
6740
+ collection {
6741
+ id
6742
+ chain_state
6743
+ }
6744
+ }
6745
+ }
6746
+ `;
6747
+
6748
+ // src/methods/sponsorNftListing/sponsorNftListing.ts
6749
+ var sponsorNftListing = async ({
6750
+ tx: existingTx,
6751
+ nftTokenId,
6752
+ options
6753
+ }) => {
6754
+ const res = await gqlChainRequest({
6755
+ chain: "sui",
6756
+ query: fetchNftCollectionChainState,
6757
+ variables: { nftTokenId }
6758
+ });
6759
+ if (res?.nfts?.length === 0) {
6760
+ throw new Error(`No nft found with token id ${nftTokenId}`);
6761
+ }
6762
+ const nft = res?.nfts?.[0];
6763
+ const nftType = getNftType({
6764
+ collectionId: nft?.collection?.id,
6765
+ collectionChainState: nft?.collection?.chain_state,
6766
+ nft
6767
+ });
6768
+ const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
6769
+ if (isOriginByteCollection(transferPolicies)) {
6770
+ throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
6771
+ }
6772
+ const tx = existingTx ?? new Transaction19();
6773
+ await addSponsorListingTx({
6774
+ tx,
6775
+ nftTokenId,
6776
+ nftType,
6777
+ sponsorOptions: options
6778
+ });
6779
+ return tx;
6996
6780
  };
6997
6781
 
6998
6782
  // src/methods/transferNfts/transferNfts.ts
6999
- import { Transaction as Transaction18 } from "@mysten/sui/transactions";
6783
+ import { Transaction as Transaction20 } from "@mysten/sui/transactions";
7000
6784
  var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context) => {
7001
6785
  if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
7002
6786
  throw new Error("Cannot transfer to self");
@@ -7014,7 +6798,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
7014
6798
  }
7015
6799
  const nftsForTracking = [];
7016
6800
  const nftsToTransferDirectly = [];
7017
- const tx = new Transaction18();
6801
+ const tx = new Transaction20();
7018
6802
  const sharedKioskState = {
7019
6803
  kioskTx: void 0
7020
6804
  };
@@ -7117,11 +6901,11 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
7117
6901
  context.suiClient
7118
6902
  );
7119
6903
  sharedKioskState?.kioskTx?.finalize();
7120
- return Transaction18.from(tx);
6904
+ return Transaction20.from(tx);
7121
6905
  };
7122
6906
 
7123
6907
  // src/methods/unlistListings/unlistListings.ts
7124
- import { Transaction as Transaction19 } from "@mysten/sui/transactions";
6908
+ import { Transaction as Transaction21 } from "@mysten/sui/transactions";
7125
6909
  var unlistListings = async ({ listingIds, walletAddress }, context) => {
7126
6910
  const res = await gqlChainRequest({
7127
6911
  chain: "sui",
@@ -7132,7 +6916,7 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
7132
6916
  throw new Error("No listings found");
7133
6917
  }
7134
6918
  const listingsForTracking = [];
7135
- const tx = new Transaction19();
6919
+ const tx = new Transaction21();
7136
6920
  const sharedKioskState = {
7137
6921
  kioskTx: void 0
7138
6922
  };
@@ -7201,12 +6985,12 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
7201
6985
  });
7202
6986
  }
7203
6987
  sharedKioskState?.kioskTx?.finalize();
7204
- return Transaction19.from(tx);
6988
+ return Transaction21.from(tx);
7205
6989
  };
7206
6990
 
7207
6991
  // src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts
7208
6992
  import { KioskTransaction as KioskTransaction2 } from "@mysten/kiosk";
7209
- import { Transaction as Transaction20 } from "@mysten/sui/transactions";
6993
+ import { Transaction as Transaction22 } from "@mysten/sui/transactions";
7210
6994
  async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7211
6995
  const res = await gqlChainRequest({
7212
6996
  chain: "sui",
@@ -7226,7 +7010,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7226
7010
  if (kiosksWithProfit.length === 0) {
7227
7011
  throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
7228
7012
  }
7229
- const tx = new Transaction20();
7013
+ const tx = new Transaction22();
7230
7014
  try {
7231
7015
  for (const kiosk of kiosksWithProfit) {
7232
7016
  let kioskTx;
@@ -7272,149 +7056,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7272
7056
  } catch (err) {
7273
7057
  console.log("err", err);
7274
7058
  }
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;
7059
+ return Transaction22.from(tx);
7418
7060
  }
7419
7061
 
7420
7062
  // src/SuiTradingClient.ts
@@ -7424,14 +7066,14 @@ var SuiTradingClient = class {
7424
7066
  apiKey,
7425
7067
  apiVercelId,
7426
7068
  apiUrl,
7427
- defiRouterUrl,
7069
+ tradeportRouterUrl,
7428
7070
  suiNodeUrl,
7429
7071
  graphQLClient
7430
7072
  }) {
7431
7073
  this.allowedApiUsersForUnsharedKiosksMigration = ["tradeport.xyz", "mercato.xyz"];
7432
7074
  this.apiUser = apiUser;
7433
7075
  this.apiKey = apiKey;
7434
- this.defiRouterUrl = defiRouterUrl ?? "https://api.indexer.xyz/router";
7076
+ this.tradeportRouterUrl = tradeportRouterUrl;
7435
7077
  this.suiClient = createSuiClient_default(suiNodeUrl ?? getFullnodeUrl("mainnet"));
7436
7078
  this.kioskClient = createKioskClient_default(this.suiClient);
7437
7079
  if (graphQLClient) {
@@ -7445,31 +7087,31 @@ var SuiTradingClient = class {
7445
7087
  ...apiVercelId && { "x-vercel-id": apiVercelId }
7446
7088
  });
7447
7089
  }
7448
- async buyListings({ listingIds, walletAddress, tx }) {
7090
+ async buyListings(args) {
7449
7091
  const context = {
7450
7092
  apiUser: this.apiUser,
7451
7093
  apiKey: this.apiKey,
7452
- defiRouterUrl: this.defiRouterUrl,
7094
+ tradeportRouterUrl: this.tradeportRouterUrl,
7453
7095
  suiClient: this.suiClient,
7454
7096
  kioskClient: this.kioskClient
7455
7097
  };
7456
- return buyListings({ listingIds, walletAddress, tx }, context);
7098
+ return buyListings(args, context);
7457
7099
  }
7458
- async listNfts({ nfts, walletAddress }) {
7100
+ async listNfts({ nfts, walletAddress, tx }) {
7459
7101
  const context = {
7460
7102
  apiUser: this.apiUser,
7461
7103
  apiKey: this.apiKey,
7462
- defiRouterUrl: this.defiRouterUrl,
7104
+ tradeportRouterUrl: this.tradeportRouterUrl,
7463
7105
  suiClient: this.suiClient,
7464
7106
  kioskClient: this.kioskClient
7465
7107
  };
7466
- return listNfts({ nfts, walletAddress }, context);
7108
+ return listNfts({ nfts, walletAddress, tx }, context);
7467
7109
  }
7468
7110
  async unlistListings({ listingIds, walletAddress }) {
7469
7111
  const context = {
7470
7112
  apiUser: this.apiUser,
7471
7113
  apiKey: this.apiKey,
7472
- defiRouterUrl: this.defiRouterUrl,
7114
+ tradeportRouterUrl: this.tradeportRouterUrl,
7473
7115
  suiClient: this.suiClient,
7474
7116
  kioskClient: this.kioskClient
7475
7117
  };
@@ -7479,7 +7121,7 @@ var SuiTradingClient = class {
7479
7121
  const context = {
7480
7122
  apiUser: this.apiUser,
7481
7123
  apiKey: this.apiKey,
7482
- defiRouterUrl: this.defiRouterUrl,
7124
+ tradeportRouterUrl: this.tradeportRouterUrl,
7483
7125
  suiClient: this.suiClient,
7484
7126
  kioskClient: this.kioskClient
7485
7127
  };
@@ -7488,7 +7130,7 @@ var SuiTradingClient = class {
7488
7130
  async removeNftBids({ bidIds, tx }) {
7489
7131
  const context = {
7490
7132
  apiUser: this.apiUser,
7491
- defiRouterUrl: this.defiRouterUrl,
7133
+ tradeportRouterUrl: this.tradeportRouterUrl,
7492
7134
  apiKey: this.apiKey,
7493
7135
  suiClient: this.suiClient,
7494
7136
  kioskClient: this.kioskClient
@@ -7499,7 +7141,7 @@ var SuiTradingClient = class {
7499
7141
  const context = {
7500
7142
  apiUser: this.apiUser,
7501
7143
  apiKey: this.apiKey,
7502
- defiRouterUrl: this.defiRouterUrl,
7144
+ tradeportRouterUrl: this.tradeportRouterUrl,
7503
7145
  suiClient: this.suiClient,
7504
7146
  kioskClient: this.kioskClient
7505
7147
  };
@@ -7518,7 +7160,7 @@ var SuiTradingClient = class {
7518
7160
  const context = {
7519
7161
  apiUser: this.apiUser,
7520
7162
  apiKey: this.apiKey,
7521
- defiRouterUrl: this.defiRouterUrl,
7163
+ tradeportRouterUrl: this.tradeportRouterUrl,
7522
7164
  suiClient: this.suiClient,
7523
7165
  kioskClient: this.kioskClient
7524
7166
  };
@@ -7544,7 +7186,7 @@ var SuiTradingClient = class {
7544
7186
  const context = {
7545
7187
  apiUser: this.apiUser,
7546
7188
  apiKey: this.apiKey,
7547
- defiRouterUrl: this.defiRouterUrl,
7189
+ tradeportRouterUrl: this.tradeportRouterUrl,
7548
7190
  suiClient: this.suiClient,
7549
7191
  kioskClient: this.kioskClient
7550
7192
  };
@@ -7620,7 +7262,7 @@ var SuiTradingClient = class {
7620
7262
  const context = {
7621
7263
  apiUser: this.apiUser,
7622
7264
  apiKey: this.apiKey,
7623
- defiRouterUrl: this.defiRouterUrl,
7265
+ tradeportRouterUrl: this.tradeportRouterUrl,
7624
7266
  suiClient: this.suiClient,
7625
7267
  kioskClient: this.kioskClient
7626
7268
  };
@@ -7630,7 +7272,7 @@ var SuiTradingClient = class {
7630
7272
  const context = {
7631
7273
  apiUser: this.apiUser,
7632
7274
  apiKey: this.apiKey,
7633
- defiRouterUrl: this.defiRouterUrl,
7275
+ tradeportRouterUrl: this.tradeportRouterUrl,
7634
7276
  suiClient: this.suiClient,
7635
7277
  kioskClient: this.kioskClient
7636
7278
  };
@@ -7640,7 +7282,7 @@ var SuiTradingClient = class {
7640
7282
  const context = {
7641
7283
  apiUser: this.apiUser,
7642
7284
  apiKey: this.apiKey,
7643
- defiRouterUrl: this.defiRouterUrl,
7285
+ tradeportRouterUrl: this.tradeportRouterUrl,
7644
7286
  suiClient: this.suiClient,
7645
7287
  kioskClient: this.kioskClient
7646
7288
  };
@@ -7656,7 +7298,7 @@ var SuiTradingClient = class {
7656
7298
  const context = {
7657
7299
  apiUser: this.apiUser,
7658
7300
  apiKey: this.apiKey,
7659
- defiRouterUrl: this.defiRouterUrl,
7301
+ tradeportRouterUrl: this.tradeportRouterUrl,
7660
7302
  suiClient: this.suiClient,
7661
7303
  kioskClient: this.kioskClient
7662
7304
  };
@@ -7676,7 +7318,7 @@ var SuiTradingClient = class {
7676
7318
  const context = {
7677
7319
  apiUser: this.apiUser,
7678
7320
  apiKey: this.apiKey,
7679
- defiRouterUrl: this.defiRouterUrl,
7321
+ tradeportRouterUrl: this.tradeportRouterUrl,
7680
7322
  suiClient: this.suiClient,
7681
7323
  kioskClient: this.kioskClient
7682
7324
  };
@@ -7689,7 +7331,7 @@ var SuiTradingClient = class {
7689
7331
  const context = {
7690
7332
  apiUser: this.apiUser,
7691
7333
  apiKey: this.apiKey,
7692
- defiRouterUrl: this.defiRouterUrl,
7334
+ tradeportRouterUrl: this.tradeportRouterUrl,
7693
7335
  suiClient: this.suiClient,
7694
7336
  kioskClient: this.kioskClient
7695
7337
  };
@@ -7702,17 +7344,13 @@ var SuiTradingClient = class {
7702
7344
  return cancelMultiBid(args);
7703
7345
  }
7704
7346
  async updateMultiBid(args) {
7705
- return updateMultiBid(args);
7347
+ return updateMultiBid(args, {
7348
+ suiClient: this.suiClient,
7349
+ tradeportRouterUrl: this.tradeportRouterUrl
7350
+ });
7706
7351
  }
7707
7352
  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);
7353
+ return sponsorNftListing(args);
7716
7354
  }
7717
7355
  async applyFtStrategy(args) {
7718
7356
  return applyFtStrategy(args);
@@ -7720,15 +7358,6 @@ var SuiTradingClient = class {
7720
7358
  async applyTradeportNftStrategy(args) {
7721
7359
  return applyTradeportNftStrategy(args);
7722
7360
  }
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
7361
  };
7733
7362
  var SuiTradingClient_default = SuiTradingClient;
7734
7363
  export {