@medialane/sdk 0.5.6 → 0.6.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.
package/dist/index.cjs CHANGED
@@ -49,6 +49,8 @@ var DEFAULT_RPC_URLS = {
49
49
  mainnet: "https://rpc.starknet.lava.build",
50
50
  sepolia: "https://rpc.starknet-sepolia.lava.build"
51
51
  };
52
+ var POP_FACTORY_CONTRACT_MAINNET = "0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111";
53
+ var POP_COLLECTION_CLASS_HASH_MAINNET = "0x077c421686f10851872561953ea16898d933364b7f8937a5d7e2b1ba0a36263f";
52
54
 
53
55
  // src/abis.ts
54
56
  var IPMarketplaceABI = [
@@ -357,6 +359,148 @@ var IPMarketplaceABI = [
357
359
  ]
358
360
  }
359
361
  ];
362
+ var POPCollectionABI = [
363
+ {
364
+ type: "struct",
365
+ name: "core::byte_array::ByteArray",
366
+ members: [
367
+ { name: "data", type: "core::array::Array::<core::felt252>" },
368
+ { name: "pending_word", type: "core::felt252" },
369
+ { name: "pending_word_len", type: "core::integer::u32" }
370
+ ]
371
+ },
372
+ {
373
+ type: "function",
374
+ name: "claim",
375
+ inputs: [],
376
+ outputs: [],
377
+ state_mutability: "external"
378
+ },
379
+ {
380
+ type: "function",
381
+ name: "admin_mint",
382
+ inputs: [
383
+ { name: "recipient", type: "core::starknet::contract_address::ContractAddress" },
384
+ { name: "custom_uri", type: "core::byte_array::ByteArray" }
385
+ ],
386
+ outputs: [],
387
+ state_mutability: "external"
388
+ },
389
+ {
390
+ type: "function",
391
+ name: "add_to_allowlist",
392
+ inputs: [{ name: "address", type: "core::starknet::contract_address::ContractAddress" }],
393
+ outputs: [],
394
+ state_mutability: "external"
395
+ },
396
+ {
397
+ type: "function",
398
+ name: "batch_add_to_allowlist",
399
+ inputs: [{ name: "addresses", type: "core::array::Array::<core::starknet::contract_address::ContractAddress>" }],
400
+ outputs: [],
401
+ state_mutability: "external"
402
+ },
403
+ {
404
+ type: "function",
405
+ name: "remove_from_allowlist",
406
+ inputs: [{ name: "address", type: "core::starknet::contract_address::ContractAddress" }],
407
+ outputs: [],
408
+ state_mutability: "external"
409
+ },
410
+ {
411
+ type: "function",
412
+ name: "set_token_uri",
413
+ inputs: [
414
+ { name: "token_id", type: "core::integer::u256" },
415
+ { name: "uri", type: "core::byte_array::ByteArray" }
416
+ ],
417
+ outputs: [],
418
+ state_mutability: "external"
419
+ },
420
+ {
421
+ type: "function",
422
+ name: "set_paused",
423
+ inputs: [{ name: "paused", type: "core::bool" }],
424
+ outputs: [],
425
+ state_mutability: "external"
426
+ },
427
+ {
428
+ type: "function",
429
+ name: "is_eligible",
430
+ inputs: [{ name: "address", type: "core::starknet::contract_address::ContractAddress" }],
431
+ outputs: [{ type: "core::bool" }],
432
+ state_mutability: "view"
433
+ },
434
+ {
435
+ type: "function",
436
+ name: "has_claimed",
437
+ inputs: [{ name: "address", type: "core::starknet::contract_address::ContractAddress" }],
438
+ outputs: [{ type: "core::bool" }],
439
+ state_mutability: "view"
440
+ },
441
+ {
442
+ type: "function",
443
+ name: "total_minted",
444
+ inputs: [],
445
+ outputs: [{ type: "core::integer::u256" }],
446
+ state_mutability: "view"
447
+ }
448
+ ];
449
+ var POPFactoryABI = [
450
+ {
451
+ type: "struct",
452
+ name: "core::byte_array::ByteArray",
453
+ members: [
454
+ { name: "data", type: "core::array::Array::<core::felt252>" },
455
+ { name: "pending_word", type: "core::felt252" },
456
+ { name: "pending_word_len", type: "core::integer::u32" }
457
+ ]
458
+ },
459
+ {
460
+ type: "enum",
461
+ name: "pop_protocol::types::EventType",
462
+ variants: [
463
+ { name: "Conference", type: "()" },
464
+ { name: "Bootcamp", type: "()" },
465
+ { name: "Workshop", type: "()" },
466
+ { name: "Hackathon", type: "()" },
467
+ { name: "Meetup", type: "()" },
468
+ { name: "Course", type: "()" },
469
+ { name: "Other", type: "()" }
470
+ ]
471
+ },
472
+ {
473
+ type: "function",
474
+ name: "create_collection",
475
+ inputs: [
476
+ { name: "name", type: "core::byte_array::ByteArray" },
477
+ { name: "symbol", type: "core::byte_array::ByteArray" },
478
+ { name: "base_uri", type: "core::byte_array::ByteArray" },
479
+ { name: "claim_end_time", type: "core::integer::u64" },
480
+ { name: "event_type", type: "pop_protocol::types::EventType" }
481
+ ],
482
+ outputs: [{ type: "core::starknet::contract_address::ContractAddress" }],
483
+ state_mutability: "external"
484
+ },
485
+ {
486
+ type: "function",
487
+ name: "register_provider",
488
+ inputs: [
489
+ { name: "provider", type: "core::starknet::contract_address::ContractAddress" },
490
+ { name: "name", type: "core::byte_array::ByteArray" },
491
+ { name: "website_url", type: "core::byte_array::ByteArray" }
492
+ ],
493
+ outputs: [],
494
+ state_mutability: "external"
495
+ },
496
+ {
497
+ type: "function",
498
+ name: "set_pop_collection_class_hash",
499
+ inputs: [{ name: "new_class_hash", type: "core::starknet::class_hash::ClassHash" }],
500
+ outputs: [],
501
+ state_mutability: "external"
502
+ }
503
+ ];
360
504
 
361
505
  // src/utils/bigint.ts
362
506
  function stringifyBigInts(obj) {
@@ -1073,10 +1217,11 @@ var ApiClient = class {
1073
1217
  );
1074
1218
  }
1075
1219
  // ─── Collections ───────────────────────────────────────────────────────────
1076
- getCollections(page = 1, limit = 20, isKnown, sort) {
1220
+ getCollections(page = 1, limit = 20, isKnown, sort, source) {
1077
1221
  const params = new URLSearchParams({ page: String(page), limit: String(limit) });
1078
1222
  if (isKnown !== void 0) params.set("isKnown", String(isKnown));
1079
1223
  if (sort) params.set("sort", sort);
1224
+ if (source) params.set("source", source);
1080
1225
  return this.get(`/v1/collections?${params}`);
1081
1226
  }
1082
1227
  getCollectionsByOwner(owner, page = 1, limit = 50) {
@@ -1271,6 +1416,14 @@ var ApiClient = class {
1271
1416
  });
1272
1417
  return res.json();
1273
1418
  }
1419
+ async getGatedContent(contractAddress, clerkToken) {
1420
+ const url = `${this.baseUrl.replace(/\/$/, "")}/v1/collections/${normalizeAddress(contractAddress)}/gated-content`;
1421
+ const res = await fetch(url, {
1422
+ headers: { ...this.baseHeaders, "Authorization": `Bearer ${clerkToken}` }
1423
+ });
1424
+ if (res.status === 403 || res.status === 404) return null;
1425
+ return res.json();
1426
+ }
1274
1427
  // ─── Creator Profiles ───────────────────────────────────────────────────────
1275
1428
  /** List all creators with an approved username. */
1276
1429
  async getCreators(opts = {}) {
@@ -1440,6 +1593,92 @@ var ApiClient = class {
1440
1593
  headers: { "Authorization": `Bearer ${clerkToken}` }
1441
1594
  });
1442
1595
  }
1596
+ // ─── POP Protocol ──────────────────────────────────────────────────────────
1597
+ getPopCollections(opts = {}) {
1598
+ return this.getCollections(opts.page ?? 1, opts.limit ?? 20, void 0, opts.sort, "POP_PROTOCOL");
1599
+ }
1600
+ async getPopEligibility(collection, wallet) {
1601
+ const res = await this.get(
1602
+ `/v1/pop/eligibility/${normalizeAddress(collection)}/${normalizeAddress(wallet)}`
1603
+ );
1604
+ return res.data;
1605
+ }
1606
+ async getPopEligibilityBatch(collection, wallets) {
1607
+ const params = new URLSearchParams({ wallets: wallets.map(normalizeAddress).join(",") });
1608
+ const res = await this.get(
1609
+ `/v1/pop/eligibility/${normalizeAddress(collection)}?${params}`
1610
+ );
1611
+ return res.data;
1612
+ }
1613
+ };
1614
+ var POP_FACTORY_MAINNET = "0x00b32c34b427d8f346b5843ada6a37bd3368d879fc752cd52b68a87287f60111";
1615
+ var PopService = class {
1616
+ constructor(_config) {
1617
+ this.factoryAddress = POP_FACTORY_MAINNET;
1618
+ }
1619
+ async claim(account, collectionAddress) {
1620
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(collectionAddress), account);
1621
+ const call = collection.populate("claim", []);
1622
+ const res = await account.execute([call]);
1623
+ return { txHash: res.transaction_hash };
1624
+ }
1625
+ async adminMint(account, params) {
1626
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(params.collection), account);
1627
+ const call = collection.populate("admin_mint", [
1628
+ params.recipient,
1629
+ params.customUri ?? ""
1630
+ ]);
1631
+ const res = await account.execute([call]);
1632
+ return { txHash: res.transaction_hash };
1633
+ }
1634
+ async addToAllowlist(account, params) {
1635
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(params.collection), account);
1636
+ const call = collection.populate("add_to_allowlist", [params.address]);
1637
+ const res = await account.execute([call]);
1638
+ return { txHash: res.transaction_hash };
1639
+ }
1640
+ async batchAddToAllowlist(account, params) {
1641
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(params.collection), account);
1642
+ const CHUNK = 200;
1643
+ const calls = [];
1644
+ for (let i = 0; i < params.addresses.length; i += CHUNK) {
1645
+ const chunk = params.addresses.slice(i, i + CHUNK);
1646
+ calls.push(collection.populate("batch_add_to_allowlist", [chunk]));
1647
+ }
1648
+ const res = await account.execute(calls);
1649
+ return { txHash: res.transaction_hash };
1650
+ }
1651
+ async removeFromAllowlist(account, params) {
1652
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(params.collection), account);
1653
+ const call = collection.populate("remove_from_allowlist", [params.address]);
1654
+ const res = await account.execute([call]);
1655
+ return { txHash: res.transaction_hash };
1656
+ }
1657
+ async setTokenUri(account, params) {
1658
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(params.collection), account);
1659
+ const call = collection.populate("set_token_uri", [BigInt(params.tokenId), params.uri]);
1660
+ const res = await account.execute([call]);
1661
+ return { txHash: res.transaction_hash };
1662
+ }
1663
+ async setPaused(account, params) {
1664
+ const collection = new starknet.Contract(POPCollectionABI, normalizeAddress(params.collection), account);
1665
+ const call = collection.populate("set_paused", [params.paused]);
1666
+ const res = await account.execute([call]);
1667
+ return { txHash: res.transaction_hash };
1668
+ }
1669
+ async createCollection(account, params) {
1670
+ const factory = new starknet.Contract(POPFactoryABI, this.factoryAddress, account);
1671
+ const eventTypeVariant = { [params.eventType]: {} };
1672
+ const call = factory.populate("create_collection", [
1673
+ params.name,
1674
+ params.symbol,
1675
+ params.baseUri,
1676
+ params.claimEndTime,
1677
+ eventTypeVariant
1678
+ ]);
1679
+ const res = await account.execute([call]);
1680
+ return { txHash: res.transaction_hash };
1681
+ }
1443
1682
  };
1444
1683
 
1445
1684
  // src/client.ts
@@ -1447,6 +1686,9 @@ var MedialaneClient = class {
1447
1686
  constructor(rawConfig = {}) {
1448
1687
  this.config = resolveConfig(rawConfig);
1449
1688
  this.marketplace = new MarketplaceModule(this.config);
1689
+ this.services = {
1690
+ pop: new PopService(this.config)
1691
+ };
1450
1692
  if (!this.config.backendUrl) {
1451
1693
  this.api = new Proxy({}, {
1452
1694
  get(_target, prop) {
@@ -1485,6 +1727,11 @@ exports.MedialaneApiError = MedialaneApiError;
1485
1727
  exports.MedialaneClient = MedialaneClient;
1486
1728
  exports.MedialaneError = MedialaneError;
1487
1729
  exports.OPEN_LICENSES = OPEN_LICENSES;
1730
+ exports.POPCollectionABI = POPCollectionABI;
1731
+ exports.POPFactoryABI = POPFactoryABI;
1732
+ exports.POP_COLLECTION_CLASS_HASH_MAINNET = POP_COLLECTION_CLASS_HASH_MAINNET;
1733
+ exports.POP_FACTORY_CONTRACT_MAINNET = POP_FACTORY_CONTRACT_MAINNET;
1734
+ exports.PopService = PopService;
1488
1735
  exports.SUPPORTED_NETWORKS = SUPPORTED_NETWORKS;
1489
1736
  exports.SUPPORTED_TOKENS = SUPPORTED_TOKENS;
1490
1737
  exports.buildCancellationTypedData = buildCancellationTypedData;