@tradeport/sui-trading-sdk 0.4.2 → 0.4.4

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/.env.demo CHANGED
@@ -1,4 +1,5 @@
1
1
  GRAPHQL_API_USER=
2
2
  GRAPHQL_API_KEY=
3
3
  SUI_WALLET_SECRET_KEY=
4
- SUI_WALLET_PUBLIC_KEY=
4
+ SUI_WALLET_PUBLIC_KEY=
5
+ SUI_RPC_URL=
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tradeport/sui-trading-sdk
2
2
 
3
+ ## 0.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 81db18f: Fix normalizing sui object for removing bids
8
+
3
9
  ## 0.4.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1505,10 +1505,7 @@ var kioskTxWrapper = async ({
1505
1505
  version: ""
1506
1506
  }
1507
1507
  });
1508
- } else if (shouldConvertToPersonalKiosk || kiosks.length === 0) {
1509
- kioskTx = new import_kiosk3.KioskTransaction({ transactionBlock: tx, kioskClient });
1510
- kioskTx.createPersonal(true);
1511
- } else {
1508
+ } else if (kiosks.length > 0 && !shouldConvertToPersonalKiosk) {
1512
1509
  const kioskCapId = (await gqlChainRequest({
1513
1510
  chain: "sui",
1514
1511
  query: fetchOwnerCapByKiosk,
@@ -1525,9 +1522,11 @@ var kioskTxWrapper = async ({
1525
1522
  version: ""
1526
1523
  }
1527
1524
  });
1525
+ } else {
1526
+ kioskTx = new import_kiosk3.KioskTransaction({ transactionBlock: tx, kioskClient });
1527
+ kioskTx.createPersonal(true);
1528
1528
  }
1529
1529
  await runCommands(kioskTx);
1530
- kioskTx.finalize();
1531
1530
  };
1532
1531
 
1533
1532
  // src/helpers/originByte/confirmOBTranfer.ts
@@ -1643,8 +1642,9 @@ var getObjectType = async ({
1643
1642
  suiClient,
1644
1643
  objectId
1645
1644
  }) => {
1646
- if ((0, import_utils.isValidSuiObjectId)(objectId)) {
1647
- 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 } });
1648
1648
  return res.data.type;
1649
1649
  }
1650
1650
  return "";
@@ -4461,16 +4461,17 @@ var addClaimTransferredNftWithPurchaseCapTx = async ({
4461
4461
  kioskClient,
4462
4462
  nftTokenId,
4463
4463
  nftType,
4464
- sellerKiosk
4464
+ sellerKiosk,
4465
+ preloadedTransferPolicyId
4465
4466
  }) => {
4466
- const transferPolicyId = (await getKioskTransferPolicies(nftType))?.at(0)?.id;
4467
+ const transferPolicyId = preloadedTransferPolicyId ?? (await getKioskTransferPolicies(nftType))?.at(0)?.id;
4467
4468
  const [transferRequest] = tx.moveCall({
4468
4469
  target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::claim_with_purchase_cap",
4469
4470
  arguments: [
4470
4471
  tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
4471
4472
  tx.object(sellerKiosk),
4472
- tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
4473
- tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
4473
+ kioskTx.kiosk,
4474
+ kioskTx.kioskCap,
4474
4475
  tx.pure.address(nftTokenId),
4475
4476
  tx.object(transferPolicyId)
4476
4477
  ],
@@ -4542,7 +4543,9 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4542
4543
  variables: { ownerAddress: addLeadingZerosAfter0x(walletAddress) }
4543
4544
  });
4544
4545
  const walletAddressKiosks = kiosksByOwnerRes?.kiosks;
4546
+ let globalKioskTx;
4545
4547
  for (const nft of res.nfts) {
4548
+ let existingKioskTx;
4546
4549
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
4547
4550
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
4548
4551
  }
@@ -4591,9 +4594,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4591
4594
  kioskOwner: txData?.claimer,
4592
4595
  kioskOwnerKiosks: walletAddressKiosks,
4593
4596
  kiosk: txData?.sellerKiosk,
4597
+ kioskTx: globalKioskTx,
4594
4598
  shouldConvertToPersonalKiosk: true,
4595
4599
  shouldAllowNftUnsharedKiosk: true,
4596
4600
  async runCommands(kioskTx) {
4601
+ existingKioskTx = kioskTx;
4597
4602
  await addBluemoveClaimAcceptedBidNft({
4598
4603
  ...txData,
4599
4604
  suiClient: context.suiClient,
@@ -4610,9 +4615,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4610
4615
  kioskOwner: txData?.claimer,
4611
4616
  kioskOwnerKiosks: walletAddressKiosks,
4612
4617
  kiosk: txData?.sellerKiosk,
4618
+ kioskTx: globalKioskTx,
4613
4619
  shouldConvertToPersonalKiosk: true,
4614
4620
  shouldAllowNftUnsharedKiosk: true,
4615
4621
  async runCommands(kioskTx) {
4622
+ existingKioskTx = kioskTx;
4616
4623
  await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
4617
4624
  }
4618
4625
  });
@@ -4623,9 +4630,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4623
4630
  kioskOwner: txData?.claimer,
4624
4631
  kioskOwnerKiosks: walletAddressKiosks,
4625
4632
  kiosk: txData?.sellerKiosk,
4633
+ kioskTx: globalKioskTx,
4626
4634
  shouldConvertToPersonalKiosk: true,
4627
4635
  shouldAssertNftInSharedKiosk: true,
4628
4636
  async runCommands(kioskTx) {
4637
+ existingKioskTx = kioskTx;
4629
4638
  await addClaimAcceptedBidNftWithPurchaseCapTx({ ...txData, kioskTx });
4630
4639
  }
4631
4640
  });
@@ -4651,9 +4660,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4651
4660
  kiosk: txData?.sellerKiosk,
4652
4661
  kioskOwnerKiosks: walletAddressKiosks,
4653
4662
  kioskStrategy: "exclude",
4663
+ kioskTx: globalKioskTx,
4654
4664
  shouldConvertToPersonalKiosk: true,
4655
4665
  shouldAllowNftUnsharedKiosk: true,
4656
4666
  async runCommands(kioskTx) {
4667
+ existingKioskTx = kioskTx;
4657
4668
  await addClaimTransferredNftTx({ ...txData, kioskTx });
4658
4669
  }
4659
4670
  });
@@ -4665,15 +4676,19 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4665
4676
  kiosk: txData?.sellerKiosk,
4666
4677
  kioskOwnerKiosks: walletAddressKiosks,
4667
4678
  kioskStrategy: "exclude",
4679
+ kioskTx: globalKioskTx,
4668
4680
  shouldConvertToPersonalKiosk: true,
4669
4681
  shouldAllowNftUnsharedKiosk: true,
4670
4682
  async runCommands(kioskTx) {
4683
+ existingKioskTx = kioskTx;
4671
4684
  await addClaimTransferredNftWithPurchaseCapTx({ ...txData, kioskTx });
4672
4685
  }
4673
4686
  });
4674
4687
  }
4675
4688
  }
4689
+ globalKioskTx = existingKioskTx;
4676
4690
  }
4691
+ globalKioskTx?.finalize();
4677
4692
  return import_transactions13.Transaction.from(tx);
4678
4693
  };
4679
4694
 
@@ -5254,6 +5269,27 @@ var fetchNftsByKioskId = import_graphql_request19.gql`
5254
5269
  }
5255
5270
  }
5256
5271
  `;
5272
+ var fetchBulkNftsByKioskId = import_graphql_request19.gql`
5273
+ query fetchNftsByKioskId($where: nfts_bool_exp) {
5274
+ nfts(where: $where) {
5275
+ id
5276
+ name
5277
+ token_id
5278
+ properties
5279
+ chain_state
5280
+ collection_id
5281
+ claimable_reason
5282
+ owner
5283
+ contract {
5284
+ properties
5285
+ }
5286
+ collection {
5287
+ id
5288
+ chain_state
5289
+ }
5290
+ }
5291
+ }
5292
+ `;
5257
5293
 
5258
5294
  // src/methods/transferNfts/addTransferNftTx.ts
5259
5295
  async function addOriginByteTransferNftTx({
@@ -5292,10 +5328,11 @@ async function addTradeportKioskTransferTx({
5292
5328
  kioskTx,
5293
5329
  nftTokenId,
5294
5330
  nftType,
5295
- recipientAddress
5331
+ recipientAddress,
5332
+ transferPolicy
5296
5333
  }) {
5297
- const transferPolicy = (await getKioskTransferPolicies(nftType))?.at(0);
5298
- const hasFloorPriceRule = transferPolicy?.rules?.some(
5334
+ const existingTransferPolicy = transferPolicy ?? (await getKioskTransferPolicies(nftType))?.at(0);
5335
+ const hasFloorPriceRule = existingTransferPolicy?.rules?.some(
5299
5336
  (rule) => rule.type === "floor_price_rule"
5300
5337
  );
5301
5338
  if (hasFloorPriceRule) {
@@ -5388,7 +5425,7 @@ function getTransferPolicyForDirectTransfer(collectionChainState) {
5388
5425
  }
5389
5426
 
5390
5427
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5391
- async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 }, context) {
5428
+ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
5392
5429
  const tx = new import_transactions19.Transaction();
5393
5430
  const res = await gqlChainRequest({
5394
5431
  chain: "sui",
@@ -5445,20 +5482,52 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5445
5482
  }
5446
5483
  }
5447
5484
  const unsharedNativeKiosks = res?.kiosks?.filter((k) => !k.is_shared && !k.is_origin_byte)?.map((k) => k.id);
5485
+ const allNfts = await gqlChainRequest({
5486
+ chain: "sui",
5487
+ query: fetchBulkNftsByKioskId,
5488
+ variables: {
5489
+ where: {
5490
+ _or: unsharedNativeKiosks.map((nk) => ({
5491
+ chain_state: { _contains: { kiosk_id: nk } }
5492
+ }))
5493
+ }
5494
+ }
5495
+ });
5496
+ const formatted = {};
5497
+ allNfts.nfts.forEach((e) => {
5498
+ if (formatted[e.chain_state.kiosk_id]) {
5499
+ formatted[e.chain_state.kiosk_id]?.push(e);
5500
+ } else {
5501
+ formatted[e.chain_state.kiosk_id] = [e];
5502
+ }
5503
+ });
5504
+ const allNftTypes = allNfts.nfts.reduce((acc, curr) => {
5505
+ const type = getNftType({
5506
+ collectionId: curr?.collection?.id,
5507
+ collectionChainState: curr?.collection?.chain_state,
5508
+ nft: curr
5509
+ });
5510
+ if (!acc.includes(type)) acc.push(type);
5511
+ return acc;
5512
+ }, []);
5513
+ const transferPolicies = await Promise.all(
5514
+ allNftTypes.map(async (type) => getKioskTransferPolicies(type))
5515
+ );
5516
+ const mappedTrasferPolicies = {};
5517
+ transferPolicies.forEach((tp) => {
5518
+ mappedTrasferPolicies[tp.transfer_policies_by_type?.[0]?.type] = tp.transfer_policies_by_type;
5519
+ });
5520
+ let globalKioskTx;
5448
5521
  for (const unsharedNativeKiosk of unsharedNativeKiosks) {
5449
5522
  if (currentMigrationCount >= max) {
5450
5523
  continue;
5451
5524
  }
5452
- const res2 = await gqlChainRequest({
5453
- chain: "sui",
5454
- query: fetchNftsByKioskId,
5455
- variables: { jsonFilter: { kiosk_id: unsharedNativeKiosk } }
5456
- });
5457
- const nfts = res2?.nfts;
5525
+ const nfts = formatted[unsharedNativeKiosk] ?? [];
5458
5526
  if (nfts?.length > 0) {
5459
5527
  currentMigrationCount++;
5460
5528
  }
5461
5529
  for (const nft of nfts) {
5530
+ let existingKioskTx;
5462
5531
  if (nft?.claimable_reason === "offer-transfer") {
5463
5532
  continue;
5464
5533
  }
@@ -5483,7 +5552,8 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5483
5552
  senderAddress: walletAddress,
5484
5553
  recipientAddress: walletAddress,
5485
5554
  nftTokenId,
5486
- nftType
5555
+ nftType,
5556
+ transferPolicy: mappedTrasferPolicies[nftType]?.[0]
5487
5557
  });
5488
5558
  }
5489
5559
  });
@@ -5493,8 +5563,10 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5493
5563
  kioskOwner: walletAddress,
5494
5564
  kiosk: unsharedNativeKiosk,
5495
5565
  kioskStrategy: "exclude",
5566
+ kioskTx: globalKioskTx,
5496
5567
  shouldConvertToPersonalKiosk: true,
5497
5568
  async runCommands(kioskTx) {
5569
+ existingKioskTx = kioskTx;
5498
5570
  await addClaimTransferredNftWithPurchaseCapTx({
5499
5571
  tx,
5500
5572
  kioskTx,
@@ -5505,12 +5577,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5505
5577
  nftTokenId,
5506
5578
  nftType,
5507
5579
  sellerKiosk: unsharedNativeKiosk,
5508
- seller: nft?.owner
5580
+ seller: nft?.owner,
5581
+ preloadedTransferPolicyId: mappedTrasferPolicies[nftType]?.[0]?.id
5509
5582
  });
5510
5583
  }
5511
5584
  });
5585
+ globalKioskTx = existingKioskTx;
5512
5586
  }
5513
5587
  }
5588
+ globalKioskTx?.finalize();
5514
5589
  return import_transactions19.Transaction.from(tx);
5515
5590
  }
5516
5591