@xoxno/sdk-js 0.1.54-alpha → 0.1.55-alpha

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 (62) hide show
  1. package/dist/236.bundle.js +1 -0
  2. package/dist/265.bundle.js +2 -0
  3. package/dist/265.bundle.js.LICENSE.txt +10 -0
  4. package/dist/collection/index.d.ts +13 -1
  5. package/dist/common/index.d.ts +1 -9
  6. package/dist/index.bundle.js +1 -0
  7. package/dist/index.d.ts +0 -2
  8. package/dist/interactions.bundle.js +1 -0
  9. package/dist/launchpad.bundle.js +1 -0
  10. package/dist/runtime.bundle.js +1 -0
  11. package/dist/types/collection.d.ts +3 -0
  12. package/dist/types/trading.d.ts +39 -19
  13. package/dist/utils/api.d.ts +1 -1
  14. package/package.json +11 -8
  15. package/dist/collection/index.js +0 -520
  16. package/dist/collection/index.js.map +0 -1
  17. package/dist/common/index.js +0 -78
  18. package/dist/common/index.js.map +0 -1
  19. package/dist/index.js +0 -26
  20. package/dist/index.js.map +0 -1
  21. package/dist/interactions/index.js +0 -678
  22. package/dist/interactions/index.js.map +0 -1
  23. package/dist/launchpad/index.js +0 -158
  24. package/dist/launchpad/index.js.map +0 -1
  25. package/dist/nft/index.js +0 -121
  26. package/dist/nft/index.js.map +0 -1
  27. package/dist/staking/index.js +0 -29
  28. package/dist/staking/index.js.map +0 -1
  29. package/dist/types/collection.js +0 -183
  30. package/dist/types/collection.js.map +0 -1
  31. package/dist/types/common.js +0 -3
  32. package/dist/types/common.js.map +0 -1
  33. package/dist/types/index.js +0 -21
  34. package/dist/types/index.js.map +0 -1
  35. package/dist/types/interactions.js +0 -11
  36. package/dist/types/interactions.js.map +0 -1
  37. package/dist/types/nft.js +0 -3
  38. package/dist/types/nft.js.map +0 -1
  39. package/dist/types/staking.js +0 -15
  40. package/dist/types/staking.js.map +0 -1
  41. package/dist/types/trading.js +0 -26
  42. package/dist/types/trading.js.map +0 -1
  43. package/dist/types/user.js +0 -13
  44. package/dist/types/user.js.map +0 -1
  45. package/dist/users/index.js +0 -220
  46. package/dist/users/index.js.map +0 -1
  47. package/dist/utils/SmartContractAbis.js +0 -103
  48. package/dist/utils/SmartContractAbis.js.map +0 -1
  49. package/dist/utils/SmartContractService.js +0 -13
  50. package/dist/utils/SmartContractService.js.map +0 -1
  51. package/dist/utils/api.js +0 -79
  52. package/dist/utils/api.js.map +0 -1
  53. package/dist/utils/const.js +0 -17
  54. package/dist/utils/const.js.map +0 -1
  55. package/dist/utils/getActivity.js +0 -53
  56. package/dist/utils/getActivity.js.map +0 -1
  57. package/dist/utils/helpers.js +0 -27
  58. package/dist/utils/helpers.js.map +0 -1
  59. package/dist/utils/regex.js +0 -12
  60. package/dist/utils/regex.js.map +0 -1
  61. package/dist/utils/scCalls.js +0 -39
  62. package/dist/utils/scCalls.js.map +0 -1
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,+CAA6B;AAC7B,8CAA4B;AAC5B,iDAA+B;AAC/B,wCAAsB;AACtB,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB"}
@@ -1,678 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.SCInteraction = void 0;
16
- const __1 = require("../");
17
- const scCalls_1 = require("../utils/scCalls");
18
- const SmartContractAbis_1 = require("../utils/SmartContractAbis");
19
- const SmartContractService_1 = require("../utils/SmartContractService");
20
- const numerical_1 = require("@multiversx/sdk-core/out/smartcontracts/typesystem/numerical");
21
- const interactions_1 = require("../types/interactions");
22
- const tokenTransfer_1 = require("@multiversx/sdk-core/out/tokenTransfer");
23
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
24
- const struct_1 = require("@multiversx/sdk-core/out/smartcontracts/typesystem/struct");
25
- const tokenIdentifier_1 = require("@multiversx/sdk-core/out/smartcontracts/typesystem/tokenIdentifier");
26
- const fields_1 = require("@multiversx/sdk-core/out/smartcontracts/typesystem/fields");
27
- const boolean_1 = require("@multiversx/sdk-core/out/smartcontracts/typesystem/boolean");
28
- const out_1 = require("@multiversx/sdk-core/out");
29
- class SCInteraction {
30
- constructor(marketAbiXOXNO) {
31
- /**
32
- * Gets the percentage of each transaction that will be paid to the marketplace.
33
- *
34
- * @returns The percentage of each transaction that will be paid to the marketplace.
35
- */
36
- this.getMarketplaceFees = () => __awaiter(this, void 0, void 0, function* () {
37
- var _a;
38
- const interaction = this.xo.methods.getMarketplaceCutPercentage();
39
- const result = yield this.getResult(interaction);
40
- return parseInt((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
41
- });
42
- /**
43
- * Retrieves the list of accepted payment tokens.
44
- * @returns {string[]} A list of accepted payment tokens.
45
- */
46
- this.getAcceptedPaymentTokens = () => __awaiter(this, void 0, void 0, function* () {
47
- var _b;
48
- const interaction = this.xo.methods.getAcceptedTokens();
49
- const result = yield this.getResult(interaction);
50
- return (_b = result.firstValue) === null || _b === void 0 ? void 0 : _b.valueOf();
51
- });
52
- /**
53
- * This function returns a list of IDs of global offers.
54
- * @returns {number[]} a list of IDs of global offers.
55
- */
56
- this.getGlobalOfferIDs = () => __awaiter(this, void 0, void 0, function* () {
57
- var _c;
58
- const interaction = this.xo.methods.getGlobalOffers();
59
- const result = yield this.getResult(interaction);
60
- return (_c = result.firstValue) === null || _c === void 0 ? void 0 : _c.valueOf().map((id) => parseInt(id));
61
- });
62
- /**
63
- * Returns the global offer data for the offer with the given id.
64
- *
65
- * @param global_offer_id The id of the global offer for which to return the data.
66
- *
67
- * @returns An object containing the global offer data for the offer with the given id. If the global offer id is invalid, the return value will be null.
68
- */
69
- this.getGlobalOfferData = (global_offer_id) => __awaiter(this, void 0, void 0, function* () {
70
- var _d;
71
- const interaction = this.xo.methods.getGlobalOffer([global_offer_id]);
72
- const result = yield this.getResult(interaction);
73
- const body = (_d = result.firstValue) === null || _d === void 0 ? void 0 : _d.valueOf();
74
- body.offer_id = parseInt(body.offer_id.valueOf());
75
- body.marketplace = 'XO';
76
- body.short_price = parseFloat(new numerical_1.BigUIntValue(body.price).valueOf().shiftedBy(-18).toString());
77
- body.new_version = Boolean(body.new_version);
78
- if (!body.new_version) {
79
- body.isActive = this.isOfferActive(body.short_price, yield this.getUserPoolBalance(body.owner, body.payment_token, body.payment_nonce));
80
- }
81
- else {
82
- body.isActive = true;
83
- }
84
- body.quantity = parseInt(body.quantity.valueOf());
85
- body.payment_nonce = parseInt(body.payment_nonce.valueOf());
86
- body.price = body.price.valueOf();
87
- body.timestamp = parseInt(body.timestamp.valueOf());
88
- body.owner = body.owner.valueOf().toString();
89
- if (body.attributes) {
90
- body.attributes = JSON.parse(Buffer.from(body.attributes.valueOf().toString(), 'base64').toString('ascii'));
91
- }
92
- return body;
93
- });
94
- /**
95
- * Returns the auction struct for the given id.
96
- *
97
- * @param auctionID The id of the auction for which to return the data.
98
- *
99
- * @returns {Auction} An object containing the auction data for the given id. If the auction id is invalid, the return value will be null.
100
- */
101
- this.getAuctionInfo = (auctionID) => __awaiter(this, void 0, void 0, function* () {
102
- var _e;
103
- const interaction = this.xo.methods.getFullAuctionData([auctionID]);
104
- const result = yield this.getResult(interaction);
105
- const body = (_e = result.firstValue) === null || _e === void 0 ? void 0 : _e.valueOf();
106
- if (!body) {
107
- return null;
108
- }
109
- body.auctioned_token_nonce = parseInt(body.auctioned_token_nonce.valueOf());
110
- body.nr_auctioned_tokens = parseInt(body.nr_auctioned_tokens.valueOf());
111
- body.auction_type = body.auction_type.name;
112
- body.payment_token_nonce = parseInt(body.payment_token_nonce.valueOf());
113
- body.min_bid = body.min_bid.valueOf();
114
- body.max_bid = body.max_bid.valueOf();
115
- body.start_time = parseInt(body.start_time.valueOf());
116
- body.deadline = parseInt(body.deadline.valueOf());
117
- body.original_owner = body.original_owner.valueOf().toString();
118
- body.current_winner = body.current_winner.valueOf().toString();
119
- body.current_bid = body.current_bid.valueOf().toString();
120
- body.marketplace_cut_percentage = body.marketplace_cut_percentage.valueOf();
121
- body.creator_royalties_percentage =
122
- body.creator_royalties_percentage.valueOf();
123
- return body;
124
- });
125
- this.xo = marketAbiXOXNO;
126
- this.call = new scCalls_1.ContractQueryRunner();
127
- this.api = __1.XOXNOClient.init();
128
- }
129
- static init() {
130
- return __awaiter(this, void 0, void 0, function* () {
131
- const config = __1.XOXNOClient.init().config;
132
- const marketAbiXOXNO = yield SmartContractAbis_1.SmartContractAbis.getMarket();
133
- const xo_abi = (0, SmartContractService_1.getSmartContract)(marketAbiXOXNO, config.XO_SC);
134
- return new SCInteraction(xo_abi);
135
- });
136
- }
137
- getResult(interaction) {
138
- return __awaiter(this, void 0, void 0, function* () {
139
- return yield this.call.runQuery(this.xo, interaction);
140
- });
141
- }
142
- /**
143
- * Gets the balance of a user in a token of a specific pool.
144
- * @param address The address of the user.
145
- * @param token The token address.
146
- * @param nonce The nonce of the pool.
147
- * @returns {number} The balance of the user in the token of the pool.
148
- */
149
- getUserPoolBalance(address, token, nonce) {
150
- return __awaiter(this, void 0, void 0, function* () {
151
- const result = yield this.getResult(this.xo.methods.userDeposit([address, token, nonce]));
152
- if (!(result === null || result === void 0 ? void 0 : result.firstValue)) {
153
- return 0;
154
- }
155
- return new numerical_1.BigUIntValue(result.firstValue.valueOf().amount)
156
- .valueOf()
157
- .shiftedBy(-18)
158
- .toNumber();
159
- });
160
- }
161
- // function to determine if the offer is active
162
- // based on the offer price and user balance
163
- isOfferActive(offer_price, user_balance) {
164
- return offer_price <= user_balance;
165
- }
166
- /** Gets the number of listings.
167
- * @returns {number} The number of listings.
168
- * */
169
- getListingsCount() {
170
- var _a;
171
- return __awaiter(this, void 0, void 0, function* () {
172
- const result = yield this.getResult(this.xo.methods.getListingsCount());
173
- const count = parseInt((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
174
- return count;
175
- });
176
- }
177
- /** Gets the number of custom offers.
178
- * @returns {number} The number of custom offers.
179
- * */
180
- getOffersCount() {
181
- var _a;
182
- return __awaiter(this, void 0, void 0, function* () {
183
- const result = yield this.getResult(this.xo.methods.getOffersCount());
184
- const count = parseInt((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
185
- return count;
186
- });
187
- }
188
- /** Gets the number of global offers.
189
- * @returns {number} The number of global offers.
190
- * */
191
- getGlobalOffersCount() {
192
- var _a;
193
- return __awaiter(this, void 0, void 0, function* () {
194
- const result = yield this.getResult(this.xo.methods.getGlobalOffersCount());
195
- const count = parseInt((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
196
- return count;
197
- });
198
- }
199
- /** Gets the number of collections listed.
200
- * @returns {number} The number of collections listed.
201
- * */
202
- getCollectionsCount() {
203
- var _a;
204
- return __awaiter(this, void 0, void 0, function* () {
205
- const result = yield this.getResult(this.xo.methods.getCollectionsCount());
206
- const count = parseInt((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
207
- return count;
208
- });
209
- }
210
- /**
211
- * Checks whether a collection is listed with at least 1 NFT.
212
- *
213
- * @param collection name of the collection
214
- * @return true if the collection is listed, false otherwise
215
- */
216
- isCollectionListed(collection) {
217
- var _a;
218
- return __awaiter(this, void 0, void 0, function* () {
219
- const result = yield this.getResult(this.xo.methods.isCollectionListed([collection]));
220
- return Boolean((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
221
- });
222
- }
223
- /** Gets the on sale NFT count of the collection.
224
- *
225
- * @param collection The collection identifier for which one wants to get the on sale NFT count.
226
- *
227
- * @returns {number} The on sale NFT count of the collection.
228
- * */
229
- getCollectionNFTsOnSaleCount(collection) {
230
- var _a;
231
- return __awaiter(this, void 0, void 0, function* () {
232
- const result = yield this.getResult(this.xo.methods.getTokenItemsForSaleCount([collection]));
233
- return parseInt((_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf());
234
- });
235
- }
236
- /** Gets the active unique auction IDs of collection.
237
- *
238
- * @param collection The collection identifier for which one wants to get the active unique auction IDs.
239
- *
240
- * @returns {number[]} The active unique auction IDs of collection.
241
- * */
242
- getAuctionIDsForCollection(collection) {
243
- var _a;
244
- return __awaiter(this, void 0, void 0, function* () {
245
- const result = yield this.getResult(this.xo.methods.getAuctionsForTicker([collection]));
246
- const ids = (_a = result.firstValue) === null || _a === void 0 ? void 0 : _a.valueOf().map((id) => parseInt(id));
247
- return ids;
248
- });
249
- }
250
- /**
251
- * Withdraw auctions from the smart contract.
252
- *
253
- * @param auctionIDs The IDs of the auctions to withdraw from
254
- * @returns {Interaction} The interaction object of the smart contract
255
- */
256
- withdrawAuctions(auctionIDs, senderNonce, market) {
257
- if (market === 'XO') {
258
- const interaction = this.xo.methods.withdraw(auctionIDs);
259
- if (senderNonce.nonce) {
260
- interaction.withNonce(senderNonce.nonce);
261
- }
262
- return interaction
263
- .withChainID(this.api.chain)
264
- .withSender(new out_1.Address(senderNonce.address))
265
- .withGasLimit(Math.min(600000000, 15000000 + auctionIDs.length * 5000000));
266
- }
267
- else {
268
- throw new Error('Market not supported');
269
- }
270
- }
271
- /**
272
- * Withdraw global offer from the smart contract.
273
- *
274
- * @param auctionIDs The IDs of the global offer to withdraw
275
- * @returns {Interaction} The interaction object of the smart contract
276
- */
277
- withdrawGlobalOffer(offerID, senderNonce) {
278
- const interaction = this.xo.methods.withdrawGlobalOffer([offerID]);
279
- if (senderNonce.nonce) {
280
- interaction.withNonce(senderNonce.nonce);
281
- }
282
- return interaction
283
- .withChainID(this.api.chain)
284
- .withSender(new out_1.Address(senderNonce.address))
285
- .withGasLimit(15000000);
286
- }
287
- /**
288
- * Accept a global offer
289
- *
290
- * @param offerID The offer ID
291
- * @returns {Interaction} The interaction object of the smart contract
292
- */
293
- acceptGlobalOffer({ signature, offer_id, auction_id_opt, nft, address, nonce, }) {
294
- var _a;
295
- const interaction = signature
296
- ? this.xo.methods.acceptGlobalOffer([offer_id, auction_id_opt, signature])
297
- : this.xo.methods.acceptGlobalOffer([offer_id, auction_id_opt]);
298
- interaction.withSender(new out_1.Address(address));
299
- if (nft) {
300
- interaction.withSingleESDTNFTTransfer(tokenTransfer_1.TokenTransfer.semiFungible(nft.collection, nft.nonce, (_a = nft.amount) !== null && _a !== void 0 ? _a : 1));
301
- }
302
- if (nonce) {
303
- interaction.withNonce(nonce);
304
- }
305
- return interaction.withChainID(this.api.chain).withGasLimit(30000000);
306
- }
307
- /**
308
- * Send a global offer
309
- * @param payment_token The token used for payment
310
- * @param payment_nonce The nonce of the payment token
311
- * @param price The price of the offer
312
- * @param collection The collection of the NFT
313
- * @param attributes The attributes of the NFT
314
- * @param depositAmount The deposit amount
315
- * @returns {Interaction} The interaction object of the smart contract
316
- * */
317
- sendGlobalOffer({ payment_token, payment_nonce, price, collection, attributes, depositAmount, address, nonce, }) {
318
- const interaction = attributes
319
- ? this.xo.methods.sendGlobalOffer([
320
- payment_token,
321
- payment_nonce,
322
- tokenTransfer_1.TokenTransfer.egldFromAmount(price).toString(),
323
- collection,
324
- attributes,
325
- ])
326
- : this.xo.methods.sendGlobalOffer([
327
- payment_token,
328
- payment_nonce,
329
- tokenTransfer_1.TokenTransfer.egldFromAmount(price).toString(),
330
- collection,
331
- ]);
332
- if (nonce) {
333
- interaction.withNonce(nonce);
334
- }
335
- interaction.withSender(new out_1.Address(address));
336
- if (depositAmount) {
337
- interaction.withValue(tokenTransfer_1.TokenTransfer.egldFromAmount(depositAmount));
338
- }
339
- return interaction.withChainID(this.api.chain).withGasLimit(30000000);
340
- }
341
- /**
342
- * Send a custom offer
343
- * @param payment_token The token used for payment
344
- * @param payment_nonce The nonce of the payment token
345
- * @param price The price of the offer
346
- * @param deadline The deadline of the offer
347
- * @param nft The NFT to be sold
348
- * @param depositAmount The deposit amount
349
- * @returns {Interaction} The interaction object of the smart contract
350
- * */
351
- sendCustomOffer({ payment_token, payment_nonce, price, deadline, nft, depositAmount, address, nonce, }) {
352
- var _a;
353
- const interaction = this.xo.methods.sendOffer([
354
- payment_token,
355
- payment_nonce,
356
- tokenTransfer_1.TokenTransfer.egldFromAmount(price).toString(),
357
- nft.collection,
358
- nft.nonce,
359
- (_a = nft.amount) !== null && _a !== void 0 ? _a : 1,
360
- deadline,
361
- ]);
362
- if (nonce) {
363
- interaction.withNonce(nonce);
364
- }
365
- interaction.withSender(new out_1.Address(address));
366
- if (depositAmount) {
367
- interaction.withValue(tokenTransfer_1.TokenTransfer.egldFromAmount(depositAmount));
368
- }
369
- return interaction.withChainID(this.api.chain).withGasLimit(30000000);
370
- }
371
- /**
372
- * Withdraws a custom offer
373
- *
374
- * @param offerID The offer ID
375
- * @returns {Interaction} The interaction object of the smart contract
376
- */
377
- withdrawCustomOffer(offerID, senderNonce) {
378
- const interaction = this.xo.methods.withdrawOffer([offerID]);
379
- if (senderNonce.nonce) {
380
- interaction.withNonce(senderNonce.nonce);
381
- }
382
- interaction.withSender(new out_1.Address(senderNonce.address));
383
- return interaction.withChainID(this.api.chain).withGasLimit(15000000);
384
- }
385
- /**
386
- * Decline a custom offer
387
- *
388
- * @param offerID The offer ID
389
- * @returns {Interaction} The interaction object of the smart contract
390
- */
391
- declineCustomOffer(offerID, sender, nft) {
392
- var _a;
393
- const interaction = this.xo.methods.declineOffer([offerID]);
394
- if (sender.nonce) {
395
- interaction.withNonce(sender.nonce);
396
- }
397
- interaction.withSender(new out_1.Address(sender.address));
398
- if (nft) {
399
- interaction.withSingleESDTNFTTransfer(tokenTransfer_1.TokenTransfer.semiFungible(nft.collection, nft.nonce, (_a = nft.amount) !== null && _a !== void 0 ? _a : 1));
400
- }
401
- return interaction.withChainID(this.api.chain).withGasLimit(20000000);
402
- }
403
- /**
404
- * Accept a custom offer
405
- *
406
- * @param offerID The offer ID
407
- * @returns {Interaction} The interaction object of the smart contract
408
- */
409
- acceptCustomOffer(offerID, sender, nft) {
410
- var _a;
411
- const interaction = this.xo.methods.acceptOffer([offerID]);
412
- if (sender.nonce) {
413
- interaction.withNonce(sender.nonce);
414
- }
415
- interaction.withSender(new out_1.Address(sender.address));
416
- if (nft) {
417
- interaction.withSingleESDTNFTTransfer(tokenTransfer_1.TokenTransfer.semiFungible(nft.collection, nft.nonce, (_a = nft.amount) !== null && _a !== void 0 ? _a : 1));
418
- }
419
- return interaction.withChainID(this.api.chain).withGasLimit(30000000);
420
- }
421
- /**
422
- * @public
423
- * @function endAuction
424
- * @param {number} auctionID - The unique identifier of the auction.
425
- * @returns {Interaction} The resulting interaction with the specified chainID and gas limit.
426
- *
427
- * This function allows ending an auction by its auctionID. It takes the following parameter:
428
- * - auctionID (number): The unique identifier of the auction.
429
- *
430
- * The function calls the `endAuction` method on the smart contract with the provided auctionID.
431
- * Finally, it returns the resulting interaction with the specified chainID and gas limit.
432
- */
433
- endAuction(auctionID, sender, market = 'XO') {
434
- if (market == 'XO') {
435
- const interaction = this.xo.methods.endAuction([auctionID]);
436
- if (sender.nonce) {
437
- interaction.withNonce(sender.nonce);
438
- }
439
- interaction.withSender(new out_1.Address(sender.address));
440
- return interaction.withChainID(this.api.chain).withGasLimit(15000000);
441
- }
442
- else {
443
- throw new Error('Market not supported');
444
- }
445
- }
446
- /**
447
- * Bid on an auction
448
- *
449
- * @param auctionID The auction ID
450
- * @param collection The NFT Collection
451
- * @param nonce The NFT nonce
452
- * @param payment The payment object
453
- * @returns {Interaction} The interaction object of the smart contract
454
- */
455
- bidOnAuctionId(auctionID, collection, nonce, payment, sender) {
456
- var _a;
457
- const interaction = this.xo.methods.bid([auctionID, collection, nonce]);
458
- if (!payment.amount) {
459
- throw new Error('Payment amount is required');
460
- }
461
- if (sender.nonce) {
462
- interaction.withNonce(sender.nonce);
463
- }
464
- interaction.withSender(new out_1.Address(sender.address));
465
- if (payment.collection == 'EGLD' && payment.amount) {
466
- interaction.withValue(tokenTransfer_1.TokenTransfer.egldFromAmount(payment.amount));
467
- }
468
- else {
469
- interaction.withSingleESDTTransfer(tokenTransfer_1.TokenTransfer.fungibleFromAmount(payment.collection, payment.amount, (_a = payment.decimals) !== null && _a !== void 0 ? _a : 18));
470
- }
471
- return interaction.withChainID(this.api.chain).withGasLimit(30000000);
472
- }
473
- /**
474
- * Bulk buy auctions
475
- *
476
- * @param auctionIDs The auction IDs
477
- * @param payment The payment object
478
- * @returns {Interaction} The interaction object of the smart contract
479
- */
480
- bulkBuy(auctionIDs, payment, sender) {
481
- var _a;
482
- const interaction = this.xo.methods.bid(auctionIDs);
483
- if (sender.nonce) {
484
- interaction.withNonce(sender.nonce);
485
- }
486
- interaction.withSender(new out_1.Address(sender.address));
487
- if (!payment.amount) {
488
- throw new Error('Payment amount is required');
489
- }
490
- if (payment.collection == 'EGLD' && payment.amount) {
491
- interaction.withValue(tokenTransfer_1.TokenTransfer.egldFromAmount(payment.amount));
492
- }
493
- else {
494
- interaction.withSingleESDTTransfer(tokenTransfer_1.TokenTransfer.fungibleFromAmount(payment.collection, payment.amount, (_a = payment.decimals) !== null && _a !== void 0 ? _a : 18));
495
- }
496
- return interaction
497
- .withChainID(this.api.chain)
498
- .withGasLimit(Math.min(600000000, 20000000 + auctionIDs.length * 5000000));
499
- }
500
- /**
501
- * @public
502
- * @async
503
- * @function buyAuctionById
504
- * @param {Object} options - An object containing the necessary parameters to buy an auction.
505
- * @param {number} options.auctionID - The unique identifier of the auction.
506
- * @param {string} [options.collection] - The collection the auctioned token belongs to (optional).
507
- * @param {number} [options.nonce] - The nonce of the auctioned token (optional).
508
- * @param {number} [options.quantity=1] - The quantity of tokens to buy (default is 1).
509
- * @param {string} [options.token='EGLD'] - The payment token (default is 'EGLD').
510
- * @param {number} [options.paymentAmount] - The payment amount for the auction (optional).
511
- * @param {boolean} [options.withCheck=true] - Whether to check the auction information (default is true).
512
- * @param {boolean} [options.isBigUintPayment=false] - Whether the payment amount is a big integer (default is false).
513
- * @returns {Promise<Interaction>} The resulting interaction with the specified chainID and gas limit.
514
- *
515
- * This function allows a user to buy an auction by its auctionID. It takes an object with the following properties:
516
- * - auctionID (number): The unique identifier of the auction.
517
- * - collection (string, optional): The collection the auctioned token belongs to.
518
- * - nonce (number, optional): The nonce of the auctioned token.
519
- * - quantity (number, optional): The quantity of tokens to buy (default is 1).
520
- * - token (string, optional): The payment token (default is 'EGLD').
521
- * - paymentAmount (number, optional): The payment amount for the auction.
522
- * - withCheck (boolean, optional): Whether to check the auction information (default is true).
523
- * - isBigUintPayment (boolean, optional): Whether the payment amount is a big integer (default is false).
524
- *
525
- * The function first checks if the auction exists and if its type is NFT or SftOnePerPayment. If not, an error is thrown.
526
- * Then, it calculates the payment amount and calls the `buy` method on the smart contract with the provided parameters.
527
- * Finally, the function returns the resulting interaction with the specified chainID and gas limit.
528
- */
529
- buyAuctionById({ auctionID, collection, nonce, paymentAmount, quantity = 1, token = 'EGLD', withCheck = true, isBigUintPayment = false, address, nonce: senderNonce, isBid = false, decimals = 18, market = 'XO', }) {
530
- var _a, _b, _c, _d, _e;
531
- return __awaiter(this, void 0, void 0, function* () {
532
- if (market !== 'XO') {
533
- throw new Error('Market not supported');
534
- }
535
- if (!auctionID) {
536
- throw new Error('AuctionID not provided');
537
- }
538
- let auction = null;
539
- if (!paymentAmount || !token || !collection || !nonce || withCheck) {
540
- auction = yield this.getAuctionInfo(auctionID);
541
- if (auction === null) {
542
- throw new Error('Auction not found');
543
- }
544
- if (auction.auction_type === interactions_1.AuctionType.Nft ||
545
- auction.auction_type === interactions_1.AuctionType.SftOnePerPayment) {
546
- throw new Error('Auction type is not NFT or SftOnePerPayment');
547
- }
548
- }
549
- const paymentToken = (_a = auction === null || auction === void 0 ? void 0 : auction.payment_token_type) !== null && _a !== void 0 ? _a : token;
550
- const bigNumber = auction ? true : isBigUintPayment;
551
- let amount = isBid
552
- ? (_b = auction === null || auction === void 0 ? void 0 : auction.max_bid) !== null && _b !== void 0 ? _b : paymentAmount
553
- : (_c = auction === null || auction === void 0 ? void 0 : auction.min_bid) !== null && _c !== void 0 ? _c : paymentAmount;
554
- if (!amount) {
555
- throw new Error('Payment amount not provided');
556
- }
557
- const interaction = this.xo.methods.buy([
558
- auctionID,
559
- (_d = auction === null || auction === void 0 ? void 0 : auction.auctioned_token_type) !== null && _d !== void 0 ? _d : collection,
560
- (_e = auction === null || auction === void 0 ? void 0 : auction.auctioned_token_nonce) !== null && _e !== void 0 ? _e : nonce,
561
- quantity !== null && quantity !== void 0 ? quantity : 1,
562
- ]);
563
- if (senderNonce) {
564
- interaction.withNonce(senderNonce);
565
- }
566
- interaction.withSender(new out_1.Address(address));
567
- if (token === 'EGLD') {
568
- interaction.withValue(bigNumber
569
- ? tokenTransfer_1.TokenTransfer.egldFromBigInteger(new bignumber_js_1.default(amount).multipliedBy(quantity))
570
- : tokenTransfer_1.TokenTransfer.egldFromAmount(new bignumber_js_1.default(amount).multipliedBy(quantity)));
571
- }
572
- else {
573
- if (!bigNumber) {
574
- auction = yield this.getAuctionInfo(auctionID);
575
- if (auction === null) {
576
- throw new Error('Auction not found');
577
- }
578
- amount = isBid ? auction.max_bid : auction.min_bid;
579
- }
580
- interaction.withSingleESDTTransfer(tokenTransfer_1.TokenTransfer.fungibleFromBigInteger(paymentToken, amount, decimals));
581
- }
582
- return interaction.withChainID(this.api.chain).withGasLimit(20000000);
583
- });
584
- }
585
- /**
586
- * @docutype
587
- * @public
588
- * @async
589
- * @function changeListing
590
- * @param {ChangeListing[]} listings - An array of objects containing the information needed to change a listing.
591
- * @returns {Interaction} The resulting interaction with the specified chainID and gas limit.
592
- *
593
- * This function takes an array of `ChangeListing` objects and constructs `Struct` instances using the provided
594
- * information. Each `ChangeListing` object should have the following properties:
595
- * - paymentToken (string): The identifier of the payment token type.
596
- * - price (BigInt): The new price for the listing.
597
- * - auctionID (number): The unique identifier of the auction.
598
- * - deadline (number): The deadline (in Unix time) for the listing.
599
- *
600
- * The function then calls the `changeListing` method on the smart contract and returns the resulting interaction
601
- * with the specified chainID and gas limit.
602
- */
603
- changeListing(listings, sender) {
604
- return __awaiter(this, void 0, void 0, function* () {
605
- const fooType = new struct_1.StructType('BulkUpdateListing', [
606
- new fields_1.FieldDefinition('payment_token_type', '', new tokenIdentifier_1.TokenIdentifierType()),
607
- new fields_1.FieldDefinition('new_price', '', new numerical_1.BigUIntType()),
608
- new fields_1.FieldDefinition('auction_id', '', new numerical_1.U64Type()),
609
- new fields_1.FieldDefinition('deadline', '', new numerical_1.U64Type()),
610
- ]);
611
- const structs = [];
612
- listings.forEach(({ paymentToken, price, auctionID, deadline }) => {
613
- structs.push(new struct_1.Struct(fooType, [
614
- new fields_1.Field(new tokenIdentifier_1.TokenIdentifierValue(paymentToken), 'payment_token_type'),
615
- new fields_1.Field(new numerical_1.BigUIntValue(price), 'new_price'),
616
- new fields_1.Field(new numerical_1.U64Value(auctionID), 'auction_id'),
617
- new fields_1.Field(new numerical_1.U64Value(deadline), 'deadline'),
618
- ]));
619
- });
620
- const interaction = this.xo.methods.changeListing(structs);
621
- if (sender.nonce) {
622
- interaction.withNonce(sender.nonce);
623
- }
624
- interaction.withSender(new out_1.Address(sender.address));
625
- return interaction
626
- .withChainID(this.api.chain)
627
- .withGasLimit(Math.min(600000000, 8000000 + listings.length * 2000000));
628
- });
629
- }
630
- listNFTs(listings, sender) {
631
- return __awaiter(this, void 0, void 0, function* () {
632
- const fooType = new struct_1.StructType('BulkListing', [
633
- new fields_1.FieldDefinition('min_bid', '', new numerical_1.BigUIntType()),
634
- new fields_1.FieldDefinition('max_bid', '', new numerical_1.BigUIntType()),
635
- new fields_1.FieldDefinition('deadline', '', new numerical_1.U64Type()),
636
- new fields_1.FieldDefinition('accepted_payment_token', '', new tokenIdentifier_1.TokenIdentifierType()),
637
- new fields_1.FieldDefinition('bid', '', new boolean_1.BooleanType()),
638
- new fields_1.FieldDefinition('opt_sft_max_one_per_payment', '', new boolean_1.BooleanType()),
639
- new fields_1.FieldDefinition('opt_start_time', '', new numerical_1.U64Type()),
640
- new fields_1.FieldDefinition('collection', '', new tokenIdentifier_1.TokenIdentifierType()),
641
- new fields_1.FieldDefinition('nonce', '', new numerical_1.U64Type()),
642
- new fields_1.FieldDefinition('nft_amount', '', new numerical_1.BigUIntType()),
643
- ]);
644
- const structs = [];
645
- const tokens = [];
646
- listings.forEach((listing) => {
647
- var _a, _b, _c, _d, _e, _f;
648
- const decimals = (_a = listing.accepted_payment_token_decimals) !== null && _a !== void 0 ? _a : 18;
649
- const minBID = new bignumber_js_1.default(listing.min_bid).shiftedBy(decimals);
650
- const maxBID = new bignumber_js_1.default((_b = listing.max_bid) !== null && _b !== void 0 ? _b : 0).shiftedBy(decimals);
651
- tokens.push(tokenTransfer_1.TokenTransfer.semiFungible(listing.collection, listing.nonce, listing.nft_amount));
652
- structs.push(new struct_1.Struct(fooType, [
653
- new fields_1.Field(new numerical_1.BigUIntValue(minBID), 'min_bid'),
654
- new fields_1.Field(new numerical_1.BigUIntValue(maxBID), 'max_bid'),
655
- new fields_1.Field(new numerical_1.U64Value(new bignumber_js_1.default((_c = listing.deadline) !== null && _c !== void 0 ? _c : 0)), 'deadline'),
656
- new fields_1.Field(new tokenIdentifier_1.TokenIdentifierValue((_d = listing.accepted_payment_token) !== null && _d !== void 0 ? _d : 'EGLD'), 'accepted_payment_token'),
657
- new fields_1.Field(new boolean_1.BooleanValue((_e = listing.bid) !== null && _e !== void 0 ? _e : false), 'bid'),
658
- new fields_1.Field(new boolean_1.BooleanValue((_f = listing.isSFTPack) !== null && _f !== void 0 ? _f : false), 'opt_sft_max_one_per_payment'),
659
- new fields_1.Field(new numerical_1.U64Value(new bignumber_js_1.default(listing.opt_start_time ? listing.opt_start_time : 0)), 'opt_start_time'),
660
- new fields_1.Field(new tokenIdentifier_1.TokenIdentifierValue(listing.collection), 'collection'),
661
- new fields_1.Field(new numerical_1.U64Value(listing.nonce), 'nonce'),
662
- new fields_1.Field(new numerical_1.BigUIntValue(new bignumber_js_1.default(listing.nft_amount)), 'nft_amount'),
663
- ]));
664
- });
665
- const interaction = this.xo.methods.listings(structs);
666
- if (sender.nonce) {
667
- interaction.withNonce(sender.nonce);
668
- }
669
- interaction.withSender(new out_1.Address(sender.address));
670
- interaction.withMultiESDTNFTTransfer(tokens);
671
- return interaction
672
- .withChainID(this.api.chain)
673
- .withGasLimit(Math.min(600000000, 8000000 + listings.length * 2000000));
674
- });
675
- }
676
- }
677
- exports.SCInteraction = SCInteraction;
678
- //# sourceMappingURL=index.js.map