@tradeport/sui-trading-sdk 0.1.29 → 0.1.31

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tradeport/sui-trading-sdk
2
2
 
3
+ ## 0.1.30
4
+
5
+ ### Patch Changes
6
+
7
+ - 443b95b: Added temp fix for older listings to use different market fee
8
+
3
9
  ## 0.1.29
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -708,6 +708,7 @@ function resolveRoyaltyRule({
708
708
  }
709
709
 
710
710
  // src/helpers/kiosk/resolveTransferPolicies.ts
711
+ var originByteRuleModules = ["royalty_strategy_bps", "transfer_allowlist"];
711
712
  var resolveTransferPolicies = async ({
712
713
  tx,
713
714
  kioskTx,
@@ -726,6 +727,13 @@ var resolveTransferPolicies = async ({
726
727
  const transferPolicies = await kioskClient_default.getTransferPolicies({
727
728
  type: normalizedNftType(nftType)
728
729
  });
730
+ if (transferPolicies.length === 0 && (customTransferPolicies ?? []).every(
731
+ (p) => p.transferRequest !== transferRequest
732
+ )) {
733
+ throw new Error(
734
+ `Missing transfer policy of ${nftType}. No way to resolve the transfer request.`
735
+ );
736
+ }
729
737
  let policies = transferPolicies.length > 0 ? [
730
738
  {
731
739
  data: transferPolicies[0],
@@ -759,7 +767,11 @@ var resolveTransferPolicies = async ({
759
767
  if (!rulePackageId) {
760
768
  rulePackageId = rule?.split("::")?.[0];
761
769
  }
762
- switch (rule?.split("::")?.[1]) {
770
+ const moduleName = rule?.split("::")?.[1];
771
+ if (originByteRuleModules.includes(moduleName)) {
772
+ throw new Error(`Using Origin Byte rule ${rule} inside the native kiosk transaction`);
773
+ }
774
+ switch (moduleName) {
763
775
  case "royalty_rule":
764
776
  case "kiosk_royalty_rule":
765
777
  if (shouldSkipResolvingRoyaltyRule)
@@ -767,7 +779,7 @@ var resolveTransferPolicies = async ({
767
779
  resolveRoyaltyRule({
768
780
  tx,
769
781
  packageId: rulePackageId,
770
- moduleName: rule?.split("::")?.[1],
782
+ moduleName,
771
783
  policyId: policy.data.id,
772
784
  transferRequest: policy.transferRequest,
773
785
  nftType: policy.isCustom && policy.type ? policy.type : nftType,
@@ -816,7 +828,6 @@ var resolveTransferPolicies = async ({
816
828
  if (canTransferOutsideKiosk && kioskItem) {
817
829
  kioskTx.place({ itemType: nftType, item: kioskItem });
818
830
  }
819
- console.log({ transferRequest });
820
831
  await beforeResolveKioskTransferRequest?.(transferRequest);
821
832
  for (const policy of policies) {
822
833
  tx.moveCall({
@@ -1777,7 +1788,11 @@ var getDSLLegacyMarketFeePrice = (price) => {
1777
1788
  10
1778
1789
  );
1779
1790
  };
1780
- var getMarketFeePrice = ({ price, collectionId }) => {
1791
+ var getMarketFeePrice = ({
1792
+ price,
1793
+ collectionId,
1794
+ marketFeeDecimalPercent
1795
+ }) => {
1781
1796
  if (collectionId === "6824e1ff-477e-4810-9ba7-8d6387b68c7d") {
1782
1797
  return getBASCMarketFeePrice(price);
1783
1798
  }
@@ -1790,6 +1805,9 @@ var getMarketFeePrice = ({ price, collectionId }) => {
1790
1805
  let marketFeePrice = 0;
1791
1806
  if (!COLLECTION_IDS_WITH_ZERO_COMMISSION?.includes(collectionId)) {
1792
1807
  marketFeePrice = price * TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT;
1808
+ if (marketFeeDecimalPercent) {
1809
+ marketFeePrice = price * marketFeeDecimalPercent;
1810
+ }
1793
1811
  }
1794
1812
  if (marketFeePrice < 1) {
1795
1813
  return marketFeePrice;
@@ -2112,11 +2130,18 @@ var addTradeportKioskBuyTx = async ({
2112
2130
  sellerKiosk,
2113
2131
  coinToSplit,
2114
2132
  collectionId,
2133
+ marketFeeDecimalPercent,
2115
2134
  beforeResolveKioskTransferRequest
2116
2135
  }) => {
2117
- const marketFeePrice = getMarketFeePrice({ price, collectionId });
2136
+ const response = await suiClient_default.getDynamicFieldObject({
2137
+ parentId: TRADEPORT_KIOSK_LISTING_STORE,
2138
+ name: { type: "0x2::object::ID", value: nftTokenId }
2139
+ });
2140
+ if (response.error?.code === "dynamicFieldNotFound") {
2141
+ throw new Error(`Not found kiosk listing object of token ${nftTokenId}`);
2142
+ }
2118
2143
  const coin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [
2119
- tx.pure.u64(price + marketFeePrice)
2144
+ tx.pure.u64(price + Number(response.data.content.fields.commission))
2120
2145
  ]);
2121
2146
  if (!coin)
2122
2147
  throw new Error("Coin could not be split");
@@ -2409,6 +2434,19 @@ async function addTradePortBuyTxHandler(txData) {
2409
2434
  await addOriginByteBuyTx(txData);
2410
2435
  return;
2411
2436
  }
2437
+ if (txData.listingNonce?.startsWith("0x")) {
2438
+ const response = await suiClient_default.getObject({
2439
+ id: txData.listingNonce,
2440
+ options: { showType: true }
2441
+ });
2442
+ if (response.error) {
2443
+ throw new Error(response.error.code);
2444
+ }
2445
+ if (response.data.type === NON_KIOSK_LISTING_NONCE_TYPE) {
2446
+ addTradePortBuyTx(txData);
2447
+ return;
2448
+ }
2449
+ }
2412
2450
  if (txData?.sellerKiosk) {
2413
2451
  return kioskTxWrapper({
2414
2452
  tx: txData?.tx,
@@ -2499,7 +2537,7 @@ var buyListings = async ({
2499
2537
  kioskTx,
2500
2538
  coinToSplit,
2501
2539
  beforeResolveKioskTransferRequest
2502
- }, context) => {
2540
+ }, context, marketFeeDecimalPercent) => {
2503
2541
  const res = await gqlChainRequest({
2504
2542
  chain: "sui",
2505
2543
  query: fetchListingsById,
@@ -2534,6 +2572,7 @@ var buyListings = async ({
2534
2572
  collectionId: listing?.nft?.collection_id,
2535
2573
  nftContractId: listing?.nft?.contract_id,
2536
2574
  coinToSplit,
2575
+ marketFeeDecimalPercent,
2537
2576
  beforeResolveKioskTransferRequest
2538
2577
  };
2539
2578
  switch (listing?.market_name) {