@tradeport/sui-trading-sdk 0.1.16 → 0.1.17
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 +6 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +58 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +2 -2
- package/src/graphql/queries/fetchActiveLockStateByNftId.ts +10 -0
- package/src/helpers/getActiveLockStateByNftId.ts +15 -0
- package/src/methods/cancelLocks/cancelLocks.ts +12 -4
- package/src/methods/createLongLocks/createLongLocks.ts +11 -0
- package/src/methods/exerciseLongLocks/exerciseLongLocks.ts +3 -3
- package/src/methods/exerciseShortLocks/exerciseShortLocks.ts +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -200,8 +200,8 @@ var TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK = "0xa677dab85a93bd8d6845b6cc7914f3bb
|
|
|
200
200
|
var TRADEPORT_KIOSK_BIDDING_STORE = "0x1e5e7f38e3a61d1d189506d0fc6b7e47e935a292d9e1b23c0f3f1c0f94227772";
|
|
201
201
|
var TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK = "0x151fbe627d3f8de855f424c879ea2176d89282185a4b9226a7157172dd2919cc";
|
|
202
202
|
var TRADEPORT_KIOSK_BID_NONCE_TYPE = "0xec175e537be9e48f75fa6929291de6454d2502f1091feb22c0d26a22821bbf28::kiosk_biddings::Bid";
|
|
203
|
-
var TRADEPORT_PRICE_LOCK_PACKAGE = "
|
|
204
|
-
var TRADEPORT_PRICE_LOCK_STORE = "
|
|
203
|
+
var TRADEPORT_PRICE_LOCK_PACKAGE = "0x5a3fd22413e0340f27353cb2f1b693f1ec83587e979fd07a099ec9793aabbf14";
|
|
204
|
+
var TRADEPORT_PRICE_LOCK_STORE = "0x56fa8d9303151c699c02931dc911c1974674355c5901d6ebf21ba18ee491586a";
|
|
205
205
|
var COLLECTION_IDS_WITH_ZERO_COMMISSION = [
|
|
206
206
|
""
|
|
207
207
|
];
|
|
@@ -1801,8 +1801,8 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1801
1801
|
const tx = transaction ?? new import_transactions4.Transaction();
|
|
1802
1802
|
for (const { id: lockId, bidId } of locks) {
|
|
1803
1803
|
const lock = await getLockById(lockId);
|
|
1804
|
-
if (!transaction && lock.state !== "
|
|
1805
|
-
throw new Error("Lock must be in
|
|
1804
|
+
if (!transaction && lock.state !== "bought") {
|
|
1805
|
+
throw new Error("Lock must be in bought state");
|
|
1806
1806
|
}
|
|
1807
1807
|
const transferPolicy = (await getKioskTransferPolicies(lock.nft_type))?.at(0);
|
|
1808
1808
|
if (!transferPolicy) {
|
|
@@ -1815,7 +1815,7 @@ async function exerciseLongLocks({ walletAddress, transaction, locks }, context)
|
|
|
1815
1815
|
kioskOwner: walletAddress,
|
|
1816
1816
|
async runCommands(kioskTx) {
|
|
1817
1817
|
if (!lock.nft?.token_id) {
|
|
1818
|
-
throw new Error(`The long lock ${lockId} must have nft to be
|
|
1818
|
+
throw new Error(`The long lock ${lockId} must have nft to be exercised`);
|
|
1819
1819
|
}
|
|
1820
1820
|
let bid = null;
|
|
1821
1821
|
if (bidId) {
|
|
@@ -2476,25 +2476,32 @@ var buyListings = async ({ listingIds, walletAddress, tx: existingTx, kioskTx },
|
|
|
2476
2476
|
|
|
2477
2477
|
// src/methods/cancelLocks/cancelLocks.ts
|
|
2478
2478
|
var import_transactions7 = require("@mysten/sui/transactions");
|
|
2479
|
-
|
|
2480
|
-
|
|
2479
|
+
var import_utils3 = require("@mysten/sui.js/utils");
|
|
2480
|
+
async function cancelLocks({
|
|
2481
|
+
lockIds,
|
|
2482
|
+
walletAddress,
|
|
2483
|
+
tx: existingTx
|
|
2484
|
+
}) {
|
|
2485
|
+
const tx = existingTx ?? new import_transactions7.Transaction();
|
|
2481
2486
|
for (const lockId of lockIds) {
|
|
2482
2487
|
const lock = await getLockById(lockId);
|
|
2483
2488
|
if (!lock) {
|
|
2484
2489
|
throw new Error(`Lock ${lockId} is not found`);
|
|
2485
2490
|
}
|
|
2486
|
-
if (!["active", "
|
|
2487
|
-
throw new Error(`Lock ${lockId} is not in state active
|
|
2491
|
+
if (!["active", "expired"].includes(lock.state)) {
|
|
2492
|
+
throw new Error(`Lock ${lockId} is not in state active or expired`);
|
|
2488
2493
|
}
|
|
2489
2494
|
await kioskTxWrapper({
|
|
2490
2495
|
tx,
|
|
2491
2496
|
kioskOwner: walletAddress,
|
|
2497
|
+
kiosk: lock?.chain_state?.makerKioskId,
|
|
2492
2498
|
async runCommands(kioskTx) {
|
|
2493
2499
|
tx.moveCall({
|
|
2494
2500
|
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::cancel_lock`,
|
|
2495
2501
|
typeArguments: [lock.nft_type],
|
|
2496
2502
|
arguments: [
|
|
2497
2503
|
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2504
|
+
tx.object(import_utils3.SUI_CLOCK_OBJECT_ID),
|
|
2498
2505
|
tx.pure.id(lock.lock_id),
|
|
2499
2506
|
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk)
|
|
2500
2507
|
]
|
|
@@ -2755,6 +2762,29 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context, useOl
|
|
|
2755
2762
|
|
|
2756
2763
|
// src/methods/createLongLocks/createLongLocks.ts
|
|
2757
2764
|
var import_transactions9 = require("@mysten/sui/transactions");
|
|
2765
|
+
|
|
2766
|
+
// src/graphql/queries/fetchActiveLockStateByNftId.ts
|
|
2767
|
+
var import_graphql_request16 = require("graphql-request");
|
|
2768
|
+
var fetchActiveLockStateByNftId = import_graphql_request16.gql`
|
|
2769
|
+
query fetchActiveLockStateByNftId($nftId: uuid!) {
|
|
2770
|
+
locks(where: { state: { _nin: ["exercised", "canceled"] }, nft_meta_id: { _eq: $nftId } }) {
|
|
2771
|
+
id
|
|
2772
|
+
state
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
`;
|
|
2776
|
+
|
|
2777
|
+
// src/helpers/getActiveLockStateByNftId.ts
|
|
2778
|
+
var getActiveLockStateByNftId = async (nftId) => {
|
|
2779
|
+
const res = await gqlChainRequest({
|
|
2780
|
+
chain: "sui",
|
|
2781
|
+
query: fetchActiveLockStateByNftId,
|
|
2782
|
+
variables: { nftId }
|
|
2783
|
+
});
|
|
2784
|
+
return res?.locks?.[0] ?? void 0;
|
|
2785
|
+
};
|
|
2786
|
+
|
|
2787
|
+
// src/methods/createLongLocks/createLongLocks.ts
|
|
2758
2788
|
async function createLongLocks({
|
|
2759
2789
|
walletAddress,
|
|
2760
2790
|
nfts
|
|
@@ -2762,6 +2792,13 @@ async function createLongLocks({
|
|
|
2762
2792
|
const expireIn = 7 * 24 * 3600 * 1e3;
|
|
2763
2793
|
const tx = new import_transactions9.Transaction();
|
|
2764
2794
|
for (const argNft of nfts) {
|
|
2795
|
+
const existingLock = await getActiveLockStateByNftId(argNft.id);
|
|
2796
|
+
if (existingLock) {
|
|
2797
|
+
if (existingLock.state === "bought") {
|
|
2798
|
+
throw new Error(`Nft ${argNft.id} is used by the lock ${existingLock.id}`);
|
|
2799
|
+
}
|
|
2800
|
+
await cancelLocks({ lockIds: [existingLock.id], walletAddress, tx });
|
|
2801
|
+
}
|
|
2765
2802
|
const premium = calculatePremium(BigInt(argNft.priceInMist));
|
|
2766
2803
|
const nft = (await gqlChainRequest({
|
|
2767
2804
|
chain: "sui",
|
|
@@ -2856,14 +2893,14 @@ async function createShortLocks({ nfts }) {
|
|
|
2856
2893
|
}
|
|
2857
2894
|
|
|
2858
2895
|
// src/methods/exerciseShortLocks/exerciseShortLocks.ts
|
|
2859
|
-
var
|
|
2896
|
+
var import_utils4 = require("@mysten/sui.js/utils");
|
|
2860
2897
|
var import_transactions11 = require("@mysten/sui/transactions");
|
|
2861
2898
|
async function exerciseShortLocks({ walletAddress, transaction, locks }, context) {
|
|
2862
2899
|
const tx = transaction ?? new import_transactions11.Transaction();
|
|
2863
2900
|
for (const { id: lockId, listingId, nftId: nftIdArg } of locks) {
|
|
2864
2901
|
const lock = await getLockById(lockId);
|
|
2865
|
-
if (!transaction && lock.state !== "
|
|
2866
|
-
throw new Error("Lock must be in
|
|
2902
|
+
if (!transaction && lock.state !== "bought") {
|
|
2903
|
+
throw new Error("Lock must be in bought state");
|
|
2867
2904
|
}
|
|
2868
2905
|
const transferPolicy = (await getKioskTransferPolicies(lock.nft_type))?.at(0);
|
|
2869
2906
|
if (!transferPolicy) {
|
|
@@ -2923,7 +2960,7 @@ async function exerciseShortLocks({ walletAddress, transaction, locks }, context
|
|
|
2923
2960
|
typeArguments: [lock.nft_type],
|
|
2924
2961
|
arguments: [
|
|
2925
2962
|
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2926
|
-
tx.object(
|
|
2963
|
+
tx.object(import_utils4.SUI_CLOCK_OBJECT_ID),
|
|
2927
2964
|
tx.pure.id(lock.lock_id),
|
|
2928
2965
|
tx.pure.u64(requiredCoins)
|
|
2929
2966
|
]
|
|
@@ -3269,8 +3306,8 @@ var listNfts = async ({ nfts, walletAddress }, context) => {
|
|
|
3269
3306
|
var import_transactions13 = require("@mysten/sui/transactions");
|
|
3270
3307
|
|
|
3271
3308
|
// src/graphql/queries/fetchCollectionsById.ts
|
|
3272
|
-
var
|
|
3273
|
-
var fetchCollectionsById =
|
|
3309
|
+
var import_graphql_request17 = require("graphql-request");
|
|
3310
|
+
var fetchCollectionsById = import_graphql_request17.gql`
|
|
3274
3311
|
query fetchCollectionsById($collectionIds: [uuid!]) {
|
|
3275
3312
|
collections(where: { id: { _in: $collectionIds } }) {
|
|
3276
3313
|
id
|
|
@@ -3280,7 +3317,7 @@ var fetchCollectionsById = import_graphql_request16.gql`
|
|
|
3280
3317
|
}
|
|
3281
3318
|
}
|
|
3282
3319
|
`;
|
|
3283
|
-
var fetchCollectionsByIdWithOneNft =
|
|
3320
|
+
var fetchCollectionsByIdWithOneNft = import_graphql_request17.gql`
|
|
3284
3321
|
query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
|
|
3285
3322
|
collections(where: { id: { _in: $collectionIds } }) {
|
|
3286
3323
|
id
|
|
@@ -3297,7 +3334,7 @@ var fetchCollectionsByIdWithOneNft = import_graphql_request16.gql`
|
|
|
3297
3334
|
}
|
|
3298
3335
|
}
|
|
3299
3336
|
`;
|
|
3300
|
-
var fetchCollectionsBySlug =
|
|
3337
|
+
var fetchCollectionsBySlug = import_graphql_request17.gql`
|
|
3301
3338
|
query fetchCollectionsBySlug($slug: String!) {
|
|
3302
3339
|
collections(where: { slug: { _eq: $slug } }) {
|
|
3303
3340
|
id
|
|
@@ -3918,8 +3955,8 @@ var removeNftBids = async ({ bidIds }, context) => {
|
|
|
3918
3955
|
var import_transactions17 = require("@mysten/sui/transactions");
|
|
3919
3956
|
|
|
3920
3957
|
// src/graphql/queries/fetchCryptoToUsdRate.ts
|
|
3921
|
-
var
|
|
3922
|
-
var fetchCryptoToUsdRate =
|
|
3958
|
+
var import_graphql_request18 = require("graphql-request");
|
|
3959
|
+
var fetchCryptoToUsdRate = import_graphql_request18.gql`
|
|
3923
3960
|
query fetchCryptoToUsdRate($crypto: String!) {
|
|
3924
3961
|
crypto_rates(where: { crypto: { _eq: $crypto }, fiat: { _eq: "USD" } }) {
|
|
3925
3962
|
crypto
|
|
@@ -3956,8 +3993,8 @@ var addOneDollarFee = async (tx) => {
|
|
|
3956
3993
|
};
|
|
3957
3994
|
|
|
3958
3995
|
// src/graphql/queries/fetchAccountKiosks.ts
|
|
3959
|
-
var
|
|
3960
|
-
var fetchAccountKiosks2 =
|
|
3996
|
+
var import_graphql_request19 = require("graphql-request");
|
|
3997
|
+
var fetchAccountKiosks2 = import_graphql_request19.gql`
|
|
3961
3998
|
query fetchAccountKiosks($accountAddress: String!) {
|
|
3962
3999
|
kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
|
|
3963
4000
|
id
|