@tradeport/sui-trading-sdk 0.1.13 → 0.1.15

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,18 @@
1
1
  # @tradeport/sui-trading-sdk
2
2
 
3
+ ## 0.1.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 89e22b0: Fixed exercising shorts for a profit
8
+ - eadadc1: New kiosk_biddings package
9
+
10
+ ## 0.1.14
11
+
12
+ ### Patch Changes
13
+
14
+ - cd4da4d: Updated to new personal kiosk compatible kiosk_biddings and kiosk_transfers modules
15
+
3
16
  ## 0.1.13
4
17
 
5
18
  ### Patch Changes
package/dist/index.js CHANGED
@@ -874,15 +874,13 @@ async function addTradeportKioskAcceptNftBidTx({
874
874
  }) {
875
875
  const { transferPolicy } = sharedObjects;
876
876
  const [feeCoin, transferRequest] = tx.moveCall({
877
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::accept_bid",
877
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_biddings::accept_bid_with_purchase_cap",
878
878
  arguments: [
879
879
  tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
880
880
  tx.pure.address(bidNonce),
881
- tx.object(TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK),
882
881
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
883
882
  tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
884
- tx.pure.address(nftTokenId),
885
- tx.object(transferPolicy)
883
+ tx.pure.address(nftTokenId)
886
884
  ],
887
885
  typeArguments: [nftType]
888
886
  });
@@ -897,7 +895,6 @@ async function addTradeportKioskAcceptNftBidTx({
897
895
  nftType,
898
896
  price: "0",
899
897
  transferRequest,
900
- kioskToLockRuleProve: TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK,
901
898
  shouldSkipKioskLocking: true,
902
899
  shouldSkipResolvingRoyaltyRule: true
903
900
  });
@@ -1026,7 +1023,7 @@ async function addTradePortKioskUnlistTx({
1026
1023
  nftType
1027
1024
  }) {
1028
1025
  tx.moveCall({
1029
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_listings::unlist",
1026
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_listings::unlist",
1030
1027
  arguments: [
1031
1028
  tx.object(TRADEPORT_KIOSK_LISTING_STORE),
1032
1029
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
@@ -2024,7 +2021,7 @@ var addTradeportKioskBuyTx = async ({
2024
2021
  if (!coin)
2025
2022
  throw new Error("Coin could not be split");
2026
2023
  const [kioskItem, transferRequest, kioskPrice] = tx.moveCall({
2027
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_listings::buy",
2024
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_listings::buy",
2028
2025
  arguments: [
2029
2026
  tx.object(TRADEPORT_KIOSK_LISTING_STORE),
2030
2027
  tx.object(sellerKiosk),
@@ -2542,7 +2539,7 @@ var addClaimAcceptedBidNftTx = async ({
2542
2539
  }) => {
2543
2540
  const { transferPolicy } = sharedObjects;
2544
2541
  const [transferRequest] = tx.moveCall({
2545
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::claim_bid",
2542
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_biddings::claim_bid",
2546
2543
  arguments: [
2547
2544
  tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
2548
2545
  tx.object(TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK),
@@ -2562,6 +2559,36 @@ var addClaimAcceptedBidNftTx = async ({
2562
2559
  shouldSkipKioskLocking: true
2563
2560
  });
2564
2561
  };
2562
+ var addClaimAcceptedBidNftWithPurchaseCapTx = async ({
2563
+ tx,
2564
+ kioskTx,
2565
+ sharedObjects,
2566
+ nftTokenId,
2567
+ nftType,
2568
+ sellerKiosk
2569
+ }) => {
2570
+ const { transferPolicy } = sharedObjects;
2571
+ const [transferRequest] = tx.moveCall({
2572
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_biddings::claim_bid_with_purchase_cap",
2573
+ arguments: [
2574
+ tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
2575
+ tx.object(sellerKiosk),
2576
+ tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
2577
+ tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
2578
+ tx.pure.address(nftTokenId),
2579
+ tx.object(transferPolicy)
2580
+ ],
2581
+ typeArguments: [nftType]
2582
+ });
2583
+ await resolveTransferPolicies({
2584
+ tx,
2585
+ kioskTx,
2586
+ nftType,
2587
+ price: "0",
2588
+ transferRequest,
2589
+ shouldSkipKioskLocking: true
2590
+ });
2591
+ };
2565
2592
  var addClaimTransferredNftTx = async ({
2566
2593
  tx,
2567
2594
  sharedObjects,
@@ -2571,7 +2598,7 @@ var addClaimTransferredNftTx = async ({
2571
2598
  }) => {
2572
2599
  const { transferPolicy } = sharedObjects;
2573
2600
  const [transferRequest] = tx.moveCall({
2574
- target: "0x78eae99d1a7edae714b5de107f4b44ccbdf5f9ca6919498d9b024ef378dc13f7::kiosk_transfers::claim",
2601
+ target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::claim",
2575
2602
  arguments: [
2576
2603
  tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
2577
2604
  tx.object(TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK),
@@ -2591,6 +2618,36 @@ var addClaimTransferredNftTx = async ({
2591
2618
  shouldSkipKioskLocking: true
2592
2619
  });
2593
2620
  };
2621
+ var addClaimTransferredNftWithPurchaseCapTx = async ({
2622
+ tx,
2623
+ sharedObjects,
2624
+ kioskTx,
2625
+ nftTokenId,
2626
+ nftType,
2627
+ sellerKiosk
2628
+ }) => {
2629
+ const { transferPolicy } = sharedObjects;
2630
+ const [transferRequest] = tx.moveCall({
2631
+ target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::claim_with_purchase_cap",
2632
+ arguments: [
2633
+ tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
2634
+ tx.object(sellerKiosk),
2635
+ tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
2636
+ tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
2637
+ tx.pure.address(nftTokenId),
2638
+ tx.object(transferPolicy)
2639
+ ],
2640
+ typeArguments: [nftType]
2641
+ });
2642
+ await resolveTransferPolicies({
2643
+ tx,
2644
+ kioskTx,
2645
+ nftType,
2646
+ price: "0",
2647
+ transferRequest,
2648
+ shouldSkipKioskLocking: true
2649
+ });
2650
+ };
2594
2651
 
2595
2652
  // src/methods/claimNfts/claimNfts.ts
2596
2653
  var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context) => {
@@ -2637,14 +2694,25 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context) => {
2637
2694
  nftTokenId: nft?.token_id,
2638
2695
  sellerKiosk: nft?.chain_state?.kiosk_id
2639
2696
  };
2640
- await kioskTxWrapper({
2641
- tx,
2642
- kioskOwner: txData?.claimer,
2643
- kiosk: txData?.sellerKiosk,
2644
- async runCommands(kioskTx) {
2645
- await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
2646
- }
2647
- });
2697
+ try {
2698
+ await kioskTxWrapper({
2699
+ tx,
2700
+ kioskOwner: txData?.claimer,
2701
+ kiosk: txData?.sellerKiosk,
2702
+ async runCommands(kioskTx) {
2703
+ await addClaimAcceptedBidNftWithPurchaseCapTx({ ...txData, kioskTx });
2704
+ }
2705
+ });
2706
+ } catch {
2707
+ await kioskTxWrapper({
2708
+ tx,
2709
+ kioskOwner: txData?.claimer,
2710
+ kiosk: txData?.sellerKiosk,
2711
+ async runCommands(kioskTx) {
2712
+ await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
2713
+ }
2714
+ });
2715
+ }
2648
2716
  continue;
2649
2717
  }
2650
2718
  if (nft?.chain_state?.claimable_reason === "offer-transfer") {
@@ -2656,14 +2724,25 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context) => {
2656
2724
  nftTokenId: nft?.token_id,
2657
2725
  sellerKiosk: nft?.chain_state?.kiosk_id
2658
2726
  };
2659
- await kioskTxWrapper({
2660
- tx,
2661
- kioskOwner: txData?.claimer,
2662
- kiosk: txData?.sellerKiosk,
2663
- async runCommands(kioskTx) {
2664
- await addClaimTransferredNftTx({ ...txData, kioskTx });
2665
- }
2666
- });
2727
+ try {
2728
+ await kioskTxWrapper({
2729
+ tx,
2730
+ kioskOwner: txData?.claimer,
2731
+ kiosk: txData?.sellerKiosk,
2732
+ async runCommands(kioskTx) {
2733
+ await addClaimTransferredNftWithPurchaseCapTx({ ...txData, kioskTx });
2734
+ }
2735
+ });
2736
+ } catch {
2737
+ await kioskTxWrapper({
2738
+ tx,
2739
+ kioskOwner: txData?.claimer,
2740
+ kiosk: txData?.sellerKiosk,
2741
+ async runCommands(kioskTx) {
2742
+ await addClaimTransferredNftTx({ ...txData, kioskTx });
2743
+ }
2744
+ });
2745
+ }
2667
2746
  }
2668
2747
  nftsForTracking.push({
2669
2748
  nftType: getNftTypeFromNft(nft),
@@ -2781,7 +2860,7 @@ var import_utils3 = require("@mysten/sui.js/utils");
2781
2860
  var import_transactions11 = require("@mysten/sui/transactions");
2782
2861
  async function exerciseShortLocks({ walletAddress, transaction, locks }, context) {
2783
2862
  const tx = transaction ?? new import_transactions11.Transaction();
2784
- for (let { id: lockId, listingId, nftId } of locks) {
2863
+ for (const { id: lockId, listingId, nftId: nftIdArg } of locks) {
2785
2864
  const lock = await getLockById(lockId);
2786
2865
  if (!transaction && lock.state !== "locked") {
2787
2866
  throw new Error("Lock must be in locked state");
@@ -2795,7 +2874,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
2795
2874
  if (lock.nft?.token_id) {
2796
2875
  throw new Error(`The short lock ${lockId} must not have any nft`);
2797
2876
  }
2798
- let requiredCoins = BigInt(lock.maker_price) + calculateRoyaltyFee(transferPolicy.rules, 0n);
2877
+ const requiredCoins = BigInt(lock.maker_price) + calculateRoyaltyFee(transferPolicy.rules, 0n);
2799
2878
  let listing = null;
2800
2879
  if (listingId) {
2801
2880
  const res = await gqlChainRequest({
@@ -2808,17 +2887,17 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
2808
2887
  throw new Error(`Missing listing ${listingId}`);
2809
2888
  }
2810
2889
  }
2890
+ let nftId = nftIdArg;
2811
2891
  if (listing) {
2812
- if (nftId && listing.nft.id !== nftId) {
2892
+ if (nftIdArg && listing.nft.id !== nftIdArg) {
2813
2893
  throw new Error(`The listing ${listingId} must be for token ${listing.nft.token_id}`);
2814
2894
  }
2815
- if (!nftId) {
2895
+ if (!nftIdArg) {
2816
2896
  nftId = listing.nft.id;
2817
2897
  }
2818
2898
  if (listing.nonce && isOriginByteTx(sharedObjects) || !listing.nft?.chain_state?.kiosk_id) {
2819
2899
  throw new Error(`The listing ${listingId} must be for native kiosk`);
2820
2900
  }
2821
- requiredCoins += calculateRoyaltyFee(transferPolicy.rules, BigInt(listing.price));
2822
2901
  }
2823
2902
  if (!nftId) {
2824
2903
  throw new Error(`nftId is required for shorts`);
@@ -2837,7 +2916,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
2837
2916
  await kioskTxWrapper({
2838
2917
  tx,
2839
2918
  kioskOwner: walletAddress,
2840
- kiosk: nft?.chain_state?.kiosk_id,
2919
+ kiosk: nftIdArg ? nft?.chain_state?.kiosk_id : null,
2841
2920
  async runCommands(kioskTx) {
2842
2921
  const [request] = tx.moveCall({
2843
2922
  target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_short_lock`,
@@ -2966,7 +3045,7 @@ async function addTradePortKioskListTx({
2966
3045
  }) {
2967
3046
  const marketFeePrice = getMarketFeePrice({ price: listPrice, collectionId });
2968
3047
  tx.moveCall({
2969
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_listings::list",
3048
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_listings::list",
2970
3049
  arguments: [
2971
3050
  tx.object(TRADEPORT_KIOSK_LISTING_STORE),
2972
3051
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
@@ -3309,7 +3388,7 @@ function addTradePortKioskCollectionBidTx({
3309
3388
  coin = coin1;
3310
3389
  }
3311
3390
  tx.moveCall({
3312
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::collection_bid",
3391
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_biddings::collection_bid",
3313
3392
  arguments: [
3314
3393
  tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
3315
3394
  tx.pure.u64(bidAmount),
@@ -3464,18 +3543,20 @@ function addTradePortKioskPlaceNftBidTx({
3464
3543
  }) {
3465
3544
  const { transferPolicy } = sharedObjects;
3466
3545
  const marketFeePrice = getMarketFeePrice({ price: bidAmount, collectionId });
3546
+ console.log("transferPolicy", transferPolicy);
3467
3547
  const royaltyCoin = tx.moveCall({
3468
3548
  target: `${royaltyRulePackageId}::${royaltyRuleModule}::fee_amount`,
3469
3549
  arguments: [tx.object(transferPolicy), tx.pure.u64(bidAmount?.toString())],
3470
3550
  typeArguments: [nftType]
3471
3551
  });
3552
+ console.log("royaltyCoin", royaltyCoin);
3472
3553
  const [coin1, coin2] = splitCoins({
3473
3554
  tx,
3474
3555
  amounts: [tx.pure.u64(bidAmount + marketFeePrice), tx.object(royaltyCoin)]
3475
3556
  });
3476
3557
  tx.mergeCoins(tx.object(coin1), [tx.object(coin2)]);
3477
3558
  tx.moveCall({
3478
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::bid",
3559
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_biddings::bid",
3479
3560
  arguments: [
3480
3561
  tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
3481
3562
  tx.pure.address(nftTokenId),
@@ -3580,7 +3661,7 @@ function addTradeportRemoveNftBidTx({ tx, bidNonce, nftType }) {
3580
3661
  }
3581
3662
  function addTradeportKioskRemoveNftBidTx({ tx, bidNonce, nftType }) {
3582
3663
  tx.moveCall({
3583
- target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::cancel_bid",
3664
+ target: "0xf527efa4c02d079f15389fb596b04688cd5767948d953942e494ff455f11aa7b::kiosk_biddings::cancel_bid",
3584
3665
  arguments: [tx.object(TRADEPORT_KIOSK_BIDDING_STORE), tx.pure.address(bidNonce)],
3585
3666
  typeArguments: [nftType]
3586
3667
  });
@@ -3938,35 +4019,22 @@ async function addOriginByteTransferNftTx({
3938
4019
  }
3939
4020
  async function addTradeportKioskTransferTx({
3940
4021
  tx,
3941
- sharedObjects,
3942
4022
  kioskTx,
3943
4023
  nftTokenId,
3944
4024
  nftType,
3945
4025
  recipientAddress
3946
4026
  }) {
3947
- const { transferPolicy } = sharedObjects;
3948
- const [transferRequest] = tx.moveCall({
3949
- target: "0x78eae99d1a7edae714b5de107f4b44ccbdf5f9ca6919498d9b024ef378dc13f7::kiosk_transfers::transfer",
4027
+ tx.moveCall({
4028
+ target: "0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::transfer_with_purchase_capability",
3950
4029
  arguments: [
3951
4030
  tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
3952
- tx.object(TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK),
3953
4031
  tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
3954
4032
  tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
3955
4033
  tx.pure.address(nftTokenId),
3956
- tx.pure.address(addLeadingZerosAfter0x(recipientAddress)),
3957
- tx.object(transferPolicy)
4034
+ tx.pure.address(addLeadingZerosAfter0x(recipientAddress))
3958
4035
  ],
3959
4036
  typeArguments: [nftType]
3960
4037
  });
3961
- await resolveTransferPolicies({
3962
- tx,
3963
- kioskTx,
3964
- nftType,
3965
- price: "0",
3966
- transferRequest,
3967
- kioskToLockRuleProve: TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK,
3968
- shouldSkipKioskLocking: true
3969
- });
3970
4038
  }
3971
4039
 
3972
4040
  // src/methods/transferNfts/transferNfts.ts