@tradeport/sui-trading-sdk 0.4.39 → 0.4.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/index.d.mts +14 -0
  2. package/dist/index.d.ts +14 -0
  3. package/dist/index.js +534 -134
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +518 -125
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +6 -2
  8. package/src/SuiTradingClient.ts +15 -0
  9. package/src/bigNumberConfig.ts +10 -0
  10. package/src/constants.ts +17 -1
  11. package/src/graphql/queries/fetchNftCollectionChainState.ts +12 -0
  12. package/src/helpers/calculateRoyaltyFee.ts +12 -7
  13. package/src/helpers/isExpiredListing.ts +9 -0
  14. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +9 -8
  15. package/src/helpers/swap.ts +197 -0
  16. package/src/helpers/validateMinFloorPrice.ts +22 -0
  17. package/src/methods/buyListings/addBuyListingTxs.ts +111 -5
  18. package/src/methods/buyLocks/buyLocks.ts +2 -2
  19. package/src/methods/createLongLocks/createLongLocks.ts +2 -2
  20. package/src/methods/createShortLocks/createShortLocks.ts +3 -3
  21. package/src/methods/listNfts/addListTxs.ts +17 -37
  22. package/src/methods/listNfts/addRelistTxs.ts +26 -17
  23. package/src/methods/listNfts/listNfts.ts +27 -16
  24. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +1 -1
  25. package/src/methods/relistNft/relistNft.ts +19 -28
  26. package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +71 -0
  27. package/src/methods/sponsorNftListing/sponsorNftListing.ts +62 -0
  28. package/src/methods/unlistListings/addUnlistListingTxs.ts +68 -5
  29. package/src/methods/unlistListings/unlistListings.ts +2 -6
  30. package/src/tests/SuiWallet.ts +4 -1
  31. package/src/utils/printTxBlockTxs.ts +7 -1
  32. package/src/utils/pureValues.ts +13 -0
package/dist/index.mjs CHANGED
@@ -113,8 +113,11 @@ var MYSTEN_TRANFER_POLICY_RULES_PACKAGE_ID = "0x434b5bd8f6a7b05fede0ff46c6e511d7
113
113
  var TRADEPORT_BENEFICIARY_ADDRESS = "0xbca3b5c01c8d1a93aed3a036feff45145518292dd3c1db1d67cc99a699a7b517";
114
114
  var TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT = 0.03;
115
115
  var TRADEPORT_THIRD_PARTY_FEE_DECIMAL_PERCENT = 5e-3;
116
+ var TRADEPORT_LISTINGS_DEFAULT_COMMISSION_BPS = 300;
116
117
  var TRADEPORT_LISTING_STORE = "0x47cba0b6309a12ce39f9306e28b899ed4b3698bce4f4911fd0c58ff2329a2ff6";
117
118
  var TRADEPORT_BIDDING_STORE = "0x3d3b0c6e616fdc1a45b2b73d022bc085448e78bd729d28081c7a340abb33cba1";
119
+ var TRADEPORT_LISTINGS_PACKAGE = "0x318d9bbbbc65be1fe53f0de1af9fd93dcbcb8d57146aba9754cf7a3b55880f5c";
120
+ var TRADEPORT_LISTINGS_STORE = "0x90626186ce022b50109628f44ef09e183e55961972d9b1b79de53558103161ef";
118
121
  var TRADEPORT_KIOSK_LISTING_STORE = "0xbff3161b047fb8b727883838c09b08afa9e0dd0f5488bde9e99e80643da9b9e0";
119
122
  var TRADEPORT_KIOSK_TRANSFERS_STORE = "0xe0f61b6915d3fd4ec8bbe4618514e2152a82841605bfa00cde22ace434153a1b";
120
123
  var TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK = "0xa677dab85a93bd8d6845b6cc7914f3bbb334fef7fbcbe0e997b5f75b5922d106";
@@ -126,6 +129,18 @@ var TRADEPORT_PRICE_LOCK_STORE = "0x4b705de46a79b29276baf45009bc7d6f70cc0f1407f0
126
129
  var TRADEPORT_MULTI_BID_PACKAGE = "0xd1dedf8379f1781469e95cb92eed7e155c8ad141c8528c3855f59ce2a5d9d659";
127
130
  var TRADEPORT_MULTI_BID_PACKAGE_ORIGINAL = "0x53134eb544c5a0b5085e99efaf7eab13b28ad123de35d61f941f8c8c40b72033";
128
131
  var TRADEPORT_MULTI_BID_STORE = "0x8aaed7e884343fb8b222c721d02eaac2c6ae2abbb4ddcdf16cb55cf8754ee860";
132
+ var DexConstants = {
133
+ commission: "0x24f5f2258ef80c0a3243088199faeb95ad50516ca1517dbd93be398d759057bb",
134
+ commissionManager: "0xd19a03d4ec3d12b0ce407b54eb676cc0f8e1403621deda77d9677bfcb9d738c1",
135
+ poolsToExclude: [
136
+ "0x3addbbc82866c0bbd93e51b6e2d75c0a4faaf270cc0e281d8f4de5df48bebfa4",
137
+ "0x19d614f421046cae90f5a3a976816063478f648087a12adc74e90ebd54dfaf19",
138
+ "0x514c74e28a9720366abc4a65a5688f47c72e784dbf035844d3f59059bfaed056",
139
+ "0x0854de4e9d64716b757b2f6f22258467f59cc1b4bc0cc64c70086549faaddedf"
140
+ ]
141
+ };
142
+ var TRADEPORT_SPONSOR_USDC_FEE_AMOUNT_PER_PERIOD = 2e7;
143
+ var USDC_COIN_TYPE = "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC";
129
144
  var COLLECTION_IDS_WITH_ZERO_COMMISSION = [
130
145
  ""
131
146
  ];
@@ -2579,14 +2594,14 @@ var isNonKioskListing = async ({
2579
2594
  };
2580
2595
 
2581
2596
  // src/methods/unlistListings/addUnlistListingTxs.ts
2582
- function addTradePortUnlistTx({ tx, listingNonce, nftType }) {
2597
+ function addLegacyTradePortUnlistTx({ tx, listingNonce, nftType }) {
2583
2598
  tx.moveCall({
2584
2599
  target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::unlist",
2585
2600
  arguments: [tx.object(TRADEPORT_LISTING_STORE), tx.pure.address(listingNonce)],
2586
2601
  typeArguments: [nftType]
2587
2602
  });
2588
2603
  }
2589
- async function addTradePortKioskUnlistTx({
2604
+ async function addLegacyTradePortKioskUnlistTx({
2590
2605
  tx,
2591
2606
  kioskTx,
2592
2607
  nftTokenId,
@@ -2603,6 +2618,30 @@ async function addTradePortKioskUnlistTx({
2603
2618
  typeArguments: [nftType]
2604
2619
  });
2605
2620
  }
2621
+ function addTradePortUnlistTx({ tx, nftTokenId, nftType }) {
2622
+ tx.moveCall({
2623
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::cancel_listing_without_transfer_policy`,
2624
+ arguments: [tx.object(TRADEPORT_LISTINGS_STORE), tx.pure.id(nftTokenId)],
2625
+ typeArguments: [nftType]
2626
+ });
2627
+ }
2628
+ async function addKioskTradePortUnlistTx({
2629
+ tx,
2630
+ kioskTx,
2631
+ nftTokenId,
2632
+ nftType
2633
+ }) {
2634
+ tx.moveCall({
2635
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::cancel_listing_with_transfer_policy`,
2636
+ arguments: [
2637
+ tx.object(TRADEPORT_LISTINGS_STORE),
2638
+ tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
2639
+ tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
2640
+ tx.pure.id(nftTokenId)
2641
+ ],
2642
+ typeArguments: [nftType]
2643
+ });
2644
+ }
2606
2645
  function addOriginByteUnlistTx({
2607
2646
  tx,
2608
2647
  sharedObjects,
@@ -2707,10 +2746,36 @@ async function addTradePortUnlistTxHandler(txData) {
2707
2746
  addOriginByteUnlistTx({ ...txData, sharedObjects });
2708
2747
  return;
2709
2748
  }
2710
- if (txData?.listingNonce && await isNonKioskListing({ suiClient: txData?.suiClient, listingNonce: txData?.listingNonce })) {
2749
+ if (txData?.listingNonce?.startsWith("0::")) {
2711
2750
  addTradePortUnlistTx(txData);
2712
2751
  return;
2713
2752
  }
2753
+ if (txData?.listingNonce?.startsWith("1::")) {
2754
+ return kioskTxWrapper({
2755
+ tx: txData?.tx,
2756
+ kioskClient: txData?.kioskClient,
2757
+ kioskOwner: txData?.seller,
2758
+ kiosk: txData?.sellerKiosk,
2759
+ shouldAllowNftUnsharedKiosk: true,
2760
+ sharedKioskState: txData?.sharedKioskState,
2761
+ shouldUseSharedKioskTx: false,
2762
+ async runCommands(kioskTx) {
2763
+ await addKioskTradePortUnlistTx({
2764
+ ...txData,
2765
+ kioskTx
2766
+ });
2767
+ }
2768
+ });
2769
+ }
2770
+ if (txData?.listingNonce && await isNonKioskListing({ suiClient: txData?.suiClient, listingNonce: txData?.listingNonce })) {
2771
+ if (txData?.isPartOfRelist) {
2772
+ throw new Error(
2773
+ "Cannot relist this non kiosk NFT in one transaction from legacy contract. You must unlist and list again"
2774
+ );
2775
+ }
2776
+ addLegacyTradePortUnlistTx(txData);
2777
+ return;
2778
+ }
2714
2779
  if (txData?.sellerKiosk) {
2715
2780
  return kioskTxWrapper({
2716
2781
  tx: txData?.tx,
@@ -2721,7 +2786,7 @@ async function addTradePortUnlistTxHandler(txData) {
2721
2786
  sharedKioskState: txData?.sharedKioskState,
2722
2787
  shouldUseSharedKioskTx: false,
2723
2788
  async runCommands(kioskTx) {
2724
- await addTradePortKioskUnlistTx({
2789
+ await addLegacyTradePortKioskUnlistTx({
2725
2790
  ...txData,
2726
2791
  kioskTx
2727
2792
  });
@@ -2744,7 +2809,7 @@ async function addTradePortUnlistTxHandler(txData) {
2744
2809
  }
2745
2810
  });
2746
2811
  }
2747
- addTradePortUnlistTx(txData);
2812
+ addLegacyTradePortUnlistTx(txData);
2748
2813
  }
2749
2814
  async function addHyperspaceUnlistTxHandler(txData) {
2750
2815
  if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
@@ -3368,17 +3433,26 @@ function calculatePremium(price) {
3368
3433
  return BigInt(price) * PREMIUM_NOMINATOR / 10000n;
3369
3434
  }
3370
3435
 
3436
+ // src/bigNumberConfig.ts
3437
+ import { BigNumber as BigNumber2 } from "bignumber.js";
3438
+ BigNumber2.set({
3439
+ POW_PRECISION: 64
3440
+ });
3441
+ var ZERO = new BigNumber2(0);
3442
+ var ONE = new BigNumber2(1);
3443
+ var bigNumberConfig_default = BigNumber2;
3444
+
3371
3445
  // src/helpers/calculateRoyaltyFee.ts
3372
3446
  function calculateRoyaltyFee(transferPolicyRules, price) {
3373
3447
  const royaltyRule = transferPolicyRules?.filter(
3374
- (rule) => rule.type === "royalty_rule"
3448
+ (rule) => rule.type === "royalty_rule" || rule.type === "kiosk_royalty_rule"
3375
3449
  )?.[0];
3376
3450
  if (!royaltyRule || !royaltyRule.amount_bp && !royaltyRule.min_amount) {
3377
- return 0n;
3451
+ return ZERO;
3378
3452
  }
3379
- const royaltyFee = royaltyRule.amount_bp ? BigInt(royaltyRule.amount_bp) * price / 10000n : 0n;
3380
- if (royaltyRule.min_amount && BigInt(royaltyRule.min_amount) > royaltyFee) {
3381
- return BigInt(royaltyRule.min_amount);
3453
+ const royaltyFee = royaltyRule.amount_bp ? new bigNumberConfig_default(royaltyRule.amount_bp).times(price).div(1e4) : ZERO;
3454
+ if (royaltyRule.min_amount && new bigNumberConfig_default(royaltyRule.min_amount).isGreaterThan(royaltyFee)) {
3455
+ return new bigNumberConfig_default(royaltyRule.min_amount);
3382
3456
  }
3383
3457
  return royaltyFee;
3384
3458
  }
@@ -3518,7 +3592,7 @@ async function buyLocks({ lockIds, transaction }, context) {
3518
3592
  collectionId: lock.collection_id
3519
3593
  })
3520
3594
  );
3521
- const royalty = calculateRoyaltyFee(transferPolicy.rules, BigInt(lock.maker_price));
3595
+ const royalty = calculateRoyaltyFee(transferPolicy.rules, new BigNumber(lock.maker_price));
3522
3596
  const premiumAmount = calculatePremium(lock.maker_price);
3523
3597
  const [premium] = tx.splitCoins(tx.gas, [premiumAmount]);
3524
3598
  tx.moveCall({
@@ -3530,7 +3604,7 @@ async function buyLocks({ lockIds, transaction }, context) {
3530
3604
  tx.pure.id(lock.lock_id),
3531
3605
  tx.pure.u64(lock.maker_price),
3532
3606
  tx.pure.u64(marketplaceFee),
3533
- tx.pure.u64(royalty),
3607
+ tx.pure.u64(royalty.toNumber()),
3534
3608
  tx.pure.u64(lock.expire_in),
3535
3609
  premium
3536
3610
  ]
@@ -3809,10 +3883,10 @@ var preProcessSharedBulkBuyingData = async ({
3809
3883
  sharedBulkBuyingDataByNftType[nftType].sharedObjects = await getSharedObjects(nftType);
3810
3884
  continue;
3811
3885
  }
3812
- const tradeportKioskListings = listingsByNftType[nftType]?.filter(
3813
- (listing) => listing.market_name === "tradeport" && listing.price && listing.listed && !(listing?.nonce && isOriginByteCollection(transferPolicies)) && listing.nft?.chain_state?.kiosk_id
3886
+ const tradeportLegacyKioskListings = listingsByNftType[nftType]?.filter(
3887
+ (listing) => listing.market_name === "tradeport" && !listing.nonce?.startsWith("0::") && !listing.nonce?.startsWith("1::") && listing.price && listing.listed && !(listing?.nonce && isOriginByteCollection(transferPolicies)) && listing.nft?.chain_state?.kiosk_id
3814
3888
  );
3815
- if (tradeportKioskListings.length === 0) {
3889
+ if (tradeportLegacyKioskListings.length === 0) {
3816
3890
  continue;
3817
3891
  }
3818
3892
  const transferPoliciesToResolve = await getTransferPoliciesToResolve({
@@ -3824,11 +3898,11 @@ var preProcessSharedBulkBuyingData = async ({
3824
3898
  sharedBulkBuyingDataByNftType[nftType].transferPoliciesToResolve = transferPoliciesToResolve;
3825
3899
  const transferPolicyToResolve = transferPoliciesToResolve.at(0);
3826
3900
  const royaltyRuleToResolve = transferPolicyToResolve.rules.find(
3827
- (policy) => policy.moduleName === "royalty_rule" || policy.moduleName === "kiosk_royalty_rule"
3901
+ (rule) => rule.moduleName === "royalty_rule" || rule.moduleName === "kiosk_royalty_rule"
3828
3902
  );
3829
3903
  if (royaltyRuleToResolve?.rulePackageId && royaltyRuleToResolve?.moduleName) {
3830
3904
  const feeTx = new Transaction8();
3831
- for (const listing of tradeportKioskListings) {
3905
+ for (const listing of tradeportLegacyKioskListings) {
3832
3906
  feeTx.moveCall({
3833
3907
  target: `${royaltyRuleToResolve.rulePackageId}::${royaltyRuleToResolve.moduleName}::fee_amount`,
3834
3908
  arguments: [feeTx.object(transferPolicyToResolve?.id), feeTx.pure.u64(listing.price)],
@@ -3846,13 +3920,13 @@ var preProcessSharedBulkBuyingData = async ({
3846
3920
  if (!feeAmount && feeAmount !== 0n) {
3847
3921
  continue;
3848
3922
  }
3849
- sharedBulkBuyingDataByNftType[nftType].royaltyFeeAmountsByListingId[tradeportKioskListings[i].id] = feeAmount;
3923
+ sharedBulkBuyingDataByNftType[nftType].royaltyFeeAmountsByListingId[tradeportLegacyKioskListings[i].id] = feeAmount;
3850
3924
  }
3851
3925
  }
3852
3926
  const batchSize = 10;
3853
3927
  const commissionResults = [];
3854
- for (let i = 0; i < tradeportKioskListings.length; i += batchSize) {
3855
- const batch = tradeportKioskListings.slice(i, i + batchSize);
3928
+ for (let i = 0; i < tradeportLegacyKioskListings.length; i += batchSize) {
3929
+ const batch = tradeportLegacyKioskListings.slice(i, i + batchSize);
3856
3930
  const batchPromises = batch.map(async (listing) => {
3857
3931
  const response = await suiClient.getDynamicFieldObject({
3858
3932
  parentId: TRADEPORT_KIOSK_LISTING_STORE,
@@ -3917,7 +3991,7 @@ var destroyZeroCoin = ({ tx, coin }) => {
3917
3991
  };
3918
3992
 
3919
3993
  // src/methods/buyListings/addBuyListingTxs.ts
3920
- function addTradePortBuyTx({
3994
+ function addLegacyTradePortBuyTx({
3921
3995
  tx,
3922
3996
  nftType,
3923
3997
  listingNonce,
@@ -3953,7 +4027,7 @@ function addTradePortBuyTx({
3953
4027
  }
3954
4028
  destroyZeroCoin({ tx, coin });
3955
4029
  }
3956
- var addTradeportKioskBuyTx = async ({
4030
+ var addLegacyTradeportKioskBuyTx = async ({
3957
4031
  tx,
3958
4032
  transferPolicies,
3959
4033
  kioskTx,
@@ -4017,6 +4091,57 @@ var addTradeportKioskBuyTx = async ({
4017
4091
  });
4018
4092
  destroyZeroCoin({ tx, coin });
4019
4093
  };
4094
+ async function addTradePortBuyTx({ tx, nftType, nftTokenId, price, coinToSplit }) {
4095
+ const marketFee = new bigNumberConfig_default(price).times(TRADEPORT_LISTINGS_DEFAULT_COMMISSION_BPS).div(1e4).integerValue(bigNumberConfig_default.ROUND_DOWN).toNumber();
4096
+ const totalAmount = new bigNumberConfig_default(price).plus(marketFee).toNumber();
4097
+ const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [tx.pure.u64(totalAmount)]);
4098
+ if (!coin) throw new Error("Coin could not be split");
4099
+ tx.moveCall({
4100
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::buy_listing_without_transfer_policy`,
4101
+ arguments: [tx.object(TRADEPORT_LISTINGS_STORE), tx.pure.id(nftTokenId), tx.object(coin)],
4102
+ typeArguments: [nftType]
4103
+ });
4104
+ destroyZeroCoin({ tx, coin });
4105
+ }
4106
+ async function addKioskTradePortBuyTx({
4107
+ tx,
4108
+ transferPolicies,
4109
+ kioskTx,
4110
+ nftType,
4111
+ nftTokenId,
4112
+ price,
4113
+ sellerKiosk,
4114
+ coinToSplit
4115
+ }) {
4116
+ const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
4117
+ const marketFee = new bigNumberConfig_default(price).times(TRADEPORT_LISTINGS_DEFAULT_COMMISSION_BPS).div(1e4).integerValue(bigNumberConfig_default.ROUND_DOWN);
4118
+ const royaltyFee = calculateRoyaltyFee(
4119
+ getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.rules,
4120
+ new bigNumberConfig_default(price)
4121
+ );
4122
+ const totalAmount = new bigNumberConfig_default(price).plus(marketFee).plus(royaltyFee).toNumber();
4123
+ const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [tx.pure.u64(totalAmount)]);
4124
+ if (!coin) throw new Error("Coin could not be split");
4125
+ const transferRequest = tx.moveCall({
4126
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::buy_listing_with_transfer_policy`,
4127
+ arguments: [
4128
+ tx.object(TRADEPORT_LISTINGS_STORE),
4129
+ tx.object(sellerKiosk),
4130
+ tx.object("value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk),
4131
+ tx.object("value" in kioskTx.kioskCap ? kioskTx.kioskCap.value : kioskTx.kioskCap),
4132
+ tx.pure.id(nftTokenId),
4133
+ tx.object(coin),
4134
+ tx.object(transferPolicyId)
4135
+ ],
4136
+ typeArguments: [nftType]
4137
+ });
4138
+ tx.moveCall({
4139
+ target: "0x2::transfer_policy::confirm_request",
4140
+ arguments: [tx.object(transferPolicyId), transferRequest],
4141
+ typeArguments: [nftType]
4142
+ });
4143
+ destroyZeroCoin({ tx, coin });
4144
+ }
4020
4145
  async function addOriginByteBuyTx({
4021
4146
  tx,
4022
4147
  sharedObjects,
@@ -4308,6 +4433,26 @@ async function addTradePortBuyTxHandler(txData) {
4308
4433
  await addOriginByteBuyTx({ ...txData, sharedObjects: sharedObjects2 });
4309
4434
  return;
4310
4435
  }
4436
+ if (txData?.listingNonce?.startsWith("0::")) {
4437
+ await addTradePortBuyTx(txData);
4438
+ return;
4439
+ }
4440
+ if (txData?.listingNonce?.startsWith("1::")) {
4441
+ return kioskTxWrapper({
4442
+ tx: txData?.tx,
4443
+ kioskClient: txData?.kioskClient,
4444
+ kioskOwner: txData?.buyer,
4445
+ kiosk: txData?.sellerKiosk,
4446
+ shouldConvertToPersonalKiosk: true,
4447
+ sharedKioskState: txData?.sharedKioskState,
4448
+ async runCommands(kioskTx) {
4449
+ await addKioskTradePortBuyTx({
4450
+ ...txData,
4451
+ kioskTx
4452
+ });
4453
+ }
4454
+ });
4455
+ }
4311
4456
  if (txData.listingNonce?.startsWith("0x")) {
4312
4457
  const response = await txData?.suiClient.getObject({
4313
4458
  id: txData.listingNonce,
@@ -4318,7 +4463,7 @@ async function addTradePortBuyTxHandler(txData) {
4318
4463
  }
4319
4464
  if (response.data.type === NON_KIOSK_LISTING_NONCE_TYPE) {
4320
4465
  const sharedObjects2 = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4321
- addTradePortBuyTx({ ...txData, sharedObjects: sharedObjects2 });
4466
+ addLegacyTradePortBuyTx({ ...txData, sharedObjects: sharedObjects2 });
4322
4467
  return;
4323
4468
  }
4324
4469
  }
@@ -4331,7 +4476,7 @@ async function addTradePortBuyTxHandler(txData) {
4331
4476
  shouldConvertToPersonalKiosk: true,
4332
4477
  sharedKioskState: txData?.sharedKioskState,
4333
4478
  async runCommands(kioskTx) {
4334
- await addTradeportKioskBuyTx({
4479
+ await addLegacyTradeportKioskBuyTx({
4335
4480
  ...txData,
4336
4481
  kioskTx
4337
4482
  });
@@ -4339,7 +4484,7 @@ async function addTradePortBuyTxHandler(txData) {
4339
4484
  });
4340
4485
  }
4341
4486
  const sharedObjects = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4342
- addTradePortBuyTx({ ...txData, sharedObjects });
4487
+ addLegacyTradePortBuyTx({ ...txData, sharedObjects });
4343
4488
  }
4344
4489
  async function addHyperspaceBuyTxHandler(txData) {
4345
4490
  if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies)) {
@@ -5368,7 +5513,7 @@ async function createLongLocks({ walletAddress, nfts }, context) {
5368
5513
  if (!transferPolicy) {
5369
5514
  throw new Error(`Missing transfer policy for ${nftType}`);
5370
5515
  }
5371
- const royalty = calculateRoyaltyFee(transferPolicy.rules, BigInt(argNft.priceInMist));
5516
+ const royalty = calculateRoyaltyFee(transferPolicy.rules, new BigNumber(argNft.priceInMist));
5372
5517
  await kioskTxWrapper({
5373
5518
  tx,
5374
5519
  kioskClient: context.kioskClient,
@@ -5392,7 +5537,7 @@ async function createLongLocks({ walletAddress, nfts }, context) {
5392
5537
  })
5393
5538
  )
5394
5539
  ),
5395
- tx.pure.u64(royalty),
5540
+ tx.pure.u64(royalty.toNumber()),
5396
5541
  tx.pure.u64(premium),
5397
5542
  tx.pure.u64(expireIn)
5398
5543
  ]
@@ -5486,9 +5631,9 @@ async function createShortLocks({ nfts }, context) {
5486
5631
  collectionId: argNft.collectionId
5487
5632
  })
5488
5633
  );
5489
- const royalty = calculateRoyaltyFee(transferPolicy.rules, BigInt(argNft.priceInMist));
5634
+ const royalty = calculateRoyaltyFee(transferPolicy.rules, new BigNumber(argNft.priceInMist));
5490
5635
  const [deposit] = tx.splitCoins(tx.gas, [
5491
- BigInt(argNft.priceInMist) + royalty + marketplaceFee
5636
+ new BigNumber(argNft.priceInMist).plus(royalty).plus(marketplaceFee).toNumber()
5492
5637
  ]);
5493
5638
  tx.moveCall({
5494
5639
  target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::create_short_lock`,
@@ -5497,7 +5642,7 @@ async function createShortLocks({ nfts }, context) {
5497
5642
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
5498
5643
  tx.pure.u64(BigInt(argNft.priceInMist)),
5499
5644
  tx.pure.u64(marketplaceFee),
5500
- tx.pure.u64(royalty),
5645
+ tx.pure.u64(royalty.toNumber()),
5501
5646
  tx.pure.u64(premium),
5502
5647
  tx.pure.u64(expireIn),
5503
5648
  deposit
@@ -5508,8 +5653,23 @@ async function createShortLocks({ nfts }, context) {
5508
5653
  }
5509
5654
 
5510
5655
  // src/methods/listNfts/listNfts.ts
5511
- import { Transaction as Transaction18 } from "@mysten/sui/transactions";
5512
- import { normalizeSuiAddress } from "@mysten/sui/utils";
5656
+ import { Transaction as Transaction19 } from "@mysten/sui/transactions";
5657
+
5658
+ // src/helpers/validateMinFloorPrice.ts
5659
+ function validateMinFloorPrice({ transferPolicies, listPrice }) {
5660
+ const transferPolicy = getNativeKioskTransferPolicies(transferPolicies)?.at(0);
5661
+ const minFloorPrice = transferPolicy?.rules?.filter(
5662
+ (rule) => rule?.type === "floor_price_rule"
5663
+ )?.[0]?.floor_price;
5664
+ if (minFloorPrice) {
5665
+ if (listPrice < minFloorPrice) {
5666
+ const formattedMinFloorPrice = Number(minFloorPrice) / 1e9;
5667
+ throw new Error(
5668
+ `NFT Transfer Policy has a miminum floor price rule. Item cannot be listed for less than ${formattedMinFloorPrice} SUI`
5669
+ );
5670
+ }
5671
+ }
5672
+ }
5513
5673
 
5514
5674
  // src/methods/listNfts/addListTxs.ts
5515
5675
  async function addOriginByteListTx({
@@ -5565,54 +5725,35 @@ function addTradePortListTx({
5565
5725
  nftTokenId,
5566
5726
  borrowedItem,
5567
5727
  nftType,
5568
- collectionId,
5569
5728
  listPrice
5570
5729
  }) {
5571
- const marketFeePrice = getMarketFeePrice({ price: listPrice, collectionId });
5572
5730
  tx.moveCall({
5573
- target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::list",
5731
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::create_listing_without_transfer_policy`,
5574
5732
  arguments: [
5575
- tx.object(TRADEPORT_LISTING_STORE),
5733
+ tx.object(TRADEPORT_LISTINGS_STORE),
5576
5734
  borrowedItem ? tx.object(borrowedItem) : tx.object(nftTokenId),
5577
- tx.pure.u64(listPrice),
5578
- tx.pure.u64(marketFeePrice),
5579
- tx.pure.address(TRADEPORT_BENEFICIARY_ADDRESS)
5735
+ tx.pure.u64(listPrice)
5580
5736
  ],
5581
5737
  typeArguments: [nftType]
5582
5738
  });
5583
5739
  }
5584
- async function addTradePortKioskListTx({
5740
+ async function addKioskTradePortListTx({
5585
5741
  tx,
5586
5742
  kioskTx,
5587
5743
  transferPolicies,
5588
5744
  nftTokenId,
5589
5745
  nftType,
5590
- collectionId,
5591
5746
  listPrice
5592
5747
  }) {
5593
- const transferPolicy = getNativeKioskTransferPolicies(transferPolicies)?.at(0);
5594
- const minFloorPrice = transferPolicy?.rules?.filter(
5595
- (rule) => rule?.type === "floor_price_rule"
5596
- )?.[0]?.floor_price;
5597
- if (minFloorPrice) {
5598
- if (listPrice < minFloorPrice) {
5599
- const formattedMinFloorPrice = Number(minFloorPrice) / 1e9;
5600
- throw new Error(
5601
- `NFT Transfer Policy has a miminum floor price rule. Item cannot be listed for less than ${formattedMinFloorPrice} SUI`
5602
- );
5603
- }
5604
- }
5605
- const marketFeePrice = getMarketFeePrice({ price: listPrice, collectionId });
5748
+ validateMinFloorPrice({ transferPolicies, listPrice });
5606
5749
  tx.moveCall({
5607
- target: "0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_listings::list",
5750
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::create_listing_with_transfer_policy`,
5608
5751
  arguments: [
5609
- tx.object(TRADEPORT_KIOSK_LISTING_STORE),
5752
+ tx.object(TRADEPORT_LISTINGS_STORE),
5610
5753
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
5611
5754
  tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
5612
- tx.pure.address(nftTokenId),
5613
- tx.pure.u64(listPrice + marketFeePrice),
5614
- tx.pure.u64(marketFeePrice),
5615
- tx.pure.address(TRADEPORT_BENEFICIARY_ADDRESS)
5755
+ tx.pure.id(nftTokenId),
5756
+ tx.pure.u64(listPrice)
5616
5757
  ],
5617
5758
  typeArguments: [nftType]
5618
5759
  });
@@ -5657,7 +5798,7 @@ async function addTradePortListTxHandler(txData) {
5657
5798
  sharedKioskState: txData?.sharedKioskState,
5658
5799
  shouldUseSharedKioskTx: false,
5659
5800
  async runCommands(kioskTx) {
5660
- await addTradePortKioskListTx({
5801
+ await addKioskTradePortListTx({
5661
5802
  ...txData,
5662
5803
  kioskTx
5663
5804
  });
@@ -5677,7 +5818,7 @@ async function addTradePortListTxHandler(txData) {
5677
5818
  item: txData?.nftTokenId,
5678
5819
  itemType: txData?.nftType
5679
5820
  });
5680
- await addTradePortKioskListTx({
5821
+ await addKioskTradePortListTx({
5681
5822
  ...txData,
5682
5823
  kioskTx
5683
5824
  });
@@ -5688,43 +5829,53 @@ async function addTradePortListTxHandler(txData) {
5688
5829
  }
5689
5830
 
5690
5831
  // src/methods/listNfts/addRelistTxs.ts
5691
- function addTradePortRelistTx({
5832
+ function addTradePortRelistTx({ tx, nftTokenId, nftType, listPrice }) {
5833
+ tx.moveCall({
5834
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::relist_listing_without_transfer_policy`,
5835
+ arguments: [
5836
+ tx.object(TRADEPORT_LISTINGS_STORE),
5837
+ tx.pure.id(nftTokenId),
5838
+ tx.pure.u64(listPrice)
5839
+ ],
5840
+ typeArguments: [nftType]
5841
+ });
5842
+ }
5843
+ async function addKioskTradePortRelistTx({
5692
5844
  tx,
5845
+ kioskTx,
5846
+ nftTokenId,
5693
5847
  nftType,
5694
- collectionId,
5695
- listingNonce,
5696
5848
  listPrice
5697
5849
  }) {
5698
- const marketFeePrice = getMarketFeePrice({ price: listPrice, collectionId });
5699
5850
  tx.moveCall({
5700
- target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::relist",
5851
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::relist_listing_with_transfer_policy`,
5701
5852
  arguments: [
5702
- tx.object(TRADEPORT_LISTING_STORE),
5703
- tx.pure.address(listingNonce),
5704
- tx.pure.u64(listPrice),
5705
- tx.pure.u64(marketFeePrice),
5706
- tx.pure.address(TRADEPORT_BENEFICIARY_ADDRESS)
5853
+ tx.object(TRADEPORT_LISTINGS_STORE),
5854
+ tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
5855
+ tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
5856
+ tx.pure.id(nftTokenId),
5857
+ tx.pure.u64(listPrice)
5707
5858
  ],
5708
5859
  typeArguments: [nftType]
5709
5860
  });
5710
5861
  }
5711
5862
  function addBlueMoveRelistTx(txData) {
5712
- const { tx, nftTokenId, nftType, listPrice, suiClient } = txData;
5863
+ const { tx, nftTokenId, nftType, listPrice } = txData;
5713
5864
  const borrowedItem = tx.moveCall({
5714
5865
  target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist",
5715
5866
  arguments: [tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT), tx.pure.address(nftTokenId)],
5716
5867
  typeArguments: [nftType, nftType]
5717
5868
  });
5718
- addTradePortListTx({ ...txData, listPrice, borrowedItem, suiClient });
5869
+ addTradePortListTx({ ...txData, listPrice, borrowedItem });
5719
5870
  }
5720
5871
  function addTocenRelistTx(txData) {
5721
- const { tx, nftTokenId, nftType, listPrice, suiClient } = txData;
5872
+ const { tx, nftTokenId, nftType, listPrice } = txData;
5722
5873
  const borrowedItem = tx.moveCall({
5723
5874
  target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::delist",
5724
5875
  arguments: [tx.object(TOCEN_MARKETPLACE_OBJECT), tx.pure.address(nftTokenId)],
5725
5876
  typeArguments: [nftType]
5726
5877
  });
5727
- addTradePortListTx({ ...txData, listPrice, borrowedItem, suiClient });
5878
+ addTradePortListTx({ ...txData, listPrice, borrowedItem });
5728
5879
  }
5729
5880
 
5730
5881
  // src/methods/relistNft/relistNft.ts
@@ -5762,20 +5913,19 @@ async function relistNft({
5762
5913
  };
5763
5914
  switch (firstListedOrExpiredListing.market_name) {
5764
5915
  case "tradeport":
5765
- if ((!isOriginByteCollection(txData?.transferPolicies) || ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) && txData?.listingNonce && await isNonKioskListing({
5766
- suiClient: txData?.suiClient,
5767
- listingNonce: txData?.listingNonce
5768
- })) {
5916
+ if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
5917
+ await addTradePortUnlistTxHandler(txData);
5918
+ await addTradePortListTxHandler({
5919
+ ...txData,
5920
+ listPrice
5921
+ });
5922
+ return;
5923
+ }
5924
+ if (txData?.listingNonce?.startsWith("0::")) {
5769
5925
  addTradePortRelistTx({ ...txData, listPrice });
5770
- } else {
5771
- if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
5772
- await addTradePortUnlistTxHandler(txData);
5773
- await addTradePortListTxHandler({
5774
- ...txData,
5775
- listPrice
5776
- });
5777
- return;
5778
- }
5926
+ return;
5927
+ }
5928
+ if (txData?.listingNonce?.startsWith("1::")) {
5779
5929
  return kioskTxWrapper({
5780
5930
  tx: txData?.tx,
5781
5931
  kioskClient: txData?.kioskClient,
@@ -5785,11 +5935,7 @@ async function relistNft({
5785
5935
  sharedKioskState: txData?.sharedKioskState,
5786
5936
  shouldUseSharedKioskTx: false,
5787
5937
  async runCommands(kioskTx) {
5788
- await addTradePortKioskUnlistTx({
5789
- ...txData,
5790
- kioskTx
5791
- });
5792
- await addTradePortKioskListTx({
5938
+ await addKioskTradePortRelistTx({
5793
5939
  ...txData,
5794
5940
  kioskTx,
5795
5941
  listPrice
@@ -5797,6 +5943,8 @@ async function relistNft({
5797
5943
  }
5798
5944
  });
5799
5945
  }
5946
+ await addTradePortUnlistTxHandler({ ...txData, isPartOfRelist: true });
5947
+ await addTradePortListTxHandler({ ...txData, listPrice });
5800
5948
  break;
5801
5949
  case "hyperspace":
5802
5950
  await addHyperspaceUnlistTxHandler(txData);
@@ -5828,6 +5976,180 @@ async function relistNft({
5828
5976
  }
5829
5977
  }
5830
5978
 
5979
+ // src/helpers/swap.ts
5980
+ import { AggregatorQuoter, CoinProvider, Protocol, TradeBuilder } from "@flowx-finance/sdk";
5981
+ import {
5982
+ coinWithBalance,
5983
+ Transaction as Transaction18
5984
+ } from "@mysten/sui/transactions";
5985
+ import { normalizeStructTag as normalizeStructTag2, normalizeSuiAddress } from "@mysten/sui/utils";
5986
+ import ms from "ms";
5987
+ import { bcs as bcs4 } from "@mysten/sui/bcs";
5988
+
5989
+ // src/utils/pureValues.ts
5990
+ var toDecimalValue = (value, decimals) => {
5991
+ if (!value || decimals === void 0) return new bigNumberConfig_default(0);
5992
+ return new bigNumberConfig_default(value).div(10 ** decimals);
5993
+ };
5994
+ var toPureValue = (value, decimals) => {
5995
+ if (!value || decimals === void 0) return new bigNumberConfig_default(0);
5996
+ return new bigNumberConfig_default(new bigNumberConfig_default(value).multipliedBy(10 ** decimals).toFixed(0));
5997
+ };
5998
+
5999
+ // src/helpers/swap.ts
6000
+ var aggregatorQuoter = new AggregatorQuoter("mainnet");
6001
+ var suiCoinType = "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";
6002
+ async function createSwapTransaction({
6003
+ suiClient,
6004
+ walletAddress,
6005
+ options
6006
+ }) {
6007
+ const tx = options?.transaction ?? new Transaction18();
6008
+ tx.setSender(normalizeSuiAddress(walletAddress));
6009
+ const {
6010
+ coinInType,
6011
+ coinInAmount = ZERO,
6012
+ coinOutType,
6013
+ slippage = 1,
6014
+ ttl = "15m",
6015
+ excludeSources = [Protocol.STEAMM, ...DexConstants.poolsToExclude],
6016
+ rewardNftType
6017
+ } = options ?? {};
6018
+ if (normalizeStructTag2(coinOutType) === suiCoinType && normalizeStructTag2(coinInType) === suiCoinType) {
6019
+ const [coin] = tx.splitCoins(tx.gas, [coinInAmount.toFixed()]);
6020
+ return {
6021
+ transaction: tx,
6022
+ coinOut: coin
6023
+ };
6024
+ }
6025
+ const amountInSwap = coinInAmount.minus(coinInAmount.div(100).toFixed(0));
6026
+ const commissionAmount = coinInAmount.div(100).toFixed(0);
6027
+ const { routes } = await aggregatorQuoter.getRoutes({
6028
+ tokenIn: coinInType,
6029
+ tokenOut: coinOutType ?? suiCoinType,
6030
+ amountIn: amountInSwap.toFixed(),
6031
+ excludeSources
6032
+ });
6033
+ const tradeBuilder = new TradeBuilder("mainnet", routes);
6034
+ const trade = tradeBuilder.sender(normalizeSuiAddress(walletAddress)).slippage(slippage).deadline(Date.now() + ms(ttl)).build();
6035
+ let coinIn;
6036
+ if (normalizeStructTag2(coinInType) === suiCoinType) {
6037
+ [coinIn] = tx.splitCoins(tx.gas, [
6038
+ tx.pure.u64((BigInt(amountInSwap.toFixed()) + BigInt(commissionAmount)).toString())
6039
+ ]);
6040
+ } else {
6041
+ coinIn = coinWithBalance({
6042
+ balance: BigInt(amountInSwap.toFixed()) + BigInt(commissionAmount),
6043
+ type: coinInType
6044
+ })(tx);
6045
+ }
6046
+ const [commissionCoin] = tx.splitCoins(coinIn, [tx.pure.u64(commissionAmount.toString())]);
6047
+ tx.moveCall({
6048
+ target: `${DexConstants.commission}::commission::pay`,
6049
+ arguments: [
6050
+ tx.object(DexConstants.commissionManager),
6051
+ tx.pure.string("swap"),
6052
+ tx.object(commissionCoin),
6053
+ tx.pure(bcs4.option(bcs4.String).serialize(rewardNftType).toBytes())
6054
+ ],
6055
+ typeArguments: [coinInType]
6056
+ });
6057
+ const coinOut = await trade.swap({ client: suiClient, tx, coinIn });
6058
+ if (!coinOut) {
6059
+ throw new Error("Swap did not return a valid coin out.");
6060
+ }
6061
+ if (coinOut && options?.amountToSplitFromSuiBalance > 0n) {
6062
+ mergeSwapCoinWithSuiBalance(tx, coinOut, options?.amountToSplitFromSuiBalance);
6063
+ }
6064
+ return { transaction: tx, coinOut };
6065
+ }
6066
+ function mergeSwapCoinWithSuiBalance(transaction, coinToMergeInto, amountToSplitFromSuiBalance) {
6067
+ if (coinToMergeInto && amountToSplitFromSuiBalance > 0n) {
6068
+ const [coinFromSuiBalance] = transaction.splitCoins(transaction.gas, [
6069
+ transaction.pure.u64(amountToSplitFromSuiBalance)
6070
+ ]);
6071
+ transaction.mergeCoins(coinToMergeInto, [coinFromSuiBalance]);
6072
+ }
6073
+ }
6074
+ function transferBackExtraSwappedCoin(transaction, swapResultCoin, walletAddress) {
6075
+ if (swapResultCoin) {
6076
+ transaction.transferObjects([swapResultCoin], walletAddress);
6077
+ }
6078
+ }
6079
+ async function calculateSwapInputAmountWithSlippage({
6080
+ coinInType,
6081
+ coinOutType,
6082
+ coinOutAmount,
6083
+ slippage = 0
6084
+ }) {
6085
+ if (coinInType === coinOutType) {
6086
+ return new bigNumberConfig_default(coinOutAmount);
6087
+ }
6088
+ const provider = new CoinProvider("mainnet");
6089
+ const coinQueryResult = await provider.getCoins({
6090
+ limit: 2,
6091
+ coinTypes: [coinInType, coinOutType]
6092
+ });
6093
+ const coinIn = coinQueryResult[0];
6094
+ const coinOut = coinQueryResult[1];
6095
+ const exchangeRate = new bigNumberConfig_default(coinOut.derivedPriceInUSD ?? 0)?.gt(0) ? new bigNumberConfig_default(coinIn?.derivedPriceInUSD ?? 1)?.div(coinOut?.derivedPriceInUSD ?? 1) : new bigNumberConfig_default(0);
6096
+ const amountSell = toDecimalValue(coinOutAmount.toString(), coinOut?.decimals).div(exchangeRate);
6097
+ const slippageMultiplier = 1 + parseInt(slippage.toString() || "0", 10) / 1e6;
6098
+ const amountWithSlippage = amountSell.times(slippageMultiplier);
6099
+ const coinInAmount = toPureValue(amountWithSlippage, coinIn?.decimals);
6100
+ return coinInAmount;
6101
+ }
6102
+
6103
+ // src/methods/sponsorNftListing/addSponsorNftListingTx.ts
6104
+ import { SUI_CLOCK_OBJECT_ID as SUI_CLOCK_OBJECT_ID6 } from "@mysten/sui.js/utils";
6105
+ var addSponsorListingTx = async ({
6106
+ tx,
6107
+ nftTokenId,
6108
+ nftType,
6109
+ suiClient,
6110
+ walletAddress,
6111
+ sponsorOptions
6112
+ }) => {
6113
+ const coinInAmount = await calculateSwapInputAmountWithSlippage({
6114
+ coinInType: sponsorOptions?.coinInType,
6115
+ coinOutType: USDC_COIN_TYPE,
6116
+ coinOutAmount: new bigNumberConfig_default(TRADEPORT_SPONSOR_USDC_FEE_AMOUNT_PER_PERIOD)?.times(sponsorOptions?.numOfPeriods).toString(),
6117
+ slippage: sponsorOptions?.slippage
6118
+ });
6119
+ const { coinOut } = await createSwapTransaction({
6120
+ suiClient,
6121
+ walletAddress,
6122
+ options: {
6123
+ transaction: tx,
6124
+ coinInType: sponsorOptions?.coinInType,
6125
+ coinInAmount,
6126
+ coinOutType: USDC_COIN_TYPE,
6127
+ slippage: sponsorOptions?.slippage
6128
+ }
6129
+ });
6130
+ const [sponsorFeeCoin] = tx.splitCoins(coinOut, [
6131
+ tx.pure.u64(
6132
+ new bigNumberConfig_default(TRADEPORT_SPONSOR_USDC_FEE_AMOUNT_PER_PERIOD)?.times(sponsorOptions?.numOfPeriods).toString()
6133
+ )
6134
+ ]);
6135
+ tx.moveCall({
6136
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::add_sponsored_listing`,
6137
+ arguments: [
6138
+ tx.object(TRADEPORT_LISTINGS_STORE),
6139
+ tx.object(SUI_CLOCK_OBJECT_ID6),
6140
+ tx.pure.id(nftTokenId),
6141
+ tx.pure.u64(sponsorOptions?.numOfPeriods),
6142
+ tx.object(sponsorFeeCoin)
6143
+ ],
6144
+ typeArguments: [nftType]
6145
+ });
6146
+ transferBackExtraSwappedCoin(tx, coinOut, walletAddress);
6147
+ };
6148
+
6149
+ // src/helpers/isExpiredListing.ts
6150
+ import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui/utils";
6151
+ var isExpiredListing = (listing, walletAddress) => listing.nonce && listing.seller && normalizeSuiAddress2(listing.seller) === normalizeSuiAddress2(walletAddress);
6152
+
5831
6153
  // src/methods/listNfts/listNfts.ts
5832
6154
  var listNfts = async ({ nfts, walletAddress }, context) => {
5833
6155
  const res = await gqlChainRequest({
@@ -5839,11 +6161,12 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5839
6161
  throw new Error("No nfts found");
5840
6162
  }
5841
6163
  const nftsForTracking = [];
5842
- const tx = new Transaction18();
6164
+ const tx = new Transaction19();
5843
6165
  const sharedKioskState = {
5844
6166
  kioskTx: void 0
5845
6167
  };
5846
6168
  for (const nft of res.nfts) {
6169
+ const inputNft = nfts?.find((n) => n.id === nft?.id);
5847
6170
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
5848
6171
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
5849
6172
  }
@@ -5853,8 +6176,11 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5853
6176
  nft
5854
6177
  });
5855
6178
  const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
6179
+ if (inputNft?.sponsorOptions?.shouldSponsor && isOriginByteCollection(transferPolicies)) {
6180
+ throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nft?.token_id}`);
6181
+ }
5856
6182
  if (nft?.listed || nft.listings.some(
5857
- (listing) => listing.nonce && listing.seller && normalizeSuiAddress(listing.seller) === normalizeSuiAddress(walletAddress)
6183
+ (listing) => isExpiredListing(listing, walletAddress)
5858
6184
  )) {
5859
6185
  await relistNft({
5860
6186
  tx,
@@ -5863,7 +6189,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5863
6189
  sharedKioskState,
5864
6190
  transferPolicies,
5865
6191
  nft,
5866
- listPrice: nfts?.find((n) => n.id === nft?.id)?.listPriceInMist,
6192
+ listPrice: inputNft?.listPriceInMist,
5867
6193
  walletAddress
5868
6194
  });
5869
6195
  } else {
@@ -5877,26 +6203,36 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5877
6203
  collectionId: nft?.collection_id,
5878
6204
  nftTokenId: nft?.token_id,
5879
6205
  nftType,
5880
- listPrice: nfts?.find((n) => n.id === nft?.id)?.listPriceInMist,
6206
+ listPrice: inputNft?.listPriceInMist,
5881
6207
  sellerKiosk: nft?.chain_state?.kiosk_id
5882
6208
  };
5883
6209
  await addTradePortListTxHandler(listTxData);
5884
6210
  }
6211
+ if (inputNft?.sponsorOptions?.shouldSponsor) {
6212
+ await addSponsorListingTx({
6213
+ tx,
6214
+ suiClient: context.suiClient,
6215
+ nftTokenId: nft?.token_id,
6216
+ nftType,
6217
+ walletAddress,
6218
+ sponsorOptions: inputNft?.sponsorOptions
6219
+ });
6220
+ }
5885
6221
  nftsForTracking.push({
5886
6222
  walletAddress,
5887
6223
  nftType,
5888
6224
  collectionId: nft?.collection_id,
5889
- listPrice: nfts?.find((n) => n.id === nft?.id)?.listPriceInMist,
6225
+ listPrice: inputNft?.listPriceInMist,
5890
6226
  isRelist: nft?.listed,
5891
6227
  marketRelistedFrom: nft?.listings?.[0]?.market_name
5892
6228
  });
5893
6229
  }
5894
6230
  sharedKioskState?.kioskTx?.finalize();
5895
- return Transaction18.from(tx);
6231
+ return Transaction19.from(tx);
5896
6232
  };
5897
6233
 
5898
6234
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5899
- import { Transaction as Transaction19 } from "@mysten/sui/transactions";
6235
+ import { Transaction as Transaction20 } from "@mysten/sui/transactions";
5900
6236
 
5901
6237
  // src/graphql/queries/fetchNftsByKioskId.ts
5902
6238
  import { gql as gql18 } from "graphql-request";
@@ -6099,7 +6435,7 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
6099
6435
 
6100
6436
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
6101
6437
  async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
6102
- const tx = new Transaction19();
6438
+ const tx = new Transaction20();
6103
6439
  const res = await gqlChainRequest({
6104
6440
  chain: "sui",
6105
6441
  query: fetchKiosksByOwner,
@@ -6265,11 +6601,11 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
6265
6601
  }
6266
6602
  }
6267
6603
  sharedKioskState?.kioskTx?.finalize();
6268
- return Transaction19.from(tx);
6604
+ return Transaction20.from(tx);
6269
6605
  }
6270
6606
 
6271
6607
  // src/methods/placeCollectionBids/placeCollectionBids.ts
6272
- import { Transaction as Transaction20 } from "@mysten/sui/transactions";
6608
+ import { Transaction as Transaction21 } from "@mysten/sui/transactions";
6273
6609
 
6274
6610
  // src/graphql/queries/fetchCollectionsById.ts
6275
6611
  import { gql as gql19 } from "graphql-request";
@@ -6326,12 +6662,12 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
6326
6662
  expireAt,
6327
6663
  coinToSplit
6328
6664
  } = txData;
6329
- let bcs4;
6665
+ let bcs5;
6330
6666
  if (nftTokenId && isDynamicCollection(collectionId)) {
6331
6667
  if (!bcsHex) {
6332
6668
  throw new Error(`No BCS found for token ${nftTokenId}`);
6333
6669
  }
6334
- bcs4 = fromHex(bcsHex);
6670
+ bcs5 = fromHex(bcsHex);
6335
6671
  }
6336
6672
  let multiBidChainId;
6337
6673
  let expiredBids;
@@ -6393,7 +6729,7 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
6393
6729
  arguments: [multiBidChainId]
6394
6730
  }) : void 0,
6395
6731
  tx.pure.option("id", nftTokenId ? normalizeSuiObjectId5(nftTokenId) : void 0),
6396
- tx.pure.option("vector<u8>", bcs4 ? [...bcs4] : void 0),
6732
+ tx.pure.option("vector<u8>", bcs5 ? [...bcs5] : void 0),
6397
6733
  tx.pure.option("u64", expireAt?.getTime()),
6398
6734
  tx.pure.u64(price),
6399
6735
  ...transferPolicy ? [tx.object(transferPolicy.id)] : [],
@@ -6544,11 +6880,11 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6544
6880
  if (swapResultCoin) {
6545
6881
  tx.transferObjects([swapResultCoin], walletAddress);
6546
6882
  }
6547
- return Transaction20.from(tx);
6883
+ return Transaction21.from(tx);
6548
6884
  };
6549
6885
 
6550
6886
  // src/methods/placeNftBids/placeNftBids.ts
6551
- import { Transaction as Transaction21 } from "@mysten/sui/transactions";
6887
+ import { Transaction as Transaction22 } from "@mysten/sui/transactions";
6552
6888
  var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6553
6889
  const tx = deserializeOrCreateTxBlock({ existingTx });
6554
6890
  const swapResultCoin = extractSwapResultCoinFromTxBlock(tx);
@@ -6598,11 +6934,11 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6598
6934
  if (swapResultCoin) {
6599
6935
  tx.transferObjects([swapResultCoin], walletAddress);
6600
6936
  }
6601
- return Transaction21.from(tx);
6937
+ return Transaction22.from(tx);
6602
6938
  };
6603
6939
 
6604
6940
  // src/methods/removeCollectionBids/removeCollectionBids.ts
6605
- import { Transaction as Transaction22 } from "@mysten/sui/transactions";
6941
+ import { Transaction as Transaction23 } from "@mysten/sui/transactions";
6606
6942
 
6607
6943
  // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
6608
6944
  import { normalizeSuiObjectId as normalizeSuiObjectId6 } from "@mysten/sui/utils";
@@ -6710,7 +7046,7 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6710
7046
  throw new Error("No bids found");
6711
7047
  }
6712
7048
  const bidsForTracking = [];
6713
- const tx = existingTx ? Transaction22.from(existingTx) : new Transaction22();
7049
+ const tx = existingTx ? Transaction23.from(existingTx) : new Transaction23();
6714
7050
  for (const bid of res.bids) {
6715
7051
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6716
7052
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6758,11 +7094,11 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6758
7094
  bidder: bid?.bidder
6759
7095
  });
6760
7096
  }
6761
- return Transaction22.from(tx);
7097
+ return Transaction23.from(tx);
6762
7098
  };
6763
7099
 
6764
7100
  // src/methods/removeNftBids/removeNftBids.ts
6765
- import { Transaction as Transaction23 } from "@mysten/sui/transactions";
7101
+ import { Transaction as Transaction24 } from "@mysten/sui/transactions";
6766
7102
  var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6767
7103
  const res = await gqlChainRequest({
6768
7104
  chain: "sui",
@@ -6773,7 +7109,7 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6773
7109
  throw new Error("No bids found");
6774
7110
  }
6775
7111
  const bidsForTracking = [];
6776
- const tx = existingTx ? Transaction23.from(existingTx) : new Transaction23();
7112
+ const tx = existingTx ? Transaction24.from(existingTx) : new Transaction24();
6777
7113
  for (const bid of res.bids) {
6778
7114
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6779
7115
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6818,11 +7154,11 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6818
7154
  bidder: bid?.bidder
6819
7155
  });
6820
7156
  }
6821
- return Transaction23.from(tx);
7157
+ return Transaction24.from(tx);
6822
7158
  };
6823
7159
 
6824
7160
  // src/methods/transferNfts/transferNfts.ts
6825
- import { Transaction as Transaction24 } from "@mysten/sui/transactions";
7161
+ import { Transaction as Transaction25 } from "@mysten/sui/transactions";
6826
7162
  var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context) => {
6827
7163
  if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
6828
7164
  throw new Error("Cannot transfer to self");
@@ -6840,7 +7176,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6840
7176
  }
6841
7177
  const nftsForTracking = [];
6842
7178
  const nftsToTransferDirectly = [];
6843
- const tx = new Transaction24();
7179
+ const tx = new Transaction25();
6844
7180
  const sharedKioskState = {
6845
7181
  kioskTx: void 0
6846
7182
  };
@@ -6943,11 +7279,11 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6943
7279
  context.suiClient
6944
7280
  );
6945
7281
  sharedKioskState?.kioskTx?.finalize();
6946
- return Transaction24.from(tx);
7282
+ return Transaction25.from(tx);
6947
7283
  };
6948
7284
 
6949
7285
  // src/methods/unlistListings/unlistListings.ts
6950
- import { Transaction as Transaction25 } from "@mysten/sui/transactions";
7286
+ import { Transaction as Transaction26 } from "@mysten/sui/transactions";
6951
7287
  var unlistListings = async ({ listingIds, walletAddress }, context) => {
6952
7288
  const res = await gqlChainRequest({
6953
7289
  chain: "sui",
@@ -6958,7 +7294,7 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
6958
7294
  throw new Error("No listings found");
6959
7295
  }
6960
7296
  const listingsForTracking = [];
6961
- const tx = new Transaction25();
7297
+ const tx = new Transaction26();
6962
7298
  const sharedKioskState = {
6963
7299
  kioskTx: void 0
6964
7300
  };
@@ -7027,12 +7363,12 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
7027
7363
  });
7028
7364
  }
7029
7365
  sharedKioskState?.kioskTx?.finalize();
7030
- return Transaction25.from(tx);
7366
+ return Transaction26.from(tx);
7031
7367
  };
7032
7368
 
7033
7369
  // src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts
7034
7370
  import { KioskTransaction as KioskTransaction2 } from "@mysten/kiosk";
7035
- import { Transaction as Transaction26 } from "@mysten/sui/transactions";
7371
+ import { Transaction as Transaction27 } from "@mysten/sui/transactions";
7036
7372
  async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7037
7373
  const res = await gqlChainRequest({
7038
7374
  chain: "sui",
@@ -7052,7 +7388,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7052
7388
  if (kiosksWithProfit.length === 0) {
7053
7389
  throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
7054
7390
  }
7055
- const tx = new Transaction26();
7391
+ const tx = new Transaction27();
7056
7392
  try {
7057
7393
  for (const kiosk of kiosksWithProfit) {
7058
7394
  let kioskTx;
@@ -7098,9 +7434,57 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
7098
7434
  } catch (err) {
7099
7435
  console.log("err", err);
7100
7436
  }
7101
- return Transaction26.from(tx);
7437
+ return Transaction27.from(tx);
7102
7438
  }
7103
7439
 
7440
+ // src/methods/sponsorNftListing/sponsorNftListing.ts
7441
+ import { Transaction as Transaction28 } from "@mysten/sui/transactions";
7442
+
7443
+ // src/graphql/queries/fetchNftCollectionChainState.ts
7444
+ import { gql as gql21 } from "graphql-request";
7445
+ var fetchNftCollectionChainState = gql21`
7446
+ query fetchNftCollectionChainState($nftTokenId: String!) {
7447
+ nfts(where: { token_id: { _eq: $nftTokenId } }) {
7448
+ collection {
7449
+ id
7450
+ chain_state
7451
+ }
7452
+ }
7453
+ }
7454
+ `;
7455
+
7456
+ // src/methods/sponsorNftListing/sponsorNftListing.ts
7457
+ var sponsorNftListing = async ({ nftTokenId, walletAddress, options }, context) => {
7458
+ const res = await gqlChainRequest({
7459
+ chain: "sui",
7460
+ query: fetchNftCollectionChainState,
7461
+ variables: { nftTokenId }
7462
+ });
7463
+ if (res?.nfts?.length === 0) {
7464
+ throw new Error(`No nft found with token id ${nftTokenId}`);
7465
+ }
7466
+ const nft = res?.nfts?.[0];
7467
+ const nftType = getNftType({
7468
+ collectionId: nft?.collection?.id,
7469
+ collectionChainState: nft?.collection?.chain_state,
7470
+ nft
7471
+ });
7472
+ const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
7473
+ if (isOriginByteCollection(transferPolicies)) {
7474
+ throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
7475
+ }
7476
+ const tx = new Transaction28();
7477
+ await addSponsorListingTx({
7478
+ tx,
7479
+ suiClient: context.suiClient,
7480
+ nftTokenId,
7481
+ nftType,
7482
+ walletAddress,
7483
+ sponsorOptions: options
7484
+ });
7485
+ return Transaction28.from(tx);
7486
+ };
7487
+
7104
7488
  // src/SuiTradingClient.ts
7105
7489
  var SuiTradingClient = class {
7106
7490
  constructor({ apiUser, apiKey, suiNodeUrl, graphQLClient }) {
@@ -7434,6 +7818,15 @@ var SuiTradingClient = class {
7434
7818
  async updateMultiBid(args) {
7435
7819
  return updateMultiBid(args);
7436
7820
  }
7821
+ async sponsorNftListing(args) {
7822
+ const context = {
7823
+ apiUser: this.apiUser,
7824
+ apiKey: this.apiKey,
7825
+ suiClient: this.suiClient,
7826
+ kioskClient: this.kioskClient
7827
+ };
7828
+ return sponsorNftListing(args, context);
7829
+ }
7437
7830
  };
7438
7831
  var SuiTradingClient_default = SuiTradingClient;
7439
7832
  export {