@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,216 +0,0 @@
1
- import type { KioskClient } from '@mysten/kiosk';
2
- import type { SuiGrpcClient } from '@mysten/sui/grpc';
3
- import { Transaction } from '@mysten/sui/transactions';
4
- import { type RequestContext } from '../../SuiTradingClient';
5
- import {
6
- DELOREAN_TOKEN_IDS_TO_DISABLE,
7
- DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
8
- XOCIETY_FRONTIER_COLLECTION_ID,
9
- } from '../../constants';
10
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
11
- import { fetchNftsById } from '../../graphql/queries/fetchNftsById';
12
- import { getNftType } from '../../helpers/getNftType';
13
- import { hasNativeKioskTransferPolicyRules } from '../../helpers/hasTransferPolicyRules';
14
- import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
15
- import { type SharedKioskState } from '../../helpers/kiosk/sharedKioskState.type';
16
- import { takeAndBorrowNftFromKiosk } from '../../helpers/kiosk/takeAndBorrowNftFromKiosk';
17
- import { isOBKiosk } from '../../helpers/originByte/isOBKiosk';
18
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
19
- import {
20
- addOriginByteTransferNftTx,
21
- addTradeportKioskDirectTransferTx,
22
- addTradeportKioskTransferTx,
23
- canBeTransferedDirectly,
24
- } from './addTransferNftTx';
25
-
26
- export type TransferNftTx = {
27
- tx: Transaction;
28
- kioskClient: KioskClient;
29
- sharedKioskState?: SharedKioskState;
30
- nftType: string;
31
- nftTokenId: string;
32
- senderKiosk: string;
33
- senderAddress: string;
34
- recipientAddress: string;
35
- transferPolicies: any;
36
- kioskTx?: any;
37
- transferPolicy?: any;
38
- suiClient: SuiGrpcClient;
39
- };
40
-
41
- export type TransferNfts = {
42
- nftIds: string[];
43
- recipientAddress: string;
44
- walletAddress: string;
45
- };
46
-
47
- export const transferNfts = async (
48
- { nftIds, recipientAddress, walletAddress }: TransferNfts,
49
- context: RequestContext,
50
- ): Promise<Transaction> => {
51
- if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
52
- throw new Error('Cannot transfer to self');
53
- }
54
-
55
- // Recipient address needs to have a balance to be a valid address
56
- if (!recipientAddress?.includes('0x') || recipientAddress?.length < 65) {
57
- throw new Error('Invalid recipient address');
58
- }
59
-
60
- const res = await gqlChainRequest({
61
- chain: 'sui',
62
- query: fetchNftsById,
63
- variables: { nftIds },
64
- });
65
-
66
- if (res?.nfts?.length === 0) {
67
- throw new Error('No nfts found');
68
- }
69
-
70
- const nftsForTracking = [];
71
- const nftsToTransferDirectly = [];
72
- const tx = new Transaction();
73
-
74
- const sharedKioskState: SharedKioskState = {
75
- kioskTx: undefined,
76
- };
77
-
78
- for (const nft of res.nfts) {
79
- if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
80
- throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
81
- }
82
-
83
- if (nft?.listed) {
84
- throw new Error('Cannot transfer a listed NFT');
85
- }
86
-
87
- const nftType = getNftType({
88
- collectionId: nft?.collection?.id,
89
- collectionChainState: nft?.collection?.chain_state,
90
- nft,
91
- });
92
-
93
- const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
94
-
95
- const txData: TransferNftTx = {
96
- tx,
97
- suiClient: context.suiClient,
98
- kioskClient: context.kioskClient,
99
- sharedKioskState,
100
- nftType,
101
- nftTokenId: nft?.token_id,
102
- senderKiosk: nft?.chain_state?.kiosk_id,
103
- senderAddress: walletAddress,
104
- recipientAddress,
105
- transferPolicies,
106
- };
107
-
108
- // If NFT is not inside kiosk, transfer the NFT directly
109
- if (!txData.senderKiosk) {
110
- tx.transferObjects(
111
- [tx.object(txData.nftTokenId)],
112
- tx.pure.address(addLeadingZerosAfter0x(recipientAddress)),
113
- );
114
- continue;
115
- }
116
-
117
- const isSenderKioskOriginByte = await isOBKiosk(txData.senderAddress, txData.senderKiosk);
118
-
119
- // If NFT is inside ob kiosk
120
- if (isSenderKioskOriginByte) {
121
- await addOriginByteTransferNftTx(txData);
122
-
123
- continue;
124
- }
125
-
126
- // If NFT is inside native kiosk and has no transfer policy rules or is XOCIETY Frontier collection, take it out of the kiosk and transfer it directly
127
- if (
128
- txData?.senderKiosk &&
129
- (!hasNativeKioskTransferPolicyRules(txData?.transferPolicies) ||
130
- nft?.collection?.id === XOCIETY_FRONTIER_COLLECTION_ID)
131
- ) {
132
- await kioskTxWrapper({
133
- tx: txData?.tx,
134
- kioskClient: txData?.kioskClient,
135
- kioskOwner: txData?.senderAddress,
136
- kiosk: txData?.senderKiosk,
137
- shouldAssertNftInSharedKiosk: true,
138
- sharedKioskState: txData?.sharedKioskState,
139
- shouldUseSharedKioskTx: false,
140
- async runCommands(kioskTx) {
141
- const borrowedItem = await takeAndBorrowNftFromKiosk({
142
- tx: txData?.tx,
143
- transferPolicies: txData?.transferPolicies,
144
- kioskTx,
145
- kioskClient: txData?.kioskClient,
146
- nftTokenId: txData?.nftTokenId,
147
- nftType: txData?.nftType,
148
- suiClient: txData?.suiClient,
149
- kioskOwner: txData?.senderAddress,
150
- });
151
-
152
- tx.transferObjects(
153
- [tx.object(borrowedItem)],
154
- tx.pure.address(addLeadingZerosAfter0x(recipientAddress)),
155
- );
156
- },
157
- });
158
-
159
- continue;
160
- }
161
-
162
- // If NFT can be transferred directly by creating new kiosk for receiver
163
- if (await canBeTransferedDirectly(context.suiClient, nft?.collection?.chain_state)) {
164
- nftsToTransferDirectly.push(nft);
165
- } else {
166
- await kioskTxWrapper({
167
- tx: txData?.tx,
168
- kioskClient: txData?.kioskClient,
169
- kioskOwner: txData?.senderAddress,
170
- kiosk: txData?.senderKiosk,
171
- shouldAssertNftInSharedKiosk: true,
172
- sharedKioskState: txData?.sharedKioskState,
173
- shouldUseSharedKioskTx: false,
174
- async runCommands(kioskTx) {
175
- await addTradeportKioskTransferTx({ ...txData, kioskTx });
176
- },
177
- });
178
- }
179
-
180
- nftsForTracking.push({
181
- nftType,
182
- senderAddress: walletAddress,
183
- recipientAddress,
184
- });
185
- }
186
-
187
- await addTradeportKioskDirectTransferTx(
188
- {
189
- tx,
190
- kioskClient: context.kioskClient,
191
- sharedKioskState,
192
- senderAddress: walletAddress,
193
- recipientAddress,
194
- },
195
- nftsToTransferDirectly,
196
- context.suiClient,
197
- );
198
-
199
- // currently turned off $1 bulk transfer fee
200
- // if (res?.nfts?.length > 1) {
201
- // await addOneDollarFee(tx);
202
- // }
203
-
204
- sharedKioskState?.kioskTx?.finalize();
205
-
206
- // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && nftsForTracking.length > 0) {
207
- // trackMethodCall({
208
- // apiUser: context.apiUser,
209
- // apiKey: context.apiKey,
210
- // event: 'TRANSFER_NFTS',
211
- // items: nftsForTracking,
212
- // });
213
- // }
214
-
215
- return Transaction.from(tx);
216
- };
@@ -1,399 +0,0 @@
1
- import {
2
- BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT,
3
- BLUEMOVE_MARKET_CONFIG_OBJECT,
4
- HYPERSPACE_MP_TRANSFER_POLICY_TYPE,
5
- KEEPSAKE_MARKETPLACE_KIOSK,
6
- KEEPSAKE_MARKETPLACE_OBJECT,
7
- ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK,
8
- SOUFFL3_VERSION_OBJECT,
9
- TOCEN_MARKETPLACE_OBJECT,
10
- TRADEPORT_KIOSK_LISTING_STORE,
11
- TRADEPORT_LISTING_STORE,
12
- TRADEPORT_LISTINGS_PACKAGE,
13
- TRADEPORT_LISTINGS_STORE,
14
- TRADEPORT_ORDERBOOK_STORE,
15
- XOCIETY_FRONTIER_COLLECTION_ID,
16
- } from '../../constants';
17
- import { getSharedObjects } from '../../helpers/getSharedObjects';
18
- import { hasNativeKioskTransferPolicyRules } from '../../helpers/hasTransferPolicyRules';
19
- import { isNonKioskListing } from '../../helpers/isNonKioskListing';
20
- import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
21
- import { takeAndBorrowNftFromKiosk } from '../../helpers/kiosk/takeAndBorrowNftFromKiosk';
22
- import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
23
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
24
- import { normalizedNftType } from '../../utils/normalizeNftType';
25
- import { type UnlistListingTx } from './unlistListings';
26
-
27
- export function addLegacyTradePortUnlistTx({ tx, listingNonce, nftType }: UnlistListingTx) {
28
- tx.moveCall({
29
- target: '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::unlist',
30
- arguments: [tx.object(TRADEPORT_LISTING_STORE), tx.pure.address(listingNonce)],
31
- typeArguments: [nftType],
32
- });
33
- }
34
-
35
- export async function addLegacyTradePortKioskUnlistTx({
36
- tx,
37
- kioskTx,
38
- nftTokenId,
39
- nftType,
40
- }: UnlistListingTx) {
41
- tx.moveCall({
42
- target:
43
- '0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_listings::unlist',
44
- arguments: [
45
- tx.object(TRADEPORT_KIOSK_LISTING_STORE),
46
- tx.object(kioskTx.kiosk),
47
- tx.object(kioskTx.kioskCap),
48
- tx.pure.address(nftTokenId),
49
- ],
50
- typeArguments: [nftType],
51
- });
52
- }
53
-
54
- export function addTradePortUnlistTx({ tx, nftTokenId, nftType }: UnlistListingTx) {
55
- tx.moveCall({
56
- target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::cancel_ob_listing_without_transfer_policy`,
57
- arguments: [
58
- tx.object(TRADEPORT_LISTINGS_STORE),
59
- tx.object(TRADEPORT_ORDERBOOK_STORE),
60
- tx.pure.id(nftTokenId),
61
- ],
62
- typeArguments: [nftType],
63
- });
64
- }
65
-
66
- export async function addKioskTradePortUnlistTx({
67
- tx,
68
- kioskTx,
69
- nftTokenId,
70
- nftType,
71
- }: UnlistListingTx) {
72
- tx.moveCall({
73
- target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::cancel_ob_listing_with_transfer_policy`,
74
- arguments: [
75
- tx.object(TRADEPORT_LISTINGS_STORE),
76
- tx.object(TRADEPORT_ORDERBOOK_STORE),
77
- tx.object(kioskTx.kiosk),
78
- tx.object(kioskTx.kioskCap),
79
- tx.pure.id(nftTokenId),
80
- ],
81
- typeArguments: [nftType],
82
- });
83
- }
84
-
85
- export function addOriginByteUnlistTx({
86
- tx,
87
- sharedObjects,
88
- listingNonce,
89
- price,
90
- nftTokenId,
91
- nftType,
92
- }: UnlistListingTx) {
93
- const { orderbook } = sharedObjects;
94
-
95
- tx.moveCall({
96
- target:
97
- '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::cancel_ask',
98
- arguments: [
99
- tx.object(orderbook),
100
- tx.object(listingNonce),
101
- tx.pure.u64(price),
102
- tx.pure.address(nftTokenId),
103
- ],
104
- typeArguments: [nftType, '0x2::sui::SUI'],
105
- });
106
- }
107
-
108
- export function addSouffl3UnlistTx({ tx, listingNonce, nftType }: UnlistListingTx) {
109
- tx.moveCall({
110
- target:
111
- '0x30d90b5b67be77e6e06f02dae9f0f2fcdad16e38854316ae8a7b4f5b4971f5e0::Market::delist_generic',
112
- arguments: [tx.object(SOUFFL3_VERSION_OBJECT), tx.object(listingNonce)],
113
- typeArguments: [nftType, '0x2::sui::SUI'],
114
- });
115
- }
116
-
117
- export function addBluemoveUnlistTx({ tx, nftTokenId, nftType }: UnlistListingTx) {
118
- tx.moveCall({
119
- target:
120
- '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist_and_take',
121
- arguments: [tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT), tx.pure.address(nftTokenId)],
122
- typeArguments: [nftType, nftType],
123
- });
124
- }
125
-
126
- export async function addBluemoveKioskUnlistTx({
127
- tx,
128
- kioskTx,
129
- nftTokenId,
130
- nftType,
131
- }: UnlistListingTx) {
132
- tx.moveCall({
133
- target:
134
- '0xcc97b74ed95c8e8a3ed88050a898727dee37896da579fc400d482b64db6149ff::kiosk_trade::kiosk_delist',
135
- arguments: [
136
- tx.object(BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT),
137
- tx.object(kioskTx.kiosk),
138
- tx.pure.address(nftTokenId),
139
- ],
140
- typeArguments: [nftType],
141
- });
142
- }
143
-
144
- export function addKeepsakeUnlistTx({ tx, nftTokenId, nftType }: UnlistListingTx) {
145
- tx.moveCall({
146
- target:
147
- '0x2be8c4a1a3cea4d3255d870d367c87838a8cc2bfe4f216a6b67b153027087a7::keepsake_marketplace::delist_and_take',
148
- arguments: [
149
- tx.object(KEEPSAKE_MARKETPLACE_OBJECT),
150
- tx.object(KEEPSAKE_MARKETPLACE_KIOSK),
151
- tx.pure.address(nftTokenId),
152
- ],
153
- typeArguments: [nftType],
154
- });
155
- }
156
-
157
- export async function addHyperspaceKioskUnlistTx({
158
- tx,
159
- kioskTx,
160
- nftTokenId,
161
- nftType,
162
- }: UnlistListingTx) {
163
- tx.moveCall({
164
- target:
165
- '0x6ea97b03c441edd54ae89224bf9560e583ee66c37e6c246f5db35258e580ba94::hyperspace::delist',
166
- arguments: [tx.object(kioskTx.kiosk), tx.object(kioskTx.kioskCap), tx.pure.address(nftTokenId)],
167
- typeArguments: [nftType, HYPERSPACE_MP_TRANSFER_POLICY_TYPE],
168
- });
169
- }
170
-
171
- export function addTocenUnlistTx({ tx, nftTokenId, nftType }: UnlistListingTx) {
172
- tx.moveCall({
173
- target:
174
- '0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::delist_and_take',
175
- arguments: [tx.object(TOCEN_MARKETPLACE_OBJECT), tx.pure.address(nftTokenId)],
176
- typeArguments: [nftType],
177
- });
178
- }
179
-
180
- export function addSomisUnlistTx({
181
- tx,
182
- sharedObjects,
183
- nftTokenId,
184
- nftType,
185
- price,
186
- }: UnlistListingTx) {
187
- const { marketplace } = sharedObjects;
188
-
189
- tx.moveCall({
190
- target:
191
- '0xf0b0beb956e26bde50dbd6ac393026c4525aee3b194a9478f09748f7211b5a02::marketplace::cancel_ask',
192
- arguments: [tx.object(marketplace), tx.pure.address(nftTokenId), tx.pure.u64(price)],
193
- typeArguments: [nftType, '0x2::sui::SUI'],
194
- });
195
- }
196
-
197
- export async function addTradePortUnlistTxHandler(txData: UnlistListingTx) {
198
- if (
199
- txData?.listingNonce &&
200
- isOriginByteCollection(txData?.transferPolicies) &&
201
- !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))
202
- ) {
203
- const sharedObjects = await getSharedObjects(txData?.nftType);
204
- addOriginByteUnlistTx({ ...txData, sharedObjects });
205
-
206
- return;
207
- }
208
-
209
- // If non kiosk listing (nonce starts with "0::")
210
- if (txData?.listingNonce?.startsWith('0::')) {
211
- addTradePortUnlistTx(txData);
212
- return;
213
- }
214
-
215
- // If kiosk listing (nonce starts with "1::")
216
- if (txData?.listingNonce?.startsWith('1::')) {
217
- return kioskTxWrapper({
218
- tx: txData?.tx,
219
- kioskClient: txData?.kioskClient,
220
- kioskOwner: txData?.seller,
221
- kiosk: txData?.sellerKiosk,
222
- shouldAllowNftUnsharedKiosk: true,
223
- sharedKioskState: txData?.sharedKioskState,
224
- shouldUseSharedKioskTx: false,
225
- async runCommands(kioskTx) {
226
- await addKioskTradePortUnlistTx({
227
- ...txData,
228
- kioskTx,
229
- });
230
-
231
- // If XOCIETY Frontier collection, take NFT out of kiosk and transfer it back to user (seller)
232
- if (txData?.collectionId === XOCIETY_FRONTIER_COLLECTION_ID) {
233
- const borrowedItem = await takeAndBorrowNftFromKiosk({
234
- tx: txData?.tx,
235
- transferPolicies: txData?.transferPolicies,
236
- kioskTx,
237
- kioskClient: txData?.kioskClient,
238
- nftTokenId: txData?.nftTokenId,
239
- nftType: txData?.nftType,
240
- suiClient: txData?.suiClient,
241
- kioskOwner: txData?.seller,
242
- });
243
-
244
- txData?.tx.transferObjects(
245
- [txData?.tx.object(borrowedItem)],
246
- txData?.tx.pure.address(addLeadingZerosAfter0x(txData?.seller)),
247
- );
248
- }
249
- },
250
- });
251
- }
252
-
253
- // Fallback to legacy contract logic
254
- if (
255
- txData?.listingNonce &&
256
- (await isNonKioskListing({ suiClient: txData?.suiClient, listingNonce: txData?.listingNonce }))
257
- ) {
258
- if (txData?.isPartOfRelist) {
259
- throw new Error(
260
- 'Cannot relist this non kiosk NFT in one transaction from legacy contract. You must unlist and list again',
261
- );
262
- }
263
-
264
- addLegacyTradePortUnlistTx(txData);
265
- return;
266
- }
267
-
268
- // If legacy kiosk listing
269
- if (txData?.sellerKiosk) {
270
- return kioskTxWrapper({
271
- tx: txData?.tx,
272
- kioskClient: txData?.kioskClient,
273
- kioskOwner: txData?.seller,
274
- kiosk: txData?.sellerKiosk,
275
- shouldAllowNftUnsharedKiosk: true,
276
- sharedKioskState: txData?.sharedKioskState,
277
- shouldUseSharedKioskTx: false,
278
- async runCommands(kioskTx) {
279
- await addLegacyTradePortKioskUnlistTx({
280
- ...txData,
281
- kioskTx,
282
- });
283
-
284
- // if nft has no transfer policy rule but is inside a kiosk, take it out of the kiosk
285
- if (!hasNativeKioskTransferPolicyRules(txData?.transferPolicies)) {
286
- const borrowedItem = await takeAndBorrowNftFromKiosk({
287
- tx: txData?.tx,
288
- transferPolicies: txData?.transferPolicies,
289
- kioskTx,
290
- kioskClient: txData?.kioskClient,
291
- nftTokenId: txData?.nftTokenId,
292
- nftType: txData?.nftType,
293
- suiClient: txData?.suiClient,
294
- kioskOwner: txData?.seller,
295
- });
296
-
297
- // Transfer the borrowed item back to the seller
298
- txData?.tx.transferObjects(
299
- [txData?.tx.object(borrowedItem)],
300
- txData?.tx.pure.address(addLeadingZerosAfter0x(txData?.seller)),
301
- );
302
- }
303
- },
304
- });
305
- }
306
-
307
- // If legacy non kiosk listing
308
- addLegacyTradePortUnlistTx(txData);
309
- }
310
-
311
- export async function addHyperspaceUnlistTxHandler(txData: UnlistListingTx) {
312
- if (
313
- txData?.listingNonce &&
314
- isOriginByteCollection(txData?.transferPolicies) &&
315
- !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))
316
- ) {
317
- const sharedObjects = await getSharedObjects(txData?.nftType);
318
- addOriginByteUnlistTx({ ...txData, sharedObjects });
319
-
320
- return;
321
- }
322
-
323
- return kioskTxWrapper({
324
- tx: txData?.tx,
325
- kioskClient: txData?.kioskClient,
326
- kioskOwner: txData?.seller,
327
- kiosk: txData?.sellerKiosk,
328
- shouldAllowNftUnsharedKiosk: true,
329
- sharedKioskState: txData?.sharedKioskState,
330
- shouldUseSharedKioskTx: false,
331
- async runCommands(kioskTx) {
332
- await addHyperspaceKioskUnlistTx({
333
- ...txData,
334
- kioskTx,
335
- });
336
- },
337
- });
338
- }
339
-
340
- export async function addBluemoveUnlistTxHandler(txData: UnlistListingTx) {
341
- if (
342
- txData?.listingNonce &&
343
- isOriginByteCollection(txData?.transferPolicies) &&
344
- !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))
345
- ) {
346
- const sharedObjects = await getSharedObjects(txData?.nftType);
347
- addOriginByteUnlistTx({ ...txData, sharedObjects });
348
-
349
- return;
350
- }
351
-
352
- if (txData?.sellerKiosk) {
353
- return kioskTxWrapper({
354
- tx: txData?.tx,
355
- kioskClient: txData?.kioskClient,
356
- kioskOwner: txData?.seller,
357
- kiosk: txData?.sellerKiosk,
358
- shouldAllowNftUnsharedKiosk: true,
359
- sharedKioskState: txData?.sharedKioskState,
360
- shouldUseSharedKioskTx: false,
361
- async runCommands(kioskTx) {
362
- await addBluemoveKioskUnlistTx({
363
- ...txData,
364
- kioskTx,
365
- });
366
- },
367
- });
368
- }
369
-
370
- addBluemoveUnlistTx(txData);
371
- }
372
-
373
- export async function addClutchyUnlistTxHandler(txData: UnlistListingTx) {
374
- const sharedObjects = await getSharedObjects(txData?.nftType);
375
- addOriginByteUnlistTx({ ...txData, sharedObjects });
376
- }
377
-
378
- export async function addSouffl3UnlistTxHandler(txData: UnlistListingTx) {
379
- addSouffl3UnlistTx(txData);
380
- }
381
-
382
- export async function addSomisUnlistTxHandler(txData: UnlistListingTx) {
383
- const sharedObjects = await getSharedObjects(txData?.nftType);
384
-
385
- if (sharedObjects?.marketplace) {
386
- addSomisUnlistTx(txData);
387
- return;
388
- }
389
-
390
- addOriginByteUnlistTx({ ...txData, sharedObjects });
391
- }
392
-
393
- export async function addKeepsakeUnlistTxHandler(txData: UnlistListingTx) {
394
- addKeepsakeUnlistTx(txData);
395
- }
396
-
397
- export function addTocenUnlistTxHandler(txData: UnlistListingTx) {
398
- addTocenUnlistTx(txData);
399
- }