@tradeport/sui-trading-sdk 0.4.13 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1254,7 +1254,7 @@ var getSharedObjects = async (nftType) => {
1254
1254
  };
1255
1255
 
1256
1256
  // src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts
1257
- import { normalizeSuiObjectId as normalizeSuiObjectId2 } from "@mysten/sui/utils";
1257
+ import { normalizeSuiObjectId as normalizeSuiObjectId3 } from "@mysten/sui/utils";
1258
1258
 
1259
1259
  // src/utils/normalizeNftType.ts
1260
1260
  var normalizedNftType = (nftType) => {
@@ -1293,10 +1293,7 @@ var hasPersonalKioskRule = (transferPolicies) => getNativeKioskTransferPolicies(
1293
1293
  );
1294
1294
 
1295
1295
  // src/helpers/hasTransferPolicyRules.ts
1296
- var hasNativeKioskTransferPolicyRules = (transferPolicies) => {
1297
- const nativeKioskTransferPolicies = getNativeKioskTransferPolicies(transferPolicies);
1298
- return nativeKioskTransferPolicies?.some((policy) => policy?.rules?.length > 0);
1299
- };
1296
+ var hasNativeKioskTransferPolicyRules = (transferPolicies) => getNativeKioskTransferPolicies(transferPolicies)?.length > 0;
1300
1297
 
1301
1298
  // src/helpers/isSIngleBid.ts
1302
1299
  var isSingleBid = (bidType) => {
@@ -1356,16 +1353,52 @@ function addHexPrefix(input) {
1356
1353
  return "0x" + input;
1357
1354
  }
1358
1355
 
1356
+ // src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts
1357
+ import { normalizeStructTag, normalizeSuiObjectId } from "@mysten/sui/utils";
1358
+ var getTransferPolicyRuleNamesFromSuiObject = async ({
1359
+ suiClient,
1360
+ transferPolicyId
1361
+ }) => {
1362
+ const { data, error } = await suiClient.getObject({
1363
+ id: normalizeSuiObjectId(transferPolicyId),
1364
+ options: {
1365
+ showContent: true
1366
+ }
1367
+ });
1368
+ if (error) {
1369
+ throw new Error(`Error on getting SUI object ${transferPolicyId}: ${error.code}`);
1370
+ }
1371
+ const content = data.content;
1372
+ const ruleNames = content.fields.rules.fields.contents.map(
1373
+ (rule) => normalizeStructTag(rule.fields.name)
1374
+ );
1375
+ return ruleNames;
1376
+ };
1377
+
1359
1378
  // src/helpers/kiosk/getRulePackageId.ts
1360
1379
  var getRulePackageId = async ({
1380
+ transferPolicies,
1361
1381
  nftType,
1362
1382
  ruleType,
1363
- kioskClient
1383
+ kioskClient,
1384
+ suiClient
1364
1385
  }) => {
1365
- const transferPolicies = await kioskClient.getTransferPolicies({
1386
+ const transferPoliciesFromMystenSdk = await kioskClient.getTransferPolicies({
1366
1387
  type: normalizedNftType(nftType)
1367
1388
  });
1368
- const rule = transferPolicies.flatMap((policy) => policy.rules).filter((rule2) => rule2?.split("::")?.[1] === ruleType)?.[0];
1389
+ let rule;
1390
+ if (transferPoliciesFromMystenSdk.length > 0) {
1391
+ rule = transferPoliciesFromMystenSdk.flatMap((policy) => policy.rules).filter((rule2) => rule2?.split("::")?.[1] === ruleType)?.[0];
1392
+ } else if (transferPolicies.length > 0) {
1393
+ const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
1394
+ const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
1395
+ suiClient,
1396
+ transferPolicyId
1397
+ });
1398
+ rule = ruleNames.filter((ruleName) => ruleName?.split("::")?.[1] === ruleType)?.[0];
1399
+ } else {
1400
+ throw new Error(`No transfer policy found for ${nftType}`);
1401
+ }
1369
1402
  const ruleDefinition = kioskClient.rules.find(
1370
1403
  (x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule)
1371
1404
  );
@@ -1628,7 +1661,7 @@ var getObjectType = async ({
1628
1661
  };
1629
1662
 
1630
1663
  // src/methods/acceptNftBids/addAcceptNftBidTxs.ts
1631
- import { normalizeStructTag, normalizeSuiObjectId, SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
1664
+ import { normalizeStructTag as normalizeStructTag2, normalizeSuiObjectId as normalizeSuiObjectId2, SUI_CLOCK_OBJECT_ID } from "@mysten/sui/utils";
1632
1665
 
1633
1666
  // src/graphql/queries/fetchMultibidById.ts
1634
1667
  import { gql as gql10 } from "graphql-request";
@@ -1843,6 +1876,7 @@ async function resolveRoyaltyRule({
1843
1876
  var originByteRuleModules = ["royalty_strategy_bps", "transfer_allowlist"];
1844
1877
  var resolveTransferPolicies = async ({
1845
1878
  tx,
1879
+ transferPolicies,
1846
1880
  suiClient,
1847
1881
  walletAddress,
1848
1882
  kioskClient,
@@ -1858,35 +1892,51 @@ var resolveTransferPolicies = async ({
1858
1892
  coinToSplit,
1859
1893
  beforeResolveKioskTransferRequest
1860
1894
  }) => {
1861
- const transferPolicies = await kioskClient.getTransferPolicies({
1895
+ const transferPoliciesFromMystenSdk = await kioskClient.getTransferPolicies({
1862
1896
  type: normalizedNftType(nftType)
1863
1897
  });
1864
- if (transferPolicies.length === 0 && (customTransferPolicies ?? []).every(
1865
- (p) => p.transferRequest !== transferRequest
1866
- )) {
1867
- throw new Error(
1868
- `Missing transfer policy of ${nftType}. No way to resolve the transfer request.`
1869
- );
1870
- }
1871
- let policies = transferPolicies.length > 0 ? [
1872
- {
1873
- data: transferPolicies?.filter(
1874
- (policy) => policy?.rules?.filter(
1875
- (rule) => rule?.includes("royalty_rule") || rule?.includes("kiosk_lock_rule") || rule?.includes("personal_kiosk_rule") || rule?.includes("floor_price_rule")
1876
- )?.length > 0
1877
- )?.[0],
1878
- transferRequest,
1879
- isCustom: false
1880
- }
1881
- ] : [];
1882
- if (!policies?.[0]?.data && transferPolicies.length > 0) {
1898
+ let policies = [];
1899
+ if (transferPoliciesFromMystenSdk.length > 0) {
1883
1900
  policies = [
1884
1901
  {
1885
- data: transferPolicies?.[0],
1902
+ data: (
1903
+ // Find first policy with relevant rules, or fall back to first policy
1904
+ transferPoliciesFromMystenSdk.find(
1905
+ (policy) => policy?.rules?.some(
1906
+ (rule) => knownTransferPolicyRules.some((ruleType) => rule?.includes(ruleType))
1907
+ )
1908
+ ) ?? transferPoliciesFromMystenSdk[0]
1909
+ ),
1886
1910
  transferRequest,
1887
1911
  isCustom: false
1888
1912
  }
1889
1913
  ];
1914
+ } else if (transferPolicies.length > 0) {
1915
+ const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
1916
+ if (transferPolicyId) {
1917
+ const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
1918
+ suiClient,
1919
+ transferPolicyId
1920
+ });
1921
+ if (ruleNames.length > 0) {
1922
+ policies = [
1923
+ {
1924
+ data: {
1925
+ id: transferPolicyId,
1926
+ rules: ruleNames
1927
+ },
1928
+ transferRequest,
1929
+ isCustom: false
1930
+ }
1931
+ ];
1932
+ }
1933
+ }
1934
+ } else if ((customTransferPolicies ?? []).every(
1935
+ (p) => p.transferRequest !== transferRequest
1936
+ )) {
1937
+ throw new Error(
1938
+ `Missing transfer policy of ${nftType}. No way to resolve the transfer request.`
1939
+ );
1890
1940
  }
1891
1941
  if (customTransferPolicies) {
1892
1942
  for (const customTransferPolicy of customTransferPolicies) {
@@ -2080,6 +2130,7 @@ async function addTradeportKioskAcceptNftBidTx({
2080
2130
  await beforeResolveKioskTransferRequest?.(feeCoin, transferRequest);
2081
2131
  await resolveTransferPolicies({
2082
2132
  tx,
2133
+ transferPolicies,
2083
2134
  suiClient,
2084
2135
  walletAddress: seller,
2085
2136
  kioskTx,
@@ -2112,6 +2163,7 @@ async function addTradeportKioskAcceptNftBidTx({
2112
2163
  }
2113
2164
  await resolveTransferPolicies({
2114
2165
  tx,
2166
+ transferPolicies,
2115
2167
  suiClient,
2116
2168
  walletAddress: seller,
2117
2169
  kioskTx,
@@ -2194,7 +2246,7 @@ function addBluemoveAcceptNftBidTx({
2194
2246
  });
2195
2247
  }
2196
2248
  async function addSingleBidAcceptNftBidTx(txData) {
2197
- const { nftType, tx, bidNonce, multiBidId, kioskClient, nftTokenId } = txData;
2249
+ const { nftType, tx, bidNonce, multiBidId, kioskClient, nftTokenId, suiClient } = txData;
2198
2250
  const transferPolicies = getNativeKioskTransferPolicies(txData?.transferPolicies);
2199
2251
  const transferPolicy = transferPolicies?.find(
2200
2252
  (policy) => policy?.rules?.length > 0
@@ -2209,9 +2261,15 @@ async function addSingleBidAcceptNftBidTx(txData) {
2209
2261
  }
2210
2262
  if (transferPolicy) {
2211
2263
  const transferPolicies2 = await kioskClient.getTransferPolicies({
2212
- type: normalizeStructTag(nftType)
2264
+ type: normalizeStructTag2(nftType)
2213
2265
  });
2214
- const { rules: allRules } = transferPolicies2.find((p) => p.id === transferPolicy.id);
2266
+ let { rules: allRules } = transferPolicies2.find((p) => p.id === transferPolicy.id);
2267
+ if (allRules.length === 0) {
2268
+ allRules = await getTransferPolicyRuleNamesFromSuiObject({
2269
+ suiClient,
2270
+ transferPolicyId: transferPolicy.id
2271
+ });
2272
+ }
2215
2273
  const unsupportedRule = allRules.find(
2216
2274
  (r) => !knownTransferPolicyRules.includes(r.split("::").at(1))
2217
2275
  );
@@ -2233,7 +2291,7 @@ async function addSingleBidAcceptNftBidTx(txData) {
2233
2291
  arguments: [
2234
2292
  tx.object(SUI_CLOCK_OBJECT_ID),
2235
2293
  tx.object(TRADEPORT_MULTI_BID_STORE),
2236
- tx.pure.id(normalizeSuiObjectId(bidNonce)),
2294
+ tx.pure.id(normalizeSuiObjectId2(bidNonce)),
2237
2295
  tx.pure.option("id", multiBidChainId),
2238
2296
  tx.object(kioskTx.getKiosk()),
2239
2297
  tx.object(kioskTx.getKioskCap()),
@@ -2264,7 +2322,7 @@ async function addSingleBidAcceptNftBidTx(txData) {
2264
2322
  async function addTradePortAcceptNftBidTxHandler(txData) {
2265
2323
  const bidType = await getObjectType({
2266
2324
  suiClient: txData?.suiClient,
2267
- objectId: normalizeSuiObjectId(txData?.bidNonce)
2325
+ objectId: normalizeSuiObjectId2(txData?.bidNonce)
2268
2326
  });
2269
2327
  if (isSingleBid(bidType)) {
2270
2328
  await addSingleBidAcceptNftBidTx(txData);
@@ -2284,6 +2342,8 @@ async function addTradePortAcceptNftBidTxHandler(txData) {
2284
2342
  if (txData?.sellerKiosk) {
2285
2343
  const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
2286
2344
  const royaltyRulePackageId = await getRulePackageId({
2345
+ transferPolicies: txData?.transferPolicies,
2346
+ suiClient: txData?.suiClient,
2287
2347
  nftType: txData?.nftType,
2288
2348
  ruleType: "royalty_rule",
2289
2349
  kioskClient: txData?.kioskClient
@@ -2709,7 +2769,7 @@ function addTocenAcceptCollectionBidTx({
2709
2769
  async function addTradePortAcceptCollectionBidTxHandler(txData) {
2710
2770
  const bidType = await getObjectType({
2711
2771
  suiClient: txData?.suiClient,
2712
- objectId: normalizeSuiObjectId2(txData?.bidNonce)
2772
+ objectId: normalizeSuiObjectId3(txData?.bidNonce)
2713
2773
  });
2714
2774
  if (isSingleBid(bidType)) {
2715
2775
  await addSingleBidAcceptNftBidTx(txData);
@@ -2745,6 +2805,8 @@ async function addTradePortAcceptCollectionBidTxHandler(txData) {
2745
2805
  if (isTradePortKioskBid(bidType)) {
2746
2806
  const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
2747
2807
  const royaltyRulePackageId = await getRulePackageId({
2808
+ transferPolicies: txData?.transferPolicies,
2809
+ suiClient: txData?.suiClient,
2748
2810
  nftType: txData?.nftType,
2749
2811
  ruleType: "royalty_rule",
2750
2812
  kioskClient: txData?.kioskClient
@@ -3302,6 +3364,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
3302
3364
  });
3303
3365
  await resolveTransferPolicies({
3304
3366
  tx,
3367
+ transferPolicies,
3305
3368
  suiClient: context.suiClient,
3306
3369
  walletAddress,
3307
3370
  kioskTx,
@@ -3369,6 +3432,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
3369
3432
  });
3370
3433
  await resolveTransferPolicies({
3371
3434
  tx,
3435
+ transferPolicies,
3372
3436
  suiClient: context.suiClient,
3373
3437
  walletAddress,
3374
3438
  kioskTx,
@@ -3521,6 +3585,7 @@ function addTradePortBuyTx({ tx, nftType, listingNonce, price, sharedObjects })
3521
3585
  }
3522
3586
  var addTradeportKioskBuyTx = async ({
3523
3587
  tx,
3588
+ transferPolicies,
3524
3589
  kioskTx,
3525
3590
  suiClient,
3526
3591
  kioskClient,
@@ -3557,6 +3622,7 @@ var addTradeportKioskBuyTx = async ({
3557
3622
  });
3558
3623
  await resolveTransferPolicies({
3559
3624
  tx,
3625
+ transferPolicies,
3560
3626
  suiClient,
3561
3627
  walletAddress: seller,
3562
3628
  kioskTx,
@@ -3609,6 +3675,7 @@ async function addOriginByteBuyTx({
3609
3675
  }
3610
3676
  var addHyperspaceKioskBuyTx = async ({
3611
3677
  tx,
3678
+ transferPolicies,
3612
3679
  suiClient,
3613
3680
  kioskTx,
3614
3681
  kioskClient,
@@ -3640,6 +3707,7 @@ var addHyperspaceKioskBuyTx = async ({
3640
3707
  await beforeResolveKioskTransferRequest?.(transferRequest);
3641
3708
  await resolveTransferPolicies({
3642
3709
  tx,
3710
+ transferPolicies,
3643
3711
  suiClient,
3644
3712
  walletAddress: seller,
3645
3713
  kioskTx,
@@ -3704,6 +3772,7 @@ async function addBluemoveKioskBuyTx({
3704
3772
  await beforeResolveKioskTransferRequest?.(transferRequest);
3705
3773
  await resolveTransferPolicies({
3706
3774
  tx,
3775
+ transferPolicies,
3707
3776
  suiClient,
3708
3777
  walletAddress: seller,
3709
3778
  kioskTx,
@@ -4171,6 +4240,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
4171
4240
  });
4172
4241
  await resolveTransferPolicies({
4173
4242
  tx,
4243
+ transferPolicies,
4174
4244
  suiClient: context.suiClient,
4175
4245
  walletAddress,
4176
4246
  kioskTx,
@@ -4402,6 +4472,7 @@ var addClaimAcceptedBidNftTx = async ({
4402
4472
  });
4403
4473
  await resolveTransferPolicies({
4404
4474
  tx,
4475
+ transferPolicies,
4405
4476
  suiClient,
4406
4477
  walletAddress: claimer,
4407
4478
  kioskTx,
@@ -4438,6 +4509,7 @@ var addClaimAcceptedBidNftWithPurchaseCapTx = async ({
4438
4509
  });
4439
4510
  await resolveTransferPolicies({
4440
4511
  tx,
4512
+ transferPolicies,
4441
4513
  suiClient,
4442
4514
  walletAddress: claimer,
4443
4515
  kioskTx,
@@ -4473,6 +4545,7 @@ var addClaimTransferredNftTx = async ({
4473
4545
  });
4474
4546
  await resolveTransferPolicies({
4475
4547
  tx,
4548
+ transferPolicies,
4476
4549
  suiClient,
4477
4550
  walletAddress: claimer,
4478
4551
  kioskTx,
@@ -4510,6 +4583,7 @@ var addClaimTransferredNftWithPurchaseCapTx = async ({
4510
4583
  });
4511
4584
  await resolveTransferPolicies({
4512
4585
  tx,
4586
+ transferPolicies,
4513
4587
  suiClient,
4514
4588
  walletAddress: claimer,
4515
4589
  kioskTx,
@@ -5339,7 +5413,6 @@ var fetchBulkNftsByKioskId = gql18`
5339
5413
  `;
5340
5414
 
5341
5415
  // src/methods/transferNfts/addTransferNftTx.ts
5342
- import { normalizeSuiObjectId as normalizeSuiObjectId3, normalizeStructTag as normalizeStructTag2 } from "@mysten/sui/utils";
5343
5416
  async function addOriginByteTransferNftTx({
5344
5417
  tx,
5345
5418
  nftTokenId,
@@ -5478,19 +5551,10 @@ async function getTransferPolicyForDirectTransfer(suiClient, collectionChainStat
5478
5551
  ).length === 0
5479
5552
  );
5480
5553
  if (validateRules && candidatePolicy) {
5481
- const { data, error } = await suiClient.getObject({
5482
- id: normalizeSuiObjectId3(candidatePolicy.id),
5483
- options: {
5484
- showContent: true
5485
- }
5554
+ const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
5555
+ suiClient,
5556
+ transferPolicyId: candidatePolicy.id
5486
5557
  });
5487
- if (error) {
5488
- throw new Error(`Error on getting SUI object ${candidatePolicy.id}: ${error.code}`);
5489
- }
5490
- const content = data.content;
5491
- const ruleNames = content.fields.rules.fields.contents.map(
5492
- (rule) => normalizeStructTag2(rule.fields.name)
5493
- );
5494
5558
  if (!ruleNames.every((name) => name.startsWith(MYSTEN_TRANFER_POLICY_RULES_PACKAGE_ID))) {
5495
5559
  return void 0;
5496
5560
  }