@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/.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/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
@@ -4461,16 +4460,17 @@ var addClaimTransferredNftWithPurchaseCapTx = async ({
4461
4460
  kioskClient,
4462
4461
  nftTokenId,
4463
4462
  nftType,
4464
- sellerKiosk
4463
+ sellerKiosk,
4464
+ preloadedTransferPolicyId
4465
4465
  }) => {
4466
- const transferPolicyId = (await getKioskTransferPolicies(nftType))?.at(0)?.id;
4466
+ const transferPolicyId = preloadedTransferPolicyId ?? (await getKioskTransferPolicies(nftType))?.at(0)?.id;
4467
4467
  const [transferRequest] = tx.moveCall({
4468
4468
  target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::claim_with_purchase_cap",
4469
4469
  arguments: [
4470
4470
  tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
4471
4471
  tx.object(sellerKiosk),
4472
- tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
4473
- tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
4472
+ kioskTx.kiosk,
4473
+ kioskTx.kioskCap,
4474
4474
  tx.pure.address(nftTokenId),
4475
4475
  tx.object(transferPolicyId)
4476
4476
  ],
@@ -5254,6 +5254,27 @@ var fetchNftsByKioskId = import_graphql_request19.gql`
5254
5254
  }
5255
5255
  }
5256
5256
  `;
5257
+ var fetchBulkNftsByKioskId = import_graphql_request19.gql`
5258
+ query fetchNftsByKioskId($where: nfts_bool_exp) {
5259
+ nfts(where: $where) {
5260
+ id
5261
+ name
5262
+ token_id
5263
+ properties
5264
+ chain_state
5265
+ collection_id
5266
+ claimable_reason
5267
+ owner
5268
+ contract {
5269
+ properties
5270
+ }
5271
+ collection {
5272
+ id
5273
+ chain_state
5274
+ }
5275
+ }
5276
+ }
5277
+ `;
5257
5278
 
5258
5279
  // src/methods/transferNfts/addTransferNftTx.ts
5259
5280
  async function addOriginByteTransferNftTx({
@@ -5292,10 +5313,11 @@ async function addTradeportKioskTransferTx({
5292
5313
  kioskTx,
5293
5314
  nftTokenId,
5294
5315
  nftType,
5295
- recipientAddress
5316
+ recipientAddress,
5317
+ transferPolicy
5296
5318
  }) {
5297
- const transferPolicy = (await getKioskTransferPolicies(nftType))?.at(0);
5298
- const hasFloorPriceRule = transferPolicy?.rules?.some(
5319
+ const existingTransferPolicy = transferPolicy ?? (await getKioskTransferPolicies(nftType))?.at(0);
5320
+ const hasFloorPriceRule = existingTransferPolicy?.rules?.some(
5299
5321
  (rule) => rule.type === "floor_price_rule"
5300
5322
  );
5301
5323
  if (hasFloorPriceRule) {
@@ -5388,7 +5410,7 @@ function getTransferPolicyForDirectTransfer(collectionChainState) {
5388
5410
  }
5389
5411
 
5390
5412
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5391
- async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 }, context) {
5413
+ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
5392
5414
  const tx = new import_transactions19.Transaction();
5393
5415
  const res = await gqlChainRequest({
5394
5416
  chain: "sui",
@@ -5445,20 +5467,52 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5445
5467
  }
5446
5468
  }
5447
5469
  const unsharedNativeKiosks = res?.kiosks?.filter((k) => !k.is_shared && !k.is_origin_byte)?.map((k) => k.id);
5470
+ let globalKioskTx;
5471
+ const allNfts = await gqlChainRequest({
5472
+ chain: "sui",
5473
+ query: fetchBulkNftsByKioskId,
5474
+ variables: {
5475
+ where: {
5476
+ _or: unsharedNativeKiosks.map((nk) => ({
5477
+ chain_state: { _contains: { kiosk_id: nk } }
5478
+ }))
5479
+ }
5480
+ }
5481
+ });
5482
+ const formatted = {};
5483
+ allNfts.nfts.forEach((e) => {
5484
+ if (formatted[e.chain_state.kiosk_id]) {
5485
+ formatted[e.chain_state.kiosk_id]?.push(e);
5486
+ } else {
5487
+ formatted[e.chain_state.kiosk_id] = [e];
5488
+ }
5489
+ });
5490
+ const allNftTypes = allNfts.nfts.reduce((acc, curr) => {
5491
+ const type = getNftType({
5492
+ collectionId: curr?.collection?.id,
5493
+ collectionChainState: curr?.collection?.chain_state,
5494
+ nft: curr
5495
+ });
5496
+ if (!acc.includes(type)) acc.push(type);
5497
+ return acc;
5498
+ }, []);
5499
+ const transferPolicies = await Promise.all(
5500
+ allNftTypes.map((type) => getKioskTransferPolicies(type))
5501
+ );
5502
+ const mappedTrasferPolicies = {};
5503
+ transferPolicies.forEach((tp) => {
5504
+ mappedTrasferPolicies[tp.transfer_policies_by_type?.[0]?.type] = tp.transfer_policies_by_type;
5505
+ });
5448
5506
  for (const unsharedNativeKiosk of unsharedNativeKiosks) {
5449
5507
  if (currentMigrationCount >= max) {
5450
5508
  continue;
5451
5509
  }
5452
- const res2 = await gqlChainRequest({
5453
- chain: "sui",
5454
- query: fetchNftsByKioskId,
5455
- variables: { jsonFilter: { kiosk_id: unsharedNativeKiosk } }
5456
- });
5457
- const nfts = res2?.nfts;
5510
+ const nfts = formatted[unsharedNativeKiosk] ?? [];
5458
5511
  if (nfts?.length > 0) {
5459
5512
  currentMigrationCount++;
5460
5513
  }
5461
5514
  for (const nft of nfts) {
5515
+ let existingKioskTx;
5462
5516
  if (nft?.claimable_reason === "offer-transfer") {
5463
5517
  continue;
5464
5518
  }
@@ -5483,7 +5537,8 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5483
5537
  senderAddress: walletAddress,
5484
5538
  recipientAddress: walletAddress,
5485
5539
  nftTokenId,
5486
- nftType
5540
+ nftType,
5541
+ transferPolicy: mappedTrasferPolicies[nftType]?.[0]
5487
5542
  });
5488
5543
  }
5489
5544
  });
@@ -5493,8 +5548,10 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5493
5548
  kioskOwner: walletAddress,
5494
5549
  kiosk: unsharedNativeKiosk,
5495
5550
  kioskStrategy: "exclude",
5551
+ kioskTx: globalKioskTx,
5496
5552
  shouldConvertToPersonalKiosk: true,
5497
5553
  async runCommands(kioskTx) {
5554
+ existingKioskTx = kioskTx;
5498
5555
  await addClaimTransferredNftWithPurchaseCapTx({
5499
5556
  tx,
5500
5557
  kioskTx,
@@ -5505,12 +5562,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
5505
5562
  nftTokenId,
5506
5563
  nftType,
5507
5564
  sellerKiosk: unsharedNativeKiosk,
5508
- seller: nft?.owner
5565
+ seller: nft?.owner,
5566
+ preloadedTransferPolicyId: mappedTrasferPolicies[nftType]?.[0]?.id
5509
5567
  });
5510
5568
  }
5511
5569
  });
5570
+ globalKioskTx = existingKioskTx;
5512
5571
  }
5513
5572
  }
5573
+ globalKioskTx?.finalize();
5514
5574
  return import_transactions19.Transaction.from(tx);
5515
5575
  }
5516
5576