@tradeport/sui-trading-sdk 0.5.1 → 0.5.3

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.
Files changed (154) hide show
  1. package/dist/index.js +19 -1
  2. package/dist/index.js.map +1 -1
  3. package/package.json +71 -66
  4. package/.babel.config.js +0 -3
  5. package/.claude/settings.json +0 -5
  6. package/.env.demo +0 -5
  7. package/.eslintrc.json +0 -46
  8. package/.prettierignore +0 -4
  9. package/.prettierrc.json +0 -7
  10. package/.vscode/launch.json +0 -23
  11. package/CHANGELOG.md +0 -746
  12. package/dist/index.d.mts +0 -193
  13. package/dist/index.mjs +0 -7386
  14. package/dist/index.mjs.map +0 -1
  15. package/jest.config.js +0 -12
  16. package/src/SuiTradingClient.ts +0 -442
  17. package/src/apiClients/createKioskClient.ts +0 -10
  18. package/src/apiClients/createSuiClient.ts +0 -5
  19. package/src/apiClients/graphqlClient.ts +0 -17
  20. package/src/bigNumberConfig.ts +0 -10
  21. package/src/constants.ts +0 -1052
  22. package/src/graphql/createChainGQLQuery.ts +0 -27
  23. package/src/graphql/gqlChainRequest.ts +0 -21
  24. package/src/graphql/queries/fetchAccountKiosks.ts +0 -12
  25. package/src/graphql/queries/fetchActiveLockStateByNftId.ts +0 -15
  26. package/src/graphql/queries/fetchBidsById.ts +0 -36
  27. package/src/graphql/queries/fetchCollectionBidById.ts +0 -21
  28. package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +0 -29
  29. package/src/graphql/queries/fetchCollectionChainState.ts +0 -17
  30. package/src/graphql/queries/fetchCollectionFloorListingForMarket.ts +0 -28
  31. package/src/graphql/queries/fetchCollectionFloorListings.ts +0 -15
  32. package/src/graphql/queries/fetchCollectionsById.ts +0 -39
  33. package/src/graphql/queries/fetchCommissionByListingId.ts +0 -13
  34. package/src/graphql/queries/fetchCryptoToUsdRate.ts +0 -13
  35. package/src/graphql/queries/fetchKiosksByOwner.ts +0 -14
  36. package/src/graphql/queries/fetchListingsById.ts +0 -29
  37. package/src/graphql/queries/fetchListingsByNftId.ts +0 -23
  38. package/src/graphql/queries/fetchLockById.ts +0 -23
  39. package/src/graphql/queries/fetchMultibidById.ts +0 -34
  40. package/src/graphql/queries/fetchNftCollectionChainState.ts +0 -12
  41. package/src/graphql/queries/fetchNftsById.ts +0 -75
  42. package/src/graphql/queries/fetchNftsByKioskId.ts +0 -45
  43. package/src/graphql/queries/fetchOwnerCapByKiosk.ts +0 -10
  44. package/src/graphql/queries/fetchPersonalCapByKiosk.ts +0 -10
  45. package/src/graphql/queries/fetchSharedObjectsByType.ts +0 -12
  46. package/src/graphql/queries/fetchTransferPoliciesByType.ts +0 -12
  47. package/src/graphql/queries/fetchWalletKiosks.ts +0 -14
  48. package/src/graphql/queries/getCommissionByListingId.ts +0 -15
  49. package/src/helpers/addOneDollarFee.ts +0 -17
  50. package/src/helpers/addThirdPartyTxFee.ts +0 -17
  51. package/src/helpers/calculatePremium.ts +0 -9
  52. package/src/helpers/calculateRoyaltyFee.ts +0 -28
  53. package/src/helpers/destroyZeroCoin.ts +0 -14
  54. package/src/helpers/getActiveLockStateByNftId.ts +0 -15
  55. package/src/helpers/getCollectionChainState.ts +0 -31
  56. package/src/helpers/getCollectionFloorPrice.ts +0 -12
  57. package/src/helpers/getLockById.ts +0 -29
  58. package/src/helpers/getMarketFeePrice.ts +0 -82
  59. package/src/helpers/getNftType.ts +0 -38
  60. package/src/helpers/getRoyaltyRuleModule.ts +0 -7
  61. package/src/helpers/getSharedObjects.ts +0 -119
  62. package/src/helpers/getSuiToUsdRate.ts +0 -14
  63. package/src/helpers/getTradeportBiddingContractBidAmount.ts +0 -31
  64. package/src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts +0 -24
  65. package/src/helpers/hasPersonalKioskRule.ts +0 -7
  66. package/src/helpers/hasRoyaltyRule.ts +0 -7
  67. package/src/helpers/hasTransferPolicyRules.ts +0 -6
  68. package/src/helpers/isExpiredListing.ts +0 -9
  69. package/src/helpers/isNonKioskListing.ts +0 -14
  70. package/src/helpers/isSIngleBid.ts +0 -13
  71. package/src/helpers/kiosk/assertNftInSharedKiosk.ts +0 -31
  72. package/src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts +0 -71
  73. package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +0 -29
  74. package/src/helpers/kiosk/getKioskPlaceBidCoin.ts +0 -59
  75. package/src/helpers/kiosk/getNativeKioskTransferPolicies.ts +0 -29
  76. package/src/helpers/kiosk/getNativeKioskTransferPoliciesByNftType.ts +0 -21
  77. package/src/helpers/kiosk/getRulePackageId.ts +0 -59
  78. package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +0 -154
  79. package/src/helpers/kiosk/isBluemoveKioskBid.ts +0 -1
  80. package/src/helpers/kiosk/isTradePortKioskBid.ts +0 -4
  81. package/src/helpers/kiosk/kioskListingBcs.ts +0 -19
  82. package/src/helpers/kiosk/kioskTxWrapper.ts +0 -152
  83. package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +0 -100
  84. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +0 -171
  85. package/src/helpers/kiosk/resolveCustomTransferPolicyRules.ts +0 -75
  86. package/src/helpers/kiosk/resolveFloorPriceRule.ts +0 -21
  87. package/src/helpers/kiosk/resolveKioskLockRule.ts +0 -47
  88. package/src/helpers/kiosk/resolvePersonalKioskRule.ts +0 -23
  89. package/src/helpers/kiosk/resolveRoyaltyRule.ts +0 -57
  90. package/src/helpers/kiosk/resolveTableAllowlistRule.ts +0 -34
  91. package/src/helpers/kiosk/resolveTransferPolicies.ts +0 -158
  92. package/src/helpers/kiosk/sharedKioskState.type.ts +0 -11
  93. package/src/helpers/kiosk/takeAndBorrowNftFromKiosk.ts +0 -50
  94. package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +0 -73
  95. package/src/helpers/kiosk/upgradeKioskRulesPackageId.ts +0 -17
  96. package/src/helpers/originByte/confirmOBTranfer.ts +0 -33
  97. package/src/helpers/originByte/createOBKiosk.ts +0 -14
  98. package/src/helpers/originByte/depositNftIntoOBKiosk.ts +0 -16
  99. package/src/helpers/originByte/getOBBidderKiosk.ts +0 -12
  100. package/src/helpers/originByte/getOBKiosk.ts +0 -24
  101. package/src/helpers/originByte/getOrCreateOBKiosk.ts +0 -42
  102. package/src/helpers/originByte/isOBKiosk.ts +0 -13
  103. package/src/helpers/originByte/isOriginByteBid.ts +0 -6
  104. package/src/helpers/originByte/isOriginByteCollection.ts +0 -11
  105. package/src/helpers/originByte/shareOriginByteKiosk.ts +0 -14
  106. package/src/helpers/rpc/getAcountBalance.ts +0 -18
  107. package/src/helpers/rpc/getObjectType.ts +0 -25
  108. package/src/helpers/splitCoins.ts +0 -12
  109. package/src/helpers/track.ts +0 -20
  110. package/src/helpers/validateMinFloorPrice.ts +0 -22
  111. package/src/index.ts +0 -2
  112. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +0 -189
  113. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +0 -398
  114. package/src/methods/acceptNftBids/acceptNftBids.ts +0 -174
  115. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +0 -438
  116. package/src/methods/applyFtStrategy/applyFtStrategy.ts +0 -55
  117. package/src/methods/applyNftStrategy/applyNftStrategy.ts +0 -90
  118. package/src/methods/buyListings/addBuyListingTxs.ts +0 -803
  119. package/src/methods/buyListings/buyListings.ts +0 -230
  120. package/src/methods/cancelMultiBid/cancelMultiBid.ts +0 -51
  121. package/src/methods/cancelNftTransfers/addCancelNftTransfersTx.ts +0 -20
  122. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +0 -118
  123. package/src/methods/claimNfts/addClaimNftsTxs.ts +0 -247
  124. package/src/methods/claimNfts/claimNfts.ts +0 -270
  125. package/src/methods/createMultiBid/createMultiBid.ts +0 -36
  126. package/src/methods/listNfts/addListTxs.ts +0 -210
  127. package/src/methods/listNfts/addRelistTxs.ts +0 -87
  128. package/src/methods/listNfts/listNfts.ts +0 -152
  129. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +0 -226
  130. package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +0 -149
  131. package/src/methods/placeCollectionBids/placeCollectionBids.ts +0 -153
  132. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +0 -154
  133. package/src/methods/placeNftBids/placeNftBids.ts +0 -111
  134. package/src/methods/relistNft/relistNft.ts +0 -153
  135. package/src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts +0 -132
  136. package/src/methods/removeCollectionBids/removeCollectionBids.ts +0 -117
  137. package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +0 -122
  138. package/src/methods/removeNftBids/removeNftBids.ts +0 -116
  139. package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +0 -40
  140. package/src/methods/sponsorNftListing/sponsorNftListing.ts +0 -60
  141. package/src/methods/transferNfts/addTransferNftTx.ts +0 -220
  142. package/src/methods/transferNfts/transferNfts.ts +0 -216
  143. package/src/methods/unlistListings/addUnlistListingTxs.ts +0 -399
  144. package/src/methods/unlistListings/unlistListings.ts +0 -158
  145. package/src/methods/updateMultiBid/updateMultiBid.ts +0 -66
  146. package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +0 -100
  147. package/src/tests/SuiWallet.ts +0 -83
  148. package/src/utils/addHexPrefix.ts +0 -7
  149. package/src/utils/addLeadingZerosAfter0x.ts +0 -9
  150. package/src/utils/normalizeNftType.ts +0 -7
  151. package/src/utils/printTxBlockTxs.ts +0 -11
  152. package/src/utils/pureValues.ts +0 -13
  153. package/src/utils/toUint8Array.ts +0 -12
  154. package/tsconfig.json +0 -16
@@ -1,154 +0,0 @@
1
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
2
- import { fromHex, normalizeSuiObjectId } from '@mysten/sui/utils';
3
- import {
4
- DYNAMIC_COLLECTION_IDS,
5
- ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK,
6
- TRADEPORT_MULTI_BID_PACKAGE,
7
- TRADEPORT_MULTI_BID_STORE,
8
- } from '../../constants';
9
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
10
- import {
11
- fetchMultibidChainIdAndExpiredSingleBidsById,
12
- fetchMultibidChainIdById,
13
- } from '../../graphql/queries/fetchMultibidById';
14
- import { getNativeKioskTransferPolicies } from '../../helpers/kiosk/getNativeKioskTransferPolicies';
15
- import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
16
- import { normalizedNftType } from '../../utils/normalizeNftType';
17
- import { type PlaceNftBidTx } from './placeNftBids';
18
- import { addCancelSingleBidForMultibidChainId } from '../removeNftBids/addRemoveNftBidTxs';
19
- import { type Transaction } from '@mysten/sui/transactions';
20
-
21
- export async function addTradePortPlaceNftBidTxHandler(txData: PlaceNftBidTx) {
22
- if (
23
- isOriginByteCollection(txData?.transferPolicies) &&
24
- !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))
25
- ) {
26
- throw new Error('OriginByte bidding not supported currently');
27
- }
28
-
29
- const {
30
- tx,
31
- nftType,
32
- multiBidId,
33
- multiBidChainId: existingMultiBidChainId,
34
- nftTokenId,
35
- collectionId,
36
- bcsHex,
37
- expireAt,
38
- coinToSplit,
39
- } = txData;
40
- let bcs: Uint8Array | undefined;
41
- if (nftTokenId && isDynamicCollection(collectionId)) {
42
- if (!bcsHex) {
43
- throw new Error(`No BCS found for token ${nftTokenId}`);
44
- }
45
-
46
- bcs = fromHex(bcsHex);
47
- }
48
-
49
- let multiBidChainId;
50
- let expiredBids;
51
- if (existingMultiBidChainId) {
52
- multiBidChainId = existingMultiBidChainId;
53
- } else {
54
- const {
55
- chain_id: chainId,
56
- cancelled_at,
57
- bids,
58
- } = multiBidId
59
- ? ((
60
- await gqlChainRequest({
61
- chain: 'sui',
62
- query: fetchMultibidChainIdAndExpiredSingleBidsById,
63
- variables: { multiBidId, expiredBidLimit: 300 },
64
- })
65
- )?.multi_bids?.[0] ?? {})
66
- : {};
67
-
68
- if (chainId && cancelled_at) {
69
- throw new Error(`MultiBid ${chainId} already cancelled`);
70
- }
71
-
72
- multiBidChainId = chainId;
73
- expiredBids = bids;
74
- }
75
-
76
- const transferPolicies = getNativeKioskTransferPolicies(txData?.transferPolicies);
77
- const transferPolicy = transferPolicies?.find(
78
- (policy: { rules: any[] }) => policy?.rules?.length > 0,
79
- );
80
- const price = BigInt(txData?.bidAmount ?? 0n);
81
- const fee = (BigInt(txData?.bidAmount ?? 0) * (await getBidFeeBps(txData?.suiClient))) / 10_000n;
82
- let royalty = 0n;
83
- const royaltyRule = (transferPolicy?.rules ?? []).find((r: { type: string }) =>
84
- r.type.endsWith('royalty_rule'),
85
- );
86
-
87
- if (royaltyRule) {
88
- const { amount_bp, min_amount } = royaltyRule;
89
- royalty = BigInt((price * BigInt(amount_bp)) / 10_000n);
90
- if (royalty < BigInt(min_amount ?? 0n)) {
91
- royalty = BigInt(min_amount ?? 0n);
92
- }
93
- }
94
-
95
- const txWithState = tx as Transaction & { hasCancelBidTransactions: Map<string, boolean> };
96
- txWithState.hasCancelBidTransactions ??= new Map<string, boolean>();
97
-
98
- if (multiBidChainId && !txWithState.hasCancelBidTransactions.get(multiBidChainId)) {
99
- // Clean up expired bids in existing multibid
100
- for (const { nonce } of expiredBids ?? []) {
101
- addCancelSingleBidForMultibidChainId(tx, nonce, multiBidChainId);
102
- }
103
-
104
- txWithState.hasCancelBidTransactions.set(multiBidChainId, true);
105
- }
106
-
107
- const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [
108
- multiBidChainId ? 0n : price + fee + royalty,
109
- ]);
110
- tx.moveCall({
111
- target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_bid_with${transferPolicy ? '' : 'out'}_transfer_policy`,
112
- typeArguments: [nftType],
113
- arguments: [
114
- tx.object(TRADEPORT_MULTI_BID_STORE),
115
- tx.pure.u64(nftTokenId ? 1 : 0),
116
- multiBidChainId
117
- ? typeof multiBidChainId === 'string'
118
- ? tx.pure.option('id', normalizeSuiObjectId(multiBidChainId))
119
- : tx.moveCall({
120
- target: '0x1::option::some',
121
- typeArguments: ['0x2::object::ID'],
122
- arguments: [multiBidChainId],
123
- })
124
- : undefined,
125
- tx.pure.option('id', nftTokenId ? normalizeSuiObjectId(nftTokenId) : undefined),
126
- tx.pure.option('vector<u8>', bcs ? [...bcs] : undefined),
127
- tx.pure.option('u64', expireAt?.getTime()),
128
- tx.pure.u64(price),
129
- ...(transferPolicy ? [tx.object(transferPolicy.id)] : []),
130
- tx.object(coin),
131
- ],
132
- });
133
- }
134
-
135
- let bidFeeBps: bigint | undefined;
136
-
137
- export async function getBidFeeBps(suiClient: SuiGrpcClient) {
138
- if (bidFeeBps !== undefined) {
139
- return bidFeeBps;
140
- }
141
-
142
- const res = await suiClient.getObject({
143
- objectId: TRADEPORT_MULTI_BID_STORE,
144
- include: { json: true },
145
- });
146
-
147
- bidFeeBps = BigInt((res?.object?.json as unknown as { fee_bps: string })?.fee_bps ?? 0);
148
-
149
- return bidFeeBps;
150
- }
151
-
152
- export function isDynamicCollection(collectionId: string): boolean {
153
- return DYNAMIC_COLLECTION_IDS.includes(collectionId);
154
- }
@@ -1,111 +0,0 @@
1
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
2
- import { Transaction } from '@mysten/sui/transactions';
3
- import { type RequestContext } from '../../SuiTradingClient';
4
- import {
5
- DELOREAN_TOKEN_IDS_TO_DISABLE,
6
- DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
7
- } from '../../constants';
8
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
9
- import { fetchNftsById } from '../../graphql/queries/fetchNftsById';
10
- import { getNftType } from '../../helpers/getNftType';
11
- import { addTradePortPlaceNftBidTxHandler } from './addPlaceNftBidTxs';
12
-
13
- export type PlaceNftBidTx = {
14
- tx: Transaction;
15
- suiClient: SuiGrpcClient;
16
- bidder: string;
17
- collectionId: string;
18
- nftTokenId?: string;
19
- nftType: string;
20
- bidAmount: bigint;
21
- multiBidId?: string;
22
- multiBidChainId?: any;
23
- expireAt?: Date;
24
- sharedObjects?: any;
25
- transferPolicies: any;
26
- bcsHex?: string;
27
- coinToSplit?: any;
28
- };
29
-
30
- export type PlaceNftBids = {
31
- bids: Array<{
32
- nftId: string;
33
- bidAmountInMist: number;
34
- expireAt?: Date;
35
- }>;
36
- walletAddress: string;
37
- multiBidId?: string;
38
- multiBidChainId?: any;
39
- tx?: Transaction;
40
- coinToSplit?: any;
41
- };
42
-
43
- export const placeNftBids = async (
44
- { bids, walletAddress, multiBidId, multiBidChainId, tx: existingTx, coinToSplit }: PlaceNftBids,
45
- context: RequestContext,
46
- ): Promise<Transaction> => {
47
- const tx = existingTx ?? new Transaction();
48
-
49
- const res = await gqlChainRequest({
50
- chain: 'sui',
51
- query: fetchNftsById,
52
- variables: { nftIds: bids.map((bid) => bid.nftId) },
53
- });
54
-
55
- if (res?.nfts?.length === 0) {
56
- throw new Error('No nfts found');
57
- }
58
-
59
- const nftsForTracking = [];
60
- for (const bid of bids) {
61
- const nft = res.nfts?.find((nft: any) => nft.id === bid.nftId);
62
-
63
- if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
64
- throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
65
- }
66
-
67
- const nftType = getNftType({
68
- collectionId: nft?.collection_id,
69
- collectionChainState: nft?.collection?.chain_state,
70
- nft,
71
- });
72
-
73
- const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
74
-
75
- const txData: PlaceNftBidTx = {
76
- tx,
77
- suiClient: context.suiClient,
78
- transferPolicies,
79
- bidder: walletAddress,
80
- collectionId: nft?.collection_id,
81
- nftTokenId: nft?.token_id,
82
- nftType,
83
- bidAmount: BigInt(bid?.bidAmountInMist ?? 0n),
84
- bcsHex: nft.chain_state?.bcs?.bcsHex,
85
- multiBidId,
86
- multiBidChainId,
87
- expireAt: bid?.expireAt,
88
- coinToSplit,
89
- };
90
-
91
- await addTradePortPlaceNftBidTxHandler(txData);
92
-
93
- nftsForTracking.push({
94
- nftType,
95
- collectionId: nft?.collection_id,
96
- bidAmount: bid?.bidAmountInMist,
97
- bidder: walletAddress,
98
- });
99
- }
100
-
101
- // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && nftsForTracking.length > 0) {
102
- // trackMethodCall({
103
- // apiUser: context.apiUser,
104
- // apiKey: context.apiKey,
105
- // event: 'PLACE_NFT_BIDS',
106
- // items: nftsForTracking,
107
- // });
108
- // }
109
-
110
- return tx;
111
- };
@@ -1,153 +0,0 @@
1
- import { type KioskClient } from '@mysten/kiosk';
2
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
3
- import { type Transaction } from '@mysten/sui/transactions';
4
- import { ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK } from '../../constants';
5
- import { getNftType } from '../../helpers/getNftType';
6
- import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
7
- import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
8
- import { normalizedNftType } from '../../utils/normalizeNftType';
9
- import { addTradePortListTxHandler } from '../listNfts/addListTxs';
10
- import {
11
- addBlueMoveRelistTx,
12
- addTocenRelistTx,
13
- addTradePortRelistTx,
14
- addKioskTradePortRelistTx,
15
- } from '../listNfts/addRelistTxs';
16
- import {
17
- addBluemoveUnlistTxHandler,
18
- addClutchyUnlistTxHandler,
19
- addHyperspaceUnlistTxHandler,
20
- addTradePortUnlistTxHandler,
21
- } from '../unlistListings/addUnlistListingTxs';
22
- import { type UnlistListingTx } from '../unlistListings/unlistListings';
23
- import { type SharedKioskState } from '../../helpers/kiosk/sharedKioskState.type';
24
-
25
- interface Args {
26
- tx: Transaction;
27
- suiClient: SuiGrpcClient;
28
- kioskClient: KioskClient;
29
- sharedKioskState: SharedKioskState;
30
- transferPolicies: any;
31
- nft: any;
32
- listPrice: number;
33
- walletAddress: string;
34
- }
35
-
36
- export async function relistNft({
37
- tx,
38
- suiClient,
39
- kioskClient,
40
- sharedKioskState,
41
- nft,
42
- listPrice,
43
- transferPolicies,
44
- walletAddress,
45
- }: Args) {
46
- const firstListedOrExpiredListing = (
47
- nft?.listings as Array<{ listed: boolean; price?: number; nonce?: string; market_name: string }>
48
- ).find((l) => l.listed || l.nonce);
49
- if (!firstListedOrExpiredListing) {
50
- throw new Error('No listing found for NFT');
51
- }
52
-
53
- const txData: UnlistListingTx = {
54
- tx,
55
- suiClient,
56
- kioskClient,
57
- sharedKioskState,
58
- transferPolicies,
59
- nftTokenId: nft?.token_id,
60
- nftType: getNftType({
61
- collectionId: nft?.collection?.id,
62
- collectionChainState: nft?.collection?.chain_state,
63
- nft,
64
- }),
65
- listingNonce: firstListedOrExpiredListing.nonce,
66
- price: firstListedOrExpiredListing.price,
67
- sellerKiosk: nft?.chain_state?.kiosk_id,
68
- collectionId: nft?.collection_id,
69
- seller: walletAddress,
70
- };
71
-
72
- switch (firstListedOrExpiredListing.market_name) {
73
- case 'tradeport':
74
- if (
75
- txData?.listingNonce &&
76
- isOriginByteCollection(txData?.transferPolicies) &&
77
- !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))
78
- ) {
79
- await addTradePortUnlistTxHandler(txData);
80
- await addTradePortListTxHandler({
81
- ...txData,
82
- listPrice,
83
- });
84
- return;
85
- }
86
-
87
- if (txData?.listingNonce?.startsWith('0::')) {
88
- addTradePortRelistTx({ ...txData, listPrice });
89
- return;
90
- }
91
-
92
- if (txData?.listingNonce?.startsWith('1::')) {
93
- return kioskTxWrapper({
94
- tx: txData?.tx,
95
- kioskClient: txData?.kioskClient,
96
- kioskOwner: txData?.seller,
97
- kiosk: txData?.sellerKiosk,
98
- shouldAssertNftInSharedKiosk: true,
99
- sharedKioskState: txData?.sharedKioskState,
100
- shouldUseSharedKioskTx: false,
101
- async runCommands(kioskTx) {
102
- await addKioskTradePortRelistTx({
103
- ...txData,
104
- kioskTx,
105
- listPrice,
106
- });
107
- },
108
- });
109
- }
110
-
111
- await addTradePortUnlistTxHandler({ ...txData, isPartOfRelist: true });
112
- await addTradePortListTxHandler({ ...txData, listPrice });
113
- break;
114
- case 'hyperspace':
115
- await addHyperspaceUnlistTxHandler(txData);
116
- await addTradePortListTxHandler({ ...txData, listPrice });
117
- break;
118
- case 'bluemove':
119
- if (
120
- !isOriginByteCollection(txData?.transferPolicies) ||
121
- (ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType)) &&
122
- !txData?.sellerKiosk)
123
- ) {
124
- addBlueMoveRelistTx({ ...txData, listPrice });
125
- } else {
126
- await addBluemoveUnlistTxHandler(txData);
127
- await addTradePortListTxHandler({ ...txData, listPrice });
128
- }
129
-
130
- break;
131
- case 'clutchy':
132
- await addClutchyUnlistTxHandler(txData);
133
- await addTradePortListTxHandler({ ...txData, listPrice });
134
- break;
135
- case 'souffl3':
136
- // Souffl3 contract does not support relists
137
-
138
- break;
139
- case 'somis':
140
- // Somis contract does not support relists
141
-
142
- break;
143
- case 'keepsake':
144
- // Keepsake contract does not support relists
145
-
146
- break;
147
- case 'tocen':
148
- addTocenRelistTx({ ...txData, listPrice });
149
- break;
150
- default:
151
- throw new Error('Marketplace not supported');
152
- }
153
- }
@@ -1,132 +0,0 @@
1
- import { normalizeSuiObjectId } from '@mysten/sui/utils';
2
- import {
3
- BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT,
4
- BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT,
5
- TRADEPORT_BIDDING_STORE,
6
- } from '../../constants';
7
- import { getSharedObjects } from '../../helpers/getSharedObjects';
8
- import { isSingleBid } from '../../helpers/isSIngleBid';
9
- import { isBluemoveKioskBid } from '../../helpers/kiosk/isBluemoveKioskBid';
10
- import { isTradePortKioskBid } from '../../helpers/kiosk/isTradePortKioskBid';
11
- import { isOriginByteBid } from '../../helpers/originByte/isOriginByteBid';
12
- import { getObjectType } from '../../helpers/rpc/getObjectType';
13
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
14
- import {
15
- addSingleBidRemoveNftBidTx,
16
- addTradeportKioskRemoveNftBidTx,
17
- } from '../removeNftBids/addRemoveNftBidTxs';
18
- import { type RemoveCollectionBidTx } from './removeCollectionBids';
19
-
20
- export function addTradeportRemoveCollectionBidTx({
21
- tx,
22
- nftType,
23
- bidNonce,
24
- }: RemoveCollectionBidTx) {
25
- tx.moveCall({
26
- target:
27
- '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::cancel_bid',
28
- arguments: [tx.object(TRADEPORT_BIDDING_STORE), tx.pure.address(bidNonce)],
29
- typeArguments: [nftType],
30
- });
31
- }
32
-
33
- export function addTradePortKioskRemoveCollectionBidTx(txData: RemoveCollectionBidTx) {
34
- addTradeportKioskRemoveNftBidTx(txData);
35
- }
36
-
37
- export function addOriginByteRemoveCollectionBidTx({
38
- tx,
39
- nftType,
40
- bidAmount,
41
- bidder,
42
- sharedObjects,
43
- }: RemoveCollectionBidTx) {
44
- const { orderbook } = sharedObjects;
45
-
46
- const [coin] = tx.moveCall({
47
- target: '0x2::coin::zero',
48
- arguments: [],
49
- typeArguments: ['0x2::sui::SUI'],
50
- });
51
-
52
- tx.moveCall({
53
- target:
54
- '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::cancel_bid',
55
- arguments: [tx.object(orderbook), tx.pure.u64(bidAmount), tx.object(coin)],
56
- typeArguments: [nftType, '0x2::sui::SUI'],
57
- });
58
-
59
- tx.transferObjects([tx.object(coin)], tx.pure.address(addLeadingZerosAfter0x(bidder)));
60
- }
61
-
62
- export function addBluemoveRemoveCollectionBidTx({ tx, nftType, bidNonce }: RemoveCollectionBidTx) {
63
- tx.moveCall({
64
- target:
65
- '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_collection::cancel_offer_collection',
66
- arguments: [tx.object(BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT), tx.pure.u64(bidNonce)],
67
- typeArguments: [nftType],
68
- });
69
- }
70
-
71
- export function addBluemoveKioskRemoveCollectionBidTx({
72
- tx,
73
- nftType,
74
- bidNonce,
75
- }: RemoveCollectionBidTx) {
76
- tx.moveCall({
77
- target:
78
- '0xcc97b74ed95c8e8a3ed88050a898727dee37896da579fc400d482b64db6149ff::kiosk_offer_collection_v2::cancel_offer_collection_v2',
79
- arguments: [tx.object(BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT), tx.pure.u64(bidNonce)],
80
- typeArguments: [nftType],
81
- });
82
- }
83
-
84
- export async function addTradePortRemoveCollectionBidTxHandler(txData: RemoveCollectionBidTx) {
85
- const bidType = await getObjectType({
86
- suiClient: txData?.suiClient,
87
- objectId: normalizeSuiObjectId(txData?.bidNonce),
88
- });
89
-
90
- if (isSingleBid(bidType)) {
91
- await addSingleBidRemoveNftBidTx(txData);
92
- return;
93
- }
94
-
95
- if (isOriginByteBid(bidType)) {
96
- const sharedObjects = await getSharedObjects(txData?.nftType);
97
- addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
98
- return;
99
- }
100
-
101
- if (isTradePortKioskBid(bidType)) {
102
- addTradePortKioskRemoveCollectionBidTx(txData);
103
- return;
104
- }
105
-
106
- addTradeportRemoveCollectionBidTx(txData);
107
- }
108
-
109
- export async function addBluemoveRemoveCollectionBidTxHandler(txData: RemoveCollectionBidTx) {
110
- const bidType = await getObjectType({
111
- suiClient: txData?.suiClient,
112
- objectId: normalizeSuiObjectId(txData?.bidNonce),
113
- });
114
-
115
- if (isOriginByteBid(bidType)) {
116
- const sharedObjects = await getSharedObjects(txData?.nftType);
117
- addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
118
- return;
119
- }
120
-
121
- if (isBluemoveKioskBid(txData?.bidNonce)) {
122
- addBluemoveKioskRemoveCollectionBidTx(txData);
123
- return;
124
- }
125
-
126
- addBluemoveRemoveCollectionBidTx(txData);
127
- }
128
-
129
- export async function addClutchyRemoveCollectionBidTxHandler(txData: RemoveCollectionBidTx) {
130
- const sharedObjects = await getSharedObjects(txData?.nftType);
131
- addOriginByteRemoveCollectionBidTx({ ...txData, sharedObjects });
132
- }
@@ -1,117 +0,0 @@
1
- import type { SuiGrpcClient } from '@mysten/sui/grpc';
2
- import { Transaction } from '@mysten/sui/transactions';
3
- import { type RequestContext } from '../../SuiTradingClient';
4
- import {
5
- DELOREAN_TOKEN_IDS_TO_DISABLE,
6
- DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
7
- } from '../../constants';
8
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
9
- import { fetchCollectionBidsById } from '../../graphql/queries/fetchCollectionBidById';
10
- import { fetchCollectionsByIdWithOneNft } from '../../graphql/queries/fetchCollectionsById';
11
- import { getNftType } from '../../helpers/getNftType';
12
- import {
13
- addBluemoveRemoveCollectionBidTxHandler,
14
- addClutchyRemoveCollectionBidTxHandler,
15
- addTradePortRemoveCollectionBidTxHandler,
16
- } from './addRemoveCollectionBidsTxs';
17
-
18
- export type RemoveCollectionBidTx = {
19
- tx: Transaction;
20
- suiClient: SuiGrpcClient;
21
- sharedObjects?: any;
22
- bidNonce: string;
23
- bidder: string;
24
- nftType: string;
25
- nftTokenId: string;
26
- bidAmount: number;
27
- sellerKiosk: string;
28
- bidMarketName: string;
29
- multiBidId?: string;
30
- };
31
-
32
- export type RemoveCollectionBids = {
33
- bidIds: string[];
34
- tx?: Transaction | string;
35
- };
36
-
37
- export const removeCollectionBids = async (
38
- { bidIds, tx: existingTx }: RemoveCollectionBids,
39
- context: RequestContext,
40
- ): Promise<Transaction> => {
41
- const res = await gqlChainRequest({
42
- chain: 'sui',
43
- query: fetchCollectionBidsById,
44
- variables: { bidIds },
45
- });
46
-
47
- if (res?.bids?.length === 0) {
48
- throw new Error('No bids found');
49
- }
50
-
51
- const bidsForTracking = [];
52
- const tx = existingTx ? Transaction.from(existingTx) : new Transaction();
53
-
54
- for (const bid of res.bids) {
55
- if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
56
- throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
57
- }
58
-
59
- const collectionWithOneNftRes = await gqlChainRequest({
60
- chain: 'sui',
61
- query: fetchCollectionsByIdWithOneNft,
62
- variables: { collectionIds: [bid?.collection_id] },
63
- });
64
-
65
- const nftType = getNftType({
66
- collectionId: collectionWithOneNftRes?.collections?.[0]?.id,
67
- collectionChainState: collectionWithOneNftRes?.collections?.[0]?.chain_state,
68
- nft: collectionWithOneNftRes?.collections?.[0]?.nfts?.[0],
69
- });
70
-
71
- const txData: RemoveCollectionBidTx = {
72
- tx,
73
- suiClient: context.suiClient,
74
- bidNonce: bid?.nonce,
75
- bidder: bid?.bidder,
76
- nftType,
77
- nftTokenId: bid?.nft?.token_id,
78
- bidAmount: bid?.price,
79
- sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
80
- bidMarketName: bid?.market_contract?.name,
81
- multiBidId: bid?.multi_bid_id,
82
- };
83
-
84
- switch (txData.bidMarketName) {
85
- case 'tradeport':
86
- await addTradePortRemoveCollectionBidTxHandler(txData);
87
- break;
88
- case 'bluemove':
89
- await addBluemoveRemoveCollectionBidTxHandler(txData);
90
- break;
91
- case 'clutchy':
92
- await addClutchyRemoveCollectionBidTxHandler(txData);
93
- break;
94
- default:
95
- throw new Error('Marketplace not supported');
96
- }
97
-
98
- bidsForTracking.push({
99
- nftType,
100
- collectionId: bid?.collection_id,
101
- bidAmount: bid?.price,
102
- bidMarketName: bid?.market_contract?.name,
103
- bidder: bid?.bidder,
104
- });
105
- }
106
-
107
- // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && bidsForTracking.length > 0) {
108
- // trackMethodCall({
109
- // apiUser: context.apiUser,
110
- // apiKey: context.apiKey,
111
- // event: 'REMOVE_COLLECTION_BID',
112
- // items: bidsForTracking,
113
- // });
114
- // }
115
-
116
- return Transaction.from(tx);
117
- };