@tradeport/sui-trading-sdk 0.1.12 → 0.1.13

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,11 @@
1
1
  # @tradeport/sui-trading-sdk
2
2
 
3
+ ## 0.1.13
4
+
5
+ ### Patch Changes
6
+
7
+ - 7157dff: Fixed exerciseShortLocks
8
+
3
9
  ## 0.1.12
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1827,9 +1827,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
1827
1827
  query: fetchBidsById,
1828
1828
  variables: { bidIds: [bidId] }
1829
1829
  });
1830
- bid = res.bids.find(
1831
- (bid2) => bid2.status === "active"
1832
- );
1830
+ bid = res.bids.find((bid2) => bid2.status === "active");
1833
1831
  if (!bid) {
1834
1832
  throw new Error(`Active bid ${bidId} is missing for ${lock.nft_type}`);
1835
1833
  }
@@ -2794,52 +2792,53 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
2794
2792
  }
2795
2793
  const transferPolicyId = transferPolicy?.id;
2796
2794
  const sharedObjects = await getSharedObjects(lock.nft_type);
2795
+ if (lock.nft?.token_id) {
2796
+ throw new Error(`The short lock ${lockId} must not have any nft`);
2797
+ }
2798
+ let requiredCoins = BigInt(lock.maker_price) + calculateRoyaltyFee(transferPolicy.rules, 0n);
2799
+ let listing = null;
2800
+ if (listingId) {
2801
+ const res = await gqlChainRequest({
2802
+ chain: "sui",
2803
+ query: fetchListingsById,
2804
+ variables: { listingIds: [listingId] }
2805
+ });
2806
+ listing = res.listings[0];
2807
+ if (!listing) {
2808
+ throw new Error(`Missing listing ${listingId}`);
2809
+ }
2810
+ }
2811
+ if (listing) {
2812
+ if (nftId && listing.nft.id !== nftId) {
2813
+ throw new Error(`The listing ${listingId} must be for token ${listing.nft.token_id}`);
2814
+ }
2815
+ if (!nftId) {
2816
+ nftId = listing.nft.id;
2817
+ }
2818
+ if (listing.nonce && isOriginByteTx(sharedObjects) || !listing.nft?.chain_state?.kiosk_id) {
2819
+ throw new Error(`The listing ${listingId} must be for native kiosk`);
2820
+ }
2821
+ requiredCoins += calculateRoyaltyFee(transferPolicy.rules, BigInt(listing.price));
2822
+ }
2823
+ if (!nftId) {
2824
+ throw new Error(`nftId is required for shorts`);
2825
+ }
2826
+ const nft = (await gqlChainRequest({
2827
+ chain: "sui",
2828
+ query: fetchNftById,
2829
+ variables: { nftId }
2830
+ }))?.nfts?.[0];
2831
+ if (!nft) {
2832
+ throw new Error(`No nft ${nftId} found`);
2833
+ }
2834
+ if (!listing && nft.owner !== walletAddress) {
2835
+ throw new Error(`The nft ${nftId} must be owned by ${walletAddress}`);
2836
+ }
2797
2837
  await kioskTxWrapper({
2798
2838
  tx,
2799
2839
  kioskOwner: walletAddress,
2840
+ kiosk: nft?.chain_state?.kiosk_id,
2800
2841
  async runCommands(kioskTx) {
2801
- if (lock.nft?.token_id) {
2802
- throw new Error(`The short lock ${lockId} must not have any nft`);
2803
- }
2804
- let requiredCoins = BigInt(lock.maker_price) + calculateRoyaltyFee(transferPolicy.rules, 0n);
2805
- let listing = null;
2806
- if (listingId) {
2807
- const res = await gqlChainRequest({
2808
- chain: "sui",
2809
- query: fetchListingsById,
2810
- variables: { listingIds: [listingId] }
2811
- });
2812
- listing = res.listings[0];
2813
- if (!listing) {
2814
- throw new Error(`Missing listing ${listingId}`);
2815
- }
2816
- }
2817
- if (listing) {
2818
- if (nftId && listing.nft.id !== nftId) {
2819
- throw new Error(`The listing ${listingId} must be for token ${listing.nft.token_id}`);
2820
- }
2821
- if (!nftId) {
2822
- nftId = listing.nft.id;
2823
- }
2824
- if (listing.nonce && isOriginByteTx(sharedObjects) || !listing.nft?.chain_state?.kiosk_id) {
2825
- throw new Error(`The listing ${listingId} must be for native kiosk`);
2826
- }
2827
- requiredCoins += calculateRoyaltyFee(transferPolicy.rules, BigInt(listing.price));
2828
- }
2829
- if (!nftId) {
2830
- throw new Error(`nftId is required for shorts`);
2831
- }
2832
- const nft = (await gqlChainRequest({
2833
- chain: "sui",
2834
- query: fetchNftById,
2835
- variables: { nftId }
2836
- }))?.nfts?.[0];
2837
- if (!nft) {
2838
- throw new Error(`No nft ${nftId} found`);
2839
- }
2840
- if (!listing && nft.owner !== walletAddress) {
2841
- throw new Error(`The nft ${nftId} must be owned by ${walletAddress}`);
2842
- }
2843
2842
  const [request] = tx.moveCall({
2844
2843
  target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_short_lock`,
2845
2844
  typeArguments: [lock.nft_type],
@@ -2882,6 +2881,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
2882
2881
  nftType: lock.nft_type,
2883
2882
  price: "0",
2884
2883
  transferRequest,
2884
+ kioskToLockRuleProve: TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK,
2885
2885
  shouldSkipKioskLocking: true
2886
2886
  });
2887
2887
  }