@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,438 +0,0 @@
1
- import { type TransactionArgument } from '@mysten/sui/transactions';
2
- import { normalizeSuiObjectId, SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
3
- import {
4
- BLUEMOVE_CREATOR_CONFIG_OBJECT,
5
- BLUEMOVE_MARKET_CONFIG_OBJECT,
6
- BLUEMOVE_OFFER_DATA_OBJECT,
7
- BLUEMOVE_ROYALTY_COLLECTION_OBJECT,
8
- TRADEPORT_BIDDING_STORE,
9
- TRADEPORT_KIOSK_BIDDING_STORE,
10
- TRADEPORT_MULTI_BID_PACKAGE,
11
- TRADEPORT_MULTI_BID_STORE,
12
- } from '../../constants';
13
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
14
- import { fetchMultibidChainIdById } from '../../graphql/queries/fetchMultibidById';
15
- import { getRoyaltyRuleModule } from '../../helpers/getRoyaltyRuleModule';
16
- import { getSharedObjects } from '../../helpers/getSharedObjects';
17
- import { getTransferPolicyRuleNamesFromSuiObject } from '../../helpers/getTransferPolicyRuleNamesFromSuiObject';
18
- import { hasPersonalKioskRule } from '../../helpers/hasPersonalKioskRule';
19
- import { hasNativeKioskTransferPolicyRules } from '../../helpers/hasTransferPolicyRules';
20
- import { isSingleBid } from '../../helpers/isSIngleBid';
21
- import { assertNftInSharedKiosk } from '../../helpers/kiosk/assertNftInSharedKiosk';
22
- import {
23
- getNativeKioskTransferPolicies,
24
- knownTransferPolicyRules,
25
- } from '../../helpers/kiosk/getNativeKioskTransferPolicies';
26
- import { getRulePackageId } from '../../helpers/kiosk/getRulePackageId';
27
- import { isTradePortKioskBid } from '../../helpers/kiosk/isTradePortKioskBid';
28
- import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
29
- import { lockNftInsideKioskIfNotLocked } from '../../helpers/kiosk/lockNftInsideKioskIfNotLocked';
30
- import {
31
- resolveCustomTransferPolicyRules,
32
- customTransferPolicyRuleNames,
33
- } from '../../helpers/kiosk/resolveCustomTransferPolicyRules';
34
- import { resolveTransferPolicies } from '../../helpers/kiosk/resolveTransferPolicies';
35
- import { confirmOBTranfer } from '../../helpers/originByte/confirmOBTranfer';
36
- import { getOBBidderKiosk } from '../../helpers/originByte/getOBBidderKiosk';
37
- import { isOriginByteBid } from '../../helpers/originByte/isOriginByteBid';
38
- import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
39
- import { getObjectType } from '../../helpers/rpc/getObjectType';
40
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
41
- import { type AcceptNftBidTx } from './acceptNftBids';
42
-
43
- export function addTradeportAcceptNftBidTx({
44
- tx,
45
- sharedObjects,
46
- bidNonce,
47
- nftTokenId,
48
- nftType,
49
- }: AcceptNftBidTx) {
50
- const { collection, royaltyStrategy } = sharedObjects;
51
-
52
- if (collection && royaltyStrategy) {
53
- tx.moveCall({
54
- target:
55
- '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::ob_accept_bid',
56
- arguments: [
57
- tx.object(TRADEPORT_BIDDING_STORE),
58
- tx.pure.address(bidNonce),
59
- tx.object(nftTokenId),
60
- tx.object(collection),
61
- tx.object(royaltyStrategy),
62
- ],
63
- typeArguments: [nftType],
64
- });
65
- } else {
66
- tx.moveCall({
67
- target:
68
- '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::accept_bid',
69
- arguments: [
70
- tx.object(TRADEPORT_BIDDING_STORE),
71
- tx.pure.address(bidNonce),
72
- tx.object(nftTokenId),
73
- ],
74
- typeArguments: [nftType],
75
- });
76
- }
77
- }
78
-
79
- export async function addTradeportKioskAcceptNftBidTx({
80
- tx,
81
- suiClient,
82
- kioskClient,
83
- transferPolicies,
84
- seller,
85
- kioskTx,
86
- bidNonce,
87
- nftTokenId,
88
- nftType,
89
- royaltyRulePackageId,
90
- royaltyRuleModule,
91
- bidAmount,
92
- shouldSplitRoyaltyFromUserGasCoins,
93
- beforeResolveKioskTransferRequest,
94
- }: AcceptNftBidTx) {
95
- const transferPolicyId = getNativeKioskTransferPolicies(transferPolicies)?.at(0)?.id;
96
-
97
- await lockNftInsideKioskIfNotLocked({
98
- tx,
99
- kioskClient,
100
- kioskTx,
101
- nftTokenId,
102
- nftType,
103
- transferPolicyId,
104
- });
105
-
106
- if (beforeResolveKioskTransferRequest) {
107
- const [feeCoin, transferRequest] = tx.moveCall({
108
- target:
109
- '0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_biddings::accept_bid_with_price_lock',
110
- arguments: [
111
- tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
112
- tx.pure.address(bidNonce),
113
- tx.object(kioskTx.kiosk),
114
- tx.object(kioskTx.kioskCap),
115
- tx.pure.address(nftTokenId),
116
- ],
117
- typeArguments: [nftType],
118
- });
119
-
120
- await beforeResolveKioskTransferRequest?.(feeCoin, transferRequest);
121
-
122
- await resolveTransferPolicies({
123
- tx,
124
- transferPolicies,
125
- suiClient,
126
- walletAddress: seller,
127
- kioskTx,
128
- kioskClient,
129
- nftType,
130
- price: bidAmount?.toString(),
131
- transferRequest,
132
- coinToSplit: feeCoin,
133
- shouldSkipKioskLocking: true,
134
- });
135
-
136
- tx.transferObjects([tx.object(feeCoin)], tx.pure.address(addLeadingZerosAfter0x(seller)));
137
- } else {
138
- const [feeCoin, transferRequest] = tx.moveCall({
139
- target:
140
- '0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_biddings::accept_bid_with_purchase_cap',
141
- arguments: [
142
- tx.object(TRADEPORT_KIOSK_BIDDING_STORE),
143
- tx.pure.address(bidNonce),
144
- tx.object(kioskTx.kiosk),
145
- tx.object(kioskTx.kioskCap),
146
- tx.pure.address(nftTokenId),
147
- ],
148
- typeArguments: [nftType],
149
- });
150
-
151
- if (!shouldSplitRoyaltyFromUserGasCoins) {
152
- tx.moveCall({
153
- target: `${royaltyRulePackageId}::${royaltyRuleModule}::pay`,
154
- typeArguments: [nftType],
155
- arguments: [tx.object(transferPolicyId), transferRequest, feeCoin],
156
- });
157
- }
158
-
159
- await resolveTransferPolicies({
160
- tx,
161
- transferPolicies,
162
- suiClient,
163
- walletAddress: seller,
164
- kioskTx,
165
- kioskClient,
166
- nftType,
167
- price: shouldSplitRoyaltyFromUserGasCoins ? bidAmount?.toString() : '0',
168
- transferRequest,
169
- shouldSkipKioskLocking: true,
170
- shouldSkipResolvingRoyaltyRule: !shouldSplitRoyaltyFromUserGasCoins,
171
- });
172
-
173
- if (shouldSplitRoyaltyFromUserGasCoins) {
174
- tx.transferObjects([tx.object(feeCoin)], tx.pure.address(addLeadingZerosAfter0x(seller)));
175
- }
176
- }
177
- }
178
-
179
- export async function addOriginByteAcceptNftBidTx({
180
- tx,
181
- suiClient,
182
- sharedObjects,
183
- sellerKiosk,
184
- bidNonce,
185
- nftTokenId,
186
- nftType,
187
- itemOwner,
188
- }: AcceptNftBidTx) {
189
- await assertNftInSharedKiosk({
190
- kioskId: sellerKiosk,
191
- walletAddress: itemOwner,
192
- });
193
-
194
- const receiverKiosk = await getOBBidderKiosk({ suiClient, bidNonce });
195
-
196
- let transferRequest: TransactionArgument;
197
- if (sellerKiosk) {
198
- transferRequest = tx.moveCall({
199
- target:
200
- '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::sell_nft_from_kiosk',
201
- arguments: [
202
- tx.object(bidNonce),
203
- tx.object(sellerKiosk),
204
- tx.object(receiverKiosk),
205
- tx.pure.address(nftTokenId),
206
- ],
207
- typeArguments: [nftType, '0x2::sui::SUI'],
208
- });
209
- } else {
210
- transferRequest = tx.moveCall({
211
- target:
212
- '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::sell_nft',
213
- arguments: [tx.object(bidNonce), tx.object(receiverKiosk), tx.object(nftTokenId)],
214
- typeArguments: [nftType, '0x2::sui::SUI'],
215
- });
216
- }
217
-
218
- confirmOBTranfer({ tx, sharedObjects, transferRequest, nftType });
219
- }
220
-
221
- export function addBluemoveAcceptNftBidTx({
222
- tx,
223
- nftTokenId,
224
- nftType,
225
- bidNonce,
226
- isListedOnBluemove,
227
- }: AcceptNftBidTx) {
228
- if (isListedOnBluemove) {
229
- tx.moveCall({
230
- target:
231
- '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist',
232
- arguments: [tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT), tx.pure.address(nftTokenId)],
233
- typeArguments: [nftType, nftType],
234
- });
235
- }
236
-
237
- tx.moveCall({
238
- target:
239
- '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_item::accept_offer_nft',
240
- arguments: [
241
- tx.object(BLUEMOVE_MARKET_CONFIG_OBJECT),
242
- tx.object(BLUEMOVE_ROYALTY_COLLECTION_OBJECT),
243
- tx.object(BLUEMOVE_CREATOR_CONFIG_OBJECT),
244
- tx.object(BLUEMOVE_OFFER_DATA_OBJECT),
245
- tx.pure.u64(bidNonce),
246
- isListedOnBluemove
247
- ? ({
248
- kind: 'Result',
249
- index: 0,
250
- } as any)
251
- : tx.object(nftTokenId),
252
- ],
253
- typeArguments: [nftType],
254
- });
255
- }
256
-
257
- export async function addSingleBidAcceptNftBidTx(txData: AcceptNftBidTx) {
258
- const { nftType, tx, bidNonce, multiBidId, nftTokenId, suiClient, sharedKioskState } = txData;
259
- const transferPolicies = getNativeKioskTransferPolicies(txData?.transferPolicies);
260
- const transferPolicy = transferPolicies?.find(
261
- (policy: { rules: any[] }) => policy?.rules?.length > 0,
262
- );
263
- const { chain_id: multiBidChainId, cancelled_at } = multiBidId
264
- ? ((
265
- await gqlChainRequest({
266
- chain: 'sui',
267
- query: fetchMultibidChainIdById,
268
- variables: { multiBidId },
269
- })
270
- )?.multi_bids?.[0] ?? {})
271
- : {};
272
-
273
- if (multiBidChainId && cancelled_at) {
274
- throw new Error(`MultiBid ${multiBidId} already cancelled`);
275
- }
276
-
277
- if (transferPolicy) {
278
- const allRules = await getTransferPolicyRuleNamesFromSuiObject({
279
- suiClient,
280
- transferPolicyId: transferPolicy.id,
281
- });
282
-
283
- const unsupportedRule = allRules.find((r) => {
284
- const moduleName = r.split('::').at(1);
285
- return (
286
- !knownTransferPolicyRules.includes(moduleName) &&
287
- !customTransferPolicyRuleNames.includes(moduleName)
288
- );
289
- });
290
- if (unsupportedRule) {
291
- throw new Error(
292
- `Found unsupported transfer policy rule ${unsupportedRule} for ${transferPolicy.id} of ${nftType}`,
293
- );
294
- }
295
-
296
- return kioskTxWrapper({
297
- tx: txData?.tx,
298
- kioskClient: txData?.kioskClient,
299
- kioskOwner: txData?.seller,
300
- kiosk: txData?.sellerKiosk,
301
- sharedKioskState,
302
- async runCommands(kioskTx) {
303
- if (!txData?.sellerKiosk) {
304
- kioskTx.place({
305
- item: txData?.nftTokenId,
306
- itemType: txData?.nftType,
307
- });
308
- }
309
-
310
- const [transferRequest] = tx.moveCall({
311
- target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::accept_bid_with_transfer_policy`,
312
- typeArguments: [nftType],
313
- arguments: [
314
- tx.object(SUI_CLOCK_OBJECT_ID),
315
- tx.object(TRADEPORT_MULTI_BID_STORE),
316
- tx.pure.id(normalizeSuiObjectId(bidNonce)),
317
- tx.pure.option('id', multiBidChainId),
318
- tx.object(kioskTx.getKiosk() as any),
319
- tx.object(kioskTx.getKioskCap() as any),
320
- tx.pure.id(nftTokenId),
321
- tx.object(transferPolicy.id),
322
- ],
323
- });
324
- // The contract resolves itself to the standard transfer policy rules
325
- // Resolve custom transfer policy rules (e.g. table_allowlist_rule)
326
- const customRules = allRules
327
- .filter((r) => customTransferPolicyRuleNames.includes(r.split('::').at(1)))
328
- .map((rule) => ({
329
- rule,
330
- rulePackageId: rule.split('::')[0],
331
- moduleName: rule.split('::')[1],
332
- }));
333
- if (customRules.length > 0) {
334
- resolveCustomTransferPolicyRules({
335
- tx,
336
- rules: customRules,
337
- transferRequest,
338
- nftType,
339
- policyId: transferPolicy.id,
340
- });
341
- }
342
-
343
- tx.moveCall({
344
- target: '0x2::transfer_policy::confirm_request',
345
- arguments: [tx.object(transferPolicy.id), transferRequest],
346
- typeArguments: [nftType],
347
- });
348
- },
349
- });
350
- }
351
-
352
- if (txData.sellerKiosk) {
353
- throw new Error(`Can't use NFT in kiosk without transfer policy`);
354
- }
355
-
356
- tx.moveCall({
357
- target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::accept_bid_without_transfer_policy`,
358
- typeArguments: [nftType],
359
- arguments: [
360
- tx.object(SUI_CLOCK_OBJECT_ID),
361
- tx.object(TRADEPORT_MULTI_BID_STORE),
362
- tx.pure.id(bidNonce),
363
- tx.pure.option('id', multiBidChainId),
364
- tx.object(nftTokenId),
365
- ],
366
- });
367
- }
368
-
369
- export async function addTradePortAcceptNftBidTxHandler(txData: AcceptNftBidTx) {
370
- const bidType = await getObjectType({
371
- suiClient: txData?.suiClient,
372
- objectId: normalizeSuiObjectId(txData?.bidNonce),
373
- });
374
-
375
- if (isSingleBid(bidType)) {
376
- await addSingleBidAcceptNftBidTx(txData);
377
- return;
378
- }
379
-
380
- if (isOriginByteBid(bidType)) {
381
- if (isOriginByteCollection(txData?.transferPolicies)) {
382
- const sharedObjects = await getSharedObjects(txData?.nftType);
383
- await addOriginByteAcceptNftBidTx({ ...txData, sharedObjects });
384
-
385
- return;
386
- }
387
-
388
- throw new Error(
389
- `You cannot accept an Origin Byte bid with a NFT outside of an Origin Byte kiosk. Nft Token Id: ${txData?.nftTokenId}`,
390
- );
391
- }
392
-
393
- if (isTradePortKioskBid(bidType)) {
394
- if (txData?.sellerKiosk) {
395
- const royaltyRuleModule = getRoyaltyRuleModule(txData?.nftType);
396
- const royaltyRulePackageId = await getRulePackageId({
397
- transferPolicies: txData?.transferPolicies,
398
- suiClient: txData?.suiClient,
399
- nftType: txData?.nftType,
400
- ruleType: 'royalty_rule',
401
- kioskClient: txData?.kioskClient,
402
- });
403
-
404
- return kioskTxWrapper({
405
- tx: txData?.tx,
406
- kioskClient: txData?.kioskClient,
407
- kioskOwner: txData?.itemOwner,
408
- kiosk: txData?.sellerKiosk,
409
- shouldConvertToPersonalKiosk: Boolean(hasPersonalKioskRule(txData?.transferPolicies)),
410
- shouldAssertNftInSharedKiosk: true,
411
- failIfNoKiosk: Boolean(txData?.sellerKiosk),
412
- sharedKioskState: txData?.sharedKioskState,
413
- async runCommands(kioskTx) {
414
- if (hasNativeKioskTransferPolicyRules(txData?.transferPolicies) && !txData?.sellerKiosk) {
415
- kioskTx.place({
416
- item: txData?.nftTokenId,
417
- itemType: txData?.nftType,
418
- });
419
- }
420
-
421
- await addTradeportKioskAcceptNftBidTx({
422
- ...txData,
423
- kioskTx,
424
- royaltyRulePackageId,
425
- royaltyRuleModule,
426
- });
427
- },
428
- });
429
- }
430
-
431
- throw new Error(
432
- `You cannot accept an Native Kiosk Bid with a NFT outside of a native kiosk. Nft Token Id: ${txData?.nftTokenId}`,
433
- );
434
- }
435
-
436
- const sharedObjects = await getSharedObjects(txData?.nftType);
437
- addTradeportAcceptNftBidTx({ ...txData, sharedObjects });
438
- }
@@ -1,55 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import {
3
- TRADEPORT_NFT_STRATEGY_PACKAGE_ID,
4
- TRADEPORT_NFT_STRATEGY_MANAGER_ID,
5
- TRADEPORT_POOL_REGISTRY_ID,
6
- TRADEPORT_POOL_VERSIONED_ID,
7
- } from '../../constants';
8
- import { getCollectionChainState } from '../../helpers/getCollectionChainState';
9
-
10
- export type ApplyFtStrategy = {
11
- collectionId: string;
12
- strategyFtType?: string;
13
- tx?: Transaction;
14
- collectionChainState?: Record<string, unknown>;
15
- };
16
-
17
- export async function applyFtStrategy({
18
- collectionId,
19
- strategyFtType,
20
- tx: existingTx,
21
- collectionChainState,
22
- }: ApplyFtStrategy): Promise<Transaction> {
23
- const tx = existingTx ?? new Transaction();
24
- const chainState = collectionChainState ?? (await getCollectionChainState(collectionId));
25
- const nftStrategies = (chainState?.nft_strategies ?? {}) as Record<
26
- string,
27
- Record<string, unknown>
28
- >;
29
- const nftStrategyKeys = Object.keys(nftStrategies);
30
- const nftType = chainState?.nft_type as string;
31
-
32
- if (nftStrategyKeys.length === 0) {
33
- throw new Error('No NFT strategies found for collection');
34
- }
35
-
36
- strategyFtType = strategyFtType ?? nftStrategyKeys[0];
37
-
38
- if (!nftStrategyKeys.includes(strategyFtType)) {
39
- throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
40
- }
41
-
42
- tx.moveCall({
43
- target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_ft_strategy`,
44
- typeArguments: [nftType, strategyFtType],
45
- arguments: [
46
- tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
47
- tx.object((nftStrategies[strategyFtType] as { kiosk_id: string }).kiosk_id),
48
- tx.object(TRADEPORT_POOL_REGISTRY_ID),
49
- tx.object(TRADEPORT_POOL_VERSIONED_ID),
50
- tx.object.clock(),
51
- ],
52
- });
53
-
54
- return tx;
55
- }
@@ -1,90 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import {
3
- TRADEPORT_NFT_STRATEGY_PACKAGE_ID,
4
- TRADEPORT_NFT_STRATEGY_MANAGER_ID,
5
- TRADEPORT_ORDERBOOK_STORE,
6
- TRADEPORT_LISTINGS_STORE,
7
- } from '../../constants';
8
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
9
- import { fetchCollectionFloorListingsForMarket } from '../../graphql/queries/fetchCollectionFloorListingForMarket';
10
- import { getNativeKioskTransferPolicies } from '../../helpers/kiosk/getNativeKioskTransferPolicies';
11
- import { RequestContext } from '../../SuiTradingClient';
12
- import { getCollectionChainState } from '../../helpers/getCollectionChainState';
13
-
14
- export type ApplyNftStrategy = {
15
- collectionId: string;
16
- strategyFtType?: string;
17
- tx?: Transaction;
18
- };
19
-
20
- export async function applyTradeportNftStrategy({
21
- collectionId,
22
- strategyFtType,
23
- tx: existingTx,
24
- }: ApplyNftStrategy): Promise<Transaction> {
25
- const tx = existingTx ?? new Transaction();
26
- const chainState = await getCollectionChainState(collectionId);
27
- const nftStrategies = (chainState?.nft_strategies ?? {}) as Record<
28
- string,
29
- Record<string, unknown>
30
- >;
31
- const nftStrategyKeys = Object.keys(nftStrategies);
32
- if (nftStrategyKeys.length === 0) {
33
- throw new Error('No NFT strategies found for collection');
34
- }
35
-
36
- strategyFtType = strategyFtType ?? nftStrategyKeys[0];
37
-
38
- if (!nftStrategyKeys.includes(strategyFtType)) {
39
- throw new Error(`Specified FT type ${strategyFtType} is not supported for this collection`);
40
- }
41
-
42
- const transferPolicy = getNativeKioskTransferPolicies(chainState?.transfer_policies ?? [])?.at(0);
43
-
44
- if (!transferPolicy) {
45
- throw new Error('No transfer policy found for collection');
46
- }
47
-
48
- const nftType = chainState?.nft_type as string;
49
- let suiBalance = BigInt(
50
- (nftStrategies[strategyFtType] as { sui_balance: string }).sui_balance ?? 0n,
51
- );
52
-
53
- const result = await gqlChainRequest({
54
- chain: 'sui',
55
- query: fetchCollectionFloorListingsForMarket,
56
- variables: {
57
- collectionId,
58
- marketAddress: TRADEPORT_NFT_STRATEGY_MANAGER_ID,
59
- totalPrice: suiBalance.toString(),
60
- },
61
- });
62
- if ((result?.listings?.length ?? 0) === 0) {
63
- throw new Error(
64
- `No floor listing found for collection with price bellow or equal to ${suiBalance} MIST`,
65
- );
66
- }
67
-
68
- for (const floorListing of result.listings) {
69
- suiBalance -= BigInt(floorListing.price);
70
- if (suiBalance < 0n) {
71
- break;
72
- }
73
-
74
- tx.moveCall({
75
- target: `${TRADEPORT_NFT_STRATEGY_PACKAGE_ID}::tradeport_nft_strategy::apply_tradeport_nft_strategy_confirm_request`,
76
- typeArguments: [nftType, strategyFtType],
77
- arguments: [
78
- tx.object(TRADEPORT_NFT_STRATEGY_MANAGER_ID),
79
- tx.object((nftStrategies[strategyFtType] as { kiosk_id: string }).kiosk_id),
80
- tx.object(TRADEPORT_LISTINGS_STORE),
81
- tx.object(TRADEPORT_ORDERBOOK_STORE),
82
- tx.object(floorListing.nft.delegated_owner),
83
- tx.object(floorListing.nft.token_id),
84
- tx.object(transferPolicy.id),
85
- ],
86
- });
87
- }
88
-
89
- return tx;
90
- }