@tradeport/sui-trading-sdk 0.4.3 → 0.4.5

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,17 @@
1
1
  # @tradeport/sui-trading-sdk
2
2
 
3
+ ## 0.4.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 41ffd43: normalize bid nonce IDs across all bid-related operations
8
+
9
+ ## 0.4.4
10
+
11
+ ### Patch Changes
12
+
13
+ - 81db18f: Fix normalizing sui object for removing bids
14
+
3
15
  ## 0.4.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1642,8 +1642,9 @@ var getObjectType = async ({
1642
1642
  suiClient,
1643
1643
  objectId
1644
1644
  }) => {
1645
- if ((0, import_utils.isValidSuiObjectId)(objectId)) {
1646
- const res = await suiClient.getObject({ id: objectId, options: { showType: true } });
1645
+ const normalizedObjectId = objectId.startsWith("0x") ? addLeadingZerosAfter0x(objectId) : objectId;
1646
+ if ((0, import_utils.isValidSuiObjectId)(normalizedObjectId)) {
1647
+ const res = await suiClient.getObject({ id: normalizedObjectId, options: { showType: true } });
1647
1648
  return res.data.type;
1648
1649
  }
1649
1650
  return "";
@@ -2263,7 +2264,7 @@ async function addSingleBidAcceptNftBidTx(txData) {
2263
2264
  arguments: [
2264
2265
  tx.object(import_utils2.SUI_CLOCK_OBJECT_ID),
2265
2266
  tx.object(TRADEPORT_MULTI_BID_STORE),
2266
- tx.pure.id(bidNonce),
2267
+ tx.pure.id((0, import_utils2.normalizeSuiObjectId)(bidNonce)),
2267
2268
  tx.pure.option("id", multiBidChainId),
2268
2269
  tx.object(kioskTx.getKiosk()),
2269
2270
  tx.object(kioskTx.getKioskCap()),
@@ -2292,7 +2293,10 @@ async function addSingleBidAcceptNftBidTx(txData) {
2292
2293
  });
2293
2294
  }
2294
2295
  async function addTradePortAcceptNftBidTxHandler(txData) {
2295
- const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
2296
+ const bidType = await getObjectType({
2297
+ suiClient: txData?.suiClient,
2298
+ objectId: (0, import_utils2.normalizeSuiObjectId)(txData?.bidNonce)
2299
+ });
2296
2300
  if (isSingleBid(bidType)) {
2297
2301
  await addSingleBidAcceptNftBidTx(txData);
2298
2302
  return;
@@ -2560,6 +2564,7 @@ function addTocenUnlistTxHandler(txData) {
2560
2564
  }
2561
2565
 
2562
2566
  // src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts
2567
+ var import_utils3 = require("@mysten/sui/utils");
2563
2568
  function addTradeportAcceptCollectionBidTx({
2564
2569
  tx,
2565
2570
  sharedObjects,
@@ -2726,7 +2731,10 @@ function addTocenAcceptCollectionBidTx({
2726
2731
  });
2727
2732
  }
2728
2733
  async function addTradePortAcceptCollectionBidTxHandler(txData) {
2729
- const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
2734
+ const bidType = await getObjectType({
2735
+ suiClient: txData?.suiClient,
2736
+ objectId: (0, import_utils3.normalizeSuiObjectId)(txData?.bidNonce)
2737
+ });
2730
2738
  if (isSingleBid(bidType)) {
2731
2739
  await addSingleBidAcceptNftBidTx(txData);
2732
2740
  return;
@@ -3063,7 +3071,7 @@ var acceptNftBids = async ({
3063
3071
  var import_transactions6 = require("@mysten/sui/transactions");
3064
3072
 
3065
3073
  // src/methods/buyLocks/buyLocks.ts
3066
- var import_utils3 = require("@mysten/sui.js/utils");
3074
+ var import_utils4 = require("@mysten/sui.js/utils");
3067
3075
  var import_transactions4 = require("@mysten/sui/transactions");
3068
3076
 
3069
3077
  // src/helpers/calculatePremium.ts
@@ -3206,7 +3214,7 @@ async function buyLocks({ lockIds, transaction }, context) {
3206
3214
  typeArguments: [lock.nft_type],
3207
3215
  arguments: [
3208
3216
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
3209
- tx.object(import_utils3.SUI_CLOCK_OBJECT_ID),
3217
+ tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
3210
3218
  tx.pure.id(lock.lock_id),
3211
3219
  tx.pure.u64(lock.maker_price),
3212
3220
  tx.pure.u64(marketplaceFee),
@@ -3220,7 +3228,7 @@ async function buyLocks({ lockIds, transaction }, context) {
3220
3228
  }
3221
3229
 
3222
3230
  // src/methods/exerciseLongLocks/exerciseLongLocks.ts
3223
- var import_utils4 = require("@mysten/sui.js/utils");
3231
+ var import_utils5 = require("@mysten/sui.js/utils");
3224
3232
  var import_transactions5 = require("@mysten/sui/transactions");
3225
3233
  async function exerciseLongLocks({ walletAddress, transaction, locks }, context) {
3226
3234
  const tx = transaction ?? new import_transactions5.Transaction();
@@ -3278,7 +3286,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
3278
3286
  typeArguments: [lock.nft_type],
3279
3287
  arguments: [
3280
3288
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
3281
- tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
3289
+ tx.object(import_utils5.SUI_CLOCK_OBJECT_ID),
3282
3290
  tx.pure.id(lock.lock_id),
3283
3291
  tx.object(lock.chain_state.makerKioskId),
3284
3292
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
@@ -3383,7 +3391,7 @@ async function buyAndExerciseLongLocks({ walletAddress, locks, tx: existingTx },
3383
3391
  var import_transactions9 = require("@mysten/sui/transactions");
3384
3392
 
3385
3393
  // src/methods/exerciseShortLocks/exerciseShortLocks.ts
3386
- var import_utils5 = require("@mysten/sui.js/utils");
3394
+ var import_utils6 = require("@mysten/sui.js/utils");
3387
3395
  var import_transactions8 = require("@mysten/sui/transactions");
3388
3396
 
3389
3397
  // src/graphql/queries/fetchListingsById.ts
@@ -4092,7 +4100,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
4092
4100
  typeArguments: [lock.nft_type],
4093
4101
  arguments: [
4094
4102
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
4095
- tx.object(import_utils5.SUI_CLOCK_OBJECT_ID),
4103
+ tx.object(import_utils6.SUI_CLOCK_OBJECT_ID),
4096
4104
  tx.pure.id(lock.lock_id)
4097
4105
  ]
4098
4106
  });
@@ -4173,7 +4181,7 @@ async function buyAndExerciseShortLocks({ walletAddress, locks, tx: existingTx }
4173
4181
  }
4174
4182
 
4175
4183
  // src/methods/cancelLocks/cancelLocks.ts
4176
- var import_utils6 = require("@mysten/sui.js/utils");
4184
+ var import_utils7 = require("@mysten/sui.js/utils");
4177
4185
  var import_transactions10 = require("@mysten/sui/transactions");
4178
4186
  async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context) {
4179
4187
  const tx = existingTx ?? new import_transactions10.Transaction();
@@ -4196,7 +4204,7 @@ async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context)
4196
4204
  typeArguments: [lock.nft_type],
4197
4205
  arguments: [
4198
4206
  tx.object(TRADEPORT_PRICE_LOCK_STORE),
4199
- tx.object(import_utils6.SUI_CLOCK_OBJECT_ID),
4207
+ tx.object(import_utils7.SUI_CLOCK_OBJECT_ID),
4200
4208
  tx.pure.id(lock.lock_id),
4201
4209
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk)
4202
4210
  ]
@@ -4542,7 +4550,9 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4542
4550
  variables: { ownerAddress: addLeadingZerosAfter0x(walletAddress) }
4543
4551
  });
4544
4552
  const walletAddressKiosks = kiosksByOwnerRes?.kiosks;
4553
+ let globalKioskTx;
4545
4554
  for (const nft of res.nfts) {
4555
+ let existingKioskTx;
4546
4556
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
4547
4557
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
4548
4558
  }
@@ -4591,9 +4601,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4591
4601
  kioskOwner: txData?.claimer,
4592
4602
  kioskOwnerKiosks: walletAddressKiosks,
4593
4603
  kiosk: txData?.sellerKiosk,
4604
+ kioskTx: globalKioskTx,
4594
4605
  shouldConvertToPersonalKiosk: true,
4595
4606
  shouldAllowNftUnsharedKiosk: true,
4596
4607
  async runCommands(kioskTx) {
4608
+ existingKioskTx = kioskTx;
4597
4609
  await addBluemoveClaimAcceptedBidNft({
4598
4610
  ...txData,
4599
4611
  suiClient: context.suiClient,
@@ -4610,9 +4622,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4610
4622
  kioskOwner: txData?.claimer,
4611
4623
  kioskOwnerKiosks: walletAddressKiosks,
4612
4624
  kiosk: txData?.sellerKiosk,
4625
+ kioskTx: globalKioskTx,
4613
4626
  shouldConvertToPersonalKiosk: true,
4614
4627
  shouldAllowNftUnsharedKiosk: true,
4615
4628
  async runCommands(kioskTx) {
4629
+ existingKioskTx = kioskTx;
4616
4630
  await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
4617
4631
  }
4618
4632
  });
@@ -4623,9 +4637,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4623
4637
  kioskOwner: txData?.claimer,
4624
4638
  kioskOwnerKiosks: walletAddressKiosks,
4625
4639
  kiosk: txData?.sellerKiosk,
4640
+ kioskTx: globalKioskTx,
4626
4641
  shouldConvertToPersonalKiosk: true,
4627
4642
  shouldAssertNftInSharedKiosk: true,
4628
4643
  async runCommands(kioskTx) {
4644
+ existingKioskTx = kioskTx;
4629
4645
  await addClaimAcceptedBidNftWithPurchaseCapTx({ ...txData, kioskTx });
4630
4646
  }
4631
4647
  });
@@ -4651,9 +4667,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4651
4667
  kiosk: txData?.sellerKiosk,
4652
4668
  kioskOwnerKiosks: walletAddressKiosks,
4653
4669
  kioskStrategy: "exclude",
4670
+ kioskTx: globalKioskTx,
4654
4671
  shouldConvertToPersonalKiosk: true,
4655
4672
  shouldAllowNftUnsharedKiosk: true,
4656
4673
  async runCommands(kioskTx) {
4674
+ existingKioskTx = kioskTx;
4657
4675
  await addClaimTransferredNftTx({ ...txData, kioskTx });
4658
4676
  }
4659
4677
  });
@@ -4665,15 +4683,19 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4665
4683
  kiosk: txData?.sellerKiosk,
4666
4684
  kioskOwnerKiosks: walletAddressKiosks,
4667
4685
  kioskStrategy: "exclude",
4686
+ kioskTx: globalKioskTx,
4668
4687
  shouldConvertToPersonalKiosk: true,
4669
4688
  shouldAllowNftUnsharedKiosk: true,
4670
4689
  async runCommands(kioskTx) {
4690
+ existingKioskTx = kioskTx;
4671
4691
  await addClaimTransferredNftWithPurchaseCapTx({ ...txData, kioskTx });
4672
4692
  }
4673
4693
  });
4674
4694
  }
4675
4695
  }
4696
+ globalKioskTx = existingKioskTx;
4676
4697
  }
4698
+ globalKioskTx?.finalize();
4677
4699
  return import_transactions13.Transaction.from(tx);
4678
4700
  };
4679
4701
 
@@ -5467,7 +5489,6 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
5467
5489
  }
5468
5490
  }
5469
5491
  const unsharedNativeKiosks = res?.kiosks?.filter((k) => !k.is_shared && !k.is_origin_byte)?.map((k) => k.id);
5470
- let globalKioskTx;
5471
5492
  const allNfts = await gqlChainRequest({
5472
5493
  chain: "sui",
5473
5494
  query: fetchBulkNftsByKioskId,
@@ -5497,12 +5518,13 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
5497
5518
  return acc;
5498
5519
  }, []);
5499
5520
  const transferPolicies = await Promise.all(
5500
- allNftTypes.map((type) => getKioskTransferPolicies(type))
5521
+ allNftTypes.map(async (type) => getKioskTransferPolicies(type))
5501
5522
  );
5502
5523
  const mappedTrasferPolicies = {};
5503
5524
  transferPolicies.forEach((tp) => {
5504
5525
  mappedTrasferPolicies[tp.transfer_policies_by_type?.[0]?.type] = tp.transfer_policies_by_type;
5505
5526
  });
5527
+ let globalKioskTx;
5506
5528
  for (const unsharedNativeKiosk of unsharedNativeKiosks) {
5507
5529
  if (currentMigrationCount >= max) {
5508
5530
  continue;
@@ -5616,7 +5638,7 @@ var fetchCollectionsBySlug = import_graphql_request20.gql`
5616
5638
  `;
5617
5639
 
5618
5640
  // src/methods/placeNftBids/addPlaceNftBidTxs.ts
5619
- var import_utils7 = require("@mysten/sui/utils");
5641
+ var import_utils8 = require("@mysten/sui/utils");
5620
5642
  async function addTradePortPlaceNftBidTxHandler(txData) {
5621
5643
  if (isOriginByteTx(txData?.sharedObjects) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
5622
5644
  throw new Error("OriginByte bidding not supported currently");
@@ -5636,7 +5658,7 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
5636
5658
  if (!bcsHex) {
5637
5659
  throw new Error(`No BCS found for token ${nftTokenId}`);
5638
5660
  }
5639
- bcs3 = (0, import_utils7.fromHex)(bcsHex);
5661
+ bcs3 = (0, import_utils8.fromHex)(bcsHex);
5640
5662
  }
5641
5663
  let multiBidChainId;
5642
5664
  if (existingMultiBidChainId) {
@@ -5676,12 +5698,12 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
5676
5698
  arguments: [
5677
5699
  tx.object(TRADEPORT_MULTI_BID_STORE),
5678
5700
  tx.pure.u64(nftTokenId ? 1 : 0),
5679
- multiBidChainId ? typeof multiBidChainId === "string" ? tx.pure.option("id", (0, import_utils7.normalizeSuiObjectId)(multiBidChainId)) : tx.moveCall({
5701
+ multiBidChainId ? typeof multiBidChainId === "string" ? tx.pure.option("id", (0, import_utils8.normalizeSuiObjectId)(multiBidChainId)) : tx.moveCall({
5680
5702
  target: "0x1::option::some",
5681
5703
  typeArguments: ["0x2::object::ID"],
5682
5704
  arguments: [multiBidChainId]
5683
5705
  }) : void 0,
5684
- tx.pure.option("id", nftTokenId ? (0, import_utils7.normalizeSuiObjectId)(nftTokenId) : void 0),
5706
+ tx.pure.option("id", nftTokenId ? (0, import_utils8.normalizeSuiObjectId)(nftTokenId) : void 0),
5685
5707
  tx.pure.option("vector<u8>", bcs3 ? [...bcs3] : void 0),
5686
5708
  tx.pure.option("u64", expireAt?.getTime()),
5687
5709
  tx.pure.u64(price),
@@ -5879,7 +5901,11 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
5879
5901
  // src/methods/removeCollectionBids/removeCollectionBids.ts
5880
5902
  var import_transactions22 = require("@mysten/sui/transactions");
5881
5903
 
5904
+ // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
5905
+ var import_utils10 = require("@mysten/sui/utils");
5906
+
5882
5907
  // src/methods/removeNftBids/addRemoveNftBidTxs.ts
5908
+ var import_utils9 = require("@mysten/sui/utils");
5883
5909
  function addTradeportRemoveNftBidTx({ tx, bidNonce, nftType }) {
5884
5910
  tx.moveCall({
5885
5911
  target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::cancel_bid",
@@ -5933,13 +5959,16 @@ async function addSingleBidRemoveNftBidTx({ tx, bidNonce, multiBidId }) {
5933
5959
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::cancel_bid`,
5934
5960
  arguments: [
5935
5961
  tx.object(TRADEPORT_MULTI_BID_STORE),
5936
- tx.pure.id(bidNonce),
5962
+ tx.pure.id((0, import_utils9.normalizeSuiObjectId)(bidNonce)),
5937
5963
  tx.pure.option("id", multiBidChainId)
5938
5964
  ]
5939
5965
  });
5940
5966
  }
5941
5967
  async function addTradePortRemoveNftBidTxHandler(txData) {
5942
- const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
5968
+ const bidType = await getObjectType({
5969
+ suiClient: txData?.suiClient,
5970
+ objectId: (0, import_utils9.normalizeSuiObjectId)(txData?.bidNonce)
5971
+ });
5943
5972
  if (isSingleBid(bidType)) {
5944
5973
  await addSingleBidRemoveNftBidTx(txData);
5945
5974
  return;
@@ -6011,8 +6040,12 @@ function addBluemoveKioskRemoveCollectionBidTx({
6011
6040
  async function addTradePortRemoveCollectionBidTxHandler(txData) {
6012
6041
  const bidType = await getObjectType({
6013
6042
  suiClient: txData?.suiClient,
6014
- objectId: txData?.bidNonce
6043
+ objectId: (0, import_utils10.normalizeSuiObjectId)(txData?.bidNonce)
6015
6044
  });
6045
+ if (isSingleBid(bidType)) {
6046
+ await addSingleBidRemoveNftBidTx(txData);
6047
+ return;
6048
+ }
6016
6049
  if (isOriginByteBid(bidType)) {
6017
6050
  const sharedObjects = await getSharedObjects(txData?.nftType);
6018
6051
  addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
@@ -6025,11 +6058,10 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
6025
6058
  addTradeportRemoveCollectionBidTx(txData);
6026
6059
  }
6027
6060
  async function addBluemoveRemoveCollectionBidTxHandler(txData) {
6028
- const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
6029
- if (isSingleBid(bidType)) {
6030
- await addSingleBidRemoveNftBidTx(txData);
6031
- return;
6032
- }
6061
+ const bidType = await getObjectType({
6062
+ suiClient: txData?.suiClient,
6063
+ objectId: (0, import_utils10.normalizeSuiObjectId)(txData?.bidNonce)
6064
+ });
6033
6065
  if (isOriginByteBid(bidType)) {
6034
6066
  const sharedObjects = await getSharedObjects(txData?.nftType);
6035
6067
  addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });