@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,398 +0,0 @@
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
- }
@@ -1,174 +0,0 @@
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
- };