@medialane/sdk 0.64.0 → 0.65.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
@@ -1297,6 +1297,50 @@ function createFailoverFetch(urls, options = {}) {
1297
1297
  return failover;
1298
1298
  }
1299
1299
 
1300
+ // src/starknet/marketplace/errors.ts
1301
+ var MedialaneError = class extends Error {
1302
+ constructor(message, code = "UNKNOWN", cause) {
1303
+ super(message);
1304
+ this.code = code;
1305
+ this.cause = cause;
1306
+ this.name = "MedialaneError";
1307
+ }
1308
+ };
1309
+
1310
+ // src/starknet/marketplace/utils.ts
1311
+ var START_TIME_BUFFER_SECS = 30;
1312
+ function newContract(abi, address, providerOrAccount) {
1313
+ const C = starknet.Contract;
1314
+ return C.length === 1 ? new starknet.Contract({ abi, address, providerOrAccount }) : new starknet.Contract(
1315
+ abi,
1316
+ address,
1317
+ providerOrAccount
1318
+ );
1319
+ }
1320
+ function getChainId(config) {
1321
+ if (config.chain !== "STARKNET") {
1322
+ throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
1323
+ }
1324
+ return starknet.constants.StarknetChainId.SN_MAIN;
1325
+ }
1326
+ function resolveToken(currency) {
1327
+ const token = SUPPORTED_TOKENS.find(
1328
+ (t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
1329
+ );
1330
+ if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
1331
+ return token;
1332
+ }
1333
+ var _providerCache = /* @__PURE__ */ new WeakMap();
1334
+ function getProvider(config) {
1335
+ let p = _providerCache.get(config);
1336
+ if (!p) {
1337
+ const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
1338
+ p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
1339
+ _providerCache.set(config, p);
1340
+ }
1341
+ return p;
1342
+ }
1343
+
1300
1344
  // src/starknet/abis/ipMarketplace.ts
1301
1345
  var IPMarketplaceABI = [
1302
1346
  {
@@ -11332,7 +11376,7 @@ var PopService = class {
11332
11376
  this.factoryAddress = getStarknetCoordinates(config.chain).popFactory;
11333
11377
  }
11334
11378
  _collection(address, account) {
11335
- return new starknet.Contract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
11379
+ return newContract(POPCollectionABI, normalizeAddress("STARKNET", address), account);
11336
11380
  }
11337
11381
  async claim(account, collectionAddress) {
11338
11382
  const call = this._collection(collectionAddress, account).populate("claim", []);
@@ -11381,7 +11425,7 @@ var PopService = class {
11381
11425
  return { txHash: res.transaction_hash };
11382
11426
  }
11383
11427
  async createCollection(account, params) {
11384
- const factory = new starknet.Contract(POPFactoryABI, this.factoryAddress, account);
11428
+ const factory = newContract(POPFactoryABI, this.factoryAddress, account);
11385
11429
  const call = factory.populate("create_collection", [
11386
11430
  params.name,
11387
11431
  params.symbol,
@@ -11423,7 +11467,7 @@ var DropService = class {
11423
11467
  this.config = config;
11424
11468
  }
11425
11469
  _collection(address, account) {
11426
- return new starknet.Contract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
11470
+ return newContract(DropCollectionABI, normalizeAddress("STARKNET", address), account);
11427
11471
  }
11428
11472
  async claim(account, collectionAddress, quantity = 1) {
11429
11473
  const collection = this._collection(collectionAddress, account);
@@ -11487,7 +11531,7 @@ var DropService = class {
11487
11531
  return { txHash: res.transaction_hash };
11488
11532
  }
11489
11533
  async createDrop(account, params) {
11490
- const factory = new starknet.Contract(DropFactoryABI, this.factoryAddress, account);
11534
+ const factory = newContract(DropFactoryABI, this.factoryAddress, account);
11491
11535
  const call = factory.populate("create_drop", [
11492
11536
  params.name,
11493
11537
  params.symbol,
@@ -11499,19 +11543,21 @@ var DropService = class {
11499
11543
  return { txHash: res.transaction_hash };
11500
11544
  }
11501
11545
  };
11546
+
11547
+ // src/starknet/services/erc1155collection.ts
11502
11548
  var ERC1155CollectionService = class {
11503
11549
  constructor(config) {
11504
11550
  this.factoryAddress = config.collection1155Contract ?? getStarknetCoordinates(config.chain).collection1155;
11505
11551
  }
11506
11552
  _factory(account) {
11507
- return new starknet.Contract(
11553
+ return newContract(
11508
11554
  IPCollection1155FactoryABI,
11509
11555
  normalizeAddress("STARKNET", this.factoryAddress),
11510
11556
  account
11511
11557
  );
11512
11558
  }
11513
11559
  _collection(address, account) {
11514
- return new starknet.Contract(
11560
+ return newContract(
11515
11561
  IPCollection1155ABI,
11516
11562
  normalizeAddress("STARKNET", address),
11517
11563
  account
@@ -11656,7 +11702,7 @@ async function getCreatorCoinPrice(coinAddress, provider) {
11656
11702
  var _factoryContract = null;
11657
11703
  function factoryContract() {
11658
11704
  if (!_factoryContract) {
11659
- _factoryContract = new starknet.Contract(
11705
+ _factoryContract = newContract(
11660
11706
  CreatorCoinFactoryABI,
11661
11707
  getStarknetCoordinates("STARKNET").creatorCoinFactory
11662
11708
  );
@@ -11726,7 +11772,7 @@ var CreatorCoinService = class {
11726
11772
  this.config = config;
11727
11773
  }
11728
11774
  _factory(account) {
11729
- return new starknet.Contract(CreatorCoinFactoryABI, this.factoryAddress, account);
11775
+ return newContract(CreatorCoinFactoryABI, this.factoryAddress, account);
11730
11776
  }
11731
11777
  /** Deploy a fixed-supply CreatorCoin (full supply minted to the Factory). */
11732
11778
  async createCreatorCoin(account, params) {
@@ -11761,14 +11807,14 @@ var TicketService = class {
11761
11807
  _factory(account, factoryAddress) {
11762
11808
  const address = factoryAddress ?? this.factoryAddress;
11763
11809
  if (!address) throw new Error("IP-Tickets factory address not configured for this chain");
11764
- return new starknet.Contract(IPTicketCollectionFactoryABI, normalizeAddress("STARKNET", address), account);
11810
+ return newContract(IPTicketCollectionFactoryABI, normalizeAddress("STARKNET", address), account);
11765
11811
  }
11766
11812
  _collection(address, account) {
11767
- return new starknet.Contract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), account);
11813
+ return newContract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), account);
11768
11814
  }
11769
11815
  _collectionRead(address) {
11770
11816
  const provider = new starknet.RpcProvider({ nodeUrl: this.config.rpcUrl });
11771
- return new starknet.Contract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), provider);
11817
+ return newContract(IPTicketCollectionABI, normalizeAddress("STARKNET", address), provider);
11772
11818
  }
11773
11819
  /** Deploys a new IPTicketCollection via the factory. Caller becomes owner. */
11774
11820
  async deployCollection(account, params) {
@@ -11843,15 +11889,15 @@ var ClubService = class {
11843
11889
  _registry(account, registryAddress) {
11844
11890
  const address = registryAddress ?? this.registryAddress;
11845
11891
  if (!address) throw new Error("IP-Club registry address not configured for this chain");
11846
- return new starknet.Contract(IPClubABI, normalizeAddress("STARKNET", address), account);
11892
+ return newContract(IPClubABI, normalizeAddress("STARKNET", address), account);
11847
11893
  }
11848
11894
  _factory(account, factoryAddress) {
11849
11895
  const address = factoryAddress ?? this.factoryAddress;
11850
11896
  if (!address) throw new Error("IP-Club factory address not configured for this chain");
11851
- return new starknet.Contract(IPClubFactoryABI, normalizeAddress("STARKNET", address), account);
11897
+ return newContract(IPClubFactoryABI, normalizeAddress("STARKNET", address), account);
11852
11898
  }
11853
11899
  _collection(account, collectionAddress) {
11854
- return new starknet.Contract(IPClubCollectionABI, normalizeAddress("STARKNET", collectionAddress), account);
11900
+ return newContract(IPClubCollectionABI, normalizeAddress("STARKNET", collectionAddress), account);
11855
11901
  }
11856
11902
  /** Deploy a new per-creator membership ERC-721 collection via the factory. */
11857
11903
  async deployClub(account, params) {
@@ -11963,7 +12009,7 @@ var SponsorshipService = class {
11963
12009
  if (!resolved) {
11964
12010
  throw new Error("IP-Sponsorship address not configured for this chain");
11965
12011
  }
11966
- return new starknet.Contract(IPSponsorshipABI, normalizeAddress("STARKNET", resolved), account);
12012
+ return newContract(IPSponsorshipABI, normalizeAddress("STARKNET", resolved), account);
11967
12013
  }
11968
12014
  /** The offer author must currently own (nftContract, tokenId) — enforced on-chain at create and accept. */
11969
12015
  async createOffer(account, params) {
@@ -12032,7 +12078,7 @@ var SponsorshipService = class {
12032
12078
  starknet.cairo.uint256(params.offerId),
12033
12079
  params.sponsor
12034
12080
  ]);
12035
- const receipt = new starknet.Contract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
12081
+ const receipt = newContract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
12036
12082
  const mintCall = receipt.populate("mint_item", [params.sponsor, params.licenseTermsUri]);
12037
12083
  const res = await account.execute([acceptCall, mintCall]);
12038
12084
  return { txHash: res.transaction_hash };
@@ -12052,7 +12098,7 @@ var SponsorshipService = class {
12052
12098
  ];
12053
12099
  const receiptAddress = params.licenseReceiptAddress ?? this.licenseReceiptAddress;
12054
12100
  if (receiptAddress && params.receiptTokenId != null) {
12055
- const receipt = new starknet.Contract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
12101
+ const receipt = newContract(IPGenesisABI, normalizeAddress("STARKNET", receiptAddress), account);
12056
12102
  calls.push(receipt.populate("transfer_from", [account.address, params.to, starknet.cairo.uint256(params.receiptTokenId)]));
12057
12103
  }
12058
12104
  const res = await account.execute(calls);
@@ -12107,48 +12153,6 @@ var MedialaneClient = class {
12107
12153
  }
12108
12154
  };
12109
12155
 
12110
- // src/starknet/marketplace/errors.ts
12111
- var MedialaneError = class extends Error {
12112
- constructor(message, code = "UNKNOWN", cause) {
12113
- super(message);
12114
- this.code = code;
12115
- this.cause = cause;
12116
- this.name = "MedialaneError";
12117
- }
12118
- };
12119
- var START_TIME_BUFFER_SECS = 30;
12120
- function newContract(abi, address, providerOrAccount) {
12121
- const C = starknet.Contract;
12122
- return C.length === 1 ? new starknet.Contract({ abi, address, providerOrAccount }) : new starknet.Contract(
12123
- abi,
12124
- address,
12125
- providerOrAccount
12126
- );
12127
- }
12128
- function getChainId(config) {
12129
- if (config.chain !== "STARKNET") {
12130
- throw new Error(`SNIP-12 signing is Starknet-only; got chain "${config.chain}"`);
12131
- }
12132
- return starknet.constants.StarknetChainId.SN_MAIN;
12133
- }
12134
- function resolveToken(currency) {
12135
- const token = SUPPORTED_TOKENS.find(
12136
- (t) => t.symbol === currency.toUpperCase() || t.address.toLowerCase() === currency.toLowerCase()
12137
- );
12138
- if (!token) throw new MedialaneError(`Unsupported currency: ${currency}`, "INVALID_PARAMS");
12139
- return token;
12140
- }
12141
- var _providerCache = /* @__PURE__ */ new WeakMap();
12142
- function getProvider(config) {
12143
- let p = _providerCache.get(config);
12144
- if (!p) {
12145
- const urls = Array.from(/* @__PURE__ */ new Set([config.rpcUrl, ...PUBLIC_RPC_FALLBACKS]));
12146
- p = new starknet.RpcProvider({ nodeUrl: urls[0], baseFetch: createFailoverFetch(urls) });
12147
- _providerCache.set(config, p);
12148
- }
12149
- return p;
12150
- }
12151
-
12152
12156
  // src/starknet/marketplace/orders.ts
12153
12157
  var _contractCache = /* @__PURE__ */ new WeakMap();
12154
12158
  function makeContract(config) {