@tradeport/sui-trading-sdk 0.2.2 → 0.3.0
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/CHANGELOG.md +6 -0
- package/dist/index.js +92 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/methods/transferNfts/addTransferNftTx.ts +108 -0
- package/src/methods/transferNfts/transferNfts.ts +28 -11
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -5089,6 +5089,79 @@ async function addTradeportKioskTransferTx({
|
|
|
5089
5089
|
typeArguments: [nftType]
|
|
5090
5090
|
});
|
|
5091
5091
|
}
|
|
5092
|
+
async function addTradeportKioskDirectTransferTx(txData, nfts) {
|
|
5093
|
+
const { tx, recipientAddress, kioskClient, senderAddress } = txData;
|
|
5094
|
+
if (nfts.length === 0) {
|
|
5095
|
+
return;
|
|
5096
|
+
}
|
|
5097
|
+
const [receiverKiosk, receiverKioskCap] = tx.moveCall({
|
|
5098
|
+
target: "0x2::kiosk::new",
|
|
5099
|
+
arguments: []
|
|
5100
|
+
});
|
|
5101
|
+
const recipientAddressWithPrefix = addLeadingZerosAfter0x(recipientAddress);
|
|
5102
|
+
tx.moveCall({
|
|
5103
|
+
target: "0x2::kiosk::set_owner_custom",
|
|
5104
|
+
arguments: [
|
|
5105
|
+
tx.object(receiverKiosk),
|
|
5106
|
+
tx.object(receiverKioskCap),
|
|
5107
|
+
tx.pure.address(recipientAddressWithPrefix)
|
|
5108
|
+
]
|
|
5109
|
+
});
|
|
5110
|
+
const totalRoyaltyAmount = nfts.reduce(
|
|
5111
|
+
(sum, nft) => sum + BigInt(
|
|
5112
|
+
getTransferPolicyForDirectTransfer(nft.collection.chain_state)?.rules?.find(
|
|
5113
|
+
(rule) => rule.type === "royalty_rule"
|
|
5114
|
+
)?.min_amount ?? 0n
|
|
5115
|
+
),
|
|
5116
|
+
0n
|
|
5117
|
+
);
|
|
5118
|
+
const [royaltyCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(totalRoyaltyAmount)]);
|
|
5119
|
+
for (const nft of nfts) {
|
|
5120
|
+
const nftType = getNftType({
|
|
5121
|
+
collectionId: nft?.collection?.id,
|
|
5122
|
+
collectionChainState: nft?.collection?.chain_state,
|
|
5123
|
+
nft
|
|
5124
|
+
});
|
|
5125
|
+
await kioskTxWrapper({
|
|
5126
|
+
tx,
|
|
5127
|
+
kioskClient,
|
|
5128
|
+
kioskOwner: senderAddress,
|
|
5129
|
+
kiosk: nft?.chain_state?.kiosk_id,
|
|
5130
|
+
async runCommands(kioskTx) {
|
|
5131
|
+
tx.moveCall({
|
|
5132
|
+
target: "0xd0ad5bf7ac7d372cdcfee5273d5e487dabad724040e089c626cba2a01127ccd6::kiosk_transfers::direct_transfer",
|
|
5133
|
+
arguments: [
|
|
5134
|
+
tx.object(kioskTx.getKiosk()),
|
|
5135
|
+
tx.object(kioskTx.getKioskCap()),
|
|
5136
|
+
tx.object(receiverKiosk),
|
|
5137
|
+
tx.object(receiverKioskCap),
|
|
5138
|
+
tx.pure.id(nft.token_id),
|
|
5139
|
+
tx.object(getTransferPolicyForDirectTransfer(nft.collection.chain_state).id),
|
|
5140
|
+
royaltyCoin
|
|
5141
|
+
],
|
|
5142
|
+
typeArguments: [nftType]
|
|
5143
|
+
});
|
|
5144
|
+
}
|
|
5145
|
+
});
|
|
5146
|
+
}
|
|
5147
|
+
tx.transferObjects([receiverKioskCap], tx.pure.address(recipientAddressWithPrefix));
|
|
5148
|
+
tx.moveCall({
|
|
5149
|
+
target: "0x2::transfer::public_share_object",
|
|
5150
|
+
arguments: [receiverKiosk],
|
|
5151
|
+
typeArguments: ["0x2::kiosk::Kiosk"]
|
|
5152
|
+
});
|
|
5153
|
+
destroyZeroCoin({ tx, coin: royaltyCoin });
|
|
5154
|
+
}
|
|
5155
|
+
function canBeTransferedDirectly(collectionChainState) {
|
|
5156
|
+
return getTransferPolicyForDirectTransfer(collectionChainState) !== void 0;
|
|
5157
|
+
}
|
|
5158
|
+
function getTransferPolicyForDirectTransfer(collectionChainState) {
|
|
5159
|
+
return collectionChainState?.transfer_policies?.find(
|
|
5160
|
+
(policy) => !policy.is_origin_byte && policy.rules?.filter(
|
|
5161
|
+
(rule) => rule.type !== "kiosk_lock_rule" && rule.type !== "royalty_rule"
|
|
5162
|
+
).length === 0
|
|
5163
|
+
);
|
|
5164
|
+
}
|
|
5092
5165
|
|
|
5093
5166
|
// src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
|
|
5094
5167
|
async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress }, context) {
|
|
@@ -6014,6 +6087,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6014
6087
|
throw new Error("No nfts found");
|
|
6015
6088
|
}
|
|
6016
6089
|
const nftsForTracking = [];
|
|
6090
|
+
const nftsToTransferDirectly = [];
|
|
6017
6091
|
const tx = new import_transactions21.Transaction();
|
|
6018
6092
|
for (const nft of res.nfts) {
|
|
6019
6093
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
|
|
@@ -6050,22 +6124,30 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6050
6124
|
await addOriginByteTransferNftTx(txData);
|
|
6051
6125
|
continue;
|
|
6052
6126
|
}
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6127
|
+
if (canBeTransferedDirectly(nft?.collection?.chain_state)) {
|
|
6128
|
+
nftsToTransferDirectly.push(nft);
|
|
6129
|
+
} else {
|
|
6130
|
+
await kioskTxWrapper({
|
|
6131
|
+
tx: txData?.tx,
|
|
6132
|
+
kioskClient: txData?.kioskClient,
|
|
6133
|
+
kioskOwner: txData?.senderAddress,
|
|
6134
|
+
kiosk: txData?.senderKiosk,
|
|
6135
|
+
shouldAssertNftInSharedKiosk: true,
|
|
6136
|
+
async runCommands(kioskTx) {
|
|
6137
|
+
await addTradeportKioskTransferTx({ ...txData, kioskTx });
|
|
6138
|
+
}
|
|
6139
|
+
});
|
|
6140
|
+
}
|
|
6063
6141
|
nftsForTracking.push({
|
|
6064
6142
|
nftType,
|
|
6065
6143
|
senderAddress: walletAddress,
|
|
6066
6144
|
recipientAddress
|
|
6067
6145
|
});
|
|
6068
6146
|
}
|
|
6147
|
+
await addTradeportKioskDirectTransferTx(
|
|
6148
|
+
{ tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
|
|
6149
|
+
nftsToTransferDirectly
|
|
6150
|
+
);
|
|
6069
6151
|
return import_transactions21.Transaction.from(tx);
|
|
6070
6152
|
};
|
|
6071
6153
|
|