@tradeport/sui-trading-sdk 0.4.11 → 0.4.12
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.js +53 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +2 -0
- package/src/methods/transferNfts/addTransferNftTx.ts +65 -16
- package/src/methods/transferNfts/transferNfts.ts +3 -2
package/dist/index.js
CHANGED
|
@@ -135,6 +135,7 @@ var fetchCollectionBidsAtSamePrice = import_graphql_request4.gql`
|
|
|
135
135
|
var import_transactions2 = require("@mysten/sui/transactions");
|
|
136
136
|
|
|
137
137
|
// src/constants.ts
|
|
138
|
+
var MYSTEN_TRANFER_POLICY_RULES_PACKAGE_ID = "0x434b5bd8f6a7b05fede0ff46c6e511d71ea326ed38056e3bcd681d2d7c2a7879";
|
|
138
139
|
var TRADEPORT_BENEFICIARY_ADDRESS = "0xbca3b5c01c8d1a93aed3a036feff45145518292dd3c1db1d67cc99a699a7b517";
|
|
139
140
|
var TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT = 0.03;
|
|
140
141
|
var TRADEPORT_THIRD_PARTY_FEE_DECIMAL_PERCENT = 5e-3;
|
|
@@ -5362,6 +5363,7 @@ var fetchBulkNftsByKioskId = import_graphql_request19.gql`
|
|
|
5362
5363
|
`;
|
|
5363
5364
|
|
|
5364
5365
|
// src/methods/transferNfts/addTransferNftTx.ts
|
|
5366
|
+
var import_utils8 = require("@mysten/sui/utils");
|
|
5365
5367
|
async function addOriginByteTransferNftTx({
|
|
5366
5368
|
tx,
|
|
5367
5369
|
nftTokenId,
|
|
@@ -5421,7 +5423,7 @@ async function addTradeportKioskTransferTx({
|
|
|
5421
5423
|
typeArguments: [nftType]
|
|
5422
5424
|
});
|
|
5423
5425
|
}
|
|
5424
|
-
async function addTradeportKioskDirectTransferTx(txData, nfts) {
|
|
5426
|
+
async function addTradeportKioskDirectTransferTx(txData, nfts, suiClient) {
|
|
5425
5427
|
const { tx, recipientAddress, kioskClient, senderAddress } = txData;
|
|
5426
5428
|
if (nfts.length === 0) {
|
|
5427
5429
|
return;
|
|
@@ -5439,14 +5441,20 @@ async function addTradeportKioskDirectTransferTx(txData, nfts) {
|
|
|
5439
5441
|
tx.pure.address(recipientAddressWithPrefix)
|
|
5440
5442
|
]
|
|
5441
5443
|
});
|
|
5442
|
-
const
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
(
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5444
|
+
const transferPolicies = new Map(
|
|
5445
|
+
await Promise.all(
|
|
5446
|
+
nfts.map(
|
|
5447
|
+
async (nft) => [
|
|
5448
|
+
nft.id,
|
|
5449
|
+
await getTransferPolicyForDirectTransfer(suiClient, nft.collection.chain_state)
|
|
5450
|
+
]
|
|
5451
|
+
)
|
|
5452
|
+
)
|
|
5453
|
+
);
|
|
5454
|
+
const royaltyAmounts = [...transferPolicies.values()].map(
|
|
5455
|
+
(transferPolicy) => BigInt(transferPolicy?.rules.find((rule) => rule.type === "royalty_rule")?.min_amount ?? 0n)
|
|
5449
5456
|
);
|
|
5457
|
+
const totalRoyaltyAmount = royaltyAmounts.reduce((sum, amount) => sum + amount, 0n);
|
|
5450
5458
|
const [royaltyCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(totalRoyaltyAmount)]);
|
|
5451
5459
|
for (const nft of nfts) {
|
|
5452
5460
|
const nftType = getNftType({
|
|
@@ -5468,7 +5476,7 @@ async function addTradeportKioskDirectTransferTx(txData, nfts) {
|
|
|
5468
5476
|
tx.object(receiverKiosk),
|
|
5469
5477
|
tx.object(receiverKioskCap),
|
|
5470
5478
|
tx.pure.id(nft.token_id),
|
|
5471
|
-
tx.object(
|
|
5479
|
+
tx.object(transferPolicies.get(nft.id).id),
|
|
5472
5480
|
royaltyCoin
|
|
5473
5481
|
],
|
|
5474
5482
|
typeArguments: [nftType]
|
|
@@ -5484,15 +5492,34 @@ async function addTradeportKioskDirectTransferTx(txData, nfts) {
|
|
|
5484
5492
|
});
|
|
5485
5493
|
destroyZeroCoin({ tx, coin: royaltyCoin });
|
|
5486
5494
|
}
|
|
5487
|
-
function canBeTransferedDirectly(collectionChainState) {
|
|
5488
|
-
return getTransferPolicyForDirectTransfer(collectionChainState) !== void 0;
|
|
5495
|
+
async function canBeTransferedDirectly(suiClient, collectionChainState) {
|
|
5496
|
+
return await getTransferPolicyForDirectTransfer(suiClient, collectionChainState, true) !== void 0;
|
|
5489
5497
|
}
|
|
5490
|
-
function getTransferPolicyForDirectTransfer(collectionChainState) {
|
|
5491
|
-
|
|
5498
|
+
async function getTransferPolicyForDirectTransfer(suiClient, collectionChainState, validateRules = false) {
|
|
5499
|
+
const candidatePolicy = collectionChainState?.transfer_policies?.find(
|
|
5492
5500
|
(policy) => !policy.is_origin_byte && policy.rules.length > 0 && policy.rules?.filter(
|
|
5493
5501
|
(rule) => rule.type !== "kiosk_lock_rule" && rule.type !== "royalty_rule"
|
|
5494
5502
|
).length === 0
|
|
5495
5503
|
);
|
|
5504
|
+
if (validateRules && candidatePolicy) {
|
|
5505
|
+
const { data, error } = await suiClient.getObject({
|
|
5506
|
+
id: (0, import_utils8.normalizeSuiObjectId)(candidatePolicy.id),
|
|
5507
|
+
options: {
|
|
5508
|
+
showContent: true
|
|
5509
|
+
}
|
|
5510
|
+
});
|
|
5511
|
+
if (error) {
|
|
5512
|
+
throw new Error(`Error on getting SUI object ${candidatePolicy.id}: ${error.code}`);
|
|
5513
|
+
}
|
|
5514
|
+
const content = data.content;
|
|
5515
|
+
const ruleNames = content.fields.rules.fields.contents.map(
|
|
5516
|
+
(rule) => (0, import_utils8.normalizeStructTag)(rule.fields.name)
|
|
5517
|
+
);
|
|
5518
|
+
if (!ruleNames.every((name) => name.startsWith(MYSTEN_TRANFER_POLICY_RULES_PACKAGE_ID))) {
|
|
5519
|
+
return void 0;
|
|
5520
|
+
}
|
|
5521
|
+
}
|
|
5522
|
+
return candidatePolicy;
|
|
5496
5523
|
}
|
|
5497
5524
|
|
|
5498
5525
|
// src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
|
|
@@ -5705,7 +5732,7 @@ var fetchCollectionsBySlug = import_graphql_request20.gql`
|
|
|
5705
5732
|
`;
|
|
5706
5733
|
|
|
5707
5734
|
// src/methods/placeNftBids/addPlaceNftBidTxs.ts
|
|
5708
|
-
var
|
|
5735
|
+
var import_utils9 = require("@mysten/sui/utils");
|
|
5709
5736
|
async function addTradePortPlaceNftBidTxHandler(txData) {
|
|
5710
5737
|
if (isOriginByteCollection(txData?.transferPolicies) && !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))) {
|
|
5711
5738
|
throw new Error("OriginByte bidding not supported currently");
|
|
@@ -5725,7 +5752,7 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
|
|
|
5725
5752
|
if (!bcsHex) {
|
|
5726
5753
|
throw new Error(`No BCS found for token ${nftTokenId}`);
|
|
5727
5754
|
}
|
|
5728
|
-
bcs3 = (0,
|
|
5755
|
+
bcs3 = (0, import_utils9.fromHex)(bcsHex);
|
|
5729
5756
|
}
|
|
5730
5757
|
let multiBidChainId;
|
|
5731
5758
|
if (existingMultiBidChainId) {
|
|
@@ -5765,12 +5792,12 @@ async function addTradePortPlaceNftBidTxHandler(txData) {
|
|
|
5765
5792
|
arguments: [
|
|
5766
5793
|
tx.object(TRADEPORT_MULTI_BID_STORE),
|
|
5767
5794
|
tx.pure.u64(nftTokenId ? 1 : 0),
|
|
5768
|
-
multiBidChainId ? typeof multiBidChainId === "string" ? tx.pure.option("id", (0,
|
|
5795
|
+
multiBidChainId ? typeof multiBidChainId === "string" ? tx.pure.option("id", (0, import_utils9.normalizeSuiObjectId)(multiBidChainId)) : tx.moveCall({
|
|
5769
5796
|
target: "0x1::option::some",
|
|
5770
5797
|
typeArguments: ["0x2::object::ID"],
|
|
5771
5798
|
arguments: [multiBidChainId]
|
|
5772
5799
|
}) : void 0,
|
|
5773
|
-
tx.pure.option("id", nftTokenId ? (0,
|
|
5800
|
+
tx.pure.option("id", nftTokenId ? (0, import_utils9.normalizeSuiObjectId)(nftTokenId) : void 0),
|
|
5774
5801
|
tx.pure.option("vector<u8>", bcs3 ? [...bcs3] : void 0),
|
|
5775
5802
|
tx.pure.option("u64", expireAt?.getTime()),
|
|
5776
5803
|
tx.pure.u64(price),
|
|
@@ -5972,10 +5999,10 @@ var placeNftBids = async ({ bids, walletAddress, multiBidId, multiBidChainId, tx
|
|
|
5972
5999
|
var import_transactions22 = require("@mysten/sui/transactions");
|
|
5973
6000
|
|
|
5974
6001
|
// src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
|
|
5975
|
-
var
|
|
6002
|
+
var import_utils11 = require("@mysten/sui/utils");
|
|
5976
6003
|
|
|
5977
6004
|
// src/methods/removeNftBids/addRemoveNftBidTxs.ts
|
|
5978
|
-
var
|
|
6005
|
+
var import_utils10 = require("@mysten/sui/utils");
|
|
5979
6006
|
function addTradeportRemoveNftBidTx({ tx, bidNonce, nftType }) {
|
|
5980
6007
|
tx.moveCall({
|
|
5981
6008
|
target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::cancel_bid",
|
|
@@ -6029,7 +6056,7 @@ async function addSingleBidRemoveNftBidTx({ tx, bidNonce, multiBidId }) {
|
|
|
6029
6056
|
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::cancel_bid`,
|
|
6030
6057
|
arguments: [
|
|
6031
6058
|
tx.object(TRADEPORT_MULTI_BID_STORE),
|
|
6032
|
-
tx.pure.id((0,
|
|
6059
|
+
tx.pure.id((0, import_utils10.normalizeSuiObjectId)(bidNonce)),
|
|
6033
6060
|
tx.pure.option("id", multiBidChainId)
|
|
6034
6061
|
]
|
|
6035
6062
|
});
|
|
@@ -6037,7 +6064,7 @@ async function addSingleBidRemoveNftBidTx({ tx, bidNonce, multiBidId }) {
|
|
|
6037
6064
|
async function addTradePortRemoveNftBidTxHandler(txData) {
|
|
6038
6065
|
const bidType = await getObjectType({
|
|
6039
6066
|
suiClient: txData?.suiClient,
|
|
6040
|
-
objectId: (0,
|
|
6067
|
+
objectId: (0, import_utils10.normalizeSuiObjectId)(txData?.bidNonce)
|
|
6041
6068
|
});
|
|
6042
6069
|
if (isSingleBid(bidType)) {
|
|
6043
6070
|
await addSingleBidRemoveNftBidTx(txData);
|
|
@@ -6110,7 +6137,7 @@ function addBluemoveKioskRemoveCollectionBidTx({
|
|
|
6110
6137
|
async function addTradePortRemoveCollectionBidTxHandler(txData) {
|
|
6111
6138
|
const bidType = await getObjectType({
|
|
6112
6139
|
suiClient: txData?.suiClient,
|
|
6113
|
-
objectId: (0,
|
|
6140
|
+
objectId: (0, import_utils11.normalizeSuiObjectId)(txData?.bidNonce)
|
|
6114
6141
|
});
|
|
6115
6142
|
if (isSingleBid(bidType)) {
|
|
6116
6143
|
await addSingleBidRemoveNftBidTx(txData);
|
|
@@ -6130,7 +6157,7 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
|
|
|
6130
6157
|
async function addBluemoveRemoveCollectionBidTxHandler(txData) {
|
|
6131
6158
|
const bidType = await getObjectType({
|
|
6132
6159
|
suiClient: txData?.suiClient,
|
|
6133
|
-
objectId: (0,
|
|
6160
|
+
objectId: (0, import_utils11.normalizeSuiObjectId)(txData?.bidNonce)
|
|
6134
6161
|
});
|
|
6135
6162
|
if (isOriginByteBid(bidType)) {
|
|
6136
6163
|
const sharedObjects = await getSharedObjects(txData?.nftType);
|
|
@@ -6343,7 +6370,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6343
6370
|
await addOriginByteTransferNftTx(txData);
|
|
6344
6371
|
continue;
|
|
6345
6372
|
}
|
|
6346
|
-
if (canBeTransferedDirectly(nft?.collection?.chain_state)) {
|
|
6373
|
+
if (await canBeTransferedDirectly(context.suiClient, nft?.collection?.chain_state)) {
|
|
6347
6374
|
nftsToTransferDirectly.push(nft);
|
|
6348
6375
|
} else {
|
|
6349
6376
|
await kioskTxWrapper({
|
|
@@ -6365,7 +6392,8 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6365
6392
|
}
|
|
6366
6393
|
await addTradeportKioskDirectTransferTx(
|
|
6367
6394
|
{ tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
|
|
6368
|
-
nftsToTransferDirectly
|
|
6395
|
+
nftsToTransferDirectly,
|
|
6396
|
+
context.suiClient
|
|
6369
6397
|
);
|
|
6370
6398
|
return import_transactions24.Transaction.from(tx);
|
|
6371
6399
|
};
|