@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/dist/index.mjs
CHANGED
|
@@ -5065,6 +5065,79 @@ async function addTradeportKioskTransferTx({
|
|
|
5065
5065
|
typeArguments: [nftType]
|
|
5066
5066
|
});
|
|
5067
5067
|
}
|
|
5068
|
+
async function addTradeportKioskDirectTransferTx(txData, nfts) {
|
|
5069
|
+
const { tx, recipientAddress, kioskClient, senderAddress } = txData;
|
|
5070
|
+
if (nfts.length === 0) {
|
|
5071
|
+
return;
|
|
5072
|
+
}
|
|
5073
|
+
const [receiverKiosk, receiverKioskCap] = tx.moveCall({
|
|
5074
|
+
target: "0x2::kiosk::new",
|
|
5075
|
+
arguments: []
|
|
5076
|
+
});
|
|
5077
|
+
const recipientAddressWithPrefix = addLeadingZerosAfter0x(recipientAddress);
|
|
5078
|
+
tx.moveCall({
|
|
5079
|
+
target: "0x2::kiosk::set_owner_custom",
|
|
5080
|
+
arguments: [
|
|
5081
|
+
tx.object(receiverKiosk),
|
|
5082
|
+
tx.object(receiverKioskCap),
|
|
5083
|
+
tx.pure.address(recipientAddressWithPrefix)
|
|
5084
|
+
]
|
|
5085
|
+
});
|
|
5086
|
+
const totalRoyaltyAmount = nfts.reduce(
|
|
5087
|
+
(sum, nft) => sum + BigInt(
|
|
5088
|
+
getTransferPolicyForDirectTransfer(nft.collection.chain_state)?.rules?.find(
|
|
5089
|
+
(rule) => rule.type === "royalty_rule"
|
|
5090
|
+
)?.min_amount ?? 0n
|
|
5091
|
+
),
|
|
5092
|
+
0n
|
|
5093
|
+
);
|
|
5094
|
+
const [royaltyCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(totalRoyaltyAmount)]);
|
|
5095
|
+
for (const nft of nfts) {
|
|
5096
|
+
const nftType = getNftType({
|
|
5097
|
+
collectionId: nft?.collection?.id,
|
|
5098
|
+
collectionChainState: nft?.collection?.chain_state,
|
|
5099
|
+
nft
|
|
5100
|
+
});
|
|
5101
|
+
await kioskTxWrapper({
|
|
5102
|
+
tx,
|
|
5103
|
+
kioskClient,
|
|
5104
|
+
kioskOwner: senderAddress,
|
|
5105
|
+
kiosk: nft?.chain_state?.kiosk_id,
|
|
5106
|
+
async runCommands(kioskTx) {
|
|
5107
|
+
tx.moveCall({
|
|
5108
|
+
target: "0xd0ad5bf7ac7d372cdcfee5273d5e487dabad724040e089c626cba2a01127ccd6::kiosk_transfers::direct_transfer",
|
|
5109
|
+
arguments: [
|
|
5110
|
+
tx.object(kioskTx.getKiosk()),
|
|
5111
|
+
tx.object(kioskTx.getKioskCap()),
|
|
5112
|
+
tx.object(receiverKiosk),
|
|
5113
|
+
tx.object(receiverKioskCap),
|
|
5114
|
+
tx.pure.id(nft.token_id),
|
|
5115
|
+
tx.object(getTransferPolicyForDirectTransfer(nft.collection.chain_state).id),
|
|
5116
|
+
royaltyCoin
|
|
5117
|
+
],
|
|
5118
|
+
typeArguments: [nftType]
|
|
5119
|
+
});
|
|
5120
|
+
}
|
|
5121
|
+
});
|
|
5122
|
+
}
|
|
5123
|
+
tx.transferObjects([receiverKioskCap], tx.pure.address(recipientAddressWithPrefix));
|
|
5124
|
+
tx.moveCall({
|
|
5125
|
+
target: "0x2::transfer::public_share_object",
|
|
5126
|
+
arguments: [receiverKiosk],
|
|
5127
|
+
typeArguments: ["0x2::kiosk::Kiosk"]
|
|
5128
|
+
});
|
|
5129
|
+
destroyZeroCoin({ tx, coin: royaltyCoin });
|
|
5130
|
+
}
|
|
5131
|
+
function canBeTransferedDirectly(collectionChainState) {
|
|
5132
|
+
return getTransferPolicyForDirectTransfer(collectionChainState) !== void 0;
|
|
5133
|
+
}
|
|
5134
|
+
function getTransferPolicyForDirectTransfer(collectionChainState) {
|
|
5135
|
+
return collectionChainState?.transfer_policies?.find(
|
|
5136
|
+
(policy) => !policy.is_origin_byte && policy.rules?.filter(
|
|
5137
|
+
(rule) => rule.type !== "kiosk_lock_rule" && rule.type !== "royalty_rule"
|
|
5138
|
+
).length === 0
|
|
5139
|
+
);
|
|
5140
|
+
}
|
|
5068
5141
|
|
|
5069
5142
|
// src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
|
|
5070
5143
|
async function migrateNftsFromUnsharedToSharedKiosks({ walletAddress }, context) {
|
|
@@ -5957,44 +6030,6 @@ var removeNftBids = async ({ bidIds }, context) => {
|
|
|
5957
6030
|
// src/methods/transferNfts/transferNfts.ts
|
|
5958
6031
|
import { Transaction as Transaction21 } from "@mysten/sui/transactions";
|
|
5959
6032
|
|
|
5960
|
-
// src/graphql/queries/fetchCryptoToUsdRate.ts
|
|
5961
|
-
import { gql as gql20 } from "graphql-request";
|
|
5962
|
-
var fetchCryptoToUsdRate = gql20`
|
|
5963
|
-
query fetchCryptoToUsdRate($crypto: String!) {
|
|
5964
|
-
crypto_rates(where: { crypto: { _eq: $crypto }, fiat: { _eq: "USD" } }) {
|
|
5965
|
-
crypto
|
|
5966
|
-
fiat
|
|
5967
|
-
id
|
|
5968
|
-
rate
|
|
5969
|
-
timestamp
|
|
5970
|
-
}
|
|
5971
|
-
}
|
|
5972
|
-
`;
|
|
5973
|
-
|
|
5974
|
-
// src/helpers/getSuiToUsdRate.ts
|
|
5975
|
-
var getSuiToUsdRate = async () => {
|
|
5976
|
-
try {
|
|
5977
|
-
const res = await gqlChainRequest({
|
|
5978
|
-
chain: "sui",
|
|
5979
|
-
query: fetchCryptoToUsdRate,
|
|
5980
|
-
variables: { crypto: "sui" }
|
|
5981
|
-
});
|
|
5982
|
-
return res?.crypto_rates?.[0]?.rate;
|
|
5983
|
-
} catch (e) {
|
|
5984
|
-
}
|
|
5985
|
-
};
|
|
5986
|
-
|
|
5987
|
-
// src/helpers/addOneDollarFee.ts
|
|
5988
|
-
var addOneDollarFee = async (tx) => {
|
|
5989
|
-
const rate = await getSuiToUsdRate();
|
|
5990
|
-
const companyFee = BigInt(Math.ceil(1e9 / rate));
|
|
5991
|
-
const [microTxFee] = tx.splitCoins(tx.gas, [tx.pure.u64(Number(companyFee))]);
|
|
5992
|
-
tx.transferObjects(
|
|
5993
|
-
[tx.object(microTxFee)],
|
|
5994
|
-
tx.pure.address(addLeadingZerosAfter0x(TRADEPORT_BENEFICIARY_ADDRESS))
|
|
5995
|
-
);
|
|
5996
|
-
};
|
|
5997
|
-
|
|
5998
6033
|
// src/helpers/rpc/getAcountBalance.ts
|
|
5999
6034
|
var getAccountBalance = async ({ suiClient, owner }) => {
|
|
6000
6035
|
try {
|
|
@@ -6028,6 +6063,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6028
6063
|
throw new Error("No nfts found");
|
|
6029
6064
|
}
|
|
6030
6065
|
const nftsForTracking = [];
|
|
6066
|
+
const nftsToTransferDirectly = [];
|
|
6031
6067
|
const tx = new Transaction21();
|
|
6032
6068
|
for (const nft of res.nfts) {
|
|
6033
6069
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
|
|
@@ -6064,25 +6100,30 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6064
6100
|
await addOriginByteTransferNftTx(txData);
|
|
6065
6101
|
continue;
|
|
6066
6102
|
}
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6103
|
+
if (canBeTransferedDirectly(nft?.collection?.chain_state)) {
|
|
6104
|
+
nftsToTransferDirectly.push(nft);
|
|
6105
|
+
} else {
|
|
6106
|
+
await kioskTxWrapper({
|
|
6107
|
+
tx: txData?.tx,
|
|
6108
|
+
kioskClient: txData?.kioskClient,
|
|
6109
|
+
kioskOwner: txData?.senderAddress,
|
|
6110
|
+
kiosk: txData?.senderKiosk,
|
|
6111
|
+
shouldAssertNftInSharedKiosk: true,
|
|
6112
|
+
async runCommands(kioskTx) {
|
|
6113
|
+
await addTradeportKioskTransferTx({ ...txData, kioskTx });
|
|
6114
|
+
}
|
|
6115
|
+
});
|
|
6116
|
+
}
|
|
6077
6117
|
nftsForTracking.push({
|
|
6078
6118
|
nftType,
|
|
6079
6119
|
senderAddress: walletAddress,
|
|
6080
6120
|
recipientAddress
|
|
6081
6121
|
});
|
|
6082
6122
|
}
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6123
|
+
await addTradeportKioskDirectTransferTx(
|
|
6124
|
+
{ tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
|
|
6125
|
+
nftsToTransferDirectly
|
|
6126
|
+
);
|
|
6086
6127
|
return Transaction21.from(tx);
|
|
6087
6128
|
};
|
|
6088
6129
|
|