@xoxno/sdk-js 0.1.179-alpha → 0.1.182

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