@tradeport/sui-trading-sdk 0.0.0

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 (103) hide show
  1. package/.babel.config.js +3 -0
  2. package/.env.demo +4 -0
  3. package/.eslintrc.json +46 -0
  4. package/.prettierignore +4 -0
  5. package/.prettierrc.json +7 -0
  6. package/README.md +1 -0
  7. package/dist/index.d.mts +90 -0
  8. package/dist/index.d.ts +90 -0
  9. package/dist/index.js +3760 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/index.mjs +3733 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/jest.config.js +7 -0
  14. package/package.json +45 -0
  15. package/src/SuiTradingClient.ts +158 -0
  16. package/src/apiClients/graphqlClient.ts +5 -0
  17. package/src/apiClients/kioskClient.ts +10 -0
  18. package/src/apiClients/suiClient.ts +5 -0
  19. package/src/constants.ts +74 -0
  20. package/src/graphql/createChainGQLQuery.ts +25 -0
  21. package/src/graphql/gqlChainRequest.ts +20 -0
  22. package/src/graphql/queries/fetchAccountKiosks.ts +12 -0
  23. package/src/graphql/queries/fetchBidsById.ts +28 -0
  24. package/src/graphql/queries/fetchCollectionBidById.ts +20 -0
  25. package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +28 -0
  26. package/src/graphql/queries/fetchCollectionsById.ts +30 -0
  27. package/src/graphql/queries/fetchCommissionByListingId.ts +13 -0
  28. package/src/graphql/queries/fetchCryptoToUsdRate.ts +13 -0
  29. package/src/graphql/queries/fetchKiosksByOwner.ts +13 -0
  30. package/src/graphql/queries/fetchListingsById.ts +24 -0
  31. package/src/graphql/queries/fetchListingsByNftId.ts +23 -0
  32. package/src/graphql/queries/fetchNftsById.ts +61 -0
  33. package/src/graphql/queries/fetchOwnerCapByKiosk.ts +10 -0
  34. package/src/graphql/queries/fetchPersonalCapByKiosk.ts +10 -0
  35. package/src/graphql/queries/fetchSharedObjectsByType.ts +12 -0
  36. package/src/graphql/queries/fetchTransferPoliciesByType.ts +12 -0
  37. package/src/graphql/queries/getCommissionByListingId.ts +15 -0
  38. package/src/helpers/addOneDollarFee.ts +17 -0
  39. package/src/helpers/addThirdPartyTxFee.ts +17 -0
  40. package/src/helpers/destroyZeroCoin.ts +14 -0
  41. package/src/helpers/getMarketFeePrice.ts +78 -0
  42. package/src/helpers/getNftTypeFromNft.ts +8 -0
  43. package/src/helpers/getSharedObjects.ts +113 -0
  44. package/src/helpers/getSuiToUsdRate.ts +17 -0
  45. package/src/helpers/getTradeportBiddingContractParsedBidAmount.ts +32 -0
  46. package/src/helpers/hasRoyaltyRule.ts +14 -0
  47. package/src/helpers/hasTransferPolicyRules.ts +21 -0
  48. package/src/helpers/isNonKioskListing.ts +7 -0
  49. package/src/helpers/kiosk/getRulePackageId.ts +26 -0
  50. package/src/helpers/kiosk/isBluemoveKioskBid.ts +1 -0
  51. package/src/helpers/kiosk/isTradePortKioskBid.ts +4 -0
  52. package/src/helpers/kiosk/kioskTxWrapper.ts +102 -0
  53. package/src/helpers/kiosk/resolveFloorPriceRule.ts +25 -0
  54. package/src/helpers/kiosk/resolveKioskLockRule.ts +49 -0
  55. package/src/helpers/kiosk/resolvePersonalKioskRule.ts +26 -0
  56. package/src/helpers/kiosk/resolveRoyaltyRule.ts +41 -0
  57. package/src/helpers/kiosk/resolveTransferPolicies.ts +150 -0
  58. package/src/helpers/originByte/confirmOBTranfer.ts +33 -0
  59. package/src/helpers/originByte/createOBKiosk.ts +14 -0
  60. package/src/helpers/originByte/depositNftIntoOBKiosk.ts +14 -0
  61. package/src/helpers/originByte/getOBBidderKiosk.ts +9 -0
  62. package/src/helpers/originByte/getOBKiosk.ts +24 -0
  63. package/src/helpers/originByte/getOrCreateOBKiosk.ts +37 -0
  64. package/src/helpers/originByte/isOBKiosk.ts +13 -0
  65. package/src/helpers/originByte/isOriginByteBid.ts +6 -0
  66. package/src/helpers/originByte/isOriginByteTx.ts +2 -0
  67. package/src/helpers/originByte/shareOriginByteKiosk.ts +14 -0
  68. package/src/helpers/rpc/getAcountBalance.ts +17 -0
  69. package/src/helpers/rpc/getObjectType.ts +10 -0
  70. package/src/helpers/splitCoins.ts +12 -0
  71. package/src/index.ts +3 -0
  72. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +119 -0
  73. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +359 -0
  74. package/src/methods/acceptNftBids/acceptNftBids.ts +100 -0
  75. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +214 -0
  76. package/src/methods/buyListings/addBuyListingTxs.ts +503 -0
  77. package/src/methods/buyListings/buyListings.ts +143 -0
  78. package/src/methods/claimNfts/addClaimNftsTxs.ts +104 -0
  79. package/src/methods/claimNfts/claimNfts.ts +139 -0
  80. package/src/methods/listNfts/addListTxs.ts +186 -0
  81. package/src/methods/listNfts/addRelistTxs.ts +79 -0
  82. package/src/methods/listNfts/listNfts.ts +80 -0
  83. package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +146 -0
  84. package/src/methods/placeCollectionBids/placeCollectionBids.ts +120 -0
  85. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +146 -0
  86. package/src/methods/placeNftBids/placeNftBids.ts +69 -0
  87. package/src/methods/relistNft/relistNft.ts +104 -0
  88. package/src/methods/removeCollectionBid/addRemoveCollectionBidTxs.ts +119 -0
  89. package/src/methods/removeCollectionBid/removeCollectionBid.ts +97 -0
  90. package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +84 -0
  91. package/src/methods/removeNftBids/removeNftBids.ts +80 -0
  92. package/src/methods/transferNfts/addTransferNftTx.ts +78 -0
  93. package/src/methods/transferNfts/transferNfts.ts +107 -0
  94. package/src/methods/unlistListings/addUnlistListingTxs.ts +258 -0
  95. package/src/methods/unlistListings/unlistListings.ts +108 -0
  96. package/src/methods/withdrawKioskProfits/withdrawKioskProfits.ts +25 -0
  97. package/src/tests/SuiWallet.ts +49 -0
  98. package/src/utils/addHexPrefix.ts +7 -0
  99. package/src/utils/addLeadingZerosAfter0x.ts +2 -0
  100. package/src/utils/parseSUI.ts +1 -0
  101. package/src/utils/printTxBlockTxs.ts +5 -0
  102. package/src/utils/toUint8Array.ts +12 -0
  103. package/tsconfig.json +14 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,3733 @@
1
+ // src/apiClients/graphqlClient.ts
2
+ import { GraphQLClient } from "graphql-request";
3
+ var graphqlClient = new GraphQLClient("https://api.indexer.xyz/graphql");
4
+ var graphqlClient_default = graphqlClient;
5
+
6
+ // src/apiClients/suiClient.ts
7
+ import { SuiClient } from "@mysten/sui.js/client";
8
+ var suiClient = new SuiClient({ url: "https://rpc-mainnet.suiscan.xyz/" });
9
+ var suiClient_default = suiClient;
10
+
11
+ // src/graphql/createChainGQLQuery.ts
12
+ import { gql } from "graphql-request";
13
+ function createChainGQLQuery({ chain, query }) {
14
+ const regex = /query\s+(\w+)\s*\((.*?)\)\s*{([\s\S]*)}/;
15
+ const matches = regex.exec(query);
16
+ if (!matches || matches.length !== 4) {
17
+ throw new Error("Invalid query string format");
18
+ }
19
+ const [, queryName, argsString, bodyString] = matches;
20
+ if (!argsString || !bodyString)
21
+ return "";
22
+ const args = argsString.trim().length ? `(${argsString.trim()})` : "";
23
+ const body = bodyString.trim();
24
+ const wrappedBody = `${chain} {
25
+ ${body}
26
+ }`;
27
+ return gql`query ${queryName}${args} {\n${wrappedBody}\n}`;
28
+ }
29
+
30
+ // src/graphql/gqlChainRequest.ts
31
+ var gqlChainRequest = async ({ chain, query, variables }) => {
32
+ if (!chain || !query) {
33
+ throw new Error("Missing required arguments");
34
+ }
35
+ const response = await graphqlClient_default.request(
36
+ createChainGQLQuery({ chain, query }),
37
+ variables
38
+ );
39
+ return response?.[chain];
40
+ };
41
+
42
+ // src/graphql/queries/fetchCollectionBidById.ts
43
+ import { gql as gql2 } from "graphql-request";
44
+ var fetchCollectionBidById = gql2`
45
+ query fetchCollectionBidById($bidId: uuid!) {
46
+ bids(where: { id: { _eq: $bidId } }) {
47
+ nonce
48
+ price
49
+ bidder
50
+ status
51
+ type
52
+ collection_id
53
+ contract {
54
+ properties
55
+ }
56
+ market_contract {
57
+ name
58
+ }
59
+ }
60
+ }
61
+ `;
62
+
63
+ // src/graphql/queries/fetchCollectionBidsAtSamePrice.ts
64
+ import { gql as gql3 } from "graphql-request";
65
+ var fetchCollectionBidsAtSamePrice = gql3`
66
+ query fetchCollectionBidsAtSamePrice($collectionId: uuid!, $price: numeric) {
67
+ bids(
68
+ where: {
69
+ collection_id: { _eq: $collectionId }
70
+ price: { _eq: $price }
71
+ status: { _eq: "active" }
72
+ type: { _eq: "collection" }
73
+ }
74
+ order_by: { price: desc }
75
+ ) {
76
+ nonce
77
+ price
78
+ bidder
79
+ status
80
+ type
81
+ collection_id
82
+ contract {
83
+ properties
84
+ }
85
+ market_contract {
86
+ name
87
+ }
88
+ }
89
+ }
90
+ `;
91
+
92
+ // src/methods/acceptCollectionBid/acceptCollectionBid.ts
93
+ import { TransactionBlock } from "@mysten/sui.js/transactions";
94
+
95
+ // src/graphql/queries/fetchNftsById.ts
96
+ import { gql as gql4 } from "graphql-request";
97
+ var fetchNftById = gql4`
98
+ query fetchNftById($nftId: uuid!) {
99
+ nfts(where: { id: { _eq: $nftId } }) {
100
+ id
101
+ token_id
102
+ collection_id
103
+ properties
104
+ chain_state
105
+ listed
106
+ owner
107
+ contract {
108
+ properties
109
+ }
110
+ listings(where: { listed: { _eq: true } }) {
111
+ price
112
+ nonce
113
+ market_name
114
+ }
115
+ }
116
+ }
117
+ `;
118
+ var fetchNftsById = gql4`
119
+ query fetchNftsById($nftIds: [uuid!]) {
120
+ nfts(where: { id: { _in: $nftIds } }) {
121
+ id
122
+ token_id
123
+ collection_id
124
+ properties
125
+ chain_state
126
+ listed
127
+ contract {
128
+ properties
129
+ }
130
+ }
131
+ }
132
+ `;
133
+ var fetchNftsWithListingsById = gql4`
134
+ query fetchNftsWithListingsById($nftIds: [uuid!]) {
135
+ nfts(where: { id: { _in: $nftIds } }) {
136
+ id
137
+ token_id
138
+ collection_id
139
+ properties
140
+ chain_state
141
+ listed
142
+ contract {
143
+ properties
144
+ }
145
+ listings(where: { listed: { _eq: true } }) {
146
+ listed
147
+ market_name
148
+ price
149
+ nonce
150
+ }
151
+ }
152
+ }
153
+ `;
154
+
155
+ // src/helpers/getNftTypeFromNft.ts
156
+ var getNftTypeFromNft = (nft) => {
157
+ let nftType = nft?.properties?.nft_type;
158
+ if (!nftType || nftType?.split("::")?.length <= 1) {
159
+ nftType = nft?.contract?.properties?.nft_type;
160
+ }
161
+ return nftType;
162
+ };
163
+
164
+ // src/constants.ts
165
+ var TRADEPORT_BENEFICIARY_ADDRESS = "0xbca3b5c01c8d1a93aed3a036feff45145518292dd3c1db1d67cc99a699a7b517";
166
+ var TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT = 0.03;
167
+ var TRADEPORT_THIRD_PARTY_FEE_DECIMAL_PERCENT = 5e-3;
168
+ var TRADEPORT_LISTING_STORE = "0x47cba0b6309a12ce39f9306e28b899ed4b3698bce4f4911fd0c58ff2329a2ff6";
169
+ var TRADEPORT_BIDDING_STORE = "0x3d3b0c6e616fdc1a45b2b73d022bc085448e78bd729d28081c7a340abb33cba1";
170
+ var TRADEPORT_KIOSK_LISTING_STORE = "0xbff3161b047fb8b727883838c09b08afa9e0dd0f5488bde9e99e80643da9b9e0";
171
+ var TRADEPORT_KIOSK_TRANSFERS_STORE = "0xe0f61b6915d3fd4ec8bbe4618514e2152a82841605bfa00cde22ace434153a1b";
172
+ var TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK = "0xa677dab85a93bd8d6845b6cc7914f3bbb334fef7fbcbe0e997b5f75b5922d106";
173
+ var TRADEPORT_KIOSK_BIDDING_STORE = "0x1e5e7f38e3a61d1d189506d0fc6b7e47e935a292d9e1b23c0f3f1c0f94227772";
174
+ var TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK = "0x151fbe627d3f8de855f424c879ea2176d89282185a4b9226a7157172dd2919cc";
175
+ var TRADEPORT_KIOSK_BID_NONCE_TYPE = "0xec175e537be9e48f75fa6929291de6454d2502f1091feb22c0d26a22821bbf28::kiosk_biddings::Bid";
176
+ var COLLECTION_IDS_WITH_ZERO_COMMISSION = [
177
+ ""
178
+ ];
179
+ var ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0xb9353bccfb7ad87b9195c6956b2ac81551350b104d5bfec9cf0ea6f5c467c6d1";
180
+ var STORKS_ORIGIN_BYTE_ALLOW_LIST = "0x2566a35b1703ea3a67dda8a4cd25a77382543a9faad15a1028eaa7592fbcd0ca";
181
+ var SUISHI_ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0xa9afd6ac0b5a68710992ebc145b9be4e764628dfffebbccb065ed891948f7d7c";
182
+ var FUDDIES_ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0x1ae174e8e2f238648d5fbef41e2b435b7285e678aa5e2e7db27f1be006ab242c";
183
+ var CRYPTOPEDIA_ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0x3bbe09ea50c49f58e2c4915bed1b19ffdce43e6a3763be44a4fdd8c5d8cb3f32";
184
+ var GNOMES_ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0xa830cf84682a597cdf3337bf1917492a0eea78a0135384060d675d4808daa318";
185
+ var SACABAM_ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0x6ec53faee01f3e193501b84e98a43915228faa2df3f070ef069f57d0ed7601ca";
186
+ var SUI_ECOSYSTEM_ORIGIN_BYTE_ALLOW_LIST_OBJECT = "0x86f62b145974165fa53a8ac167de61a0fd0f9f7206dc67ac118fb3ac63b80476";
187
+ var BLUEMOVE_MARKET_CONFIG_OBJECT = "0x09e24b156b08e7bc5272f9b731e93b80b458f0b79a5195eb81a471d514f1b1b8";
188
+ var BLUEMOVE_ROYALTY_COLLECTION_OBJECT = "0xbf471e4f38f76ed88f18e44f3dce2c27e03c1857d51ea17cd9b230b6d69b4bc1";
189
+ var BLUEMOVE_CREATOR_CONFIG_OBJECT = "0x6bdeb62b036f5f9c3f0587a0480e6dd75cb4e758660cf30b542c031fa394bb83";
190
+ var BLUEMOVE_OFFER_DATA_OBJECT = "0x4a8e6a4634e3dedae00ffe9f065351664ba32d7e9c2d26221a666ca380ea68b9";
191
+ var BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT = "0xd1def3ba244a0cb3d248cd3e72078cae869c05b4f03ccc9289998188b1d7b768";
192
+ var BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT = "0x7ffb33136bcf4a69fefd9b962c5e47f9213c79cf4f443dd2a39ab17a1424ba6f";
193
+ var BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT = "0xd29edb24787f6b128018de0a2a513cdf63a48f7c256ecad1186cba3c6a45cb55";
194
+ var BLUEMOVE_KIOSK_OFFER_COLLECTION_BIDDER_BAG = "0x15708d74504203a9620779583f8e63f2b5a599b28dd3a7d9063ab41e6fb75942";
195
+ var SOUFFL3_MARKETPLACE_OBJECT = "0x0ad62c9d9c5b06b60c1f2e7da6659f7408636c11392651444dfdc5f5930d5dce";
196
+ var SOUFFL3_VERSION_OBJECT = "0x2c012a80a7fab8fe025d3d5be531227ccebbaa86d85cb56d09d235b1f3209cef";
197
+ var SOUFFL3_EXTENSION_OBJECT = "0xa3e5b249961bae7270af1484687b7d924d6364476119f687564dba0530055e6f";
198
+ var SOUFFL3_GENERIC_BUY_METHOD_COLLECTIONS = [
199
+ "f7ccba9d-04f8-49c4-8e1f-d264b122584d",
200
+ "86a437d7-e073-4365-8455-a4f2d983f840",
201
+ "d8863069-7281-4809-b66c-30bb80d47967",
202
+ "f447de12-64f1-490a-b8e5-636d4e778a61",
203
+ "f6cf1905-8378-44c5-98aa-ef6b20d0a527",
204
+ "19569440-6dfb-42af-8189-59fff6fa9905"
205
+ ];
206
+ var KEEPSAKE_MARKETPLACE_OBJECT = "0x08f446892306164934c0622388d8220961a9d08bc143888b6c923bb97a179ea8";
207
+ var KEEPSAKE_MARKETPLACE_KIOSK = "0xfaf1b99c273737e914da13324ee1191f42346643083892d3f6f09a2d246967e5";
208
+ var TOCEN_MARKETPLACE_OBJECT = "0xb2b140b2841329320b66f92373a2683af7f9066472233effab03755270bcf65f";
209
+ var HYPERSPACE_TRANSFER_POLICY_TYPE = "0x9a84b6a7914aedd6741e73cc2ca23cbc77e22ed3c5f884c072a51868fedde45b::hyperspace::Hyperspace";
210
+ var HYPERSPACE_MP_TRANSFER_POLICY_TYPE = "0x9a84b6a7914aedd6741e73cc2ca23cbc77e22ed3c5f884c072a51868fedde45b::hyperspace_mp::Hyperspace_mp";
211
+ var NON_KIOSK_LISTING_NONCE_TYPE = "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::Listing";
212
+ var ORIGIN_BYTE_BID_NONCE_TYPE = "0x4e0629fa51a62b0c1d7c7b9fc89237ec5b6f630d7798ad3f06d820afb93a995a::bidding::Bid<0x2::sui::SUI>";
213
+ var MASC_ROYALTY_DECIMAL_PERCENT = 0.085;
214
+ var BASC_ROYALTY_DECIMAL_PERCENT = 0.055;
215
+ var DSL_LEGACY_ROYALTY_DECIMAL_PERCENT = 0.05;
216
+
217
+ // src/graphql/queries/fetchSharedObjectsByType.ts
218
+ import { gql as gql5 } from "graphql-request";
219
+ var fetchSharedObjectsByType = gql5`
220
+ query fetchSharedObjectsByType($type: String!) {
221
+ sharedObjects: shared_objects_by_type(type: $type) {
222
+ id
223
+ module
224
+ pkg
225
+ type
226
+ }
227
+ }
228
+ `;
229
+
230
+ // src/utils/addLeadingZerosAfter0x.ts
231
+ var addLeadingZerosAfter0x = (str) => `0x${str?.replace("0x", "").padStart(64, "0")}`;
232
+
233
+ // src/helpers/getSharedObjects.ts
234
+ var getSharedObjects = async (nftType) => {
235
+ const nftTypeSplit = nftType?.split("::");
236
+ if (nftTypeSplit?.[0])
237
+ nftTypeSplit[0] = addLeadingZerosAfter0x(nftTypeSplit[0]);
238
+ const res = await gqlChainRequest({
239
+ chain: "sui",
240
+ query: fetchSharedObjectsByType,
241
+ variables: { type: nftTypeSplit?.join("::") }
242
+ });
243
+ let allowList = res?.sharedObjects?.filter((object) => object?.module === "allowlist")?.[0]?.id;
244
+ if (!allowList)
245
+ allowList = ORIGIN_BYTE_ALLOW_LIST_OBJECT;
246
+ if (nftType === "0x5f1fa51a6d5c52df7dfe0ff7efaab7cc769d81e51cf208a424e455575aa1ed7a::stork::Stork") {
247
+ allowList = STORKS_ORIGIN_BYTE_ALLOW_LIST;
248
+ }
249
+ if (nftType === "0xf1681f601a1c021a0b4c8c8859d50917308fcbebfd19364c4e856ac670bb8496::suishi::Suishi") {
250
+ allowList = SUISHI_ORIGIN_BYTE_ALLOW_LIST_OBJECT;
251
+ }
252
+ if (nftType?.includes(
253
+ "ac176715abe5bcdaae627c5048958bbe320a8474f524674f3278e31af3c8b86b::fuddies::Fuddies"
254
+ )) {
255
+ allowList = FUDDIES_ORIGIN_BYTE_ALLOW_LIST_OBJECT;
256
+ }
257
+ if (nftType === "0x71bd3651e47a7590e607b976a332338e2230e995fa96de430703af537086b643::cryptopedia::Cryptopedia") {
258
+ allowList = CRYPTOPEDIA_ORIGIN_BYTE_ALLOW_LIST_OBJECT;
259
+ }
260
+ if (nftType === "0xe81341eba87d19f8d53ee237b3666cff6a74c9fd7a960cf5753af69bc7c6a221::gnomes::Gnome") {
261
+ allowList = GNOMES_ORIGIN_BYTE_ALLOW_LIST_OBJECT;
262
+ }
263
+ if (nftType === "0x7f481ffff2b72f3f1d9b70d5ad999d8b514a6281aa29aedbb6c537bd4b0d04ad::sacabam::Sacabam") {
264
+ allowList = SACABAM_ORIGIN_BYTE_ALLOW_LIST_OBJECT;
265
+ }
266
+ if (nftType === "0x5fe8e884960f6977f813d871a3d43049d72d19d4ad07819b979c06434f60af4d::mint::SuiEcosystemNFT") {
267
+ allowList = SUI_ECOSYSTEM_ORIGIN_BYTE_ALLOW_LIST_OBJECT;
268
+ }
269
+ let transferPolicy = res?.sharedObjects?.filter(
270
+ (object) => object?.module === "transfer_policy"
271
+ )?.[0]?.id;
272
+ if (nftTypeSplit?.join("::")?.includes("keepsake_nft::KEEPSAKE")) {
273
+ transferPolicy = res?.sharedObjects?.filter(
274
+ (object) => object?.type?.includes(
275
+ "0x02be8c4a1a3cea4d3255d870d367c87838a8cc2bfe4f216a6b67b153027087a7::transfer_policy::TransferPolicy"
276
+ )
277
+ )?.[0]?.id;
278
+ }
279
+ return {
280
+ orderbook: res?.sharedObjects?.filter((object) => object?.module === "orderbook")?.[0]?.id,
281
+ collection: res?.sharedObjects?.filter((object) => object?.module === "collection")?.[0]?.id,
282
+ marketplace: res?.sharedObjects?.filter((object) => object?.module === "marketplace")?.[0]?.id,
283
+ royaltyStrategy: res?.sharedObjects?.filter(
284
+ (object) => object?.module === "royalty_strategy_bps"
285
+ )?.[0]?.id,
286
+ keepsakeRoyaltyStrategy: res?.sharedObjects?.filter(
287
+ (object) => object?.module === "keepsake_royalties"
288
+ )?.[0]?.id,
289
+ transferPolicy,
290
+ allowList
291
+ };
292
+ };
293
+
294
+ // src/apiClients/kioskClient.ts
295
+ import { KioskClient, Network } from "@mysten/kiosk";
296
+ var kioskClient = new KioskClient({
297
+ // @ts-ignore
298
+ client: suiClient_default,
299
+ network: Network.MAINNET
300
+ });
301
+ var kioskClient_default = kioskClient;
302
+
303
+ // src/helpers/hasTransferPolicyRules.ts
304
+ var hasTransferPolicyRules = async (nftType) => {
305
+ const nftTypeSplit = nftType?.split("::");
306
+ if (nftTypeSplit?.[0])
307
+ nftTypeSplit[0] = addLeadingZerosAfter0x(nftTypeSplit[0]);
308
+ const res = await kioskClient_default.getTransferPolicies({ type: nftTypeSplit?.join("::") });
309
+ return res?.some((policy) => policy?.rules?.length > 0);
310
+ };
311
+
312
+ // src/helpers/kiosk/getRulePackageId.ts
313
+ import { getNormalizedRuleType } from "@mysten/kiosk";
314
+
315
+ // src/utils/addHexPrefix.ts
316
+ function addHexPrefix(input) {
317
+ if (input.startsWith("0x")) {
318
+ return input;
319
+ }
320
+ return "0x" + input;
321
+ }
322
+
323
+ // src/helpers/kiosk/getRulePackageId.ts
324
+ var getRulePackageId = async (nftType, ruleType) => {
325
+ const transferPolicies = await kioskClient_default.getTransferPolicies({
326
+ type: nftType
327
+ });
328
+ const rule = transferPolicies.flatMap((policy) => policy.rules).filter((rule2) => rule2?.split("::")?.[1] === ruleType)?.[0];
329
+ const ruleDefinition = kioskClient_default.rules.find(
330
+ (x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule)
331
+ );
332
+ let rulePackageId = ruleDefinition?.packageId;
333
+ if (!rulePackageId) {
334
+ rulePackageId = rule?.split("::")?.[0];
335
+ }
336
+ return addHexPrefix(rulePackageId);
337
+ };
338
+
339
+ // src/helpers/kiosk/isBluemoveKioskBid.ts
340
+ var isBluemoveKioskBid = (bidNonce) => bidNonce?.startsWith("10000");
341
+
342
+ // src/helpers/kiosk/isTradePortKioskBid.ts
343
+ var isTradePortKioskBid = (bidType) => bidType === TRADEPORT_KIOSK_BID_NONCE_TYPE;
344
+
345
+ // src/helpers/kiosk/kioskTxWrapper.ts
346
+ import { KioskTransaction } from "@mysten/kiosk";
347
+
348
+ // src/graphql/queries/fetchKiosksByOwner.ts
349
+ import { gql as gql6 } from "graphql-request";
350
+ var fetchKiosksByOwner = gql6`
351
+ query fetchKiosksByOwner($ownerAddress: String!) {
352
+ kiosks: kiosks_by_owner_address(owner_address: $ownerAddress) {
353
+ id
354
+ is_origin_byte
355
+ is_personal
356
+ owner_address
357
+ profits
358
+ }
359
+ }
360
+ `;
361
+
362
+ // src/graphql/queries/fetchOwnerCapByKiosk.ts
363
+ import { gql as gql7 } from "graphql-request";
364
+ var fetchOwnerCapByKiosk = gql7`
365
+ query fetchOwnerCapByKiosk($kioskId: String!) {
366
+ ownerCap: kiosk_owner_cap_by_kiosk(kiosk_id: $kioskId) {
367
+ id
368
+ kiosk_id
369
+ }
370
+ }
371
+ `;
372
+
373
+ // src/graphql/queries/fetchPersonalCapByKiosk.ts
374
+ import { gql as gql8 } from "graphql-request";
375
+ var fetchPersonalCapByKiosk = gql8`
376
+ query fetchPersonalCapByKiosk($kioskId: String!) {
377
+ personalCap: personal_kiosk_cap_by_kiosk(kiosk_id: $kioskId) {
378
+ id
379
+ kiosk_id
380
+ }
381
+ }
382
+ `;
383
+
384
+ // src/helpers/kiosk/kioskTxWrapper.ts
385
+ var kioskTxWrapper = async ({
386
+ txBlock,
387
+ kioskOwner,
388
+ kiosk,
389
+ tx,
390
+ shouldConvertToPersonalKiosk
391
+ }) => {
392
+ let kioskTx;
393
+ let kiosks = (await gqlChainRequest({
394
+ chain: "sui",
395
+ query: fetchKiosksByOwner,
396
+ variables: { ownerAddress: addLeadingZerosAfter0x(kioskOwner) }
397
+ })).kiosks ?? [];
398
+ kiosks = kiosks?.filter((k) => !k.is_origin_byte);
399
+ if (kiosk) {
400
+ const filteredKiosks = kiosks.filter((k) => k?.id === kiosk);
401
+ if (filteredKiosks.length > 0) {
402
+ kiosks = filteredKiosks;
403
+ }
404
+ }
405
+ const personalKiosk = kiosks.find((k) => k.is_personal);
406
+ if (personalKiosk) {
407
+ const personalKioskCapId = (await gqlChainRequest({
408
+ chain: "sui",
409
+ query: fetchPersonalCapByKiosk,
410
+ variables: { kioskId: personalKiosk.id }
411
+ })).personalCap.id;
412
+ kioskTx = new KioskTransaction({
413
+ transactionBlock: txBlock,
414
+ kioskClient: kioskClient_default,
415
+ cap: {
416
+ isPersonal: true,
417
+ objectId: personalKioskCapId,
418
+ kioskId: personalKiosk.id,
419
+ digest: "",
420
+ version: ""
421
+ }
422
+ });
423
+ } else if (kiosks.length > 0) {
424
+ const kioskCapId = (await gqlChainRequest({
425
+ chain: "sui",
426
+ query: fetchOwnerCapByKiosk,
427
+ variables: { kioskId: kiosks[0].id }
428
+ })).ownerCap?.id;
429
+ kioskTx = new KioskTransaction({
430
+ transactionBlock: txBlock,
431
+ kioskClient: kioskClient_default,
432
+ cap: {
433
+ isPersonal: false,
434
+ objectId: kioskCapId,
435
+ kioskId: kiosks[0].id,
436
+ digest: "",
437
+ version: ""
438
+ }
439
+ });
440
+ if (shouldConvertToPersonalKiosk) {
441
+ kioskTx.convertToPersonal(true);
442
+ }
443
+ } else {
444
+ kioskTx = new KioskTransaction({ transactionBlock: txBlock, kioskClient: kioskClient_default });
445
+ kioskTx.createPersonal(true);
446
+ }
447
+ await tx(kioskTx);
448
+ kioskTx.finalize();
449
+ };
450
+
451
+ // src/helpers/originByte/confirmOBTranfer.ts
452
+ var confirmOBTranfer = ({ txBlock, sharedObjects, transferRequest, nftType }) => {
453
+ txBlock.moveCall({
454
+ target: "0x6f42ec2355fcda5ebeee2399d901ae9f71cb214e640a45a0007f1f1cdf9f7b5e::transfer_allowlist::confirm_transfer",
455
+ arguments: [txBlock.object(sharedObjects?.allowList), txBlock.object(transferRequest)],
456
+ typeArguments: [nftType]
457
+ });
458
+ if (sharedObjects?.royaltyStrategy) {
459
+ txBlock.moveCall({
460
+ target: "0x6f42ec2355fcda5ebeee2399d901ae9f71cb214e640a45a0007f1f1cdf9f7b5e::royalty_strategy_bps::confirm_transfer",
461
+ arguments: [txBlock.object(sharedObjects?.royaltyStrategy), txBlock.object(transferRequest)],
462
+ typeArguments: [nftType, "0x2::sui::SUI"]
463
+ });
464
+ }
465
+ txBlock.moveCall({
466
+ target: "0xadf32ebafc587cc86e1e56e59f7b17c7e8cbeb3315193be63c6f73157d4e88b9::transfer_request::confirm",
467
+ arguments: [txBlock.object(transferRequest), txBlock.object(sharedObjects?.transferPolicy)],
468
+ typeArguments: [nftType, "0x2::sui::SUI"]
469
+ });
470
+ };
471
+
472
+ // src/helpers/originByte/depositNftIntoOBKiosk.ts
473
+ var depositItemIntoOBKiosk = ({ txBlock, kiosk, nftTokenId, nftType }) => {
474
+ txBlock.moveCall({
475
+ target: "0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::deposit",
476
+ arguments: [txBlock.object(kiosk), txBlock.pure(nftTokenId)],
477
+ typeArguments: [nftType]
478
+ });
479
+ };
480
+
481
+ // src/helpers/originByte/createOBKiosk.ts
482
+ var createOBKiosk = async ({ txBlock, createMethod = "new" }) => {
483
+ const [kiosk] = txBlock.moveCall({
484
+ target: `0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::${createMethod}`,
485
+ arguments: [],
486
+ typeArguments: []
487
+ });
488
+ return [kiosk];
489
+ };
490
+
491
+ // src/helpers/originByte/getOBKiosk.ts
492
+ import { gql as gql9 } from "graphql-request";
493
+ var fetchAccountKiosks = gql9`
494
+ query fetchAccountKiosks($accountAddress: String!) {
495
+ kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
496
+ id
497
+ is_origin_byte
498
+ owner_address
499
+ profits
500
+ }
501
+ }
502
+ `;
503
+ var getOBKiosk = async (accountAddress) => {
504
+ const res = await gqlChainRequest({
505
+ chain: "sui",
506
+ query: fetchAccountKiosks,
507
+ variables: { accountAddress: addLeadingZerosAfter0x(accountAddress) }
508
+ });
509
+ return res?.kiosks?.filter((kiosk) => kiosk?.is_origin_byte)?.[0]?.id;
510
+ };
511
+
512
+ // src/helpers/originByte/getOrCreateOBKiosk.ts
513
+ var getOrCreateOBKiosk = async ({
514
+ txBlock,
515
+ address,
516
+ kioskToUseIfExists,
517
+ createMethod
518
+ }) => {
519
+ if (kioskToUseIfExists) {
520
+ return {
521
+ kiosk: kioskToUseIfExists,
522
+ isNewKiosk: false
523
+ };
524
+ }
525
+ const existingKiosk = await getOBKiosk(address);
526
+ if (existingKiosk) {
527
+ return {
528
+ kiosk: existingKiosk,
529
+ isNewKiosk: false
530
+ };
531
+ }
532
+ const [newKiosk] = await createOBKiosk({ txBlock, createMethod });
533
+ return {
534
+ kiosk: newKiosk,
535
+ isNewKiosk: true
536
+ };
537
+ };
538
+
539
+ // src/helpers/originByte/isOriginByteBid.ts
540
+ var isOriginByteBid = (bidType) => bidType === ORIGIN_BYTE_BID_NONCE_TYPE || bidType === "0x2::Kiosk::Kiosk" || bidType === "0x2::kiosk::Kiosk";
541
+
542
+ // src/helpers/originByte/isOriginByteTx.ts
543
+ var isOriginByteTx = (sharedObjects) => Boolean(sharedObjects?.orderbook && sharedObjects?.collection);
544
+
545
+ // src/helpers/originByte/shareOriginByteKiosk.ts
546
+ var shareOriginByteKiosk = async ({ txBlock, kiosk }) => {
547
+ txBlock.moveCall({
548
+ target: "0x2::transfer::public_share_object",
549
+ arguments: [txBlock.object(kiosk)],
550
+ typeArguments: ["0x2::kiosk::Kiosk"]
551
+ });
552
+ };
553
+
554
+ // src/helpers/rpc/getObjectType.ts
555
+ var getObjectType = async (objectId) => {
556
+ try {
557
+ const res = await suiClient_default.getObject({ id: objectId, options: { showType: true } });
558
+ return res?.data?.type;
559
+ } catch (err) {
560
+ return "";
561
+ }
562
+ };
563
+
564
+ // src/helpers/kiosk/resolveTransferPolicies.ts
565
+ import { getNormalizedRuleType as getNormalizedRuleType2 } from "@mysten/kiosk";
566
+
567
+ // src/helpers/kiosk/resolveFloorPriceRule.ts
568
+ function resolveFloorPriceRule({
569
+ txBlock,
570
+ packageId,
571
+ nftType,
572
+ policyId,
573
+ transferRequest
574
+ }) {
575
+ txBlock.moveCall({
576
+ target: `${packageId}::floor_price_rule::prove`,
577
+ typeArguments: [nftType],
578
+ arguments: [txBlock.object(policyId), transferRequest]
579
+ });
580
+ }
581
+
582
+ // src/helpers/kiosk/resolveKioskLockRule.ts
583
+ function resolveKioskLockRule({
584
+ txBlock,
585
+ packageId,
586
+ policyId,
587
+ transferRequest,
588
+ nftType,
589
+ kiosk,
590
+ kioskCap,
591
+ kioskItem,
592
+ shouldSkipLocking
593
+ }) {
594
+ if (!kiosk || !kioskCap)
595
+ throw new Error("Missing Owned Kiosk or Owned Kiosk Cap");
596
+ if (!shouldSkipLocking) {
597
+ if (!kioskItem)
598
+ throw new Error("Missing Kiosk Item");
599
+ txBlock.moveCall({
600
+ target: "0x2::kiosk::lock",
601
+ typeArguments: [nftType],
602
+ arguments: [
603
+ txBlock.object(kiosk),
604
+ txBlock.object(kioskCap),
605
+ txBlock.object(policyId),
606
+ txBlock.object(kioskItem)
607
+ ]
608
+ });
609
+ }
610
+ txBlock.moveCall({
611
+ target: `${packageId}::kiosk_lock_rule::prove`,
612
+ typeArguments: [nftType],
613
+ arguments: [transferRequest, txBlock.object(kiosk)]
614
+ });
615
+ }
616
+
617
+ // src/helpers/kiosk/resolvePersonalKioskRule.ts
618
+ function resolvePersonalKioskRule({
619
+ txBlock,
620
+ packageId,
621
+ nftType,
622
+ kiosk,
623
+ transferRequest
624
+ }) {
625
+ if (!kiosk)
626
+ throw new Error("Missing owned Kiosk.");
627
+ txBlock.moveCall({
628
+ target: `${packageId}::personal_kiosk_rule::prove`,
629
+ typeArguments: [nftType],
630
+ arguments: [txBlock.object(kiosk), transferRequest]
631
+ });
632
+ }
633
+
634
+ // src/helpers/kiosk/resolveRoyaltyRule.ts
635
+ function resolveRoyaltyRule({
636
+ txBlock,
637
+ packageId,
638
+ moduleName,
639
+ policyId,
640
+ transferRequest,
641
+ nftType,
642
+ price,
643
+ priceObjectArgument
644
+ }) {
645
+ const [amount] = txBlock.moveCall({
646
+ target: `${packageId}::${moduleName}::fee_amount`,
647
+ typeArguments: [nftType],
648
+ arguments: [
649
+ txBlock.object(policyId),
650
+ priceObjectArgument ? txBlock.object(priceObjectArgument) : txBlock.pure(price || "0")
651
+ ]
652
+ });
653
+ const feeCoin = txBlock.splitCoins(txBlock.gas, [amount]);
654
+ txBlock.moveCall({
655
+ target: `${packageId}::${moduleName}::pay`,
656
+ typeArguments: [nftType],
657
+ arguments: [txBlock.object(policyId), transferRequest, feeCoin]
658
+ });
659
+ }
660
+
661
+ // src/helpers/kiosk/resolveTransferPolicies.ts
662
+ var resolveTransferPolicies = async ({
663
+ txBlock,
664
+ kioskTx,
665
+ nftType,
666
+ kioskToLockRuleProve,
667
+ kioskItem,
668
+ transferRequest,
669
+ customTransferPolicies,
670
+ price,
671
+ priceObjectArgument,
672
+ shouldSkipKioskLocking,
673
+ shouldSkipResolvingRoyaltyRule
674
+ }) => {
675
+ const transferPolicies = await kioskClient_default.getTransferPolicies({
676
+ type: nftType
677
+ });
678
+ let policies = transferPolicies.length > 0 ? [
679
+ {
680
+ data: transferPolicies[0],
681
+ transferRequest,
682
+ isCustom: false
683
+ }
684
+ ] : [];
685
+ if (customTransferPolicies) {
686
+ for (const customTransferPolicy of customTransferPolicies) {
687
+ const customPolicy = await kioskClient_default.getTransferPolicies({
688
+ type: customTransferPolicy?.type
689
+ });
690
+ policies = [
691
+ ...policies,
692
+ {
693
+ data: customPolicy[0],
694
+ transferRequest: customTransferPolicy?.transferRequest,
695
+ isCustom: true,
696
+ type: customTransferPolicy?.type
697
+ }
698
+ ];
699
+ }
700
+ }
701
+ let canTransferOutsideKiosk = true;
702
+ for (const policy of policies) {
703
+ for (const rule of policy.data.rules) {
704
+ const ruleDefinition = kioskClient_default.rules.find(
705
+ (x) => getNormalizedRuleType2(x.rule) === getNormalizedRuleType2(rule)
706
+ );
707
+ let rulePackageId = ruleDefinition?.packageId;
708
+ if (!rulePackageId) {
709
+ rulePackageId = rule?.split("::")?.[0];
710
+ }
711
+ switch (rule?.split("::")?.[1]) {
712
+ case "royalty_rule":
713
+ case "kiosk_royalty_rule":
714
+ if (shouldSkipResolvingRoyaltyRule)
715
+ break;
716
+ resolveRoyaltyRule({
717
+ txBlock,
718
+ packageId: rulePackageId,
719
+ moduleName: rule?.split("::")?.[1],
720
+ policyId: policy.data.id,
721
+ transferRequest: policy.transferRequest,
722
+ nftType: policy.isCustom && policy.type ? policy.type : nftType,
723
+ price,
724
+ priceObjectArgument
725
+ });
726
+ break;
727
+ case "kiosk_lock_rule":
728
+ canTransferOutsideKiosk = false;
729
+ resolveKioskLockRule({
730
+ txBlock,
731
+ packageId: rulePackageId,
732
+ policyId: policy.data.id,
733
+ transferRequest: policy.transferRequest,
734
+ nftType: policy.isCustom && policy.type ? policy.type : nftType,
735
+ kiosk: kioskToLockRuleProve ? kioskToLockRuleProve : kioskTx.kiosk,
736
+ kioskCap: kioskTx.kioskCap,
737
+ kioskItem,
738
+ shouldSkipLocking: shouldSkipKioskLocking
739
+ });
740
+ break;
741
+ case "personal_kiosk_rule":
742
+ resolvePersonalKioskRule({
743
+ txBlock,
744
+ packageId: rulePackageId,
745
+ nftType: policy.isCustom && policy.type ? policy.type : nftType,
746
+ kiosk: kioskTx.kiosk,
747
+ transferRequest: policy.transferRequest
748
+ });
749
+ break;
750
+ case "floor_price_rule":
751
+ resolveFloorPriceRule({
752
+ txBlock,
753
+ packageId: rulePackageId,
754
+ nftType: policy.isCustom && policy.type ? policy.type : nftType,
755
+ policyId: policy.data.id,
756
+ transferRequest: policy.transferRequest
757
+ });
758
+ break;
759
+ default:
760
+ throw new Error(`No resolver for the following rule: ${rule}.`);
761
+ }
762
+ }
763
+ txBlock.moveCall({
764
+ target: "0x2::transfer_policy::confirm_request",
765
+ arguments: [txBlock.object(policy.data.id), policy.transferRequest],
766
+ typeArguments: [policy.isCustom && policy.type ? policy.type : nftType]
767
+ });
768
+ }
769
+ if (canTransferOutsideKiosk && kioskItem) {
770
+ kioskTx.place({ itemType: nftType, item: kioskItem });
771
+ }
772
+ };
773
+
774
+ // src/helpers/originByte/getOBBidderKiosk.ts
775
+ var getOBBidderKiosk = async (bidNonce) => {
776
+ const bidObject = await suiClient_default.call("sui_getObject", [
777
+ bidNonce,
778
+ { showContent: true }
779
+ ]);
780
+ return bidObject.data?.content?.fields?.kiosk;
781
+ };
782
+
783
+ // src/methods/acceptNftBids/addAcceptNftBidTxs.ts
784
+ function addTradeportAcceptNftBidTx({
785
+ txBlock,
786
+ sharedObjects,
787
+ bidNonce,
788
+ nftTokenId,
789
+ nftType
790
+ }) {
791
+ const { collection, royaltyStrategy } = sharedObjects;
792
+ if (collection && royaltyStrategy) {
793
+ txBlock.moveCall({
794
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::ob_accept_bid",
795
+ arguments: [
796
+ txBlock.object(TRADEPORT_BIDDING_STORE),
797
+ txBlock.pure(bidNonce),
798
+ txBlock.pure(nftTokenId),
799
+ txBlock.object(collection),
800
+ txBlock.object(royaltyStrategy)
801
+ ],
802
+ typeArguments: [nftType]
803
+ });
804
+ } else {
805
+ txBlock.moveCall({
806
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::accept_bid",
807
+ arguments: [
808
+ txBlock.object(TRADEPORT_BIDDING_STORE),
809
+ txBlock.pure(bidNonce),
810
+ txBlock.pure(nftTokenId)
811
+ ],
812
+ typeArguments: [nftType]
813
+ });
814
+ }
815
+ }
816
+ async function addTradeportKioskAcceptNftBidTx({
817
+ txBlock,
818
+ sharedObjects,
819
+ kioskTx,
820
+ bidNonce,
821
+ nftTokenId,
822
+ nftType,
823
+ royaltyRulePackageId
824
+ }) {
825
+ const { transferPolicy } = sharedObjects;
826
+ const [feeCoin, transferRequest] = txBlock.moveCall({
827
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::accept_bid",
828
+ arguments: [
829
+ txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE),
830
+ txBlock.pure(bidNonce),
831
+ txBlock.object(TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK),
832
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
833
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
834
+ txBlock.pure(nftTokenId),
835
+ txBlock.object(transferPolicy)
836
+ ],
837
+ typeArguments: [nftType]
838
+ });
839
+ txBlock.moveCall({
840
+ target: `${royaltyRulePackageId}::royalty_rule::pay`,
841
+ typeArguments: [nftType],
842
+ arguments: [txBlock.object(transferPolicy), transferRequest, feeCoin]
843
+ });
844
+ await resolveTransferPolicies({
845
+ txBlock,
846
+ kioskTx,
847
+ nftType,
848
+ price: "0",
849
+ transferRequest,
850
+ kioskToLockRuleProve: TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK,
851
+ shouldSkipKioskLocking: true,
852
+ shouldSkipResolvingRoyaltyRule: true
853
+ });
854
+ }
855
+ async function addOriginByteAcceptNftBidTx({
856
+ txBlock,
857
+ sharedObjects,
858
+ sellerKiosk,
859
+ bidNonce,
860
+ nftTokenId,
861
+ nftType
862
+ }) {
863
+ const receiverKiosk = await getOBBidderKiosk(bidNonce);
864
+ let transferRequest;
865
+ if (sellerKiosk) {
866
+ transferRequest = txBlock.moveCall({
867
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::sell_nft_from_kiosk",
868
+ arguments: [
869
+ txBlock.object(bidNonce),
870
+ txBlock.object(sellerKiosk),
871
+ txBlock.object(receiverKiosk),
872
+ txBlock.pure(nftTokenId)
873
+ ],
874
+ typeArguments: [nftType, "0x2::sui::SUI"]
875
+ });
876
+ } else {
877
+ transferRequest = txBlock.moveCall({
878
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::sell_nft",
879
+ arguments: [
880
+ txBlock.object(bidNonce),
881
+ txBlock.object(receiverKiosk),
882
+ txBlock.pure(nftTokenId)
883
+ ],
884
+ typeArguments: [nftType, "0x2::sui::SUI"]
885
+ });
886
+ }
887
+ confirmOBTranfer({ txBlock, sharedObjects, transferRequest, nftType });
888
+ }
889
+ function addBluemoveAcceptNftBidTx({
890
+ txBlock,
891
+ nftTokenId,
892
+ nftType,
893
+ bidNonce,
894
+ isListedOnBluemove
895
+ }) {
896
+ if (isListedOnBluemove) {
897
+ txBlock.moveCall({
898
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist",
899
+ arguments: [txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT), txBlock.pure(nftTokenId)],
900
+ typeArguments: [nftType, nftType]
901
+ });
902
+ }
903
+ txBlock.moveCall({
904
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_item::accept_offer_nft",
905
+ arguments: [
906
+ txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT),
907
+ txBlock.object(BLUEMOVE_ROYALTY_COLLECTION_OBJECT),
908
+ txBlock.object(BLUEMOVE_CREATOR_CONFIG_OBJECT),
909
+ txBlock.object(BLUEMOVE_OFFER_DATA_OBJECT),
910
+ txBlock.pure(bidNonce),
911
+ isListedOnBluemove ? {
912
+ kind: "Result",
913
+ index: 0
914
+ } : txBlock.pure(nftTokenId)
915
+ ],
916
+ typeArguments: [nftType]
917
+ });
918
+ }
919
+ async function addTradePortAcceptNftBidTxHandler(txData) {
920
+ const bidType = await getObjectType(txData?.bidNonce);
921
+ if (isOriginByteBid(bidType)) {
922
+ if (isOriginByteTx(txData?.sharedObjects)) {
923
+ await addOriginByteAcceptNftBidTx(txData);
924
+ return;
925
+ }
926
+ throw new Error(
927
+ `You cannot accept an Origin Byte bid with a NFT outside of an Origin Byte kiosk. Nft Token Id: ${txData?.nftTokenId}`
928
+ );
929
+ }
930
+ if (isTradePortKioskBid(bidType)) {
931
+ if (txData?.sellerKiosk) {
932
+ const royaltyRulePackageId = await getRulePackageId(txData.nftType, "royalty_rule");
933
+ return kioskTxWrapper({
934
+ txBlock: txData?.txBlock,
935
+ kioskOwner: txData?.itemOwner,
936
+ kiosk: txData?.sellerKiosk,
937
+ async tx(kioskTx) {
938
+ await addTradeportKioskAcceptNftBidTx({
939
+ ...txData,
940
+ kioskTx,
941
+ royaltyRulePackageId
942
+ });
943
+ }
944
+ });
945
+ }
946
+ throw new Error(
947
+ `You cannot accept an Native Kiosk Bid with a NFT outside of a native kiosk. Nft Token Id: ${txData?.nftTokenId}`
948
+ );
949
+ }
950
+ addTradeportAcceptNftBidTx(txData);
951
+ }
952
+
953
+ // src/helpers/isNonKioskListing.ts
954
+ var isNonKioskListing = async (listingNonce) => {
955
+ const listingType = await getObjectType(listingNonce);
956
+ return listingType === NON_KIOSK_LISTING_NONCE_TYPE;
957
+ };
958
+
959
+ // src/helpers/splitCoins.ts
960
+ var splitCoins = ({ txBlock, amounts }) => {
961
+ const res = txBlock.splitCoins(txBlock.gas, amounts);
962
+ return res;
963
+ };
964
+
965
+ // src/methods/unlistListings/addUnlistListingTxs.ts
966
+ function addTradePortUnlistTx({ txBlock, listingNonce, nftType }) {
967
+ txBlock.moveCall({
968
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::unlist",
969
+ arguments: [txBlock.object(TRADEPORT_LISTING_STORE), txBlock.pure(listingNonce)],
970
+ typeArguments: [nftType]
971
+ });
972
+ }
973
+ async function addTradePortKioskUnlistTx({
974
+ txBlock,
975
+ kioskTx,
976
+ nftTokenId,
977
+ nftType
978
+ }) {
979
+ txBlock.moveCall({
980
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_listings::unlist",
981
+ arguments: [
982
+ txBlock.object(TRADEPORT_KIOSK_LISTING_STORE),
983
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
984
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
985
+ txBlock.pure(nftTokenId)
986
+ ],
987
+ typeArguments: [nftType]
988
+ });
989
+ }
990
+ function addOriginByteUnlistTx({
991
+ txBlock,
992
+ sharedObjects,
993
+ listingNonce,
994
+ price,
995
+ nftTokenId,
996
+ nftType
997
+ }) {
998
+ const { orderbook } = sharedObjects;
999
+ txBlock.moveCall({
1000
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::cancel_ask",
1001
+ arguments: [
1002
+ txBlock.object(orderbook),
1003
+ txBlock.object(listingNonce),
1004
+ txBlock.pure(price),
1005
+ txBlock.pure(nftTokenId)
1006
+ ],
1007
+ typeArguments: [nftType, "0x2::sui::SUI"]
1008
+ });
1009
+ }
1010
+ function addSouffl3UnlistTx({ txBlock, listingNonce, nftType }) {
1011
+ txBlock.moveCall({
1012
+ target: "0x30d90b5b67be77e6e06f02dae9f0f2fcdad16e38854316ae8a7b4f5b4971f5e0::Market::delist_generic",
1013
+ arguments: [txBlock.object(SOUFFL3_VERSION_OBJECT), txBlock.pure(listingNonce)],
1014
+ typeArguments: [nftType, "0x2::sui::SUI"]
1015
+ });
1016
+ }
1017
+ function addBluemoveUnlistTx({ txBlock, nftTokenId, nftType }) {
1018
+ txBlock.moveCall({
1019
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist_and_take",
1020
+ arguments: [txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT), txBlock.pure(nftTokenId)],
1021
+ typeArguments: [nftType, nftType]
1022
+ });
1023
+ }
1024
+ async function addBluemoveKioskUnlistTx({
1025
+ txBlock,
1026
+ kioskTx,
1027
+ nftTokenId,
1028
+ nftType
1029
+ }) {
1030
+ txBlock.moveCall({
1031
+ target: "0x2949e130ca4dabfe6448173758468a3e45ea3f070e3264f112b51c023f3ecf9f::kiosk_trade::kiosk_delist",
1032
+ arguments: [
1033
+ txBlock.object(BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT),
1034
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
1035
+ txBlock.pure(nftTokenId)
1036
+ ],
1037
+ typeArguments: [nftType]
1038
+ });
1039
+ }
1040
+ function addKeepsakeUnlistTx({ txBlock, nftTokenId, nftType }) {
1041
+ txBlock.moveCall({
1042
+ target: "0x2be8c4a1a3cea4d3255d870d367c87838a8cc2bfe4f216a6b67b153027087a7::keepsake_marketplace::delist_and_take",
1043
+ arguments: [
1044
+ txBlock.object(KEEPSAKE_MARKETPLACE_OBJECT),
1045
+ txBlock.object(KEEPSAKE_MARKETPLACE_KIOSK),
1046
+ txBlock.pure(nftTokenId)
1047
+ ],
1048
+ typeArguments: [nftType]
1049
+ });
1050
+ }
1051
+ async function addHyperspaceKioskUnlistTx({
1052
+ txBlock,
1053
+ kioskTx,
1054
+ nftTokenId,
1055
+ nftType
1056
+ }) {
1057
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(1)] });
1058
+ txBlock.moveCall({
1059
+ target: "0x6ea97b03c441edd54ae89224bf9560e583ee66c37e6c246f5db35258e580ba94::hyperspace::delist",
1060
+ arguments: [
1061
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
1062
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
1063
+ txBlock.pure(nftTokenId)
1064
+ ],
1065
+ typeArguments: [nftType, HYPERSPACE_MP_TRANSFER_POLICY_TYPE]
1066
+ });
1067
+ txBlock.transferObjects([txBlock.object(coin)], txBlock.pure(nftTokenId));
1068
+ }
1069
+ function addTocenUnlistTx({ txBlock, nftTokenId, nftType }) {
1070
+ txBlock.moveCall({
1071
+ target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::delist_and_take",
1072
+ arguments: [txBlock.pure(TOCEN_MARKETPLACE_OBJECT), txBlock.pure(nftTokenId)],
1073
+ typeArguments: [nftType]
1074
+ });
1075
+ }
1076
+ function addSomisUnlistTx({
1077
+ txBlock,
1078
+ sharedObjects,
1079
+ nftTokenId,
1080
+ nftType,
1081
+ price
1082
+ }) {
1083
+ const { marketplace } = sharedObjects;
1084
+ txBlock.moveCall({
1085
+ target: "0xf0b0beb956e26bde50dbd6ac393026c4525aee3b194a9478f09748f7211b5a02::marketplace::cancel_ask",
1086
+ arguments: [txBlock.pure(marketplace), txBlock.pure(nftTokenId), txBlock.pure(price)],
1087
+ typeArguments: [nftType, "0x2::sui::SUI"]
1088
+ });
1089
+ }
1090
+ async function addTradePortUnlistTxHandler(txData) {
1091
+ if (txData?.listingNonce && isOriginByteTx(txData?.sharedObjects)) {
1092
+ addOriginByteUnlistTx(txData);
1093
+ return;
1094
+ }
1095
+ if (txData?.listingNonce && await isNonKioskListing(txData?.listingNonce)) {
1096
+ addTradePortUnlistTx(txData);
1097
+ return;
1098
+ }
1099
+ if (txData?.sellerKiosk) {
1100
+ return kioskTxWrapper({
1101
+ txBlock: txData?.txBlock,
1102
+ kioskOwner: txData?.seller,
1103
+ kiosk: txData?.sellerKiosk,
1104
+ async tx(kioskTx) {
1105
+ await addTradePortKioskUnlistTx({
1106
+ ...txData,
1107
+ kioskTx
1108
+ });
1109
+ }
1110
+ });
1111
+ }
1112
+ addTradePortUnlistTx(txData);
1113
+ }
1114
+ async function addHyperspaceUnlistTxHandler(txData) {
1115
+ if (txData?.listingNonce && isOriginByteTx(txData?.sharedObjects)) {
1116
+ addOriginByteUnlistTx(txData);
1117
+ return;
1118
+ }
1119
+ return kioskTxWrapper({
1120
+ txBlock: txData?.txBlock,
1121
+ kioskOwner: txData?.seller,
1122
+ kiosk: txData?.sellerKiosk,
1123
+ async tx(kioskTx) {
1124
+ await addHyperspaceKioskUnlistTx({
1125
+ ...txData,
1126
+ kioskTx
1127
+ });
1128
+ }
1129
+ });
1130
+ }
1131
+ async function addBluemoveUnlistTxHandler(txData) {
1132
+ if (txData?.listingNonce && isOriginByteTx(txData?.sharedObjects)) {
1133
+ addOriginByteUnlistTx(txData);
1134
+ return;
1135
+ }
1136
+ if (txData?.sellerKiosk) {
1137
+ return kioskTxWrapper({
1138
+ txBlock: txData?.txBlock,
1139
+ kioskOwner: txData?.seller,
1140
+ kiosk: txData?.sellerKiosk,
1141
+ async tx(kioskTx) {
1142
+ await addBluemoveKioskUnlistTx({
1143
+ ...txData,
1144
+ kioskTx
1145
+ });
1146
+ }
1147
+ });
1148
+ }
1149
+ addBluemoveUnlistTx(txData);
1150
+ }
1151
+ async function addClutchyUnlistTxHandler(txData) {
1152
+ addOriginByteUnlistTx(txData);
1153
+ }
1154
+ async function addSouffl3UnlistTxHandler(txData) {
1155
+ addSouffl3UnlistTx(txData);
1156
+ }
1157
+ async function addSomisUnlistTxHandler(txData) {
1158
+ if (txData?.sharedObjects?.marketplace) {
1159
+ addSomisUnlistTx(txData);
1160
+ return;
1161
+ }
1162
+ addOriginByteUnlistTx(txData);
1163
+ }
1164
+ async function addKeepsakeUnlistTxHandler(txData) {
1165
+ addKeepsakeUnlistTx(txData);
1166
+ }
1167
+ function addTocenUnlistTxHandler(txData) {
1168
+ addTocenUnlistTx(txData);
1169
+ }
1170
+
1171
+ // src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts
1172
+ function addTradeportAcceptCollectionBidTx({
1173
+ txBlock,
1174
+ sharedObjects,
1175
+ nftTokenId,
1176
+ nftType,
1177
+ itemTakenOutOfNativeKiosk,
1178
+ bidNonce
1179
+ }) {
1180
+ const { collection, royaltyStrategy } = sharedObjects;
1181
+ if (collection && royaltyStrategy) {
1182
+ txBlock.moveCall({
1183
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::ob_accept_bid",
1184
+ arguments: [
1185
+ txBlock.object(TRADEPORT_BIDDING_STORE),
1186
+ txBlock.pure(bidNonce),
1187
+ itemTakenOutOfNativeKiosk ? txBlock.object(itemTakenOutOfNativeKiosk) : txBlock.pure(nftTokenId),
1188
+ txBlock.object(collection),
1189
+ txBlock.object(royaltyStrategy)
1190
+ ],
1191
+ typeArguments: [nftType]
1192
+ });
1193
+ } else {
1194
+ txBlock.moveCall({
1195
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::accept_bid",
1196
+ arguments: [
1197
+ txBlock.object(TRADEPORT_BIDDING_STORE),
1198
+ txBlock.pure(bidNonce),
1199
+ itemTakenOutOfNativeKiosk ? txBlock.object(itemTakenOutOfNativeKiosk) : txBlock.pure(nftTokenId)
1200
+ ],
1201
+ typeArguments: [nftType]
1202
+ });
1203
+ }
1204
+ }
1205
+ var addTradeportKioskAcceptCollectionBidTx = async (txData) => {
1206
+ await addTradeportKioskAcceptNftBidTx(txData);
1207
+ };
1208
+ async function addOriginByteAcceptCollectionBidTx(txData) {
1209
+ const {
1210
+ txBlock,
1211
+ sharedObjects,
1212
+ sellerKiosk,
1213
+ itemOwner,
1214
+ nftTokenId,
1215
+ nftType,
1216
+ bidAmount,
1217
+ bidNonce,
1218
+ listingPrice
1219
+ } = txData;
1220
+ if (listingPrice && listingPrice > 0) {
1221
+ addOriginByteUnlistTx({
1222
+ ...txData,
1223
+ price: txData?.listingPrice
1224
+ });
1225
+ }
1226
+ const { kiosk, isNewKiosk } = await getOrCreateOBKiosk({
1227
+ txBlock,
1228
+ address: itemOwner,
1229
+ kioskToUseIfExists: sellerKiosk
1230
+ });
1231
+ if (isNewKiosk) {
1232
+ depositItemIntoOBKiosk({
1233
+ txBlock,
1234
+ kiosk: sellerKiosk,
1235
+ nftTokenId,
1236
+ nftType
1237
+ });
1238
+ }
1239
+ const { orderbook } = sharedObjects;
1240
+ const [tradeInfo] = txBlock.moveCall({
1241
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::market_sell",
1242
+ arguments: [
1243
+ txBlock.object(orderbook),
1244
+ txBlock.object(kiosk),
1245
+ txBlock.pure(bidAmount),
1246
+ txBlock.pure(nftTokenId)
1247
+ ],
1248
+ typeArguments: [nftType, "0x2::sui::SUI"]
1249
+ });
1250
+ const [id] = txBlock.moveCall({
1251
+ target: "0xa0bab69d913e5a0ce8b448235a08bcf4c42da45c50622743dc9cab2dc0dff30f::orderbook::trade_id",
1252
+ arguments: [txBlock.object(tradeInfo)],
1253
+ typeArguments: []
1254
+ });
1255
+ const transferRequest = txBlock.moveCall({
1256
+ target: "0xa0bab69d913e5a0ce8b448235a08bcf4c42da45c50622743dc9cab2dc0dff30f::orderbook::finish_trade",
1257
+ arguments: [
1258
+ txBlock.object(orderbook),
1259
+ txBlock.object(id),
1260
+ txBlock.object(kiosk),
1261
+ txBlock.object(bidNonce)
1262
+ ],
1263
+ typeArguments: [nftType, "0x2::sui::SUI"]
1264
+ });
1265
+ confirmOBTranfer({ txBlock, sharedObjects, transferRequest, nftType });
1266
+ if (isNewKiosk) {
1267
+ await shareOriginByteKiosk({ txBlock, kiosk });
1268
+ }
1269
+ }
1270
+ function addBluemoveAcceptCollectionBidTx({
1271
+ txBlock,
1272
+ nftTokenId,
1273
+ nftType,
1274
+ bidNonce,
1275
+ listingPrice,
1276
+ itemTakenOutOfNativeKiosk
1277
+ }) {
1278
+ let unlistedItem;
1279
+ if (listingPrice && listingPrice > 0) {
1280
+ unlistedItem = txBlock.moveCall({
1281
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist",
1282
+ arguments: [txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT), txBlock.pure(nftTokenId)],
1283
+ typeArguments: [nftType, nftType]
1284
+ });
1285
+ }
1286
+ txBlock.moveCall({
1287
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_collection::accept_offer_collection",
1288
+ arguments: [
1289
+ txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT),
1290
+ txBlock.object(BLUEMOVE_ROYALTY_COLLECTION_OBJECT),
1291
+ txBlock.object(BLUEMOVE_CREATOR_CONFIG_OBJECT),
1292
+ txBlock.object(BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT),
1293
+ txBlock.pure(bidNonce),
1294
+ itemTakenOutOfNativeKiosk ? txBlock.object(itemTakenOutOfNativeKiosk) : unlistedItem ? txBlock.object(unlistedItem) : txBlock.pure(nftTokenId)
1295
+ ],
1296
+ typeArguments: [nftType]
1297
+ });
1298
+ }
1299
+ async function addBluemoveKioskAcceptCollectionBidTx({
1300
+ txBlock,
1301
+ kioskTx,
1302
+ nftTokenId,
1303
+ nftType,
1304
+ bidNonce
1305
+ }) {
1306
+ txBlock.moveCall({
1307
+ target: "0x2949e130ca4dabfe6448173758468a3e45ea3f070e3264f112b51c023f3ecf9f::kiosk_offer_collection_v2::accept_offer_collection_v2",
1308
+ arguments: [
1309
+ txBlock.object(BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT),
1310
+ txBlock.object(BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT),
1311
+ txBlock.object(BLUEMOVE_KIOSK_OFFER_COLLECTION_BIDDER_BAG),
1312
+ txBlock.pure(bidNonce),
1313
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
1314
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
1315
+ txBlock.pure(nftTokenId)
1316
+ ],
1317
+ typeArguments: [nftType]
1318
+ });
1319
+ }
1320
+ function addTocenAcceptCollectionBidTx({
1321
+ txBlock,
1322
+ nftTokenId,
1323
+ nftType,
1324
+ bidAmount,
1325
+ bidder
1326
+ }) {
1327
+ txBlock.moveCall({
1328
+ target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::accept_offer_list",
1329
+ arguments: [
1330
+ txBlock.object(TOCEN_MARKETPLACE_OBJECT),
1331
+ txBlock.pure(nftTokenId),
1332
+ txBlock.pure(bidder),
1333
+ txBlock.pure(bidAmount)
1334
+ ],
1335
+ typeArguments: [nftType]
1336
+ });
1337
+ }
1338
+ async function addTradePortAcceptCollectionBidTxHandler(txData) {
1339
+ const bidType = await getObjectType(txData?.bidNonce);
1340
+ if (isOriginByteBid(bidType)) {
1341
+ if (isOriginByteTx(txData?.sharedObjects)) {
1342
+ await addOriginByteAcceptCollectionBidTx(txData);
1343
+ return;
1344
+ }
1345
+ throw new Error(
1346
+ `You cannot accept an Origin Byte bid with a NFT outside of an Origin Byte kiosk. Nft Token Id: ${txData?.nftTokenId}`
1347
+ );
1348
+ }
1349
+ if (!await hasTransferPolicyRules(txData?.nftType) && txData?.sellerKiosk) {
1350
+ return kioskTxWrapper({
1351
+ txBlock: txData?.txBlock,
1352
+ kioskOwner: txData?.seller,
1353
+ kiosk: txData?.sellerKiosk,
1354
+ async tx(kioskTx) {
1355
+ const item = kioskTx.take({
1356
+ itemId: txData?.nftTokenId,
1357
+ itemType: txData?.nftType
1358
+ });
1359
+ addTradeportAcceptCollectionBidTx({ ...txData, itemTakenOutOfNativeKiosk: item });
1360
+ }
1361
+ });
1362
+ }
1363
+ if (isTradePortKioskBid(bidType)) {
1364
+ if (txData?.sellerKiosk) {
1365
+ const royaltyRulePackageId = await getRulePackageId(txData.nftType, "royalty_rule");
1366
+ return kioskTxWrapper({
1367
+ txBlock: txData?.txBlock,
1368
+ kioskOwner: txData?.itemOwner,
1369
+ kiosk: txData?.sellerKiosk,
1370
+ async tx(kioskTx) {
1371
+ await addTradeportKioskAcceptCollectionBidTx({
1372
+ ...txData,
1373
+ kioskTx,
1374
+ royaltyRulePackageId
1375
+ });
1376
+ }
1377
+ });
1378
+ }
1379
+ if (await hasTransferPolicyRules(txData?.nftType) && !txData?.sellerKiosk) {
1380
+ const royaltyRulePackageId = await getRulePackageId(txData.nftType, "royalty_rule");
1381
+ return kioskTxWrapper({
1382
+ txBlock: txData?.txBlock,
1383
+ kioskOwner: txData?.seller,
1384
+ kiosk: txData?.sellerKiosk,
1385
+ async tx(kioskTx) {
1386
+ kioskTx.place({
1387
+ item: txData?.nftTokenId,
1388
+ itemType: txData?.nftType
1389
+ });
1390
+ await addTradeportKioskAcceptCollectionBidTx({
1391
+ ...txData,
1392
+ kioskTx,
1393
+ royaltyRulePackageId
1394
+ });
1395
+ }
1396
+ });
1397
+ }
1398
+ }
1399
+ addTradeportAcceptCollectionBidTx(txData);
1400
+ }
1401
+ async function addBluemoveAcceptCollectionBidTxHandler(txData) {
1402
+ const bidType = await getObjectType(txData?.bidNonce);
1403
+ if (isOriginByteBid(bidType)) {
1404
+ if (isOriginByteTx(txData?.sharedObjects)) {
1405
+ await addOriginByteAcceptCollectionBidTx(txData);
1406
+ return;
1407
+ }
1408
+ throw new Error(
1409
+ `You cannot accept an Origin Byte bid with a NFT outside of an Origin Byte kiosk. Nft Token Id: ${txData?.nftTokenId}`
1410
+ );
1411
+ }
1412
+ if (isBluemoveKioskBid(txData?.bidNonce)) {
1413
+ if (txData?.sellerKiosk) {
1414
+ return kioskTxWrapper({
1415
+ txBlock: txData?.txBlock,
1416
+ kioskOwner: txData?.itemOwner,
1417
+ kiosk: txData?.sellerKiosk,
1418
+ async tx(kioskTx) {
1419
+ await addBluemoveKioskAcceptCollectionBidTx({
1420
+ ...txData,
1421
+ kioskTx
1422
+ });
1423
+ }
1424
+ });
1425
+ }
1426
+ throw new Error(
1427
+ `You cannot accept an Native Kiosk Bid with a NFT outside of a native kiosk. Nft Token Id: ${txData?.nftTokenId}`
1428
+ );
1429
+ }
1430
+ if (!isBluemoveKioskBid(txData?.bidNonce)) {
1431
+ if (txData?.sellerKiosk) {
1432
+ return kioskTxWrapper({
1433
+ txBlock: txData?.txBlock,
1434
+ kioskOwner: txData?.itemOwner,
1435
+ kiosk: txData?.sellerKiosk,
1436
+ async tx(kioskTx) {
1437
+ const item = kioskTx.take({
1438
+ itemId: txData?.nftTokenId,
1439
+ itemType: txData?.nftType
1440
+ });
1441
+ addBluemoveAcceptCollectionBidTx({ ...txData, itemTakenOutOfNativeKiosk: item });
1442
+ }
1443
+ });
1444
+ }
1445
+ addBluemoveAcceptCollectionBidTx(txData);
1446
+ }
1447
+ }
1448
+ function addTocenAcceptCollectionBidTxHandler(txData) {
1449
+ addTocenAcceptCollectionBidTx(txData);
1450
+ }
1451
+
1452
+ // src/methods/acceptCollectionBid/acceptCollectionBid.ts
1453
+ var ERROR_UNLIST_FIRST = "Item must be unlisted first before you can accept a collection bid with it";
1454
+ var acceptCollectionBid = async ({
1455
+ bid,
1456
+ nftId,
1457
+ walletAddress
1458
+ }) => {
1459
+ const nftRes = await gqlChainRequest({
1460
+ chain: "sui",
1461
+ query: fetchNftById,
1462
+ variables: { nftId }
1463
+ });
1464
+ const nft = nftRes?.nfts?.[0];
1465
+ if (!nft) {
1466
+ throw new Error("No nft found");
1467
+ }
1468
+ const txBlock = new TransactionBlock();
1469
+ const sharedObjects = await getSharedObjects(
1470
+ nft?.properties?.nft_type || nft?.contract?.properties?.nft_type
1471
+ );
1472
+ const txData = {
1473
+ txBlock,
1474
+ sharedObjects,
1475
+ bidNonce: bid?.nonce,
1476
+ nftType: getNftTypeFromNft(nft),
1477
+ nftTokenId: nft?.token_id,
1478
+ itemOwner: nft?.owner,
1479
+ listingPrice: nft?.listings?.[0]?.price,
1480
+ listingNonce: nft?.listings?.[0]?.nonce,
1481
+ bidAmount: bid?.price,
1482
+ bidder: bid?.bidder,
1483
+ seller: walletAddress,
1484
+ sellerKiosk: nft?.chain_state?.kiosk_id,
1485
+ collectionId: nft?.collection_id,
1486
+ isListedOnBluemove: nft?.listings?.[0]?.market_name === "bluemove",
1487
+ bidMarketName: bid?.market_contract?.name
1488
+ };
1489
+ switch (txData.bidMarketName) {
1490
+ case "tradeport":
1491
+ if (txData?.listingPrice && txData?.listingPrice > 0) {
1492
+ throw new Error(ERROR_UNLIST_FIRST);
1493
+ }
1494
+ await addTradePortAcceptCollectionBidTxHandler(txData);
1495
+ break;
1496
+ case "clutchy":
1497
+ await addOriginByteAcceptCollectionBidTx(txData);
1498
+ break;
1499
+ case "bluemove":
1500
+ if (txData?.listingPrice && txData?.listingPrice > 0 && !txData?.isListedOnBluemove) {
1501
+ throw new Error(ERROR_UNLIST_FIRST);
1502
+ }
1503
+ await addBluemoveAcceptCollectionBidTxHandler(txData);
1504
+ break;
1505
+ case "tocen":
1506
+ if (txData?.listingPrice && txData?.listingPrice > 0) {
1507
+ throw new Error(ERROR_UNLIST_FIRST);
1508
+ }
1509
+ addTocenAcceptCollectionBidTxHandler(txData);
1510
+ break;
1511
+ default:
1512
+ throw new Error("Marketplace not supported");
1513
+ }
1514
+ return new TransactionBlock(txBlock);
1515
+ };
1516
+
1517
+ // src/methods/acceptNftBids/acceptNftBids.ts
1518
+ import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
1519
+
1520
+ // src/graphql/queries/fetchBidsById.ts
1521
+ import { gql as gql10 } from "graphql-request";
1522
+ var fetchBidsById = gql10`
1523
+ query fetchBidsById($bidIds: [uuid!]) {
1524
+ bids(where: { id: { _in: $bidIds } }) {
1525
+ nonce
1526
+ price
1527
+ status
1528
+ type
1529
+ nft {
1530
+ token_id
1531
+ properties
1532
+ chain_state
1533
+ owner
1534
+ contract {
1535
+ properties
1536
+ }
1537
+ listings(where: { listed: { _eq: true } }) {
1538
+ price
1539
+ market_name
1540
+ }
1541
+ }
1542
+ market_contract {
1543
+ name
1544
+ }
1545
+ }
1546
+ }
1547
+ `;
1548
+
1549
+ // src/methods/acceptNftBids/acceptNftBids.ts
1550
+ var ERROR_UNLIST_FIRST2 = "Item must be unlisted first before you can accept a solo bid on it";
1551
+ var acceptNftBids = async ({ bidIds }) => {
1552
+ const res = await gqlChainRequest({
1553
+ chain: "sui",
1554
+ query: fetchBidsById,
1555
+ variables: { bidIds }
1556
+ });
1557
+ if (res?.bids?.length === 0) {
1558
+ throw new Error("No bids found");
1559
+ }
1560
+ const txBlock = new TransactionBlock2();
1561
+ for (const bid of res.bids) {
1562
+ if (bid?.status !== "active") {
1563
+ throw new Error("Bid not active");
1564
+ }
1565
+ if (bid?.type !== "solo") {
1566
+ throw new Error("Bid is not an individual item bid. Use acceptCollectionBid() instead.");
1567
+ }
1568
+ const sharedObjects = await getSharedObjects(
1569
+ bid?.nft?.properties?.nft_type || bid?.nft?.contract?.properties?.nft_type
1570
+ );
1571
+ const txData = {
1572
+ txBlock,
1573
+ sharedObjects,
1574
+ bidNonce: bid?.nonce,
1575
+ nftType: getNftTypeFromNft(bid?.nft),
1576
+ listingPrice: bid?.nft?.listings?.[0]?.price,
1577
+ nftTokenId: bid?.nft?.token_id,
1578
+ itemOwner: bid?.nft?.owner,
1579
+ bidAmount: bid?.price,
1580
+ sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
1581
+ isListedOnBluemove: bid?.nft?.listings?.[0]?.market_name === "bluemove",
1582
+ bidMarketName: bid?.market_contract?.name
1583
+ };
1584
+ switch (txData.bidMarketName) {
1585
+ case "tradeport":
1586
+ if (txData?.listingPrice && txData?.listingPrice > 0) {
1587
+ throw new Error(ERROR_UNLIST_FIRST2);
1588
+ }
1589
+ await addTradePortAcceptNftBidTxHandler(txData);
1590
+ break;
1591
+ case "clutchy":
1592
+ case "hyperspace":
1593
+ case "somis":
1594
+ await addOriginByteAcceptNftBidTx(txData);
1595
+ break;
1596
+ case "bluemove":
1597
+ addBluemoveAcceptNftBidTx(txData);
1598
+ break;
1599
+ default:
1600
+ throw new Error("Marketplace not supported");
1601
+ }
1602
+ }
1603
+ return new TransactionBlock2(txBlock);
1604
+ };
1605
+
1606
+ // src/methods/buyListings/buyListings.ts
1607
+ import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
1608
+
1609
+ // src/graphql/queries/fetchListingsById.ts
1610
+ import { gql as gql11 } from "graphql-request";
1611
+ var fetchListingsById = gql11`
1612
+ query fetchListingsById($listingIds: [uuid!]) {
1613
+ listings(where: { id: { _in: $listingIds } }) {
1614
+ seller
1615
+ listed
1616
+ market_name
1617
+ price
1618
+ nonce
1619
+ nft {
1620
+ id
1621
+ token_id
1622
+ collection_id
1623
+ contract_id
1624
+ properties
1625
+ chain_state
1626
+ contract {
1627
+ properties
1628
+ }
1629
+ }
1630
+ }
1631
+ }
1632
+ `;
1633
+
1634
+ // src/helpers/addThirdPartyTxFee.ts
1635
+ var addThirdPartyTxFee = async (txBlock, price) => {
1636
+ const [microTxFee] = txBlock.splitCoins(txBlock.gas, [
1637
+ txBlock.pure(price * TRADEPORT_THIRD_PARTY_FEE_DECIMAL_PERCENT)
1638
+ ]);
1639
+ txBlock.transferObjects(
1640
+ [txBlock.object(microTxFee)],
1641
+ txBlock.pure(addLeadingZerosAfter0x(TRADEPORT_BENEFICIARY_ADDRESS))
1642
+ );
1643
+ };
1644
+
1645
+ // src/graphql/queries/fetchCommissionByListingId.ts
1646
+ import { gql as gql12 } from "graphql-request";
1647
+ var fetchCommissionByNftContractId = gql12`
1648
+ query fetchCommissionByNftContractId($nftContractId: uuid!) {
1649
+ commissions(where: { contract_id: { _eq: $nftContractId } }) {
1650
+ is_custodial
1651
+ key
1652
+ market_fee
1653
+ market_name
1654
+ royalty
1655
+ }
1656
+ }
1657
+ `;
1658
+
1659
+ // src/graphql/queries/getCommissionByListingId.ts
1660
+ var getCommissionByNftContractId = async (nftContractId) => {
1661
+ try {
1662
+ const res = await gqlChainRequest({
1663
+ chain: "sui",
1664
+ query: fetchCommissionByNftContractId,
1665
+ variables: { nftContractId }
1666
+ });
1667
+ return res?.commissions?.[0];
1668
+ } catch (err) {
1669
+ throw new Error(`Failed to fetch commission for listing ${nftContractId}`);
1670
+ }
1671
+ };
1672
+
1673
+ // src/helpers/destroyZeroCoin.ts
1674
+ var destroyZeroCoin = ({ txBlock, coin }) => {
1675
+ txBlock.moveCall({
1676
+ target: "0x2::coin::destroy_zero",
1677
+ arguments: [txBlock.object(coin)],
1678
+ typeArguments: ["0x2::sui::SUI"]
1679
+ });
1680
+ };
1681
+
1682
+ // src/methods/buyListings/addBuyListingTxs.ts
1683
+ function addTradePortBuyTx({ txBlock, nftType, listingNonce, price, sharedObjects }) {
1684
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1685
+ if (!coin)
1686
+ throw new Error("Coin could not be split");
1687
+ const { collection, royaltyStrategy } = sharedObjects;
1688
+ if (collection && royaltyStrategy) {
1689
+ txBlock.moveCall({
1690
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::ob_buy",
1691
+ arguments: [
1692
+ txBlock.object(TRADEPORT_LISTING_STORE),
1693
+ txBlock.pure(listingNonce),
1694
+ txBlock.object(coin),
1695
+ txBlock.object(collection),
1696
+ txBlock.object(royaltyStrategy)
1697
+ ],
1698
+ typeArguments: [nftType]
1699
+ });
1700
+ } else {
1701
+ txBlock.moveCall({
1702
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::buy",
1703
+ arguments: [
1704
+ txBlock.object(TRADEPORT_LISTING_STORE),
1705
+ txBlock.pure(listingNonce),
1706
+ txBlock.object(coin)
1707
+ ],
1708
+ typeArguments: [nftType]
1709
+ });
1710
+ }
1711
+ destroyZeroCoin({ txBlock, coin });
1712
+ }
1713
+ var addTradeportKioskBuyTx = async ({
1714
+ txBlock,
1715
+ kioskTx,
1716
+ nftType,
1717
+ nftTokenId,
1718
+ price,
1719
+ sellerKiosk
1720
+ }) => {
1721
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1722
+ if (!coin)
1723
+ throw new Error("Coin could not be split");
1724
+ const [kioskItem, transferRequest, kioskPrice] = txBlock.moveCall({
1725
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_listings::buy",
1726
+ arguments: [
1727
+ txBlock.object(TRADEPORT_KIOSK_LISTING_STORE),
1728
+ txBlock.object(sellerKiosk),
1729
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
1730
+ txBlock.pure(nftTokenId),
1731
+ txBlock.object(coin)
1732
+ ],
1733
+ typeArguments: [nftType]
1734
+ });
1735
+ await resolveTransferPolicies({
1736
+ txBlock,
1737
+ kioskTx,
1738
+ nftType,
1739
+ priceObjectArgument: kioskPrice,
1740
+ kioskItem,
1741
+ transferRequest
1742
+ });
1743
+ destroyZeroCoin({ txBlock, coin });
1744
+ };
1745
+ async function addOriginByteBuyTx({
1746
+ txBlock,
1747
+ sharedObjects,
1748
+ buyer,
1749
+ nftTokenId,
1750
+ nftType,
1751
+ listingNonce,
1752
+ price
1753
+ }) {
1754
+ const { orderbook } = sharedObjects;
1755
+ const { kiosk: buyerKiosk, isNewKiosk: isNewBuyerKiosk } = await getOrCreateOBKiosk({
1756
+ txBlock,
1757
+ address: buyer
1758
+ });
1759
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1760
+ if (!coin)
1761
+ throw new Error("Coin could not be split");
1762
+ const transferRequest = txBlock.moveCall({
1763
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::buy_nft",
1764
+ arguments: [
1765
+ txBlock.object(orderbook),
1766
+ txBlock.object(listingNonce),
1767
+ txBlock.object(buyerKiosk),
1768
+ txBlock.pure(nftTokenId),
1769
+ txBlock.pure(price),
1770
+ txBlock.object(coin)
1771
+ ],
1772
+ typeArguments: [nftType, "0x2::sui::SUI"]
1773
+ });
1774
+ confirmOBTranfer({ txBlock, sharedObjects, transferRequest, nftType });
1775
+ destroyZeroCoin({ txBlock, coin });
1776
+ if (isNewBuyerKiosk) {
1777
+ await shareOriginByteKiosk({ txBlock, kiosk: buyerKiosk });
1778
+ }
1779
+ }
1780
+ var addHyperspaceKioskBuyTx = async ({
1781
+ txBlock,
1782
+ kioskTx,
1783
+ nftType,
1784
+ nftTokenId,
1785
+ price,
1786
+ sellerKiosk
1787
+ }) => {
1788
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1789
+ if (!coin)
1790
+ throw new Error("Coin could not be split");
1791
+ const [kioskItem, transferRequest, hyperspaceTransferRequest, hyperspaceMpTransferRequest] = txBlock.moveCall({
1792
+ target: "0x6ea97b03c441edd54ae89224bf9560e583ee66c37e6c246f5db35258e580ba94::hyperspace::purchase",
1793
+ arguments: [txBlock.object(sellerKiosk), txBlock.pure(nftTokenId), txBlock.object(coin)],
1794
+ typeArguments: [nftType, HYPERSPACE_MP_TRANSFER_POLICY_TYPE]
1795
+ });
1796
+ const customTransferPolicies = [
1797
+ {
1798
+ type: HYPERSPACE_TRANSFER_POLICY_TYPE,
1799
+ transferRequest: hyperspaceTransferRequest
1800
+ },
1801
+ {
1802
+ type: HYPERSPACE_MP_TRANSFER_POLICY_TYPE,
1803
+ transferRequest: hyperspaceMpTransferRequest
1804
+ }
1805
+ ];
1806
+ await resolveTransferPolicies({
1807
+ txBlock,
1808
+ kioskTx,
1809
+ nftType,
1810
+ price: price?.toString(),
1811
+ kioskItem,
1812
+ transferRequest,
1813
+ customTransferPolicies
1814
+ });
1815
+ };
1816
+ function addBluemoveBuyTx({ txBlock, nftTokenId, nftType, price }) {
1817
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1818
+ if (!coin)
1819
+ throw new Error("Coin could not be split");
1820
+ txBlock.moveCall({
1821
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::buy_and_take",
1822
+ arguments: [
1823
+ txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT),
1824
+ txBlock.object(BLUEMOVE_ROYALTY_COLLECTION_OBJECT),
1825
+ txBlock.object(BLUEMOVE_CREATOR_CONFIG_OBJECT),
1826
+ txBlock.pure(nftTokenId),
1827
+ txBlock.object(coin),
1828
+ txBlock.pure(price)
1829
+ ],
1830
+ typeArguments: [nftType, nftType]
1831
+ });
1832
+ }
1833
+ async function addBluemoveKioskBuyTx({
1834
+ txBlock,
1835
+ kioskTx,
1836
+ sharedObjects,
1837
+ nftTokenId,
1838
+ nftType,
1839
+ price,
1840
+ sellerKiosk
1841
+ }) {
1842
+ const { transferPolicy } = sharedObjects;
1843
+ const [coin1, coin2] = splitCoins({
1844
+ txBlock,
1845
+ amounts: [txBlock.pure(price), txBlock.pure(price * 0.025)]
1846
+ });
1847
+ if (!coin1 || !coin2)
1848
+ throw new Error("Coin could not be split");
1849
+ txBlock.mergeCoins(txBlock.object(coin1), [txBlock.object(coin2)]);
1850
+ const [kioskItem, transferRequest] = txBlock.moveCall({
1851
+ target: "0xcc97b74ed95c8e8a3ed88050a898727dee37896da579fc400d482b64db6149ff::kiosk_trade::kiosk_buy_v2",
1852
+ arguments: [
1853
+ txBlock.object(BLUEMOVE_KIOSK_MARKETPLACE_KIOSK_OBJECT),
1854
+ txBlock.object(sellerKiosk),
1855
+ txBlock.object(transferPolicy),
1856
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
1857
+ txBlock.pure(nftTokenId),
1858
+ txBlock.pure(price),
1859
+ txBlock.object(coin1)
1860
+ ],
1861
+ typeArguments: [nftType]
1862
+ });
1863
+ await resolveTransferPolicies({
1864
+ txBlock,
1865
+ kioskTx,
1866
+ nftType,
1867
+ price: price?.toString(),
1868
+ kioskItem,
1869
+ transferRequest
1870
+ });
1871
+ }
1872
+ function addSouffl3BuyTx({
1873
+ txBlock,
1874
+ sharedObjects,
1875
+ nftType,
1876
+ price,
1877
+ listingNonce,
1878
+ collectionId,
1879
+ buyer
1880
+ }) {
1881
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1882
+ const { transferPolicy } = sharedObjects;
1883
+ if (transferPolicy && !SOUFFL3_GENERIC_BUY_METHOD_COLLECTIONS?.includes(collectionId)) {
1884
+ const [coinToDestroy] = txBlock.moveCall({
1885
+ target: "0x30d90b5b67be77e6e06f02dae9f0f2fcdad16e38854316ae8a7b4f5b4971f5e0::Market::buy_with_sui_with_ext",
1886
+ arguments: [
1887
+ txBlock.object(SOUFFL3_VERSION_OBJECT),
1888
+ txBlock.object(SOUFFL3_EXTENSION_OBJECT),
1889
+ txBlock.object(transferPolicy),
1890
+ txBlock.object(listingNonce),
1891
+ txBlock.pure(price),
1892
+ txBlock.object(SOUFFL3_MARKETPLACE_OBJECT),
1893
+ txBlock.object(coin)
1894
+ ],
1895
+ typeArguments: [nftType]
1896
+ });
1897
+ destroyZeroCoin({ txBlock, coin: coinToDestroy });
1898
+ } else {
1899
+ const [coinToDestroy] = txBlock.moveCall({
1900
+ target: "0x30d90b5b67be77e6e06f02dae9f0f2fcdad16e38854316ae8a7b4f5b4971f5e0::Market::buy_generic_with_ext",
1901
+ arguments: [
1902
+ txBlock.object(SOUFFL3_VERSION_OBJECT),
1903
+ txBlock.object(SOUFFL3_EXTENSION_OBJECT),
1904
+ txBlock.object(listingNonce),
1905
+ txBlock.pure(price),
1906
+ txBlock.object(SOUFFL3_MARKETPLACE_OBJECT),
1907
+ txBlock.object(coin)
1908
+ ],
1909
+ typeArguments: [nftType, "0x2::sui::SUI"]
1910
+ });
1911
+ destroyZeroCoin({ txBlock, coin: coinToDestroy });
1912
+ }
1913
+ }
1914
+ function addSomisBuyTx({ txBlock, sharedObjects, nftTokenId, nftType, price }) {
1915
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1916
+ if (!coin)
1917
+ throw new Error("Coin could not be split");
1918
+ txBlock.moveCall({
1919
+ target: "0xf0b0beb956e26bde50dbd6ac393026c4525aee3b194a9478f09748f7211b5a02::marketplace::buy_nft",
1920
+ arguments: [
1921
+ txBlock.object(sharedObjects?.marketplace),
1922
+ txBlock.pure(nftTokenId),
1923
+ txBlock.object(coin)
1924
+ ],
1925
+ typeArguments: [nftType, "0x2::sui::SUI"]
1926
+ });
1927
+ }
1928
+ function addKeepsakeBuyTx({
1929
+ txBlock,
1930
+ sharedObjects,
1931
+ buyer,
1932
+ nftTokenId,
1933
+ nftType,
1934
+ price,
1935
+ royalty
1936
+ }) {
1937
+ const { keepsakeRoyaltyStrategy, transferPolicy } = sharedObjects;
1938
+ const [coin1, coin2] = splitCoins({
1939
+ txBlock,
1940
+ amounts: [
1941
+ txBlock.pure(price),
1942
+ txBlock.pure(price * Number(royalty) / 100 + price * Number(royalty) * 5e-5)
1943
+ ]
1944
+ });
1945
+ if (!coin1 || !coin2)
1946
+ throw new Error("Coin could not be split");
1947
+ const [balance] = txBlock.moveCall({
1948
+ target: "0x2::coin::into_balance",
1949
+ arguments: [txBlock.object(coin2)],
1950
+ typeArguments: ["0x2::sui::SUI"]
1951
+ });
1952
+ if (!balance)
1953
+ throw new Error("Coin into_balance failed");
1954
+ const [transferRequest] = txBlock.moveCall({
1955
+ target: "0x02be8c4a1a3cea4d3255d870d367c87838a8cc2bfe4f216a6b67b153027087a7::keepsake_marketplace::buy",
1956
+ arguments: [
1957
+ txBlock.object(KEEPSAKE_MARKETPLACE_OBJECT),
1958
+ txBlock.object(KEEPSAKE_MARKETPLACE_KIOSK),
1959
+ txBlock.pure(nftTokenId),
1960
+ txBlock.object(coin1)
1961
+ ],
1962
+ typeArguments: [nftType]
1963
+ });
1964
+ if (!transferRequest)
1965
+ throw new Error("Transfer request could not be created");
1966
+ txBlock.moveCall({
1967
+ target: "0x02be8c4a1a3cea4d3255d870d367c87838a8cc2bfe4f216a6b67b153027087a7::keepsake_royalties::confirm_transfer_with_balance",
1968
+ arguments: [
1969
+ txBlock.object(keepsakeRoyaltyStrategy),
1970
+ txBlock.object(transferRequest),
1971
+ txBlock.object(balance)
1972
+ ],
1973
+ typeArguments: [nftType]
1974
+ });
1975
+ txBlock.moveCall({
1976
+ target: "0x02be8c4a1a3cea4d3255d870d367c87838a8cc2bfe4f216a6b67b153027087a7::transfer_policy::confirm_request",
1977
+ arguments: [txBlock.object(transferPolicy), txBlock.object(transferRequest)],
1978
+ typeArguments: [nftType]
1979
+ });
1980
+ const [balanceToTransfer] = txBlock.moveCall({
1981
+ target: "0x2::coin::from_balance",
1982
+ arguments: [txBlock.object(balance)],
1983
+ typeArguments: ["0x2::sui::SUI"]
1984
+ });
1985
+ if (!balanceToTransfer)
1986
+ throw new Error("Coin from_balance failed");
1987
+ txBlock.transferObjects(
1988
+ [txBlock.object(balanceToTransfer)],
1989
+ txBlock.pure(addLeadingZerosAfter0x(buyer))
1990
+ );
1991
+ }
1992
+ var addTocenBuyTx = ({ txBlock, nftTokenIds, nftType, price }) => {
1993
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(price)] });
1994
+ if (!coin)
1995
+ throw new Error("Coin could not be split");
1996
+ txBlock.moveCall({
1997
+ target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::buy_cart",
1998
+ arguments: [
1999
+ txBlock.pure(TOCEN_MARKETPLACE_OBJECT),
2000
+ txBlock.pure(nftTokenIds),
2001
+ txBlock.object(coin)
2002
+ ],
2003
+ typeArguments: [nftType]
2004
+ });
2005
+ };
2006
+ async function addTradePortBuyTxHandler(txData) {
2007
+ if (txData?.listingNonce && isOriginByteTx(txData?.sharedObjects)) {
2008
+ await addOriginByteBuyTx(txData);
2009
+ return;
2010
+ }
2011
+ if (txData?.sellerKiosk) {
2012
+ return kioskTxWrapper({
2013
+ txBlock: txData?.txBlock,
2014
+ kioskOwner: txData?.buyer,
2015
+ kiosk: txData?.sellerKiosk,
2016
+ shouldConvertToPersonalKiosk: true,
2017
+ async tx(kioskTx) {
2018
+ await addTradeportKioskBuyTx({
2019
+ ...txData,
2020
+ kioskTx
2021
+ });
2022
+ }
2023
+ });
2024
+ }
2025
+ addTradePortBuyTx(txData);
2026
+ }
2027
+ async function addHyperspaceBuyTxHandler(txData) {
2028
+ if (txData?.listingNonce && isOriginByteTx(txData?.sharedObjects)) {
2029
+ await addOriginByteBuyTx(txData);
2030
+ return;
2031
+ }
2032
+ return kioskTxWrapper({
2033
+ txBlock: txData?.txBlock,
2034
+ kioskOwner: txData?.buyer,
2035
+ kiosk: txData?.sellerKiosk,
2036
+ shouldConvertToPersonalKiosk: true,
2037
+ async tx(kioskTx) {
2038
+ await addHyperspaceKioskBuyTx({
2039
+ ...txData,
2040
+ kioskTx
2041
+ });
2042
+ }
2043
+ });
2044
+ }
2045
+ async function addBluemoveBuyTxHandler(txData) {
2046
+ if (txData?.listingNonce && isOriginByteTx(txData?.sharedObjects)) {
2047
+ await addOriginByteBuyTx(txData);
2048
+ return;
2049
+ }
2050
+ if (txData?.sellerKiosk) {
2051
+ return kioskTxWrapper({
2052
+ txBlock: txData?.txBlock,
2053
+ kioskOwner: txData?.buyer,
2054
+ kiosk: txData?.sellerKiosk,
2055
+ shouldConvertToPersonalKiosk: true,
2056
+ async tx(kioskTx) {
2057
+ await addBluemoveKioskBuyTx({
2058
+ ...txData,
2059
+ kioskTx
2060
+ });
2061
+ }
2062
+ });
2063
+ }
2064
+ addBluemoveBuyTx(txData);
2065
+ }
2066
+ async function addClutchyBuyTxHandler(txData) {
2067
+ await addOriginByteBuyTx(txData);
2068
+ }
2069
+ async function addSouffl3BuyTxHandler(txData) {
2070
+ addSouffl3BuyTx(txData);
2071
+ }
2072
+ async function addSomisBuyTxHandler(txData) {
2073
+ if (txData?.sharedObjects?.marketplace) {
2074
+ addSomisBuyTx(txData);
2075
+ return;
2076
+ }
2077
+ return addOriginByteBuyTx(txData);
2078
+ }
2079
+ async function addKeepsakeBuyTxHandler(txData) {
2080
+ const commission = await getCommissionByNftContractId(txData?.nftContractId);
2081
+ addKeepsakeBuyTx({
2082
+ ...txData,
2083
+ royalty: commission?.royalty
2084
+ });
2085
+ }
2086
+ function addTocenBuyTxHandler(txData) {
2087
+ addTocenBuyTx(txData);
2088
+ }
2089
+
2090
+ // src/methods/buyListings/buyListings.ts
2091
+ var buyListings = async ({
2092
+ listingIds,
2093
+ walletAddress
2094
+ }) => {
2095
+ const res = await gqlChainRequest({
2096
+ chain: "sui",
2097
+ query: fetchListingsById,
2098
+ variables: { listingIds }
2099
+ });
2100
+ if (res?.listings?.length === 0) {
2101
+ throw new Error("No listings found");
2102
+ }
2103
+ const txBlock = new TransactionBlock3();
2104
+ const tocenTokenIds = [];
2105
+ let tocenNftType = "";
2106
+ let tocenTotalPrice = 0;
2107
+ for (const listing of res.listings) {
2108
+ if (!listing?.listed) {
2109
+ throw new Error(`Listing ${listing?.id} is not listed`);
2110
+ }
2111
+ const sharedObjects = await getSharedObjects(
2112
+ listing?.nft?.properties?.nft_type || listing?.nft?.contract?.properties?.nft_type
2113
+ );
2114
+ const buyTxData = {
2115
+ txBlock,
2116
+ sharedObjects,
2117
+ buyer: walletAddress,
2118
+ nftTokenId: listing.nft?.token_id,
2119
+ nftType: getNftTypeFromNft(listing?.nft),
2120
+ listingId: listing?.id,
2121
+ listingNonce: listing?.nonce,
2122
+ price: listing?.price,
2123
+ sellerKiosk: listing.nft?.chain_state?.kiosk_id,
2124
+ collectionId: listing?.nft?.collection_id,
2125
+ nftContractId: listing?.nft?.contract_id
2126
+ };
2127
+ switch (listing?.market_name) {
2128
+ case "tradeport":
2129
+ await addTradePortBuyTxHandler(buyTxData);
2130
+ break;
2131
+ case "hyperspace":
2132
+ await addHyperspaceBuyTxHandler(buyTxData);
2133
+ break;
2134
+ case "bluemove":
2135
+ await addBluemoveBuyTxHandler(buyTxData);
2136
+ break;
2137
+ case "clutchy":
2138
+ await addClutchyBuyTxHandler(buyTxData);
2139
+ break;
2140
+ case "souffl3":
2141
+ await addSouffl3BuyTxHandler(buyTxData);
2142
+ break;
2143
+ case "somis":
2144
+ await addSomisBuyTxHandler(buyTxData);
2145
+ break;
2146
+ case "keepsake":
2147
+ await addKeepsakeBuyTxHandler(buyTxData);
2148
+ break;
2149
+ case "tocen":
2150
+ tocenTokenIds.push(buyTxData?.nftTokenId);
2151
+ tocenNftType = buyTxData?.nftType;
2152
+ tocenTotalPrice += Number(listing.price);
2153
+ break;
2154
+ default:
2155
+ throw new Error("Marketplace not supported");
2156
+ }
2157
+ if (listing?.market_name !== "tradeport") {
2158
+ await addThirdPartyTxFee(txBlock, listing?.price);
2159
+ }
2160
+ }
2161
+ if (tocenTokenIds?.length > 0) {
2162
+ addTocenBuyTxHandler({
2163
+ txBlock,
2164
+ nftType: tocenNftType,
2165
+ nftTokenIds: tocenTokenIds,
2166
+ price: tocenTotalPrice
2167
+ });
2168
+ }
2169
+ return new TransactionBlock3(txBlock);
2170
+ };
2171
+
2172
+ // src/methods/claimNfts/claimNfts.ts
2173
+ import { TransactionBlock as TransactionBlock4 } from "@mysten/sui.js/transactions";
2174
+
2175
+ // src/methods/claimNfts/addClaimNftsTxs.ts
2176
+ var addClaimTradeHoldTx = ({
2177
+ txBlock,
2178
+ sharedObjects,
2179
+ nftType,
2180
+ claimableTradeId,
2181
+ claimableSellerKiosk,
2182
+ claimableBuyerKiosk
2183
+ }) => {
2184
+ const { orderbook } = sharedObjects;
2185
+ const transferRequest = txBlock.moveCall({
2186
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::finish_trade",
2187
+ arguments: [
2188
+ txBlock.object(orderbook),
2189
+ txBlock.pure(claimableTradeId),
2190
+ txBlock.object(claimableSellerKiosk),
2191
+ txBlock.object(claimableBuyerKiosk)
2192
+ ],
2193
+ typeArguments: [nftType, "0x2::sui::SUI"]
2194
+ });
2195
+ confirmOBTranfer({ txBlock, sharedObjects, transferRequest, nftType });
2196
+ };
2197
+ var addClaimAcceptedBidNftTx = async ({
2198
+ txBlock,
2199
+ kioskTx,
2200
+ sharedObjects,
2201
+ nftTokenId,
2202
+ nftType
2203
+ }) => {
2204
+ const { transferPolicy } = sharedObjects;
2205
+ const [transferRequest] = txBlock.moveCall({
2206
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::claim_bid",
2207
+ arguments: [
2208
+ txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE),
2209
+ txBlock.object(TRADEPORT_KIOSK_BIDDING_ESCROW_KIOSK),
2210
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
2211
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
2212
+ txBlock.pure(nftTokenId),
2213
+ txBlock.object(transferPolicy)
2214
+ ],
2215
+ typeArguments: [nftType]
2216
+ });
2217
+ await resolveTransferPolicies({
2218
+ txBlock,
2219
+ kioskTx,
2220
+ nftType,
2221
+ price: "0",
2222
+ transferRequest,
2223
+ shouldSkipKioskLocking: true
2224
+ });
2225
+ };
2226
+ var addClaimTransferredNftTx = async ({
2227
+ txBlock,
2228
+ sharedObjects,
2229
+ kioskTx,
2230
+ nftTokenId,
2231
+ nftType
2232
+ }) => {
2233
+ const { transferPolicy } = sharedObjects;
2234
+ const [transferRequest] = txBlock.moveCall({
2235
+ target: "0x78eae99d1a7edae714b5de107f4b44ccbdf5f9ca6919498d9b024ef378dc13f7::kiosk_transfers::claim",
2236
+ arguments: [
2237
+ txBlock.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
2238
+ txBlock.object(TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK),
2239
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
2240
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
2241
+ txBlock.pure(nftTokenId),
2242
+ txBlock.object(transferPolicy)
2243
+ ],
2244
+ typeArguments: [nftType]
2245
+ });
2246
+ await resolveTransferPolicies({
2247
+ txBlock,
2248
+ kioskTx,
2249
+ nftType,
2250
+ price: "0",
2251
+ transferRequest,
2252
+ shouldSkipKioskLocking: true
2253
+ });
2254
+ };
2255
+
2256
+ // src/methods/claimNfts/claimNfts.ts
2257
+ var claimNfts = async ({
2258
+ nftIds,
2259
+ walletAddress
2260
+ }) => {
2261
+ const res = await gqlChainRequest({
2262
+ chain: "sui",
2263
+ query: fetchNftsById,
2264
+ variables: { nftIds }
2265
+ });
2266
+ if (res?.nfts?.length === 0) {
2267
+ throw new Error("No nfts found");
2268
+ }
2269
+ const txBlock = new TransactionBlock4();
2270
+ for (const nft of res.nfts) {
2271
+ if (!nft) {
2272
+ throw new Error("No nft found");
2273
+ }
2274
+ if (!nft?.chain_state?.claimable) {
2275
+ throw new Error(`Nft ID: ${nft?.id} is not claimable`);
2276
+ }
2277
+ const sharedObjects = await getSharedObjects(
2278
+ nft?.properties?.nft_type || nft?.contract?.properties?.nft_type
2279
+ );
2280
+ if (nft?.chain_state?.claimable_trade_id) {
2281
+ const txData = {
2282
+ txBlock,
2283
+ sharedObjects,
2284
+ nftType: getNftTypeFromNft(nft),
2285
+ claimableTradeId: nft?.chain_state?.claimable_trade_id,
2286
+ claimableSellerKiosk: nft?.chain_state?.claimable_seller_kiosk,
2287
+ claimableBuyerKiosk: nft?.chain_state?.claimable_buyer_kiosk
2288
+ };
2289
+ addClaimTradeHoldTx(txData);
2290
+ continue;
2291
+ }
2292
+ if (["accept-token-offer", "accept-collection-offer"]?.includes(
2293
+ nft?.chain_state?.claimable_reason
2294
+ )) {
2295
+ const txData = {
2296
+ txBlock,
2297
+ sharedObjects,
2298
+ claimer: walletAddress,
2299
+ nftType: getNftTypeFromNft(nft),
2300
+ nftTokenId: nft?.token_id,
2301
+ sellerKiosk: nft?.chain_state?.kiosk_id
2302
+ };
2303
+ await kioskTxWrapper({
2304
+ txBlock,
2305
+ kioskOwner: txData?.claimer,
2306
+ kiosk: txData?.sellerKiosk,
2307
+ async tx(kioskTx) {
2308
+ await addClaimAcceptedBidNftTx({ ...txData, kioskTx });
2309
+ }
2310
+ });
2311
+ continue;
2312
+ }
2313
+ if (nft?.chain_state?.claimable_reason === "offer-transfer") {
2314
+ const txData = {
2315
+ txBlock,
2316
+ sharedObjects,
2317
+ claimer: walletAddress,
2318
+ nftType: getNftTypeFromNft(nft),
2319
+ nftTokenId: nft?.token_id,
2320
+ sellerKiosk: nft?.chain_state?.kiosk_id
2321
+ };
2322
+ await kioskTxWrapper({
2323
+ txBlock,
2324
+ kioskOwner: txData?.claimer,
2325
+ kiosk: txData?.sellerKiosk,
2326
+ async tx(kioskTx) {
2327
+ await addClaimTransferredNftTx({ ...txData, kioskTx });
2328
+ }
2329
+ });
2330
+ }
2331
+ }
2332
+ return new TransactionBlock4(txBlock);
2333
+ };
2334
+
2335
+ // src/methods/listNfts/listNfts.ts
2336
+ import { TransactionBlock as TransactionBlock5 } from "@mysten/sui.js/transactions";
2337
+
2338
+ // src/helpers/getMarketFeePrice.ts
2339
+ var getMASCMarketFeePrice = (price) => {
2340
+ if (price * (MASC_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT) < 1) {
2341
+ return price * (MASC_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT);
2342
+ }
2343
+ return parseInt(
2344
+ (price * (MASC_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT))?.toFixed(0),
2345
+ 10
2346
+ );
2347
+ };
2348
+ var getBASCMarketFeePrice = (price) => {
2349
+ if (price * (BASC_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT) < 1) {
2350
+ return price * (BASC_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT);
2351
+ }
2352
+ return parseInt(
2353
+ (price * (BASC_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT))?.toFixed(0),
2354
+ 10
2355
+ );
2356
+ };
2357
+ var getDSLLegacyMarketFeePrice = (price) => {
2358
+ if (price * (DSL_LEGACY_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT) < 1) {
2359
+ return price * (DSL_LEGACY_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT);
2360
+ }
2361
+ return parseInt(
2362
+ (price * (DSL_LEGACY_ROYALTY_DECIMAL_PERCENT + TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT))?.toFixed(
2363
+ 0
2364
+ ),
2365
+ 10
2366
+ );
2367
+ };
2368
+ var getMarketFeePrice = ({ price, collectionId, walletId }) => {
2369
+ if (collectionId === "6824e1ff-477e-4810-9ba7-8d6387b68c7d") {
2370
+ return getBASCMarketFeePrice(price);
2371
+ }
2372
+ if (collectionId === "8568521c-73a3-4beb-b830-d1ff27a3f1ca") {
2373
+ return getMASCMarketFeePrice(price);
2374
+ }
2375
+ if (collectionId === "307c7e7a-be3a-43a5-ae44-37f3a37d01f9") {
2376
+ return getDSLLegacyMarketFeePrice(price);
2377
+ }
2378
+ let marketFeePrice = 0;
2379
+ if (!COLLECTION_IDS_WITH_ZERO_COMMISSION?.includes(collectionId)) {
2380
+ marketFeePrice = price * TRADEPORT_DEFAULT_FEE_DECIMAL_PERCENT;
2381
+ }
2382
+ if (marketFeePrice < 1) {
2383
+ return marketFeePrice;
2384
+ }
2385
+ return parseInt(marketFeePrice?.toFixed(0), 10);
2386
+ };
2387
+
2388
+ // src/utils/parseSUI.ts
2389
+ var parseSUI = (num) => parseInt((1e9 * num).toFixed(0), 10);
2390
+
2391
+ // src/methods/listNfts/addListTxs.ts
2392
+ async function addOriginByteListTx({
2393
+ txBlock,
2394
+ sharedObjects,
2395
+ nftTokenId,
2396
+ nftType,
2397
+ seller,
2398
+ listPrice,
2399
+ collectionId,
2400
+ sellerKiosk
2401
+ }) {
2402
+ const { orderbook } = sharedObjects;
2403
+ const { kiosk, isNewKiosk } = await getOrCreateOBKiosk({
2404
+ txBlock,
2405
+ address: seller,
2406
+ kioskToUseIfExists: sellerKiosk
2407
+ });
2408
+ if (isNewKiosk) {
2409
+ depositItemIntoOBKiosk({
2410
+ txBlock,
2411
+ kiosk: sellerKiosk,
2412
+ nftTokenId,
2413
+ nftType
2414
+ });
2415
+ }
2416
+ const parsedListPrice = parseSUI(listPrice);
2417
+ const marketFeePrice = getMarketFeePrice({
2418
+ price: parsedListPrice,
2419
+ collectionId,
2420
+ walletId: seller
2421
+ });
2422
+ txBlock.moveCall({
2423
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::create_ask_with_commission",
2424
+ arguments: [
2425
+ txBlock.object(orderbook),
2426
+ txBlock.object(kiosk),
2427
+ txBlock.pure(parsedListPrice),
2428
+ txBlock.pure(nftTokenId),
2429
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS),
2430
+ txBlock.pure(marketFeePrice)
2431
+ ],
2432
+ typeArguments: [nftType, "0x2::sui::SUI"]
2433
+ });
2434
+ if (isNewKiosk) {
2435
+ await shareOriginByteKiosk({ txBlock, kiosk });
2436
+ }
2437
+ }
2438
+ function addTradePortListTx({
2439
+ txBlock,
2440
+ nftTokenId,
2441
+ borrowedItem,
2442
+ nftType,
2443
+ collectionId,
2444
+ listPrice,
2445
+ seller
2446
+ }) {
2447
+ const parsedListPrice = parseSUI(listPrice);
2448
+ const marketFeePrice = getMarketFeePrice({
2449
+ price: parsedListPrice,
2450
+ collectionId,
2451
+ walletId: seller
2452
+ });
2453
+ txBlock.moveCall({
2454
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::list",
2455
+ arguments: [
2456
+ txBlock.object(TRADEPORT_LISTING_STORE),
2457
+ borrowedItem ? txBlock.object(borrowedItem) : txBlock.pure(nftTokenId),
2458
+ txBlock.pure(parsedListPrice),
2459
+ txBlock.pure(marketFeePrice),
2460
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2461
+ ],
2462
+ typeArguments: [nftType]
2463
+ });
2464
+ }
2465
+ async function addTradePortKioskListTx({
2466
+ txBlock,
2467
+ kioskTx,
2468
+ nftTokenId,
2469
+ nftType,
2470
+ collectionId,
2471
+ listPrice,
2472
+ seller
2473
+ }) {
2474
+ const parsedListPrice = parseSUI(listPrice);
2475
+ const marketFeePrice = getMarketFeePrice({
2476
+ price: parsedListPrice,
2477
+ collectionId,
2478
+ walletId: seller
2479
+ });
2480
+ txBlock.moveCall({
2481
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_listings::list",
2482
+ arguments: [
2483
+ txBlock.object(TRADEPORT_KIOSK_LISTING_STORE),
2484
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
2485
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
2486
+ txBlock.pure(nftTokenId),
2487
+ txBlock.pure(Number(parsedListPrice) + marketFeePrice),
2488
+ txBlock.pure(marketFeePrice),
2489
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2490
+ ],
2491
+ typeArguments: [nftType]
2492
+ });
2493
+ }
2494
+ async function addTradePortListTxHandler(txData) {
2495
+ if (isOriginByteTx(txData?.sharedObjects)) {
2496
+ await addOriginByteListTx(txData);
2497
+ return;
2498
+ }
2499
+ if (!await hasTransferPolicyRules(txData?.nftType) && txData?.sellerKiosk) {
2500
+ return kioskTxWrapper({
2501
+ txBlock: txData?.txBlock,
2502
+ kioskOwner: txData?.seller,
2503
+ kiosk: txData?.sellerKiosk,
2504
+ async tx(kioskTx) {
2505
+ const borrowedItem = kioskTx.take({
2506
+ itemId: txData?.nftTokenId,
2507
+ itemType: txData?.nftType
2508
+ });
2509
+ addTradePortListTx({ ...txData, borrowedItem });
2510
+ }
2511
+ });
2512
+ }
2513
+ if (txData?.sellerKiosk) {
2514
+ return kioskTxWrapper({
2515
+ txBlock: txData?.txBlock,
2516
+ kioskOwner: txData?.seller,
2517
+ kiosk: txData?.sellerKiosk,
2518
+ async tx(kioskTx) {
2519
+ await addTradePortKioskListTx({
2520
+ ...txData,
2521
+ kioskTx
2522
+ });
2523
+ }
2524
+ });
2525
+ }
2526
+ if (!txData?.sellerKiosk && await hasTransferPolicyRules(txData?.nftType)) {
2527
+ return kioskTxWrapper({
2528
+ txBlock: txData?.txBlock,
2529
+ kioskOwner: txData?.seller,
2530
+ kiosk: txData?.sellerKiosk,
2531
+ async tx(kioskTx) {
2532
+ kioskTx.place({
2533
+ item: txData?.nftTokenId,
2534
+ itemType: txData?.nftType
2535
+ });
2536
+ await addTradePortKioskListTx({
2537
+ ...txData,
2538
+ kioskTx
2539
+ });
2540
+ }
2541
+ });
2542
+ }
2543
+ addTradePortListTx(txData);
2544
+ }
2545
+
2546
+ // src/methods/listNfts/addRelistTxs.ts
2547
+ function addTradePortRelistTx({
2548
+ txBlock,
2549
+ nftType,
2550
+ collectionId,
2551
+ listingNonce,
2552
+ listPrice,
2553
+ seller
2554
+ }) {
2555
+ const parsedListPrice = parseSUI(listPrice);
2556
+ const marketFeePrice = getMarketFeePrice({
2557
+ price: parsedListPrice,
2558
+ collectionId,
2559
+ walletId: seller
2560
+ });
2561
+ txBlock.moveCall({
2562
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::listings::relist",
2563
+ arguments: [
2564
+ txBlock.object(TRADEPORT_LISTING_STORE),
2565
+ txBlock.pure(listingNonce),
2566
+ txBlock.pure(parsedListPrice),
2567
+ txBlock.pure(marketFeePrice),
2568
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2569
+ ],
2570
+ typeArguments: [nftType]
2571
+ });
2572
+ }
2573
+ function addBlueMoveRelistTx(txData) {
2574
+ const { txBlock, nftTokenId, nftType, listPrice } = txData;
2575
+ const borrowedItem = txBlock.moveCall({
2576
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::marketplace::delist",
2577
+ arguments: [txBlock.object(BLUEMOVE_MARKET_CONFIG_OBJECT), txBlock.pure(nftTokenId)],
2578
+ typeArguments: [nftType, nftType]
2579
+ });
2580
+ addTradePortListTx({ ...txData, listPrice, borrowedItem });
2581
+ }
2582
+ function addTocenRelistTx(txData) {
2583
+ const { txBlock, nftTokenId, nftType, listPrice } = txData;
2584
+ const borrowedItem = txBlock.moveCall({
2585
+ target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::delist",
2586
+ arguments: [txBlock.pure(TOCEN_MARKETPLACE_OBJECT), txBlock.pure(nftTokenId)],
2587
+ typeArguments: [nftType]
2588
+ });
2589
+ addTradePortListTx({ ...txData, listPrice, borrowedItem });
2590
+ }
2591
+
2592
+ // src/methods/relistNft/relistNft.ts
2593
+ async function relistNft({ txBlock, nft, listPrice, sharedObjects, walletAddress }) {
2594
+ const txData = {
2595
+ txBlock,
2596
+ sharedObjects,
2597
+ nftTokenId: nft?.token_id,
2598
+ nftType: getNftTypeFromNft(nft),
2599
+ listingNonce: nft?.listings?.[0]?.nonce,
2600
+ price: nft?.listings?.[0]?.price,
2601
+ sellerKiosk: nft?.chain_state?.kiosk_id,
2602
+ collectionId: nft?.collection_id,
2603
+ seller: walletAddress
2604
+ };
2605
+ switch (nft?.listings?.[0]?.market_name) {
2606
+ case "tradeport":
2607
+ if (!isOriginByteTx(txData?.sharedObjects) && txData?.listingNonce && await isNonKioskListing(txData?.listingNonce)) {
2608
+ addTradePortRelistTx({ ...txData, listPrice });
2609
+ } else {
2610
+ return kioskTxWrapper({
2611
+ txBlock: txData?.txBlock,
2612
+ kioskOwner: txData?.seller,
2613
+ kiosk: txData?.sellerKiosk,
2614
+ async tx(kioskTx) {
2615
+ await addTradePortKioskUnlistTx({
2616
+ ...txData,
2617
+ kioskTx
2618
+ });
2619
+ await addTradePortKioskListTx({
2620
+ ...txData,
2621
+ kioskTx,
2622
+ listPrice
2623
+ });
2624
+ }
2625
+ });
2626
+ }
2627
+ break;
2628
+ case "hyperspace":
2629
+ await addHyperspaceUnlistTxHandler(txData);
2630
+ await addTradePortListTxHandler({ ...txData, listPrice });
2631
+ break;
2632
+ case "bluemove":
2633
+ if (!isOriginByteTx(txData?.sharedObjects) && !txData?.sellerKiosk) {
2634
+ addBlueMoveRelistTx({ ...txData, listPrice });
2635
+ } else {
2636
+ await addBluemoveUnlistTxHandler(txData);
2637
+ await addTradePortListTxHandler({ ...txData, listPrice });
2638
+ }
2639
+ break;
2640
+ case "clutchy":
2641
+ await addClutchyUnlistTxHandler(txData);
2642
+ await addTradePortListTxHandler({ ...txData, listPrice });
2643
+ break;
2644
+ case "souffl3":
2645
+ break;
2646
+ case "somis":
2647
+ break;
2648
+ case "keepsake":
2649
+ break;
2650
+ case "tocen":
2651
+ addTocenRelistTx({ ...txData, listPrice });
2652
+ break;
2653
+ default:
2654
+ throw new Error("Marketplace not supported");
2655
+ }
2656
+ }
2657
+
2658
+ // src/methods/listNfts/listNfts.ts
2659
+ var listNfts = async ({ nfts, walletAddress }) => {
2660
+ const res = await gqlChainRequest({
2661
+ chain: "sui",
2662
+ query: fetchNftsWithListingsById,
2663
+ variables: { nftIds: nfts.map((nft) => nft.id) }
2664
+ });
2665
+ if (res?.nfts?.length === 0) {
2666
+ throw new Error("No nfts found");
2667
+ }
2668
+ const txBlock = new TransactionBlock5();
2669
+ for (const nft of res.nfts) {
2670
+ const sharedObjects = await getSharedObjects(
2671
+ nft?.properties?.nft_type || nft?.contract?.properties?.nft_type
2672
+ );
2673
+ if (nft?.listed) {
2674
+ await relistNft({
2675
+ txBlock,
2676
+ sharedObjects,
2677
+ nft,
2678
+ listPrice: nfts?.find((n) => n.id === nft?.id)?.listPrice,
2679
+ walletAddress
2680
+ });
2681
+ } else {
2682
+ const listTxData = {
2683
+ txBlock,
2684
+ sharedObjects,
2685
+ seller: walletAddress,
2686
+ collectionId: nft?.collection_id,
2687
+ nftTokenId: nft?.token_id,
2688
+ nftType: getNftTypeFromNft(nft),
2689
+ listPrice: nfts?.find((n) => n.id === nft?.id)?.listPrice,
2690
+ sellerKiosk: nft?.chain_state?.kiosk_id
2691
+ };
2692
+ await addTradePortListTxHandler(listTxData);
2693
+ }
2694
+ }
2695
+ return new TransactionBlock5(txBlock);
2696
+ };
2697
+
2698
+ // src/methods/placeCollectionBids/placeCollectionBids.ts
2699
+ import { TransactionBlock as TransactionBlock6 } from "@mysten/sui.js/transactions";
2700
+
2701
+ // src/graphql/queries/fetchCollectionsById.ts
2702
+ import { gql as gql13 } from "graphql-request";
2703
+ var fetchCollectionsById = gql13`
2704
+ query fetchCollectionsById($collectionIds: [uuid!]) {
2705
+ collections(where: { id: { _in: $collectionIds } }) {
2706
+ id
2707
+ contract {
2708
+ properties
2709
+ }
2710
+ }
2711
+ }
2712
+ `;
2713
+ var fetchCollectionsByIdWithOneNft = gql13`
2714
+ query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
2715
+ collections(where: { id: { _in: $collectionIds } }) {
2716
+ id
2717
+ contract {
2718
+ properties
2719
+ }
2720
+ nfts(limit: 1) {
2721
+ id
2722
+ properties
2723
+ contract {
2724
+ properties
2725
+ }
2726
+ }
2727
+ }
2728
+ }
2729
+ `;
2730
+
2731
+ // src/helpers/getTradeportBiddingContractParsedBidAmount.ts
2732
+ var getTradeportBiddingContractParsedBidAmount = ({ bidAmount, collectionId }) => {
2733
+ let amount = bidAmount;
2734
+ if (collectionId === "8568521c-73a3-4beb-b830-d1ff27a3f1ca") {
2735
+ amount = bidAmount - bidAmount * MASC_ROYALTY_DECIMAL_PERCENT;
2736
+ }
2737
+ if (collectionId === "6824e1ff-477e-4810-9ba7-8d6387b68c7d") {
2738
+ amount = bidAmount - bidAmount * BASC_ROYALTY_DECIMAL_PERCENT;
2739
+ }
2740
+ if (collectionId === "307c7e7a-be3a-43a5-ae44-37f3a37d01f9") {
2741
+ amount = bidAmount - bidAmount * DSL_LEGACY_ROYALTY_DECIMAL_PERCENT;
2742
+ }
2743
+ return Number(parseSUI(amount));
2744
+ };
2745
+
2746
+ // src/helpers/hasRoyaltyRule.ts
2747
+ var hasRoyaltyRule = async (nftType) => {
2748
+ const nftTypeSplit = nftType?.split("::");
2749
+ if (nftTypeSplit?.[0])
2750
+ nftTypeSplit[0] = addLeadingZerosAfter0x(nftTypeSplit[0]);
2751
+ const res = await kioskClient_default.getTransferPolicies({ type: nftTypeSplit?.join("::") });
2752
+ return res?.some(
2753
+ (policy) => policy?.rules?.filter((rule) => rule?.includes("royalty_rule"))?.length > 0
2754
+ );
2755
+ };
2756
+
2757
+ // src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts
2758
+ function addTradePortCollectionBidTx({
2759
+ txBlock,
2760
+ collectionId,
2761
+ nftType,
2762
+ bidAmount,
2763
+ bidder
2764
+ }) {
2765
+ const parsedBidAmount = getTradeportBiddingContractParsedBidAmount({ bidAmount, collectionId });
2766
+ const marketFeePrice = getMarketFeePrice({
2767
+ price: Number(parseSUI(bidAmount)),
2768
+ collectionId,
2769
+ walletId: bidder
2770
+ });
2771
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(parsedBidAmount + marketFeePrice)] });
2772
+ txBlock.moveCall({
2773
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::collection_bid",
2774
+ arguments: [
2775
+ txBlock.object(TRADEPORT_BIDDING_STORE),
2776
+ txBlock.pure(parsedBidAmount),
2777
+ txBlock.object(coin),
2778
+ txBlock.pure(marketFeePrice),
2779
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2780
+ ],
2781
+ typeArguments: [nftType]
2782
+ });
2783
+ destroyZeroCoin({ txBlock, coin });
2784
+ }
2785
+ function addTradePortKioskCollectionBidTx({
2786
+ txBlock,
2787
+ collectionId,
2788
+ nftType,
2789
+ bidAmount,
2790
+ sharedObjects,
2791
+ bidder,
2792
+ royaltyRulePackageId,
2793
+ royaltyRuleModule
2794
+ }) {
2795
+ const { transferPolicy } = sharedObjects;
2796
+ const parsedBidAmount = Number(parseSUI(bidAmount));
2797
+ const marketFeePrice = getMarketFeePrice({
2798
+ price: parsedBidAmount,
2799
+ collectionId,
2800
+ walletId: bidder
2801
+ });
2802
+ const fee = txBlock.moveCall({
2803
+ target: `${royaltyRulePackageId}::${royaltyRuleModule}::fee_amount`,
2804
+ arguments: [txBlock.object(transferPolicy), txBlock.pure(parsedBidAmount)],
2805
+ typeArguments: [nftType]
2806
+ });
2807
+ const [coin1, coin2] = splitCoins({
2808
+ txBlock,
2809
+ amounts: [txBlock.pure(parsedBidAmount + marketFeePrice), txBlock.object(fee)]
2810
+ });
2811
+ if (!coin1 || !coin2)
2812
+ throw new Error("Coin could not be split");
2813
+ txBlock.mergeCoins(txBlock.object(coin1), [txBlock.object(coin2)]);
2814
+ txBlock.moveCall({
2815
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::collection_bid",
2816
+ arguments: [
2817
+ txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE),
2818
+ txBlock.pure(parsedBidAmount),
2819
+ txBlock.object(coin1),
2820
+ txBlock.pure(marketFeePrice),
2821
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2822
+ ],
2823
+ typeArguments: [nftType]
2824
+ });
2825
+ destroyZeroCoin({ txBlock, coin: coin1 });
2826
+ }
2827
+ async function addOriginByteCollectionBidTx({
2828
+ txBlock,
2829
+ collectionId,
2830
+ nftType,
2831
+ bidAmount,
2832
+ bidder,
2833
+ sharedObjects,
2834
+ bidderKiosk
2835
+ }) {
2836
+ const { orderbook } = sharedObjects;
2837
+ const parsedBidAmount = Number(parseSUI(bidAmount));
2838
+ const marketFeePrice = getMarketFeePrice({
2839
+ price: parsedBidAmount,
2840
+ collectionId,
2841
+ walletId: bidder
2842
+ });
2843
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(parsedBidAmount + marketFeePrice)] });
2844
+ txBlock.moveCall({
2845
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::create_bid_with_commission",
2846
+ arguments: [
2847
+ txBlock.object(orderbook),
2848
+ txBlock.object(bidderKiosk),
2849
+ txBlock.pure(parsedBidAmount),
2850
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS),
2851
+ txBlock.pure(marketFeePrice),
2852
+ txBlock.object(coin)
2853
+ ],
2854
+ typeArguments: [nftType, "0x2::sui::SUI"]
2855
+ });
2856
+ destroyZeroCoin({ txBlock, coin });
2857
+ }
2858
+ async function addTradePortPlaceCollectionBidTxHandler(txData) {
2859
+ if (await hasRoyaltyRule(txData?.nftType)) {
2860
+ const royaltyRuleModule = txData?.collectionId === "fa58ae52-b18d-4179-a2d4-c2471ede5f14" ? "kiosk_royalty_rule" : "royalty_rule";
2861
+ const royaltyRulePackageId = await getRulePackageId(txData.nftType, royaltyRuleModule);
2862
+ addTradePortKioskCollectionBidTx({ ...txData, royaltyRulePackageId, royaltyRuleModule });
2863
+ return;
2864
+ }
2865
+ addTradePortCollectionBidTx(txData);
2866
+ }
2867
+
2868
+ // src/methods/placeCollectionBids/placeCollectionBids.ts
2869
+ var placeCollectionBids = async ({
2870
+ collections,
2871
+ walletAddress
2872
+ }) => {
2873
+ const res = await gqlChainRequest({
2874
+ chain: "sui",
2875
+ query: collections?.some(
2876
+ (collection) => collection.id === "fa58ae52-b18d-4179-a2d4-c2471ede5f14" || // S-Card
2877
+ collection.id === "ca37bbb2-4398-46cb-b467-8a834d2d2612" || // S-Card mint ticket
2878
+ collection.id === "c8e19183-3a9e-4312-939f-c63a1416e344" || // Panzerdogs
2879
+ collection.id === "819eabe2-1565-4c3a-a9f6-1b5fca48e09a"
2880
+ // Panzerdog Tanks
2881
+ ) ? fetchCollectionsByIdWithOneNft : fetchCollectionsById,
2882
+ variables: { collectionIds: collections.map((collection) => collection.id) }
2883
+ });
2884
+ if (res?.collections?.length === 0) {
2885
+ throw new Error("No collection found");
2886
+ }
2887
+ if (res?.collections?.length === 0) {
2888
+ throw new Error("No collection found");
2889
+ }
2890
+ const txBlock = new TransactionBlock6();
2891
+ for (const collection of res.collections) {
2892
+ const nftType = collections?.some(
2893
+ (collection2) => collection2.id === "fa58ae52-b18d-4179-a2d4-c2471ede5f14" || // S-Card
2894
+ collection2.id === "ca37bbb2-4398-46cb-b467-8a834d2d2612" || // S-Card mint ticket
2895
+ collection2.id === "c8e19183-3a9e-4312-939f-c63a1416e344" || // Panzerdogs
2896
+ collection2.id === "819eabe2-1565-4c3a-a9f6-1b5fca48e09a"
2897
+ // Panzerdog Tanks
2898
+ ) ? getNftTypeFromNft(collection?.nfts?.[0]) : collection.id === "07231735-96de-4710-8e11-52c61a482578" ? "0x034c162f6b594cb5a1805264dd01ca5d80ce3eca6522e6ee37fd9ebfb9d3ddca::factory::PrimeMachin" : collection?.contract?.properties?.nft_type;
2899
+ const sharedObjects = await getSharedObjects(nftType);
2900
+ const txData = {
2901
+ txBlock,
2902
+ sharedObjects,
2903
+ bidder: walletAddress,
2904
+ collectionId: collection?.id,
2905
+ nftType,
2906
+ bidAmount: collections?.find((c) => c.id === collection?.id)?.bidAmount
2907
+ };
2908
+ const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
2909
+ if (isOriginByteTx(txData?.sharedObjects)) {
2910
+ const { kiosk: bidderKiosk, isNewKiosk: isNewBidderKiosk } = await getOrCreateOBKiosk({
2911
+ txBlock,
2912
+ address: txData.bidder
2913
+ });
2914
+ for (let i = 0; i < numOfBids; i++) {
2915
+ await addOriginByteCollectionBidTx({ ...txData, bidderKiosk });
2916
+ }
2917
+ if (isNewBidderKiosk) {
2918
+ await shareOriginByteKiosk({ txBlock, kiosk: bidderKiosk });
2919
+ }
2920
+ } else {
2921
+ for (let i = 0; i < numOfBids; i++) {
2922
+ await addTradePortPlaceCollectionBidTxHandler(txData);
2923
+ }
2924
+ }
2925
+ }
2926
+ return new TransactionBlock6(txBlock);
2927
+ };
2928
+
2929
+ // src/methods/placeNftBids/placeNftBids.ts
2930
+ import { TransactionBlock as TransactionBlock7 } from "@mysten/sui.js/transactions";
2931
+
2932
+ // src/methods/placeNftBids/addPlaceNftBidTxs.ts
2933
+ function addTradePortPlaceNftBidTx({
2934
+ txBlock,
2935
+ collectionId,
2936
+ nftTokenId,
2937
+ nftType,
2938
+ bidAmount,
2939
+ bidder
2940
+ }) {
2941
+ const parsedBidAmount = getTradeportBiddingContractParsedBidAmount({ bidAmount, collectionId });
2942
+ const marketFeePrice = getMarketFeePrice({
2943
+ price: Number(parseSUI(bidAmount)),
2944
+ collectionId,
2945
+ walletId: bidder
2946
+ });
2947
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(parsedBidAmount + marketFeePrice)] });
2948
+ txBlock.moveCall({
2949
+ target: "0x398aae1ad267d989dcc99ba449b0a30101a6b851ec1284ccddab5937df66bfcf::biddings::bid",
2950
+ arguments: [
2951
+ txBlock.object(TRADEPORT_BIDDING_STORE),
2952
+ txBlock.pure(nftTokenId),
2953
+ txBlock.pure(parsedBidAmount),
2954
+ txBlock.object(coin),
2955
+ txBlock.pure(marketFeePrice),
2956
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2957
+ ],
2958
+ typeArguments: [nftType]
2959
+ });
2960
+ destroyZeroCoin({ txBlock, coin });
2961
+ }
2962
+ function addTradePortKioskPlaceNftBidTx({
2963
+ txBlock,
2964
+ sharedObjects,
2965
+ collectionId,
2966
+ nftTokenId,
2967
+ nftType,
2968
+ bidAmount,
2969
+ bidder,
2970
+ royaltyRulePackageId
2971
+ }) {
2972
+ const { transferPolicy } = sharedObjects;
2973
+ const bidPrice = Number(parseSUI(bidAmount));
2974
+ const marketFeePrice = getMarketFeePrice({ price: bidPrice, collectionId, walletId: bidder });
2975
+ const royaltyCoin = txBlock.moveCall({
2976
+ target: `${royaltyRulePackageId}::royalty_rule::fee_amount`,
2977
+ arguments: [txBlock.object(transferPolicy), txBlock.pure(bidPrice?.toString())],
2978
+ typeArguments: [nftType]
2979
+ });
2980
+ const [coin1, coin2] = splitCoins({
2981
+ txBlock,
2982
+ amounts: [txBlock.pure(bidPrice + marketFeePrice), txBlock.object(royaltyCoin)]
2983
+ });
2984
+ txBlock.mergeCoins(txBlock.object(coin1), [txBlock.object(coin2)]);
2985
+ txBlock.moveCall({
2986
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::bid",
2987
+ arguments: [
2988
+ txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE),
2989
+ txBlock.pure(nftTokenId),
2990
+ txBlock.pure(bidPrice),
2991
+ txBlock.object(coin1),
2992
+ txBlock.pure(marketFeePrice),
2993
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
2994
+ ],
2995
+ typeArguments: [nftType]
2996
+ });
2997
+ destroyZeroCoin({ txBlock, coin: coin1 });
2998
+ }
2999
+ async function addOriginBytePlaceNftBidTx({
3000
+ txBlock,
3001
+ nftTokenId,
3002
+ collectionId,
3003
+ bidAmount,
3004
+ bidder
3005
+ }) {
3006
+ const { kiosk: bidderKiosk, isNewKiosk: isNewBidderKiosk } = await getOrCreateOBKiosk({
3007
+ txBlock,
3008
+ address: bidder,
3009
+ createMethod: "create_for_sender"
3010
+ });
3011
+ const parsedBidAmount = Number(parseSUI(bidAmount));
3012
+ const marketFeePrice = getMarketFeePrice({
3013
+ price: parsedBidAmount,
3014
+ collectionId,
3015
+ walletId: bidder
3016
+ });
3017
+ const [coin] = splitCoins({ txBlock, amounts: [txBlock.pure(parsedBidAmount + marketFeePrice)] });
3018
+ txBlock.moveCall({
3019
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::create_bid_with_commission",
3020
+ arguments: [
3021
+ isNewBidderKiosk ? txBlock.object(bidderKiosk) : txBlock.pure(bidderKiosk),
3022
+ txBlock.pure(nftTokenId),
3023
+ txBlock.pure(parsedBidAmount),
3024
+ txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS),
3025
+ txBlock.pure(marketFeePrice),
3026
+ txBlock.object(coin)
3027
+ ],
3028
+ typeArguments: ["0x2::sui::SUI"]
3029
+ });
3030
+ destroyZeroCoin({ txBlock, coin });
3031
+ }
3032
+ async function addTradePortPlaceNftBidTxHandler(txData) {
3033
+ if (isOriginByteTx(txData?.sharedObjects)) {
3034
+ await addOriginBytePlaceNftBidTx(txData);
3035
+ return;
3036
+ }
3037
+ if (await hasTransferPolicyRules(txData?.nftType) && txData?.sellerKiosk) {
3038
+ const royaltyRulePackageId = await getRulePackageId(txData.nftType, "royalty_rule");
3039
+ addTradePortKioskPlaceNftBidTx({ ...txData, royaltyRulePackageId });
3040
+ return;
3041
+ }
3042
+ addTradePortPlaceNftBidTx(txData);
3043
+ }
3044
+
3045
+ // src/methods/placeNftBids/placeNftBids.ts
3046
+ var placeNftBids = async ({
3047
+ nfts,
3048
+ walletAddress
3049
+ }) => {
3050
+ const res = await gqlChainRequest({
3051
+ chain: "sui",
3052
+ query: fetchNftsById,
3053
+ variables: { nftIds: nfts.map((nft) => nft.id) }
3054
+ });
3055
+ if (res?.nfts?.length === 0) {
3056
+ throw new Error("No nfts found");
3057
+ }
3058
+ const txBlock = new TransactionBlock7();
3059
+ for (const nft of res.nfts) {
3060
+ const sharedObjects = await getSharedObjects(
3061
+ nft?.properties?.nft_type || nft?.contract?.properties?.nft_type
3062
+ );
3063
+ const txData = {
3064
+ txBlock,
3065
+ sharedObjects,
3066
+ bidder: walletAddress,
3067
+ collectionId: nft?.collection_id,
3068
+ nftTokenId: nft?.token_id,
3069
+ nftType: nft?.properties?.nft_type || nft?.contract?.properties?.nft_type,
3070
+ bidAmount: nfts?.find((n) => n.id === nft?.id)?.bidAmount,
3071
+ sellerKiosk: nft?.chain_state?.kiosk_id
3072
+ };
3073
+ await addTradePortPlaceNftBidTxHandler(txData);
3074
+ }
3075
+ return new TransactionBlock7(txBlock);
3076
+ };
3077
+
3078
+ // src/methods/removeCollectionBid/removeCollectionBid.ts
3079
+ import { TransactionBlock as TransactionBlock8 } from "@mysten/sui.js/transactions";
3080
+
3081
+ // src/methods/removeNftBids/addRemoveNftBidTxs.ts
3082
+ function addTradeportRemoveNftBidTx({ txBlock, bidNonce, nftType }) {
3083
+ txBlock.moveCall({
3084
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::cancel_bid",
3085
+ arguments: [txBlock.object(TRADEPORT_BIDDING_STORE), txBlock.pure(bidNonce)],
3086
+ typeArguments: [nftType]
3087
+ });
3088
+ }
3089
+ function addTradeportKioskRemoveNftBidTx({ txBlock, bidNonce, nftType }) {
3090
+ txBlock.moveCall({
3091
+ target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::cancel_bid",
3092
+ arguments: [txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE), txBlock.pure(bidNonce)],
3093
+ typeArguments: [nftType]
3094
+ });
3095
+ }
3096
+ function addOriginByteRemoveNftBidTx({ txBlock, bidNonce }) {
3097
+ txBlock.moveCall({
3098
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::close_bid",
3099
+ arguments: [txBlock.pure(bidNonce)],
3100
+ typeArguments: ["0x2::sui::SUI"]
3101
+ });
3102
+ }
3103
+ function addBluemoveRemoveNftBidTx({
3104
+ txBlock,
3105
+ bidNonce,
3106
+ nftTokenId,
3107
+ nftType
3108
+ }) {
3109
+ txBlock.moveCall({
3110
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_item::cancel_offer_nft",
3111
+ arguments: [
3112
+ txBlock.object(BLUEMOVE_OFFER_DATA_OBJECT),
3113
+ txBlock.pure(nftTokenId),
3114
+ txBlock.pure(bidNonce)
3115
+ ],
3116
+ typeArguments: [nftType]
3117
+ });
3118
+ }
3119
+ function addTocenRemoveNftBidTx({ txBlock, nftTokenId, bidAmount }) {
3120
+ txBlock.moveCall({
3121
+ target: "0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::cancel_offer",
3122
+ arguments: [
3123
+ txBlock.pure(TOCEN_MARKETPLACE_OBJECT),
3124
+ txBlock.pure(nftTokenId),
3125
+ txBlock.pure(bidAmount)
3126
+ ],
3127
+ typeArguments: []
3128
+ });
3129
+ }
3130
+ async function addTradePortRemoveNftBidTxHandler(txData) {
3131
+ const bidType = await getObjectType(txData?.bidNonce);
3132
+ if (isOriginByteBid(bidType)) {
3133
+ addOriginByteRemoveNftBidTx(txData);
3134
+ return;
3135
+ }
3136
+ if (isTradePortKioskBid(bidType)) {
3137
+ addTradeportKioskRemoveNftBidTx(txData);
3138
+ return;
3139
+ }
3140
+ addTradeportRemoveNftBidTx(txData);
3141
+ }
3142
+
3143
+ // src/methods/removeCollectionBid/addRemoveCollectionBidTxs.ts
3144
+ function addTradeportRemoveCollectionBidTx({
3145
+ txBlock,
3146
+ nftType,
3147
+ bidNonce
3148
+ }) {
3149
+ txBlock.moveCall({
3150
+ target: "0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::cancel_bid",
3151
+ arguments: [txBlock.object(TRADEPORT_BIDDING_STORE), txBlock.pure(bidNonce)],
3152
+ typeArguments: [nftType]
3153
+ });
3154
+ }
3155
+ function addTradePortKioskRemoveCollectionBidTx(txData) {
3156
+ addTradeportKioskRemoveNftBidTx(txData);
3157
+ }
3158
+ function addOriginByteRemoveCollectionBidTx({
3159
+ txBlock,
3160
+ nftType,
3161
+ bidAmount,
3162
+ bidder,
3163
+ sharedObjects
3164
+ }) {
3165
+ const { orderbook } = sharedObjects;
3166
+ const [coin] = txBlock.moveCall({
3167
+ target: "0x2::coin::zero",
3168
+ arguments: [],
3169
+ typeArguments: ["0x2::sui::SUI"]
3170
+ });
3171
+ txBlock.moveCall({
3172
+ target: "0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::orderbook::cancel_bid",
3173
+ arguments: [txBlock.object(orderbook), txBlock.pure(bidAmount), txBlock.object(coin)],
3174
+ typeArguments: [nftType, "0x2::sui::SUI"]
3175
+ });
3176
+ txBlock.transferObjects([txBlock.object(coin)], txBlock.pure(addLeadingZerosAfter0x(bidder)));
3177
+ }
3178
+ function addBluemoveRemoveCollectionBidTx({
3179
+ txBlock,
3180
+ nftType,
3181
+ bidNonce
3182
+ }) {
3183
+ txBlock.moveCall({
3184
+ target: "0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_collection::cancel_offer_collection",
3185
+ arguments: [txBlock.object(BLUEMOVE_OFFER_COLLECTION_DATA_OBJECT), txBlock.pure(bidNonce)],
3186
+ typeArguments: [nftType]
3187
+ });
3188
+ }
3189
+ function addBluemoveKioskRemoveCollectionBidTx({
3190
+ txBlock,
3191
+ nftType,
3192
+ bidNonce
3193
+ }) {
3194
+ txBlock.moveCall({
3195
+ target: "0xcc97b74ed95c8e8a3ed88050a898727dee37896da579fc400d482b64db6149ff::kiosk_offer_collection_v2::cancel_offer_collection_v2",
3196
+ arguments: [
3197
+ txBlock.object(BLUEMOVE_KIOSK_OFFER_COLLECTION_DATA_OBJECT),
3198
+ txBlock.pure(bidNonce)
3199
+ ],
3200
+ typeArguments: [nftType]
3201
+ });
3202
+ }
3203
+ async function addTradePortRemoveCollectionBidTxHandler(txData) {
3204
+ const bidType = await getObjectType(txData?.bidNonce);
3205
+ if (isOriginByteBid(bidType)) {
3206
+ addOriginByteRemoveCollectionBidTx(txData);
3207
+ return;
3208
+ }
3209
+ if (isTradePortKioskBid(bidType)) {
3210
+ addTradePortKioskRemoveCollectionBidTx(txData);
3211
+ return;
3212
+ }
3213
+ addTradeportRemoveCollectionBidTx(txData);
3214
+ }
3215
+ async function addBluemoveRemoveCollectionBidTxHandler(txData) {
3216
+ const bidType = await getObjectType(txData?.bidNonce);
3217
+ if (isOriginByteBid(bidType)) {
3218
+ addOriginByteRemoveCollectionBidTx(txData);
3219
+ return;
3220
+ }
3221
+ if (isBluemoveKioskBid(txData?.bidNonce)) {
3222
+ addBluemoveKioskRemoveCollectionBidTx(txData);
3223
+ return;
3224
+ }
3225
+ addBluemoveRemoveCollectionBidTx(txData);
3226
+ }
3227
+ async function addClutchyRemoveCollectionBidTxHandler(txData) {
3228
+ addOriginByteRemoveCollectionBidTx(txData);
3229
+ }
3230
+
3231
+ // src/methods/removeCollectionBid/removeCollectionBid.ts
3232
+ var removeCollectionBid = async ({
3233
+ bidId
3234
+ }) => {
3235
+ const res = await gqlChainRequest({
3236
+ chain: "sui",
3237
+ query: fetchCollectionBidById,
3238
+ variables: { bidId }
3239
+ });
3240
+ if (res?.bids?.length === 0) {
3241
+ throw new Error("No bids found");
3242
+ }
3243
+ const txBlock = new TransactionBlock8();
3244
+ for (const bid of res.bids) {
3245
+ let nftType;
3246
+ if ([
3247
+ "fa58ae52-b18d-4179-a2d4-c2471ede5f14",
3248
+ // S-Card
3249
+ "ca37bbb2-4398-46cb-b467-8a834d2d2612",
3250
+ // S-Card mint ticket
3251
+ "c8e19183-3a9e-4312-939f-c63a1416e344",
3252
+ // Panzerdogs
3253
+ "819eabe2-1565-4c3a-a9f6-1b5fca48e09a"
3254
+ // Panzerdog Tanks
3255
+ ]?.includes(bid?.collection_id)) {
3256
+ const collectionWithOneNftRes = await gqlChainRequest({
3257
+ chain: "sui",
3258
+ query: fetchCollectionsByIdWithOneNft,
3259
+ variables: { collectionIds: [bid?.collection_id] }
3260
+ });
3261
+ nftType = getNftTypeFromNft(collectionWithOneNftRes?.collections?.[0]?.nfts?.[0]);
3262
+ } else if (bid?.collection_id === "07231735-96de-4710-8e11-52c61a482578") {
3263
+ nftType = "0x034c162f6b594cb5a1805264dd01ca5d80ce3eca6522e6ee37fd9ebfb9d3ddca::factory::PrimeMachin";
3264
+ } else {
3265
+ nftType = bid?.contract?.properties?.nft_type;
3266
+ }
3267
+ const sharedObjects = await getSharedObjects(nftType);
3268
+ const txData = {
3269
+ txBlock,
3270
+ sharedObjects,
3271
+ bidNonce: bid?.nonce,
3272
+ bidder: bid?.bidder,
3273
+ nftType,
3274
+ nftTokenId: bid?.nft?.token_id,
3275
+ bidAmount: bid?.price,
3276
+ sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
3277
+ bidMarketName: bid?.market_contract?.name
3278
+ };
3279
+ switch (txData.bidMarketName) {
3280
+ case "tradeport":
3281
+ await addTradePortRemoveCollectionBidTxHandler(txData);
3282
+ break;
3283
+ case "bluemove":
3284
+ await addBluemoveRemoveCollectionBidTxHandler(txData);
3285
+ break;
3286
+ case "clutchy":
3287
+ await addClutchyRemoveCollectionBidTxHandler(txData);
3288
+ break;
3289
+ default:
3290
+ throw new Error("Marketplace not supported");
3291
+ }
3292
+ }
3293
+ return new TransactionBlock8(txBlock);
3294
+ };
3295
+
3296
+ // src/methods/removeNftBids/removeNftBids.ts
3297
+ import { TransactionBlock as TransactionBlock9 } from "@mysten/sui.js/transactions";
3298
+ var removeNftBids = async ({ bidIds }) => {
3299
+ const res = await gqlChainRequest({
3300
+ chain: "sui",
3301
+ query: fetchBidsById,
3302
+ variables: { bidIds }
3303
+ });
3304
+ if (res?.bids?.length === 0) {
3305
+ throw new Error("No bids found");
3306
+ }
3307
+ const txBlock = new TransactionBlock9();
3308
+ for (const bid of res.bids) {
3309
+ const sharedObjects = await getSharedObjects(
3310
+ bid?.nft?.properties?.nft_type || bid?.nft?.contract?.properties?.nft_type
3311
+ );
3312
+ const txData = {
3313
+ txBlock,
3314
+ sharedObjects,
3315
+ bidNonce: bid?.nonce,
3316
+ nftType: getNftTypeFromNft(bid?.nft),
3317
+ nftTokenId: bid?.nft?.token_id,
3318
+ bidAmount: bid?.price,
3319
+ sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
3320
+ bidMarketName: bid?.market_contract?.name
3321
+ };
3322
+ switch (txData.bidMarketName) {
3323
+ case "tradeport":
3324
+ await addTradePortRemoveNftBidTxHandler(txData);
3325
+ break;
3326
+ case "clutchy":
3327
+ addOriginByteRemoveNftBidTx(txData);
3328
+ break;
3329
+ case "bluemove":
3330
+ addBluemoveRemoveNftBidTx(txData);
3331
+ break;
3332
+ case "tocen":
3333
+ addTocenRemoveNftBidTx(txData);
3334
+ break;
3335
+ default:
3336
+ throw new Error("Marketplace not supported");
3337
+ }
3338
+ }
3339
+ return new TransactionBlock9(txBlock);
3340
+ };
3341
+
3342
+ // src/methods/transferNfts/transferNfts.ts
3343
+ import { TransactionBlock as TransactionBlock10 } from "@mysten/sui.js/transactions";
3344
+
3345
+ // src/graphql/queries/fetchCryptoToUsdRate.ts
3346
+ import { gql as gql14 } from "graphql-request";
3347
+ var fetchCryptoToUsdRate = gql14`
3348
+ query fetchCryptoToUsdRate($crypto: String!) {
3349
+ crypto_rates(where: { crypto: { _eq: $crypto }, fiat: { _eq: "USD" } }) {
3350
+ crypto
3351
+ fiat
3352
+ id
3353
+ rate
3354
+ timestamp
3355
+ }
3356
+ }
3357
+ `;
3358
+
3359
+ // src/helpers/getSuiToUsdRate.ts
3360
+ var getSuiToUsdRate = async () => {
3361
+ try {
3362
+ const res = await gqlChainRequest({
3363
+ chain: "sui",
3364
+ query: fetchCryptoToUsdRate,
3365
+ variables: { crypto: "sui" }
3366
+ });
3367
+ return res?.crypto_rates?.[0]?.rate;
3368
+ } catch (e) {
3369
+ console.log(e);
3370
+ }
3371
+ };
3372
+
3373
+ // src/helpers/addOneDollarFee.ts
3374
+ var addOneDollarFee = async (txBlock) => {
3375
+ const rate = await getSuiToUsdRate();
3376
+ const companyFee = BigInt(Math.ceil(1e9 / rate));
3377
+ const [microTxFee] = txBlock.splitCoins(txBlock.gas, [txBlock.pure(Number(companyFee))]);
3378
+ txBlock.transferObjects(
3379
+ [txBlock.object(microTxFee)],
3380
+ txBlock.pure(addLeadingZerosAfter0x(TRADEPORT_BENEFICIARY_ADDRESS))
3381
+ );
3382
+ };
3383
+
3384
+ // src/graphql/queries/fetchAccountKiosks.ts
3385
+ import { gql as gql15 } from "graphql-request";
3386
+ var fetchAccountKiosks2 = gql15`
3387
+ query fetchAccountKiosks($accountAddress: String!) {
3388
+ kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
3389
+ id
3390
+ is_origin_byte
3391
+ owner_address
3392
+ profits
3393
+ }
3394
+ }
3395
+ `;
3396
+
3397
+ // src/helpers/originByte/isOBKiosk.ts
3398
+ var isOBKiosk = async (accountAddress, kiosk) => {
3399
+ const res = await gqlChainRequest({
3400
+ chain: "sui",
3401
+ query: fetchAccountKiosks2,
3402
+ variables: { accountAddress: addLeadingZerosAfter0x(accountAddress) }
3403
+ });
3404
+ return res?.kiosks?.filter((k) => k?.id === kiosk)?.[0]?.is_origin_byte;
3405
+ };
3406
+
3407
+ // src/helpers/rpc/getAcountBalance.ts
3408
+ var getAccountBalance = async ({ owner }) => {
3409
+ try {
3410
+ const res = await suiClient_default.getBalance({
3411
+ owner: addLeadingZerosAfter0x(owner)
3412
+ });
3413
+ return res?.totalBalance;
3414
+ } catch (err) {
3415
+ return "";
3416
+ }
3417
+ };
3418
+
3419
+ // src/methods/transferNfts/addTransferNftTx.ts
3420
+ async function addOriginByteTransferNftTx({
3421
+ txBlock,
3422
+ nftTokenId,
3423
+ nftType,
3424
+ recipientAddress,
3425
+ senderKiosk
3426
+ }) {
3427
+ const recipientOBKiosk = await getOBKiosk(recipientAddress);
3428
+ if (recipientOBKiosk) {
3429
+ txBlock.moveCall({
3430
+ target: "0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::p2p_transfer",
3431
+ arguments: [
3432
+ txBlock.object(senderKiosk),
3433
+ txBlock.object(recipientOBKiosk),
3434
+ txBlock.pure(nftTokenId)
3435
+ ],
3436
+ typeArguments: [nftType]
3437
+ });
3438
+ } else {
3439
+ txBlock.moveCall({
3440
+ target: "0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::p2p_transfer_and_create_target_kiosk",
3441
+ arguments: [
3442
+ txBlock.object(senderKiosk),
3443
+ txBlock.pure(addLeadingZerosAfter0x(recipientAddress)),
3444
+ txBlock.pure(nftTokenId)
3445
+ ],
3446
+ typeArguments: [nftType]
3447
+ });
3448
+ }
3449
+ }
3450
+ async function addTradeportKioskTransferTx({
3451
+ txBlock,
3452
+ sharedObjects,
3453
+ kioskTx,
3454
+ nftTokenId,
3455
+ nftType,
3456
+ recipientAddress
3457
+ }) {
3458
+ const { transferPolicy } = sharedObjects;
3459
+ const [transferRequest] = txBlock.moveCall({
3460
+ target: "0x78eae99d1a7edae714b5de107f4b44ccbdf5f9ca6919498d9b024ef378dc13f7::kiosk_transfers::transfer",
3461
+ arguments: [
3462
+ txBlock.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
3463
+ txBlock.object(TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK),
3464
+ txBlock.object(kioskTx.kiosk.value ?? kioskTx.kiosk),
3465
+ txBlock.object(kioskTx.kioskCap.value ?? kioskTx.kioskCap),
3466
+ txBlock.pure(nftTokenId),
3467
+ txBlock.pure(addLeadingZerosAfter0x(recipientAddress)),
3468
+ txBlock.object(transferPolicy)
3469
+ ],
3470
+ typeArguments: [nftType]
3471
+ });
3472
+ await resolveTransferPolicies({
3473
+ txBlock,
3474
+ kioskTx,
3475
+ nftType,
3476
+ price: "0",
3477
+ transferRequest,
3478
+ kioskToLockRuleProve: TRADEPORT_KIOSK_TRANSFERS_ESCROW_KIOSK,
3479
+ shouldSkipKioskLocking: true
3480
+ });
3481
+ }
3482
+
3483
+ // src/methods/transferNfts/transferNfts.ts
3484
+ var transferNfts = async ({
3485
+ nftIds,
3486
+ recipientAddress,
3487
+ walletAddress
3488
+ }) => {
3489
+ if (addLeadingZerosAfter0x(recipientAddress) === addLeadingZerosAfter0x(walletAddress)) {
3490
+ throw new Error("Cannot transfer to self");
3491
+ }
3492
+ const recipientAddressBalance = await getAccountBalance({ owner: recipientAddress });
3493
+ if (!recipientAddressBalance || !recipientAddress?.includes("0x")) {
3494
+ throw new Error("Invalid recipient address");
3495
+ }
3496
+ const res = await gqlChainRequest({
3497
+ chain: "sui",
3498
+ query: fetchNftsById,
3499
+ variables: { nftIds }
3500
+ });
3501
+ if (res?.nfts?.length === 0) {
3502
+ throw new Error("No nfts found");
3503
+ }
3504
+ const txBlock = new TransactionBlock10();
3505
+ for (const nft of res.nfts) {
3506
+ if (nft?.listed) {
3507
+ throw new Error("Cannot transfer a listed NFT");
3508
+ }
3509
+ const sharedObjects = await getSharedObjects(getNftTypeFromNft(nft));
3510
+ const txData = {
3511
+ txBlock,
3512
+ nftType: getNftTypeFromNft(nft),
3513
+ nftTokenId: nft?.token_id,
3514
+ senderKiosk: nft?.chain_state?.kiosk_id,
3515
+ senderAddress: walletAddress,
3516
+ recipientAddress,
3517
+ sharedObjects
3518
+ };
3519
+ if (!txData.senderKiosk) {
3520
+ txBlock.transferObjects(
3521
+ [txBlock.object(txData.nftTokenId)],
3522
+ txBlock.pure(addLeadingZerosAfter0x(recipientAddress))
3523
+ );
3524
+ continue;
3525
+ }
3526
+ const isSenderKioskOriginByte = await isOBKiosk(txData.senderAddress, txData.senderKiosk);
3527
+ if (isSenderKioskOriginByte) {
3528
+ await addOriginByteTransferNftTx(txData);
3529
+ continue;
3530
+ }
3531
+ await kioskTxWrapper({
3532
+ txBlock: txData?.txBlock,
3533
+ kioskOwner: txData?.senderAddress,
3534
+ kiosk: txData?.senderKiosk,
3535
+ async tx(kioskTx) {
3536
+ await addTradeportKioskTransferTx({ ...txData, kioskTx });
3537
+ }
3538
+ });
3539
+ }
3540
+ if (res?.nfts?.length > 1) {
3541
+ await addOneDollarFee(txBlock);
3542
+ }
3543
+ return new TransactionBlock10(txBlock);
3544
+ };
3545
+
3546
+ // src/methods/unlistListings/unlistListings.ts
3547
+ import { TransactionBlock as TransactionBlock11 } from "@mysten/sui.js/transactions";
3548
+ var unlistListings = async ({
3549
+ listingIds,
3550
+ walletAddress
3551
+ }) => {
3552
+ const res = await gqlChainRequest({
3553
+ chain: "sui",
3554
+ query: fetchListingsById,
3555
+ variables: { listingIds }
3556
+ });
3557
+ if (res?.listings?.length === 0) {
3558
+ throw new Error("No listings found");
3559
+ }
3560
+ const txBlock = new TransactionBlock11();
3561
+ for (const listing of res.listings) {
3562
+ if (!listing?.listed) {
3563
+ throw new Error(`Listing ${listing?.id} is not listed`);
3564
+ }
3565
+ const sharedObjects = await getSharedObjects(
3566
+ listing?.nft?.properties?.nft_type || listing?.nft?.contract?.properties?.nft_type
3567
+ );
3568
+ const txData = {
3569
+ txBlock,
3570
+ sharedObjects,
3571
+ nftTokenId: listing.nft?.token_id,
3572
+ nftType: getNftTypeFromNft(listing?.nft),
3573
+ listingNonce: listing?.nonce,
3574
+ price: listing?.price,
3575
+ sellerKiosk: listing.nft?.chain_state?.kiosk_id,
3576
+ collectionId: listing?.nft?.collection_id,
3577
+ seller: walletAddress
3578
+ };
3579
+ switch (listing?.market_name) {
3580
+ case "tradeport":
3581
+ await addTradePortUnlistTxHandler(txData);
3582
+ break;
3583
+ case "hyperspace":
3584
+ await addHyperspaceUnlistTxHandler(txData);
3585
+ break;
3586
+ case "bluemove":
3587
+ await addBluemoveUnlistTxHandler(txData);
3588
+ break;
3589
+ case "clutchy":
3590
+ await addClutchyUnlistTxHandler(txData);
3591
+ break;
3592
+ case "souffl3":
3593
+ await addSouffl3UnlistTxHandler(txData);
3594
+ break;
3595
+ case "somis":
3596
+ await addSomisUnlistTxHandler(txData);
3597
+ break;
3598
+ case "keepsake":
3599
+ await addKeepsakeUnlistTxHandler(txData);
3600
+ break;
3601
+ case "tocen":
3602
+ addTocenUnlistTxHandler(txData);
3603
+ break;
3604
+ default:
3605
+ throw new Error("Marketplace not supported");
3606
+ }
3607
+ }
3608
+ return new TransactionBlock11(txBlock);
3609
+ };
3610
+
3611
+ // src/methods/withdrawKioskProfits/withdrawKioskProfits.ts
3612
+ import { TransactionBlock as TransactionBlock12 } from "@mysten/sui.js/transactions";
3613
+ var withdrawKioskProfits = async ({
3614
+ amount,
3615
+ walletAddress
3616
+ }) => {
3617
+ const txBlock = new TransactionBlock12();
3618
+ await kioskTxWrapper({
3619
+ txBlock,
3620
+ kioskOwner: walletAddress,
3621
+ async tx(kioskTx) {
3622
+ kioskTx.withdraw(addLeadingZerosAfter0x(walletAddress), amount);
3623
+ }
3624
+ });
3625
+ return new TransactionBlock12(txBlock);
3626
+ };
3627
+
3628
+ // src/SuiTradingClient.ts
3629
+ var SuiTradingClient = class {
3630
+ constructor({ apiUser, apiKey }) {
3631
+ graphqlClient_default.setHeaders({
3632
+ "x-api-user": apiUser,
3633
+ "x-api-key": apiKey
3634
+ });
3635
+ }
3636
+ async buyListings({ listingIds, walletAddress }) {
3637
+ return buyListings({ listingIds, walletAddress });
3638
+ }
3639
+ async listNfts({ nfts, walletAddress }) {
3640
+ return listNfts({ nfts, walletAddress });
3641
+ }
3642
+ async unlistListings({ listingIds, walletAddress }) {
3643
+ return unlistListings({ listingIds, walletAddress });
3644
+ }
3645
+ async placeNftBids({ nfts, walletAddress }) {
3646
+ return placeNftBids({ nfts, walletAddress });
3647
+ }
3648
+ async removeNftBids({ bidIds }) {
3649
+ return removeNftBids({ bidIds });
3650
+ }
3651
+ async acceptNftBids({ bidIds }) {
3652
+ return acceptNftBids({ bidIds });
3653
+ }
3654
+ async placeCollectionBid({
3655
+ collectionId,
3656
+ bidAmount,
3657
+ numOfBids,
3658
+ walletAddress
3659
+ }) {
3660
+ return placeCollectionBids({
3661
+ collections: [
3662
+ {
3663
+ id: collectionId,
3664
+ bidAmount,
3665
+ numOfBids
3666
+ }
3667
+ ],
3668
+ walletAddress
3669
+ });
3670
+ }
3671
+ async acceptCollectionBid({ bidId, nftId, walletAddress }) {
3672
+ const collectionBidRes = await gqlChainRequest({
3673
+ chain: "sui",
3674
+ query: fetchCollectionBidById,
3675
+ variables: { bidId }
3676
+ });
3677
+ const bid = collectionBidRes?.bids?.[0];
3678
+ if (!bid) {
3679
+ throw new Error("No bid found");
3680
+ }
3681
+ if (bid?.status !== "active") {
3682
+ throw new Error("Bid not active");
3683
+ }
3684
+ if (bid?.type !== "collection") {
3685
+ throw new Error("Bid is not a collection bid. Use acceptNftBid() instead.");
3686
+ }
3687
+ const allBidsWithSameHighestPriceRes = await gqlChainRequest({
3688
+ chain: "sui",
3689
+ query: fetchCollectionBidsAtSamePrice,
3690
+ variables: {
3691
+ collectionId: bid?.collection_id,
3692
+ price: bid?.price
3693
+ }
3694
+ });
3695
+ const allBidsWithSameHighestPrice = allBidsWithSameHighestPriceRes?.bids;
3696
+ for (let i = 0; i < allBidsWithSameHighestPrice?.length; i++) {
3697
+ try {
3698
+ const txBlock = await acceptCollectionBid({
3699
+ bid: allBidsWithSameHighestPrice?.[i],
3700
+ nftId,
3701
+ walletAddress
3702
+ });
3703
+ txBlock.setSenderIfNotSet(walletAddress);
3704
+ const rawTransaction = await txBlock.build({ client: suiClient_default });
3705
+ await suiClient_default.dryRunTransactionBlock({
3706
+ transactionBlock: rawTransaction
3707
+ });
3708
+ return txBlock;
3709
+ } catch (err) {
3710
+ if (i === allBidsWithSameHighestPrice.length - 1) {
3711
+ throw err;
3712
+ }
3713
+ }
3714
+ }
3715
+ }
3716
+ async removeCollectionBid({ bidId }) {
3717
+ return removeCollectionBid({ bidId });
3718
+ }
3719
+ async transferNfts({ nftIds, recipientAddress, walletAddress }) {
3720
+ return transferNfts({ nftIds, recipientAddress, walletAddress });
3721
+ }
3722
+ async claimNfts({ nftIds, walletAddress }) {
3723
+ return claimNfts({ nftIds, walletAddress });
3724
+ }
3725
+ async withdrawKioskProfits({ amount, walletAddress }) {
3726
+ return withdrawKioskProfits({ amount, walletAddress });
3727
+ }
3728
+ };
3729
+ var SuiTradingClient_default = SuiTradingClient;
3730
+ export {
3731
+ SuiTradingClient_default as SuiTradingClient
3732
+ };
3733
+ //# sourceMappingURL=index.mjs.map