@tradeport/sui-trading-sdk 0.5.3 → 0.5.4

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,398 @@
1
+ import { type TransactionObjectInput } from '@mysten/sui/transactions';
2
+ import { normalizeSuiObjectId } from '@mysten/sui/utils';
3
+ import {
4
+ BLUEMOVE_CREATOR_CONFIG_OBJECT,
5
+ BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT,
6
+ BLUEMOVE_KIOSK_OFFER_COLLECTION_BIDDER_BAG,
7
+ BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT,
8
+ BLUEMOVE_MARKET_CONFIG_OBJECT,
9
+ BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT,
10
+ BLUEMOVE_ROYALTY_COLLECTION_OBJECT,
11
+ TOCEN_MARKETPLACE_OBJECT,
12
+ TRADEPORT_BIDDING_STORE,
13
+ } from '../../constants';
14
+ import { getRoyaltyRuleModule } from '../../helpers/getRoyaltyRuleModule';
15
+ import { getSharedObjects } from '../../helpers/getSharedObjects';
16
+ import { hasPersonalKioskRule } from '../../helpers/hasPersonalKioskRule';
17
+ import { hasNativeKioskTransferPolicyRules } from '../../helpers/hasTransferPolicyRules';
18
+ import { isSingleBid } from '../../helpers/isSIngleBid';
19
+ import { assertNftInSharedKiosk } from '../../helpers/kiosk/assertNftInSharedKiosk';
20
+ import { getRulePackageId } from '../../helpers/kiosk/getRulePackageId';
21
+ import { isBluemoveKioskBid } from '../../helpers/kiosk/isBluemoveKioskBid';
22
+ import { isTradePortKioskBid } from '../../helpers/kiosk/isTradePortKioskBid';
23
+ import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
24
+ import { takeAndBorrowNftFromKiosk } from '../../helpers/kiosk/takeAndBorrowNftFromKiosk';
25
+ import { confirmOBTranfer } from '../../helpers/originByte/confirmOBTranfer';
26
+ import { depositItemIntoOBKiosk } from '../../helpers/originByte/depositNftIntoOBKiosk';
27
+ import { getOrCreateOBKiosk } from '../../helpers/originByte/getOrCreateOBKiosk';
28
+ import { isOriginByteBid } from '../../helpers/originByte/isOriginByteBid';
29
+ import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
30
+ import { shareOriginByteKiosk } from '../../helpers/originByte/shareOriginByteKiosk';
31
+ import { getObjectType } from '../../helpers/rpc/getObjectType';
32
+ import {
33
+ addSingleBidAcceptNftBidTx,
34
+ addTradeportKioskAcceptNftBidTx,
35
+ } from '../acceptNftBids/addAcceptNftBidTxs';
36
+ import { addOriginByteUnlistTx } from '../unlistListings/addUnlistListingTxs';
37
+ import { type AcceptCollectionBidTx } from './acceptCollectionBid';
38
+
39
+ export function addTradeportAcceptCollectionBidTx({
40
+ tx,
41
+ sharedObjects,
42
+ nftTokenId,
43
+ nftType,
44
+ itemTakenOutOfNativeKiosk,
45
+ bidNonce,
46
+ }: AcceptCollectionBidTx) {
47
+ const { collection, royaltyStrategy } = sharedObjects ?? {};
48
+
49
+ if (collection && royaltyStrategy) {
50
+ tx.moveCall({
51
+ target:
52
+ '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::ob_accept_bid',
53
+ arguments: [
54
+ tx.object(TRADEPORT_BIDDING_STORE),
55
+ tx.pure.address(bidNonce),
56
+ itemTakenOutOfNativeKiosk ? tx.object(itemTakenOutOfNativeKiosk) : tx.object(nftTokenId),
57
+ tx.object(collection),
58
+ tx.object(royaltyStrategy),
59
+ ],
60
+ typeArguments: [nftType],
61
+ });
62
+ } else {
63
+ tx.moveCall({
64
+ target:
65
+ '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::accept_bid',
66
+ arguments: [
67
+ tx.object(TRADEPORT_BIDDING_STORE),
68
+ tx.pure.address(bidNonce),
69
+ itemTakenOutOfNativeKiosk ? tx.object(itemTakenOutOfNativeKiosk) : tx.object(nftTokenId),
70
+ ],
71
+ typeArguments: [nftType],
72
+ });
73
+ }
74
+ }
75
+
76
+ export const addTradeportKioskAcceptCollectionBidTx = async (txData: AcceptCollectionBidTx) => {
77
+ await addTradeportKioskAcceptNftBidTx(txData);
78
+ };
79
+
80
+ export async function addOriginByteAcceptCollectionBidTx(txData: AcceptCollectionBidTx) {
81
+ const {
82
+ tx,
83
+ sharedObjects,
84
+ sellerKiosk,
85
+ itemOwner,
86
+ nftTokenId,
87
+ nftType,
88
+ bidAmount,
89
+ bidNonce,
90
+ listingPrice,
91
+ } = txData;
92
+
93
+ await assertNftInSharedKiosk({
94
+ kioskId: sellerKiosk,
95
+ walletAddress: itemOwner,
96
+ });
97
+
98
+ if (listingPrice && listingPrice > 0) {
99
+ addOriginByteUnlistTx({
100
+ ...txData,
101
+ sharedObjects,
102
+ price: txData?.listingPrice,
103
+ });
104
+ }
105
+
106
+ const { kiosk, isNewKiosk } = await getOrCreateOBKiosk({
107
+ tx,
108
+ address: itemOwner,
109
+ kioskToUseIfExists: sellerKiosk,
110
+ });
111
+
112
+ if (isNewKiosk) {
113
+ depositItemIntoOBKiosk({
114
+ tx,
115
+ kiosk,
116
+ nftTokenId,
117
+ nftType,
118
+ });
119
+ }
120
+
121
+ const { orderbook } = sharedObjects;
122
+
123
+ const [tradeInfo] = tx.moveCall({
124
+ target:
125
+ '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::market_sell',
126
+ arguments: [
127
+ tx.object(orderbook),
128
+ tx.object(kiosk),
129
+ tx.pure.u64(bidAmount),
130
+ tx.object(nftTokenId),
131
+ ],
132
+ typeArguments: [nftType, '0x2::sui::SUI'],
133
+ });
134
+
135
+ const [id] = tx.moveCall({
136
+ target:
137
+ '0xa0bab69d913e5a0ce8b448235a08bcf4c42da45c50622743dc9cab2dc0dff30f::orderbook::trade_id',
138
+ arguments: [tx.object(tradeInfo)],
139
+ typeArguments: [],
140
+ });
141
+
142
+ const transferRequest = tx.moveCall({
143
+ target:
144
+ '0xa0bab69d913e5a0ce8b448235a08bcf4c42da45c50622743dc9cab2dc0dff30f::orderbook::finish_trade',
145
+ arguments: [tx.object(orderbook), tx.object(id), tx.object(kiosk), tx.object(bidNonce)],
146
+ typeArguments: [nftType, '0x2::sui::SUI'],
147
+ });
148
+
149
+ confirmOBTranfer({ tx, sharedObjects, transferRequest, nftType });
150
+
151
+ if (isNewKiosk) {
152
+ shareOriginByteKiosk({ tx, kiosk });
153
+ }
154
+ }
155
+
156
+ export function addBluemoveAcceptCollectionBidTx({
157
+ tx,
158
+ nftTokenId,
159
+ nftType,
160
+ bidNonce,
161
+ listingPrice,
162
+ itemTakenOutOfNativeKiosk,
163
+ }: AcceptCollectionBidTx) {
164
+ let unlistedItem: TransactionObjectInput;
165
+ if (listingPrice && listingPrice > 0) {
166
+ unlistedItem = tx.moveCall({
167
+ target:
168
+ '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist',
169
+ arguments: [tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT), tx.pure.address(nftTokenId)],
170
+ typeArguments: [nftType, nftType],
171
+ });
172
+ }
173
+
174
+ tx.moveCall({
175
+ target:
176
+ '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_collection::accept_offer_collection',
177
+ arguments: [
178
+ tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT),
179
+ tx.object(BLUEMOVE_ROYALTY_COLLECTION_OBJECT),
180
+ tx.object(BLUEMOVE_CREATOR_CONFIG_OBJECT),
181
+ tx.object(BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT),
182
+ tx.pure.u64(bidNonce),
183
+ itemTakenOutOfNativeKiosk
184
+ ? tx.object(itemTakenOutOfNativeKiosk)
185
+ : unlistedItem
186
+ ? tx.object(unlistedItem)
187
+ : tx.object(nftTokenId),
188
+ ],
189
+ typeArguments: [nftType],
190
+ });
191
+ }
192
+
193
+ export async function addBluemoveKioskAcceptCollectionBidTx({
194
+ tx,
195
+ kioskTx,
196
+ nftTokenId,
197
+ nftType,
198
+ bidNonce,
199
+ }: AcceptCollectionBidTx) {
200
+ tx.moveCall({
201
+ target:
202
+ '0xcc97b74ed95c8e8a3ed88050a898727dee37896da579fc400d482b64db6149ff::kiosk_offer_collection_v2::accept_offer_collection_v2',
203
+ arguments: [
204
+ tx.object(BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT),
205
+ tx.object(BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT),
206
+ tx.object(BLUEMOVE_KIOSK_OFFER_COLLECTION_BIDDER_BAG),
207
+ tx.pure.u64(bidNonce),
208
+ tx.object(kioskTx.kiosk),
209
+ tx.object(kioskTx.kioskCap),
210
+ tx.pure.address(nftTokenId),
211
+ ],
212
+ typeArguments: [nftType],
213
+ });
214
+ }
215
+
216
+ export function addTocenAcceptCollectionBidTx({
217
+ tx,
218
+ nftTokenId,
219
+ nftType,
220
+ bidAmount,
221
+ bidder,
222
+ }: AcceptCollectionBidTx) {
223
+ tx.moveCall({
224
+ target:
225
+ '0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::accept_offer_list',
226
+ arguments: [
227
+ tx.object(TOCEN_MARKETPLACE_OBJECT),
228
+ tx.pure.address(nftTokenId),
229
+ tx.pure.address(bidder),
230
+ tx.pure.u64(bidAmount),
231
+ ],
232
+ typeArguments: [nftType],
233
+ });
234
+ }
235
+
236
+ export async function addTradePortAcceptCollectionBidTxHandler(txData: AcceptCollectionBidTx) {
237
+ const bidType = await getObjectType({
238
+ suiClient: txData?.suiClient,
239
+ objectId: normalizeSuiObjectId(txData?.bidNonce),
240
+ });
241
+
242
+ if (isSingleBid(bidType)) {
243
+ await addSingleBidAcceptNftBidTx(txData);
244
+ return;
245
+ }
246
+
247
+ if (isOriginByteBid(bidType)) {
248
+ if (isOriginByteCollection(txData?.transferPolicies)) {
249
+ const sharedObjects = await getSharedObjects(txData?.nftType);
250
+ await addOriginByteAcceptCollectionBidTx({ ...txData, sharedObjects });
251
+
252
+ return;
253
+ }
254
+
255
+ throw new Error(
256
+ `You cannot accept an Origin Byte bid with a NFT outside of an Origin Byte kiosk. Nft Token Id: ${txData?.nftTokenId}`,
257
+ );
258
+ }
259
+
260
+ // If nft has no transfer policy rules but is inside a kiosk, take it out of the kiosk
261
+ if (!hasNativeKioskTransferPolicyRules(txData?.transferPolicies) && txData?.sellerKiosk) {
262
+ return kioskTxWrapper({
263
+ tx: txData?.tx,
264
+ kioskClient: txData?.kioskClient,
265
+ kioskOwner: txData?.seller,
266
+ kiosk: txData?.sellerKiosk,
267
+ shouldAssertNftInSharedKiosk: true,
268
+ sharedKioskState: txData?.sharedKioskState,
269
+ async runCommands(kioskTx) {
270
+ const borrowedItem = await takeAndBorrowNftFromKiosk({
271
+ tx: txData?.tx,
272
+ transferPolicies: txData?.transferPolicies,
273
+ kioskTx,
274
+ kioskClient: txData?.kioskClient,
275
+ nftTokenId: txData?.nftTokenId,
276
+ nftType: txData?.nftType,
277
+ suiClient: txData?.suiClient,
278
+ kioskOwner: txData?.seller,
279
+ });
280
+
281
+ addTradeportAcceptCollectionBidTx({ ...txData, itemTakenOutOfNativeKiosk: borrowedItem });
282
+ },
283
+ });
284
+ }
285
+
286
+ if (isTradePortKioskBid(bidType)) {
287
+ const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
288
+ const royaltyRulePackageId = await getRulePackageId({
289
+ transferPolicies: txData?.transferPolicies,
290
+ suiClient: txData?.suiClient,
291
+ nftType: txData?.nftType,
292
+ ruleType: 'royalty_rule',
293
+ kioskClient: txData?.kioskClient,
294
+ });
295
+
296
+ return kioskTxWrapper({
297
+ tx: txData?.tx,
298
+ kioskClient: txData?.kioskClient,
299
+ kioskOwner: txData?.itemOwner,
300
+ kiosk: txData?.sellerKiosk,
301
+ shouldConvertToPersonalKiosk: Boolean(hasPersonalKioskRule(txData?.transferPolicies)),
302
+ shouldAssertNftInSharedKiosk: true,
303
+ failIfNoKiosk: Boolean(txData?.sellerKiosk),
304
+ sharedKioskState: txData?.sharedKioskState,
305
+ async runCommands(kioskTx) {
306
+ if (hasNativeKioskTransferPolicyRules(txData?.transferPolicies) && !txData?.sellerKiosk) {
307
+ kioskTx.place({
308
+ item: txData?.nftTokenId,
309
+ itemType: txData?.nftType,
310
+ });
311
+ }
312
+
313
+ await addTradeportKioskAcceptCollectionBidTx({
314
+ ...txData,
315
+ kioskTx,
316
+ royaltyRulePackageId,
317
+ royaltyRuleModule,
318
+ });
319
+ },
320
+ });
321
+ }
322
+
323
+ const sharedObjects = await getSharedObjects(txData?.nftType);
324
+ addTradeportAcceptCollectionBidTx({ ...txData, sharedObjects });
325
+ }
326
+
327
+ export async function addBluemoveAcceptCollectionBidTxHandler(txData: AcceptCollectionBidTx) {
328
+ const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
329
+
330
+ if (isOriginByteBid(bidType)) {
331
+ if (isOriginByteCollection(txData?.transferPolicies)) {
332
+ const sharedObjects = await getSharedObjects(txData?.nftType);
333
+ await addOriginByteAcceptCollectionBidTx({ ...txData, sharedObjects });
334
+
335
+ return;
336
+ }
337
+
338
+ throw new Error(
339
+ `You cannot accept an Origin Byte bid with a NFT outside of an Origin Byte kiosk. Nft Token Id: ${txData?.nftTokenId}`,
340
+ );
341
+ }
342
+
343
+ if (isBluemoveKioskBid(txData?.bidNonce)) {
344
+ if (txData?.sellerKiosk) {
345
+ return kioskTxWrapper({
346
+ tx: txData?.tx,
347
+ kioskClient: txData?.kioskClient,
348
+ kioskOwner: txData?.itemOwner,
349
+ kiosk: txData?.sellerKiosk,
350
+ shouldAssertNftInSharedKiosk: true,
351
+ sharedKioskState: txData?.sharedKioskState,
352
+ async runCommands(kioskTx) {
353
+ await addBluemoveKioskAcceptCollectionBidTx({
354
+ ...txData,
355
+ kioskTx,
356
+ });
357
+ },
358
+ });
359
+ }
360
+
361
+ throw new Error(
362
+ `You cannot accept an Native Kiosk Bid with a NFT outside of a native kiosk. Nft Token Id: ${txData?.nftTokenId}`,
363
+ );
364
+ }
365
+
366
+ if (!isBluemoveKioskBid(txData?.bidNonce)) {
367
+ if (txData?.sellerKiosk) {
368
+ return kioskTxWrapper({
369
+ tx: txData?.tx,
370
+ kioskClient: txData?.kioskClient,
371
+ kioskOwner: txData?.itemOwner,
372
+ kiosk: txData?.sellerKiosk,
373
+ shouldAssertNftInSharedKiosk: true,
374
+ sharedKioskState: txData?.sharedKioskState,
375
+ async runCommands(kioskTx) {
376
+ const borrowedItem = await takeAndBorrowNftFromKiosk({
377
+ tx: txData?.tx,
378
+ transferPolicies: txData?.transferPolicies,
379
+ kioskTx,
380
+ kioskClient: txData?.kioskClient,
381
+ nftTokenId: txData?.nftTokenId,
382
+ nftType: txData?.nftType,
383
+ suiClient: txData?.suiClient,
384
+ kioskOwner: txData?.itemOwner,
385
+ });
386
+
387
+ addBluemoveAcceptCollectionBidTx({ ...txData, itemTakenOutOfNativeKiosk: borrowedItem });
388
+ },
389
+ });
390
+ }
391
+
392
+ addBluemoveAcceptCollectionBidTx(txData);
393
+ }
394
+ }
395
+
396
+ export function addTocenAcceptCollectionBidTxHandler(txData: AcceptCollectionBidTx) {
397
+ addTocenAcceptCollectionBidTx(txData);
398
+ }
@@ -0,0 +1,174 @@
1
+ import { type KioskClient, type KioskTransaction } 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
+ } from '../../constants';
9
+ import { gqlChainRequest } from '../../graphql/gqlChainRequest';
10
+ import { fetchBidsById } from '../../graphql/queries/fetchBidsById';
11
+ import { getNftType } from '../../helpers/getNftType';
12
+ import { getSharedObjects } from '../../helpers/getSharedObjects';
13
+ import { type SharedKioskState } from '../../helpers/kiosk/sharedKioskState.type';
14
+ import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
15
+ import {
16
+ addBluemoveAcceptNftBidTx,
17
+ addOriginByteAcceptNftBidTx,
18
+ addTradePortAcceptNftBidTxHandler,
19
+ } from './addAcceptNftBidTxs';
20
+
21
+ export type AcceptNftBidTx = {
22
+ tx: Transaction;
23
+ sharedObjects?: any;
24
+ transferPolicies: any;
25
+ suiClient: SuiGrpcClient;
26
+ kioskClient: KioskClient;
27
+ kioskTx?: any;
28
+ sharedKioskState?: SharedKioskState;
29
+ seller?: string;
30
+ bidNonce: string;
31
+ nftType: string;
32
+ nftTokenId: string;
33
+ itemOwner: string;
34
+ listingPrice: number;
35
+ bidAmount: number;
36
+ sellerKiosk: string;
37
+ isListedOnBluemove: boolean;
38
+ bidMarketName: string;
39
+ royaltyRulePackageId?: string;
40
+ royaltyRuleModule?: string;
41
+ shouldSplitRoyaltyFromUserGasCoins?: boolean;
42
+ beforeResolveKioskTransferRequest?: (coin: any, transferRequest: any) => void | Promise<void>;
43
+ multiBidId?: string;
44
+ };
45
+
46
+ export type AcceptNftBids = {
47
+ bidIds: string[];
48
+ walletAddress: string;
49
+ tx?: Transaction;
50
+ kioskTx?: KioskTransaction;
51
+ beforeResolveKioskTransferRequest?: (coin: any, transferRequest: any) => void | Promise<void>;
52
+ };
53
+
54
+ const ERROR_UNLIST_FIRST = 'Item must be unlisted first before you can accept a solo bid on it';
55
+
56
+ export const acceptNftBids = async (
57
+ {
58
+ bidIds,
59
+ walletAddress,
60
+ tx: existingTx,
61
+ kioskTx,
62
+ beforeResolveKioskTransferRequest,
63
+ }: AcceptNftBids,
64
+ context: RequestContext,
65
+ ): Promise<Transaction> => {
66
+ const res = await gqlChainRequest({
67
+ chain: 'sui',
68
+ query: fetchBidsById,
69
+ variables: { bidIds },
70
+ });
71
+
72
+ if (res?.bids?.length === 0) {
73
+ throw new Error('No bids found');
74
+ }
75
+
76
+ const bidsForTracking = [];
77
+ const tx = existingTx ?? new Transaction();
78
+
79
+ const sharedKioskState: SharedKioskState = {
80
+ kioskTx: kioskTx ?? undefined,
81
+ };
82
+
83
+ for (const bid of res.bids) {
84
+ if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
85
+ throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
86
+ }
87
+
88
+ if (addLeadingZerosAfter0x(bid?.bidder) === addLeadingZerosAfter0x(walletAddress)) {
89
+ throw new Error('Wallet cannot accept its own bid');
90
+ }
91
+
92
+ if (bid?.status !== 'active') {
93
+ throw new Error('Bid not active');
94
+ }
95
+
96
+ if (bid?.type !== 'solo') {
97
+ throw new Error('Bid is not an individual item bid. Use acceptCollectionBid() instead.');
98
+ }
99
+
100
+ const nftType = getNftType({
101
+ collectionId: bid?.collection?.id,
102
+ collectionChainState: bid?.collection?.chain_state,
103
+ nft: bid?.nft,
104
+ });
105
+
106
+ const transferPolicies = bid?.collection?.chain_state?.transfer_policies;
107
+
108
+ const txData: AcceptNftBidTx = {
109
+ tx,
110
+ kioskTx,
111
+ sharedKioskState,
112
+ transferPolicies,
113
+ suiClient: context.suiClient,
114
+ kioskClient: context.kioskClient,
115
+ bidNonce: bid?.nonce,
116
+ nftType,
117
+ listingPrice: bid?.nft?.listings?.[0]?.price,
118
+ nftTokenId: bid?.nft?.token_id,
119
+ itemOwner: bid?.nft?.owner,
120
+ bidAmount: bid?.price,
121
+ sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
122
+ seller: bid?.nft?.owner,
123
+ isListedOnBluemove: bid?.nft?.listings?.[0]?.market_name === 'bluemove',
124
+ bidMarketName: bid?.market_contract?.name,
125
+ multiBidId: bid?.multi_bid_id,
126
+ beforeResolveKioskTransferRequest,
127
+ };
128
+
129
+ switch (txData.bidMarketName) {
130
+ case 'tradeport':
131
+ if (txData?.listingPrice && txData?.listingPrice > 0) {
132
+ throw new Error(ERROR_UNLIST_FIRST);
133
+ }
134
+
135
+ await addTradePortAcceptNftBidTxHandler(txData);
136
+ break;
137
+ case 'clutchy':
138
+ case 'hyperspace':
139
+ case 'somis': {
140
+ const sharedObjects = await getSharedObjects(txData?.nftType);
141
+ await addOriginByteAcceptNftBidTx({ ...txData, sharedObjects });
142
+ break;
143
+ }
144
+
145
+ case 'bluemove':
146
+ addBluemoveAcceptNftBidTx(txData);
147
+ break;
148
+ default:
149
+ throw new Error('Marketplace not supported');
150
+ }
151
+
152
+ bidsForTracking.push({
153
+ nftType,
154
+ collectionId: bid?.nft?.collection_id,
155
+ bidAmount: bid?.price,
156
+ bidMarketName: bid?.market_contract?.name,
157
+ itemOwner: bid?.nft?.owner,
158
+ bidder: bid?.bidder,
159
+ });
160
+ }
161
+
162
+ sharedKioskState?.kioskTx?.finalize();
163
+
164
+ // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && bidsForTracking.length > 0) {
165
+ // trackMethodCall({
166
+ // apiUser: context.apiUser,
167
+ // apiKey: context.apiKey,
168
+ // event: 'ACCEPT_NFT_BIDS',
169
+ // items: bidsForTracking,
170
+ // });
171
+ // }
172
+
173
+ return Transaction.from(tx);
174
+ };