@tradeport/sui-trading-sdk 0.4.2 → 0.4.3

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/dist/index.mjs CHANGED
@@ -1479,10 +1479,7 @@ var kioskTxWrapper = async ({
1479
1479
  version: ""
1480
1480
  }
1481
1481
  });
1482
- } else if (shouldConvertToPersonalKiosk || kiosks.length === 0) {
1483
- kioskTx = new KioskTransaction({ transactionBlock: tx, kioskClient });
1484
- kioskTx.createPersonal(true);
1485
- } else {
1482
+ } else if (kiosks.length > 0 && !shouldConvertToPersonalKiosk) {
1486
1483
  const kioskCapId = (await gqlChainRequest({
1487
1484
  chain: "sui",
1488
1485
  query: fetchOwnerCapByKiosk,
@@ -1499,9 +1496,11 @@ var kioskTxWrapper = async ({
1499
1496
  version: ""
1500
1497
  }
1501
1498
  });
1499
+ } else {
1500
+ kioskTx = new KioskTransaction({ transactionBlock: tx, kioskClient });
1501
+ kioskTx.createPersonal(true);
1502
1502
  }
1503
1503
  await runCommands(kioskTx);
1504
- kioskTx.finalize();
1505
1504
  };
1506
1505
 
1507
1506
  // src/helpers/originByte/confirmOBTranfer.ts
@@ -4437,16 +4436,17 @@ var addClaimTransferredNftWithPurchaseCapTx = async ({
4437
4436
  kioskClient,
4438
4437
  nftTokenId,
4439
4438
  nftType,
4440
- sellerKiosk
4439
+ sellerKiosk,
4440
+ preloadedTransferPolicyId
4441
4441
  }) => {
4442
- const transferPolicyId = (await getKioskTransferPolicies(nftType))?.at(0)?.id;
4442
+ const transferPolicyId = preloadedTransferPolicyId ?? (await getKioskTransferPolicies(nftType))?.at(0)?.id;
4443
4443
  const [transferRequest] = tx.moveCall({
4444
4444
  target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::claim_with_purchase_cap",
4445
4445
  arguments: [
4446
4446
  tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
4447
4447
  tx.object(sellerKiosk),
4448
- tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
4449
- tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
4448
+ kioskTx.kiosk,
4449
+ kioskTx.kioskCap,
4450
4450
  tx.pure.address(nftTokenId),
4451
4451
  tx.object(transferPolicyId)
4452
4452
  ],
@@ -5230,6 +5230,27 @@ var fetchNftsByKioskId = gql18`
5230
5230
  }
5231
5231
  }
5232
5232
  `;
5233
+ var fetchBulkNftsByKioskId = gql18`
5234
+ query fetchNftsByKioskId($where: nfts_bool_exp) {
5235
+ nfts(where: $where) {
5236
+ id
5237
+ name
5238
+ token_id
5239
+ properties
5240
+ chain_state
5241
+ collection_id
5242
+ claimable_reason
5243
+ owner
5244
+ contract {
5245
+ properties
5246
+ }
5247
+ collection {
5248
+ id
5249
+ chain_state
5250
+ }
5251
+ }
5252
+ }
5253
+ `;
5233
5254
 
5234
5255
  // src/methods/transferNfts/addTransferNftTx.ts
5235
5256
  async function addOriginByteTransferNftTx({
@@ -5268,10 +5289,11 @@ async function addTradeportKioskTransferTx({
5268
5289
  kioskTx,
5269
5290
  nftTokenId,
5270
5291
  nftType,
5271
- recipientAddress
5292
+ recipientAddress,
5293
+ transferPolicy
5272
5294
  }) {
5273
- const transferPolicy = (await getKioskTransferPolicies(nftType))?.at(0);
5274
- const hasFloorPriceRule = transferPolicy?.rules?.some(
5295
+ const existingTransferPolicy = transferPolicy ?? (await getKioskTransferPolicies(nftType))?.at(0);
5296
+ const hasFloorPriceRule = existingTransferPolicy?.rules?.some(
5275
5297
  (rule) => rule.type === "floor_price_rule"
5276
5298
  );
5277
5299
  if (hasFloorPriceRule) {
@@ -5364,7 +5386,7 @@ function getTransferPolicyForDirectTransfer(collectionChainState) {
5364
5386
  }
5365
5387
 
5366
5388
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5367
- async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 }, context) {
5389
+ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
5368
5390
  const tx = new Transaction19();
5369
5391
  const res = await gqlChainRequest({
5370
5392
  chain: "sui",
@@ -5421,20 +5443,52 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5421
5443
  }
5422
5444
  }
5423
5445
  const unsharedNativeKiosks = res?.kiosks?.filter((k) => !k.is_shared && !k.is_origin_byte)?.map((k) => k.id);
5446
+ let globalKioskTx;
5447
+ const allNfts = await gqlChainRequest({
5448
+ chain: "sui",
5449
+ query: fetchBulkNftsByKioskId,
5450
+ variables: {
5451
+ where: {
5452
+ _or: unsharedNativeKiosks.map((nk) => ({
5453
+ chain_state: { _contains: { kiosk_id: nk } }
5454
+ }))
5455
+ }
5456
+ }
5457
+ });
5458
+ const formatted = {};
5459
+ allNfts.nfts.forEach((e) => {
5460
+ if (formatted[e.chain_state.kiosk_id]) {
5461
+ formatted[e.chain_state.kiosk_id]?.push(e);
5462
+ } else {
5463
+ formatted[e.chain_state.kiosk_id] = [e];
5464
+ }
5465
+ });
5466
+ const allNftTypes = allNfts.nfts.reduce((acc, curr) => {
5467
+ const type = getNftType({
5468
+ collectionId: curr?.collection?.id,
5469
+ collectionChainState: curr?.collection?.chain_state,
5470
+ nft: curr
5471
+ });
5472
+ if (!acc.includes(type)) acc.push(type);
5473
+ return acc;
5474
+ }, []);
5475
+ const transferPolicies = await Promise.all(
5476
+ allNftTypes.map((type) => getKioskTransferPolicies(type))
5477
+ );
5478
+ const mappedTrasferPolicies = {};
5479
+ transferPolicies.forEach((tp) => {
5480
+ mappedTrasferPolicies[tp.transfer_policies_by_type?.[0]?.type] = tp.transfer_policies_by_type;
5481
+ });
5424
5482
  for (const unsharedNativeKiosk of unsharedNativeKiosks) {
5425
5483
  if (currentMigrationCount >= max) {
5426
5484
  continue;
5427
5485
  }
5428
- const res2 = await gqlChainRequest({
5429
- chain: "sui",
5430
- query: fetchNftsByKioskId,
5431
- variables: { jsonFilter: { kiosk_id: unsharedNativeKiosk } }
5432
- });
5433
- const nfts = res2?.nfts;
5486
+ const nfts = formatted[unsharedNativeKiosk] ?? [];
5434
5487
  if (nfts?.length > 0) {
5435
5488
  currentMigrationCount++;
5436
5489
  }
5437
5490
  for (const nft of nfts) {
5491
+ let existingKioskTx;
5438
5492
  if (nft?.claimable_reason === "offer-transfer") {
5439
5493
  continue;
5440
5494
  }
@@ -5459,7 +5513,8 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5459
5513
  senderAddress: walletAddress,
5460
5514
  recipientAddress: walletAddress,
5461
5515
  nftTokenId,
5462
- nftType
5516
+ nftType,
5517
+ transferPolicy: mappedTrasferPolicies[nftType]?.[0]
5463
5518
  });
5464
5519
  }
5465
5520
  });
@@ -5469,8 +5524,10 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5469
5524
  kioskOwner: walletAddress,
5470
5525
  kiosk: unsharedNativeKiosk,
5471
5526
  kioskStrategy: "exclude",
5527
+ kioskTx: globalKioskTx,
5472
5528
  shouldConvertToPersonalKiosk: true,
5473
5529
  async runCommands(kioskTx) {
5530
+ existingKioskTx = kioskTx;
5474
5531
  await addClaimTransferredNftWithPurchaseCapTx({
5475
5532
  tx,
5476
5533
  kioskTx,
@@ -5481,12 +5538,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5481
5538
  nftTokenId,
5482
5539
  nftType,
5483
5540
  sellerKiosk: unsharedNativeKiosk,
5484
- seller: nft?.owner
5541
+ seller: nft?.owner,
5542
+ preloadedTransferPolicyId: mappedTrasferPolicies[nftType]?.[0]?.id
5485
5543
  });
5486
5544
  }
5487
5545
  });
5546
+ globalKioskTx = existingKioskTx;
5488
5547
  }
5489
5548
  }
5549
+ globalKioskTx?.finalize();
5490
5550
  return Transaction19.from(tx);
5491
5551
  }
5492
5552