@tradeport/sui-trading-sdk 0.1.11 → 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 +12 -0
- package/dist/index.js +62 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +62 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/helpers/getLockById.ts +2 -2
- package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +3 -2
- package/src/methods/exerciseLongLocks/exerciseLongLocks.ts +20 -8
- package/src/methods/exerciseShortLocks/exerciseShortLocks.ts +61 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @tradeport/sui-trading-sdk
|
|
2
2
|
|
|
3
|
+
## 0.1.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7157dff: Fixed exerciseShortLocks
|
|
8
|
+
|
|
9
|
+
## 0.1.12
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8b610ab: Updated exercising long price locks to accept collection bid
|
|
14
|
+
|
|
3
15
|
## 0.1.11
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -1499,7 +1499,7 @@ function addTocenAcceptCollectionBidTxHandler(txData) {
|
|
|
1499
1499
|
|
|
1500
1500
|
// src/methods/acceptCollectionBid/acceptCollectionBid.ts
|
|
1501
1501
|
var ERROR_UNLIST_FIRST = "Item must be unlisted first before you can accept a collection bid with it";
|
|
1502
|
-
var acceptCollectionBid = async ({ bid, nftId, walletAddress }, context) => {
|
|
1502
|
+
var acceptCollectionBid = async ({ bid, nftId, walletAddress, tx: existingTx }, context) => {
|
|
1503
1503
|
const nftRes = await gqlChainRequest({
|
|
1504
1504
|
chain: "sui",
|
|
1505
1505
|
query: fetchNftById,
|
|
@@ -1510,7 +1510,7 @@ var acceptCollectionBid = async ({ bid, nftId, walletAddress }, context) => {
|
|
|
1510
1510
|
throw new Error("No nft found");
|
|
1511
1511
|
}
|
|
1512
1512
|
const bidsForTracking = [];
|
|
1513
|
-
const tx = new import_transactions.Transaction();
|
|
1513
|
+
const tx = existingTx ?? new import_transactions.Transaction();
|
|
1514
1514
|
const sharedObjects = await getSharedObjects(
|
|
1515
1515
|
nft?.properties?.nft_type || nft?.contract?.properties?.nft_type
|
|
1516
1516
|
);
|
|
@@ -1827,11 +1827,9 @@ 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" && bid2.type === "solo"
|
|
1832
|
-
);
|
|
1830
|
+
bid = res.bids.find((bid2) => bid2.status === "active");
|
|
1833
1831
|
if (!bid) {
|
|
1834
|
-
throw new Error(`Active
|
|
1832
|
+
throw new Error(`Active bid ${bidId} is missing for ${lock.nft_type}`);
|
|
1835
1833
|
}
|
|
1836
1834
|
}
|
|
1837
1835
|
if (bid) {
|
|
@@ -1841,7 +1839,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1841
1839
|
}
|
|
1842
1840
|
}
|
|
1843
1841
|
if (!lock.chain_state.makerKioskId) {
|
|
1844
|
-
throw new Error("Missing makerKioskId
|
|
1842
|
+
throw new Error("Missing makerKioskId in the lock data");
|
|
1845
1843
|
}
|
|
1846
1844
|
const marketplaceFee = BigInt(
|
|
1847
1845
|
getMarketFeePrice({
|
|
@@ -1876,7 +1874,19 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1876
1874
|
shouldSkipKioskLocking: true
|
|
1877
1875
|
});
|
|
1878
1876
|
if (bid) {
|
|
1879
|
-
|
|
1877
|
+
switch (bid.type) {
|
|
1878
|
+
case "solo": {
|
|
1879
|
+
await acceptNftBids({ bidIds: [bidId], tx, kioskTx }, context);
|
|
1880
|
+
break;
|
|
1881
|
+
}
|
|
1882
|
+
case "collection": {
|
|
1883
|
+
await acceptCollectionBid({ bid, tx, nftId: lock.nft?.id, walletAddress }, context);
|
|
1884
|
+
break;
|
|
1885
|
+
}
|
|
1886
|
+
default: {
|
|
1887
|
+
throw new Error(`Unsupported bid type ${bid.type}`);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1880
1890
|
}
|
|
1881
1891
|
}
|
|
1882
1892
|
});
|
|
@@ -2782,52 +2792,53 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
|
|
|
2782
2792
|
}
|
|
2783
2793
|
const transferPolicyId = transferPolicy?.id;
|
|
2784
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
|
+
}
|
|
2785
2837
|
await kioskTxWrapper({
|
|
2786
2838
|
tx,
|
|
2787
2839
|
kioskOwner: walletAddress,
|
|
2840
|
+
kiosk: nft?.chain_state?.kiosk_id,
|
|
2788
2841
|
async runCommands(kioskTx) {
|
|
2789
|
-
if (lock.nft?.token_id) {
|
|
2790
|
-
throw new Error(`The short lock ${lockId} must not have any nft`);
|
|
2791
|
-
}
|
|
2792
|
-
let requiredCoins = BigInt(lock.maker_price) + calculateRoyaltyFee(transferPolicy.rules, 0n);
|
|
2793
|
-
let listing = null;
|
|
2794
|
-
if (listingId) {
|
|
2795
|
-
const res = await gqlChainRequest({
|
|
2796
|
-
chain: "sui",
|
|
2797
|
-
query: fetchListingsById,
|
|
2798
|
-
variables: { listingIds: [listingId] }
|
|
2799
|
-
});
|
|
2800
|
-
listing = res.listings[0];
|
|
2801
|
-
if (!listing) {
|
|
2802
|
-
throw new Error(`Missing listing ${listingId}`);
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
if (listing) {
|
|
2806
|
-
if (nftId && listing.nft.id !== nftId) {
|
|
2807
|
-
throw new Error(`The listing ${listingId} must be for token ${listing.nft.token_id}`);
|
|
2808
|
-
}
|
|
2809
|
-
if (!nftId) {
|
|
2810
|
-
nftId = listing.nft.id;
|
|
2811
|
-
}
|
|
2812
|
-
if (listing.nonce && isOriginByteTx(sharedObjects) || !listing.nft?.chain_state?.kiosk_id) {
|
|
2813
|
-
throw new Error(`The listing ${listingId} must be for native kiosk`);
|
|
2814
|
-
}
|
|
2815
|
-
requiredCoins += calculateRoyaltyFee(transferPolicy.rules, BigInt(listing.price));
|
|
2816
|
-
}
|
|
2817
|
-
if (!nftId) {
|
|
2818
|
-
throw new Error(`nftId is required for shorts`);
|
|
2819
|
-
}
|
|
2820
|
-
const nft = (await gqlChainRequest({
|
|
2821
|
-
chain: "sui",
|
|
2822
|
-
query: fetchNftById,
|
|
2823
|
-
variables: { nftId }
|
|
2824
|
-
}))?.nfts?.[0];
|
|
2825
|
-
if (!nft) {
|
|
2826
|
-
throw new Error(`No nft ${nftId} found`);
|
|
2827
|
-
}
|
|
2828
|
-
if (!listing && nft.owner !== walletAddress) {
|
|
2829
|
-
throw new Error(`The nft ${nftId} must be owned by ${walletAddress}`);
|
|
2830
|
-
}
|
|
2831
2842
|
const [request] = tx.moveCall({
|
|
2832
2843
|
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::start_confirm_short_lock`,
|
|
2833
2844
|
typeArguments: [lock.nft_type],
|
|
@@ -2870,6 +2881,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
|
|
|
2870
2881
|
nftType: lock.nft_type,
|
|
2871
2882
|
price: "0",
|
|
2872
2883
|
transferRequest,
|
|
2884
|
+
kioskToLockRuleProve: TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK,
|
|
2873
2885
|
shouldSkipKioskLocking: true
|
|
2874
2886
|
});
|
|
2875
2887
|
}
|