@tradeport/sui-trading-sdk 0.1.92 → 0.1.93

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.93
4
+
5
+ ### Patch Changes
6
+
7
+ - c88bdb6: Fixes for accept collection bids
8
+
3
9
  ## 0.1.92
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -521,7 +521,8 @@ var kioskTxWrapper = async ({
521
521
  shouldConvertToPersonalKiosk,
522
522
  shouldAssertNftInSharedKiosk,
523
523
  shouldUseNftUnsharedKiosk,
524
- kioskStrategy
524
+ kioskStrategy,
525
+ failIfNoKiosk
525
526
  }) => {
526
527
  if (kioskTx) {
527
528
  await runCommands(kioskTx);
@@ -550,6 +551,8 @@ var kioskTxWrapper = async ({
550
551
  }
551
552
  if (filteredKiosks.length > 0) {
552
553
  kiosks = filteredKiosks;
554
+ } else if (failIfNoKiosk ?? false) {
555
+ throw new Error(`Kiosk ${kiosk} not found for account ${kioskOwner}`);
553
556
  }
554
557
  }
555
558
  const personalKiosk = kiosks.find((k) => k.is_personal);
@@ -706,18 +709,16 @@ var shareOriginByteKiosk = async ({ tx, kiosk }) => {
706
709
  };
707
710
 
708
711
  // src/helpers/rpc/getObjectType.ts
712
+ var import_utils = require("@mysten/sui/utils");
709
713
  var getObjectType = async ({
710
714
  suiClient,
711
715
  objectId
712
716
  }) => {
713
- try {
717
+ if ((0, import_utils.isValidSuiObjectId)(objectId)) {
714
718
  const res = await suiClient.getObject({ id: objectId, options: { showType: true } });
715
- console.log("res", res);
716
- return res?.data?.type;
717
- } catch (err) {
718
- console.log("err", err);
719
- return "";
719
+ return res.data.type;
720
720
  }
721
+ return "";
721
722
  };
722
723
 
723
724
  // src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts
@@ -725,36 +726,67 @@ var lockNftInsideKioskIfNotLocked = async ({
725
726
  tx,
726
727
  kioskClient,
727
728
  kioskTx,
728
- sellerKiosk,
729
729
  nftTokenId,
730
730
  nftType,
731
731
  transferPolicyId
732
732
  }) => {
733
- try {
734
- let isLocked = false;
735
- if (sellerKiosk) {
736
- const res = await kioskClient.getKiosk({ id: sellerKiosk });
737
- isLocked = res?.items?.find((i) => i.objectId === nftTokenId)?.isLocked;
738
- }
739
- if (isLocked) return;
740
- const item = kioskTx.take({
741
- itemId: nftTokenId,
742
- itemType: nftType
733
+ if (lockNftInsideKioskIfKioskCreatedInThisTx({ tx, kioskTx, nftTokenId, nftType, transferPolicyId })) {
734
+ return;
735
+ }
736
+ const kioskId = "value" in kioskTx.kiosk ? kioskTx.kiosk.value : "index" in kioskTx.kiosk ? tx.blockData.inputs[kioskTx.kiosk.index].value : (() => {
737
+ throw new Error("Invalid kiosk transaction structure");
738
+ })();
739
+ const res = await kioskClient.getKiosk({ id: kioskId });
740
+ const nftInKiosk = res.items.find((i) => i.objectId === nftTokenId);
741
+ let takeFromKiosk = true;
742
+ if (!nftInKiosk) {
743
+ const result = await kioskClient.client.getObject({
744
+ id: nftTokenId,
745
+ options: { showOwner: true }
743
746
  });
744
- tx.moveCall({
745
- target: "0x2::kiosk::lock",
746
- typeArguments: [nftType],
747
- arguments: [
748
- tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
749
- tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
750
- tx.object(transferPolicyId),
751
- tx.object(item)
752
- ]
747
+ if (result.data.owner.AddressOwner) {
748
+ takeFromKiosk = false;
749
+ } else {
750
+ throw new Error(`NFT ${nftTokenId} is not found in kiosk ${kioskId}`);
751
+ }
752
+ }
753
+ if (!nftInKiosk?.isLocked) {
754
+ let takenNftId;
755
+ if (takeFromKiosk) {
756
+ const takenNft = kioskTx.take({
757
+ itemId: nftTokenId,
758
+ itemType: nftType
759
+ });
760
+ takenNftId = "value" in takenNft ? takenNft.value : takenNft;
761
+ }
762
+ kioskTx.lock({
763
+ itemId: takenNftId ?? nftTokenId,
764
+ itemType: nftType,
765
+ policy: transferPolicyId
753
766
  });
754
- } catch (e) {
755
- console.log("error attempting to lock nft inside kiosk if not locked", e);
756
767
  }
757
768
  };
769
+ function lockNftInsideKioskIfKioskCreatedInThisTx({
770
+ tx,
771
+ kioskTx,
772
+ nftTokenId,
773
+ nftType,
774
+ transferPolicyId
775
+ }) {
776
+ if (Array.isArray(kioskTx.kiosk.NestedResult)) {
777
+ const transaction = tx.blockData.transactions[kioskTx.kiosk.NestedResult[0]];
778
+ if (transaction.target === "0x0000000000000000000000000000000000000000000000000000000000000002::kiosk::new" || transaction.target === "0x0000000000000000000000000000000000000000000000000000000000000002::personal_kiosk::new") {
779
+ kioskTx.lock({
780
+ itemId: nftTokenId,
781
+ itemType: nftType,
782
+ policy: transferPolicyId
783
+ });
784
+ return true;
785
+ }
786
+ throw new Error(`Unsupported kiosk move call ${transaction.target}`);
787
+ }
788
+ return false;
789
+ }
758
790
 
759
791
  // src/helpers/kiosk/resolveTransferPolicies.ts
760
792
  var import_kiosk4 = require("@mysten/kiosk");
@@ -1044,11 +1076,18 @@ async function addTradeportKioskAcceptNftBidTx({
1044
1076
  royaltyRulePackageId,
1045
1077
  royaltyRuleModule,
1046
1078
  bidAmount,
1047
- sellerKiosk,
1048
1079
  shouldSplitRoyaltyFromUserGasCoins,
1049
1080
  beforeResolveKioskTransferRequest
1050
1081
  }) {
1051
1082
  const transferPolicyId = (await getKioskTransferPolicies(nftType))?.at(0)?.id;
1083
+ await lockNftInsideKioskIfNotLocked({
1084
+ tx,
1085
+ kioskClient,
1086
+ kioskTx,
1087
+ nftTokenId,
1088
+ nftType,
1089
+ transferPolicyId
1090
+ });
1052
1091
  if (beforeResolveKioskTransferRequest) {
1053
1092
  const [feeCoin, transferRequest] = tx.moveCall({
1054
1093
  target: "0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_biddings::accept_bid_with_price_lock",
@@ -1074,15 +1113,6 @@ async function addTradeportKioskAcceptNftBidTx({
1074
1113
  });
1075
1114
  tx.transferObjects([tx.object(feeCoin)], tx.pure.address(addLeadingZerosAfter0x(seller)));
1076
1115
  } else {
1077
- await lockNftInsideKioskIfNotLocked({
1078
- tx,
1079
- kioskClient,
1080
- kioskTx,
1081
- sellerKiosk,
1082
- nftTokenId,
1083
- nftType,
1084
- transferPolicyId
1085
- });
1086
1116
  const [feeCoin, transferRequest] = tx.moveCall({
1087
1117
  target: "0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_biddings::accept_bid_with_purchase_cap",
1088
1118
  arguments: [
@@ -1209,6 +1239,7 @@ async function addTradePortAcceptNftBidTxHandler(txData) {
1209
1239
  kiosk: txData?.sellerKiosk,
1210
1240
  shouldConvertToPersonalKiosk: Boolean(await hasPersonalKioskRule(txData?.nftType)),
1211
1241
  shouldAssertNftInSharedKiosk: true,
1242
+ failIfNoKiosk: true,
1212
1243
  async runCommands(kioskTx) {
1213
1244
  await addTradeportKioskAcceptNftBidTx({
1214
1245
  ...txData,
@@ -1640,59 +1671,30 @@ async function addTradePortAcceptCollectionBidTxHandler(txData) {
1640
1671
  });
1641
1672
  }
1642
1673
  if (isTradePortKioskBid(bidType)) {
1643
- if (txData?.sellerKiosk) {
1644
- const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
1645
- const royaltyRulePackageId = await getRulePackageId({
1646
- nftType: txData?.nftType,
1647
- ruleType: "royalty_rule",
1648
- kioskClient: txData?.kioskClient
1649
- });
1650
- return kioskTxWrapper({
1651
- tx: txData?.tx,
1652
- kioskClient: txData?.kioskClient,
1653
- kioskTx: txData?.kioskTx,
1654
- kioskOwner: txData?.itemOwner,
1655
- kiosk: txData?.sellerKiosk,
1656
- shouldConvertToPersonalKiosk: Boolean(await hasPersonalKioskRule(txData?.nftType)),
1657
- shouldAssertNftInSharedKiosk: true,
1658
- async runCommands(kioskTx) {
1659
- await addTradeportKioskAcceptCollectionBidTx({
1660
- ...txData,
1661
- kioskTx,
1662
- royaltyRulePackageId,
1663
- royaltyRuleModule
1664
- });
1665
- }
1666
- });
1667
- }
1668
- if (await hasTransferPolicyRules(txData?.nftType) && !txData?.sellerKiosk) {
1669
- const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
1670
- const royaltyRulePackageId = await getRulePackageId({
1671
- nftType: txData?.nftType,
1672
- ruleType: "royalty_rule",
1673
- kioskClient: txData?.kioskClient
1674
- });
1675
- return kioskTxWrapper({
1676
- tx: txData?.tx,
1677
- kioskClient: txData?.kioskClient,
1678
- kioskTx: txData?.kioskTx,
1679
- kioskOwner: txData?.seller,
1680
- kiosk: txData?.sellerKiosk,
1681
- shouldConvertToPersonalKiosk: Boolean(await hasPersonalKioskRule(txData?.nftType)),
1682
- async runCommands(kioskTx) {
1683
- kioskTx.place({
1684
- item: txData?.nftTokenId,
1685
- itemType: txData?.nftType
1686
- });
1687
- await addTradeportKioskAcceptCollectionBidTx({
1688
- ...txData,
1689
- kioskTx,
1690
- royaltyRulePackageId,
1691
- royaltyRuleModule
1692
- });
1693
- }
1694
- });
1695
- }
1674
+ const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
1675
+ const royaltyRulePackageId = await getRulePackageId({
1676
+ nftType: txData?.nftType,
1677
+ ruleType: "royalty_rule",
1678
+ kioskClient: txData?.kioskClient
1679
+ });
1680
+ return kioskTxWrapper({
1681
+ tx: txData?.tx,
1682
+ kioskClient: txData?.kioskClient,
1683
+ kioskTx: txData?.kioskTx,
1684
+ kioskOwner: txData?.itemOwner,
1685
+ kiosk: txData?.sellerKiosk,
1686
+ shouldConvertToPersonalKiosk: Boolean(await hasPersonalKioskRule(txData?.nftType)),
1687
+ shouldAssertNftInSharedKiosk: true,
1688
+ failIfNoKiosk: Boolean(txData?.sellerKiosk),
1689
+ async runCommands(kioskTx) {
1690
+ await addTradeportKioskAcceptCollectionBidTx({
1691
+ ...txData,
1692
+ kioskTx,
1693
+ royaltyRulePackageId,
1694
+ royaltyRuleModule
1695
+ });
1696
+ }
1697
+ });
1696
1698
  }
1697
1699
  addTradeportAcceptCollectionBidTx(txData);
1698
1700
  }
@@ -1955,7 +1957,7 @@ var acceptNftBids = async ({ bidIds, tx: existingTx, kioskTx, beforeResolveKiosk
1955
1957
  var import_transactions5 = require("@mysten/sui/transactions");
1956
1958
 
1957
1959
  // src/methods/buyLocks/buyLocks.ts
1958
- var import_utils = require("@mysten/sui.js/utils");
1960
+ var import_utils2 = require("@mysten/sui.js/utils");
1959
1961
  var import_transactions3 = require("@mysten/sui/transactions");
1960
1962
 
1961
1963
  // src/helpers/calculatePremium.ts
@@ -2098,7 +2100,7 @@ async function buyLocks({ lockIds, transaction }, context) {
2098
2100
  typeArguments: [lock.nft_type],
2099
2101
  arguments: [
2100
2102
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
2101
- tx.object(import_utils.SUI_CLOCK_OBJECT_ID),
2103
+ tx.object(import_utils2.SUI_CLOCK_OBJECT_ID),
2102
2104
  tx.pure.id(lock.lock_id),
2103
2105
  tx.pure.u64(lock.maker_price),
2104
2106
  tx.pure.u64(marketplaceFee),
@@ -2112,7 +2114,7 @@ async function buyLocks({ lockIds, transaction }, context) {
2112
2114
  }
2113
2115
 
2114
2116
  // src/methods/exerciseLongLocks/exerciseLongLocks.ts
2115
- var import_utils2 = require("@mysten/sui.js/utils");
2117
+ var import_utils3 = require("@mysten/sui.js/utils");
2116
2118
  var import_transactions4 = require("@mysten/sui/transactions");
2117
2119
  async function exerciseLongLocks({ walletAddress, transaction, locks }, context) {
2118
2120
  const tx = transaction ?? new import_transactions4.Transaction();
@@ -2170,7 +2172,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
2170
2172
  typeArguments: [lock.nft_type],
2171
2173
  arguments: [
2172
2174
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
2173
- tx.object(import_utils2.SUI_CLOCK_OBJECT_ID),
2175
+ tx.object(import_utils3.SUI_CLOCK_OBJECT_ID),
2174
2176
  tx.pure.id(lock.lock_id),
2175
2177
  tx.object(lock.chain_state.makerKioskId),
2176
2178
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
@@ -2271,7 +2273,7 @@ async function buyAndExerciseLongLocks({ walletAddress, locks, tx: existingTx },
2271
2273
  var import_transactions8 = require("@mysten/sui/transactions");
2272
2274
 
2273
2275
  // src/methods/exerciseShortLocks/exerciseShortLocks.ts
2274
- var import_utils3 = require("@mysten/sui.js/utils");
2276
+ var import_utils4 = require("@mysten/sui.js/utils");
2275
2277
  var import_transactions7 = require("@mysten/sui/transactions");
2276
2278
 
2277
2279
  // src/graphql/queries/fetchListingsById.ts
@@ -2969,7 +2971,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
2969
2971
  typeArguments: [lock.nft_type],
2970
2972
  arguments: [
2971
2973
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
2972
- tx.object(import_utils3.SUI_CLOCK_OBJECT_ID),
2974
+ tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
2973
2975
  tx.pure.id(lock.lock_id)
2974
2976
  ]
2975
2977
  });
@@ -3048,7 +3050,7 @@ async function buyAndExerciseShortLocks({ walletAddress, locks, tx: existingTx }
3048
3050
  }
3049
3051
 
3050
3052
  // src/methods/cancelLocks/cancelLocks.ts
3051
- var import_utils4 = require("@mysten/sui.js/utils");
3053
+ var import_utils5 = require("@mysten/sui.js/utils");
3052
3054
  var import_transactions9 = require("@mysten/sui/transactions");
3053
3055
  async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context) {
3054
3056
  const tx = existingTx ?? new import_transactions9.Transaction();
@@ -3071,7 +3073,7 @@ async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context)
3071
3073
  typeArguments: [lock.nft_type],
3072
3074
  arguments: [
3073
3075
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
3074
- tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
3076
+ tx.object(import_utils5.SUI_CLOCK_OBJECT_ID),
3075
3077
  tx.pure.id(lock.lock_id),
3076
3078
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk)
3077
3079
  ]
@@ -5374,49 +5376,44 @@ var SuiTradingClient = class {
5374
5376
  }
5375
5377
  });
5376
5378
  const allBidsWithSameHighestPrice = allBidsWithSameHighestPriceRes?.bids;
5377
- for (let i = 0; i < allBidsWithSameHighestPrice?.length; i++) {
5378
- try {
5379
- const tx = await acceptCollectionBid(
5380
- {
5381
- bid: allBidsWithSameHighestPrice?.[i],
5382
- nftId,
5383
- walletAddress
5384
- },
5385
- context
5386
- );
5387
- tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
5388
- const rawTransaction = await tx.build({ client: this.suiClient });
5389
- await this.suiClient.dryRunTransactionBlock({
5390
- transactionBlock: rawTransaction
5391
- });
5379
+ for (let i = 0; i < (allBidsWithSameHighestPrice?.length ?? 0); i++) {
5380
+ const tx = await acceptCollectionBid(
5381
+ {
5382
+ bid: allBidsWithSameHighestPrice?.[i],
5383
+ nftId,
5384
+ walletAddress
5385
+ },
5386
+ context
5387
+ );
5388
+ let result = await this.suiClient.devInspectTransactionBlock({
5389
+ transactionBlock: tx,
5390
+ sender: addLeadingZerosAfter0x(walletAddress)
5391
+ });
5392
+ if (result.effects.status.status === "success") {
5392
5393
  return tx;
5393
- } catch (err) {
5394
- if (i === allBidsWithSameHighestPrice.length - 1) {
5395
- for (let j = 0; j < allBidsWithSameHighestPrice?.length; j++) {
5396
- try {
5397
- const tx = await acceptCollectionBid(
5398
- {
5399
- bid: allBidsWithSameHighestPrice?.[j],
5400
- nftId,
5401
- walletAddress,
5402
- shouldSplitRoyaltyFromUserGasCoins: true
5403
- },
5404
- context
5405
- );
5406
- tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
5407
- const rawTransaction = await tx.build({ client: this.suiClient });
5408
- await this.suiClient.dryRunTransactionBlock({
5409
- transactionBlock: rawTransaction
5410
- });
5411
- return tx;
5412
- } catch (err2) {
5413
- if (j === allBidsWithSameHighestPrice.length - 1) {
5414
- throw err2;
5415
- }
5416
- }
5394
+ }
5395
+ if (i === allBidsWithSameHighestPrice.length - 1) {
5396
+ for (let j = 0; j < allBidsWithSameHighestPrice?.length; j++) {
5397
+ const tx2 = await acceptCollectionBid(
5398
+ {
5399
+ bid: allBidsWithSameHighestPrice?.[j],
5400
+ nftId,
5401
+ walletAddress,
5402
+ shouldSplitRoyaltyFromUserGasCoins: true
5403
+ },
5404
+ context
5405
+ );
5406
+ result = await this.suiClient.devInspectTransactionBlock({
5407
+ transactionBlock: tx2,
5408
+ sender: addLeadingZerosAfter0x(walletAddress)
5409
+ });
5410
+ if (result?.effects.status.status === "success") {
5411
+ return tx2;
5417
5412
  }
5418
- throw err;
5419
5413
  }
5414
+ throw new Error(
5415
+ `Failed to validate accept bid transaction: ${result?.error ?? result?.effects?.status?.error ?? "Unknown error"}`
5416
+ );
5420
5417
  }
5421
5418
  }
5422
5419
  }