@tradeport/sui-trading-sdk 0.2.1 → 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 +12 -0
- package/dist/index.js +92 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -51
- 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 +32 -15
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) {
|
|
@@ -5981,44 +6054,6 @@ var removeNftBids = async ({ bidIds }, context) => {
|
|
|
5981
6054
|
// src/methods/transferNfts/transferNfts.ts
|
|
5982
6055
|
var import_transactions21 = require("@mysten/sui/transactions");
|
|
5983
6056
|
|
|
5984
|
-
// src/graphql/queries/fetchCryptoToUsdRate.ts
|
|
5985
|
-
var import_graphql_request21 = require("graphql-request");
|
|
5986
|
-
var fetchCryptoToUsdRate = import_graphql_request21.gql`
|
|
5987
|
-
query fetchCryptoToUsdRate($crypto: String!) {
|
|
5988
|
-
crypto_rates(where: { crypto: { _eq: $crypto }, fiat: { _eq: "USD" } }) {
|
|
5989
|
-
crypto
|
|
5990
|
-
fiat
|
|
5991
|
-
id
|
|
5992
|
-
rate
|
|
5993
|
-
timestamp
|
|
5994
|
-
}
|
|
5995
|
-
}
|
|
5996
|
-
`;
|
|
5997
|
-
|
|
5998
|
-
// src/helpers/getSuiToUsdRate.ts
|
|
5999
|
-
var getSuiToUsdRate = async () => {
|
|
6000
|
-
try {
|
|
6001
|
-
const res = await gqlChainRequest({
|
|
6002
|
-
chain: "sui",
|
|
6003
|
-
query: fetchCryptoToUsdRate,
|
|
6004
|
-
variables: { crypto: "sui" }
|
|
6005
|
-
});
|
|
6006
|
-
return res?.crypto_rates?.[0]?.rate;
|
|
6007
|
-
} catch (e) {
|
|
6008
|
-
}
|
|
6009
|
-
};
|
|
6010
|
-
|
|
6011
|
-
// src/helpers/addOneDollarFee.ts
|
|
6012
|
-
var addOneDollarFee = async (tx) => {
|
|
6013
|
-
const rate = await getSuiToUsdRate();
|
|
6014
|
-
const companyFee = BigInt(Math.ceil(1e9 / rate));
|
|
6015
|
-
const [microTxFee] = tx.splitCoins(tx.gas, [tx.pure.u64(Number(companyFee))]);
|
|
6016
|
-
tx.transferObjects(
|
|
6017
|
-
[tx.object(microTxFee)],
|
|
6018
|
-
tx.pure.address(addLeadingZerosAfter0x(TRADEPORT_BENEFICIARY_ADDRESS))
|
|
6019
|
-
);
|
|
6020
|
-
};
|
|
6021
|
-
|
|
6022
6057
|
// src/helpers/rpc/getAcountBalance.ts
|
|
6023
6058
|
var getAccountBalance = async ({ suiClient, owner }) => {
|
|
6024
6059
|
try {
|
|
@@ -6052,6 +6087,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6052
6087
|
throw new Error("No nfts found");
|
|
6053
6088
|
}
|
|
6054
6089
|
const nftsForTracking = [];
|
|
6090
|
+
const nftsToTransferDirectly = [];
|
|
6055
6091
|
const tx = new import_transactions21.Transaction();
|
|
6056
6092
|
for (const nft of res.nfts) {
|
|
6057
6093
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
|
|
@@ -6088,25 +6124,30 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6088
6124
|
await addOriginByteTransferNftTx(txData);
|
|
6089
6125
|
continue;
|
|
6090
6126
|
}
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
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
|
+
}
|
|
6101
6141
|
nftsForTracking.push({
|
|
6102
6142
|
nftType,
|
|
6103
6143
|
senderAddress: walletAddress,
|
|
6104
6144
|
recipientAddress
|
|
6105
6145
|
});
|
|
6106
6146
|
}
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6147
|
+
await addTradeportKioskDirectTransferTx(
|
|
6148
|
+
{ tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
|
|
6149
|
+
nftsToTransferDirectly
|
|
6150
|
+
);
|
|
6110
6151
|
return import_transactions21.Transaction.from(tx);
|
|
6111
6152
|
};
|
|
6112
6153
|
|