@tradeport/sui-trading-sdk 0.4.24 → 0.4.26

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.
Files changed (34) hide show
  1. package/dist/index.js +516 -306
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +517 -307
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +1 -1
  6. package/src/graphql/queries/fetchListingsById.ts +1 -0
  7. package/src/helpers/kiosk/assertNftInSharedKiosk.ts +6 -7
  8. package/src/helpers/kiosk/getRulePackageId.ts +12 -10
  9. package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +151 -0
  10. package/src/helpers/kiosk/kioskTxWrapper.ts +18 -18
  11. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +158 -0
  12. package/src/helpers/kiosk/resolveRoyaltyRule.ts +16 -11
  13. package/src/helpers/kiosk/resolveTransferPolicies.ts +36 -124
  14. package/src/helpers/kiosk/sharedKioskState.type.ts +11 -0
  15. package/src/helpers/originByte/getOBKiosk.ts +12 -1
  16. package/src/helpers/originByte/getOrCreateOBKiosk.ts +11 -6
  17. package/src/helpers/originByte/shareOriginByteKiosk.ts +1 -1
  18. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +7 -0
  19. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +5 -5
  20. package/src/methods/acceptNftBids/acceptNftBids.ts +7 -0
  21. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +8 -16
  22. package/src/methods/buyListings/addBuyListingTxs.ts +56 -25
  23. package/src/methods/buyListings/buyListings.ts +25 -1
  24. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +10 -0
  25. package/src/methods/claimNfts/claimNfts.ts +17 -36
  26. package/src/methods/listNfts/addListTxs.ts +7 -1
  27. package/src/methods/listNfts/listNfts.ts +10 -0
  28. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +9 -7
  29. package/src/methods/placeCollectionBids/placeCollectionBids.ts +1 -3
  30. package/src/methods/relistNft/relistNft.ts +15 -3
  31. package/src/methods/transferNfts/addTransferNftTx.ts +7 -2
  32. package/src/methods/transferNfts/transferNfts.ts +18 -2
  33. package/src/methods/unlistListings/addUnlistListingTxs.ts +3 -0
  34. package/src/methods/unlistListings/unlistListings.ts +9 -0
package/dist/index.js CHANGED
@@ -1355,18 +1355,17 @@ var fetchKiosksByOwner = import_graphql_request7.gql`
1355
1355
  var assertNftInSharedKiosk = async ({
1356
1356
  kioskId,
1357
1357
  walletAddress,
1358
- kiosks
1358
+ sharedKioskState
1359
1359
  }) => {
1360
- let kiosksToCheck = kiosks;
1361
- if (!kiosksToCheck) {
1360
+ if (!sharedKioskState?.ownerKiosks) {
1362
1361
  const res = await gqlChainRequest({
1363
1362
  chain: "sui",
1364
1363
  query: fetchKiosksByOwner,
1365
1364
  variables: { ownerAddress: addLeadingZerosAfter0x(walletAddress) }
1366
1365
  });
1367
- kiosksToCheck = res?.kiosks;
1366
+ sharedKioskState.ownerKiosks = res?.kiosks;
1368
1367
  }
1369
- const nftKiosk = kiosksToCheck?.find((k) => k.id === kioskId);
1368
+ const nftKiosk = sharedKioskState?.ownerKiosks?.find((k) => k.id === kioskId);
1370
1369
  if (nftKiosk && !nftKiosk?.is_shared) {
1371
1370
  throw new Error("NFT is inside a kiosk that is not shared");
1372
1371
  }
@@ -1413,13 +1412,8 @@ var getRulePackageId = async ({
1413
1412
  kioskClient,
1414
1413
  suiClient
1415
1414
  }) => {
1416
- const transferPoliciesFromMystenSdk = await kioskClient.getTransferPolicies({
1417
- type: normalizedNftType(nftType)
1418
- });
1419
1415
  let rule;
1420
- if (transferPoliciesFromMystenSdk.length > 0) {
1421
- rule = transferPoliciesFromMystenSdk.flatMap((policy) => policy.rules).filter((rule2) => rule2?.split("::")?.[1] === ruleType)?.[0];
1422
- } else if (transferPolicies.length > 0) {
1416
+ if (transferPolicies.length > 0) {
1423
1417
  const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
1424
1418
  const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
1425
1419
  suiClient,
@@ -1427,7 +1421,14 @@ var getRulePackageId = async ({
1427
1421
  });
1428
1422
  rule = ruleNames.filter((ruleName) => ruleName?.split("::")?.[1] === ruleType)?.[0];
1429
1423
  } else {
1430
- throw new Error(`No transfer policy found for ${nftType}`);
1424
+ const transferPoliciesFromMystenSdk = await kioskClient.getTransferPolicies({
1425
+ type: normalizedNftType(nftType)
1426
+ });
1427
+ if (transferPoliciesFromMystenSdk.length > 0) {
1428
+ rule = transferPoliciesFromMystenSdk.flatMap((policy) => policy.rules).filter((rule2) => rule2?.split("::")?.[1] === ruleType)?.[0];
1429
+ } else {
1430
+ throw new Error(`No transfer policy found for ${nftType}`);
1431
+ }
1431
1432
  }
1432
1433
  const ruleDefinition = kioskClient.rules.find(
1433
1434
  (x) => (0, import_kiosk2.getNormalizedRuleType)(x.rule) === (0, import_kiosk2.getNormalizedRuleType)(rule)
@@ -1474,32 +1475,34 @@ var fetchPersonalCapByKiosk = import_graphql_request9.gql`
1474
1475
  var kioskTxWrapper = async ({
1475
1476
  tx,
1476
1477
  kioskClient,
1477
- kioskTx,
1478
1478
  kioskOwner,
1479
1479
  kiosk,
1480
- kioskOwnerKiosks,
1481
1480
  runCommands,
1482
1481
  shouldConvertToPersonalKiosk,
1483
1482
  shouldAssertNftInSharedKiosk,
1484
1483
  shouldAllowNftUnsharedKiosk,
1485
- shouldSkipFinalize,
1486
1484
  kioskStrategy,
1487
- failIfNoKiosk
1485
+ failIfNoKiosk,
1486
+ sharedKioskState
1488
1487
  }) => {
1489
- if (kioskTx) {
1490
- await runCommands(kioskTx);
1488
+ if (sharedKioskState?.kioskTx) {
1489
+ await runCommands(sharedKioskState.kioskTx);
1491
1490
  return;
1492
1491
  }
1493
1492
  if (!kioskOwner) {
1494
1493
  throw new Error("No kiosk owner provided");
1495
1494
  }
1496
- let kiosks = kioskOwnerKiosks ?? ((await gqlChainRequest({
1495
+ let kioskTx;
1496
+ let kiosks = sharedKioskState?.ownerKiosks ?? ((await gqlChainRequest({
1497
1497
  chain: "sui",
1498
1498
  query: fetchKiosksByOwner,
1499
1499
  variables: { ownerAddress: addLeadingZerosAfter0x(kioskOwner) }
1500
1500
  })).kiosks ?? []);
1501
+ if (sharedKioskState) {
1502
+ sharedKioskState.ownerKiosks = kiosks;
1503
+ }
1501
1504
  if (shouldAssertNftInSharedKiosk) {
1502
- await assertNftInSharedKiosk({ kioskId: kiosk, walletAddress: kioskOwner, kiosks });
1505
+ await assertNftInSharedKiosk({ kioskId: kiosk, walletAddress: kioskOwner, sharedKioskState });
1503
1506
  }
1504
1507
  kiosks = kiosks?.filter((k) => !k.is_origin_byte && (shouldAllowNftUnsharedKiosk || k.is_shared));
1505
1508
  if (kiosk) {
@@ -1559,8 +1562,11 @@ var kioskTxWrapper = async ({
1559
1562
  kioskTx = new import_kiosk3.KioskTransaction({ transactionBlock: tx, kioskClient });
1560
1563
  kioskTx.createPersonal(true);
1561
1564
  }
1565
+ if (sharedKioskState) {
1566
+ sharedKioskState.kioskTx = kioskTx;
1567
+ }
1562
1568
  await runCommands(kioskTx);
1563
- if (!shouldSkipFinalize) {
1569
+ if (!sharedKioskState?.kioskTx) {
1564
1570
  kioskTx.finalize();
1565
1571
  }
1566
1572
  };
@@ -1576,8 +1582,112 @@ var getKioskIdFromKioskTx = ({
1576
1582
  return kioskId;
1577
1583
  };
1578
1584
 
1579
- // src/helpers/kiosk/resolveTransferPolicies.ts
1585
+ // src/helpers/kiosk/getTransferPoliciesToResolve.ts
1580
1586
  var import_kiosk4 = require("@mysten/kiosk");
1587
+ var originByteRuleModules = ["royalty_strategy_bps", "transfer_allowlist"];
1588
+ var getTransferPoliciesToResolve = async ({
1589
+ transferPolicies,
1590
+ suiClient,
1591
+ kioskClient,
1592
+ nftType,
1593
+ customTransferPolicies
1594
+ }) => {
1595
+ let policies = [];
1596
+ if (transferPolicies.length > 0) {
1597
+ const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
1598
+ if (transferPolicyId) {
1599
+ const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
1600
+ suiClient,
1601
+ transferPolicyId
1602
+ });
1603
+ policies = [
1604
+ {
1605
+ id: transferPolicyId,
1606
+ rules: ruleNames?.map((rule) => ({
1607
+ rule
1608
+ })),
1609
+ isCustom: false
1610
+ }
1611
+ ];
1612
+ }
1613
+ } else {
1614
+ const transferPoliciesFromMystenSdk = await kioskClient.getTransferPolicies({
1615
+ type: normalizedNftType(nftType)
1616
+ });
1617
+ if (transferPoliciesFromMystenSdk.length > 0) {
1618
+ const policy = transferPoliciesFromMystenSdk.find(
1619
+ (policy2) => policy2?.rules?.some(
1620
+ (rule) => knownTransferPolicyRules.some((ruleType) => rule?.includes(ruleType))
1621
+ )
1622
+ ) ?? transferPoliciesFromMystenSdk[0];
1623
+ policies = [
1624
+ {
1625
+ id: policy.id,
1626
+ rules: policy.rules?.map((rule) => ({
1627
+ rule
1628
+ })),
1629
+ isCustom: false
1630
+ }
1631
+ ];
1632
+ } else {
1633
+ throw new Error(
1634
+ `Missing transfer policy of ${nftType}. No way to resolve the transfer request.`
1635
+ );
1636
+ }
1637
+ }
1638
+ if (customTransferPolicies) {
1639
+ for (const customTransferPolicy of customTransferPolicies) {
1640
+ const customPolicy = await kioskClient.getTransferPolicies({
1641
+ type: normalizedNftType(customTransferPolicy?.type)
1642
+ });
1643
+ policies = [
1644
+ ...policies,
1645
+ {
1646
+ id: customPolicy[0].id,
1647
+ rules: customPolicy[0].rules?.map((rule) => ({
1648
+ rule
1649
+ })),
1650
+ isCustom: true,
1651
+ type: customTransferPolicy?.type
1652
+ }
1653
+ ];
1654
+ }
1655
+ }
1656
+ return policies.map((policy) => {
1657
+ const kioskLockRule = policy?.rules.find(
1658
+ (rule) => rule?.rule?.includes("kiosk_lock_rule")
1659
+ );
1660
+ const personalKioskRule = policy?.rules.find(
1661
+ (rule) => rule.rule.includes("personal_kiosk_rule")
1662
+ );
1663
+ const otherRules = policy?.rules.filter(
1664
+ (rule) => !rule?.rule?.includes("kiosk_lock_rule") && !rule?.rule?.includes("personal_kiosk_rule")
1665
+ );
1666
+ return {
1667
+ ...policy,
1668
+ rules: [kioskLockRule, personalKioskRule, ...otherRules].filter(Boolean)?.map((ruleData) => {
1669
+ const ruleDefinition = kioskClient.rules.find(
1670
+ (x) => (0, import_kiosk4.getNormalizedRuleType)(x.rule) === (0, import_kiosk4.getNormalizedRuleType)(ruleData.rule)
1671
+ );
1672
+ let rulePackageId = ruleDefinition?.packageId;
1673
+ if (!rulePackageId) {
1674
+ rulePackageId = ruleData?.rule?.split("::")?.[0];
1675
+ }
1676
+ const moduleName = ruleData?.rule?.split("::")?.[1];
1677
+ if (originByteRuleModules.includes(moduleName)) {
1678
+ throw new Error(
1679
+ `Using Origin Byte rule ${ruleData.rule} inside the native kiosk transaction`
1680
+ );
1681
+ }
1682
+ return {
1683
+ ...ruleData,
1684
+ rulePackageId,
1685
+ moduleName
1686
+ };
1687
+ })
1688
+ };
1689
+ });
1690
+ };
1581
1691
 
1582
1692
  // src/helpers/kiosk/resolveFloorPriceRule.ts
1583
1693
  function resolveFloorPriceRule({ tx, packageId, nftType, policyId, transferRequest }) {
@@ -1685,19 +1795,23 @@ async function resolveRoyaltyRule({
1685
1795
  transferRequest,
1686
1796
  nftType,
1687
1797
  price,
1688
- coinToSplit
1798
+ coinToSplit,
1799
+ royaltyFeeAmount
1689
1800
  }) {
1690
- const royaltyFeeAmount = await getKioskCollectionRoyaltyFeeAmount({
1691
- tx,
1692
- suiClient,
1693
- walletAddress,
1694
- royaltyRulePackageId: packageId,
1695
- royaltyRuleModule: moduleName,
1696
- transferPolicyId: policyId,
1697
- price,
1698
- nftType
1699
- });
1700
- const feeCoin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [royaltyFeeAmount]);
1801
+ let feeAmount = royaltyFeeAmount;
1802
+ if (!feeAmount) {
1803
+ feeAmount = await getKioskCollectionRoyaltyFeeAmount({
1804
+ tx,
1805
+ suiClient,
1806
+ walletAddress,
1807
+ royaltyRulePackageId: packageId,
1808
+ royaltyRuleModule: moduleName,
1809
+ transferPolicyId: policyId,
1810
+ price,
1811
+ nftType
1812
+ });
1813
+ }
1814
+ const feeCoin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [feeAmount]);
1701
1815
  tx.moveCall({
1702
1816
  target: `${packageId}::${moduleName}::pay`,
1703
1817
  typeArguments: [nftType],
@@ -1706,7 +1820,6 @@ async function resolveRoyaltyRule({
1706
1820
  }
1707
1821
 
1708
1822
  // src/helpers/kiosk/resolveTransferPolicies.ts
1709
- var originByteRuleModules = ["royalty_strategy_bps", "transfer_allowlist"];
1710
1823
  var resolveTransferPolicies = async ({
1711
1824
  tx,
1712
1825
  transferPolicies,
@@ -1723,102 +1836,28 @@ var resolveTransferPolicies = async ({
1723
1836
  shouldSkipKioskLocking,
1724
1837
  shouldSkipResolvingRoyaltyRule,
1725
1838
  coinToSplit,
1726
- beforeResolveKioskTransferRequest
1839
+ beforeResolveKioskTransferRequest,
1840
+ transferPoliciesToResolve,
1841
+ royaltyFeeAmount
1727
1842
  }) => {
1728
- let policies = [];
1729
- if (transferPolicies.length > 0) {
1730
- const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
1731
- if (transferPolicyId) {
1732
- const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
1733
- suiClient,
1734
- transferPolicyId
1735
- });
1736
- policies = [
1737
- {
1738
- data: {
1739
- id: transferPolicyId,
1740
- rules: ruleNames
1741
- },
1742
- transferRequest,
1743
- isCustom: false
1744
- }
1745
- ];
1746
- }
1747
- } else {
1748
- const transferPoliciesFromMystenSdk = await kioskClient.getTransferPolicies({
1749
- type: normalizedNftType(nftType)
1750
- });
1751
- if (transferPoliciesFromMystenSdk.length > 0) {
1752
- policies = [
1753
- {
1754
- data: (
1755
- // Find first policy with relevant rules, or fall back to first policy
1756
- transferPoliciesFromMystenSdk.find(
1757
- (policy) => policy?.rules?.some(
1758
- (rule) => knownTransferPolicyRules.some((ruleType) => rule?.includes(ruleType))
1759
- )
1760
- ) ?? transferPoliciesFromMystenSdk[0]
1761
- ),
1762
- transferRequest,
1763
- isCustom: false
1764
- }
1765
- ];
1766
- } else if ((customTransferPolicies ?? []).every(
1767
- (p) => p.transferRequest !== transferRequest
1768
- )) {
1769
- throw new Error(
1770
- `Missing transfer policy of ${nftType}. No way to resolve the transfer request.`
1771
- );
1772
- }
1773
- }
1774
- if (customTransferPolicies) {
1775
- for (const customTransferPolicy of customTransferPolicies) {
1776
- const customPolicy = await kioskClient.getTransferPolicies({
1777
- type: normalizedNftType(customTransferPolicy?.type)
1778
- });
1779
- policies = [
1780
- ...policies,
1781
- {
1782
- data: customPolicy[0],
1783
- transferRequest: customTransferPolicy?.transferRequest,
1784
- isCustom: true,
1785
- type: customTransferPolicy?.type
1786
- }
1787
- ];
1788
- }
1789
- }
1790
- let canTransferOutsideKiosk = true;
1843
+ const policies = transferPoliciesToResolve ?? await getTransferPoliciesToResolve({
1844
+ transferPolicies,
1845
+ suiClient,
1846
+ kioskClient,
1847
+ nftType,
1848
+ customTransferPolicies
1849
+ });
1850
+ let hasLockRule = false;
1791
1851
  for (const policy of policies) {
1792
- const kioskLockRule = policy?.data?.rules.find(
1793
- (rule) => rule?.includes("kiosk_lock_rule")
1794
- );
1795
- const personalKioskRule = policy.data.rules.find(
1796
- (rule) => rule.includes("personal_kiosk_rule")
1797
- );
1798
- const otherRules = policy.data.rules.filter(
1799
- (rule) => !rule?.includes("kiosk_lock_rule") && !rule?.includes("personal_kiosk_rule")
1800
- );
1801
- const sortedRules = [kioskLockRule, personalKioskRule, ...otherRules].filter(Boolean);
1802
- for (const rule of sortedRules) {
1803
- const ruleDefinition = kioskClient.rules.find(
1804
- (x) => (0, import_kiosk4.getNormalizedRuleType)(x.rule) === (0, import_kiosk4.getNormalizedRuleType)(rule)
1805
- );
1806
- let rulePackageId = ruleDefinition?.packageId;
1807
- if (!rulePackageId) {
1808
- rulePackageId = rule?.split("::")?.[0];
1809
- }
1810
- const moduleName = rule?.split("::")?.[1];
1811
- if (originByteRuleModules.includes(moduleName)) {
1812
- throw new Error(`Using Origin Byte rule ${rule} inside the native kiosk transaction`);
1813
- }
1814
- switch (moduleName) {
1852
+ for (const rule of policy.rules) {
1853
+ switch (rule.moduleName) {
1815
1854
  case "kiosk_lock_rule":
1816
- canTransferOutsideKiosk = false;
1855
+ hasLockRule = true;
1817
1856
  resolveKioskLockRule({
1818
1857
  tx,
1819
- packageId: rulePackageId,
1820
- policyId: policy.data.id,
1821
- transferRequest: policy.transferRequest,
1858
+ packageId: rule.rulePackageId,
1859
+ policyId: policy.id,
1860
+ transferRequest,
1822
1861
  nftType: policy.isCustom && policy.type ? policy.type : nftType,
1823
1862
  kiosk: kioskToLockRuleProve ? kioskToLockRuleProve : kioskTx.kiosk,
1824
1863
  kioskCap: kioskTx.kioskCap,
@@ -1829,10 +1868,10 @@ var resolveTransferPolicies = async ({
1829
1868
  case "personal_kiosk_rule":
1830
1869
  resolvePersonalKioskRule({
1831
1870
  tx,
1832
- packageId: rulePackageId,
1871
+ packageId: rule.rulePackageId,
1833
1872
  nftType: policy.isCustom && policy.type ? policy.type : nftType,
1834
1873
  kiosk: kioskTx.kiosk,
1835
- transferRequest: policy.transferRequest
1874
+ transferRequest
1836
1875
  });
1837
1876
  break;
1838
1877
  case "royalty_rule":
@@ -1842,37 +1881,38 @@ var resolveTransferPolicies = async ({
1842
1881
  tx,
1843
1882
  suiClient,
1844
1883
  walletAddress,
1845
- packageId: rulePackageId,
1846
- moduleName,
1847
- policyId: policy.data.id,
1848
- transferRequest: policy.transferRequest,
1884
+ packageId: rule.rulePackageId,
1885
+ moduleName: rule.moduleName,
1886
+ policyId: policy.id,
1887
+ transferRequest,
1849
1888
  nftType: policy.isCustom && policy.type ? policy.type : nftType,
1850
1889
  price,
1851
- coinToSplit
1890
+ coinToSplit,
1891
+ royaltyFeeAmount
1852
1892
  });
1853
1893
  break;
1854
1894
  case "floor_price_rule":
1855
1895
  resolveFloorPriceRule({
1856
1896
  tx,
1857
- packageId: rulePackageId,
1897
+ packageId: rule.rulePackageId,
1858
1898
  nftType: policy.isCustom && policy.type ? policy.type : nftType,
1859
- policyId: policy.data.id,
1860
- transferRequest: policy.transferRequest
1899
+ policyId: policy.id,
1900
+ transferRequest
1861
1901
  });
1862
1902
  break;
1863
1903
  default:
1864
- throw new Error(`No resolver for the following rule: ${rule}.`);
1904
+ throw new Error(`No resolver for the following rule: ${rule.rule}.`);
1865
1905
  }
1866
1906
  }
1867
1907
  }
1868
- if (canTransferOutsideKiosk && kioskItem) {
1908
+ if (!hasLockRule && kioskItem) {
1869
1909
  kioskTx.place({ itemType: nftType, item: kioskItem });
1870
1910
  }
1871
1911
  await beforeResolveKioskTransferRequest?.(transferRequest);
1872
1912
  for (const policy of policies) {
1873
1913
  tx.moveCall({
1874
1914
  target: "0x2::transfer_policy::confirm_request",
1875
- arguments: [tx.object(policy.data.id), policy.transferRequest],
1915
+ arguments: [tx.object(policy.id), transferRequest],
1876
1916
  typeArguments: [policy.isCustom && policy.type ? policy.type : nftType]
1877
1917
  });
1878
1918
  }
@@ -2026,12 +2066,18 @@ var fetchWalletKiosks = import_graphql_request10.gql`
2026
2066
  `;
2027
2067
 
2028
2068
  // src/helpers/originByte/getOBKiosk.ts
2029
- var getOBKiosk = async (wallet) => {
2069
+ var getOBKiosk = async ({
2070
+ wallet,
2071
+ sharedKioskState
2072
+ }) => {
2030
2073
  const res = await gqlChainRequest({
2031
2074
  chain: "sui",
2032
2075
  query: fetchWalletKiosks,
2033
2076
  variables: { wallet: addLeadingZerosAfter0x(wallet) }
2034
2077
  });
2078
+ if (!sharedKioskState?.ownerKiosks) {
2079
+ sharedKioskState.ownerKiosks = res?.kiosks;
2080
+ }
2035
2081
  return res?.kiosks?.filter((kiosk) => kiosk?.is_origin_byte && kiosk?.is_shared)?.[0]?.id;
2036
2082
  };
2037
2083
 
@@ -2040,7 +2086,8 @@ var getOrCreateOBKiosk = async ({
2040
2086
  tx,
2041
2087
  address,
2042
2088
  kioskToUseIfExists,
2043
- createMethod
2089
+ createMethod,
2090
+ sharedKioskState
2044
2091
  }) => {
2045
2092
  if (kioskToUseIfExists) {
2046
2093
  return {
@@ -2048,12 +2095,14 @@ var getOrCreateOBKiosk = async ({
2048
2095
  isNewKiosk: false
2049
2096
  };
2050
2097
  }
2051
- const existingKiosk = await getOBKiosk(address);
2052
- if (existingKiosk) {
2053
- return {
2054
- kiosk: existingKiosk,
2055
- isNewKiosk: false
2056
- };
2098
+ if (!sharedKioskState?.ownerKiosks) {
2099
+ const existingKiosk = await getOBKiosk({ wallet: address, sharedKioskState });
2100
+ if (existingKiosk) {
2101
+ return {
2102
+ kiosk: existingKiosk,
2103
+ isNewKiosk: false
2104
+ };
2105
+ }
2057
2106
  }
2058
2107
  const [newKiosk] = await createOBKiosk({ tx, createMethod });
2059
2108
  return {
@@ -2073,7 +2122,7 @@ var isOriginByteCollection = (transferPolicies) => {
2073
2122
  };
2074
2123
 
2075
2124
  // src/helpers/originByte/shareOriginByteKiosk.ts
2076
- var shareOriginByteKiosk = async ({ tx, kiosk }) => {
2125
+ var shareOriginByteKiosk = ({ tx, kiosk }) => {
2077
2126
  tx.moveCall({
2078
2127
  target: "0x2::transfer::public_share_object",
2079
2128
  arguments: [tx.object(kiosk)],
@@ -2375,7 +2424,7 @@ function addBluemoveAcceptNftBidTx({
2375
2424
  });
2376
2425
  }
2377
2426
  async function addSingleBidAcceptNftBidTx(txData) {
2378
- const { nftType, tx, bidNonce, multiBidId, kioskClient, nftTokenId, suiClient } = txData;
2427
+ const { nftType, tx, bidNonce, multiBidId, nftTokenId, suiClient, sharedKioskState } = txData;
2379
2428
  const transferPolicies = getNativeKioskTransferPolicies(txData?.transferPolicies);
2380
2429
  const transferPolicy = transferPolicies?.find(
2381
2430
  (policy) => policy?.rules?.length > 0
@@ -2388,17 +2437,11 @@ async function addSingleBidAcceptNftBidTx(txData) {
2388
2437
  if (multiBidChainId && cancelled_at) {
2389
2438
  throw new Error(`MultiBid ${multiBidId} already cancelled`);
2390
2439
  }
2391
- if (transferPolicy && txData.sellerKiosk) {
2392
- const transferPolicies2 = await kioskClient.getTransferPolicies({
2393
- type: (0, import_utils3.normalizeStructTag)(nftType)
2440
+ if (transferPolicy) {
2441
+ const allRules = await getTransferPolicyRuleNamesFromSuiObject({
2442
+ suiClient,
2443
+ transferPolicyId: transferPolicy.id
2394
2444
  });
2395
- let { rules: allRules } = transferPolicies2.find((p) => p.id === transferPolicy.id);
2396
- if (allRules.length === 0) {
2397
- allRules = await getTransferPolicyRuleNamesFromSuiObject({
2398
- suiClient,
2399
- transferPolicyId: transferPolicy.id
2400
- });
2401
- }
2402
2445
  const unsupportedRule = allRules.find(
2403
2446
  (r) => !knownTransferPolicyRules.includes(r.split("::").at(1))
2404
2447
  );
@@ -2410,9 +2453,9 @@ async function addSingleBidAcceptNftBidTx(txData) {
2410
2453
  return kioskTxWrapper({
2411
2454
  tx: txData?.tx,
2412
2455
  kioskClient: txData?.kioskClient,
2413
- kioskTx: txData?.kioskTx,
2414
2456
  kioskOwner: txData?.seller,
2415
2457
  kiosk: txData?.sellerKiosk,
2458
+ sharedKioskState,
2416
2459
  async runCommands(kioskTx) {
2417
2460
  const [transferRequest] = tx.moveCall({
2418
2461
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::accept_bid_with_transfer_policy`,
@@ -2483,12 +2526,12 @@ async function addTradePortAcceptNftBidTxHandler(txData) {
2483
2526
  return kioskTxWrapper({
2484
2527
  tx: txData?.tx,
2485
2528
  kioskClient: txData?.kioskClient,
2486
- kioskTx: txData?.kioskTx,
2487
2529
  kioskOwner: txData?.itemOwner,
2488
2530
  kiosk: txData?.sellerKiosk,
2489
2531
  shouldConvertToPersonalKiosk: Boolean(hasPersonalKioskRule(txData?.transferPolicies)),
2490
2532
  shouldAssertNftInSharedKiosk: true,
2491
2533
  failIfNoKiosk: true,
2534
+ sharedKioskState: txData?.sharedKioskState,
2492
2535
  async runCommands(kioskTx) {
2493
2536
  await addTradeportKioskAcceptNftBidTx({
2494
2537
  ...txData,
@@ -2656,6 +2699,7 @@ async function addTradePortUnlistTxHandler(txData) {
2656
2699
  kioskOwner: txData?.seller,
2657
2700
  kiosk: txData?.sellerKiosk,
2658
2701
  shouldAllowNftUnsharedKiosk: true,
2702
+ sharedKioskState: txData?.sharedKioskState,
2659
2703
  async runCommands(kioskTx) {
2660
2704
  await addTradePortKioskUnlistTx({
2661
2705
  ...txData,
@@ -2694,6 +2738,7 @@ async function addHyperspaceUnlistTxHandler(txData) {
2694
2738
  kioskOwner: txData?.seller,
2695
2739
  kiosk: txData?.sellerKiosk,
2696
2740
  shouldAllowNftUnsharedKiosk: true,
2741
+ sharedKioskState: txData?.sharedKioskState,
2697
2742
  async runCommands(kioskTx) {
2698
2743
  await addHyperspaceKioskUnlistTx({
2699
2744
  ...txData,
@@ -2715,6 +2760,7 @@ async function addBluemoveUnlistTxHandler(txData) {
2715
2760
  kioskOwner: txData?.seller,
2716
2761
  kiosk: txData?.sellerKiosk,
2717
2762
  shouldAllowNftUnsharedKiosk: true,
2763
+ sharedKioskState: txData?.sharedKioskState,
2718
2764
  async runCommands(kioskTx) {
2719
2765
  await addBluemoveKioskUnlistTx({
2720
2766
  ...txData,
@@ -2843,7 +2889,7 @@ async function addOriginByteAcceptCollectionBidTx(txData) {
2843
2889
  });
2844
2890
  confirmOBTranfer({ tx, sharedObjects, transferRequest, nftType });
2845
2891
  if (isNewKiosk) {
2846
- await shareOriginByteKiosk({ tx, kiosk });
2892
+ shareOriginByteKiosk({ tx, kiosk });
2847
2893
  }
2848
2894
  }
2849
2895
  function addBluemoveAcceptCollectionBidTx({
@@ -2937,10 +2983,10 @@ async function addTradePortAcceptCollectionBidTxHandler(txData) {
2937
2983
  return kioskTxWrapper({
2938
2984
  tx: txData?.tx,
2939
2985
  kioskClient: txData?.kioskClient,
2940
- kioskTx: txData?.kioskTx,
2941
2986
  kioskOwner: txData?.seller,
2942
2987
  kiosk: txData?.sellerKiosk,
2943
2988
  shouldAssertNftInSharedKiosk: true,
2989
+ sharedKioskState: txData?.sharedKioskState,
2944
2990
  async runCommands(kioskTx) {
2945
2991
  const borrowedItem = await takeAndBorrowNftFromKiosk({
2946
2992
  tx: txData?.tx,
@@ -2968,12 +3014,12 @@ async function addTradePortAcceptCollectionBidTxHandler(txData) {
2968
3014
  return kioskTxWrapper({
2969
3015
  tx: txData?.tx,
2970
3016
  kioskClient: txData?.kioskClient,
2971
- kioskTx: txData?.kioskTx,
2972
3017
  kioskOwner: txData?.itemOwner,
2973
3018
  kiosk: txData?.sellerKiosk,
2974
3019
  shouldConvertToPersonalKiosk: Boolean(hasPersonalKioskRule(txData?.transferPolicies)),
2975
3020
  shouldAssertNftInSharedKiosk: true,
2976
3021
  failIfNoKiosk: Boolean(txData?.sellerKiosk),
3022
+ sharedKioskState: txData?.sharedKioskState,
2977
3023
  async runCommands(kioskTx) {
2978
3024
  await addTradeportKioskAcceptCollectionBidTx({
2979
3025
  ...txData,
@@ -3004,10 +3050,10 @@ async function addBluemoveAcceptCollectionBidTxHandler(txData) {
3004
3050
  return kioskTxWrapper({
3005
3051
  tx: txData?.tx,
3006
3052
  kioskClient: txData?.kioskClient,
3007
- kioskTx: txData?.kioskTx,
3008
3053
  kioskOwner: txData?.itemOwner,
3009
3054
  kiosk: txData?.sellerKiosk,
3010
3055
  shouldAssertNftInSharedKiosk: true,
3056
+ sharedKioskState: txData?.sharedKioskState,
3011
3057
  async runCommands(kioskTx) {
3012
3058
  await addBluemoveKioskAcceptCollectionBidTx({
3013
3059
  ...txData,
@@ -3025,10 +3071,10 @@ async function addBluemoveAcceptCollectionBidTxHandler(txData) {
3025
3071
  return kioskTxWrapper({
3026
3072
  tx: txData?.tx,
3027
3073
  kioskClient: txData?.kioskClient,
3028
- kioskTx: txData?.kioskTx,
3029
3074
  kioskOwner: txData?.itemOwner,
3030
3075
  kiosk: txData?.sellerKiosk,
3031
3076
  shouldAssertNftInSharedKiosk: true,
3077
+ sharedKioskState: txData?.sharedKioskState,
3032
3078
  async runCommands(kioskTx) {
3033
3079
  const borrowedItem = await takeAndBorrowNftFromKiosk({
3034
3080
  tx: txData?.tx,
@@ -3076,6 +3122,9 @@ var acceptCollectionBid = async ({
3076
3122
  }
3077
3123
  const bidsForTracking = [];
3078
3124
  const tx = existingTx ?? new import_transactions2.Transaction();
3125
+ const sharedKioskState = {
3126
+ kioskTx: kioskTx ?? void 0
3127
+ };
3079
3128
  const nftType = getNftType({
3080
3129
  collectionId: nft?.collection_id,
3081
3130
  collectionChainState: nft?.collection?.chain_state,
@@ -3088,6 +3137,7 @@ var acceptCollectionBid = async ({
3088
3137
  transferPolicies,
3089
3138
  suiClient: context.suiClient,
3090
3139
  kioskClient: context.kioskClient,
3140
+ sharedKioskState,
3091
3141
  bidNonce: bid?.nonce,
3092
3142
  nftType,
3093
3143
  nftTokenId: nft?.token_id,
@@ -3202,6 +3252,9 @@ var acceptNftBids = async ({
3202
3252
  }
3203
3253
  const bidsForTracking = [];
3204
3254
  const tx = existingTx ?? new import_transactions3.Transaction();
3255
+ const sharedKioskState = {
3256
+ kioskTx: kioskTx ?? void 0
3257
+ };
3205
3258
  for (const bid of res.bids) {
3206
3259
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
3207
3260
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -3224,6 +3277,7 @@ var acceptNftBids = async ({
3224
3277
  const txData = {
3225
3278
  tx,
3226
3279
  kioskTx,
3280
+ sharedKioskState,
3227
3281
  transferPolicies,
3228
3282
  suiClient: context.suiClient,
3229
3283
  kioskClient: context.kioskClient,
@@ -3618,17 +3672,18 @@ async function buyAndExerciseLongLocks({ walletAddress, locks, tx: existingTx },
3618
3672
  }
3619
3673
 
3620
3674
  // src/methods/buyAndExerciseShortLocks/buyAndExerciseShortLocks.ts
3621
- var import_transactions9 = require("@mysten/sui/transactions");
3675
+ var import_transactions10 = require("@mysten/sui/transactions");
3622
3676
 
3623
3677
  // src/methods/exerciseShortLocks/exerciseShortLocks.ts
3624
3678
  var import_utils7 = require("@mysten/sui.js/utils");
3625
- var import_transactions8 = require("@mysten/sui/transactions");
3679
+ var import_transactions9 = require("@mysten/sui/transactions");
3626
3680
 
3627
3681
  // src/graphql/queries/fetchListingsById.ts
3628
3682
  var import_graphql_request15 = require("graphql-request");
3629
3683
  var fetchListingsById = import_graphql_request15.gql`
3630
3684
  query fetchListingsById($listingIds: [uuid!]) {
3631
3685
  listings(where: { id: { _in: $listingIds } }) {
3686
+ id
3632
3687
  seller
3633
3688
  listed
3634
3689
  market_name
@@ -3654,7 +3709,7 @@ var fetchListingsById = import_graphql_request15.gql`
3654
3709
  `;
3655
3710
 
3656
3711
  // src/methods/buyListings/buyListings.ts
3657
- var import_transactions7 = require("@mysten/sui/transactions");
3712
+ var import_transactions8 = require("@mysten/sui/transactions");
3658
3713
 
3659
3714
  // src/helpers/addThirdPartyTxFee.ts
3660
3715
  var addThirdPartyTxFee = async (tx, price) => {
@@ -3667,8 +3722,109 @@ var addThirdPartyTxFee = async (tx, price) => {
3667
3722
  );
3668
3723
  };
3669
3724
 
3670
- // src/methods/buyListings/addBuyListingTxs.ts
3725
+ // src/helpers/kiosk/preProcessSharedBulkBuyingData.ts
3671
3726
  var import_bcs2 = require("@mysten/sui/bcs");
3727
+ var import_transactions7 = require("@mysten/sui/transactions");
3728
+ var preProcessSharedBulkBuyingData = async ({
3729
+ listings,
3730
+ suiClient,
3731
+ kioskClient,
3732
+ walletAddress
3733
+ }) => {
3734
+ const sharedBulkBuyingDataByNftType = {};
3735
+ const listingsByNftType = listings.reduce(
3736
+ (acc, listing) => {
3737
+ const nftType = getNftType({
3738
+ collectionId: listing?.collection?.id,
3739
+ collectionChainState: listing?.collection?.chain_state,
3740
+ nft: listing?.nft
3741
+ });
3742
+ acc[nftType] = [...acc[nftType] || [], listing];
3743
+ return acc;
3744
+ },
3745
+ {}
3746
+ );
3747
+ for (const nftType of Object.keys(listingsByNftType)) {
3748
+ sharedBulkBuyingDataByNftType[nftType] = {
3749
+ sharedObjects: [],
3750
+ transferPoliciesToResolve: [],
3751
+ royaltyFeeAmountsByListingId: {},
3752
+ commissionFeeAmountsByListingId: {}
3753
+ };
3754
+ const transferPolicies = listingsByNftType[nftType]?.[0]?.collection?.chain_state?.transfer_policies;
3755
+ if (isOriginByteCollection(transferPolicies)) {
3756
+ sharedBulkBuyingDataByNftType[nftType].sharedObjects = await getSharedObjects(nftType);
3757
+ continue;
3758
+ }
3759
+ const tradeportKioskListings = listingsByNftType[nftType]?.filter(
3760
+ (listing) => listing.market_name === "tradeport" && listing.price && listing.listed && !(listing?.nonce && isOriginByteCollection(transferPolicies)) && listing.nft?.chain_state?.kiosk_id
3761
+ );
3762
+ if (tradeportKioskListings.length === 0) {
3763
+ continue;
3764
+ }
3765
+ const transferPoliciesToResolve = await getTransferPoliciesToResolve({
3766
+ transferPolicies,
3767
+ suiClient,
3768
+ kioskClient,
3769
+ nftType
3770
+ });
3771
+ sharedBulkBuyingDataByNftType[nftType].transferPoliciesToResolve = transferPoliciesToResolve;
3772
+ const transferPolicyToResolve = transferPoliciesToResolve.at(0);
3773
+ const royaltyRuleToResolve = transferPolicyToResolve.rules.find(
3774
+ (policy) => policy.moduleName === "royalty_rule" || policy.moduleName === "kiosk_royalty_rule"
3775
+ );
3776
+ if (royaltyRuleToResolve?.rulePackageId && royaltyRuleToResolve?.moduleName) {
3777
+ const feeTx = new import_transactions7.Transaction();
3778
+ for (const listing of tradeportKioskListings) {
3779
+ feeTx.moveCall({
3780
+ target: `${royaltyRuleToResolve.rulePackageId}::${royaltyRuleToResolve.moduleName}::fee_amount`,
3781
+ arguments: [feeTx.object(transferPolicyToResolve?.id), feeTx.pure.u64(listing.price)],
3782
+ typeArguments: [nftType]
3783
+ });
3784
+ }
3785
+ const res = await suiClient.devInspectTransactionBlock({
3786
+ sender: addLeadingZerosAfter0x(walletAddress),
3787
+ transactionBlock: feeTx
3788
+ });
3789
+ for (let i = 0; i < res.results.length; i++) {
3790
+ const result = res.results[i];
3791
+ const returnedAmount = result?.returnValues?.[0]?.[0];
3792
+ const feeAmount = BigInt(import_bcs2.bcs.U64.parse(new Uint8Array(returnedAmount)));
3793
+ if (!feeAmount && feeAmount !== 0n) {
3794
+ continue;
3795
+ }
3796
+ sharedBulkBuyingDataByNftType[nftType].royaltyFeeAmountsByListingId[tradeportKioskListings[i].id] = feeAmount;
3797
+ }
3798
+ }
3799
+ const batchSize = 10;
3800
+ const commissionResults = [];
3801
+ for (let i = 0; i < tradeportKioskListings.length; i += batchSize) {
3802
+ const batch = tradeportKioskListings.slice(i, i + batchSize);
3803
+ const batchPromises = batch.map(async (listing) => {
3804
+ const response = await suiClient.getDynamicFieldObject({
3805
+ parentId: TRADEPORT_KIOSK_LISTING_STORE,
3806
+ name: { type: "0x2::object::ID", value: listing.nft.token_id }
3807
+ });
3808
+ if (response.error?.code === "dynamicFieldNotFound") {
3809
+ throw new Error(`Not found kiosk listing object of token ${listing.nft.token_id}`);
3810
+ }
3811
+ return {
3812
+ listingId: listing.id,
3813
+ commission: Number(response.data.content.fields.commission)
3814
+ };
3815
+ });
3816
+ const batchResults = await Promise.all(batchPromises);
3817
+ commissionResults.push(...batchResults);
3818
+ }
3819
+ for (const result of commissionResults) {
3820
+ sharedBulkBuyingDataByNftType[nftType].commissionFeeAmountsByListingId[result.listingId] = result.commission;
3821
+ }
3822
+ }
3823
+ return sharedBulkBuyingDataByNftType;
3824
+ };
3825
+
3826
+ // src/methods/buyListings/addBuyListingTxs.ts
3827
+ var import_bcs3 = require("@mysten/sui/bcs");
3672
3828
 
3673
3829
  // src/graphql/queries/fetchCommissionByListingId.ts
3674
3830
  var import_graphql_request16 = require("graphql-request");
@@ -3749,24 +3905,33 @@ var addTradeportKioskBuyTx = async ({
3749
3905
  kioskTx,
3750
3906
  suiClient,
3751
3907
  kioskClient,
3908
+ listingId,
3752
3909
  nftType,
3753
3910
  nftTokenId,
3754
3911
  price,
3755
3912
  sellerKiosk,
3756
3913
  seller,
3757
3914
  coinToSplit,
3758
- beforeResolveKioskTransferRequest
3915
+ beforeResolveKioskTransferRequest,
3916
+ sharedBulkBuyingDataByNftType,
3917
+ collectionId
3759
3918
  }) => {
3760
- await assertNftInSharedKiosk({ kioskId: sellerKiosk, walletAddress: seller });
3761
- const response = await suiClient.getDynamicFieldObject({
3762
- parentId: TRADEPORT_KIOSK_LISTING_STORE,
3763
- name: { type: "0x2::object::ID", value: nftTokenId }
3764
- });
3765
- if (response.error?.code === "dynamicFieldNotFound") {
3766
- throw new Error(`Not found kiosk listing object of token ${nftTokenId}`);
3919
+ let commissionFeeAmount = sharedBulkBuyingDataByNftType?.[nftType]?.commissionFeeAmountsByListingId?.[listingId] ?? 0;
3920
+ if (!commissionFeeAmount) {
3921
+ const response = await suiClient.getDynamicFieldObject({
3922
+ parentId: TRADEPORT_KIOSK_LISTING_STORE,
3923
+ name: { type: "0x2::object::ID", value: nftTokenId }
3924
+ });
3925
+ if (response.error?.code === "dynamicFieldNotFound") {
3926
+ throw new Error(`Not found kiosk listing object of token ${nftTokenId}`);
3927
+ }
3928
+ commissionFeeAmount = Number(response.data?.content?.fields?.commission);
3929
+ }
3930
+ if (commissionFeeAmount === 0) {
3931
+ commissionFeeAmount = getMarketFeePrice({ price, collectionId });
3767
3932
  }
3768
3933
  const coin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [
3769
- tx.pure.u64(price + Number(response.data.content.fields.commission))
3934
+ tx.pure.u64(price + commissionFeeAmount)
3770
3935
  ]);
3771
3936
  if (!coin) throw new Error("Coin could not be split");
3772
3937
  const [kioskItem, transferRequest] = tx.moveCall({
@@ -3774,7 +3939,7 @@ var addTradeportKioskBuyTx = async ({
3774
3939
  arguments: [
3775
3940
  tx.object(TRADEPORT_KIOSK_LISTING_STORE),
3776
3941
  tx.object(sellerKiosk),
3777
- tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
3942
+ tx.object("value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk),
3778
3943
  tx.pure.address(nftTokenId),
3779
3944
  tx.object(coin)
3780
3945
  ],
@@ -3792,7 +3957,9 @@ var addTradeportKioskBuyTx = async ({
3792
3957
  kioskItem,
3793
3958
  transferRequest,
3794
3959
  coinToSplit,
3795
- beforeResolveKioskTransferRequest
3960
+ beforeResolveKioskTransferRequest,
3961
+ transferPoliciesToResolve: sharedBulkBuyingDataByNftType?.[nftType]?.transferPoliciesToResolve,
3962
+ royaltyFeeAmount: sharedBulkBuyingDataByNftType?.[nftType]?.royaltyFeeAmountsByListingId?.[listingId]
3796
3963
  });
3797
3964
  destroyZeroCoin({ tx, coin });
3798
3965
  };
@@ -3805,13 +3972,19 @@ async function addOriginByteBuyTx({
3805
3972
  nftTokenId,
3806
3973
  nftType,
3807
3974
  listingNonce,
3808
- price
3975
+ price,
3976
+ sharedKioskState
3809
3977
  }) {
3810
- await assertNftInSharedKiosk({ kioskId: sellerKiosk, walletAddress: seller });
3978
+ await assertNftInSharedKiosk({
3979
+ kioskId: sellerKiosk,
3980
+ walletAddress: seller,
3981
+ sharedKioskState
3982
+ });
3811
3983
  const { orderbook } = sharedObjects;
3812
3984
  const { kiosk: buyerKiosk, isNewKiosk: isNewBuyerKiosk } = await getOrCreateOBKiosk({
3813
3985
  tx,
3814
- address: buyer
3986
+ address: buyer,
3987
+ sharedKioskState
3815
3988
  });
3816
3989
  const [coin] = splitCoins({ tx, amounts: [tx.pure.u64(price)] });
3817
3990
  if (!coin) throw new Error("Coin could not be split");
@@ -3830,7 +4003,7 @@ async function addOriginByteBuyTx({
3830
4003
  confirmOBTranfer({ tx, sharedObjects, transferRequest, nftType });
3831
4004
  destroyZeroCoin({ tx, coin });
3832
4005
  if (isNewBuyerKiosk) {
3833
- await shareOriginByteKiosk({ tx, kiosk: buyerKiosk });
4006
+ shareOriginByteKiosk({ tx, kiosk: buyerKiosk });
3834
4007
  }
3835
4008
  }
3836
4009
  var addHyperspaceKioskBuyTx = async ({
@@ -3846,7 +4019,6 @@ var addHyperspaceKioskBuyTx = async ({
3846
4019
  seller,
3847
4020
  beforeResolveKioskTransferRequest
3848
4021
  }) => {
3849
- await assertNftInSharedKiosk({ kioskId: sellerKiosk, walletAddress: seller });
3850
4022
  const [coin] = splitCoins({ tx, amounts: [tx.pure.u64(price)] });
3851
4023
  if (!coin) throw new Error("Coin could not be split");
3852
4024
  const [kioskItem, transferRequest, hyperspaceTransferRequest, hyperspaceMpTransferRequest] = tx.moveCall({
@@ -3863,7 +4035,7 @@ var addHyperspaceKioskBuyTx = async ({
3863
4035
  type: HYPERSPACE_MP_TRANSFER_POLICY_TYPE,
3864
4036
  transferRequest: hyperspaceMpTransferRequest
3865
4037
  }
3866
- ];
4038
+ ].filter((customTransferPolicy) => customTransferPolicy.transferRequest !== transferRequest);
3867
4039
  await beforeResolveKioskTransferRequest?.(transferRequest);
3868
4040
  await resolveTransferPolicies({
3869
4041
  tx,
@@ -3908,7 +4080,6 @@ async function addBluemoveKioskBuyTx({
3908
4080
  seller,
3909
4081
  beforeResolveKioskTransferRequest
3910
4082
  }) {
3911
- await assertNftInSharedKiosk({ kioskId: sellerKiosk, walletAddress: seller });
3912
4083
  const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
3913
4084
  const [coin1, coin2] = splitCoins({
3914
4085
  tx,
@@ -3922,7 +4093,7 @@ async function addBluemoveKioskBuyTx({
3922
4093
  tx.object(BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT),
3923
4094
  tx.object(sellerKiosk),
3924
4095
  tx.object(transferPolicyId),
3925
- tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
4096
+ tx.object("value" in kioskTx.kiosk ? kioskTx.kiosk.value : kioskTx.kiosk),
3926
4097
  tx.pure.address(nftTokenId),
3927
4098
  tx.pure.u64(price),
3928
4099
  tx.object(coin1)
@@ -4062,7 +4233,7 @@ var addTocenBuyTx = ({ tx, nftTokenIds, nftType, price }) => {
4062
4233
  target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::buy_cart",
4063
4234
  arguments: [
4064
4235
  tx.object(TOCEN_MARKETPLACE_OBJECT),
4065
- tx.pure(import_bcs2.bcs.vector(import_bcs2.bcs.Address).serialize(nftTokenIds)),
4236
+ tx.pure(import_bcs3.bcs.vector(import_bcs3.bcs.Address).serialize(nftTokenIds)),
4066
4237
  tx.object(coin)
4067
4238
  ],
4068
4239
  typeArguments: [nftType]
@@ -4070,7 +4241,7 @@ var addTocenBuyTx = ({ tx, nftTokenIds, nftType, price }) => {
4070
4241
  };
4071
4242
  async function addTradePortBuyTxHandler(txData) {
4072
4243
  if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies)) {
4073
- const sharedObjects2 = await getSharedObjects(txData?.nftType);
4244
+ const sharedObjects2 = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4074
4245
  await addOriginByteBuyTx({ ...txData, sharedObjects: sharedObjects2 });
4075
4246
  return;
4076
4247
  }
@@ -4083,7 +4254,7 @@ async function addTradePortBuyTxHandler(txData) {
4083
4254
  throw new Error(response.error.code);
4084
4255
  }
4085
4256
  if (response.data.type === NON_KIOSK_LISTING_NONCE_TYPE) {
4086
- const sharedObjects2 = await getSharedObjects(txData?.nftType);
4257
+ const sharedObjects2 = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4087
4258
  addTradePortBuyTx({ ...txData, sharedObjects: sharedObjects2 });
4088
4259
  return;
4089
4260
  }
@@ -4092,10 +4263,10 @@ async function addTradePortBuyTxHandler(txData) {
4092
4263
  return kioskTxWrapper({
4093
4264
  tx: txData?.tx,
4094
4265
  kioskClient: txData?.kioskClient,
4095
- kioskTx: txData?.kioskTx,
4096
4266
  kioskOwner: txData?.buyer,
4097
4267
  kiosk: txData?.sellerKiosk,
4098
4268
  shouldConvertToPersonalKiosk: true,
4269
+ sharedKioskState: txData?.sharedKioskState,
4099
4270
  async runCommands(kioskTx) {
4100
4271
  await addTradeportKioskBuyTx({
4101
4272
  ...txData,
@@ -4104,22 +4275,22 @@ async function addTradePortBuyTxHandler(txData) {
4104
4275
  }
4105
4276
  });
4106
4277
  }
4107
- const sharedObjects = await getSharedObjects(txData?.nftType);
4278
+ const sharedObjects = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4108
4279
  addTradePortBuyTx({ ...txData, sharedObjects });
4109
4280
  }
4110
4281
  async function addHyperspaceBuyTxHandler(txData) {
4111
4282
  if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies)) {
4112
- const sharedObjects = await getSharedObjects(txData?.nftType);
4283
+ const sharedObjects = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4113
4284
  await addOriginByteBuyTx({ ...txData, sharedObjects });
4114
4285
  return;
4115
4286
  }
4116
4287
  return kioskTxWrapper({
4117
4288
  tx: txData?.tx,
4118
4289
  kioskClient: txData?.kioskClient,
4119
- kioskTx: txData?.kioskTx,
4120
4290
  kioskOwner: txData?.buyer,
4121
4291
  kiosk: txData?.sellerKiosk,
4122
4292
  shouldConvertToPersonalKiosk: true,
4293
+ sharedKioskState: txData?.sharedKioskState,
4123
4294
  async runCommands(kioskTx) {
4124
4295
  await addHyperspaceKioskBuyTx({
4125
4296
  ...txData,
@@ -4130,7 +4301,7 @@ async function addHyperspaceBuyTxHandler(txData) {
4130
4301
  }
4131
4302
  async function addBluemoveBuyTxHandler(txData) {
4132
4303
  if (txData?.listingNonce && isOriginByteCollection(txData?.transferPolicies)) {
4133
- const sharedObjects = await getSharedObjects(txData?.nftType);
4304
+ const sharedObjects = txData?.sharedBulkBuyingDataByNftType?.[txData?.nftType]?.sharedObjects ?? await getSharedObjects(txData?.nftType);
4134
4305
  await addOriginByteBuyTx({ ...txData, sharedObjects });
4135
4306
  return;
4136
4307
  }
@@ -4138,10 +4309,10 @@ async function addBluemoveBuyTxHandler(txData) {
4138
4309
  return kioskTxWrapper({
4139
4310
  tx: txData?.tx,
4140
4311
  kioskClient: txData?.kioskClient,
4141
- kioskTx: txData?.kioskTx,
4142
4312
  kioskOwner: txData?.buyer,
4143
4313
  kiosk: txData?.sellerKiosk,
4144
4314
  shouldConvertToPersonalKiosk: true,
4315
+ sharedKioskState: txData?.sharedKioskState,
4145
4316
  async runCommands(kioskTx) {
4146
4317
  await addBluemoveKioskBuyTx({
4147
4318
  ...txData,
@@ -4194,10 +4365,22 @@ var buyListings = async ({
4194
4365
  throw new Error("No listings found");
4195
4366
  }
4196
4367
  const listingsForTracking = [];
4197
- const tx = existingTx ?? new import_transactions7.Transaction();
4368
+ const tx = existingTx ?? new import_transactions8.Transaction();
4198
4369
  const tocenTokenIds = [];
4199
4370
  let tocenNftType = "";
4200
4371
  let tocenTotalPrice = 0;
4372
+ const sharedKioskState = {
4373
+ kioskTx: kioskTx ?? void 0
4374
+ };
4375
+ let sharedBulkBuyingDataByNftType;
4376
+ if (res.listings.length > 1) {
4377
+ sharedBulkBuyingDataByNftType = await preProcessSharedBulkBuyingData({
4378
+ listings: res.listings,
4379
+ suiClient: context.suiClient,
4380
+ kioskClient: context.kioskClient,
4381
+ walletAddress
4382
+ });
4383
+ }
4201
4384
  for (const listing of res.listings) {
4202
4385
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(listing?.nft?.token_id)) {
4203
4386
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -4229,7 +4412,9 @@ var buyListings = async ({
4229
4412
  nftContractId: listing?.nft?.contract_id,
4230
4413
  coinToSplit,
4231
4414
  marketFeeDecimalPercent,
4232
- beforeResolveKioskTransferRequest
4415
+ beforeResolveKioskTransferRequest,
4416
+ sharedKioskState,
4417
+ sharedBulkBuyingDataByNftType
4233
4418
  };
4234
4419
  switch (listing?.market_name) {
4235
4420
  case "tradeport":
@@ -4273,6 +4458,7 @@ var buyListings = async ({
4273
4458
  marketName: listing?.market_name
4274
4459
  });
4275
4460
  }
4461
+ sharedKioskState?.kioskTx?.finalize();
4276
4462
  if (tocenTokenIds?.length > 0) {
4277
4463
  addTocenBuyTxHandler({
4278
4464
  tx,
@@ -4281,12 +4467,12 @@ var buyListings = async ({
4281
4467
  price: tocenTotalPrice
4282
4468
  });
4283
4469
  }
4284
- return import_transactions7.Transaction.from(tx);
4470
+ return import_transactions8.Transaction.from(tx);
4285
4471
  };
4286
4472
 
4287
4473
  // src/methods/exerciseShortLocks/exerciseShortLocks.ts
4288
4474
  async function exerciseShortLocks({ walletAddress, transaction, locks }, context) {
4289
- const tx = transaction ?? new import_transactions8.Transaction();
4475
+ const tx = transaction ?? new import_transactions9.Transaction();
4290
4476
  for (const { id: lockId, listingId, nftId: nftIdArg } of locks) {
4291
4477
  const lock = await getLockById(lockId);
4292
4478
  if (!transaction && lock.state !== "bought") {
@@ -4424,7 +4610,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
4424
4610
 
4425
4611
  // src/methods/buyAndExerciseShortLocks/buyAndExerciseShortLocks.ts
4426
4612
  async function buyAndExerciseShortLocks({ walletAddress, locks, tx: existingTx }, context) {
4427
- const transaction = existingTx ?? new import_transactions9.Transaction();
4613
+ const transaction = existingTx ?? new import_transactions10.Transaction();
4428
4614
  await buyLocks({ lockIds: locks?.map((lock) => lock?.id), transaction }, context);
4429
4615
  await exerciseShortLocks({ locks, walletAddress, transaction }, context);
4430
4616
  return transaction;
@@ -4432,9 +4618,9 @@ async function buyAndExerciseShortLocks({ walletAddress, locks, tx: existingTx }
4432
4618
 
4433
4619
  // src/methods/cancelLocks/cancelLocks.ts
4434
4620
  var import_utils8 = require("@mysten/sui.js/utils");
4435
- var import_transactions10 = require("@mysten/sui/transactions");
4621
+ var import_transactions11 = require("@mysten/sui/transactions");
4436
4622
  async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context) {
4437
- const tx = existingTx ?? new import_transactions10.Transaction();
4623
+ const tx = existingTx ?? new import_transactions11.Transaction();
4438
4624
  for (const lockId of lockIds) {
4439
4625
  const lock = await getLockById(lockId);
4440
4626
  if (!lock) {
@@ -4466,7 +4652,7 @@ async function cancelLocks({ lockIds, walletAddress, tx: existingTx }, context)
4466
4652
  }
4467
4653
 
4468
4654
  // src/methods/cancelMultiBid/cancelMultiBid.ts
4469
- var import_transactions11 = require("@mysten/sui/transactions");
4655
+ var import_transactions12 = require("@mysten/sui/transactions");
4470
4656
  async function cancelMultiBid({ multiBidId }) {
4471
4657
  const { chain_id: multiBidChainId, cancelled_at } = (await gqlChainRequest({
4472
4658
  chain: "sui",
@@ -4479,7 +4665,7 @@ async function cancelMultiBid({ multiBidId }) {
4479
4665
  if (cancelled_at) {
4480
4666
  throw new Error(`MultiBid ${multiBidId} already cancelled`);
4481
4667
  }
4482
- const tx = new import_transactions11.Transaction();
4668
+ const tx = new import_transactions12.Transaction();
4483
4669
  tx.moveCall({
4484
4670
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::cancel_multi_bid`,
4485
4671
  arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.id(multiBidChainId)]
@@ -4488,7 +4674,7 @@ async function cancelMultiBid({ multiBidId }) {
4488
4674
  }
4489
4675
 
4490
4676
  // src/methods/cancelNftTransfers/cancelNftTransfers.ts
4491
- var import_transactions12 = require("@mysten/sui/transactions");
4677
+ var import_transactions13 = require("@mysten/sui/transactions");
4492
4678
 
4493
4679
  // src/graphql/queries/fetchAccountKiosks.ts
4494
4680
  var import_graphql_request17 = require("graphql-request");
@@ -4542,7 +4728,10 @@ var cancelNftTransfers = async ({ nftIds, walletAddress }, context) => {
4542
4728
  throw new Error("No nfts found");
4543
4729
  }
4544
4730
  const nftsForTracking = [];
4545
- const tx = new import_transactions12.Transaction();
4731
+ const tx = new import_transactions13.Transaction();
4732
+ const sharedKioskState = {
4733
+ kioskTx: void 0
4734
+ };
4546
4735
  for (const nft of res.nfts) {
4547
4736
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
4548
4737
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -4558,6 +4747,7 @@ var cancelNftTransfers = async ({ nftIds, walletAddress }, context) => {
4558
4747
  const sharedObjects = await getSharedObjects(nftType);
4559
4748
  const txData = {
4560
4749
  tx,
4750
+ sharedKioskState,
4561
4751
  nftType,
4562
4752
  nftTokenId: nft?.token_id,
4563
4753
  senderKiosk: nft?.chain_state?.kiosk_id,
@@ -4574,16 +4764,18 @@ var cancelNftTransfers = async ({ nftIds, walletAddress }, context) => {
4574
4764
  kioskOwner: txData?.senderAddress,
4575
4765
  kiosk: txData?.senderKiosk,
4576
4766
  shouldAllowNftUnsharedKiosk: true,
4767
+ sharedKioskState: txData?.sharedKioskState,
4577
4768
  async runCommands(kioskTx) {
4578
4769
  await addTradeportKioskCancelNftTransferTx({ ...txData, kioskTx });
4579
4770
  }
4580
4771
  });
4581
4772
  }
4582
- return import_transactions12.Transaction.from(tx);
4773
+ sharedKioskState?.kioskTx?.finalize();
4774
+ return import_transactions13.Transaction.from(tx);
4583
4775
  };
4584
4776
 
4585
4777
  // src/methods/claimNfts/claimNfts.ts
4586
- var import_transactions13 = require("@mysten/sui/transactions");
4778
+ var import_transactions14 = require("@mysten/sui/transactions");
4587
4779
 
4588
4780
  // src/methods/claimNfts/addClaimNftsTxs.ts
4589
4781
  var addClaimTradeHoldTx = ({
@@ -4802,16 +4994,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4802
4994
  throw new Error("No nfts found");
4803
4995
  }
4804
4996
  const nftsForTracking = [];
4805
- const tx = existingTx ?? new import_transactions13.Transaction();
4806
- const kiosksByOwnerRes = await gqlChainRequest({
4807
- chain: "sui",
4808
- query: fetchKiosksByOwner,
4809
- variables: { ownerAddress: addLeadingZerosAfter0x(walletAddress) }
4810
- });
4811
- const walletAddressKiosks = kiosksByOwnerRes?.kiosks;
4812
- let globalKioskTx;
4997
+ const tx = existingTx ?? new import_transactions14.Transaction();
4998
+ const sharedKioskState = {
4999
+ kioskTx: void 0
5000
+ };
4813
5001
  for (const nft of res.nfts) {
4814
- let existingKioskTx;
4815
5002
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
4816
5003
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
4817
5004
  }
@@ -4835,7 +5022,8 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4835
5022
  nftType,
4836
5023
  claimableTradeId: nft?.chain_state?.claimable_trade_id,
4837
5024
  claimableSellerKiosk: nft?.chain_state?.claimable_seller_kiosk,
4838
- claimableBuyerKiosk: nft?.chain_state?.claimable_buyer_kiosk
5025
+ claimableBuyerKiosk: nft?.chain_state?.claimable_buyer_kiosk,
5026
+ sharedKioskState
4839
5027
  };
4840
5028
  const sharedObjects = await getSharedObjects(nftType);
4841
5029
  addClaimTradeHoldTx({ ...txData, sharedObjects });
@@ -4848,6 +5036,7 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4848
5036
  tx,
4849
5037
  suiClient: context.suiClient,
4850
5038
  kioskClient: context.kioskClient,
5039
+ sharedKioskState,
4851
5040
  transferPolicies,
4852
5041
  claimer: walletAddress,
4853
5042
  nftType,
@@ -4860,14 +5049,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4860
5049
  tx,
4861
5050
  kioskClient: context.kioskClient,
4862
5051
  kioskOwner: txData?.claimer,
4863
- kioskOwnerKiosks: walletAddressKiosks,
4864
5052
  kiosk: txData?.sellerKiosk,
4865
- kioskTx: globalKioskTx,
4866
5053
  shouldConvertToPersonalKiosk: true,
4867
5054
  shouldAllowNftUnsharedKiosk: true,
4868
- shouldSkipFinalize: true,
5055
+ sharedKioskState,
4869
5056
  async runCommands(kioskTx) {
4870
- existingKioskTx = kioskTx;
4871
5057
  await addBluemoveClaimAcceptedBidNft({
4872
5058
  ...txData,
4873
5059
  suiClient: context.suiClient,
@@ -4875,7 +5061,6 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4875
5061
  });
4876
5062
  }
4877
5063
  });
4878
- globalKioskTx = existingKioskTx;
4879
5064
  continue;
4880
5065
  }
4881
5066
  if (useOldClaim) {
@@ -4883,14 +5068,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4883
5068
  tx,
4884
5069
  kioskClient: context.kioskClient,
4885
5070
  kioskOwner: txData?.claimer,
4886
- kioskOwnerKiosks: walletAddressKiosks,
4887
5071
  kiosk: txData?.sellerKiosk,
4888
- kioskTx: globalKioskTx,
4889
5072
  shouldConvertToPersonalKiosk: true,
4890
5073
  shouldAllowNftUnsharedKiosk: true,
4891
- shouldSkipFinalize: true,
5074
+ sharedKioskState,
4892
5075
  async runCommands(kioskTx) {
4893
- existingKioskTx = kioskTx;
4894
5076
  await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
4895
5077
  }
4896
5078
  });
@@ -4899,19 +5081,15 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4899
5081
  tx,
4900
5082
  kioskClient: context.kioskClient,
4901
5083
  kioskOwner: txData?.claimer,
4902
- kioskOwnerKiosks: walletAddressKiosks,
4903
5084
  kiosk: txData?.sellerKiosk,
4904
- kioskTx: globalKioskTx,
4905
5085
  shouldConvertToPersonalKiosk: true,
4906
5086
  shouldAssertNftInSharedKiosk: true,
4907
- shouldSkipFinalize: true,
5087
+ sharedKioskState,
4908
5088
  async runCommands(kioskTx) {
4909
- existingKioskTx = kioskTx;
4910
5089
  await addClaimAcceptedBidNftWithPurchaseCapTx({ ...txData, kioskTx });
4911
5090
  }
4912
5091
  });
4913
5092
  }
4914
- globalKioskTx = existingKioskTx;
4915
5093
  continue;
4916
5094
  }
4917
5095
  if (nft?.chain_state?.claimable_reason === "offer-transfer") {
@@ -4924,7 +5102,8 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4924
5102
  nftType,
4925
5103
  nftTokenId: nft?.token_id,
4926
5104
  sellerKiosk: nft?.chain_state?.kiosk_id,
4927
- seller: nft?.owner
5105
+ seller: nft?.owner,
5106
+ sharedKioskState
4928
5107
  };
4929
5108
  if (useOldClaim) {
4930
5109
  await kioskTxWrapper({
@@ -4932,14 +5111,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4932
5111
  kioskClient: context.kioskClient,
4933
5112
  kioskOwner: txData?.claimer,
4934
5113
  kiosk: txData?.sellerKiosk,
4935
- kioskOwnerKiosks: walletAddressKiosks,
4936
5114
  kioskStrategy: "exclude",
4937
- kioskTx: globalKioskTx,
4938
5115
  shouldConvertToPersonalKiosk: true,
4939
5116
  shouldAllowNftUnsharedKiosk: true,
4940
- shouldSkipFinalize: true,
5117
+ sharedKioskState,
4941
5118
  async runCommands(kioskTx) {
4942
- existingKioskTx = kioskTx;
4943
5119
  await addClaimTransferredNftTx({ ...txData, kioskTx });
4944
5120
  }
4945
5121
  });
@@ -4949,27 +5125,23 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
4949
5125
  kioskClient: context.kioskClient,
4950
5126
  kioskOwner: txData?.claimer,
4951
5127
  kiosk: txData?.sellerKiosk,
4952
- kioskOwnerKiosks: walletAddressKiosks,
4953
5128
  kioskStrategy: "exclude",
4954
- kioskTx: globalKioskTx,
4955
5129
  shouldConvertToPersonalKiosk: true,
4956
5130
  shouldAllowNftUnsharedKiosk: true,
4957
- shouldSkipFinalize: true,
5131
+ sharedKioskState,
4958
5132
  async runCommands(kioskTx) {
4959
- existingKioskTx = kioskTx;
4960
5133
  await addClaimTransferredNftWithPurchaseCapTx({ ...txData, kioskTx });
4961
5134
  }
4962
5135
  });
4963
5136
  }
4964
5137
  }
4965
- globalKioskTx = existingKioskTx;
4966
5138
  }
4967
- globalKioskTx?.finalize();
4968
- return import_transactions13.Transaction.from(tx);
5139
+ sharedKioskState?.kioskTx?.finalize();
5140
+ return import_transactions14.Transaction.from(tx);
4969
5141
  };
4970
5142
 
4971
5143
  // src/methods/createLongLocks/createLongLocks.ts
4972
- var import_transactions14 = require("@mysten/sui/transactions");
5144
+ var import_transactions15 = require("@mysten/sui/transactions");
4973
5145
 
4974
5146
  // src/graphql/queries/fetchActiveLockStateByNftId.ts
4975
5147
  var import_graphql_request18 = require("graphql-request");
@@ -5000,7 +5172,7 @@ var getActiveLockStateByNftId = async (nftId) => {
5000
5172
  // src/methods/createLongLocks/createLongLocks.ts
5001
5173
  async function createLongLocks({ walletAddress, nfts }, context) {
5002
5174
  const expireIn = 7 * 24 * 3600 * 1e3;
5003
- const tx = new import_transactions14.Transaction();
5175
+ const tx = new import_transactions15.Transaction();
5004
5176
  for (const argNft of nfts) {
5005
5177
  const existingLock = await getActiveLockStateByNftId(argNft.id);
5006
5178
  if (existingLock) {
@@ -5063,10 +5235,10 @@ async function createLongLocks({ walletAddress, nfts }, context) {
5063
5235
  }
5064
5236
 
5065
5237
  // src/methods/createMultiBid/createMultiBid.ts
5066
- var import_transactions16 = require("@mysten/sui/transactions");
5238
+ var import_transactions17 = require("@mysten/sui/transactions");
5067
5239
 
5068
5240
  // src/methods/updateMultiBid/updateMultiBid.ts
5069
- var import_transactions15 = require("@mysten/sui/transactions");
5241
+ var import_transactions16 = require("@mysten/sui/transactions");
5070
5242
  async function updateMultiBid({
5071
5243
  multiBidId,
5072
5244
  name,
@@ -5075,7 +5247,7 @@ async function updateMultiBid({
5075
5247
  tx: existingTx,
5076
5248
  multiBidChainId
5077
5249
  }) {
5078
- const tx = typeof existingTx === "string" ? import_transactions15.Transaction.from(existingTx) : existingTx ?? new import_transactions15.Transaction();
5250
+ const tx = typeof existingTx === "string" ? import_transactions16.Transaction.from(existingTx) : existingTx ?? new import_transactions16.Transaction();
5079
5251
  if (!multiBidChainId) {
5080
5252
  const { chain_id: chainId, cancelled_at } = (await gqlChainRequest({
5081
5253
  chain: "sui",
@@ -5111,7 +5283,7 @@ async function createMultiBid({
5111
5283
  amount,
5112
5284
  tx: existingTx
5113
5285
  }) {
5114
- const tx = existingTx ?? new import_transactions16.Transaction();
5286
+ const tx = existingTx ?? new import_transactions17.Transaction();
5115
5287
  const multiBidChainId = tx.moveCall({
5116
5288
  target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
5117
5289
  arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.option("string", name)]
@@ -5129,10 +5301,10 @@ async function createMultiBid({
5129
5301
  }
5130
5302
 
5131
5303
  // src/methods/createShortLocks/createShortLocks.ts
5132
- var import_transactions17 = require("@mysten/sui/transactions");
5304
+ var import_transactions18 = require("@mysten/sui/transactions");
5133
5305
  async function createShortLocks({ nfts }, context) {
5134
5306
  const expireIn = 7 * 24 * 3600 * 1e3;
5135
- const tx = new import_transactions17.Transaction();
5307
+ const tx = new import_transactions18.Transaction();
5136
5308
  for (const argNft of nfts) {
5137
5309
  const premium = calculatePremium(BigInt(argNft.priceInMist));
5138
5310
  if (!argNft.type) {
@@ -5170,7 +5342,7 @@ async function createShortLocks({ nfts }, context) {
5170
5342
  }
5171
5343
 
5172
5344
  // src/methods/listNfts/listNfts.ts
5173
- var import_transactions18 = require("@mysten/sui/transactions");
5345
+ var import_transactions19 = require("@mysten/sui/transactions");
5174
5346
 
5175
5347
  // src/methods/listNfts/addListTxs.ts
5176
5348
  async function addOriginByteListTx({
@@ -5181,17 +5353,20 @@ async function addOriginByteListTx({
5181
5353
  seller,
5182
5354
  listPrice,
5183
5355
  collectionId,
5184
- sellerKiosk
5356
+ sellerKiosk,
5357
+ sharedKioskState
5185
5358
  }) {
5186
5359
  const { orderbook } = sharedObjects;
5187
5360
  await assertNftInSharedKiosk({
5188
5361
  kioskId: sellerKiosk,
5189
- walletAddress: seller
5362
+ walletAddress: seller,
5363
+ sharedKioskState
5190
5364
  });
5191
5365
  const { kiosk, isNewKiosk } = await getOrCreateOBKiosk({
5192
5366
  tx,
5193
5367
  address: seller,
5194
- kioskToUseIfExists: sellerKiosk
5368
+ kioskToUseIfExists: sellerKiosk,
5369
+ sharedKioskState
5195
5370
  });
5196
5371
  if (isNewKiosk) {
5197
5372
  depositItemIntoOBKiosk({
@@ -5215,7 +5390,7 @@ async function addOriginByteListTx({
5215
5390
  typeArguments: [nftType, "0x2::sui::SUI"]
5216
5391
  });
5217
5392
  if (isNewKiosk) {
5218
- await shareOriginByteKiosk({ tx, kiosk });
5393
+ shareOriginByteKiosk({ tx, kiosk });
5219
5394
  }
5220
5395
  }
5221
5396
  function addTradePortListTx({
@@ -5288,6 +5463,7 @@ async function addTradePortListTxHandler(txData) {
5288
5463
  kioskOwner: txData?.seller,
5289
5464
  kiosk: txData?.sellerKiosk,
5290
5465
  shouldAssertNftInSharedKiosk: true,
5466
+ sharedKioskState: txData?.sharedKioskState,
5291
5467
  async runCommands(kioskTx) {
5292
5468
  const borrowedItem = await takeAndBorrowNftFromKiosk({
5293
5469
  tx: txData?.tx,
@@ -5310,6 +5486,7 @@ async function addTradePortListTxHandler(txData) {
5310
5486
  kioskOwner: txData?.seller,
5311
5487
  kiosk: txData?.sellerKiosk,
5312
5488
  shouldAssertNftInSharedKiosk: true,
5489
+ sharedKioskState: txData?.sharedKioskState,
5313
5490
  async runCommands(kioskTx) {
5314
5491
  await addTradePortKioskListTx({
5315
5492
  ...txData,
@@ -5324,6 +5501,7 @@ async function addTradePortListTxHandler(txData) {
5324
5501
  kioskClient: txData?.kioskClient,
5325
5502
  kioskOwner: txData?.seller,
5326
5503
  kiosk: txData?.sellerKiosk,
5504
+ sharedKioskState: txData?.sharedKioskState,
5327
5505
  async runCommands(kioskTx) {
5328
5506
  kioskTx.place({
5329
5507
  item: txData?.nftTokenId,
@@ -5384,15 +5562,21 @@ async function relistNft({
5384
5562
  tx,
5385
5563
  suiClient,
5386
5564
  kioskClient,
5565
+ sharedKioskState,
5387
5566
  nft,
5388
5567
  listPrice,
5389
5568
  transferPolicies,
5390
5569
  walletAddress
5391
5570
  }) {
5571
+ const firstListedOrExpiredListing = (nft?.listings).find((l) => l.listed || l.nonce);
5572
+ if (!firstListedOrExpiredListing) {
5573
+ throw new Error("No listing found for NFT");
5574
+ }
5392
5575
  const txData = {
5393
5576
  tx,
5394
5577
  suiClient,
5395
5578
  kioskClient,
5579
+ sharedKioskState,
5396
5580
  transferPolicies,
5397
5581
  nftTokenId: nft?.token_id,
5398
5582
  nftType: getNftType({
@@ -5400,13 +5584,13 @@ async function relistNft({
5400
5584
  collectionChainState: nft?.collection?.chain_state,
5401
5585
  nft
5402
5586
  }),
5403
- listingNonce: nft?.listings?.[0]?.nonce,
5404
- price: nft?.listings?.[0]?.price,
5587
+ listingNonce: firstListedOrExpiredListing.nonce,
5588
+ price: firstListedOrExpiredListing.price,
5405
5589
  sellerKiosk: nft?.chain_state?.kiosk_id,
5406
5590
  collectionId: nft?.collection_id,
5407
5591
  seller: walletAddress
5408
5592
  };
5409
- switch (nft?.listings?.[0]?.market_name) {
5593
+ switch (firstListedOrExpiredListing.market_name) {
5410
5594
  case "tradeport":
5411
5595
  if ((!isOriginByteCollection(txData?.transferPolicies) || ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) && txData?.listingNonce && await isNonKioskListing({
5412
5596
  suiClient: txData?.suiClient,
@@ -5428,6 +5612,7 @@ async function relistNft({
5428
5612
  kioskOwner: txData?.seller,
5429
5613
  kiosk: txData?.sellerKiosk,
5430
5614
  shouldAssertNftInSharedKiosk: true,
5615
+ sharedKioskState: txData?.sharedKioskState,
5431
5616
  async runCommands(kioskTx) {
5432
5617
  await addTradePortKioskUnlistTx({
5433
5618
  ...txData,
@@ -5484,7 +5669,10 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5484
5669
  throw new Error("No nfts found");
5485
5670
  }
5486
5671
  const nftsForTracking = [];
5487
- const tx = new import_transactions18.Transaction();
5672
+ const tx = new import_transactions19.Transaction();
5673
+ const sharedKioskState = {
5674
+ kioskTx: void 0
5675
+ };
5488
5676
  for (const nft of res.nfts) {
5489
5677
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
5490
5678
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -5502,6 +5690,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5502
5690
  tx,
5503
5691
  suiClient: context.suiClient,
5504
5692
  kioskClient: context.kioskClient,
5693
+ sharedKioskState,
5505
5694
  transferPolicies,
5506
5695
  nft,
5507
5696
  listPrice: nfts?.find((n) => n.id === nft?.id)?.listPriceInMist,
@@ -5512,6 +5701,7 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5512
5701
  tx,
5513
5702
  suiClient: context.suiClient,
5514
5703
  kioskClient: context.kioskClient,
5704
+ sharedKioskState,
5515
5705
  transferPolicies,
5516
5706
  seller: walletAddress,
5517
5707
  collectionId: nft?.collection_id,
@@ -5531,11 +5721,12 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
5531
5721
  marketRelistedFrom: nft?.listings?.[0]?.market_name
5532
5722
  });
5533
5723
  }
5534
- return import_transactions18.Transaction.from(tx);
5724
+ sharedKioskState?.kioskTx?.finalize();
5725
+ return import_transactions19.Transaction.from(tx);
5535
5726
  };
5536
5727
 
5537
5728
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5538
- var import_transactions19 = require("@mysten/sui/transactions");
5729
+ var import_transactions20 = require("@mysten/sui/transactions");
5539
5730
 
5540
5731
  // src/graphql/queries/fetchNftsByKioskId.ts
5541
5732
  var import_graphql_request19 = require("graphql-request");
@@ -5589,13 +5780,15 @@ async function addOriginByteTransferNftTx({
5589
5780
  nftType,
5590
5781
  recipientAddress,
5591
5782
  senderKiosk,
5592
- senderAddress
5783
+ senderAddress,
5784
+ sharedKioskState
5593
5785
  }) {
5594
5786
  await assertNftInSharedKiosk({
5595
5787
  kioskId: senderKiosk,
5596
- walletAddress: senderAddress
5788
+ walletAddress: senderAddress,
5789
+ sharedKioskState
5597
5790
  });
5598
- const recipientOBKiosk = await getOBKiosk(recipientAddress);
5791
+ const recipientOBKiosk = await getOBKiosk({ wallet: recipientAddress, sharedKioskState });
5599
5792
  if (recipientOBKiosk) {
5600
5793
  tx.moveCall({
5601
5794
  target: "0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::p2p_transfer",
@@ -5643,7 +5836,7 @@ async function addTradeportKioskTransferTx({
5643
5836
  });
5644
5837
  }
5645
5838
  async function addTradeportKioskDirectTransferTx(txData, nfts, suiClient) {
5646
- const { tx, recipientAddress, kioskClient, senderAddress } = txData;
5839
+ const { tx, recipientAddress, kioskClient, sharedKioskState, senderAddress } = txData;
5647
5840
  if (nfts.length === 0) {
5648
5841
  return;
5649
5842
  }
@@ -5686,6 +5879,7 @@ async function addTradeportKioskDirectTransferTx(txData, nfts, suiClient) {
5686
5879
  kioskClient,
5687
5880
  kioskOwner: senderAddress,
5688
5881
  kiosk: nft?.chain_state?.kiosk_id,
5882
+ sharedKioskState,
5689
5883
  async runCommands(kioskTx) {
5690
5884
  tx.moveCall({
5691
5885
  target: "0xd0ad5bf7ac7d372cdcfee5273d5e487dabad724040e089c626cba2a01127ccd6::kiosk_transfers::direct_transfer",
@@ -5734,7 +5928,7 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
5734
5928
 
5735
5929
  // src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
5736
5930
  async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
5737
- const tx = new import_transactions19.Transaction();
5931
+ const tx = new import_transactions20.Transaction();
5738
5932
  const res = await gqlChainRequest({
5739
5933
  chain: "sui",
5740
5934
  query: fetchKiosksByOwner,
@@ -5825,7 +6019,9 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
5825
6019
  transferPolicies.forEach((tp) => {
5826
6020
  mappedTrasferPolicies[tp?.[0]?.type] = tp;
5827
6021
  });
5828
- let globalKioskTx;
6022
+ const sharedKioskState = {
6023
+ kioskTx: void 0
6024
+ };
5829
6025
  for (const unsharedNativeKiosk of unsharedNativeKiosks) {
5830
6026
  if (currentMigrationCount >= max) {
5831
6027
  continue;
@@ -5851,6 +6047,7 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
5851
6047
  kioskOwner: walletAddress,
5852
6048
  kiosk: unsharedNativeKiosk,
5853
6049
  shouldAllowNftUnsharedKiosk: true,
6050
+ sharedKioskState,
5854
6051
  async runCommands(kioskTx) {
5855
6052
  await addTradeportKioskTransferTx({
5856
6053
  tx,
@@ -5873,11 +6070,9 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
5873
6070
  kioskOwner: walletAddress,
5874
6071
  kiosk: unsharedNativeKiosk,
5875
6072
  kioskStrategy: "exclude",
5876
- kioskTx: globalKioskTx,
5877
- shouldSkipFinalize: true,
5878
6073
  shouldConvertToPersonalKiosk: true,
6074
+ sharedKioskState,
5879
6075
  async runCommands(kioskTx) {
5880
- existingKioskTx = kioskTx;
5881
6076
  await addClaimTransferredNftWithPurchaseCapTx({
5882
6077
  tx,
5883
6078
  kioskTx,
@@ -5894,15 +6089,14 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }
5894
6089
  });
5895
6090
  }
5896
6091
  });
5897
- globalKioskTx = existingKioskTx;
5898
6092
  }
5899
6093
  }
5900
- globalKioskTx?.finalize();
5901
- return import_transactions19.Transaction.from(tx);
6094
+ sharedKioskState?.kioskTx?.finalize();
6095
+ return import_transactions20.Transaction.from(tx);
5902
6096
  }
5903
6097
 
5904
6098
  // src/methods/placeCollectionBids/placeCollectionBids.ts
5905
- var import_transactions20 = require("@mysten/sui/transactions");
6099
+ var import_transactions21 = require("@mysten/sui/transactions");
5906
6100
 
5907
6101
  // src/graphql/queries/fetchCollectionsById.ts
5908
6102
  var import_graphql_request20 = require("graphql-request");
@@ -5958,12 +6152,12 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
5958
6152
  bcsHex,
5959
6153
  expireAt
5960
6154
  } = txData;
5961
- let bcs3;
6155
+ let bcs4;
5962
6156
  if (nftTokenId && isDynamicCollection(collectionId)) {
5963
6157
  if (!bcsHex) {
5964
6158
  throw new Error(`No BCS found for token ${nftTokenId}`);
5965
6159
  }
5966
- bcs3 = (0, import_utils10.fromHex)(bcsHex);
6160
+ bcs4 = (0, import_utils10.fromHex)(bcsHex);
5967
6161
  }
5968
6162
  let multiBidChainId;
5969
6163
  if (existingMultiBidChainId) {
@@ -6009,7 +6203,7 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
6009
6203
  arguments: [multiBidChainId]
6010
6204
  }) : void 0,
6011
6205
  tx.pure.option("id", nftTokenId ? (0, import_utils10.normalizeSuiObjectId)(nftTokenId) : void 0),
6012
- tx.pure.option("vector<u8>", bcs3 ? [...bcs3] : void 0),
6206
+ tx.pure.option("vector<u8>", bcs4 ? [...bcs4] : void 0),
6013
6207
  tx.pure.option("u64", expireAt?.getTime()),
6014
6208
  tx.pure.u64(price),
6015
6209
  ...transferPolicy ? [tx.object(transferPolicy.id)] : [],
@@ -6106,7 +6300,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6106
6300
  throw new Error("No collection found");
6107
6301
  }
6108
6302
  const collectionsForTracking = [];
6109
- const tx = existingTx ? import_transactions20.Transaction.from(existingTx) : new import_transactions20.Transaction();
6303
+ const tx = existingTx ? import_transactions21.Transaction.from(existingTx) : new import_transactions21.Transaction();
6110
6304
  for (const collection of res.collections) {
6111
6305
  const nftType = getNftType({
6112
6306
  collectionId: collection?.id,
@@ -6128,10 +6322,8 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6128
6322
  expireAt: collections?.find((c) => c.id === collection?.id)?.expireAt
6129
6323
  };
6130
6324
  const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
6131
- console.log("txData", txData);
6132
6325
  if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
6133
6326
  const sharedObjects = await getSharedObjects(txData?.nftType);
6134
- console.log("sharedObjects", sharedObjects);
6135
6327
  const { kiosk: bidderKiosk, isNewKiosk: isNewBidderKiosk } = await getOrCreateOBKiosk({
6136
6328
  tx,
6137
6329
  address: txData.bidder
@@ -6140,7 +6332,7 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6140
6332
  await addOriginByteCollectionBidTx({ ...txData, bidderKiosk, sharedObjects });
6141
6333
  }
6142
6334
  if (isNewBidderKiosk) {
6143
- await shareOriginByteKiosk({ tx, kiosk: bidderKiosk });
6335
+ shareOriginByteKiosk({ tx, kiosk: bidderKiosk });
6144
6336
  }
6145
6337
  } else {
6146
6338
  for (let i = 0; i < numOfBids; i++) {
@@ -6154,13 +6346,13 @@ var placeCollectionBids = async ({ collections, walletAddress, multiBidId, multi
6154
6346
  bidder: walletAddress
6155
6347
  });
6156
6348
  }
6157
- return import_transactions20.Transaction.from(tx);
6349
+ return import_transactions21.Transaction.from(tx);
6158
6350
  };
6159
6351
 
6160
6352
  // src/methods/placeNftBids/placeNftBids.ts
6161
- var import_transactions21 = require("@mysten/sui/transactions");
6353
+ var import_transactions22 = require("@mysten/sui/transactions");
6162
6354
  var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx }, context) => {
6163
- const tx = existingTx ? import_transactions21.Transaction.from(existingTx) : new import_transactions21.Transaction();
6355
+ const tx = existingTx ? import_transactions22.Transaction.from(existingTx) : new import_transactions22.Transaction();
6164
6356
  const res = await gqlChainRequest({
6165
6357
  chain: "sui",
6166
6358
  query: fetchNftsById,
@@ -6203,11 +6395,11 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
6203
6395
  bidder: walletAddress
6204
6396
  });
6205
6397
  }
6206
- return import_transactions21.Transaction.from(tx);
6398
+ return import_transactions22.Transaction.from(tx);
6207
6399
  };
6208
6400
 
6209
6401
  // src/methods/removeCollectionBids/removeCollectionBids.ts
6210
- var import_transactions22 = require("@mysten/sui/transactions");
6402
+ var import_transactions23 = require("@mysten/sui/transactions");
6211
6403
 
6212
6404
  // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
6213
6405
  var import_utils12 = require("@mysten/sui/utils");
@@ -6397,7 +6589,7 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6397
6589
  throw new Error("No bids found");
6398
6590
  }
6399
6591
  const bidsForTracking = [];
6400
- const tx = existingTx ? import_transactions22.Transaction.from(existingTx) : new import_transactions22.Transaction();
6592
+ const tx = existingTx ? import_transactions23.Transaction.from(existingTx) : new import_transactions23.Transaction();
6401
6593
  for (const bid of res.bids) {
6402
6594
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6403
6595
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6445,11 +6637,11 @@ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
6445
6637
  bidder: bid?.bidder
6446
6638
  });
6447
6639
  }
6448
- return import_transactions22.Transaction.from(tx);
6640
+ return import_transactions23.Transaction.from(tx);
6449
6641
  };
6450
6642
 
6451
6643
  // src/methods/removeNftBids/removeNftBids.ts
6452
- var import_transactions23 = require("@mysten/sui/transactions");
6644
+ var import_transactions24 = require("@mysten/sui/transactions");
6453
6645
  var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6454
6646
  const res = await gqlChainRequest({
6455
6647
  chain: "sui",
@@ -6460,7 +6652,7 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6460
6652
  throw new Error("No bids found");
6461
6653
  }
6462
6654
  const bidsForTracking = [];
6463
- const tx = existingTx ? import_transactions23.Transaction.from(existingTx) : new import_transactions23.Transaction();
6655
+ const tx = existingTx ? import_transactions24.Transaction.from(existingTx) : new import_transactions24.Transaction();
6464
6656
  for (const bid of res.bids) {
6465
6657
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
6466
6658
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6505,11 +6697,11 @@ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
6505
6697
  bidder: bid?.bidder
6506
6698
  });
6507
6699
  }
6508
- return import_transactions23.Transaction.from(tx);
6700
+ return import_transactions24.Transaction.from(tx);
6509
6701
  };
6510
6702
 
6511
6703
  // src/methods/transferNfts/transferNfts.ts
6512
- var import_transactions24 = require("@mysten/sui/transactions");
6704
+ var import_transactions25 = require("@mysten/sui/transactions");
6513
6705
  var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context) => {
6514
6706
  if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
6515
6707
  throw new Error("Cannot transfer to self");
@@ -6527,7 +6719,10 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6527
6719
  }
6528
6720
  const nftsForTracking = [];
6529
6721
  const nftsToTransferDirectly = [];
6530
- const tx = new import_transactions24.Transaction();
6722
+ const tx = new import_transactions25.Transaction();
6723
+ const sharedKioskState = {
6724
+ kioskTx: void 0
6725
+ };
6531
6726
  for (const nft of res.nfts) {
6532
6727
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
6533
6728
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6545,6 +6740,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6545
6740
  tx,
6546
6741
  suiClient: context.suiClient,
6547
6742
  kioskClient: context.kioskClient,
6743
+ sharedKioskState,
6548
6744
  nftType,
6549
6745
  nftTokenId: nft?.token_id,
6550
6746
  senderKiosk: nft?.chain_state?.kiosk_id,
@@ -6571,6 +6767,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6571
6767
  kioskOwner: txData?.senderAddress,
6572
6768
  kiosk: txData?.senderKiosk,
6573
6769
  shouldAssertNftInSharedKiosk: true,
6770
+ sharedKioskState: txData?.sharedKioskState,
6574
6771
  async runCommands(kioskTx) {
6575
6772
  const borrowedItem = await takeAndBorrowNftFromKiosk({
6576
6773
  tx: txData?.tx,
@@ -6599,6 +6796,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6599
6796
  kioskOwner: txData?.senderAddress,
6600
6797
  kiosk: txData?.senderKiosk,
6601
6798
  shouldAssertNftInSharedKiosk: true,
6799
+ sharedKioskState: txData?.sharedKioskState,
6602
6800
  async runCommands(kioskTx) {
6603
6801
  await addTradeportKioskTransferTx({ ...txData, kioskTx });
6604
6802
  }
@@ -6611,15 +6809,22 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6611
6809
  });
6612
6810
  }
6613
6811
  await addTradeportKioskDirectTransferTx(
6614
- { tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
6812
+ {
6813
+ tx,
6814
+ kioskClient: context.kioskClient,
6815
+ sharedKioskState,
6816
+ senderAddress: walletAddress,
6817
+ recipientAddress
6818
+ },
6615
6819
  nftsToTransferDirectly,
6616
6820
  context.suiClient
6617
6821
  );
6618
- return import_transactions24.Transaction.from(tx);
6822
+ sharedKioskState?.kioskTx?.finalize();
6823
+ return import_transactions25.Transaction.from(tx);
6619
6824
  };
6620
6825
 
6621
6826
  // src/methods/unlistListings/unlistListings.ts
6622
- var import_transactions25 = require("@mysten/sui/transactions");
6827
+ var import_transactions26 = require("@mysten/sui/transactions");
6623
6828
  var import_utils13 = require("@mysten/sui/utils");
6624
6829
  var unlistListings = async ({ listingIds, walletAddress }, context) => {
6625
6830
  const res = await gqlChainRequest({
@@ -6631,7 +6836,10 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
6631
6836
  throw new Error("No listings found");
6632
6837
  }
6633
6838
  const listingsForTracking = [];
6634
- const tx = new import_transactions25.Transaction();
6839
+ const tx = new import_transactions26.Transaction();
6840
+ const sharedKioskState = {
6841
+ kioskTx: void 0
6842
+ };
6635
6843
  for (const listing of res.listings) {
6636
6844
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(listing?.nft?.token_id)) {
6637
6845
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -6649,6 +6857,7 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
6649
6857
  tx,
6650
6858
  suiClient: context.suiClient,
6651
6859
  kioskClient: context.kioskClient,
6860
+ sharedKioskState,
6652
6861
  transferPolicies,
6653
6862
  nftTokenId: listing.nft?.token_id,
6654
6863
  nftType,
@@ -6695,12 +6904,13 @@ var unlistListings = async ({ listingIds, walletAddress }, context) => {
6695
6904
  marketName: listing?.market_name
6696
6905
  });
6697
6906
  }
6698
- return import_transactions25.Transaction.from(tx);
6907
+ sharedKioskState?.kioskTx?.finalize();
6908
+ return import_transactions26.Transaction.from(tx);
6699
6909
  };
6700
6910
 
6701
6911
  // src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts
6702
6912
  var import_kiosk5 = require("@mysten/kiosk");
6703
- var import_transactions26 = require("@mysten/sui/transactions");
6913
+ var import_transactions27 = require("@mysten/sui/transactions");
6704
6914
  async function withdrawProfitsFromKiosks({ walletAddress }, context) {
6705
6915
  const res = await gqlChainRequest({
6706
6916
  chain: "sui",
@@ -6717,7 +6927,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
6717
6927
  if (kiosksWithProfit.length === 0) {
6718
6928
  throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
6719
6929
  }
6720
- const tx = new import_transactions26.Transaction();
6930
+ const tx = new import_transactions27.Transaction();
6721
6931
  try {
6722
6932
  for (const kiosk of kiosksWithProfit) {
6723
6933
  let kioskTx;
@@ -6763,7 +6973,7 @@ async function withdrawProfitsFromKiosks({ walletAddress }, context) {
6763
6973
  } catch (err) {
6764
6974
  console.log("err", err);
6765
6975
  }
6766
- return import_transactions26.Transaction.from(tx);
6976
+ return import_transactions27.Transaction.from(tx);
6767
6977
  }
6768
6978
 
6769
6979
  // src/SuiTradingClient.ts