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