@tradeport/sui-trading-sdk 0.4.39 → 0.4.41
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/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +534 -134
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +518 -125
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
- package/src/SuiTradingClient.ts +15 -0
- package/src/bigNumberConfig.ts +10 -0
- package/src/constants.ts +17 -1
- package/src/graphql/queries/fetchNftCollectionChainState.ts +12 -0
- package/src/helpers/calculateRoyaltyFee.ts +12 -7
- package/src/helpers/isExpiredListing.ts +9 -0
- package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +9 -8
- package/src/helpers/swap.ts +197 -0
- package/src/helpers/validateMinFloorPrice.ts +22 -0
- package/src/methods/buyListings/addBuyListingTxs.ts +111 -5
- package/src/methods/buyLocks/buyLocks.ts +2 -2
- package/src/methods/createLongLocks/createLongLocks.ts +2 -2
- package/src/methods/createShortLocks/createShortLocks.ts +3 -3
- package/src/methods/listNfts/addListTxs.ts +17 -37
- package/src/methods/listNfts/addRelistTxs.ts +26 -17
- package/src/methods/listNfts/listNfts.ts +27 -16
- package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +1 -1
- package/src/methods/relistNft/relistNft.ts +19 -28
- package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +71 -0
- package/src/methods/sponsorNftListing/sponsorNftListing.ts +62 -0
- package/src/methods/unlistListings/addUnlistListingTxs.ts +68 -5
- package/src/methods/unlistListings/unlistListings.ts +2 -6
- package/src/tests/SuiWallet.ts +4 -1
- package/src/utils/printTxBlockTxs.ts +7 -1
- package/src/utils/pureValues.ts +13 -0
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
TOCEN_MARKETPLACE_OBJECT,
|
|
10
10
|
TRADEPORT_KIOSK_LISTING_STORE,
|
|
11
11
|
TRADEPORT_LISTING_STORE,
|
|
12
|
+
TRADEPORT_LISTINGS_PACKAGE,
|
|
13
|
+
TRADEPORT_LISTINGS_STORE,
|
|
12
14
|
} from '../../constants';
|
|
13
15
|
import { getSharedObjects } from '../../helpers/getSharedObjects';
|
|
14
16
|
import { hasNativeKioskTransferPolicyRules } from '../../helpers/hasTransferPolicyRules';
|
|
@@ -20,7 +22,7 @@ import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
|
20
22
|
import { normalizedNftType } from '../../utils/normalizeNftType';
|
|
21
23
|
import { type UnlistListingTx } from './unlistListings';
|
|
22
24
|
|
|
23
|
-
export function
|
|
25
|
+
export function addLegacyTradePortUnlistTx({ tx, listingNonce, nftType }: UnlistListingTx) {
|
|
24
26
|
tx.moveCall({
|
|
25
27
|
target: '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::unlist',
|
|
26
28
|
arguments: [tx.object(TRADEPORT_LISTING_STORE), tx.pure.address(listingNonce)],
|
|
@@ -28,7 +30,7 @@ export function addTradePortUnlistTx({ tx, listingNonce, nftType }: UnlistListin
|
|
|
28
30
|
});
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
export async function
|
|
33
|
+
export async function addLegacyTradePortKioskUnlistTx({
|
|
32
34
|
tx,
|
|
33
35
|
kioskTx,
|
|
34
36
|
nftTokenId,
|
|
@@ -47,6 +49,32 @@ export async function addTradePortKioskUnlistTx({
|
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
export function addTradePortUnlistTx({ tx, nftTokenId, nftType }: UnlistListingTx) {
|
|
53
|
+
tx.moveCall({
|
|
54
|
+
target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::cancel_listing_without_transfer_policy`,
|
|
55
|
+
arguments: [tx.object(TRADEPORT_LISTINGS_STORE), tx.pure.id(nftTokenId)],
|
|
56
|
+
typeArguments: [nftType],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function addKioskTradePortUnlistTx({
|
|
61
|
+
tx,
|
|
62
|
+
kioskTx,
|
|
63
|
+
nftTokenId,
|
|
64
|
+
nftType,
|
|
65
|
+
}: UnlistListingTx) {
|
|
66
|
+
tx.moveCall({
|
|
67
|
+
target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::cancel_listing_with_transfer_policy`,
|
|
68
|
+
arguments: [
|
|
69
|
+
tx.object(TRADEPORT_LISTINGS_STORE),
|
|
70
|
+
tx.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
|
|
71
|
+
tx.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
|
|
72
|
+
tx.pure.id(nftTokenId),
|
|
73
|
+
],
|
|
74
|
+
typeArguments: [nftType],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
50
78
|
export function addOriginByteUnlistTx({
|
|
51
79
|
tx,
|
|
52
80
|
sharedObjects,
|
|
@@ -175,14 +203,47 @@ export async function addTradePortUnlistTxHandler(txData: UnlistListingTx) {
|
|
|
175
203
|
return;
|
|
176
204
|
}
|
|
177
205
|
|
|
206
|
+
// If non kiosk listing (nonce starts with "0::")
|
|
207
|
+
if (txData?.listingNonce?.startsWith('0::')) {
|
|
208
|
+
addTradePortUnlistTx(txData);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// If kiosk listing (nonce starts with "1::")
|
|
213
|
+
if (txData?.listingNonce?.startsWith('1::')) {
|
|
214
|
+
return kioskTxWrapper({
|
|
215
|
+
tx: txData?.tx,
|
|
216
|
+
kioskClient: txData?.kioskClient,
|
|
217
|
+
kioskOwner: txData?.seller,
|
|
218
|
+
kiosk: txData?.sellerKiosk,
|
|
219
|
+
shouldAllowNftUnsharedKiosk: true,
|
|
220
|
+
sharedKioskState: txData?.sharedKioskState,
|
|
221
|
+
shouldUseSharedKioskTx: false,
|
|
222
|
+
async runCommands(kioskTx) {
|
|
223
|
+
await addKioskTradePortUnlistTx({
|
|
224
|
+
...txData,
|
|
225
|
+
kioskTx,
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Fallback to legacy contract logic
|
|
178
232
|
if (
|
|
179
233
|
txData?.listingNonce &&
|
|
180
234
|
(await isNonKioskListing({ suiClient: txData?.suiClient, listingNonce: txData?.listingNonce }))
|
|
181
235
|
) {
|
|
182
|
-
|
|
236
|
+
if (txData?.isPartOfRelist) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
'Cannot relist this non kiosk NFT in one transaction from legacy contract. You must unlist and list again',
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
addLegacyTradePortUnlistTx(txData);
|
|
183
243
|
return;
|
|
184
244
|
}
|
|
185
245
|
|
|
246
|
+
// If legacy kiosk listing
|
|
186
247
|
if (txData?.sellerKiosk) {
|
|
187
248
|
return kioskTxWrapper({
|
|
188
249
|
tx: txData?.tx,
|
|
@@ -193,7 +254,7 @@ export async function addTradePortUnlistTxHandler(txData: UnlistListingTx) {
|
|
|
193
254
|
sharedKioskState: txData?.sharedKioskState,
|
|
194
255
|
shouldUseSharedKioskTx: false,
|
|
195
256
|
async runCommands(kioskTx) {
|
|
196
|
-
await
|
|
257
|
+
await addLegacyTradePortKioskUnlistTx({
|
|
197
258
|
...txData,
|
|
198
259
|
kioskTx,
|
|
199
260
|
});
|
|
@@ -211,6 +272,7 @@ export async function addTradePortUnlistTxHandler(txData: UnlistListingTx) {
|
|
|
211
272
|
kioskOwner: txData?.seller,
|
|
212
273
|
});
|
|
213
274
|
|
|
275
|
+
// Transfer the borrowed item back to the seller
|
|
214
276
|
txData?.tx.transferObjects(
|
|
215
277
|
[txData?.tx.object(borrowedItem)],
|
|
216
278
|
txData?.tx.pure.address(addLeadingZerosAfter0x(txData?.seller)),
|
|
@@ -220,7 +282,8 @@ export async function addTradePortUnlistTxHandler(txData: UnlistListingTx) {
|
|
|
220
282
|
});
|
|
221
283
|
}
|
|
222
284
|
|
|
223
|
-
|
|
285
|
+
// If legacy non kiosk listing
|
|
286
|
+
addLegacyTradePortUnlistTx(txData);
|
|
224
287
|
}
|
|
225
288
|
|
|
226
289
|
export async function addHyperspaceUnlistTxHandler(txData: UnlistListingTx) {
|
|
@@ -37,6 +37,7 @@ export type UnlistListingTx = {
|
|
|
37
37
|
listingNonce: string;
|
|
38
38
|
price: number;
|
|
39
39
|
sellerKiosk: string;
|
|
40
|
+
isPartOfRelist?: boolean;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
export type UnlistListing = {
|
|
@@ -76,12 +77,7 @@ export const unlistListings = async (
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
// Allow the owner to unlist expired listing
|
|
79
|
-
if (
|
|
80
|
-
!listing?.listed &&
|
|
81
|
-
!listing?.nonce /* &&
|
|
82
|
-
listing?.seller &&
|
|
83
|
-
normalizeSuiAddress(listing?.seller) === normalizeSuiAddress(walletAddress) */
|
|
84
|
-
) {
|
|
80
|
+
if (!listing?.listed && !listing?.nonce) {
|
|
85
81
|
throw new Error(`Listing ${listing?.id} is not listed`);
|
|
86
82
|
}
|
|
87
83
|
|
package/src/tests/SuiWallet.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
2
|
+
import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
2
3
|
import { type Transaction } from '@mysten/sui/transactions';
|
|
3
4
|
import createSuiClient from '../apiClients/createSuiClient';
|
|
4
5
|
import { toUint8Array } from '../utils/toUint8Array';
|
|
5
6
|
|
|
6
7
|
export class SuiWallet {
|
|
7
|
-
readonly keypair =
|
|
8
|
+
readonly keypair = process.env.SUI_WALLET_SECRET_KEY.startsWith('suiprivkey')
|
|
9
|
+
? Ed25519Keypair.fromSecretKey(decodeSuiPrivateKey(process.env.SUI_WALLET_SECRET_KEY).secretKey)
|
|
10
|
+
: Ed25519Keypair.fromSecretKey(toUint8Array(process.env.SUI_WALLET_SECRET_KEY));
|
|
8
11
|
|
|
9
12
|
private readonly suiClient: ReturnType<typeof createSuiClient>;
|
|
10
13
|
private balanceAmount = 0n;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { type Transaction } from '@mysten/sui/transactions';
|
|
2
2
|
|
|
3
3
|
export const printTxBlockTxs = async (tx: Transaction) => {
|
|
4
|
-
console.log(
|
|
4
|
+
console.log(
|
|
5
|
+
JSON.stringify(
|
|
6
|
+
tx?.getData(),
|
|
7
|
+
(key, value) => (typeof value === 'bigint' ? value.toString() : value),
|
|
8
|
+
2,
|
|
9
|
+
),
|
|
10
|
+
);
|
|
5
11
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import BigNumber from '../bigNumberConfig';
|
|
2
|
+
|
|
3
|
+
export const toDecimalValue = (value: string | number | BigNumber, decimals: number): BigNumber => {
|
|
4
|
+
if (!value || decimals === undefined) return new BigNumber(0);
|
|
5
|
+
|
|
6
|
+
return new BigNumber(value).div(10 ** decimals);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const toPureValue = (value: string | number | BigNumber, decimals: number): BigNumber => {
|
|
10
|
+
if (!value || decimals === undefined) return new BigNumber(0);
|
|
11
|
+
|
|
12
|
+
return new BigNumber(new BigNumber(value).multipliedBy(10 ** decimals).toFixed(0));
|
|
13
|
+
};
|