@tradeport/sui-trading-sdk 0.1.9 → 0.1.10
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 +22 -16
- package/dist/index.d.ts +22 -16
- package/dist/index.js +113 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -103
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/SuiTradingClient.ts +7 -7
- package/src/methods/buyAndExerciseLock/buyAndExerciseLock.ts +3 -3
- package/src/methods/buyLocks/buyLocks.ts +41 -0
- package/src/methods/createLocks/createLocks.ts +133 -0
- package/src/methods/buyLock/buyLock.ts +0 -38
- package/src/methods/createLock/createLock.ts +0 -117
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -20,8 +20,8 @@ type BuyListings = {
|
|
|
20
20
|
kioskTx?: KioskTransaction;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
type
|
|
24
|
-
|
|
23
|
+
type BuyLocks = {
|
|
24
|
+
lockIds: string[];
|
|
25
25
|
tx?: Transaction;
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -36,22 +36,28 @@ type ClaimNfts = {
|
|
|
36
36
|
tx?: Transaction;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
interface LongNFT {
|
|
40
|
+
id: string;
|
|
41
|
+
type?: never;
|
|
42
|
+
priceInMist: number;
|
|
43
|
+
collectionId?: string;
|
|
44
|
+
}
|
|
45
|
+
interface ShortNFT {
|
|
46
|
+
id?: never;
|
|
40
47
|
type: string;
|
|
41
|
-
|
|
48
|
+
priceInMist: number;
|
|
42
49
|
collectionId?: string;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
type CreateLongLock = CreateLockCommon & {
|
|
50
|
+
}
|
|
51
|
+
interface CreateLongLocks {
|
|
46
52
|
type: 'long';
|
|
47
|
-
nftId: string;
|
|
48
53
|
walletAddress: string;
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
nfts: LongNFT[];
|
|
55
|
+
}
|
|
56
|
+
interface CreateShortLocks {
|
|
51
57
|
type: 'short';
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
type
|
|
58
|
+
nfts: ShortNFT[];
|
|
59
|
+
}
|
|
60
|
+
type CreateLocks = CreateLongLocks | CreateShortLocks;
|
|
55
61
|
|
|
56
62
|
type ExerciseLock = {
|
|
57
63
|
lockId: string;
|
|
@@ -123,11 +129,11 @@ declare class SuiTradingClient {
|
|
|
123
129
|
removeCollectionBid({ bidId }: RemoveCollectionBid): Promise<Transaction>;
|
|
124
130
|
transferNfts({ nftIds, recipientAddress, walletAddress }: TransferNfts): Promise<Transaction>;
|
|
125
131
|
claimNfts({ nftIds, walletAddress }: ClaimNfts): Promise<Transaction>;
|
|
126
|
-
|
|
132
|
+
createLocks(args: CreateLocks): Promise<Transaction>;
|
|
127
133
|
cancelLock(args: CancelLock): Promise<Transaction>;
|
|
128
|
-
|
|
134
|
+
buyLocks(args: BuyLocks): Promise<Transaction>;
|
|
129
135
|
exerciseLock(args: ExerciseLock): Promise<Transaction>;
|
|
130
|
-
buyAndExerciseLock(args:
|
|
136
|
+
buyAndExerciseLock(args: BuyLocks & ExerciseLock): Promise<Transaction>;
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
export { SuiTradingClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ type BuyListings = {
|
|
|
20
20
|
kioskTx?: KioskTransaction;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
type
|
|
24
|
-
|
|
23
|
+
type BuyLocks = {
|
|
24
|
+
lockIds: string[];
|
|
25
25
|
tx?: Transaction;
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -36,22 +36,28 @@ type ClaimNfts = {
|
|
|
36
36
|
tx?: Transaction;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
interface LongNFT {
|
|
40
|
+
id: string;
|
|
41
|
+
type?: never;
|
|
42
|
+
priceInMist: number;
|
|
43
|
+
collectionId?: string;
|
|
44
|
+
}
|
|
45
|
+
interface ShortNFT {
|
|
46
|
+
id?: never;
|
|
40
47
|
type: string;
|
|
41
|
-
|
|
48
|
+
priceInMist: number;
|
|
42
49
|
collectionId?: string;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
type CreateLongLock = CreateLockCommon & {
|
|
50
|
+
}
|
|
51
|
+
interface CreateLongLocks {
|
|
46
52
|
type: 'long';
|
|
47
|
-
nftId: string;
|
|
48
53
|
walletAddress: string;
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
nfts: LongNFT[];
|
|
55
|
+
}
|
|
56
|
+
interface CreateShortLocks {
|
|
51
57
|
type: 'short';
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
type
|
|
58
|
+
nfts: ShortNFT[];
|
|
59
|
+
}
|
|
60
|
+
type CreateLocks = CreateLongLocks | CreateShortLocks;
|
|
55
61
|
|
|
56
62
|
type ExerciseLock = {
|
|
57
63
|
lockId: string;
|
|
@@ -123,11 +129,11 @@ declare class SuiTradingClient {
|
|
|
123
129
|
removeCollectionBid({ bidId }: RemoveCollectionBid): Promise<Transaction>;
|
|
124
130
|
transferNfts({ nftIds, recipientAddress, walletAddress }: TransferNfts): Promise<Transaction>;
|
|
125
131
|
claimNfts({ nftIds, walletAddress }: ClaimNfts): Promise<Transaction>;
|
|
126
|
-
|
|
132
|
+
createLocks(args: CreateLocks): Promise<Transaction>;
|
|
127
133
|
cancelLock(args: CancelLock): Promise<Transaction>;
|
|
128
|
-
|
|
134
|
+
buyLocks(args: BuyLocks): Promise<Transaction>;
|
|
129
135
|
exerciseLock(args: ExerciseLock): Promise<Transaction>;
|
|
130
|
-
buyAndExerciseLock(args:
|
|
136
|
+
buyAndExerciseLock(args: BuyLocks & ExerciseLock): Promise<Transaction>;
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
export { SuiTradingClient };
|
package/dist/index.js
CHANGED
|
@@ -1672,9 +1672,17 @@ var acceptNftBids = async ({ bidIds, tx: existingTx, kioskTx }, context) => {
|
|
|
1672
1672
|
// src/methods/buyAndExerciseLock/buyAndExerciseLock.ts
|
|
1673
1673
|
var import_transactions6 = require("@mysten/sui/transactions");
|
|
1674
1674
|
|
|
1675
|
-
// src/methods/
|
|
1676
|
-
var import_transactions3 = require("@mysten/sui/transactions");
|
|
1675
|
+
// src/methods/buyLocks/buyLocks.ts
|
|
1677
1676
|
var import_utils = require("@mysten/sui.js/utils");
|
|
1677
|
+
var import_transactions3 = require("@mysten/sui/transactions");
|
|
1678
|
+
|
|
1679
|
+
// src/helpers/calculatePremium.ts
|
|
1680
|
+
function calculatePremium(price) {
|
|
1681
|
+
return BigInt(price) * PREMIUM_NOMINATOR / 10000n;
|
|
1682
|
+
}
|
|
1683
|
+
function calculatePremiumFee(premium) {
|
|
1684
|
+
return BigInt(premium) * PREMIUM_FEE_NOMINATOR / 10000n;
|
|
1685
|
+
}
|
|
1678
1686
|
|
|
1679
1687
|
// src/graphql/queries/fetchLockById.ts
|
|
1680
1688
|
var import_graphql_request13 = require("graphql-request");
|
|
@@ -1709,37 +1717,31 @@ var getLockById = async (lockId) => {
|
|
|
1709
1717
|
return res?.locks?.[0] ?? void 0;
|
|
1710
1718
|
};
|
|
1711
1719
|
|
|
1712
|
-
// src/
|
|
1713
|
-
function
|
|
1714
|
-
return BigInt(price) * PREMIUM_NOMINATOR / 10000n;
|
|
1715
|
-
}
|
|
1716
|
-
function calculatePremiumFee(premium) {
|
|
1717
|
-
return BigInt(premium) * PREMIUM_FEE_NOMINATOR / 10000n;
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
// src/methods/buyLock/buyLock.ts
|
|
1721
|
-
async function buyLock(args) {
|
|
1720
|
+
// src/methods/buyLocks/buyLocks.ts
|
|
1721
|
+
async function buyLocks(args) {
|
|
1722
1722
|
const tx = args.tx ?? new import_transactions3.Transaction();
|
|
1723
|
-
const
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1723
|
+
for (const lockId of args.lockIds) {
|
|
1724
|
+
const lock = await getLockById(lockId);
|
|
1725
|
+
if (!lock) {
|
|
1726
|
+
throw new Error(`Lock ${lockId} is not found`);
|
|
1727
|
+
}
|
|
1728
|
+
if (lock.state !== "active") {
|
|
1729
|
+
throw new Error(`Lock ${lockId} must be in active state`);
|
|
1730
|
+
}
|
|
1731
|
+
const premiumAmount = calculatePremium(lock.maker_price);
|
|
1732
|
+
const premiumFee = calculatePremiumFee(premiumAmount);
|
|
1733
|
+
const [premium] = tx.splitCoins(tx.gas, [premiumAmount + premiumFee]);
|
|
1734
|
+
tx.moveCall({
|
|
1735
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::buy_lock`,
|
|
1736
|
+
typeArguments: [lock.nft_type],
|
|
1737
|
+
arguments: [
|
|
1738
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
1739
|
+
tx.object(import_utils.SUI_CLOCK_OBJECT_ID),
|
|
1740
|
+
tx.pure.id(lock.lock_id),
|
|
1741
|
+
premium
|
|
1742
|
+
]
|
|
1743
|
+
});
|
|
1729
1744
|
}
|
|
1730
|
-
const premiumAmount = calculatePremium(lock.maker_price);
|
|
1731
|
-
const premiumFee = calculatePremiumFee(premiumAmount);
|
|
1732
|
-
const [premium] = tx.splitCoins(tx.gas, [premiumAmount + premiumFee]);
|
|
1733
|
-
tx.moveCall({
|
|
1734
|
-
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::buy_lock`,
|
|
1735
|
-
typeArguments: [lock.nft_type],
|
|
1736
|
-
arguments: [
|
|
1737
|
-
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
1738
|
-
tx.object(import_utils.SUI_CLOCK_OBJECT_ID),
|
|
1739
|
-
tx.pure.id(lock.lock_id),
|
|
1740
|
-
premium
|
|
1741
|
-
]
|
|
1742
|
-
});
|
|
1743
1745
|
return tx;
|
|
1744
1746
|
}
|
|
1745
1747
|
|
|
@@ -2573,7 +2575,7 @@ async function exerciseLock(args, context) {
|
|
|
2573
2575
|
// src/methods/buyAndExerciseLock/buyAndExerciseLock.ts
|
|
2574
2576
|
async function buyAndExerciseLock(args, context) {
|
|
2575
2577
|
const tx = new import_transactions6.Transaction();
|
|
2576
|
-
await
|
|
2578
|
+
await buyLocks({ ...args, tx });
|
|
2577
2579
|
await exerciseLock({ ...args, tx }, context);
|
|
2578
2580
|
return tx;
|
|
2579
2581
|
}
|
|
@@ -2773,79 +2775,87 @@ var claimNfts = async ({ nftIds, walletAddress, tx: existingTx }, context) => {
|
|
|
2773
2775
|
return import_transactions8.Transaction.from(tx);
|
|
2774
2776
|
};
|
|
2775
2777
|
|
|
2776
|
-
// src/methods/
|
|
2778
|
+
// src/methods/createLocks/createLocks.ts
|
|
2777
2779
|
var import_transactions9 = require("@mysten/sui/transactions");
|
|
2778
|
-
async function
|
|
2780
|
+
async function createLocks(args) {
|
|
2779
2781
|
const tx = new import_transactions9.Transaction();
|
|
2780
2782
|
const expireIn = 7 * 24 * 3600 * 1e3;
|
|
2781
|
-
const
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
BigInt(
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2783
|
+
for (const argNft of args.nfts) {
|
|
2784
|
+
const premium = calculatePremium(BigInt(argNft.priceInMist));
|
|
2785
|
+
switch (args.type) {
|
|
2786
|
+
case "long": {
|
|
2787
|
+
const nft = (await gqlChainRequest({
|
|
2788
|
+
chain: "sui",
|
|
2789
|
+
query: fetchNftById,
|
|
2790
|
+
variables: { nftId: argNft.id }
|
|
2791
|
+
}))?.nfts?.[0];
|
|
2792
|
+
const nftType = argNft.type ?? getNftTypeFromNft(nft);
|
|
2793
|
+
await kioskTxWrapper({
|
|
2794
|
+
tx,
|
|
2795
|
+
kioskOwner: args.walletAddress,
|
|
2796
|
+
kiosk: nft?.chain_state?.kiosk_id,
|
|
2797
|
+
async runCommands(kioskTx) {
|
|
2798
|
+
tx.moveCall({
|
|
2799
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::create_long_lock`,
|
|
2800
|
+
typeArguments: [nftType],
|
|
2801
|
+
arguments: [
|
|
2802
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2803
|
+
tx.pure(nft.token_id),
|
|
2804
|
+
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
|
|
2805
|
+
tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
|
|
2806
|
+
tx.pure.u64(BigInt(argNft.priceInMist)),
|
|
2807
|
+
tx.pure.u64(
|
|
2808
|
+
BigInt(
|
|
2809
|
+
getMarketFeePrice({
|
|
2810
|
+
price: Number(argNft.priceInMist),
|
|
2811
|
+
collectionId: argNft.collectionId ?? nft.collection_id
|
|
2812
|
+
})
|
|
2813
|
+
)
|
|
2814
|
+
),
|
|
2815
|
+
tx.pure.u64(premium),
|
|
2816
|
+
tx.pure.u64(expireIn)
|
|
2817
|
+
]
|
|
2818
|
+
});
|
|
2819
|
+
}
|
|
2820
|
+
});
|
|
2821
|
+
break;
|
|
2822
|
+
}
|
|
2823
|
+
case "short": {
|
|
2824
|
+
if (!argNft.type) {
|
|
2825
|
+
throw new Error("Missing nftType");
|
|
2815
2826
|
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2827
|
+
const transferPolicy = (await getKioskTransferPolicies(argNft.type))?.at(0);
|
|
2828
|
+
if (!transferPolicy) {
|
|
2829
|
+
throw new Error(`Missing transfer policy for ${argNft.type}`);
|
|
2830
|
+
}
|
|
2831
|
+
const marketplaceFee = BigInt(
|
|
2832
|
+
getMarketFeePrice({
|
|
2833
|
+
price: Number(argNft.priceInMist),
|
|
2834
|
+
collectionId: argNft.collectionId
|
|
2835
|
+
})
|
|
2836
|
+
);
|
|
2837
|
+
const transferFees = calculateRoyaltyFee(transferPolicy.rules, 0n) + // transfer
|
|
2838
|
+
calculateRoyaltyFee(transferPolicy.rules, BigInt(argNft.priceInMist));
|
|
2839
|
+
const [deposit] = tx.splitCoins(tx.gas, [
|
|
2840
|
+
BigInt(argNft.priceInMist) + marketplaceFee + transferFees
|
|
2841
|
+
]);
|
|
2842
|
+
tx.moveCall({
|
|
2843
|
+
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::create_short_lock`,
|
|
2844
|
+
typeArguments: [argNft.type],
|
|
2845
|
+
arguments: [
|
|
2846
|
+
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2847
|
+
tx.pure.u64(BigInt(argNft.priceInMist)),
|
|
2848
|
+
tx.pure.u64(marketplaceFee),
|
|
2849
|
+
tx.pure.u64(premium),
|
|
2850
|
+
tx.pure.u64(expireIn),
|
|
2851
|
+
deposit
|
|
2852
|
+
]
|
|
2853
|
+
});
|
|
2854
|
+
break;
|
|
2822
2855
|
}
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
throw new Error(`Missing transfer policy for ${args.nftType}`);
|
|
2856
|
+
default: {
|
|
2857
|
+
throw new Error(`Unsupported ${args.type}`);
|
|
2826
2858
|
}
|
|
2827
|
-
const marketplaceFee = BigInt(
|
|
2828
|
-
getMarketFeePrice({ price: Number(args.price), collectionId: args.collectionId })
|
|
2829
|
-
);
|
|
2830
|
-
const transferFees = calculateRoyaltyFee(transferPolicy.rules, 0n) + // transfer
|
|
2831
|
-
calculateRoyaltyFee(transferPolicy.rules, args.price);
|
|
2832
|
-
const [deposit] = tx.splitCoins(tx.gas, [args.price + marketplaceFee + transferFees]);
|
|
2833
|
-
tx.moveCall({
|
|
2834
|
-
target: `${TRADEPORT_PRICE_LOCK_PACKAGE}::tradeport_price_lock::create_short_lock`,
|
|
2835
|
-
typeArguments: [args.nftType],
|
|
2836
|
-
arguments: [
|
|
2837
|
-
tx.object(TRADEPORT_PRICE_LOCK_STORE),
|
|
2838
|
-
tx.pure.u64(args.price),
|
|
2839
|
-
tx.pure.u64(marketplaceFee),
|
|
2840
|
-
tx.pure.u64(premium),
|
|
2841
|
-
tx.pure.u64(expireIn),
|
|
2842
|
-
deposit
|
|
2843
|
-
]
|
|
2844
|
-
});
|
|
2845
|
-
break;
|
|
2846
|
-
}
|
|
2847
|
-
default: {
|
|
2848
|
-
throw new Error(`Unsupported ${args.type}`);
|
|
2849
2859
|
}
|
|
2850
2860
|
}
|
|
2851
2861
|
return tx;
|
|
@@ -4215,14 +4225,14 @@ var SuiTradingClient = class {
|
|
|
4215
4225
|
};
|
|
4216
4226
|
return claimNfts({ nftIds, walletAddress }, context);
|
|
4217
4227
|
}
|
|
4218
|
-
async
|
|
4219
|
-
return
|
|
4228
|
+
async createLocks(args) {
|
|
4229
|
+
return createLocks(args);
|
|
4220
4230
|
}
|
|
4221
4231
|
async cancelLock(args) {
|
|
4222
4232
|
return cancelLock(args);
|
|
4223
4233
|
}
|
|
4224
|
-
async
|
|
4225
|
-
return
|
|
4234
|
+
async buyLocks(args) {
|
|
4235
|
+
return buyLocks(args);
|
|
4226
4236
|
}
|
|
4227
4237
|
async exerciseLock(args) {
|
|
4228
4238
|
const context = {
|