@lifestonelabs/tokensales 1.0.5 → 1.0.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
  ______________________________________________________________
3
+ ## [1.0.6] - 2026-02-09
4
+ ### Changed
5
+ - `buyNFT` & `burn` made ticketMasterUtxo param optional. They now fetch the correct TokenSale UTXO from the contract if one is not provided.
6
+ Lets the frontend manage the contract UTXO fetching themselves if they want to limit the amount of electrum calls.
7
+ ______________________________________________________________
3
8
  ## [1.0.5] - 2026-02-09
4
9
  ### Changed
5
10
  - `buyNFT` fixed logic so that a MintingNFT owner for the categoryID can purchase tickets for 1000sats rather than paying full price.
@@ -1 +1 @@
1
- {"version":3,"file":"burn.d.ts","sourceRoot":"","sources":["../../src/functions/burn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAItE;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAkLtF"}
1
+ {"version":3,"file":"burn.d.ts","sourceRoot":"","sources":["../../src/functions/burn.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAKtE;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA+MtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"buyNFT.d.ts","sourceRoot":"","sources":["../../src/functions/buyNFT.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAIxE;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA2T1F"}
1
+ {"version":3,"file":"buyNFT.d.ts","sourceRoot":"","sources":["../../src/functions/buyNFT.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAKxE;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAwV1F"}
package/dist/index.esm.js CHANGED
@@ -212,6 +212,61 @@ function toLittleEndianHexString(number, byteCount) {
212
212
  return hex.match(/../g)?.reverse().join('') ?? '';
213
213
  }
214
214
 
215
+ // TokenSales_old1 contract addresses
216
+ //export const AddressTicketMaster = 'bitcoincash:pvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryszkdd99zq'; //address hash: 2ef2757e6a8659a54a3a43384764091ac82c05e8d2b5941fdefb551b20564648
217
+ //export const AddressTicketMasterToken = 'bitcoincash:rvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryss93vuymt';
218
+ // TokenSales contract addresses | simplified change fee calculation in purchaseNFT()
219
+ const AddressTicketMaster = 'bitcoincash:pdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2m4afvzlt'; //address hash: 76bebd71fef3c48ef2fec86b1a24ceaa7fb06f3e1aed923ac8176955c20f5085
220
+ const AddressTicketMasterToken = 'bitcoincash:rdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2fxpg4rxq';
221
+ // Ticket Level Descriptions
222
+ const TICKET_LEVEL_DESCRIPTIONS = {
223
+ '01': {
224
+ name: 'Regular',
225
+ description: 'Regular tickets provide standard access to the event. This is the base level ticket option.'
226
+ },
227
+ '02': {
228
+ name: 'VIP',
229
+ description: 'VIP tickets offer enhanced benefits including priority access, exclusive areas, and additional perks.'
230
+ },
231
+ '03': {
232
+ name: 'Premium',
233
+ description: 'Premium tickets provide the highest level of access with all VIP benefits plus additional exclusive features.'
234
+ }
235
+ };
236
+
237
+ /**
238
+ * TokenSales contract addresses
239
+ * These are the addresses for the TokenSales (TicketMaster) contract
240
+ */
241
+ const DEFAULT_CONTRACT_ADDRESSES = {
242
+ contract: AddressTicketMaster,
243
+ token: AddressTicketMasterToken
244
+ };
245
+ /**
246
+ * Get contract address
247
+ * @returns Contract address
248
+ */
249
+ function getContractAddress() {
250
+ return AddressTicketMaster;
251
+ }
252
+ /**
253
+ * Get token address
254
+ * @returns Token address
255
+ */
256
+ function getTokenAddress() {
257
+ return AddressTicketMasterToken;
258
+ }
259
+ /**
260
+ * Get contract addresses
261
+ * @returns Object with contract and token addresses
262
+ */
263
+ function getContractAddresses() {
264
+ return {
265
+ contract: AddressTicketMaster,
266
+ token: AddressTicketMasterToken
267
+ };
268
+ }
269
+
215
270
  var contractName = "TokenSales";
216
271
  var constructorInputs = [
217
272
  ];
@@ -522,7 +577,7 @@ var contractArtifact = {
522
577
  * @throws Error if validation fails or transaction building fails
523
578
  */
524
579
  async function buyNFT(params) {
525
- const { electrumProvider, usersAddress, ticketMasterUtxo, ticketUtxo, ticketType, isAdmin } = params;
580
+ const { electrumProvider, usersAddress, ticketMasterUtxo: providedTicketMasterUtxo, ticketUtxo, ticketType, isAdmin } = params;
526
581
  if (!electrumProvider) {
527
582
  throw new Error('Electrum provider not available');
528
583
  }
@@ -531,6 +586,28 @@ async function buyNFT(params) {
531
586
  provider: electrumProvider,
532
587
  addressType: 'p2sh32'
533
588
  });
589
+ // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract
590
+ let ticketMasterUtxo;
591
+ if (providedTicketMasterUtxo?.token?.category === ticketUtxo.token?.category
592
+ && providedTicketMasterUtxo?.token?.nft?.capability === 'minting') {
593
+ ticketMasterUtxo = providedTicketMasterUtxo;
594
+ }
595
+ else {
596
+ // Get the contract token address
597
+ const contractTokenAddress = getTokenAddress();
598
+ // Get all UTXOs from the contract token address
599
+ const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);
600
+ // Filter to find the TicketMaster UTXO with matching category ID
601
+ const matchingCategoryId = ticketUtxo.token?.category;
602
+ if (!matchingCategoryId) {
603
+ throw new Error('ticketUtxo must have a token category');
604
+ }
605
+ ticketMasterUtxo = contractUtxos.find(utxo => utxo.token?.category === matchingCategoryId &&
606
+ utxo.token?.nft?.capability === 'minting');
607
+ if (!ticketMasterUtxo) {
608
+ throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);
609
+ }
610
+ }
534
611
  // Parse TicketMaster commitment to get price and admin address
535
612
  const commitment = ticketMasterUtxo.token?.nft?.commitment || '';
536
613
  if (commitment.length !== 78) {
@@ -975,7 +1052,7 @@ async function modifyTokenSale(params) {
975
1052
  * @throws Error if validation fails or transaction building fails
976
1053
  */
977
1054
  async function burn(params) {
978
- const { electrumProvider, usersAddress, ticketMasterUtxo, userMintingNFT, tickets } = params;
1055
+ const { electrumProvider, usersAddress, ticketMasterUtxo: providedTicketMasterUtxo, userMintingNFT, tickets } = params;
979
1056
  if (!electrumProvider) {
980
1057
  throw new Error('Electrum provider not available');
981
1058
  }
@@ -984,6 +1061,28 @@ async function burn(params) {
984
1061
  provider: electrumProvider,
985
1062
  addressType: 'p2sh32'
986
1063
  });
1064
+ // If ticketMasterUtxo is not provided or is not a valid Utxo, fetch it from the contract
1065
+ let ticketMasterUtxo;
1066
+ if (providedTicketMasterUtxo?.token?.category === userMintingNFT.token?.category
1067
+ && providedTicketMasterUtxo?.token?.nft?.capability === 'minting') {
1068
+ ticketMasterUtxo = providedTicketMasterUtxo;
1069
+ }
1070
+ else {
1071
+ // Get the contract token address
1072
+ const contractTokenAddress = getTokenAddress();
1073
+ // Get all UTXOs from the contract token address
1074
+ const contractUtxos = await electrumProvider.getUtxos(contractTokenAddress);
1075
+ // Filter to find the TicketMaster UTXO with matching category ID
1076
+ const matchingCategoryId = userMintingNFT.token?.category;
1077
+ if (!matchingCategoryId) {
1078
+ throw new Error('userMintingNFT must have a token category');
1079
+ }
1080
+ ticketMasterUtxo = contractUtxos.find(utxo => utxo.token?.category === matchingCategoryId &&
1081
+ utxo.token?.nft?.capability === 'minting');
1082
+ if (!ticketMasterUtxo) {
1083
+ throw new Error(`No TicketMaster UTXO found for category ${matchingCategoryId}`);
1084
+ }
1085
+ }
987
1086
  // Get contract address from compiled contract
988
1087
  const contractAddr = ticketMasterContract.address;
989
1088
  // Creating lockingBytecode for contract address
@@ -1270,28 +1369,6 @@ async function addSatoshis(params) {
1270
1369
  return wcTransactionObj;
1271
1370
  }
1272
1371
 
1273
- // TokenSales_old1 contract addresses
1274
- //export const AddressTicketMaster = 'bitcoincash:pvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryszkdd99zq'; //address hash: 2ef2757e6a8659a54a3a43384764091ac82c05e8d2b5941fdefb551b20564648
1275
- //export const AddressTicketMasterToken = 'bitcoincash:rvh0yat7d2r9nf228fpns3mypydvstq9arftt9qlmma42xeq2eryss93vuymt';
1276
- // TokenSales contract addresses | simplified change fee calculation in purchaseNFT()
1277
- const AddressTicketMaster = 'bitcoincash:pdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2m4afvzlt'; //address hash: 76bebd71fef3c48ef2fec86b1a24ceaa7fb06f3e1aed923ac8176955c20f5085
1278
- const AddressTicketMasterToken = 'bitcoincash:rdmta0t3lmeufrhjlmyxkx3ye648lvr08cdwmy36eqtkj4wzpagg2fxpg4rxq';
1279
- // Ticket Level Descriptions
1280
- const TICKET_LEVEL_DESCRIPTIONS = {
1281
- '01': {
1282
- name: 'Regular',
1283
- description: 'Regular tickets provide standard access to the event. This is the base level ticket option.'
1284
- },
1285
- '02': {
1286
- name: 'VIP',
1287
- description: 'VIP tickets offer enhanced benefits including priority access, exclusive areas, and additional perks.'
1288
- },
1289
- '03': {
1290
- name: 'Premium',
1291
- description: 'Premium tickets provide the highest level of access with all VIP benefits plus additional exclusive features.'
1292
- }
1293
- };
1294
-
1295
1372
  /**
1296
1373
  * Create a new TicketMaster listing
1297
1374
  * @param params - CreateListingParams object containing all required parameters
@@ -1431,39 +1508,6 @@ async function createListing(params) {
1431
1508
  return wcTransactionObj;
1432
1509
  }
1433
1510
 
1434
- /**
1435
- * TokenSales contract addresses
1436
- * These are the addresses for the TokenSales (TicketMaster) contract
1437
- */
1438
- const DEFAULT_CONTRACT_ADDRESSES = {
1439
- contract: AddressTicketMaster,
1440
- token: AddressTicketMasterToken
1441
- };
1442
- /**
1443
- * Get contract address
1444
- * @returns Contract address
1445
- */
1446
- function getContractAddress() {
1447
- return AddressTicketMaster;
1448
- }
1449
- /**
1450
- * Get token address
1451
- * @returns Token address
1452
- */
1453
- function getTokenAddress() {
1454
- return AddressTicketMasterToken;
1455
- }
1456
- /**
1457
- * Get contract addresses
1458
- * @returns Object with contract and token addresses
1459
- */
1460
- function getContractAddresses() {
1461
- return {
1462
- contract: AddressTicketMaster,
1463
- token: AddressTicketMasterToken
1464
- };
1465
- }
1466
-
1467
1511
  /**
1468
1512
  * List available tickets for purchase from a TokenSale
1469
1513
  * @param params - ListAvailableTicketsParams object containing all required parameters