@tradeport/sui-trading-sdk 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.demo +2 -1
- package/CHANGELOG.md +6 -0
- package/dist/index.js +98 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/graphql/queries/fetchNftsByKioskId.ts +22 -0
- package/src/helpers/destroyZeroCoin.ts +1 -1
- package/src/helpers/kiosk/kioskTxWrapper.ts +5 -6
- package/src/helpers/kiosk/resolveTransferPolicies.ts +1 -1
- package/src/helpers/rpc/getObjectType.ts +6 -2
- package/src/methods/claimNfts/addClaimNftsTxs.ts +5 -3
- package/src/methods/claimNfts/claimNfts.ts +15 -0
- package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +56 -18
- package/src/methods/transferNfts/addTransferNftTx.ts +4 -3
- package/src/methods/transferNfts/transferNfts.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -1479,10 +1479,7 @@ var kioskTxWrapper = async ({
|
|
|
1479
1479
|
version: ""
|
|
1480
1480
|
}
|
|
1481
1481
|
});
|
|
1482
|
-
} else if (
|
|
1483
|
-
kioskTx = new KioskTransaction({ transactionBlock: tx, kioskClient });
|
|
1484
|
-
kioskTx.createPersonal(true);
|
|
1485
|
-
} else {
|
|
1482
|
+
} else if (kiosks.length > 0 && !shouldConvertToPersonalKiosk) {
|
|
1486
1483
|
const kioskCapId = (await gqlChainRequest({
|
|
1487
1484
|
chain: "sui",
|
|
1488
1485
|
query: fetchOwnerCapByKiosk,
|
|
@@ -1499,9 +1496,11 @@ var kioskTxWrapper = async ({
|
|
|
1499
1496
|
version: ""
|
|
1500
1497
|
}
|
|
1501
1498
|
});
|
|
1499
|
+
} else {
|
|
1500
|
+
kioskTx = new KioskTransaction({ transactionBlock: tx, kioskClient });
|
|
1501
|
+
kioskTx.createPersonal(true);
|
|
1502
1502
|
}
|
|
1503
1503
|
await runCommands(kioskTx);
|
|
1504
|
-
kioskTx.finalize();
|
|
1505
1504
|
};
|
|
1506
1505
|
|
|
1507
1506
|
// src/helpers/originByte/confirmOBTranfer.ts
|
|
@@ -1617,8 +1616,9 @@ var getObjectType = async ({
|
|
|
1617
1616
|
suiClient,
|
|
1618
1617
|
objectId
|
|
1619
1618
|
}) => {
|
|
1620
|
-
|
|
1621
|
-
|
|
1619
|
+
const normalizedObjectId = objectId.startsWith("0x") ? addLeadingZerosAfter0x(objectId) : objectId;
|
|
1620
|
+
if (isValidSuiObjectId(normalizedObjectId)) {
|
|
1621
|
+
const res = await suiClient.getObject({ id: normalizedObjectId, options: { showType: true } });
|
|
1622
1622
|
return res.data.type;
|
|
1623
1623
|
}
|
|
1624
1624
|
return "";
|
|
@@ -4437,16 +4437,17 @@ var addClaimTransferredNftWithPurchaseCapTx = async ({
|
|
|
4437
4437
|
kioskClient,
|
|
4438
4438
|
nftTokenId,
|
|
4439
4439
|
nftType,
|
|
4440
|
-
sellerKiosk
|
|
4440
|
+
sellerKiosk,
|
|
4441
|
+
preloadedTransferPolicyId
|
|
4441
4442
|
}) => {
|
|
4442
|
-
const transferPolicyId = (await getKioskTransferPolicies(nftType))?.at(0)?.id;
|
|
4443
|
+
const transferPolicyId = preloadedTransferPolicyId ?? (await getKioskTransferPolicies(nftType))?.at(0)?.id;
|
|
4443
4444
|
const [transferRequest] = tx.moveCall({
|
|
4444
4445
|
target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::claim_with_purchase_cap",
|
|
4445
4446
|
arguments: [
|
|
4446
4447
|
tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
|
|
4447
4448
|
tx.object(sellerKiosk),
|
|
4448
|
-
|
|
4449
|
-
|
|
4449
|
+
kioskTx.kiosk,
|
|
4450
|
+
kioskTx.kioskCap,
|
|
4450
4451
|
tx.pure.address(nftTokenId),
|
|
4451
4452
|
tx.object(transferPolicyId)
|
|
4452
4453
|
],
|
|
@@ -4518,7 +4519,9 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
4518
4519
|
variables: { ownerAddress: addLeadingZerosAfter0x(walletAddress) }
|
|
4519
4520
|
});
|
|
4520
4521
|
const walletAddressKiosks = kiosksByOwnerRes?.kiosks;
|
|
4522
|
+
let globalKioskTx;
|
|
4521
4523
|
for (const nft of res.nfts) {
|
|
4524
|
+
let existingKioskTx;
|
|
4522
4525
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
|
|
4523
4526
|
throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
|
|
4524
4527
|
}
|
|
@@ -4567,9 +4570,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
4567
4570
|
kioskOwner: txData?.claimer,
|
|
4568
4571
|
kioskOwnerKiosks: walletAddressKiosks,
|
|
4569
4572
|
kiosk: txData?.sellerKiosk,
|
|
4573
|
+
kioskTx: globalKioskTx,
|
|
4570
4574
|
shouldConvertToPersonalKiosk: true,
|
|
4571
4575
|
shouldAllowNftUnsharedKiosk: true,
|
|
4572
4576
|
async runCommands(kioskTx) {
|
|
4577
|
+
existingKioskTx = kioskTx;
|
|
4573
4578
|
await addBluemoveClaimAcceptedBidNft({
|
|
4574
4579
|
...txData,
|
|
4575
4580
|
suiClient: context.suiClient,
|
|
@@ -4586,9 +4591,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
4586
4591
|
kioskOwner: txData?.claimer,
|
|
4587
4592
|
kioskOwnerKiosks: walletAddressKiosks,
|
|
4588
4593
|
kiosk: txData?.sellerKiosk,
|
|
4594
|
+
kioskTx: globalKioskTx,
|
|
4589
4595
|
shouldConvertToPersonalKiosk: true,
|
|
4590
4596
|
shouldAllowNftUnsharedKiosk: true,
|
|
4591
4597
|
async runCommands(kioskTx) {
|
|
4598
|
+
existingKioskTx = kioskTx;
|
|
4592
4599
|
await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
|
|
4593
4600
|
}
|
|
4594
4601
|
});
|
|
@@ -4599,9 +4606,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
4599
4606
|
kioskOwner: txData?.claimer,
|
|
4600
4607
|
kioskOwnerKiosks: walletAddressKiosks,
|
|
4601
4608
|
kiosk: txData?.sellerKiosk,
|
|
4609
|
+
kioskTx: globalKioskTx,
|
|
4602
4610
|
shouldConvertToPersonalKiosk: true,
|
|
4603
4611
|
shouldAssertNftInSharedKiosk: true,
|
|
4604
4612
|
async runCommands(kioskTx) {
|
|
4613
|
+
existingKioskTx = kioskTx;
|
|
4605
4614
|
await addClaimAcceptedBidNftWithPurchaseCapTx({ ...txData, kioskTx });
|
|
4606
4615
|
}
|
|
4607
4616
|
});
|
|
@@ -4627,9 +4636,11 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
4627
4636
|
kiosk: txData?.sellerKiosk,
|
|
4628
4637
|
kioskOwnerKiosks: walletAddressKiosks,
|
|
4629
4638
|
kioskStrategy: "exclude",
|
|
4639
|
+
kioskTx: globalKioskTx,
|
|
4630
4640
|
shouldConvertToPersonalKiosk: true,
|
|
4631
4641
|
shouldAllowNftUnsharedKiosk: true,
|
|
4632
4642
|
async runCommands(kioskTx) {
|
|
4643
|
+
existingKioskTx = kioskTx;
|
|
4633
4644
|
await addClaimTransferredNftTx({ ...txData, kioskTx });
|
|
4634
4645
|
}
|
|
4635
4646
|
});
|
|
@@ -4641,15 +4652,19 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
4641
4652
|
kiosk: txData?.sellerKiosk,
|
|
4642
4653
|
kioskOwnerKiosks: walletAddressKiosks,
|
|
4643
4654
|
kioskStrategy: "exclude",
|
|
4655
|
+
kioskTx: globalKioskTx,
|
|
4644
4656
|
shouldConvertToPersonalKiosk: true,
|
|
4645
4657
|
shouldAllowNftUnsharedKiosk: true,
|
|
4646
4658
|
async runCommands(kioskTx) {
|
|
4659
|
+
existingKioskTx = kioskTx;
|
|
4647
4660
|
await addClaimTransferredNftWithPurchaseCapTx({ ...txData, kioskTx });
|
|
4648
4661
|
}
|
|
4649
4662
|
});
|
|
4650
4663
|
}
|
|
4651
4664
|
}
|
|
4665
|
+
globalKioskTx = existingKioskTx;
|
|
4652
4666
|
}
|
|
4667
|
+
globalKioskTx?.finalize();
|
|
4653
4668
|
return Transaction13.from(tx);
|
|
4654
4669
|
};
|
|
4655
4670
|
|
|
@@ -5230,6 +5245,27 @@ var fetchNftsByKioskId = gql18`
|
|
|
5230
5245
|
}
|
|
5231
5246
|
}
|
|
5232
5247
|
`;
|
|
5248
|
+
var fetchBulkNftsByKioskId = gql18`
|
|
5249
|
+
query fetchNftsByKioskId($where: nfts_bool_exp) {
|
|
5250
|
+
nfts(where: $where) {
|
|
5251
|
+
id
|
|
5252
|
+
name
|
|
5253
|
+
token_id
|
|
5254
|
+
properties
|
|
5255
|
+
chain_state
|
|
5256
|
+
collection_id
|
|
5257
|
+
claimable_reason
|
|
5258
|
+
owner
|
|
5259
|
+
contract {
|
|
5260
|
+
properties
|
|
5261
|
+
}
|
|
5262
|
+
collection {
|
|
5263
|
+
id
|
|
5264
|
+
chain_state
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
}
|
|
5268
|
+
`;
|
|
5233
5269
|
|
|
5234
5270
|
// src/methods/transferNfts/addTransferNftTx.ts
|
|
5235
5271
|
async function addOriginByteTransferNftTx({
|
|
@@ -5268,10 +5304,11 @@ async function addTradeportKioskTransferTx({
|
|
|
5268
5304
|
kioskTx,
|
|
5269
5305
|
nftTokenId,
|
|
5270
5306
|
nftType,
|
|
5271
|
-
recipientAddress
|
|
5307
|
+
recipientAddress,
|
|
5308
|
+
transferPolicy
|
|
5272
5309
|
}) {
|
|
5273
|
-
const
|
|
5274
|
-
const hasFloorPriceRule =
|
|
5310
|
+
const existingTransferPolicy = transferPolicy ?? (await getKioskTransferPolicies(nftType))?.at(0);
|
|
5311
|
+
const hasFloorPriceRule = existingTransferPolicy?.rules?.some(
|
|
5275
5312
|
(rule) => rule.type === "floor_price_rule"
|
|
5276
5313
|
);
|
|
5277
5314
|
if (hasFloorPriceRule) {
|
|
@@ -5364,7 +5401,7 @@ function getTransferPolicyForDirectTransfer(collectionChainState) {
|
|
|
5364
5401
|
}
|
|
5365
5402
|
|
|
5366
5403
|
// src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
|
|
5367
|
-
async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max =
|
|
5404
|
+
async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 50 }, context) {
|
|
5368
5405
|
const tx = new Transaction19();
|
|
5369
5406
|
const res = await gqlChainRequest({
|
|
5370
5407
|
chain: "sui",
|
|
@@ -5421,20 +5458,52 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
|
|
|
5421
5458
|
}
|
|
5422
5459
|
}
|
|
5423
5460
|
const unsharedNativeKiosks = res?.kiosks?.filter((k) => !k.is_shared && !k.is_origin_byte)?.map((k) => k.id);
|
|
5461
|
+
const allNfts = await gqlChainRequest({
|
|
5462
|
+
chain: "sui",
|
|
5463
|
+
query: fetchBulkNftsByKioskId,
|
|
5464
|
+
variables: {
|
|
5465
|
+
where: {
|
|
5466
|
+
_or: unsharedNativeKiosks.map((nk) => ({
|
|
5467
|
+
chain_state: { _contains: { kiosk_id: nk } }
|
|
5468
|
+
}))
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5471
|
+
});
|
|
5472
|
+
const formatted = {};
|
|
5473
|
+
allNfts.nfts.forEach((e) => {
|
|
5474
|
+
if (formatted[e.chain_state.kiosk_id]) {
|
|
5475
|
+
formatted[e.chain_state.kiosk_id]?.push(e);
|
|
5476
|
+
} else {
|
|
5477
|
+
formatted[e.chain_state.kiosk_id] = [e];
|
|
5478
|
+
}
|
|
5479
|
+
});
|
|
5480
|
+
const allNftTypes = allNfts.nfts.reduce((acc, curr) => {
|
|
5481
|
+
const type = getNftType({
|
|
5482
|
+
collectionId: curr?.collection?.id,
|
|
5483
|
+
collectionChainState: curr?.collection?.chain_state,
|
|
5484
|
+
nft: curr
|
|
5485
|
+
});
|
|
5486
|
+
if (!acc.includes(type)) acc.push(type);
|
|
5487
|
+
return acc;
|
|
5488
|
+
}, []);
|
|
5489
|
+
const transferPolicies = await Promise.all(
|
|
5490
|
+
allNftTypes.map(async (type) => getKioskTransferPolicies(type))
|
|
5491
|
+
);
|
|
5492
|
+
const mappedTrasferPolicies = {};
|
|
5493
|
+
transferPolicies.forEach((tp) => {
|
|
5494
|
+
mappedTrasferPolicies[tp.transfer_policies_by_type?.[0]?.type] = tp.transfer_policies_by_type;
|
|
5495
|
+
});
|
|
5496
|
+
let globalKioskTx;
|
|
5424
5497
|
for (const unsharedNativeKiosk of unsharedNativeKiosks) {
|
|
5425
5498
|
if (currentMigrationCount >= max) {
|
|
5426
5499
|
continue;
|
|
5427
5500
|
}
|
|
5428
|
-
const
|
|
5429
|
-
chain: "sui",
|
|
5430
|
-
query: fetchNftsByKioskId,
|
|
5431
|
-
variables: { jsonFilter: { kiosk_id: unsharedNativeKiosk } }
|
|
5432
|
-
});
|
|
5433
|
-
const nfts = res2?.nfts;
|
|
5501
|
+
const nfts = formatted[unsharedNativeKiosk] ?? [];
|
|
5434
5502
|
if (nfts?.length > 0) {
|
|
5435
5503
|
currentMigrationCount++;
|
|
5436
5504
|
}
|
|
5437
5505
|
for (const nft of nfts) {
|
|
5506
|
+
let existingKioskTx;
|
|
5438
5507
|
if (nft?.claimable_reason === "offer-transfer") {
|
|
5439
5508
|
continue;
|
|
5440
5509
|
}
|
|
@@ -5459,7 +5528,8 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
|
|
|
5459
5528
|
senderAddress: walletAddress,
|
|
5460
5529
|
recipientAddress: walletAddress,
|
|
5461
5530
|
nftTokenId,
|
|
5462
|
-
nftType
|
|
5531
|
+
nftType,
|
|
5532
|
+
transferPolicy: mappedTrasferPolicies[nftType]?.[0]
|
|
5463
5533
|
});
|
|
5464
5534
|
}
|
|
5465
5535
|
});
|
|
@@ -5469,8 +5539,10 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
|
|
|
5469
5539
|
kioskOwner: walletAddress,
|
|
5470
5540
|
kiosk: unsharedNativeKiosk,
|
|
5471
5541
|
kioskStrategy: "exclude",
|
|
5542
|
+
kioskTx: globalKioskTx,
|
|
5472
5543
|
shouldConvertToPersonalKiosk: true,
|
|
5473
5544
|
async runCommands(kioskTx) {
|
|
5545
|
+
existingKioskTx = kioskTx;
|
|
5474
5546
|
await addClaimTransferredNftWithPurchaseCapTx({
|
|
5475
5547
|
tx,
|
|
5476
5548
|
kioskTx,
|
|
@@ -5481,12 +5553,15 @@ async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress, max = 5 },
|
|
|
5481
5553
|
nftTokenId,
|
|
5482
5554
|
nftType,
|
|
5483
5555
|
sellerKiosk: unsharedNativeKiosk,
|
|
5484
|
-
seller: nft?.owner
|
|
5556
|
+
seller: nft?.owner,
|
|
5557
|
+
preloadedTransferPolicyId: mappedTrasferPolicies[nftType]?.[0]?.id
|
|
5485
5558
|
});
|
|
5486
5559
|
}
|
|
5487
5560
|
});
|
|
5561
|
+
globalKioskTx = existingKioskTx;
|
|
5488
5562
|
}
|
|
5489
5563
|
}
|
|
5564
|
+
globalKioskTx?.finalize();
|
|
5490
5565
|
return Transaction19.from(tx);
|
|
5491
5566
|
}
|
|
5492
5567
|
|