@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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @tradeport/sui-trading-sdk
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f04f941: Added bulk remove bids
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - b86b77a: Added kiosk direct transfers
14
+
3
15
  ## 0.2.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -126,12 +126,14 @@ type PlaceNftBids = {
126
126
  walletAddress: string;
127
127
  };
128
128
 
129
- type RemoveCollectionBid = {
130
- bidId: string;
129
+ type RemoveCollectionBids = {
130
+ bidIds: string[];
131
+ tx?: Transaction;
131
132
  };
132
133
 
133
134
  type RemoveNftBids = {
134
135
  bidIds: string[];
136
+ tx?: Transaction;
135
137
  };
136
138
 
137
139
  type TransferNfts = {
@@ -166,11 +168,11 @@ declare class SuiTradingClient {
166
168
  listNfts({ nfts, walletAddress }: ListNfts): Promise<Transaction>;
167
169
  unlistListings({ listingIds, walletAddress }: UnlistListings): Promise<Transaction>;
168
170
  placeNftBids({ nfts, walletAddress }: PlaceNftBids): Promise<Transaction>;
169
- removeNftBids({ bidIds }: RemoveNftBids): Promise<Transaction>;
171
+ removeNftBids({ bidIds, tx }: RemoveNftBids): Promise<Transaction>;
170
172
  acceptNftBids({ bidIds }: AcceptNftBids): Promise<Transaction>;
171
173
  placeCollectionBid({ collectionId, bidAmountInMist, numOfBids, walletAddress, }: PlaceCollectionBid): Promise<Transaction>;
172
174
  acceptCollectionBid({ bidId, nftId, walletAddress }: AcceptCollectionBid): Promise<Transaction>;
173
- removeCollectionBid({ bidId }: RemoveCollectionBid): Promise<Transaction>;
175
+ removeCollectionBids({ bidIds, tx }: RemoveCollectionBids): Promise<Transaction>;
174
176
  transferNfts({ nftIds, recipientAddress, walletAddress }: TransferNfts): Promise<Transaction>;
175
177
  cancelNftTransfers({ nftIds, walletAddress }: CancelNftTransfers): Promise<Transaction>;
176
178
  claimNfts({ nftIds, walletAddress }: ClaimNfts): Promise<Transaction>;
package/dist/index.d.ts CHANGED
@@ -126,12 +126,14 @@ type PlaceNftBids = {
126
126
  walletAddress: string;
127
127
  };
128
128
 
129
- type RemoveCollectionBid = {
130
- bidId: string;
129
+ type RemoveCollectionBids = {
130
+ bidIds: string[];
131
+ tx?: Transaction;
131
132
  };
132
133
 
133
134
  type RemoveNftBids = {
134
135
  bidIds: string[];
136
+ tx?: Transaction;
135
137
  };
136
138
 
137
139
  type TransferNfts = {
@@ -166,11 +168,11 @@ declare class SuiTradingClient {
166
168
  listNfts({ nfts, walletAddress }: ListNfts): Promise<Transaction>;
167
169
  unlistListings({ listingIds, walletAddress }: UnlistListings): Promise<Transaction>;
168
170
  placeNftBids({ nfts, walletAddress }: PlaceNftBids): Promise<Transaction>;
169
- removeNftBids({ bidIds }: RemoveNftBids): Promise<Transaction>;
171
+ removeNftBids({ bidIds, tx }: RemoveNftBids): Promise<Transaction>;
170
172
  acceptNftBids({ bidIds }: AcceptNftBids): Promise<Transaction>;
171
173
  placeCollectionBid({ collectionId, bidAmountInMist, numOfBids, walletAddress, }: PlaceCollectionBid): Promise<Transaction>;
172
174
  acceptCollectionBid({ bidId, nftId, walletAddress }: AcceptCollectionBid): Promise<Transaction>;
173
- removeCollectionBid({ bidId }: RemoveCollectionBid): Promise<Transaction>;
175
+ removeCollectionBids({ bidIds, tx }: RemoveCollectionBids): Promise<Transaction>;
174
176
  transferNfts({ nftIds, recipientAddress, walletAddress }: TransferNfts): Promise<Transaction>;
175
177
  cancelNftTransfers({ nftIds, walletAddress }: CancelNftTransfers): Promise<Transaction>;
176
178
  claimNfts({ nftIds, walletAddress }: ClaimNfts): Promise<Transaction>;
package/dist/index.js CHANGED
@@ -81,9 +81,9 @@ var gqlChainRequest = async ({ chain, query, variables }) => {
81
81
 
82
82
  // src/graphql/queries/fetchCollectionBidById.ts
83
83
  var import_graphql_request3 = require("graphql-request");
84
- var fetchCollectionBidById = import_graphql_request3.gql`
85
- query fetchCollectionBidById($bidId: uuid!) {
86
- bids(where: { id: { _eq: $bidId } }) {
84
+ var fetchCollectionBidsById = import_graphql_request3.gql`
85
+ query fetchCollectionBidsById($bidIds: [uuid!]) {
86
+ bids(where: { id: { _in: $bidIds } }) {
87
87
  nonce
88
88
  price
89
89
  bidder
@@ -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) {
@@ -5710,7 +5783,7 @@ var placeNftBids = async ({ nfts, walletAddress }, context) => {
5710
5783
  return import_transactions18.Transaction.from(tx);
5711
5784
  };
5712
5785
 
5713
- // src/methods/removeCollectionBid/removeCollectionBid.ts
5786
+ // src/methods/removeCollectionBids/removeCollectionBids.ts
5714
5787
  var import_transactions19 = require("@mysten/sui/transactions");
5715
5788
 
5716
5789
  // src/methods/removeNftBids/addRemoveNftBidTxs.ts
@@ -5770,7 +5843,7 @@ async function addTradePortRemoveNftBidTxHandler(txData) {
5770
5843
  addTradeportRemoveNftBidTx(txData);
5771
5844
  }
5772
5845
 
5773
- // src/methods/removeCollectionBid/addRemoveCollectionBidTxs.ts
5846
+ // src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts
5774
5847
  function addTradeportRemoveCollectionBidTx({
5775
5848
  tx,
5776
5849
  nftType,
@@ -5829,7 +5902,8 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
5829
5902
  objectId: txData?.bidNonce
5830
5903
  });
5831
5904
  if (isOriginByteBid(bidType)) {
5832
- addOriginByteRemoveCollectionBidTx(txData);
5905
+ const sharedObjects = await getSharedObjects(txData?.nftType);
5906
+ addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
5833
5907
  return;
5834
5908
  }
5835
5909
  if (isTradePortKioskBid(bidType)) {
@@ -5841,7 +5915,8 @@ async function addTradePortRemoveCollectionBidTxHandler(txData) {
5841
5915
  async function addBluemoveRemoveCollectionBidTxHandler(txData) {
5842
5916
  const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
5843
5917
  if (isOriginByteBid(bidType)) {
5844
- addOriginByteRemoveCollectionBidTx(txData);
5918
+ const sharedObjects = await getSharedObjects(txData?.nftType);
5919
+ addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
5845
5920
  return;
5846
5921
  }
5847
5922
  if (isBluemoveKioskBid(txData?.bidNonce)) {
@@ -5851,21 +5926,22 @@ async function addBluemoveRemoveCollectionBidTxHandler(txData) {
5851
5926
  addBluemoveRemoveCollectionBidTx(txData);
5852
5927
  }
5853
5928
  async function addClutchyRemoveCollectionBidTxHandler(txData) {
5854
- addOriginByteRemoveCollectionBidTx(txData);
5929
+ const sharedObjects = await getSharedObjects(txData?.nftType);
5930
+ addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
5855
5931
  }
5856
5932
 
5857
- // src/methods/removeCollectionBid/removeCollectionBid.ts
5858
- var removeCollectionBid = async ({ bidId }, context) => {
5933
+ // src/methods/removeCollectionBids/removeCollectionBids.ts
5934
+ var removeCollectionBids = async ({ bidIds, tx: existingTx }, context) => {
5859
5935
  const res = await gqlChainRequest({
5860
5936
  chain: "sui",
5861
- query: fetchCollectionBidById,
5862
- variables: { bidId }
5937
+ query: fetchCollectionBidsById,
5938
+ variables: { bidIds }
5863
5939
  });
5864
5940
  if (res?.bids?.length === 0) {
5865
5941
  throw new Error("No bids found");
5866
5942
  }
5867
5943
  const bidsForTracking = [];
5868
- const tx = new import_transactions19.Transaction();
5944
+ const tx = existingTx ?? new import_transactions19.Transaction();
5869
5945
  for (const bid of res.bids) {
5870
5946
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
5871
5947
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -5880,11 +5956,9 @@ var removeCollectionBid = async ({ bidId }, context) => {
5880
5956
  collectionChainState: collectionWithOneNftRes?.collections?.[0]?.chain_state,
5881
5957
  nft: collectionWithOneNftRes?.collections?.[0]?.nfts?.[0]
5882
5958
  });
5883
- const sharedObjects = await getSharedObjects(nftType);
5884
5959
  const txData = {
5885
5960
  tx,
5886
5961
  suiClient: context.suiClient,
5887
- sharedObjects,
5888
5962
  bidNonce: bid?.nonce,
5889
5963
  bidder: bid?.bidder,
5890
5964
  nftType,
@@ -5919,7 +5993,7 @@ var removeCollectionBid = async ({ bidId }, context) => {
5919
5993
 
5920
5994
  // src/methods/removeNftBids/removeNftBids.ts
5921
5995
  var import_transactions20 = require("@mysten/sui/transactions");
5922
- var removeNftBids = async ({ bidIds }, context) => {
5996
+ var removeNftBids = async ({ bidIds, tx: existingTx }, context) => {
5923
5997
  const res = await gqlChainRequest({
5924
5998
  chain: "sui",
5925
5999
  query: fetchBidsById,
@@ -5929,7 +6003,7 @@ var removeNftBids = async ({ bidIds }, context) => {
5929
6003
  throw new Error("No bids found");
5930
6004
  }
5931
6005
  const bidsForTracking = [];
5932
- const tx = new import_transactions20.Transaction();
6006
+ const tx = existingTx ?? new import_transactions20.Transaction();
5933
6007
  for (const bid of res.bids) {
5934
6008
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
5935
6009
  throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
@@ -5939,11 +6013,9 @@ var removeNftBids = async ({ bidIds }, context) => {
5939
6013
  collectionChainState: bid?.collection?.chain_state,
5940
6014
  nft: bid?.nft
5941
6015
  });
5942
- const sharedObjects = await getSharedObjects(nftType);
5943
6016
  const txData = {
5944
6017
  tx,
5945
6018
  suiClient: context.suiClient,
5946
- sharedObjects,
5947
6019
  bidNonce: bid?.nonce,
5948
6020
  nftType,
5949
6021
  nftTokenId: bid?.nft?.token_id,
@@ -6014,6 +6086,7 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6014
6086
  throw new Error("No nfts found");
6015
6087
  }
6016
6088
  const nftsForTracking = [];
6089
+ const nftsToTransferDirectly = [];
6017
6090
  const tx = new import_transactions21.Transaction();
6018
6091
  for (const nft of res.nfts) {
6019
6092
  if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
@@ -6050,22 +6123,30 @@ var transferNfts = async ({ nftIds, recipientAddress, walletAddress }, context)
6050
6123
  await addOriginByteTransferNftTx(txData);
6051
6124
  continue;
6052
6125
  }
6053
- await kioskTxWrapper({
6054
- tx: txData?.tx,
6055
- kioskClient: txData?.kioskClient,
6056
- kioskOwner: txData?.senderAddress,
6057
- kiosk: txData?.senderKiosk,
6058
- shouldAssertNftInSharedKiosk: true,
6059
- async runCommands(kioskTx) {
6060
- await addTradeportKioskTransferTx({ ...txData, kioskTx });
6061
- }
6062
- });
6126
+ if (canBeTransferedDirectly(nft?.collection?.chain_state)) {
6127
+ nftsToTransferDirectly.push(nft);
6128
+ } else {
6129
+ await kioskTxWrapper({
6130
+ tx: txData?.tx,
6131
+ kioskClient: txData?.kioskClient,
6132
+ kioskOwner: txData?.senderAddress,
6133
+ kiosk: txData?.senderKiosk,
6134
+ shouldAssertNftInSharedKiosk: true,
6135
+ async runCommands(kioskTx) {
6136
+ await addTradeportKioskTransferTx({ ...txData, kioskTx });
6137
+ }
6138
+ });
6139
+ }
6063
6140
  nftsForTracking.push({
6064
6141
  nftType,
6065
6142
  senderAddress: walletAddress,
6066
6143
  recipientAddress
6067
6144
  });
6068
6145
  }
6146
+ await addTradeportKioskDirectTransferTx(
6147
+ { tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
6148
+ nftsToTransferDirectly
6149
+ );
6069
6150
  return import_transactions21.Transaction.from(tx);
6070
6151
  };
6071
6152
 
@@ -6268,14 +6349,14 @@ var SuiTradingClient = class {
6268
6349
  };
6269
6350
  return placeNftBids({ nfts, walletAddress }, context);
6270
6351
  }
6271
- async removeNftBids({ bidIds }) {
6352
+ async removeNftBids({ bidIds, tx }) {
6272
6353
  const context = {
6273
6354
  apiUser: this.apiUser,
6274
6355
  apiKey: this.apiKey,
6275
6356
  suiClient: this.suiClient,
6276
6357
  kioskClient: this.kioskClient
6277
6358
  };
6278
- return removeNftBids({ bidIds }, context);
6359
+ return removeNftBids({ bidIds, tx }, context);
6279
6360
  }
6280
6361
  async acceptNftBids({ bidIds }) {
6281
6362
  const context = {
@@ -6321,8 +6402,8 @@ var SuiTradingClient = class {
6321
6402
  };
6322
6403
  const collectionBidRes = await gqlChainRequest({
6323
6404
  chain: "sui",
6324
- query: fetchCollectionBidById,
6325
- variables: { bidId }
6405
+ query: fetchCollectionBidsById,
6406
+ variables: { bidIds: [bidId] }
6326
6407
  });
6327
6408
  const bid = collectionBidRes?.bids?.[0];
6328
6409
  if (!bid) {
@@ -6384,14 +6465,14 @@ var SuiTradingClient = class {
6384
6465
  }
6385
6466
  }
6386
6467
  }
6387
- async removeCollectionBid({ bidId }) {
6468
+ async removeCollectionBids({ bidIds, tx }) {
6388
6469
  const context = {
6389
6470
  apiUser: this.apiUser,
6390
6471
  apiKey: this.apiKey,
6391
6472
  suiClient: this.suiClient,
6392
6473
  kioskClient: this.kioskClient
6393
6474
  };
6394
- return removeCollectionBid({ bidId }, context);
6475
+ return removeCollectionBids({ bidIds, tx }, context);
6395
6476
  }
6396
6477
  async transferNfts({ nftIds, recipientAddress, walletAddress }) {
6397
6478
  const context = {