@tradeport/sui-trading-sdk 0.5.3 → 0.5.5

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 (153) hide show
  1. package/.babel.config.js +3 -0
  2. package/.claude/settings.json +5 -0
  3. package/.claude/settings.local.json +5 -0
  4. package/.env.demo +5 -0
  5. package/.eslintrc.json +46 -0
  6. package/.prettierignore +4 -0
  7. package/.prettierrc.json +7 -0
  8. package/.vscode/launch.json +23 -0
  9. package/CHANGELOG.md +746 -0
  10. package/jest.config.js +12 -0
  11. package/package.json +66 -71
  12. package/src/SuiTradingClient.ts +442 -0
  13. package/src/apiClients/createKioskClient.ts +10 -0
  14. package/src/apiClients/createSuiClient.ts +5 -0
  15. package/src/apiClients/graphqlClient.ts +17 -0
  16. package/src/bigNumberConfig.ts +10 -0
  17. package/src/constants.ts +1052 -0
  18. package/src/graphql/createChainGQLQuery.ts +27 -0
  19. package/src/graphql/gqlChainRequest.ts +21 -0
  20. package/src/graphql/queries/fetchAccountKiosks.ts +12 -0
  21. package/src/graphql/queries/fetchActiveLockStateByNftId.ts +15 -0
  22. package/src/graphql/queries/fetchBidsById.ts +36 -0
  23. package/src/graphql/queries/fetchCollectionBidById.ts +21 -0
  24. package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +29 -0
  25. package/src/graphql/queries/fetchCollectionChainState.ts +17 -0
  26. package/src/graphql/queries/fetchCollectionFloorListingForMarket.ts +28 -0
  27. package/src/graphql/queries/fetchCollectionFloorListings.ts +15 -0
  28. package/src/graphql/queries/fetchCollectionsById.ts +39 -0
  29. package/src/graphql/queries/fetchCommissionByListingId.ts +13 -0
  30. package/src/graphql/queries/fetchCryptoToUsdRate.ts +13 -0
  31. package/src/graphql/queries/fetchKiosksByOwner.ts +14 -0
  32. package/src/graphql/queries/fetchListingsById.ts +29 -0
  33. package/src/graphql/queries/fetchListingsByNftId.ts +23 -0
  34. package/src/graphql/queries/fetchLockById.ts +23 -0
  35. package/src/graphql/queries/fetchMultibidById.ts +34 -0
  36. package/src/graphql/queries/fetchNftCollectionChainState.ts +12 -0
  37. package/src/graphql/queries/fetchNftsById.ts +75 -0
  38. package/src/graphql/queries/fetchNftsByKioskId.ts +45 -0
  39. package/src/graphql/queries/fetchOwnerCapByKiosk.ts +10 -0
  40. package/src/graphql/queries/fetchPersonalCapByKiosk.ts +10 -0
  41. package/src/graphql/queries/fetchSharedObjectsByType.ts +12 -0
  42. package/src/graphql/queries/fetchTransferPoliciesByType.ts +12 -0
  43. package/src/graphql/queries/fetchWalletKiosks.ts +14 -0
  44. package/src/graphql/queries/getCommissionByListingId.ts +15 -0
  45. package/src/helpers/addOneDollarFee.ts +17 -0
  46. package/src/helpers/addThirdPartyTxFee.ts +17 -0
  47. package/src/helpers/calculatePremium.ts +9 -0
  48. package/src/helpers/calculateRoyaltyFee.ts +28 -0
  49. package/src/helpers/destroyZeroCoin.ts +14 -0
  50. package/src/helpers/getActiveLockStateByNftId.ts +15 -0
  51. package/src/helpers/getCollectionChainState.ts +31 -0
  52. package/src/helpers/getCollectionFloorPrice.ts +12 -0
  53. package/src/helpers/getLockById.ts +29 -0
  54. package/src/helpers/getMarketFeePrice.ts +82 -0
  55. package/src/helpers/getNftType.ts +38 -0
  56. package/src/helpers/getRoyaltyRuleModule.ts +7 -0
  57. package/src/helpers/getSharedObjects.ts +119 -0
  58. package/src/helpers/getSuiToUsdRate.ts +14 -0
  59. package/src/helpers/getTradeportBiddingContractBidAmount.ts +31 -0
  60. package/src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts +24 -0
  61. package/src/helpers/hasPersonalKioskRule.ts +7 -0
  62. package/src/helpers/hasRoyaltyRule.ts +7 -0
  63. package/src/helpers/hasTransferPolicyRules.ts +6 -0
  64. package/src/helpers/isExpiredListing.ts +9 -0
  65. package/src/helpers/isNonKioskListing.ts +14 -0
  66. package/src/helpers/isSIngleBid.ts +13 -0
  67. package/src/helpers/kiosk/assertNftInSharedKiosk.ts +31 -0
  68. package/src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts +71 -0
  69. package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +29 -0
  70. package/src/helpers/kiosk/getKioskPlaceBidCoin.ts +59 -0
  71. package/src/helpers/kiosk/getNativeKioskTransferPolicies.ts +29 -0
  72. package/src/helpers/kiosk/getNativeKioskTransferPoliciesByNftType.ts +21 -0
  73. package/src/helpers/kiosk/getRulePackageId.ts +59 -0
  74. package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +154 -0
  75. package/src/helpers/kiosk/isBluemoveKioskBid.ts +1 -0
  76. package/src/helpers/kiosk/isTradePortKioskBid.ts +4 -0
  77. package/src/helpers/kiosk/kioskListingBcs.ts +19 -0
  78. package/src/helpers/kiosk/kioskTxWrapper.ts +152 -0
  79. package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +100 -0
  80. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +171 -0
  81. package/src/helpers/kiosk/resolveCustomTransferPolicyRules.ts +75 -0
  82. package/src/helpers/kiosk/resolveFloorPriceRule.ts +21 -0
  83. package/src/helpers/kiosk/resolveKioskLockRule.ts +47 -0
  84. package/src/helpers/kiosk/resolvePersonalKioskRule.ts +23 -0
  85. package/src/helpers/kiosk/resolveRoyaltyRule.ts +57 -0
  86. package/src/helpers/kiosk/resolveTableAllowlistRule.ts +34 -0
  87. package/src/helpers/kiosk/resolveTransferPolicies.ts +158 -0
  88. package/src/helpers/kiosk/sharedKioskState.type.ts +11 -0
  89. package/src/helpers/kiosk/takeAndBorrowNftFromKiosk.ts +50 -0
  90. package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +73 -0
  91. package/src/helpers/kiosk/upgradeKioskRulesPackageId.ts +17 -0
  92. package/src/helpers/originByte/confirmOBTranfer.ts +33 -0
  93. package/src/helpers/originByte/createOBKiosk.ts +14 -0
  94. package/src/helpers/originByte/depositNftIntoOBKiosk.ts +16 -0
  95. package/src/helpers/originByte/getOBBidderKiosk.ts +12 -0
  96. package/src/helpers/originByte/getOBKiosk.ts +24 -0
  97. package/src/helpers/originByte/getOrCreateOBKiosk.ts +42 -0
  98. package/src/helpers/originByte/isOBKiosk.ts +13 -0
  99. package/src/helpers/originByte/isOriginByteBid.ts +30 -0
  100. package/src/helpers/originByte/isOriginByteCollection.ts +11 -0
  101. package/src/helpers/originByte/shareOriginByteKiosk.ts +14 -0
  102. package/src/helpers/rpc/getAcountBalance.ts +18 -0
  103. package/src/helpers/rpc/getObjectType.ts +25 -0
  104. package/src/helpers/splitCoins.ts +12 -0
  105. package/src/helpers/track.ts +20 -0
  106. package/src/helpers/validateMinFloorPrice.ts +22 -0
  107. package/src/index.ts +2 -0
  108. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +189 -0
  109. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +398 -0
  110. package/src/methods/acceptNftBids/acceptNftBids.ts +174 -0
  111. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +438 -0
  112. package/src/methods/applyFtStrategy/applyFtStrategy.ts +55 -0
  113. package/src/methods/applyNftStrategy/applyNftStrategy.ts +90 -0
  114. package/src/methods/buyListings/addBuyListingTxs.ts +806 -0
  115. package/src/methods/buyListings/buyListings.ts +230 -0
  116. package/src/methods/cancelMultiBid/cancelMultiBid.ts +51 -0
  117. package/src/methods/cancelNftTransfers/addCancelNftTransfersTx.ts +20 -0
  118. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +118 -0
  119. package/src/methods/claimNfts/addClaimNftsTxs.ts +247 -0
  120. package/src/methods/claimNfts/claimNfts.ts +270 -0
  121. package/src/methods/createMultiBid/createMultiBid.ts +36 -0
  122. package/src/methods/listNfts/addListTxs.ts +210 -0
  123. package/src/methods/listNfts/addRelistTxs.ts +87 -0
  124. package/src/methods/listNfts/listNfts.ts +152 -0
  125. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +226 -0
  126. package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +149 -0
  127. package/src/methods/placeCollectionBids/placeCollectionBids.ts +153 -0
  128. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +154 -0
  129. package/src/methods/placeNftBids/placeNftBids.ts +111 -0
  130. package/src/methods/relistNft/relistNft.ts +153 -0
  131. package/src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts +132 -0
  132. package/src/methods/removeCollectionBids/removeCollectionBids.ts +117 -0
  133. package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +122 -0
  134. package/src/methods/removeNftBids/removeNftBids.ts +116 -0
  135. package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +40 -0
  136. package/src/methods/sponsorNftListing/sponsorNftListing.ts +60 -0
  137. package/src/methods/transferNfts/addTransferNftTx.ts +220 -0
  138. package/src/methods/transferNfts/transferNfts.ts +216 -0
  139. package/src/methods/unlistListings/addUnlistListingTxs.ts +399 -0
  140. package/src/methods/unlistListings/unlistListings.ts +158 -0
  141. package/src/methods/updateMultiBid/updateMultiBid.ts +66 -0
  142. package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +100 -0
  143. package/src/tests/SuiWallet.ts +83 -0
  144. package/src/utils/addHexPrefix.ts +7 -0
  145. package/src/utils/addLeadingZerosAfter0x.ts +9 -0
  146. package/src/utils/normalizeNftType.ts +7 -0
  147. package/src/utils/printTxBlockTxs.ts +11 -0
  148. package/src/utils/pureValues.ts +13 -0
  149. package/src/utils/toUint8Array.ts +12 -0
  150. package/tsconfig.json +16 -0
  151. package/dist/index.d.ts +0 -194
  152. package/dist/index.js +0 -7419
  153. package/dist/index.js.map +0 -1
@@ -0,0 +1,270 @@
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
+ BLUEMOVE_CLAIMABLE_CONTRACT_KEYS,
7
+ DELOREAN_TOKEN_IDS_TO_DISABLE,
8
+ DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
9
+ } from '../../constants';
10
+ import { gqlChainRequest } from '../../graphql/gqlChainRequest';
11
+ import { fetchNftsById } from '../../graphql/queries/fetchNftsById';
12
+ import { getNftType } from '../../helpers/getNftType';
13
+ import { getSharedObjects } from '../../helpers/getSharedObjects';
14
+ import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
15
+ import { type SharedKioskState } from '../../helpers/kiosk/sharedKioskState.type';
16
+ import {
17
+ addBluemoveClaimAcceptedBidNft,
18
+ addClaimAcceptedBidNftTx,
19
+ addClaimAcceptedBidNftWithPurchaseCapTx,
20
+ addClaimTradeHoldTx,
21
+ addClaimTransferredNftTx,
22
+ addClaimTransferredNftWithPurchaseCapTx,
23
+ } from './addClaimNftsTxs';
24
+
25
+ export type ClaimTradeHoldTx = {
26
+ tx: Transaction;
27
+ kioskClient: KioskClient;
28
+ sharedKioskState?: SharedKioskState;
29
+ sharedObjects?: any;
30
+ transferPolicies: any;
31
+ nftType: string;
32
+ claimableTradeId: string;
33
+ claimableSellerKiosk: string;
34
+ claimableBuyerKiosk: string;
35
+ };
36
+
37
+ export type ClaimTransferredNftTx = {
38
+ tx: Transaction;
39
+ suiClient?: SuiGrpcClient;
40
+ kioskTx?: any;
41
+ kioskClient: KioskClient;
42
+ sharedKioskState?: SharedKioskState;
43
+ sharedObjects?: any;
44
+ transferPolicies: any;
45
+ claimer: string;
46
+ nftTokenId: string;
47
+ nftType: string;
48
+ sellerKiosk: string;
49
+ seller: string;
50
+ preloadedTransferPolicyId?: string;
51
+ };
52
+
53
+ export type ClaimAcceptedBidNftTx = {
54
+ tx: Transaction;
55
+ suiClient: SuiGrpcClient;
56
+ kioskTx?: any;
57
+ kioskClient: KioskClient;
58
+ sharedKioskState?: SharedKioskState;
59
+ sharedObjects?: any;
60
+ transferPolicies: any;
61
+ claimer: string;
62
+ nftTokenId: string;
63
+ nftType: string;
64
+ sellerKiosk: string;
65
+ seller: string;
66
+ };
67
+
68
+ export type ClaimNfts = {
69
+ nftIds: string[];
70
+ walletAddress: string;
71
+ tx?: Transaction;
72
+ };
73
+ export const claimNfts = async (
74
+ { nftIds, walletAddress, tx: existingTx }: ClaimNfts,
75
+ context: RequestContext,
76
+ useOldClaim?: boolean,
77
+ ): Promise<Transaction> => {
78
+ const res = await gqlChainRequest({
79
+ chain: 'sui',
80
+ query: fetchNftsById,
81
+ variables: { nftIds },
82
+ });
83
+
84
+ if (res?.nfts?.length === 0) {
85
+ throw new Error('No nfts found');
86
+ }
87
+
88
+ const nftsForTracking = [];
89
+ const tx = existingTx ?? new Transaction();
90
+
91
+ const sharedKioskState: SharedKioskState = {
92
+ kioskTx: undefined,
93
+ };
94
+
95
+ for (const nft of res.nfts) {
96
+ if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(nft?.token_id)) {
97
+ throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
98
+ }
99
+
100
+ if (!nft) {
101
+ throw new Error('No nft found');
102
+ }
103
+
104
+ if (!nft?.chain_state?.claimable) {
105
+ throw new Error(`Nft ID: ${nft?.id} is not claimable`);
106
+ }
107
+
108
+ const nftType = getNftType({
109
+ collectionId: nft?.collection?.id,
110
+ collectionChainState: nft?.collection?.chain_state,
111
+ nft,
112
+ });
113
+
114
+ const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
115
+
116
+ // claim trade hold nft
117
+ if (nft?.chain_state?.claimable_trade_id) {
118
+ const txData: ClaimTradeHoldTx = {
119
+ tx,
120
+ kioskClient: context.kioskClient,
121
+ transferPolicies,
122
+ nftType,
123
+ claimableTradeId: nft?.chain_state?.claimable_trade_id,
124
+ claimableSellerKiosk: nft?.chain_state?.claimable_seller_kiosk,
125
+ claimableBuyerKiosk: nft?.chain_state?.claimable_buyer_kiosk,
126
+ sharedKioskState,
127
+ };
128
+
129
+ const sharedObjects = await getSharedObjects(nftType);
130
+ addClaimTradeHoldTx({ ...txData, sharedObjects });
131
+ continue;
132
+ }
133
+
134
+ // claim accepted bid nft
135
+ if (
136
+ ['accept-token-offer', 'accept-collection-offer']?.includes(
137
+ nft?.chain_state?.claimable_reason,
138
+ )
139
+ ) {
140
+ const txData: ClaimAcceptedBidNftTx = {
141
+ tx,
142
+ suiClient: context.suiClient,
143
+ kioskClient: context.kioskClient,
144
+ sharedKioskState,
145
+ transferPolicies,
146
+ claimer: walletAddress,
147
+ nftType,
148
+ nftTokenId: nft?.token_id,
149
+ sellerKiosk: nft?.chain_state?.kiosk_id,
150
+ seller: nft?.owner,
151
+ };
152
+
153
+ if (BLUEMOVE_CLAIMABLE_CONTRACT_KEYS?.includes(nft?.chain_state?.claimable_contract_key)) {
154
+ await kioskTxWrapper({
155
+ tx,
156
+ kioskClient: context.kioskClient,
157
+ kioskOwner: txData?.claimer,
158
+ kiosk: txData?.sellerKiosk,
159
+ shouldConvertToPersonalKiosk: true,
160
+ shouldAllowNftUnsharedKiosk: true,
161
+ sharedKioskState,
162
+ async runCommands(kioskTx) {
163
+ await addBluemoveClaimAcceptedBidNft({
164
+ ...txData,
165
+ suiClient: context.suiClient,
166
+ kioskTx,
167
+ });
168
+ },
169
+ });
170
+
171
+ continue;
172
+ }
173
+
174
+ if (useOldClaim) {
175
+ await kioskTxWrapper({
176
+ tx,
177
+ kioskClient: context.kioskClient,
178
+ kioskOwner: txData?.claimer,
179
+ kiosk: txData?.sellerKiosk,
180
+ shouldConvertToPersonalKiosk: true,
181
+ shouldAllowNftUnsharedKiosk: true,
182
+ sharedKioskState,
183
+ async runCommands(kioskTx) {
184
+ await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
185
+ },
186
+ });
187
+ } else {
188
+ await kioskTxWrapper({
189
+ tx,
190
+ kioskClient: context.kioskClient,
191
+ kioskOwner: txData?.claimer,
192
+ kiosk: txData?.sellerKiosk,
193
+ shouldConvertToPersonalKiosk: true,
194
+ shouldAssertNftInSharedKiosk: true,
195
+ sharedKioskState,
196
+ async runCommands(kioskTx) {
197
+ await addClaimAcceptedBidNftWithPurchaseCapTx({ ...txData, kioskTx });
198
+ },
199
+ });
200
+ }
201
+
202
+ continue;
203
+ }
204
+
205
+ // claim transferred nft
206
+ if (nft?.chain_state?.claimable_reason === 'offer-transfer') {
207
+ const txData: ClaimTransferredNftTx = {
208
+ tx,
209
+ suiClient: context.suiClient,
210
+ kioskClient: context.kioskClient,
211
+ transferPolicies,
212
+ claimer: walletAddress,
213
+ nftType,
214
+ nftTokenId: nft?.token_id,
215
+ sellerKiosk: nft?.chain_state?.kiosk_id,
216
+ seller: nft?.owner,
217
+ sharedKioskState,
218
+ };
219
+
220
+ if (useOldClaim) {
221
+ await kioskTxWrapper({
222
+ tx,
223
+ kioskClient: context.kioskClient,
224
+ kioskOwner: txData?.claimer,
225
+ kiosk: txData?.sellerKiosk,
226
+ kioskStrategy: 'exclude',
227
+ shouldConvertToPersonalKiosk: true,
228
+ shouldAllowNftUnsharedKiosk: true,
229
+ sharedKioskState,
230
+ async runCommands(kioskTx) {
231
+ await addClaimTransferredNftTx({ ...txData, kioskTx });
232
+ },
233
+ });
234
+ } else {
235
+ await kioskTxWrapper({
236
+ tx,
237
+ kioskClient: context.kioskClient,
238
+ kioskOwner: txData?.claimer,
239
+ kiosk: txData?.sellerKiosk,
240
+ kioskStrategy: 'exclude',
241
+ shouldConvertToPersonalKiosk: true,
242
+ shouldAllowNftUnsharedKiosk: true,
243
+ sharedKioskState,
244
+ async runCommands(kioskTx) {
245
+ await addClaimTransferredNftWithPurchaseCapTx({ ...txData, kioskTx });
246
+ },
247
+ });
248
+ }
249
+ }
250
+
251
+ // nftsForTracking.push({
252
+ // nftType,
253
+ // claimer: walletAddress,
254
+ // claimReason: nft?.chain_state?.claimable_reason,
255
+ // });
256
+ }
257
+
258
+ sharedKioskState?.kioskTx?.finalize();
259
+
260
+ // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && nftsForTracking.length > 0) {
261
+ // trackMethodCall({
262
+ // apiUser: context.apiUser,
263
+ // apiKey: context.apiKey,
264
+ // event: 'CLAIM_NFTS',
265
+ // items: nftsForTracking,
266
+ // });
267
+ // }
268
+
269
+ return Transaction.from(tx);
270
+ };
@@ -0,0 +1,36 @@
1
+ import { Transaction } from '@mysten/sui/transactions';
2
+ import { TRADEPORT_MULTI_BID_PACKAGE, TRADEPORT_MULTI_BID_STORE } from '../../constants';
3
+ import { updateMultiBid } from '../updateMultiBid/updateMultiBid';
4
+
5
+ export interface CreateMultiBid {
6
+ walletAddress: string;
7
+ name?: string;
8
+ amount?: bigint;
9
+ tx?: Transaction;
10
+ }
11
+
12
+ export async function createMultiBid({
13
+ walletAddress,
14
+ name,
15
+ amount,
16
+ tx: existingTx,
17
+ }: CreateMultiBid): Promise<{ multiBidChainId: any; tx: Transaction }> {
18
+ const tx = existingTx ?? new Transaction();
19
+
20
+ const multiBidChainId = tx.moveCall({
21
+ target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
22
+ arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.option('string', name)],
23
+ });
24
+
25
+ if (amount > 0n) {
26
+ await updateMultiBid({
27
+ walletAddress,
28
+ multiBidChainId,
29
+ amount,
30
+ name,
31
+ tx,
32
+ });
33
+ }
34
+
35
+ return { multiBidChainId, tx };
36
+ }
@@ -0,0 +1,210 @@
1
+ import {
2
+ ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK,
3
+ TRADEPORT_BENEFICIARY_ADDRESS,
4
+ TRADEPORT_LISTINGS_PACKAGE,
5
+ TRADEPORT_LISTINGS_STORE,
6
+ TRADEPORT_ORDERBOOK_STORE,
7
+ } from '../../constants';
8
+ import { getMarketFeePrice } from '../../helpers/getMarketFeePrice';
9
+ import { getSharedObjects } from '../../helpers/getSharedObjects';
10
+ import { hasNativeKioskTransferPolicyRules } from '../../helpers/hasTransferPolicyRules';
11
+ import { assertNftInSharedKiosk } from '../../helpers/kiosk/assertNftInSharedKiosk';
12
+ import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
13
+ import { takeAndBorrowNftFromKiosk } from '../../helpers/kiosk/takeAndBorrowNftFromKiosk';
14
+ import { depositItemIntoOBKiosk } from '../../helpers/originByte/depositNftIntoOBKiosk';
15
+ import { getOrCreateOBKiosk } from '../../helpers/originByte/getOrCreateOBKiosk';
16
+ import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
17
+ import { shareOriginByteKiosk } from '../../helpers/originByte/shareOriginByteKiosk';
18
+ import { normalizedNftType } from '../../utils/normalizeNftType';
19
+ import { validateMinFloorPrice } from '../../helpers/validateMinFloorPrice';
20
+ import { type ListNftTx } from './listNfts';
21
+
22
+ export async function addOriginByteListTx({
23
+ tx,
24
+ sharedObjects,
25
+ nftTokenId,
26
+ nftType,
27
+ seller,
28
+ listPrice,
29
+ collectionId,
30
+ sellerKiosk,
31
+ sharedKioskState,
32
+ }: ListNftTx) {
33
+ const { orderbook } = sharedObjects;
34
+
35
+ await assertNftInSharedKiosk({
36
+ kioskId: sellerKiosk,
37
+ walletAddress: seller,
38
+ sharedKioskState,
39
+ });
40
+
41
+ const { kiosk, isNewKiosk } = await getOrCreateOBKiosk({
42
+ tx,
43
+ address: seller,
44
+ kioskToUseIfExists: sellerKiosk,
45
+ sharedKioskState,
46
+ });
47
+
48
+ if (isNewKiosk) {
49
+ depositItemIntoOBKiosk({
50
+ tx,
51
+ kiosk: sellerKiosk,
52
+ nftTokenId,
53
+ nftType,
54
+ });
55
+ }
56
+
57
+ const marketFeePrice = getMarketFeePrice({ price: listPrice, collectionId });
58
+
59
+ tx.moveCall({
60
+ target:
61
+ '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::create_ask_with_commission',
62
+ arguments: [
63
+ tx.object(orderbook),
64
+ tx.object(kiosk),
65
+ tx.pure.u64(listPrice),
66
+ tx.pure.address(nftTokenId),
67
+ tx.pure.address(TRADEPORT_BENEFICIARY_ADDRESS),
68
+ tx.pure.u64(marketFeePrice),
69
+ ],
70
+ typeArguments: [nftType, '0x2::sui::SUI'],
71
+ });
72
+
73
+ if (isNewKiosk) {
74
+ shareOriginByteKiosk({ tx, kiosk });
75
+ }
76
+ }
77
+
78
+ export function addTradePortListTx({
79
+ tx,
80
+ nftTokenId,
81
+ borrowedItem,
82
+ nftType,
83
+ listPrice,
84
+ }: ListNftTx) {
85
+ tx.moveCall({
86
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::create_ob_listing_without_transfer_policy`,
87
+ arguments: [
88
+ tx.object(TRADEPORT_LISTINGS_STORE),
89
+ tx.object(TRADEPORT_ORDERBOOK_STORE),
90
+ borrowedItem ? tx.object(borrowedItem) : tx.object(nftTokenId),
91
+ tx.pure.u64(listPrice),
92
+ ],
93
+ typeArguments: [nftType],
94
+ });
95
+ }
96
+
97
+ export async function addKioskTradePortListTx({
98
+ tx,
99
+ kioskTx,
100
+ transferPolicies,
101
+ nftTokenId,
102
+ nftType,
103
+ listPrice,
104
+ seller,
105
+ }: ListNftTx) {
106
+ validateMinFloorPrice({ transferPolicies, listPrice });
107
+
108
+ tx.moveCall({
109
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::create_ob_listing_with_transfer_policy`,
110
+ arguments: [
111
+ tx.object(TRADEPORT_LISTINGS_STORE),
112
+ tx.object(TRADEPORT_ORDERBOOK_STORE),
113
+ tx.object(kioskTx.kiosk),
114
+ tx.object(kioskTx.kioskCap),
115
+ tx.pure.address(seller),
116
+ tx.pure.id(nftTokenId),
117
+ tx.pure.u64(listPrice),
118
+ ],
119
+ typeArguments: [nftType],
120
+ });
121
+ }
122
+
123
+ export async function addTradePortListTxHandler(txData: ListNftTx) {
124
+ // If NFT is an Origin Byte collection, create an Origin Byte listing
125
+ if (
126
+ isOriginByteCollection(txData?.transferPolicies) &&
127
+ !ORIGIN_BYTE_NFT_TYPES_MISSING_ORDERBOOK?.includes(normalizedNftType(txData?.nftType))
128
+ ) {
129
+ const sharedObjects = await getSharedObjects(txData?.nftType);
130
+ await addOriginByteListTx({ ...txData, sharedObjects });
131
+
132
+ return;
133
+ }
134
+
135
+ // If nft has no transfer policy rule but is inside a kiosk, take it out of the kiosk
136
+ if (
137
+ !hasNativeKioskTransferPolicyRules(txData?.transferPolicies) &&
138
+ txData?.sellerKiosk &&
139
+ txData?.nftType !==
140
+ '0xbf1431324a4a6eadd70e0ac6c5a16f36492f255ed4d011978b2cf34ad738efe6::day_one::DayOne'
141
+ ) {
142
+ return kioskTxWrapper({
143
+ tx: txData?.tx,
144
+ kioskClient: txData?.kioskClient,
145
+ kioskOwner: txData?.seller,
146
+ kiosk: txData?.sellerKiosk,
147
+ shouldAssertNftInSharedKiosk: true,
148
+ sharedKioskState: txData?.sharedKioskState,
149
+ shouldUseSharedKioskTx: false,
150
+ async runCommands(kioskTx) {
151
+ const borrowedItem = await takeAndBorrowNftFromKiosk({
152
+ tx: txData?.tx,
153
+ transferPolicies: txData?.transferPolicies,
154
+ kioskTx,
155
+ kioskClient: txData?.kioskClient,
156
+ nftTokenId: txData?.nftTokenId,
157
+ nftType: txData?.nftType,
158
+ suiClient: txData?.suiClient,
159
+ kioskOwner: txData?.seller,
160
+ });
161
+
162
+ addTradePortListTx({ ...txData, borrowedItem });
163
+ },
164
+ });
165
+ }
166
+
167
+ // If NFT is in a kiosk, create a kiosk listing
168
+ if (txData?.sellerKiosk) {
169
+ return kioskTxWrapper({
170
+ tx: txData?.tx,
171
+ kioskClient: txData?.kioskClient,
172
+ kioskOwner: txData?.seller,
173
+ kiosk: txData?.sellerKiosk,
174
+ shouldAssertNftInSharedKiosk: true,
175
+ sharedKioskState: txData?.sharedKioskState,
176
+ shouldUseSharedKioskTx: false,
177
+ async runCommands(kioskTx) {
178
+ await addKioskTradePortListTx({
179
+ ...txData,
180
+ kioskTx,
181
+ });
182
+ },
183
+ });
184
+ }
185
+
186
+ // If NFT is not in a kiosk, but nft type has a transfer policy rule, create kiosk and place NFT in kiosk first
187
+ if (!txData?.sellerKiosk && hasNativeKioskTransferPolicyRules(txData?.transferPolicies)) {
188
+ return kioskTxWrapper({
189
+ tx: txData?.tx,
190
+ kioskClient: txData?.kioskClient,
191
+ kioskOwner: txData?.seller,
192
+ kiosk: txData?.sellerKiosk,
193
+ sharedKioskState: txData?.sharedKioskState,
194
+ shouldUseSharedKioskTx: false,
195
+ async runCommands(kioskTx) {
196
+ kioskTx.place({
197
+ item: txData?.nftTokenId,
198
+ itemType: txData?.nftType,
199
+ });
200
+ await addKioskTradePortListTx({
201
+ ...txData,
202
+ kioskTx,
203
+ });
204
+ },
205
+ });
206
+ }
207
+
208
+ // Fallback to non-kiosk listing
209
+ addTradePortListTx(txData);
210
+ }
@@ -0,0 +1,87 @@
1
+ import { type KioskClient, type ObjectArgument } from '@mysten/kiosk';
2
+ import { type Transaction, type TransactionObjectArgument } from '@mysten/sui/transactions';
3
+ import {
4
+ BLUEMOVE_MARKET_CONFIG_OBJECT,
5
+ TOCEN_MARKETPLACE_OBJECT,
6
+ TRADEPORT_LISTINGS_PACKAGE,
7
+ TRADEPORT_LISTINGS_STORE,
8
+ TRADEPORT_ORDERBOOK_STORE,
9
+ } from '../../constants';
10
+ import { addTradePortListTx } from './addListTxs';
11
+ import { type SuiGrpcClient } from '@mysten/sui/grpc';
12
+
13
+ export type RelistNftTx = {
14
+ tx: Transaction;
15
+ suiClient: SuiGrpcClient;
16
+ kioskTx?: any;
17
+ kioskClient: KioskClient;
18
+ transferPolicies: any;
19
+ seller: string;
20
+ collectionId: string;
21
+ nftTokenId?: string;
22
+ borrowedItem?: ObjectArgument;
23
+ nftType: string;
24
+ listPrice: number;
25
+ listingNonce: string;
26
+ sellerKiosk: string;
27
+ };
28
+
29
+ export function addTradePortRelistTx({ tx, nftTokenId, nftType, listPrice }: RelistNftTx) {
30
+ tx.moveCall({
31
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::relist_ob_listing_without_transfer_policy`,
32
+ arguments: [
33
+ tx.object(TRADEPORT_LISTINGS_STORE),
34
+ tx.object(TRADEPORT_ORDERBOOK_STORE),
35
+ tx.pure.id(nftTokenId),
36
+ tx.pure.u64(listPrice),
37
+ ],
38
+ typeArguments: [nftType],
39
+ });
40
+ }
41
+
42
+ export async function addKioskTradePortRelistTx({
43
+ tx,
44
+ kioskTx,
45
+ nftTokenId,
46
+ nftType,
47
+ listPrice,
48
+ }: RelistNftTx) {
49
+ tx.moveCall({
50
+ target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::relist_ob_listing_with_transfer_policy`,
51
+ arguments: [
52
+ tx.object(TRADEPORT_LISTINGS_STORE),
53
+ tx.object(TRADEPORT_ORDERBOOK_STORE),
54
+ tx.object(kioskTx.kiosk),
55
+ tx.object(kioskTx.kioskCap),
56
+ tx.pure.id(nftTokenId),
57
+ tx.pure.u64(listPrice),
58
+ ],
59
+ typeArguments: [nftType],
60
+ });
61
+ }
62
+
63
+ export function addBlueMoveRelistTx(txData: RelistNftTx) {
64
+ const { tx, nftTokenId, nftType, listPrice } = txData;
65
+
66
+ const borrowedItem = tx.moveCall({
67
+ target:
68
+ '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist',
69
+ arguments: [tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT), tx.pure.address(nftTokenId)],
70
+ typeArguments: [nftType, nftType],
71
+ }) as TransactionObjectArgument;
72
+
73
+ addTradePortListTx({ ...txData, listPrice, borrowedItem });
74
+ }
75
+
76
+ export function addTocenRelistTx(txData: RelistNftTx) {
77
+ const { tx, nftTokenId, nftType, listPrice } = txData;
78
+
79
+ const borrowedItem = tx.moveCall({
80
+ target:
81
+ '0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::delist',
82
+ arguments: [tx.object(TOCEN_MARKETPLACE_OBJECT), tx.pure.address(nftTokenId)],
83
+ typeArguments: [nftType],
84
+ }) as any;
85
+
86
+ addTradePortListTx({ ...txData, listPrice, borrowedItem });
87
+ }