@tradeport/sui-trading-sdk 0.2.2 → 0.3.1
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.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +116 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +116 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/SuiTradingClient.ts +10 -10
- package/src/graphql/queries/fetchCollectionBidById.ts +3 -3
- package/src/methods/{removeCollectionBid/addRemoveCollectionBidTxs.ts → removeCollectionBids/addRemoveCollectionBidsTxs.ts} +8 -4
- package/src/methods/{removeCollectionBid/removeCollectionBid.ts → removeCollectionBids/removeCollectionBids.ts} +15 -18
- package/src/methods/removeNftBids/removeNftBids.ts +8 -11
- package/src/methods/transferNfts/addTransferNftTx.ts +108 -0
- package/src/methods/transferNfts/transferNfts.ts +28 -11
- package/src/tests/SuiWallet.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -55,9 +55,9 @@ var gqlChainRequest = async ({ chain, query, variables }) => {
|
|
|
55
55
|
|
|
56
56
|
// src/graphql/queries/fetchCollectionBidById.ts
|
|
57
57
|
import { gql as gql2 } from "graphql-request";
|
|
58
|
-
var
|
|
59
|
-
query
|
|
60
|
-
bids(where: { id: {
|
|
58
|
+
var fetchCollectionBidsById = gql2`
|
|
59
|
+
query fetchCollectionBidsById($bidIds: [uuid!]) {
|
|
60
|
+
bids(where: { id: { _in: $bidIds } }) {
|
|
61
61
|
nonce
|
|
62
62
|
price
|
|
63
63
|
bidder
|
|
@@ -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) {
|
|
@@ -5686,7 +5759,7 @@ var placeNftBids = async ({ nfts, walletAddress }, context) => {
|
|
|
5686
5759
|
return Transaction18.from(tx);
|
|
5687
5760
|
};
|
|
5688
5761
|
|
|
5689
|
-
// src/methods/
|
|
5762
|
+
// src/methods/removeCollectionBids/removeCollectionBids.ts
|
|
5690
5763
|
import { Transaction as Transaction19 } from "@mysten/sui/transactions";
|
|
5691
5764
|
|
|
5692
5765
|
// src/methods/removeNftBids/addRemoveNftBidTxs.ts
|
|
@@ -5746,7 +5819,7 @@ async function addTradePortRemoveNftBidTxHandler(txData) {
|
|
|
5746
5819
|
addTradeportRemoveNftBidTx(txData);
|
|
5747
5820
|
}
|
|
5748
5821
|
|
|
5749
|
-
// src/methods/
|
|
5822
|
+
// src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
|
|
5750
5823
|
function addTradeportRemoveCollectionBidTx({
|
|
5751
5824
|
tx,
|
|
5752
5825
|
nftType,
|
|
@@ -5805,7 +5878,8 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
|
|
|
5805
5878
|
objectId: txData?.bidNonce
|
|
5806
5879
|
});
|
|
5807
5880
|
if (isOriginByteBid(bidType)) {
|
|
5808
|
-
|
|
5881
|
+
const sharedObjects = await getSharedObjects(txData?.nftType);
|
|
5882
|
+
addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
|
|
5809
5883
|
return;
|
|
5810
5884
|
}
|
|
5811
5885
|
if (isTradePortKioskBid(bidType)) {
|
|
@@ -5817,7 +5891,8 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
|
|
|
5817
5891
|
async function addBluemoveRemoveCollectionBidTxHandler(txData) {
|
|
5818
5892
|
const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
|
|
5819
5893
|
if (isOriginByteBid(bidType)) {
|
|
5820
|
-
|
|
5894
|
+
const sharedObjects = await getSharedObjects(txData?.nftType);
|
|
5895
|
+
addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
|
|
5821
5896
|
return;
|
|
5822
5897
|
}
|
|
5823
5898
|
if (isBluemoveKioskBid(txData?.bidNonce)) {
|
|
@@ -5827,21 +5902,22 @@ async function addBluemoveRemoveCollectionBidTxHandler(txData) {
|
|
|
5827
5902
|
addBluemoveRemoveCollectionBidTx(txData);
|
|
5828
5903
|
}
|
|
5829
5904
|
async function addClutchyRemoveCollectionBidTxHandler(txData) {
|
|
5830
|
-
|
|
5905
|
+
const sharedObjects = await getSharedObjects(txData?.nftType);
|
|
5906
|
+
addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
|
|
5831
5907
|
}
|
|
5832
5908
|
|
|
5833
|
-
// src/methods/
|
|
5834
|
-
var
|
|
5909
|
+
// src/methods/removeCollectionBids/removeCollectionBids.ts
|
|
5910
|
+
var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
5835
5911
|
const res = await gqlChainRequest({
|
|
5836
5912
|
chain: "sui",
|
|
5837
|
-
query:
|
|
5838
|
-
variables: {
|
|
5913
|
+
query: fetchCollectionBidsById,
|
|
5914
|
+
variables: { bidIds }
|
|
5839
5915
|
});
|
|
5840
5916
|
if (res?.bids?.length === 0) {
|
|
5841
5917
|
throw new Error("No bids found");
|
|
5842
5918
|
}
|
|
5843
5919
|
const bidsForTracking = [];
|
|
5844
|
-
const tx = new Transaction19();
|
|
5920
|
+
const tx = existingTx ?? new Transaction19();
|
|
5845
5921
|
for (const bid of res.bids) {
|
|
5846
5922
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
|
|
5847
5923
|
throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
|
|
@@ -5856,11 +5932,9 @@ var removeCollectionBid = async ({ bidId }, context) => {
|
|
|
5856
5932
|
collectionChainState: collectionWithOneNftRes?.collections?.[0]?.chain_state,
|
|
5857
5933
|
nft: collectionWithOneNftRes?.collections?.[0]?.nfts?.[0]
|
|
5858
5934
|
});
|
|
5859
|
-
const sharedObjects = await getSharedObjects(nftType);
|
|
5860
5935
|
const txData = {
|
|
5861
5936
|
tx,
|
|
5862
5937
|
suiClient: context.suiClient,
|
|
5863
|
-
sharedObjects,
|
|
5864
5938
|
bidNonce: bid?.nonce,
|
|
5865
5939
|
bidder: bid?.bidder,
|
|
5866
5940
|
nftType,
|
|
@@ -5895,7 +5969,7 @@ var removeCollectionBid = async ({ bidId }, context) => {
|
|
|
5895
5969
|
|
|
5896
5970
|
// src/methods/removeNftBids/removeNftBids.ts
|
|
5897
5971
|
import { Transaction as Transaction20 } from "@mysten/sui/transactions";
|
|
5898
|
-
var removeNftBids = async ({ bidIds }, context) => {
|
|
5972
|
+
var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
|
|
5899
5973
|
const res = await gqlChainRequest({
|
|
5900
5974
|
chain: "sui",
|
|
5901
5975
|
query: fetchBidsById,
|
|
@@ -5905,7 +5979,7 @@ var removeNftBids = async ({ bidIds }, context) => {
|
|
|
5905
5979
|
throw new Error("No bids found");
|
|
5906
5980
|
}
|
|
5907
5981
|
const bidsForTracking = [];
|
|
5908
|
-
const tx = new Transaction20();
|
|
5982
|
+
const tx = existingTx ?? new Transaction20();
|
|
5909
5983
|
for (const bid of res.bids) {
|
|
5910
5984
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
|
|
5911
5985
|
throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
|
|
@@ -5915,11 +5989,9 @@ var removeNftBids = async ({ bidIds }, context) => {
|
|
|
5915
5989
|
collectionChainState: bid?.collection?.chain_state,
|
|
5916
5990
|
nft: bid?.nft
|
|
5917
5991
|
});
|
|
5918
|
-
const sharedObjects = await getSharedObjects(nftType);
|
|
5919
5992
|
const txData = {
|
|
5920
5993
|
tx,
|
|
5921
5994
|
suiClient: context.suiClient,
|
|
5922
|
-
sharedObjects,
|
|
5923
5995
|
bidNonce: bid?.nonce,
|
|
5924
5996
|
nftType,
|
|
5925
5997
|
nftTokenId: bid?.nft?.token_id,
|
|
@@ -5990,6 +6062,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
5990
6062
|
throw new Error("No nfts found");
|
|
5991
6063
|
}
|
|
5992
6064
|
const nftsForTracking = [];
|
|
6065
|
+
const nftsToTransferDirectly = [];
|
|
5993
6066
|
const tx = new Transaction21();
|
|
5994
6067
|
for (const nft of res.nfts) {
|
|
5995
6068
|
if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
|
|
@@ -6026,22 +6099,30 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
|
|
|
6026
6099
|
await addOriginByteTransferNftTx(txData);
|
|
6027
6100
|
continue;
|
|
6028
6101
|
}
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6102
|
+
if (canBeTransferedDirectly(nft?.collection?.chain_state)) {
|
|
6103
|
+
nftsToTransferDirectly.push(nft);
|
|
6104
|
+
} else {
|
|
6105
|
+
await kioskTxWrapper({
|
|
6106
|
+
tx: txData?.tx,
|
|
6107
|
+
kioskClient: txData?.kioskClient,
|
|
6108
|
+
kioskOwner: txData?.senderAddress,
|
|
6109
|
+
kiosk: txData?.senderKiosk,
|
|
6110
|
+
shouldAssertNftInSharedKiosk: true,
|
|
6111
|
+
async runCommands(kioskTx) {
|
|
6112
|
+
await addTradeportKioskTransferTx({ ...txData, kioskTx });
|
|
6113
|
+
}
|
|
6114
|
+
});
|
|
6115
|
+
}
|
|
6039
6116
|
nftsForTracking.push({
|
|
6040
6117
|
nftType,
|
|
6041
6118
|
senderAddress: walletAddress,
|
|
6042
6119
|
recipientAddress
|
|
6043
6120
|
});
|
|
6044
6121
|
}
|
|
6122
|
+
await addTradeportKioskDirectTransferTx(
|
|
6123
|
+
{ tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
|
|
6124
|
+
nftsToTransferDirectly
|
|
6125
|
+
);
|
|
6045
6126
|
return Transaction21.from(tx);
|
|
6046
6127
|
};
|
|
6047
6128
|
|
|
@@ -6244,14 +6325,14 @@ var SuiTradingClient = class {
|
|
|
6244
6325
|
};
|
|
6245
6326
|
return placeNftBids({ nfts, walletAddress }, context);
|
|
6246
6327
|
}
|
|
6247
|
-
async removeNftBids({ bidIds }) {
|
|
6328
|
+
async removeNftBids({ bidIds, tx }) {
|
|
6248
6329
|
const context = {
|
|
6249
6330
|
apiUser: this.apiUser,
|
|
6250
6331
|
apiKey: this.apiKey,
|
|
6251
6332
|
suiClient: this.suiClient,
|
|
6252
6333
|
kioskClient: this.kioskClient
|
|
6253
6334
|
};
|
|
6254
|
-
return removeNftBids({ bidIds }, context);
|
|
6335
|
+
return removeNftBids({ bidIds, tx }, context);
|
|
6255
6336
|
}
|
|
6256
6337
|
async acceptNftBids({ bidIds }) {
|
|
6257
6338
|
const context = {
|
|
@@ -6297,8 +6378,8 @@ var SuiTradingClient = class {
|
|
|
6297
6378
|
};
|
|
6298
6379
|
const collectionBidRes = await gqlChainRequest({
|
|
6299
6380
|
chain: "sui",
|
|
6300
|
-
query:
|
|
6301
|
-
variables: { bidId }
|
|
6381
|
+
query: fetchCollectionBidsById,
|
|
6382
|
+
variables: { bidIds: [bidId] }
|
|
6302
6383
|
});
|
|
6303
6384
|
const bid = collectionBidRes?.bids?.[0];
|
|
6304
6385
|
if (!bid) {
|
|
@@ -6360,14 +6441,14 @@ var SuiTradingClient = class {
|
|
|
6360
6441
|
}
|
|
6361
6442
|
}
|
|
6362
6443
|
}
|
|
6363
|
-
async
|
|
6444
|
+
async removeCollectionBids({ bidIds, tx }) {
|
|
6364
6445
|
const context = {
|
|
6365
6446
|
apiUser: this.apiUser,
|
|
6366
6447
|
apiKey: this.apiKey,
|
|
6367
6448
|
suiClient: this.suiClient,
|
|
6368
6449
|
kioskClient: this.kioskClient
|
|
6369
6450
|
};
|
|
6370
|
-
return
|
|
6451
|
+
return removeCollectionBids({ bidIds, tx }, context);
|
|
6371
6452
|
}
|
|
6372
6453
|
async transferNfts({ nftIds, recipientAddress, walletAddress }) {
|
|
6373
6454
|
const context = {
|