@zoralabs/protocol-sdk 0.9.1 → 0.9.3

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 (50) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +12 -0
  3. package/dist/anvil.d.ts.map +1 -1
  4. package/dist/apis/http-api-base.d.ts +1 -1
  5. package/dist/apis/http-api-base.d.ts.map +1 -1
  6. package/dist/apis/subgraph-querier.d.ts +6 -0
  7. package/dist/apis/subgraph-querier.d.ts.map +1 -1
  8. package/dist/create/1155-create-helper.d.ts +4 -1
  9. package/dist/create/1155-create-helper.d.ts.map +1 -1
  10. package/dist/create/contract-getter.d.ts +30 -0
  11. package/dist/create/contract-getter.d.ts.map +1 -0
  12. package/dist/create/contract-setup.d.ts +4 -8
  13. package/dist/create/contract-setup.d.ts.map +1 -1
  14. package/dist/create/mint-from-create.d.ts +3 -3
  15. package/dist/create/mint-from-create.d.ts.map +1 -1
  16. package/dist/create/minter-defaults.d.ts +1 -1
  17. package/dist/create/minter-defaults.d.ts.map +1 -1
  18. package/dist/create/subgraph-queries.d.ts +13 -0
  19. package/dist/create/subgraph-queries.d.ts.map +1 -0
  20. package/dist/create/token-setup.d.ts +2 -0
  21. package/dist/create/token-setup.d.ts.map +1 -1
  22. package/dist/index.cjs +2166 -2099
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.js +2188 -2121
  25. package/dist/index.js.map +1 -1
  26. package/dist/mint/subgraph-mint-getter.d.ts +2 -2
  27. package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
  28. package/dist/mint/subgraph-queries.d.ts +1 -5
  29. package/dist/mint/subgraph-queries.d.ts.map +1 -1
  30. package/dist/retries.d.ts +7 -0
  31. package/dist/retries.d.ts.map +1 -0
  32. package/dist/sdk.d.ts +2 -0
  33. package/dist/sdk.d.ts.map +1 -1
  34. package/package.json +1 -1
  35. package/src/apis/http-api-base.ts +12 -20
  36. package/src/apis/subgraph-querier.ts +7 -0
  37. package/src/create/1155-create-helper.test.ts +68 -3
  38. package/src/create/1155-create-helper.ts +23 -9
  39. package/src/create/contract-getter.ts +90 -0
  40. package/src/create/contract-setup.ts +17 -46
  41. package/src/create/mint-from-create.ts +7 -15
  42. package/src/create/minter-defaults.ts +11 -20
  43. package/src/create/subgraph-queries.ts +35 -0
  44. package/src/create/token-setup.ts +5 -1
  45. package/src/create/types.ts +1 -1
  46. package/src/mint/subgraph-mint-getter.ts +5 -2
  47. package/src/mint/subgraph-queries.ts +1 -7
  48. package/src/retries.ts +49 -0
  49. package/src/sdk.ts +8 -0
  50. package/test-integration/create-multiple-tokens-on-contract.ts +104 -0
package/dist/index.cjs CHANGED
@@ -2551,6 +2551,44 @@ var toContractCreationConfigOrAddress = ({
2551
2551
  // src/premint/premint-client.ts
2552
2552
  var import_protocol_deployments4 = require("@zoralabs/protocol-deployments");
2553
2553
 
2554
+ // src/retries.ts
2555
+ async function wait(delayMs) {
2556
+ return new Promise((resolve) => {
2557
+ setTimeout(resolve, delayMs);
2558
+ });
2559
+ }
2560
+ var retryInternal = async ({
2561
+ tryFn,
2562
+ maxTries = 3,
2563
+ atTry,
2564
+ linearBackoffMS = 200,
2565
+ shouldRetryOnError = () => true
2566
+ }) => {
2567
+ try {
2568
+ return await tryFn();
2569
+ } catch (err) {
2570
+ if (shouldRetryOnError(err)) {
2571
+ if (atTry <= maxTries) {
2572
+ await wait(atTry * linearBackoffMS);
2573
+ return await retryInternal({
2574
+ tryFn,
2575
+ maxTries,
2576
+ atTry: atTry + 1,
2577
+ linearBackoffMS,
2578
+ shouldRetryOnError
2579
+ });
2580
+ }
2581
+ }
2582
+ throw err;
2583
+ }
2584
+ };
2585
+ var retriesGeneric = async (params) => {
2586
+ return retryInternal({
2587
+ ...params,
2588
+ atTry: 1
2589
+ });
2590
+ };
2591
+
2554
2592
  // src/apis/http-api-base.ts
2555
2593
  var BadResponseError = class extends Error {
2556
2594
  constructor(message, status, json) {
@@ -2560,11 +2598,6 @@ var BadResponseError = class extends Error {
2560
2598
  this.json = json;
2561
2599
  }
2562
2600
  };
2563
- async function wait(delayMs) {
2564
- return new Promise((resolve) => {
2565
- setTimeout(resolve, delayMs);
2566
- });
2567
- }
2568
2601
  var get = async (url) => {
2569
2602
  const response = await fetch(url, { method: "GET" });
2570
2603
  if (response.status !== 200) {
@@ -2610,20 +2643,16 @@ var post = async (url, data) => {
2610
2643
  }
2611
2644
  return await response.json();
2612
2645
  };
2613
- var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
2614
- try {
2615
- return await tryFn();
2616
- } catch (err) {
2617
- if (err instanceof BadResponseError) {
2618
- if (err.status >= 500) {
2619
- if (atTry <= maxTries) {
2620
- await wait(atTry * linearBackoffMS);
2621
- return await retries(tryFn, maxTries, atTry + 1);
2622
- }
2623
- }
2624
- }
2625
- throw err;
2626
- }
2646
+ var retries = async (tryFn, maxTries = 3, linearBackoffMS = 200) => {
2647
+ const shouldRetry = (err) => {
2648
+ return err instanceof BadResponseError && err.status >= 500;
2649
+ };
2650
+ return retriesGeneric({
2651
+ tryFn,
2652
+ maxTries,
2653
+ linearBackoffMS,
2654
+ shouldRetryOnError: shouldRetry
2655
+ });
2627
2656
  };
2628
2657
  var httpClient = {
2629
2658
  get,
@@ -4247,7 +4276,7 @@ async function mint({
4247
4276
  }
4248
4277
 
4249
4278
  // src/create/1155-create-helper.ts
4250
- var import_protocol_deployments11 = require("@zoralabs/protocol-deployments");
4279
+ var import_protocol_deployments10 = require("@zoralabs/protocol-deployments");
4251
4280
  var import_viem10 = require("viem");
4252
4281
 
4253
4282
  // src/create/contract-setup.ts
@@ -4259,36 +4288,6 @@ function new1155ContractVersion(chainId) {
4259
4288
  }
4260
4289
  return address.CONTRACT_1155_IMPL_VERSION;
4261
4290
  }
4262
- async function getContractInfoExistingContract({
4263
- publicClient,
4264
- contractAddress
4265
- }) {
4266
- let contractVersion;
4267
- try {
4268
- contractVersion = await publicClient.readContract({
4269
- abi: import_protocol_deployments7.zoraCreator1155ImplABI,
4270
- address: contractAddress,
4271
- functionName: "contractVersion"
4272
- });
4273
- } catch (e) {
4274
- throw new Error(`Contract does not exist at ${contractAddress}`);
4275
- }
4276
- const nextTokenId = await publicClient.readContract({
4277
- address: contractAddress,
4278
- abi: import_protocol_deployments7.zoraCreator1155ImplABI,
4279
- functionName: "nextTokenId"
4280
- });
4281
- const contractName = await publicClient.readContract({
4282
- address: contractAddress,
4283
- abi: import_protocol_deployments7.zoraCreator1155ImplABI,
4284
- functionName: "name"
4285
- });
4286
- return {
4287
- contractVersion,
4288
- contractName,
4289
- nextTokenId
4290
- };
4291
- }
4292
4291
  async function getDeterministicContractAddress({
4293
4292
  publicClient,
4294
4293
  account,
@@ -4310,2193 +4309,2261 @@ async function getDeterministicContractAddress({
4310
4309
  });
4311
4310
  return contractAddress;
4312
4311
  }
4312
+ async function getNewContractMintFee({
4313
+ publicClient,
4314
+ chainId
4315
+ }) {
4316
+ const implAddress = import_protocol_deployments7.contracts1155.addresses[chainId].CONTRACT_1155_IMPL;
4317
+ return await publicClient.readContract({
4318
+ abi: import_protocol_deployments7.zoraCreator1155ImplABI,
4319
+ address: implAddress,
4320
+ functionName: "mintFee"
4321
+ });
4322
+ }
4313
4323
 
4314
4324
  // src/create/token-setup.ts
4315
4325
  var import_protocol_deployments9 = require("@zoralabs/protocol-deployments");
4316
4326
  var import_viem8 = require("viem");
4317
4327
  var semver2 = __toESM(require_semver2(), 1);
4318
4328
 
4319
- // src/ipfs/arweave.ts
4320
- function isArweaveURL(url) {
4321
- return url && typeof url === "string" ? url.startsWith("ar://") : false;
4322
- }
4323
-
4324
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
4325
- var empty = new Uint8Array(0);
4326
- function equals(aa, bb) {
4327
- if (aa === bb)
4328
- return true;
4329
- if (aa.byteLength !== bb.byteLength) {
4330
- return false;
4331
- }
4332
- for (let ii = 0; ii < aa.byteLength; ii++) {
4333
- if (aa[ii] !== bb[ii]) {
4334
- return false;
4335
- }
4329
+ // src/create/minter-defaults.ts
4330
+ var SALE_END_FOREVER = 18446744073709551615n;
4331
+ var DEFAULT_SALE_START_AND_END = {
4332
+ // Sale start time – defaults to beginning of unix time
4333
+ saleStart: 0n,
4334
+ // This is the end of uint64, plenty of time
4335
+ saleEnd: SALE_END_FOREVER
4336
+ };
4337
+ var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
4338
+ maxTokensPerAddress: 0n
4339
+ };
4340
+ var erc20SaleSettingsWithDefaults = (params) => ({
4341
+ ...DEFAULT_SALE_START_AND_END,
4342
+ ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
4343
+ ...params
4344
+ });
4345
+ var allowListWithDefaults = (allowlist) => {
4346
+ return {
4347
+ ...DEFAULT_SALE_START_AND_END,
4348
+ ...allowlist
4349
+ };
4350
+ };
4351
+ var fixedPriceSettingsWithDefaults = (params) => ({
4352
+ ...DEFAULT_SALE_START_AND_END,
4353
+ ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
4354
+ type: "fixedPrice",
4355
+ ...params
4356
+ });
4357
+ var parseNameIntoSymbol = (name) => {
4358
+ if (name === "") {
4359
+ throw new Error("Name must be provided to generate a symbol");
4336
4360
  }
4337
- return true;
4338
- }
4339
- function coerce2(o) {
4340
- if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
4341
- return o;
4342
- if (o instanceof ArrayBuffer)
4343
- return new Uint8Array(o);
4344
- if (ArrayBuffer.isView(o)) {
4345
- return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
4361
+ const result = "$" + name.replace(/[^a-zA-Z0-9]/g, "").replace(/^\$+/, "").toUpperCase().replace(/[AEIOU\s]/g, "").slice(0, 4);
4362
+ if (result === "$") {
4363
+ throw new Error("Not enough valid characters to generate a symbol");
4346
4364
  }
4347
- throw new Error("Unknown type, must be binary type");
4348
- }
4349
-
4350
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
4351
- function base2(ALPHABET, name) {
4352
- if (ALPHABET.length >= 255) {
4353
- throw new TypeError("Alphabet too long");
4365
+ return result;
4366
+ };
4367
+ var timedSaleSettingsWithDefaults = async (params, contractName) => {
4368
+ const erc20Name = params.erc20Name || contractName;
4369
+ const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
4370
+ return {
4371
+ type: "timed",
4372
+ ...DEFAULT_SALE_START_AND_END,
4373
+ ...params,
4374
+ erc20Name,
4375
+ erc20Symbol: symbol
4376
+ };
4377
+ };
4378
+ var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
4379
+ var isErc20 = (salesConfig) => salesConfig.type === "erc20Mint";
4380
+ var isFixedPrice = (salesConfig) => {
4381
+ return salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > 0n;
4382
+ };
4383
+ var getSalesConfigWithDefaults = async (salesConfig, contractName) => {
4384
+ if (!salesConfig)
4385
+ return timedSaleSettingsWithDefaults({}, contractName);
4386
+ if (isAllowList(salesConfig)) {
4387
+ return allowListWithDefaults(salesConfig);
4354
4388
  }
4355
- var BASE_MAP = new Uint8Array(256);
4356
- for (var j = 0; j < BASE_MAP.length; j++) {
4357
- BASE_MAP[j] = 255;
4389
+ if (isErc20(salesConfig)) {
4390
+ return erc20SaleSettingsWithDefaults(salesConfig);
4358
4391
  }
4359
- for (var i = 0; i < ALPHABET.length; i++) {
4360
- var x = ALPHABET.charAt(i);
4361
- var xc = x.charCodeAt(0);
4362
- if (BASE_MAP[xc] !== 255) {
4363
- throw new TypeError(x + " is ambiguous");
4364
- }
4365
- BASE_MAP[xc] = i;
4392
+ if (isFixedPrice(salesConfig)) {
4393
+ return fixedPriceSettingsWithDefaults(salesConfig);
4366
4394
  }
4367
- var BASE = ALPHABET.length;
4368
- var LEADER = ALPHABET.charAt(0);
4369
- var FACTOR = Math.log(BASE) / Math.log(256);
4370
- var iFACTOR = Math.log(256) / Math.log(BASE);
4371
- function encode3(source) {
4372
- if (source instanceof Uint8Array)
4373
- ;
4374
- else if (ArrayBuffer.isView(source)) {
4375
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
4376
- } else if (Array.isArray(source)) {
4377
- source = Uint8Array.from(source);
4378
- }
4379
- if (!(source instanceof Uint8Array)) {
4380
- throw new TypeError("Expected Uint8Array");
4381
- }
4382
- if (source.length === 0) {
4383
- return "";
4384
- }
4385
- var zeroes = 0;
4386
- var length2 = 0;
4387
- var pbegin = 0;
4388
- var pend = source.length;
4389
- while (pbegin !== pend && source[pbegin] === 0) {
4390
- pbegin++;
4391
- zeroes++;
4392
- }
4393
- var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
4394
- var b58 = new Uint8Array(size);
4395
- while (pbegin !== pend) {
4396
- var carry = source[pbegin];
4397
- var i2 = 0;
4398
- for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
4399
- carry += 256 * b58[it1] >>> 0;
4400
- b58[it1] = carry % BASE >>> 0;
4401
- carry = carry / BASE >>> 0;
4402
- }
4403
- if (carry !== 0) {
4404
- throw new Error("Non-zero carry");
4395
+ return timedSaleSettingsWithDefaults(salesConfig, contractName);
4396
+ };
4397
+
4398
+ // src/create/minter-setup.ts
4399
+ var import_protocol_deployments8 = require("@zoralabs/protocol-deployments");
4400
+ var import_viem7 = require("viem");
4401
+ var PERMISSION_BITS = {
4402
+ MINTER: 2n ** 2n
4403
+ };
4404
+ function setupErc20Minter({
4405
+ pricePerToken,
4406
+ chainId,
4407
+ tokenId: nextTokenId,
4408
+ currency,
4409
+ saleStart,
4410
+ saleEnd,
4411
+ maxTokensPerAddress: mintLimit,
4412
+ fundsRecipient
4413
+ }) {
4414
+ const erc20MinterAddress = import_protocol_deployments8.erc20MinterAddress[chainId];
4415
+ if (!erc20MinterAddress)
4416
+ throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
4417
+ const erc20MinterApproval = (0, import_viem7.encodeFunctionData)({
4418
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4419
+ functionName: "addPermission",
4420
+ args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
4421
+ });
4422
+ const saleData = (0, import_viem7.encodeFunctionData)({
4423
+ abi: import_protocol_deployments8.erc20MinterABI,
4424
+ functionName: "setSale",
4425
+ args: [
4426
+ BigInt(nextTokenId),
4427
+ {
4428
+ saleStart: saleStart || BigInt(0),
4429
+ saleEnd: saleEnd || BigInt(0),
4430
+ maxTokensPerAddress: BigInt(mintLimit || 0),
4431
+ pricePerToken,
4432
+ fundsRecipient,
4433
+ currency
4405
4434
  }
4406
- length2 = i2;
4407
- pbegin++;
4408
- }
4409
- var it2 = size - length2;
4410
- while (it2 !== size && b58[it2] === 0) {
4411
- it2++;
4412
- }
4413
- var str = LEADER.repeat(zeroes);
4414
- for (; it2 < size; ++it2) {
4415
- str += ALPHABET.charAt(b58[it2]);
4416
- }
4417
- return str;
4418
- }
4419
- function decodeUnsafe(source) {
4420
- if (typeof source !== "string") {
4421
- throw new TypeError("Expected String");
4422
- }
4423
- if (source.length === 0) {
4424
- return new Uint8Array();
4425
- }
4426
- var psz = 0;
4427
- if (source[psz] === " ") {
4428
- return;
4429
- }
4430
- var zeroes = 0;
4431
- var length2 = 0;
4432
- while (source[psz] === LEADER) {
4433
- zeroes++;
4434
- psz++;
4435
- }
4436
- var size = (source.length - psz) * FACTOR + 1 >>> 0;
4437
- var b256 = new Uint8Array(size);
4438
- while (source[psz]) {
4439
- var carry = BASE_MAP[source.charCodeAt(psz)];
4440
- if (carry === 255) {
4441
- return;
4435
+ ]
4436
+ });
4437
+ const callSale = (0, import_viem7.encodeFunctionData)({
4438
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4439
+ functionName: "callSale",
4440
+ args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
4441
+ });
4442
+ return {
4443
+ minter: erc20MinterAddress,
4444
+ setupActions: [erc20MinterApproval, callSale]
4445
+ };
4446
+ }
4447
+ function setupFixedPriceMinter({
4448
+ pricePerToken: price,
4449
+ tokenId: nextTokenId,
4450
+ chainId,
4451
+ saleStart,
4452
+ saleEnd,
4453
+ maxTokensPerAddress: mintLimit,
4454
+ fundsRecipient
4455
+ }) {
4456
+ const fixedPriceStrategyAddress = import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyAddress[chainId];
4457
+ const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
4458
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4459
+ functionName: "addPermission",
4460
+ args: [
4461
+ BigInt(nextTokenId),
4462
+ fixedPriceStrategyAddress,
4463
+ PERMISSION_BITS.MINTER
4464
+ ]
4465
+ });
4466
+ const saleData = (0, import_viem7.encodeFunctionData)({
4467
+ abi: import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyABI,
4468
+ functionName: "setSale",
4469
+ args: [
4470
+ BigInt(nextTokenId),
4471
+ {
4472
+ pricePerToken: price,
4473
+ saleStart: saleStart || BigInt(0),
4474
+ saleEnd: saleEnd || BigInt(0),
4475
+ maxTokensPerAddress: BigInt(mintLimit || 0),
4476
+ fundsRecipient
4442
4477
  }
4443
- var i2 = 0;
4444
- for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
4445
- carry += BASE * b256[it3] >>> 0;
4446
- b256[it3] = carry % 256 >>> 0;
4447
- carry = carry / 256 >>> 0;
4478
+ ]
4479
+ });
4480
+ const callSale = (0, import_viem7.encodeFunctionData)({
4481
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4482
+ functionName: "callSale",
4483
+ args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
4484
+ });
4485
+ return {
4486
+ minter: fixedPriceStrategyAddress,
4487
+ setupActions: [fixedPriceApproval, callSale]
4488
+ };
4489
+ }
4490
+ function setupTimedSaleMinter({
4491
+ chainId,
4492
+ tokenId,
4493
+ erc20Name: erc20zName,
4494
+ erc20Symbol: erc20zSymbol,
4495
+ saleStart,
4496
+ saleEnd
4497
+ }) {
4498
+ const minterAddress = import_protocol_deployments8.zoraTimedSaleStrategyAddress[chainId];
4499
+ const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
4500
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4501
+ functionName: "addPermission",
4502
+ args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER]
4503
+ });
4504
+ const saleData = (0, import_viem7.encodeFunctionData)({
4505
+ abi: import_protocol_deployments8.zoraTimedSaleStrategyABI,
4506
+ functionName: "setSale",
4507
+ args: [
4508
+ BigInt(tokenId),
4509
+ {
4510
+ saleStart,
4511
+ saleEnd,
4512
+ name: erc20zName,
4513
+ symbol: erc20zSymbol
4448
4514
  }
4449
- if (carry !== 0) {
4450
- throw new Error("Non-zero carry");
4515
+ ]
4516
+ });
4517
+ const callSale = (0, import_viem7.encodeFunctionData)({
4518
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4519
+ functionName: "callSale",
4520
+ args: [BigInt(tokenId), minterAddress, saleData]
4521
+ });
4522
+ return {
4523
+ minter: minterAddress,
4524
+ setupActions: [fixedPriceApproval, callSale]
4525
+ };
4526
+ }
4527
+ function setupAllowListMinter({
4528
+ chainId,
4529
+ tokenId: nextTokenId,
4530
+ allowlist,
4531
+ fundsRecipient
4532
+ }) {
4533
+ const merkleSaleStrategyAddress = import_protocol_deployments8.zoraCreatorMerkleMinterStrategyAddress[chainId];
4534
+ const merkleApproval = (0, import_viem7.encodeFunctionData)({
4535
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4536
+ functionName: "addPermission",
4537
+ args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER]
4538
+ });
4539
+ const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x") ? allowlist.presaleMerkleRoot : `0x${allowlist.presaleMerkleRoot}`;
4540
+ const saleData = (0, import_viem7.encodeFunctionData)({
4541
+ abi: import_protocol_deployments8.zoraCreatorMerkleMinterStrategyABI,
4542
+ functionName: "setSale",
4543
+ args: [
4544
+ BigInt(nextTokenId),
4545
+ {
4546
+ presaleStart: allowlist.saleStart,
4547
+ presaleEnd: allowlist.saleEnd,
4548
+ merkleRoot,
4549
+ fundsRecipient
4451
4550
  }
4452
- length2 = i2;
4453
- psz++;
4454
- }
4455
- if (source[psz] === " ") {
4456
- return;
4457
- }
4458
- var it4 = size - length2;
4459
- while (it4 !== size && b256[it4] === 0) {
4460
- it4++;
4461
- }
4462
- var vch = new Uint8Array(zeroes + (size - it4));
4463
- var j2 = zeroes;
4464
- while (it4 !== size) {
4465
- vch[j2++] = b256[it4++];
4466
- }
4467
- return vch;
4551
+ ]
4552
+ });
4553
+ const callSaleMerkle = (0, import_viem7.encodeFunctionData)({
4554
+ abi: import_protocol_deployments8.zoraCreator1155ImplABI,
4555
+ functionName: "callSale",
4556
+ args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData]
4557
+ });
4558
+ return {
4559
+ minter: merkleSaleStrategyAddress,
4560
+ setupActions: [merkleApproval, callSaleMerkle]
4561
+ };
4562
+ }
4563
+ var isAllowList2 = (salesConfig) => salesConfig.type === "allowlistMint";
4564
+ var isErc202 = (salesConfig) => salesConfig.type === "erc20Mint";
4565
+ var isFixedPrice2 = (salesConfig) => salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > BigInt(0);
4566
+ function setupMinters({ salesConfig, ...rest }) {
4567
+ if (isErc202(salesConfig)) {
4568
+ return setupErc20Minter({
4569
+ ...salesConfig,
4570
+ ...rest
4571
+ });
4468
4572
  }
4469
- function decode5(string) {
4470
- var buffer = decodeUnsafe(string);
4471
- if (buffer) {
4472
- return buffer;
4473
- }
4474
- throw new Error(`Non-${name} character`);
4573
+ if (isAllowList2(salesConfig)) {
4574
+ return setupAllowListMinter({
4575
+ allowlist: salesConfig,
4576
+ ...rest
4577
+ });
4475
4578
  }
4579
+ if (isFixedPrice2(salesConfig))
4580
+ return setupFixedPriceMinter({
4581
+ ...salesConfig,
4582
+ ...rest
4583
+ });
4584
+ return setupTimedSaleMinter({
4585
+ ...salesConfig,
4586
+ ...rest
4587
+ });
4588
+ }
4589
+
4590
+ // src/create/token-setup.ts
4591
+ async function applyNew1155Defaults(props, ownerAddress, contractName) {
4592
+ const { payoutRecipient: fundsRecipient } = props;
4593
+ const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== import_viem8.zeroAddress ? fundsRecipient : ownerAddress;
4476
4594
  return {
4477
- encode: encode3,
4478
- decodeUnsafe,
4479
- decode: decode5
4595
+ payoutRecipient: fundsRecipientOrOwner,
4596
+ createReferral: props.createReferral || import_viem8.zeroAddress,
4597
+ maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
4598
+ royaltyBPS: props.royaltyBPS || 1e3,
4599
+ tokenMetadataURI: props.tokenMetadataURI,
4600
+ salesConfig: await getSalesConfigWithDefaults(
4601
+ props.salesConfig,
4602
+ contractName
4603
+ )
4480
4604
  };
4481
4605
  }
4482
- var src = base2;
4483
- var _brrp__multiformats_scope_baseX = src;
4484
- var base_x_default = _brrp__multiformats_scope_baseX;
4485
-
4486
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
4487
- var Encoder = class {
4488
- constructor(name, prefix, baseEncode) {
4489
- __publicField(this, "name");
4490
- __publicField(this, "prefix");
4491
- __publicField(this, "baseEncode");
4492
- this.name = name;
4493
- this.prefix = prefix;
4494
- this.baseEncode = baseEncode;
4606
+ function buildSetupNewToken({
4607
+ tokenURI,
4608
+ maxSupply = OPEN_EDITION_MINT_SIZE,
4609
+ createReferral = import_viem8.zeroAddress,
4610
+ contractVersion
4611
+ }) {
4612
+ if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
4613
+ return (0, import_viem8.encodeFunctionData)({
4614
+ abi: import_protocol_deployments9.zoraCreator1155ImplABI,
4615
+ functionName: "setupNewTokenWithCreateReferral",
4616
+ args: [tokenURI, BigInt(maxSupply), createReferral]
4617
+ });
4495
4618
  }
4496
- encode(bytes) {
4497
- if (bytes instanceof Uint8Array) {
4498
- return `${this.prefix}${this.baseEncode(bytes)}`;
4499
- } else {
4500
- throw Error("Unknown type, must be binary type");
4501
- }
4619
+ if (createReferral !== import_viem8.zeroAddress) {
4620
+ throw new Error(
4621
+ "Contract does not support create referral, but one was provided"
4622
+ );
4502
4623
  }
4503
- };
4504
- var Decoder = class {
4505
- constructor(name, prefix, baseDecode) {
4506
- __publicField(this, "name");
4507
- __publicField(this, "prefix");
4508
- __publicField(this, "baseDecode");
4509
- __publicField(this, "prefixCodePoint");
4510
- this.name = name;
4511
- this.prefix = prefix;
4512
- if (prefix.codePointAt(0) === void 0) {
4513
- throw new Error("Invalid prefix character");
4514
- }
4515
- this.prefixCodePoint = prefix.codePointAt(0);
4516
- this.baseDecode = baseDecode;
4517
- }
4518
- decode(text) {
4519
- if (typeof text === "string") {
4520
- if (text.codePointAt(0) !== this.prefixCodePoint) {
4521
- throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
4522
- }
4523
- return this.baseDecode(text.slice(this.prefix.length));
4524
- } else {
4525
- throw Error("Can only multibase decode strings");
4526
- }
4527
- }
4528
- or(decoder) {
4529
- return or(this, decoder);
4530
- }
4531
- };
4532
- var ComposedDecoder = class {
4533
- constructor(decoders) {
4534
- __publicField(this, "decoders");
4535
- this.decoders = decoders;
4536
- }
4537
- or(decoder) {
4538
- return or(this, decoder);
4539
- }
4540
- decode(input) {
4541
- const prefix = input[0];
4542
- const decoder = this.decoders[prefix];
4543
- if (decoder != null) {
4544
- return decoder.decode(input);
4545
- } else {
4546
- throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
4547
- }
4548
- }
4549
- };
4550
- function or(left, right) {
4551
- return new ComposedDecoder({
4552
- ...left.decoders ?? { [left.prefix]: left },
4553
- ...right.decoders ?? { [right.prefix]: right }
4624
+ return (0, import_viem8.encodeFunctionData)({
4625
+ abi: import_protocol_deployments9.zoraCreator1155ImplABI,
4626
+ functionName: "setupNewToken",
4627
+ args: [tokenURI, BigInt(maxSupply)]
4554
4628
  });
4555
4629
  }
4556
- var Codec = class {
4557
- constructor(name, prefix, baseEncode, baseDecode) {
4558
- __publicField(this, "name");
4559
- __publicField(this, "prefix");
4560
- __publicField(this, "baseEncode");
4561
- __publicField(this, "baseDecode");
4562
- __publicField(this, "encoder");
4563
- __publicField(this, "decoder");
4564
- this.name = name;
4565
- this.prefix = prefix;
4566
- this.baseEncode = baseEncode;
4567
- this.baseDecode = baseDecode;
4568
- this.encoder = new Encoder(name, prefix, baseEncode);
4569
- this.decoder = new Decoder(name, prefix, baseDecode);
4570
- }
4571
- encode(input) {
4572
- return this.encoder.encode(input);
4630
+ function setupRoyaltyConfig({
4631
+ royaltyBPS,
4632
+ royaltyRecipient,
4633
+ nextTokenId
4634
+ }) {
4635
+ if (royaltyBPS > 0 && royaltyRecipient != import_viem8.zeroAddress) {
4636
+ return (0, import_viem8.encodeFunctionData)({
4637
+ abi: import_protocol_deployments9.zoraCreator1155ImplABI,
4638
+ functionName: "updateRoyaltiesForToken",
4639
+ args: [
4640
+ nextTokenId,
4641
+ {
4642
+ royaltyBPS,
4643
+ royaltyRecipient,
4644
+ royaltyMintSchedule: 0
4645
+ }
4646
+ ]
4647
+ });
4573
4648
  }
4574
- decode(input) {
4575
- return this.decoder.decode(input);
4649
+ return null;
4650
+ }
4651
+ function makeAdminMintCall({
4652
+ ownerAddress,
4653
+ mintQuantity,
4654
+ nextTokenId
4655
+ }) {
4656
+ if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
4657
+ return null;
4576
4658
  }
4577
- };
4578
- function from({ name, prefix, encode: encode3, decode: decode5 }) {
4579
- return new Codec(name, prefix, encode3, decode5);
4659
+ return (0, import_viem8.encodeFunctionData)({
4660
+ abi: import_protocol_deployments9.zoraCreator1155ImplABI,
4661
+ functionName: "adminMint",
4662
+ args: [ownerAddress, nextTokenId, BigInt(mintQuantity), import_viem8.zeroAddress]
4663
+ });
4580
4664
  }
4581
- function baseX({ name, prefix, alphabet }) {
4582
- const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
4583
- return from({
4584
- prefix,
4585
- name,
4586
- encode: encode3,
4587
- decode: (text) => coerce2(decode5(text))
4665
+ async function constructCreate1155TokenCalls(props) {
4666
+ const {
4667
+ chainId,
4668
+ nextTokenId,
4669
+ mintToCreatorCount,
4670
+ ownerAddress,
4671
+ contractVersion
4672
+ } = props;
4673
+ const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
4674
+ props,
4675
+ ownerAddress,
4676
+ props.contractName
4677
+ );
4678
+ const verifyTokenIdExpected = (0, import_viem8.encodeFunctionData)({
4679
+ abi: import_protocol_deployments9.zoraCreator1155ImplABI,
4680
+ functionName: "assumeLastTokenIdMatches",
4681
+ args: [nextTokenId - 1n]
4682
+ });
4683
+ const setupNewToken = buildSetupNewToken({
4684
+ tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
4685
+ maxSupply: new1155TokenPropsWithDefaults.maxSupply,
4686
+ createReferral: new1155TokenPropsWithDefaults.createReferral,
4687
+ contractVersion
4688
+ });
4689
+ const royaltyConfig = setupRoyaltyConfig({
4690
+ royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
4691
+ royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
4692
+ nextTokenId
4588
4693
  });
4694
+ const { minter, setupActions: mintersSetup } = setupMinters({
4695
+ tokenId: nextTokenId,
4696
+ chainId,
4697
+ fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
4698
+ salesConfig: new1155TokenPropsWithDefaults.salesConfig
4699
+ });
4700
+ const adminMintCall = makeAdminMintCall({
4701
+ ownerAddress,
4702
+ mintQuantity: mintToCreatorCount,
4703
+ nextTokenId
4704
+ });
4705
+ const setupActions = [
4706
+ verifyTokenIdExpected,
4707
+ setupNewToken,
4708
+ ...mintersSetup,
4709
+ royaltyConfig,
4710
+ adminMintCall
4711
+ ].filter((item) => item !== null);
4712
+ return {
4713
+ setupActions,
4714
+ minter,
4715
+ newToken: new1155TokenPropsWithDefaults
4716
+ };
4589
4717
  }
4590
- function decode(string, alphabet, bitsPerChar, name) {
4591
- const codes = {};
4592
- for (let i = 0; i < alphabet.length; ++i) {
4593
- codes[alphabet[i]] = i;
4594
- }
4595
- let end = string.length;
4596
- while (string[end - 1] === "=") {
4597
- --end;
4598
- }
4599
- const out = new Uint8Array(end * bitsPerChar / 8 | 0);
4600
- let bits = 0;
4601
- let buffer = 0;
4602
- let written = 0;
4603
- for (let i = 0; i < end; ++i) {
4604
- const value = codes[string[i]];
4605
- if (value === void 0) {
4606
- throw new SyntaxError(`Non-${name} character`);
4607
- }
4608
- buffer = buffer << bitsPerChar | value;
4609
- bits += bitsPerChar;
4610
- if (bits >= 8) {
4611
- bits -= 8;
4612
- out[written++] = 255 & buffer >> bits;
4613
- }
4718
+ var contractSupportsMintRewards = (contractVersion, contractStandard) => {
4719
+ if (!contractStandard || !contractVersion) {
4720
+ return false;
4614
4721
  }
4615
- if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
4616
- throw new SyntaxError("Unexpected end of data");
4722
+ const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
4723
+ if (!semVerContractVersion)
4724
+ return false;
4725
+ if (contractStandard === "ERC1155") {
4726
+ return semver2.gte(semVerContractVersion, "1.3.5");
4727
+ } else {
4728
+ return semver2.gte(semVerContractVersion, "14.0.0");
4617
4729
  }
4618
- return out;
4619
- }
4620
- function encode(data, alphabet, bitsPerChar) {
4621
- const pad = alphabet[alphabet.length - 1] === "=";
4622
- const mask = (1 << bitsPerChar) - 1;
4623
- let out = "";
4624
- let bits = 0;
4625
- let buffer = 0;
4626
- for (let i = 0; i < data.length; ++i) {
4627
- buffer = buffer << 8 | data[i];
4628
- bits += 8;
4629
- while (bits > bitsPerChar) {
4630
- bits -= bitsPerChar;
4631
- out += alphabet[mask & buffer >> bits];
4632
- }
4730
+ };
4731
+
4732
+ // src/create/mint-from-create.ts
4733
+ var import_viem9 = require("viem");
4734
+ async function toSalesStrategyFromSubgraph({
4735
+ minter,
4736
+ salesConfig,
4737
+ getContractMintFee
4738
+ }) {
4739
+ if (salesConfig.type === "timed") {
4740
+ return {
4741
+ saleType: "timed",
4742
+ address: minter,
4743
+ // for now we hardcode this
4744
+ mintFeePerQuantity: (0, import_viem9.parseEther)("0.000111"),
4745
+ saleStart: salesConfig.saleStart.toString(),
4746
+ saleEnd: salesConfig.saleEnd.toString(),
4747
+ // the following are not needed for now but we wanna satisfy concrete
4748
+ erc20Z: import_viem9.zeroAddress,
4749
+ mintFee: 0n,
4750
+ pool: import_viem9.zeroAddress,
4751
+ secondaryActivated: false
4752
+ };
4633
4753
  }
4634
- if (bits !== 0) {
4635
- out += alphabet[mask & buffer << bitsPerChar - bits];
4754
+ if (salesConfig.type === "erc20Mint") {
4755
+ return {
4756
+ saleType: "erc20",
4757
+ address: minter,
4758
+ mintFeePerQuantity: 0n,
4759
+ saleStart: salesConfig.saleStart.toString(),
4760
+ saleEnd: salesConfig.saleEnd.toString(),
4761
+ currency: salesConfig.currency,
4762
+ pricePerToken: salesConfig.pricePerToken,
4763
+ maxTokensPerAddress: salesConfig.maxTokensPerAddress
4764
+ };
4636
4765
  }
4637
- if (pad) {
4638
- while ((out.length * bitsPerChar & 7) !== 0) {
4639
- out += "=";
4640
- }
4766
+ const contractMintFee = await getContractMintFee();
4767
+ if (salesConfig.type === "fixedPrice") {
4768
+ return {
4769
+ saleType: "fixedPrice",
4770
+ address: minter,
4771
+ maxTokensPerAddress: salesConfig.maxTokensPerAddress,
4772
+ mintFeePerQuantity: contractMintFee,
4773
+ pricePerToken: salesConfig.pricePerToken,
4774
+ saleStart: salesConfig.saleStart.toString(),
4775
+ saleEnd: salesConfig.saleEnd.toString()
4776
+ };
4641
4777
  }
4642
- return out;
4643
- }
4644
- function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
4645
- return from({
4646
- prefix,
4647
- name,
4648
- encode(input) {
4649
- return encode(input, alphabet, bitsPerChar);
4650
- },
4651
- decode(input) {
4652
- return decode(input, alphabet, bitsPerChar, name);
4653
- }
4654
- });
4778
+ return {
4779
+ saleType: "allowlist",
4780
+ address: minter,
4781
+ saleStart: salesConfig.saleStart.toString(),
4782
+ saleEnd: salesConfig.saleEnd.toString(),
4783
+ merkleRoot: salesConfig.presaleMerkleRoot,
4784
+ mintFeePerQuantity: contractMintFee
4785
+ };
4655
4786
  }
4656
-
4657
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
4658
- var base32 = rfc4648({
4659
- prefix: "b",
4660
- name: "base32",
4661
- alphabet: "abcdefghijklmnopqrstuvwxyz234567",
4662
- bitsPerChar: 5
4663
- });
4664
- var base32upper = rfc4648({
4665
- prefix: "B",
4666
- name: "base32upper",
4667
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
4668
- bitsPerChar: 5
4669
- });
4670
- var base32pad = rfc4648({
4671
- prefix: "c",
4672
- name: "base32pad",
4673
- alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
4674
- bitsPerChar: 5
4675
- });
4676
- var base32padupper = rfc4648({
4677
- prefix: "C",
4678
- name: "base32padupper",
4679
- alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
4680
- bitsPerChar: 5
4681
- });
4682
- var base32hex = rfc4648({
4683
- prefix: "v",
4684
- name: "base32hex",
4685
- alphabet: "0123456789abcdefghijklmnopqrstuv",
4686
- bitsPerChar: 5
4687
- });
4688
- var base32hexupper = rfc4648({
4689
- prefix: "V",
4690
- name: "base32hexupper",
4691
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
4692
- bitsPerChar: 5
4693
- });
4694
- var base32hexpad = rfc4648({
4695
- prefix: "t",
4696
- name: "base32hexpad",
4697
- alphabet: "0123456789abcdefghijklmnopqrstuv=",
4698
- bitsPerChar: 5
4699
- });
4700
- var base32hexpadupper = rfc4648({
4701
- prefix: "T",
4702
- name: "base32hexpadupper",
4703
- alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
4704
- bitsPerChar: 5
4705
- });
4706
- var base32z = rfc4648({
4707
- prefix: "h",
4708
- name: "base32z",
4709
- alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
4710
- bitsPerChar: 5
4711
- });
4712
-
4713
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
4714
- var base58btc = baseX({
4715
- name: "base58btc",
4716
- prefix: "z",
4717
- alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
4718
- });
4719
- var base58flickr = baseX({
4720
- name: "base58flickr",
4721
- prefix: "Z",
4722
- alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
4723
- });
4724
-
4725
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
4726
- var encode_1 = encode2;
4727
- var MSB = 128;
4728
- var REST = 127;
4729
- var MSBALL = ~REST;
4730
- var INT = Math.pow(2, 31);
4731
- function encode2(num, out, offset) {
4732
- out = out || [];
4733
- offset = offset || 0;
4734
- var oldOffset = offset;
4735
- while (num >= INT) {
4736
- out[offset++] = num & 255 | MSB;
4737
- num /= 128;
4738
- }
4739
- while (num & MSBALL) {
4740
- out[offset++] = num & 255 | MSB;
4741
- num >>>= 7;
4742
- }
4743
- out[offset] = num | 0;
4744
- encode2.bytes = offset - oldOffset + 1;
4745
- return out;
4787
+ function makeOnchainPrepareMintFromCreate({
4788
+ contractAddress,
4789
+ tokenId,
4790
+ result,
4791
+ minter,
4792
+ getContractMintFee,
4793
+ contractVersion
4794
+ }) {
4795
+ return async (params) => {
4796
+ const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
4797
+ minter,
4798
+ getContractMintFee,
4799
+ salesConfig: result
4800
+ });
4801
+ return {
4802
+ parameters: makePrepareMint1155TokenParams({
4803
+ salesConfigAndTokenInfo: {
4804
+ salesConfig: subgraphSalesConfig,
4805
+ contractVersion
4806
+ },
4807
+ ...params,
4808
+ tokenContract: contractAddress,
4809
+ tokenId
4810
+ }),
4811
+ costs: parseMintCosts({
4812
+ allowListEntry: params.allowListEntry,
4813
+ quantityToMint: BigInt(params.quantityToMint),
4814
+ salesConfig: subgraphSalesConfig
4815
+ }),
4816
+ erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
4817
+ };
4818
+ };
4746
4819
  }
4747
- var decode2 = read;
4748
- var MSB$1 = 128;
4749
- var REST$1 = 127;
4750
- function read(buf, offset) {
4751
- var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
4752
- do {
4753
- if (counter >= l) {
4754
- read.bytes = 0;
4755
- throw new RangeError("Could not decode varint");
4820
+
4821
+ // src/create/1155-create-helper.ts
4822
+ var ROYALTY_BPS_DEFAULT = 1e3;
4823
+ var getTokenIdFromCreateReceipt = (receipt) => {
4824
+ for (const data of receipt.logs) {
4825
+ try {
4826
+ const decodedLog = (0, import_viem10.decodeEventLog)({
4827
+ abi: import_protocol_deployments10.zoraCreator1155ImplABI,
4828
+ eventName: "SetupNewToken",
4829
+ ...data
4830
+ });
4831
+ if (decodedLog && decodedLog.eventName === "SetupNewToken") {
4832
+ return decodedLog.args.tokenId;
4833
+ }
4834
+ } catch (err) {
4756
4835
  }
4757
- b = buf[counter++];
4758
- res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
4759
- shift += 7;
4760
- } while (b >= MSB$1);
4761
- read.bytes = counter - offset;
4762
- return res;
4763
- }
4764
- var N1 = Math.pow(2, 7);
4765
- var N2 = Math.pow(2, 14);
4766
- var N3 = Math.pow(2, 21);
4767
- var N4 = Math.pow(2, 28);
4768
- var N5 = Math.pow(2, 35);
4769
- var N6 = Math.pow(2, 42);
4770
- var N7 = Math.pow(2, 49);
4771
- var N8 = Math.pow(2, 56);
4772
- var N9 = Math.pow(2, 63);
4773
- var length = function(value) {
4774
- return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
4836
+ }
4837
+ throw new Error(
4838
+ "No event found in receipt that could be used to get tokenId"
4839
+ );
4775
4840
  };
4776
- var varint = {
4777
- encode: encode_1,
4778
- decode: decode2,
4779
- encodingLength: length
4841
+ var getContractAddressFromReceipt = (receipt) => {
4842
+ for (const data of receipt.logs) {
4843
+ try {
4844
+ const decodedLog = (0, import_viem10.decodeEventLog)({
4845
+ abi: import_protocol_deployments10.zoraCreator1155FactoryImplABI,
4846
+ eventName: "SetupNewContract",
4847
+ ...data
4848
+ });
4849
+ if (decodedLog && decodedLog.eventName === "SetupNewContract") {
4850
+ return decodedLog.args.newContract;
4851
+ }
4852
+ } catch (err) {
4853
+ }
4854
+ }
4855
+ throw new Error(
4856
+ "No event found in receipt that could be used to get contract address"
4857
+ );
4780
4858
  };
4781
- var _brrp_varint = varint;
4782
- var varint_default = _brrp_varint;
4783
-
4784
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
4785
- function decode3(data, offset = 0) {
4786
- const code = varint_default.decode(data, offset);
4787
- return [code, varint_default.decode.bytes];
4788
- }
4789
- function encodeTo(int, target, offset = 0) {
4790
- varint_default.encode(int, target, offset);
4791
- return target;
4859
+ function makeCreateContractAndTokenCall({
4860
+ account,
4861
+ contract,
4862
+ royaltyBPS,
4863
+ fundsRecipient,
4864
+ tokenSetupActions,
4865
+ chainId
4866
+ }) {
4867
+ const accountAddress = typeof account === "string" ? account : account.address;
4868
+ return makeContractParameters({
4869
+ abi: import_protocol_deployments10.zoraCreator1155FactoryImplABI,
4870
+ functionName: "createContractDeterministic",
4871
+ account,
4872
+ address: import_protocol_deployments10.zoraCreator1155FactoryImplAddress[chainId],
4873
+ args: [
4874
+ contract.uri,
4875
+ contract.name,
4876
+ {
4877
+ // deprecated
4878
+ royaltyMintSchedule: 0,
4879
+ royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
4880
+ royaltyRecipient: fundsRecipient || accountAddress
4881
+ },
4882
+ contract.defaultAdmin || accountAddress,
4883
+ tokenSetupActions
4884
+ ]
4885
+ });
4792
4886
  }
4793
- function encodingLength(int) {
4794
- return varint_default.encodingLength(int);
4887
+ function makeCreateTokenCall({
4888
+ contractAddress,
4889
+ account,
4890
+ tokenSetupActions
4891
+ }) {
4892
+ return makeContractParameters({
4893
+ abi: import_protocol_deployments10.zoraCreator1155ImplABI,
4894
+ functionName: "multicall",
4895
+ account,
4896
+ address: contractAddress,
4897
+ args: [tokenSetupActions]
4898
+ });
4795
4899
  }
4796
-
4797
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
4798
- function create(code, digest) {
4799
- const size = digest.byteLength;
4800
- const sizeOffset = encodingLength(code);
4801
- const digestOffset = sizeOffset + encodingLength(size);
4802
- const bytes = new Uint8Array(digestOffset + size);
4803
- encodeTo(code, bytes, 0);
4804
- encodeTo(size, bytes, sizeOffset);
4805
- bytes.set(digest, digestOffset);
4806
- return new Digest(code, size, digest, bytes);
4807
- }
4808
- function decode4(multihash) {
4809
- const bytes = coerce2(multihash);
4810
- const [code, sizeOffset] = decode3(bytes);
4811
- const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
4812
- const digest = bytes.subarray(sizeOffset + digestOffset);
4813
- if (digest.byteLength !== size) {
4814
- throw new Error("Incorrect length");
4900
+ var Create1155Client = class {
4901
+ constructor({
4902
+ chainId,
4903
+ publicClient,
4904
+ contractGetter
4905
+ }) {
4906
+ this.chainId = chainId;
4907
+ this.publicClient = publicClient;
4908
+ this.contractGetter = contractGetter;
4815
4909
  }
4816
- return new Digest(code, size, digest, bytes);
4817
- }
4818
- function equals2(a, b) {
4819
- if (a === b) {
4820
- return true;
4821
- } else {
4822
- const data = b;
4823
- return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
4910
+ async createNew1155(props) {
4911
+ return createNew1155ContractAndToken({
4912
+ ...props,
4913
+ publicClient: this.publicClient,
4914
+ chainId: this.chainId
4915
+ });
4824
4916
  }
4825
- }
4826
- var Digest = class {
4827
- /**
4828
- * Creates a multihash digest.
4829
- */
4830
- constructor(code, size, digest, bytes) {
4831
- __publicField(this, "code");
4832
- __publicField(this, "size");
4833
- __publicField(this, "digest");
4834
- __publicField(this, "bytes");
4835
- this.code = code;
4836
- this.size = size;
4837
- this.digest = digest;
4838
- this.bytes = bytes;
4917
+ async createNew1155OnExistingContract({
4918
+ contractAddress: contract,
4919
+ account,
4920
+ token,
4921
+ getAdditionalSetupActions
4922
+ }) {
4923
+ return createNew1155Token({
4924
+ contractAddress: contract,
4925
+ account,
4926
+ token,
4927
+ getAdditionalSetupActions,
4928
+ publicClient: this.publicClient,
4929
+ chainId: this.chainId,
4930
+ contractGetter: this.contractGetter
4931
+ });
4839
4932
  }
4840
4933
  };
4841
-
4842
- // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
4843
- function format(link, base3) {
4844
- const { bytes, version } = link;
4845
- switch (version) {
4846
- case 0:
4847
- return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
4848
- default:
4849
- return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
4850
- }
4934
+ async function createNew1155ContractAndToken({
4935
+ contract,
4936
+ account,
4937
+ chainId,
4938
+ token,
4939
+ publicClient,
4940
+ getAdditionalSetupActions
4941
+ }) {
4942
+ const nextTokenId = 1n;
4943
+ const contractVersion = new1155ContractVersion(chainId);
4944
+ const {
4945
+ minter,
4946
+ newToken,
4947
+ setupActions: tokenSetupActions
4948
+ } = await prepareSetupActions({
4949
+ chainId,
4950
+ account,
4951
+ contractVersion,
4952
+ nextTokenId,
4953
+ token,
4954
+ getAdditionalSetupActions,
4955
+ contractName: contract.name
4956
+ });
4957
+ const request = makeCreateContractAndTokenCall({
4958
+ contract,
4959
+ account,
4960
+ chainId,
4961
+ tokenSetupActions,
4962
+ fundsRecipient: token.payoutRecipient,
4963
+ royaltyBPS: token.royaltyBPS
4964
+ });
4965
+ const contractAddress = await getDeterministicContractAddress({
4966
+ account,
4967
+ publicClient,
4968
+ setupActions: tokenSetupActions,
4969
+ chainId,
4970
+ contract
4971
+ });
4972
+ const prepareMint = makeOnchainPrepareMintFromCreate({
4973
+ contractAddress,
4974
+ contractVersion,
4975
+ minter,
4976
+ result: newToken.salesConfig,
4977
+ tokenId: nextTokenId,
4978
+ // to get the contract wide mint fee, we get what it would be for a new contract
4979
+ getContractMintFee: async () => getNewContractMintFee({
4980
+ publicClient,
4981
+ chainId
4982
+ })
4983
+ });
4984
+ return {
4985
+ parameters: request,
4986
+ tokenSetupActions,
4987
+ newTokenId: nextTokenId,
4988
+ newToken,
4989
+ contractAddress,
4990
+ contractVersion,
4991
+ minter,
4992
+ prepareMint
4993
+ };
4851
4994
  }
4852
- var cache = /* @__PURE__ */ new WeakMap();
4853
- function baseCache(cid) {
4854
- const baseCache2 = cache.get(cid);
4855
- if (baseCache2 == null) {
4856
- const baseCache3 = /* @__PURE__ */ new Map();
4857
- cache.set(cid, baseCache3);
4858
- return baseCache3;
4859
- }
4860
- return baseCache2;
4995
+ async function createNew1155Token({
4996
+ contractAddress,
4997
+ account,
4998
+ getAdditionalSetupActions,
4999
+ token,
5000
+ chainId,
5001
+ contractGetter
5002
+ }) {
5003
+ const { nextTokenId, contractVersion, mintFee, name } = await contractGetter.getContractInfo({ contractAddress, retries: 5 });
5004
+ const {
5005
+ minter,
5006
+ newToken,
5007
+ setupActions: tokenSetupActions
5008
+ } = await prepareSetupActions({
5009
+ chainId,
5010
+ account,
5011
+ contractVersion,
5012
+ nextTokenId,
5013
+ token,
5014
+ getAdditionalSetupActions,
5015
+ contractName: name
5016
+ });
5017
+ const request = makeCreateTokenCall({
5018
+ contractAddress,
5019
+ account,
5020
+ tokenSetupActions
5021
+ });
5022
+ const prepareMint = makeOnchainPrepareMintFromCreate({
5023
+ contractAddress,
5024
+ contractVersion,
5025
+ minter,
5026
+ result: newToken.salesConfig,
5027
+ tokenId: nextTokenId,
5028
+ getContractMintFee: async () => mintFee
5029
+ });
5030
+ return {
5031
+ parameters: request,
5032
+ tokenSetupActions,
5033
+ newTokenId: nextTokenId,
5034
+ newToken,
5035
+ contractVersion,
5036
+ minter,
5037
+ prepareMint
5038
+ };
4861
5039
  }
4862
- var _a;
4863
- var CID = class _CID {
4864
- /**
4865
- * @param version - Version of the CID
4866
- * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
4867
- * @param multihash - (Multi)hash of the of the content.
4868
- */
4869
- constructor(version, code, multihash, bytes) {
4870
- __publicField(this, "code");
4871
- __publicField(this, "version");
4872
- __publicField(this, "multihash");
4873
- __publicField(this, "bytes");
4874
- __publicField(this, "/");
4875
- __publicField(this, _a, "CID");
4876
- this.code = code;
4877
- this.version = version;
4878
- this.multihash = multihash;
4879
- this.bytes = bytes;
4880
- this["/"] = bytes;
4881
- }
4882
- /**
4883
- * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
4884
- * please either use `CID.asCID(cid)` or switch to new signalling mechanism
4885
- *
4886
- * @deprecated
4887
- */
4888
- get asCID() {
4889
- return this;
4890
- }
4891
- // ArrayBufferView
4892
- get byteOffset() {
4893
- return this.bytes.byteOffset;
4894
- }
4895
- // ArrayBufferView
4896
- get byteLength() {
4897
- return this.bytes.byteLength;
4898
- }
4899
- toV0() {
4900
- switch (this.version) {
4901
- case 0: {
4902
- return this;
5040
+ async function prepareSetupActions({
5041
+ chainId,
5042
+ account,
5043
+ contractVersion,
5044
+ nextTokenId,
5045
+ token,
5046
+ contractName,
5047
+ getAdditionalSetupActions
5048
+ }) {
5049
+ const {
5050
+ minter,
5051
+ newToken,
5052
+ setupActions: tokenSetupActions
5053
+ } = await constructCreate1155TokenCalls({
5054
+ chainId,
5055
+ ownerAddress: account,
5056
+ contractVersion,
5057
+ nextTokenId,
5058
+ ...token,
5059
+ contractName
5060
+ });
5061
+ const setupActions = getAdditionalSetupActions ? [
5062
+ ...getAdditionalSetupActions({
5063
+ tokenId: nextTokenId
5064
+ }),
5065
+ ...tokenSetupActions
5066
+ ] : tokenSetupActions;
5067
+ return { minter, newToken, setupActions };
5068
+ }
5069
+
5070
+ // src/sparks/mints-queries.ts
5071
+ var getMintsAccountBalanceWithPriceQuery = (account) => {
5072
+ const query = `
5073
+ query GetMintAccountBalances($account: String!) {
5074
+ mintAccountBalances(where: { account: $account }) {
5075
+ balance
5076
+ mintToken {
5077
+ id
5078
+ pricePerToken
5079
+ }
4903
5080
  }
4904
- case 1: {
4905
- const { code, multihash } = this;
4906
- if (code !== DAG_PB_CODE) {
4907
- throw new Error("Cannot convert a non dag-pb CID to CIDv0");
4908
- }
4909
- if (multihash.code !== SHA_256_CODE) {
4910
- throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
4911
- }
4912
- return _CID.createV0(multihash);
4913
- }
4914
- default: {
4915
- throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
4916
- }
4917
- }
4918
- }
4919
- toV1() {
4920
- switch (this.version) {
4921
- case 0: {
4922
- const { code, digest } = this.multihash;
4923
- const multihash = create(code, digest);
4924
- return _CID.createV1(this.code, multihash);
4925
- }
4926
- case 1: {
4927
- return this;
4928
- }
4929
- default: {
4930
- throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
4931
- }
4932
- }
4933
- }
4934
- equals(other) {
4935
- return _CID.equals(this, other);
4936
- }
4937
- static equals(self, other) {
4938
- const unknown = other;
4939
- return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
4940
- }
4941
- toString(base3) {
4942
- return format(this, base3);
4943
- }
4944
- toJSON() {
4945
- return { "/": format(this) };
4946
- }
4947
- link() {
4948
- return this;
4949
- }
4950
- // Legacy
4951
- [(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
4952
- return `CID(${this.toString()})`;
4953
- }
4954
- /**
4955
- * Takes any input `value` and returns a `CID` instance if it was
4956
- * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
4957
- * it will return value back. If `value` is not instance of this CID
4958
- * class, but is compatible CID it will return new instance of this
4959
- * `CID` class. Otherwise returns null.
4960
- *
4961
- * This allows two different incompatible versions of CID library to
4962
- * co-exist and interop as long as binary interface is compatible.
4963
- */
4964
- static asCID(input) {
4965
- if (input == null) {
4966
- return null;
4967
5081
  }
4968
- const value = input;
4969
- if (value instanceof _CID) {
4970
- return value;
4971
- } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
4972
- const { version, code, multihash, bytes } = value;
4973
- return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
4974
- } else if (value[cidSymbol] === true) {
4975
- const { version, multihash, code } = value;
4976
- const digest = decode4(multihash);
4977
- return _CID.create(version, code, digest);
4978
- } else {
4979
- return null;
4980
- }
4981
- }
4982
- /**
4983
- * @param version - Version of the CID
4984
- * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
4985
- * @param digest - (Multi)hash of the of the content.
4986
- */
4987
- static create(version, code, digest) {
4988
- if (typeof code !== "number") {
4989
- throw new Error("String codecs are no longer supported");
4990
- }
4991
- if (!(digest.bytes instanceof Uint8Array)) {
4992
- throw new Error("Invalid digest");
4993
- }
4994
- switch (version) {
4995
- case 0: {
4996
- if (code !== DAG_PB_CODE) {
4997
- throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
4998
- } else {
4999
- return new _CID(version, code, digest, digest.bytes);
5000
- }
5001
- }
5002
- case 1: {
5003
- const bytes = encodeCID(version, code, digest.bytes);
5004
- return new _CID(version, code, digest, bytes);
5005
- }
5006
- default: {
5007
- throw new Error("Invalid version");
5008
- }
5009
- }
5010
- }
5011
- /**
5012
- * Simplified version of `create` for CIDv0.
5013
- */
5014
- static createV0(digest) {
5015
- return _CID.create(0, DAG_PB_CODE, digest);
5016
- }
5017
- /**
5018
- * Simplified version of `create` for CIDv1.
5019
- *
5020
- * @param code - Content encoding format code.
5021
- * @param digest - Multihash of the content.
5022
- */
5023
- static createV1(code, digest) {
5024
- return _CID.create(1, code, digest);
5025
- }
5026
- /**
5027
- * Decoded a CID from its binary representation. The byte array must contain
5028
- * only the CID with no additional bytes.
5029
- *
5030
- * An error will be thrown if the bytes provided do not contain a valid
5031
- * binary representation of a CID.
5032
- */
5033
- static decode(bytes) {
5034
- const [cid, remainder] = _CID.decodeFirst(bytes);
5035
- if (remainder.length !== 0) {
5036
- throw new Error("Incorrect length");
5037
- }
5038
- return cid;
5039
- }
5040
- /**
5041
- * Decoded a CID from its binary representation at the beginning of a byte
5042
- * array.
5043
- *
5044
- * Returns an array with the first element containing the CID and the second
5045
- * element containing the remainder of the original byte array. The remainder
5046
- * will be a zero-length byte array if the provided bytes only contained a
5047
- * binary CID representation.
5048
- */
5049
- static decodeFirst(bytes) {
5050
- const specs = _CID.inspectBytes(bytes);
5051
- const prefixSize = specs.size - specs.multihashSize;
5052
- const multihashBytes = coerce2(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
5053
- if (multihashBytes.byteLength !== specs.multihashSize) {
5054
- throw new Error("Incorrect length");
5055
- }
5056
- const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
5057
- const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
5058
- const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
5059
- return [cid, bytes.subarray(specs.size)];
5060
- }
5061
- /**
5062
- * Inspect the initial bytes of a CID to determine its properties.
5063
- *
5064
- * Involves decoding up to 4 varints. Typically this will require only 4 to 6
5065
- * bytes but for larger multicodec code values and larger multihash digest
5066
- * lengths these varints can be quite large. It is recommended that at least
5067
- * 10 bytes be made available in the `initialBytes` argument for a complete
5068
- * inspection.
5069
- */
5070
- static inspectBytes(initialBytes) {
5071
- let offset = 0;
5072
- const next = () => {
5073
- const [i, length2] = decode3(initialBytes.subarray(offset));
5074
- offset += length2;
5075
- return i;
5082
+ `;
5083
+ return {
5084
+ query,
5085
+ variables: { account }
5086
+ };
5087
+ };
5088
+ var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
5089
+ const parsed = mintAccountBalances.map((r) => {
5090
+ return {
5091
+ tokenId: BigInt(r.mintToken.id),
5092
+ quantity: BigInt(r.balance),
5093
+ pricePerToken: BigInt(r.mintToken.pricePerToken)
5076
5094
  };
5077
- let version = next();
5078
- let codec = DAG_PB_CODE;
5079
- if (version === 18) {
5080
- version = 0;
5081
- offset = 0;
5082
- } else {
5083
- codec = next();
5084
- }
5085
- if (version !== 0 && version !== 1) {
5086
- throw new RangeError(`Invalid CID version ${version}`);
5095
+ });
5096
+ const sorted = parsed.sort((a, b) => {
5097
+ if (a.pricePerToken < b.pricePerToken) {
5098
+ return -1;
5087
5099
  }
5088
- const prefixSize = offset;
5089
- const multihashCode = next();
5090
- const digestSize = next();
5091
- const size = offset + digestSize;
5092
- const multihashSize = size - prefixSize;
5093
- return { version, codec, multihashCode, digestSize, multihashSize, size };
5094
- }
5095
- /**
5096
- * Takes cid in a string representation and creates an instance. If `base`
5097
- * decoder is not provided will use a default from the configuration. It will
5098
- * throw an error if encoding of the CID is not compatible with supplied (or
5099
- * a default decoder).
5100
- */
5101
- static parse(source, base3) {
5102
- const [prefix, bytes] = parseCIDtoBytes(source, base3);
5103
- const cid = _CID.decode(bytes);
5104
- if (cid.version === 0 && source[0] !== "Q") {
5105
- throw Error("Version 0 CID string must not include multibase prefix");
5100
+ return 1;
5101
+ });
5102
+ let remainingQuantity = quantityToCollect;
5103
+ const tokenIds = [];
5104
+ const quantities = [];
5105
+ while (remainingQuantity > 0) {
5106
+ const next = sorted.shift();
5107
+ if (!next) {
5108
+ throw new Error("Not enough MINTs to collect with");
5106
5109
  }
5107
- baseCache(cid).set(prefix, source);
5108
- return cid;
5110
+ const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
5111
+ tokenIds.push(next.tokenId);
5112
+ quantities.push(quantityToUse);
5113
+ remainingQuantity -= quantityToUse;
5109
5114
  }
5115
+ return {
5116
+ tokenIds,
5117
+ quantities
5118
+ };
5119
+ };
5120
+ var sumBalances = (mintAccountBalances) => {
5121
+ return mintAccountBalances.reduce((acc, curr) => {
5122
+ return acc + BigInt(curr.balance);
5123
+ }, BigInt(0));
5110
5124
  };
5111
- function parseCIDtoBytes(source, base3) {
5112
- switch (source[0]) {
5113
- case "Q": {
5114
- const decoder = base3 ?? base58btc;
5115
- return [
5116
- base58btc.prefix,
5117
- decoder.decode(`${base58btc.prefix}${source}`)
5118
- ];
5119
- }
5120
- case base58btc.prefix: {
5121
- const decoder = base3 ?? base58btc;
5122
- return [base58btc.prefix, decoder.decode(source)];
5123
- }
5124
- case base32.prefix: {
5125
- const decoder = base3 ?? base32;
5126
- return [base32.prefix, decoder.decode(source)];
5127
- }
5128
- default: {
5129
- if (base3 == null) {
5130
- throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
5131
- }
5132
- return [source[0], base3.decode(source)];
5133
- }
5134
- }
5135
- }
5136
- function toStringV0(bytes, cache2, base3) {
5137
- const { prefix } = base3;
5138
- if (prefix !== base58btc.prefix) {
5139
- throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
5140
- }
5141
- const cid = cache2.get(prefix);
5142
- if (cid == null) {
5143
- const cid2 = base3.encode(bytes).slice(1);
5144
- cache2.set(prefix, cid2);
5145
- return cid2;
5146
- } else {
5147
- return cid;
5148
- }
5149
- }
5150
- function toStringV1(bytes, cache2, base3) {
5151
- const { prefix } = base3;
5152
- const cid = cache2.get(prefix);
5153
- if (cid == null) {
5154
- const cid2 = base3.encode(bytes);
5155
- cache2.set(prefix, cid2);
5156
- return cid2;
5157
- } else {
5158
- return cid;
5159
- }
5160
- }
5161
- var DAG_PB_CODE = 112;
5162
- var SHA_256_CODE = 18;
5163
- function encodeCID(version, code, multihash) {
5164
- const codeOffset = encodingLength(version);
5165
- const hashOffset = codeOffset + encodingLength(code);
5166
- const bytes = new Uint8Array(hashOffset + multihash.byteLength);
5167
- encodeTo(version, bytes, 0);
5168
- encodeTo(code, bytes, codeOffset);
5169
- bytes.set(multihash, hashOffset);
5170
- return bytes;
5171
- }
5172
- var cidSymbol = Symbol.for("@ipld/js-cid/CID");
5173
5125
 
5174
- // src/ipfs/ipfs.ts
5175
- function isCID(str) {
5176
- if (!str)
5177
- return false;
5178
- try {
5179
- CID.parse(str);
5180
- return true;
5181
- } catch (e) {
5182
- if (/^(bafy|Qm)/.test(str))
5183
- return true;
5184
- return false;
5185
- }
5186
- }
5187
- function normalizeIPFSUrl(url) {
5188
- if (!url || typeof url !== "string")
5189
- return null;
5190
- url = url.replace(/"/g, "");
5191
- if (isNormalizedIPFSURL(url))
5192
- return url;
5193
- if (isCID(url))
5194
- return `ipfs://${url}`;
5195
- if (!isIPFSUrl(url))
5196
- return null;
5197
- if (isGatewayIPFSUrl(url)) {
5198
- const parsed = new URL(url.replace(/^\/\//, "http://"));
5199
- parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
5200
- const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
5201
- return `ipfs://${cid}`;
5202
- }
5203
- return null;
5204
- }
5205
- function isNormalizedIPFSURL(url) {
5206
- return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
5126
+ // src/sparks/sparks-contracts.ts
5127
+ var import_protocol_deployments11 = require("@zoralabs/protocol-deployments");
5128
+ var import_viem11 = require("viem");
5129
+ var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
5130
+ var mintWithEthParams = ({
5131
+ tokenId,
5132
+ quantity,
5133
+ recipient,
5134
+ chainId,
5135
+ pricePerMint,
5136
+ account
5137
+ }) => makeContractParameters({
5138
+ abi: import_protocol_deployments11.zoraSparksManagerImplABI,
5139
+ address: import_protocol_deployments11.zoraSparksManagerImplAddress[chainId],
5140
+ functionName: "mintWithEth",
5141
+ args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
5142
+ value: pricePerMint * quantity,
5143
+ account
5144
+ });
5145
+ var getPaidMintValue = (quantities, pricePerMint) => {
5146
+ if (!pricePerMint || pricePerMint === 0n)
5147
+ return;
5148
+ return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
5149
+ };
5150
+ var mintsBalanceOfAccountParams = ({
5151
+ account,
5152
+ chainId
5153
+ }) => ({
5154
+ abi: import_protocol_deployments11.zoraMints1155Config.abi,
5155
+ address: import_protocol_deployments11.zoraMints1155Config.address[chainId],
5156
+ functionName: "balanceOfAccount",
5157
+ args: [account]
5158
+ });
5159
+ var encodeCollectOnManager = ({
5160
+ zoraCreator1155Contract,
5161
+ minter,
5162
+ zoraCreator1155TokenId,
5163
+ mintArguments
5164
+ }) => (0, import_viem11.encodeFunctionData)({
5165
+ abi: import_protocol_deployments11.zoraMintsManagerImplConfig.abi,
5166
+ functionName: "collect",
5167
+ args: [
5168
+ zoraCreator1155Contract,
5169
+ minter,
5170
+ zoraCreator1155TokenId,
5171
+ mintArguments
5172
+ ]
5173
+ });
5174
+ function collectWithMintsParams({
5175
+ tokenIds,
5176
+ quantities,
5177
+ chainId,
5178
+ paidMintPricePerToken,
5179
+ account,
5180
+ mintArguments,
5181
+ minter,
5182
+ zoraCreator1155Contract,
5183
+ zoraCreator1155TokenId
5184
+ }) {
5185
+ const call = encodeCollectOnManager({
5186
+ tokenIds,
5187
+ quantities,
5188
+ zoraCreator1155Contract,
5189
+ zoraCreator1155TokenId,
5190
+ minter,
5191
+ mintArguments
5192
+ });
5193
+ return makeContractParameters({
5194
+ abi: import_protocol_deployments11.zoraMints1155Config.abi,
5195
+ address: import_protocol_deployments11.zoraMints1155Config.address[chainId],
5196
+ functionName: "transferBatchToManagerAndCall",
5197
+ args: [tokenIds, quantities, call],
5198
+ // if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
5199
+ // for the paid mint cost.
5200
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
5201
+ account
5202
+ });
5207
5203
  }
5208
- function isGatewayIPFSUrl(url) {
5209
- if (url && typeof url === "string") {
5210
- try {
5211
- const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
5212
- return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
5213
- } catch {
5214
- return false;
5215
- }
5204
+ function getMintsEthPrice({
5205
+ publicClient
5206
+ }) {
5207
+ const chainId = publicClient.chain?.id;
5208
+ if (!chainId || !import_protocol_deployments11.zoraMintsManagerImplAddress[chainId]) {
5209
+ throw new Error(`Chain id ${chainId} not supported`);
5216
5210
  }
5217
- return false;
5218
- }
5219
- function isIPFSUrl(url) {
5220
- return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
5221
- }
5222
- function isNormalizeableIPFSUrl(url) {
5223
- return url ? isIPFSUrl(url) || isCID(url) : false;
5211
+ return publicClient.readContract({
5212
+ abi: import_protocol_deployments11.zoraMintsManagerImplABI,
5213
+ address: import_protocol_deployments11.zoraMintsManagerImplAddress[chainId],
5214
+ functionName: "getEthPrice"
5215
+ });
5224
5216
  }
5225
-
5226
- // src/ipfs/gateway.ts
5227
- var IPFS_GATEWAY = "https://magic.decentralized-content.com";
5228
- var ARWEAVE_GATEWAY = "https://arweave.net";
5229
- function arweaveGatewayUrl(normalizedArweaveUrl) {
5230
- if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
5231
- return null;
5232
- return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
5217
+ function makePermitTransferBatchAndTypeData({
5218
+ tokenIds,
5219
+ quantities,
5220
+ chainId,
5221
+ mintsOwner,
5222
+ to,
5223
+ nonce,
5224
+ deadline,
5225
+ safeTransferData
5226
+ }) {
5227
+ const permit = {
5228
+ owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
5229
+ to,
5230
+ tokenIds,
5231
+ quantities,
5232
+ deadline,
5233
+ nonce,
5234
+ safeTransferData
5235
+ };
5236
+ const typedData = {
5237
+ ...(0, import_protocol_deployments11.mintsSafeTransferBatchTypedDataDefinition)({
5238
+ chainId,
5239
+ message: permit
5240
+ }),
5241
+ account: mintsOwner
5242
+ };
5243
+ return {
5244
+ permit,
5245
+ typedData
5246
+ };
5233
5247
  }
5234
- function ipfsGatewayUrl(url) {
5235
- if (!url || typeof url !== "string")
5236
- return null;
5237
- const normalizedIPFSUrl = normalizeIPFSUrl(url);
5238
- if (normalizedIPFSUrl) {
5239
- return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
5240
- }
5241
- return null;
5248
+ function makePermitTransferTypeData({
5249
+ tokenId,
5250
+ quantity,
5251
+ chainId,
5252
+ mintsOwner,
5253
+ to,
5254
+ nonce,
5255
+ deadline,
5256
+ safeTransferData
5257
+ }) {
5258
+ const permit = {
5259
+ owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
5260
+ to,
5261
+ tokenId,
5262
+ quantity,
5263
+ deadline,
5264
+ nonce,
5265
+ safeTransferData
5266
+ };
5267
+ const typedData = {
5268
+ ...(0, import_protocol_deployments11.mintsSafeTransferTypedDataDefinition)({
5269
+ chainId,
5270
+ message: permit
5271
+ }),
5272
+ account: mintsOwner
5273
+ };
5274
+ return {
5275
+ permit,
5276
+ typedData
5277
+ };
5242
5278
  }
5243
- function getFetchableUrl(uri) {
5244
- if (!uri || typeof uri !== "string")
5245
- return null;
5246
- if (uri.startsWith("http://"))
5247
- return null;
5248
- if (isNormalizeableIPFSUrl(uri)) {
5249
- return ipfsGatewayUrl(uri);
5250
- }
5251
- if (isArweaveURL(uri)) {
5252
- return arweaveGatewayUrl(uri);
5253
- }
5254
- if (/^(https|data|blob):/.test(uri)) {
5255
- return uri;
5279
+ var encodePremintOnManager = ({
5280
+ contractCreationConfig,
5281
+ premintConfig,
5282
+ premintSignature,
5283
+ mintArguments,
5284
+ signerContract = import_viem11.zeroAddress
5285
+ }) => (0, import_viem11.encodeFunctionData)({
5286
+ abi: import_protocol_deployments11.zoraMintsManagerImplConfig.abi,
5287
+ functionName: "collectPremintV2",
5288
+ args: [
5289
+ contractCreationConfig,
5290
+ premintConfig,
5291
+ premintSignature,
5292
+ mintArguments,
5293
+ signerContract
5294
+ ]
5295
+ });
5296
+ var makePermitToCollectPremintOrNonPremint = ({
5297
+ mintsOwner,
5298
+ chainId,
5299
+ deadline,
5300
+ tokenIds,
5301
+ // this quantity of MINTs will be used to collect premint
5302
+ // and will be burned. This same quantity is the quantity of
5303
+ // premint to collect.
5304
+ quantities,
5305
+ nonce,
5306
+ premint,
5307
+ collect
5308
+ }) => {
5309
+ let safeTransferData;
5310
+ if (premint) {
5311
+ safeTransferData = encodePremintOnManager(premint);
5312
+ } else if (collect) {
5313
+ safeTransferData = encodeCollectOnManager(collect);
5314
+ } else {
5315
+ throw new Error("Invalid operation");
5256
5316
  }
5257
- return null;
5258
- }
5259
-
5260
- // src/ipfs/mimeTypes.ts
5261
- var HTML = "text/html";
5262
- var MARKDOWN = "text/markdown";
5263
- var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
5264
- var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
5265
- var TEXT_PLAIN = "text/plain";
5266
- var CSV = "text/csv";
5267
- var NUMBERS = ".numbers";
5268
- var EXCEL = ".xlsx";
5269
- var PDF = "application/pdf";
5270
- var JPG = "image/jpg";
5271
- var JPEG = "image/jpeg";
5272
- var PNG = "image/png";
5273
- var WEBP = "image/webp";
5274
- var SVG = "image/svg+xml";
5275
- var TIFF = "image/tiff";
5276
- var GIF = "image/gif";
5277
- var isImage = (mimeType) => {
5278
- if (!mimeType)
5279
- return false;
5280
- return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
5281
- };
5282
- var DEFAULT_THUMBNAIL_CID_HASHES = {
5283
- ["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
5284
- ["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
5285
- ["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
5286
- ["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
5287
- // assuming all zip files are html directories
5288
- ["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
5289
- default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
5290
- };
5291
- var MP4 = "video/mp4";
5292
- var QUICKTIME = "video/quicktime";
5293
- var M4V = "video/x-m4v";
5294
- var WEBM = "video/webm";
5295
- var M4A = "audio/x-m4a";
5296
- var MPEG = "audio/mpeg";
5297
- var MP3 = "audio/mp3";
5298
- var WAV = "audio/wav";
5299
- var VND_WAV = "audio/vnd.wav";
5300
- var VND_WAVE = "audio/vnd.wave";
5301
- var WAVE = "audio/wave";
5302
- var X_WAV = "audio/x-wav";
5303
- var AIFF = "audio/aiff";
5304
- var GLTF = "model/gltf+json";
5305
- var GLB = "model/gltf-binary";
5306
- var GLTF_EXT = ".gltf";
5307
- var GLB_EXT = ".glb";
5308
- var JSON_MIME_TYPE = "application/json";
5309
- var ZIP = "application/zip";
5310
- var mimeToMediaType = {
5311
- [HTML]: "HTML" /* HTML */,
5312
- [JPG]: "IMAGE" /* IMAGE */,
5313
- [JPEG]: "IMAGE" /* IMAGE */,
5314
- [PNG]: "IMAGE" /* IMAGE */,
5315
- [WEBP]: "IMAGE" /* IMAGE */,
5316
- [SVG]: "IMAGE" /* IMAGE */,
5317
- [TIFF]: "TIFF" /* TIFF */,
5318
- [GIF]: "IMAGE" /* IMAGE */,
5319
- [MP4]: "VIDEO" /* VIDEO */,
5320
- [WEBM]: "VIDEO" /* VIDEO */,
5321
- [QUICKTIME]: "VIDEO" /* VIDEO */,
5322
- [M4V]: "VIDEO" /* VIDEO */,
5323
- [MPEG]: "AUDIO" /* AUDIO */,
5324
- [MP3]: "AUDIO" /* AUDIO */,
5325
- [M4A]: "AUDIO" /* AUDIO */,
5326
- [VND_WAV]: "AUDIO" /* AUDIO */,
5327
- [VND_WAVE]: "AUDIO" /* AUDIO */,
5328
- [WAV]: "AUDIO" /* AUDIO */,
5329
- [WAVE]: "AUDIO" /* AUDIO */,
5330
- [X_WAV]: "AUDIO" /* AUDIO */,
5331
- [AIFF]: "AUDIO" /* AUDIO */,
5332
- [TEXT_PLAIN]: "TEXT" /* TEXT */,
5333
- [TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
5334
- [MARKDOWN]: "TEXT" /* TEXT */,
5335
- [MARKDOWN_UTF8]: "TEXT" /* TEXT */,
5336
- [CSV]: "CSV" /* CSV */,
5337
- [NUMBERS]: "NUMBERS" /* NUMBERS */,
5338
- [EXCEL]: "EXCEL" /* EXCEL */,
5339
- [PDF]: "PDF" /* PDF */,
5340
- [ZIP]: "ZIP" /* ZIP */,
5341
- [GLTF]: "MODEL" /* MODEL */,
5342
- [GLTF_EXT]: "MODEL" /* MODEL */,
5343
- [GLB]: "MODEL" /* MODEL */,
5344
- // GLTF returns 'application/json' as the mimetype,
5345
- // and as the only JSON-encoded media we currently support,
5346
- // we assume that if the mimetype is JSON, it's a GLTF
5347
- [JSON_MIME_TYPE]: "MODEL" /* MODEL */,
5348
- [GLB_EXT]: "MODEL" /* MODEL */
5317
+ return makePermitTransferBatchAndTypeData({
5318
+ tokenIds,
5319
+ quantities,
5320
+ chainId,
5321
+ mintsOwner,
5322
+ nonce,
5323
+ deadline,
5324
+ safeTransferData,
5325
+ to: import_protocol_deployments11.zoraMintsManagerImplConfig.address[chainId]
5326
+ });
5349
5327
  };
5350
- function mimeTypeToMedia(mimeType) {
5351
- if (!mimeType)
5352
- return "UNKNOWN" /* UNKNOWN */;
5353
- return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
5328
+ function collectPremintV2WithMintsParams({
5329
+ tokenIds,
5330
+ quantities,
5331
+ paidMintPricePerToken,
5332
+ account,
5333
+ chainId,
5334
+ ...rest
5335
+ }) {
5336
+ const call = encodePremintOnManager({
5337
+ ...rest
5338
+ });
5339
+ return makeContractParameters({
5340
+ abi: import_protocol_deployments11.zoraMints1155Config.abi,
5341
+ address: import_protocol_deployments11.zoraMints1155Config.address[chainId],
5342
+ functionName: "transferBatchToManagerAndCall",
5343
+ args: [tokenIds, quantities, call],
5344
+ value: getPaidMintValue(quantities, paidMintPricePerToken),
5345
+ account
5346
+ });
5354
5347
  }
5355
- async function getMimeType(uri) {
5356
- if (!uri)
5357
- return uri;
5358
- const res = await fetch(uri, { method: "HEAD" });
5359
- let mimeType = res.headers.get("content-type");
5360
- return mimeType;
5348
+ function decodeCallFailedError(error) {
5349
+ if (error.data?.errorName !== "CallFailed")
5350
+ throw new Error("Not a CallFailed error");
5351
+ const internalErrorData = error.data?.args?.[0];
5352
+ return (0, import_viem11.decodeErrorResult)({
5353
+ abi: import_protocol_deployments11.zoraMintsManagerImplABI,
5354
+ data: internalErrorData
5355
+ });
5361
5356
  }
5362
5357
 
5363
- // src/ipfs/token-metadata.ts
5364
- var makeTextTokenMetadata = (parameters) => {
5365
- const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
5366
- const content = textFileUrl ? {
5367
- mime: TEXT_PLAIN,
5368
- uri: textFileUrl
5369
- } : null;
5370
- const image = thumbnailUrl;
5371
- const animation_url = textFileUrl;
5358
+ // src/create/subgraph-queries.ts
5359
+ function buildContractInfoQuery({
5360
+ contractAddress
5361
+ }) {
5372
5362
  return {
5373
- name,
5374
- image,
5375
- animation_url,
5376
- content,
5377
- attributes
5363
+ query: `
5364
+ query ($contractAddress: Bytes!) {
5365
+ zoraCreateContract(id: $contractAddress) {
5366
+ contractVersion
5367
+ name
5368
+ mintFeePerQuantity
5369
+ tokens(first: 1, orderBy: tokenId, orderDirection: desc) {
5370
+ tokenId
5371
+ }
5372
+ }
5373
+ }
5374
+ `,
5375
+ variables: {
5376
+ contractAddress: contractAddress.toLowerCase()
5377
+ },
5378
+ parseResponseData: (responseData) => responseData.zoraCreateContract
5378
5379
  };
5379
- };
5380
- var makeMediaTokenMetadata = async ({
5381
- name,
5382
- description,
5383
- attributes = [],
5384
- mediaUrl,
5385
- thumbnailUrl
5386
- }) => {
5387
- const contentUrl = mediaUrl;
5388
- const fetchableContentUrl = getFetchableUrl(contentUrl);
5389
- if (!fetchableContentUrl)
5390
- throw new Error(`Content url (${contentUrl}) is not fetchable`);
5391
- const mimeType = await getMimeType(fetchableContentUrl);
5392
- const mediaType = mimeTypeToMedia(mimeType);
5393
- let image = void 0;
5394
- let animation_url = null;
5395
- if (isImage(mimeType)) {
5396
- image = contentUrl;
5397
- } else {
5398
- image = thumbnailUrl;
5399
- animation_url = mediaUrl;
5380
+ }
5381
+
5382
+ // src/create/contract-getter.ts
5383
+ var SubgraphContractGetter = class {
5384
+ constructor(chainId, subgraphQuerier) {
5385
+ this.subgraphQuerier = subgraphQuerier || new SubgraphQuerier(httpClient);
5386
+ this.networkConfig = getApiNetworkConfigForChain(chainId);
5387
+ }
5388
+ async querySubgraphWithRetries({
5389
+ query,
5390
+ variables,
5391
+ parseResponseData
5392
+ }) {
5393
+ const responseData = await this.subgraphQuerier.query({
5394
+ subgraphUrl: this.networkConfig.subgraphUrl,
5395
+ query,
5396
+ variables
5397
+ });
5398
+ return parseResponseData(responseData);
5399
+ }
5400
+ async getContractInfo({
5401
+ contractAddress,
5402
+ retries: retries2 = 1
5403
+ }) {
5404
+ const tryFn = async () => {
5405
+ const responseData2 = await this.querySubgraphWithRetries(
5406
+ buildContractInfoQuery({ contractAddress })
5407
+ );
5408
+ if (!responseData2) {
5409
+ console.log("could not find contract");
5410
+ throw new Error("Cannot find contract");
5411
+ }
5412
+ return responseData2;
5413
+ };
5414
+ const responseData = await retriesGeneric({
5415
+ tryFn,
5416
+ maxTries: retries2,
5417
+ linearBackoffMS: 1e3
5418
+ });
5419
+ const nextTokenId = responseData.tokens.length === 0 ? 1n : BigInt(responseData.tokens[0].tokenId) + 1n;
5420
+ return {
5421
+ name: responseData.name,
5422
+ contractVersion: responseData.contractVersion,
5423
+ mintFee: BigInt(responseData.mintFeePerQuantity),
5424
+ nextTokenId
5425
+ };
5400
5426
  }
5401
- if (!image)
5402
- image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
5403
- const content = contentUrl ? {
5404
- mime: mimeType || "application/octet-stream",
5405
- uri: contentUrl
5406
- } : null;
5427
+ };
5428
+
5429
+ // src/sdk.ts
5430
+ function createCreatorClient(clientConfig) {
5431
+ const premintClient = new PremintClient({
5432
+ chainId: clientConfig.chainId,
5433
+ publicClient: clientConfig.publicClient,
5434
+ premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
5435
+ });
5436
+ const create1155CreatorClient = new Create1155Client({
5437
+ chainId: clientConfig.chainId,
5438
+ publicClient: clientConfig.publicClient,
5439
+ contractGetter: clientConfig.contractGetter || new SubgraphContractGetter(clientConfig.chainId)
5440
+ });
5407
5441
  return {
5408
- name,
5409
- description,
5410
- image,
5411
- animation_url,
5412
- content,
5413
- attributes
5442
+ createPremint: (p) => premintClient.createPremint(p),
5443
+ updatePremint: (p) => premintClient.updatePremint(p),
5444
+ deletePremint: (p) => premintClient.deletePremint(p),
5445
+ create1155: (p) => create1155CreatorClient.createNew1155(p),
5446
+ create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
5414
5447
  };
5415
- };
5416
- async function fetchTokenMetadata(tokenMetadataURI) {
5417
- const fetchableUrl = getFetchableUrl(tokenMetadataURI);
5418
- if (!fetchableUrl) {
5419
- throw new Error(`Invalid token metadata URI: ${tokenMetadataURI}`);
5420
- }
5421
- const json = await (await fetch(fetchableUrl)).json();
5422
- if (!json) {
5423
- throw new Error(`Failed to fetch metadata from ${fetchableUrl}`);
5424
- }
5425
- return json;
5426
5448
  }
5427
-
5428
- // src/create/minter-defaults.ts
5429
- var SALE_END_FOREVER = 18446744073709551615n;
5430
- var DEFAULT_SALE_START_AND_END = {
5431
- // Sale start time – defaults to beginning of unix time
5432
- saleStart: 0n,
5433
- // This is the end of uint64, plenty of time
5434
- saleEnd: SALE_END_FOREVER
5435
- };
5436
- var DEFAULT_MAX_TOKENS_PER_ADDRESS = {
5437
- maxTokensPerAddress: 0n
5438
- };
5439
- var erc20SaleSettingsWithDefaults = (params) => ({
5440
- ...DEFAULT_SALE_START_AND_END,
5441
- ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
5442
- ...params
5443
- });
5444
- var allowListWithDefaults = (allowlist) => {
5449
+ function createCollectorClient(params) {
5450
+ const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
5451
+ const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
5452
+ const mintClient = new MintClient({
5453
+ publicClient: params.publicClient,
5454
+ premintGetter: premintGetterToUse,
5455
+ mintGetter: mintGetterToUse
5456
+ });
5445
5457
  return {
5446
- ...DEFAULT_SALE_START_AND_END,
5447
- ...allowlist
5458
+ getPremint: (p) => premintGetterToUse.get({
5459
+ collectionAddress: p.address,
5460
+ uid: p.uid
5461
+ }),
5462
+ getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
5463
+ getToken: (p) => mintClient.get(p),
5464
+ getTokensOfContract: (p) => mintClient.getOfContract(p),
5465
+ mint: (p) => mintClient.mint(p),
5466
+ getMintCosts: (p) => mintClient.getMintCosts(p)
5448
5467
  };
5449
- };
5450
- var fixedPriceSettingsWithDefaults = (params) => ({
5451
- ...DEFAULT_SALE_START_AND_END,
5452
- ...DEFAULT_MAX_TOKENS_PER_ADDRESS,
5453
- type: "fixedPrice",
5454
- ...params
5455
- });
5456
- var parseNameIntoSymbol = (name) => {
5457
- if (name === "") {
5458
- throw new Error("Name must be provided to generate a symbol");
5468
+ }
5469
+
5470
+ // src/ipfs/arweave.ts
5471
+ function isArweaveURL(url) {
5472
+ return url && typeof url === "string" ? url.startsWith("ar://") : false;
5473
+ }
5474
+
5475
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bytes.js
5476
+ var empty = new Uint8Array(0);
5477
+ function equals(aa, bb) {
5478
+ if (aa === bb)
5479
+ return true;
5480
+ if (aa.byteLength !== bb.byteLength) {
5481
+ return false;
5459
5482
  }
5460
- const result = "$" + name.replace(/[^a-zA-Z0-9]/g, "").replace(/^\$+/, "").toUpperCase().replace(/[AEIOU\s]/g, "").slice(0, 4);
5461
- if (result === "$") {
5462
- throw new Error("Not enough valid characters to generate a symbol");
5483
+ for (let ii = 0; ii < aa.byteLength; ii++) {
5484
+ if (aa[ii] !== bb[ii]) {
5485
+ return false;
5486
+ }
5463
5487
  }
5464
- return result;
5465
- };
5466
- async function fetchTokenNameFromMetadata(tokenMetadataURI) {
5467
- const tokenMetadata = await fetchTokenMetadata(tokenMetadataURI);
5468
- if (!tokenMetadata.name) {
5469
- throw new Error("No name found in token metadata");
5488
+ return true;
5489
+ }
5490
+ function coerce3(o) {
5491
+ if (o instanceof Uint8Array && o.constructor.name === "Uint8Array")
5492
+ return o;
5493
+ if (o instanceof ArrayBuffer)
5494
+ return new Uint8Array(o);
5495
+ if (ArrayBuffer.isView(o)) {
5496
+ return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
5470
5497
  }
5471
- return tokenMetadata.name;
5498
+ throw new Error("Unknown type, must be binary type");
5472
5499
  }
5473
- var timedSaleSettingsWithDefaults = async (params, tokenMetadataURI) => {
5474
- const erc20Name = params.erc20Name || await fetchTokenNameFromMetadata(tokenMetadataURI);
5475
- const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
5476
- return {
5477
- type: "timed",
5478
- ...DEFAULT_SALE_START_AND_END,
5479
- erc20Name,
5480
- erc20Symbol: symbol
5481
- };
5482
- };
5483
- var isAllowList = (salesConfig) => salesConfig.type === "allowlistMint";
5484
- var isErc20 = (salesConfig) => salesConfig.type === "erc20Mint";
5485
- var isFixedPrice = (salesConfig) => {
5486
- return salesConfig.pricePerToken > 0n;
5487
- };
5488
- var getSalesConfigWithDefaults = async (salesConfig, tokenMetadataURI) => {
5489
- if (!salesConfig)
5490
- return timedSaleSettingsWithDefaults({}, tokenMetadataURI);
5491
- if (isAllowList(salesConfig)) {
5492
- return allowListWithDefaults(salesConfig);
5500
+
5501
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/base-x.js
5502
+ function base2(ALPHABET, name) {
5503
+ if (ALPHABET.length >= 255) {
5504
+ throw new TypeError("Alphabet too long");
5493
5505
  }
5494
- if (isErc20(salesConfig)) {
5495
- return erc20SaleSettingsWithDefaults(salesConfig);
5506
+ var BASE_MAP = new Uint8Array(256);
5507
+ for (var j = 0; j < BASE_MAP.length; j++) {
5508
+ BASE_MAP[j] = 255;
5496
5509
  }
5497
- if (isFixedPrice(salesConfig)) {
5498
- return fixedPriceSettingsWithDefaults(salesConfig);
5510
+ for (var i = 0; i < ALPHABET.length; i++) {
5511
+ var x = ALPHABET.charAt(i);
5512
+ var xc = x.charCodeAt(0);
5513
+ if (BASE_MAP[xc] !== 255) {
5514
+ throw new TypeError(x + " is ambiguous");
5515
+ }
5516
+ BASE_MAP[xc] = i;
5499
5517
  }
5500
- return timedSaleSettingsWithDefaults(salesConfig, tokenMetadataURI);
5501
- };
5502
-
5503
- // src/create/minter-setup.ts
5504
- var import_protocol_deployments8 = require("@zoralabs/protocol-deployments");
5505
- var import_viem7 = require("viem");
5506
- var PERMISSION_BITS = {
5507
- MINTER: 2n ** 2n
5508
- };
5509
- function setupErc20Minter({
5510
- pricePerToken,
5511
- chainId,
5512
- tokenId: nextTokenId,
5513
- currency,
5514
- saleStart,
5515
- saleEnd,
5516
- maxTokensPerAddress: mintLimit,
5517
- fundsRecipient
5518
- }) {
5519
- const erc20MinterAddress = import_protocol_deployments8.erc20MinterAddress[chainId];
5520
- if (!erc20MinterAddress)
5521
- throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
5522
- const erc20MinterApproval = (0, import_viem7.encodeFunctionData)({
5523
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5524
- functionName: "addPermission",
5525
- args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER]
5526
- });
5527
- const saleData = (0, import_viem7.encodeFunctionData)({
5528
- abi: import_protocol_deployments8.erc20MinterABI,
5529
- functionName: "setSale",
5530
- args: [
5531
- BigInt(nextTokenId),
5532
- {
5533
- saleStart: saleStart || BigInt(0),
5534
- saleEnd: saleEnd || BigInt(0),
5535
- maxTokensPerAddress: BigInt(mintLimit || 0),
5536
- pricePerToken,
5537
- fundsRecipient,
5538
- currency
5518
+ var BASE = ALPHABET.length;
5519
+ var LEADER = ALPHABET.charAt(0);
5520
+ var FACTOR = Math.log(BASE) / Math.log(256);
5521
+ var iFACTOR = Math.log(256) / Math.log(BASE);
5522
+ function encode3(source) {
5523
+ if (source instanceof Uint8Array)
5524
+ ;
5525
+ else if (ArrayBuffer.isView(source)) {
5526
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
5527
+ } else if (Array.isArray(source)) {
5528
+ source = Uint8Array.from(source);
5529
+ }
5530
+ if (!(source instanceof Uint8Array)) {
5531
+ throw new TypeError("Expected Uint8Array");
5532
+ }
5533
+ if (source.length === 0) {
5534
+ return "";
5535
+ }
5536
+ var zeroes = 0;
5537
+ var length2 = 0;
5538
+ var pbegin = 0;
5539
+ var pend = source.length;
5540
+ while (pbegin !== pend && source[pbegin] === 0) {
5541
+ pbegin++;
5542
+ zeroes++;
5543
+ }
5544
+ var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
5545
+ var b58 = new Uint8Array(size);
5546
+ while (pbegin !== pend) {
5547
+ var carry = source[pbegin];
5548
+ var i2 = 0;
5549
+ for (var it1 = size - 1; (carry !== 0 || i2 < length2) && it1 !== -1; it1--, i2++) {
5550
+ carry += 256 * b58[it1] >>> 0;
5551
+ b58[it1] = carry % BASE >>> 0;
5552
+ carry = carry / BASE >>> 0;
5553
+ }
5554
+ if (carry !== 0) {
5555
+ throw new Error("Non-zero carry");
5556
+ }
5557
+ length2 = i2;
5558
+ pbegin++;
5559
+ }
5560
+ var it2 = size - length2;
5561
+ while (it2 !== size && b58[it2] === 0) {
5562
+ it2++;
5563
+ }
5564
+ var str = LEADER.repeat(zeroes);
5565
+ for (; it2 < size; ++it2) {
5566
+ str += ALPHABET.charAt(b58[it2]);
5567
+ }
5568
+ return str;
5569
+ }
5570
+ function decodeUnsafe(source) {
5571
+ if (typeof source !== "string") {
5572
+ throw new TypeError("Expected String");
5573
+ }
5574
+ if (source.length === 0) {
5575
+ return new Uint8Array();
5576
+ }
5577
+ var psz = 0;
5578
+ if (source[psz] === " ") {
5579
+ return;
5580
+ }
5581
+ var zeroes = 0;
5582
+ var length2 = 0;
5583
+ while (source[psz] === LEADER) {
5584
+ zeroes++;
5585
+ psz++;
5586
+ }
5587
+ var size = (source.length - psz) * FACTOR + 1 >>> 0;
5588
+ var b256 = new Uint8Array(size);
5589
+ while (source[psz]) {
5590
+ var carry = BASE_MAP[source.charCodeAt(psz)];
5591
+ if (carry === 255) {
5592
+ return;
5539
5593
  }
5540
- ]
5541
- });
5542
- const callSale = (0, import_viem7.encodeFunctionData)({
5543
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5544
- functionName: "callSale",
5545
- args: [BigInt(nextTokenId), erc20MinterAddress, saleData]
5546
- });
5547
- return {
5548
- minter: erc20MinterAddress,
5549
- setupActions: [erc20MinterApproval, callSale]
5550
- };
5551
- }
5552
- function setupFixedPriceMinter({
5553
- pricePerToken: price,
5554
- tokenId: nextTokenId,
5555
- chainId,
5556
- saleStart,
5557
- saleEnd,
5558
- maxTokensPerAddress: mintLimit,
5559
- fundsRecipient
5560
- }) {
5561
- const fixedPriceStrategyAddress = import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyAddress[chainId];
5562
- const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
5563
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5564
- functionName: "addPermission",
5565
- args: [
5566
- BigInt(nextTokenId),
5567
- fixedPriceStrategyAddress,
5568
- PERMISSION_BITS.MINTER
5569
- ]
5570
- });
5571
- const saleData = (0, import_viem7.encodeFunctionData)({
5572
- abi: import_protocol_deployments8.zoraCreatorFixedPriceSaleStrategyABI,
5573
- functionName: "setSale",
5574
- args: [
5575
- BigInt(nextTokenId),
5576
- {
5577
- pricePerToken: price,
5578
- saleStart: saleStart || BigInt(0),
5579
- saleEnd: saleEnd || BigInt(0),
5580
- maxTokensPerAddress: BigInt(mintLimit || 0),
5581
- fundsRecipient
5594
+ var i2 = 0;
5595
+ for (var it3 = size - 1; (carry !== 0 || i2 < length2) && it3 !== -1; it3--, i2++) {
5596
+ carry += BASE * b256[it3] >>> 0;
5597
+ b256[it3] = carry % 256 >>> 0;
5598
+ carry = carry / 256 >>> 0;
5582
5599
  }
5583
- ]
5584
- });
5585
- const callSale = (0, import_viem7.encodeFunctionData)({
5586
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5587
- functionName: "callSale",
5588
- args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData]
5589
- });
5590
- return {
5591
- minter: fixedPriceStrategyAddress,
5592
- setupActions: [fixedPriceApproval, callSale]
5593
- };
5594
- }
5595
- function setupTimedSaleMinter({
5596
- chainId,
5597
- tokenId,
5598
- erc20Name: erc20zName,
5599
- erc20Symbol: erc20zSymbol,
5600
- saleStart,
5601
- saleEnd
5602
- }) {
5603
- const minterAddress = import_protocol_deployments8.zoraTimedSaleStrategyAddress[chainId];
5604
- const fixedPriceApproval = (0, import_viem7.encodeFunctionData)({
5605
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5606
- functionName: "addPermission",
5607
- args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER]
5608
- });
5609
- const saleData = (0, import_viem7.encodeFunctionData)({
5610
- abi: import_protocol_deployments8.zoraTimedSaleStrategyABI,
5611
- functionName: "setSale",
5612
- args: [
5613
- BigInt(tokenId),
5614
- {
5615
- saleStart,
5616
- saleEnd,
5617
- name: erc20zName,
5618
- symbol: erc20zSymbol
5600
+ if (carry !== 0) {
5601
+ throw new Error("Non-zero carry");
5619
5602
  }
5620
- ]
5621
- });
5622
- const callSale = (0, import_viem7.encodeFunctionData)({
5623
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5624
- functionName: "callSale",
5625
- args: [BigInt(tokenId), minterAddress, saleData]
5626
- });
5603
+ length2 = i2;
5604
+ psz++;
5605
+ }
5606
+ if (source[psz] === " ") {
5607
+ return;
5608
+ }
5609
+ var it4 = size - length2;
5610
+ while (it4 !== size && b256[it4] === 0) {
5611
+ it4++;
5612
+ }
5613
+ var vch = new Uint8Array(zeroes + (size - it4));
5614
+ var j2 = zeroes;
5615
+ while (it4 !== size) {
5616
+ vch[j2++] = b256[it4++];
5617
+ }
5618
+ return vch;
5619
+ }
5620
+ function decode5(string) {
5621
+ var buffer = decodeUnsafe(string);
5622
+ if (buffer) {
5623
+ return buffer;
5624
+ }
5625
+ throw new Error(`Non-${name} character`);
5626
+ }
5627
5627
  return {
5628
- minter: minterAddress,
5629
- setupActions: [fixedPriceApproval, callSale]
5628
+ encode: encode3,
5629
+ decodeUnsafe,
5630
+ decode: decode5
5630
5631
  };
5631
5632
  }
5632
- function setupAllowListMinter({
5633
- chainId,
5634
- tokenId: nextTokenId,
5635
- allowlist,
5636
- fundsRecipient
5637
- }) {
5638
- const merkleSaleStrategyAddress = import_protocol_deployments8.zoraCreatorMerkleMinterStrategyAddress[chainId];
5639
- const merkleApproval = (0, import_viem7.encodeFunctionData)({
5640
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5641
- functionName: "addPermission",
5642
- args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER]
5643
- });
5644
- const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x") ? allowlist.presaleMerkleRoot : `0x${allowlist.presaleMerkleRoot}`;
5645
- const saleData = (0, import_viem7.encodeFunctionData)({
5646
- abi: import_protocol_deployments8.zoraCreatorMerkleMinterStrategyABI,
5647
- functionName: "setSale",
5648
- args: [
5649
- BigInt(nextTokenId),
5650
- {
5651
- presaleStart: allowlist.saleStart,
5652
- presaleEnd: allowlist.saleEnd,
5653
- merkleRoot,
5654
- fundsRecipient
5633
+ var src = base2;
5634
+ var _brrp__multiformats_scope_baseX = src;
5635
+ var base_x_default = _brrp__multiformats_scope_baseX;
5636
+
5637
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base.js
5638
+ var Encoder = class {
5639
+ constructor(name, prefix, baseEncode) {
5640
+ __publicField(this, "name");
5641
+ __publicField(this, "prefix");
5642
+ __publicField(this, "baseEncode");
5643
+ this.name = name;
5644
+ this.prefix = prefix;
5645
+ this.baseEncode = baseEncode;
5646
+ }
5647
+ encode(bytes) {
5648
+ if (bytes instanceof Uint8Array) {
5649
+ return `${this.prefix}${this.baseEncode(bytes)}`;
5650
+ } else {
5651
+ throw Error("Unknown type, must be binary type");
5652
+ }
5653
+ }
5654
+ };
5655
+ var Decoder = class {
5656
+ constructor(name, prefix, baseDecode) {
5657
+ __publicField(this, "name");
5658
+ __publicField(this, "prefix");
5659
+ __publicField(this, "baseDecode");
5660
+ __publicField(this, "prefixCodePoint");
5661
+ this.name = name;
5662
+ this.prefix = prefix;
5663
+ if (prefix.codePointAt(0) === void 0) {
5664
+ throw new Error("Invalid prefix character");
5665
+ }
5666
+ this.prefixCodePoint = prefix.codePointAt(0);
5667
+ this.baseDecode = baseDecode;
5668
+ }
5669
+ decode(text) {
5670
+ if (typeof text === "string") {
5671
+ if (text.codePointAt(0) !== this.prefixCodePoint) {
5672
+ throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
5655
5673
  }
5656
- ]
5657
- });
5658
- const callSaleMerkle = (0, import_viem7.encodeFunctionData)({
5659
- abi: import_protocol_deployments8.zoraCreator1155ImplABI,
5660
- functionName: "callSale",
5661
- args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData]
5662
- });
5663
- return {
5664
- minter: merkleSaleStrategyAddress,
5665
- setupActions: [merkleApproval, callSaleMerkle]
5666
- };
5667
- }
5668
- var isAllowList2 = (salesConfig) => salesConfig.type === "allowlistMint";
5669
- var isErc202 = (salesConfig) => salesConfig.type === "erc20Mint";
5670
- var isFixedPrice2 = (salesConfig) => salesConfig.type === "fixedPrice" || salesConfig.pricePerToken > BigInt(0);
5671
- function setupMinters({ salesConfig, ...rest }) {
5672
- if (isErc202(salesConfig)) {
5673
- return setupErc20Minter({
5674
- ...salesConfig,
5675
- ...rest
5676
- });
5674
+ return this.baseDecode(text.slice(this.prefix.length));
5675
+ } else {
5676
+ throw Error("Can only multibase decode strings");
5677
+ }
5677
5678
  }
5678
- if (isAllowList2(salesConfig)) {
5679
- return setupAllowListMinter({
5680
- allowlist: salesConfig,
5681
- ...rest
5682
- });
5679
+ or(decoder) {
5680
+ return or(this, decoder);
5683
5681
  }
5684
- if (isFixedPrice2(salesConfig))
5685
- return setupFixedPriceMinter({
5686
- ...salesConfig,
5687
- ...rest
5688
- });
5689
- return setupTimedSaleMinter({
5690
- ...salesConfig,
5691
- ...rest
5682
+ };
5683
+ var ComposedDecoder = class {
5684
+ constructor(decoders) {
5685
+ __publicField(this, "decoders");
5686
+ this.decoders = decoders;
5687
+ }
5688
+ or(decoder) {
5689
+ return or(this, decoder);
5690
+ }
5691
+ decode(input) {
5692
+ const prefix = input[0];
5693
+ const decoder = this.decoders[prefix];
5694
+ if (decoder != null) {
5695
+ return decoder.decode(input);
5696
+ } else {
5697
+ throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
5698
+ }
5699
+ }
5700
+ };
5701
+ function or(left, right) {
5702
+ return new ComposedDecoder({
5703
+ ...left.decoders ?? { [left.prefix]: left },
5704
+ ...right.decoders ?? { [right.prefix]: right }
5692
5705
  });
5693
5706
  }
5694
-
5695
- // src/create/token-setup.ts
5696
- async function applyNew1155Defaults(props, ownerAddress) {
5697
- const { payoutRecipient: fundsRecipient } = props;
5698
- const fundsRecipientOrOwner = fundsRecipient && fundsRecipient !== import_viem8.zeroAddress ? fundsRecipient : ownerAddress;
5699
- return {
5700
- payoutRecipient: fundsRecipientOrOwner,
5701
- createReferral: props.createReferral || import_viem8.zeroAddress,
5702
- maxSupply: typeof props.maxSupply === "undefined" ? OPEN_EDITION_MINT_SIZE : BigInt(props.maxSupply),
5703
- royaltyBPS: props.royaltyBPS || 1e3,
5704
- tokenMetadataURI: props.tokenMetadataURI,
5705
- salesConfig: await getSalesConfigWithDefaults(
5706
- props.salesConfig,
5707
- props.tokenMetadataURI
5708
- )
5709
- };
5710
- }
5711
- function buildSetupNewToken({
5712
- tokenURI,
5713
- maxSupply = OPEN_EDITION_MINT_SIZE,
5714
- createReferral = import_viem8.zeroAddress,
5715
- contractVersion
5716
- }) {
5717
- if (contractSupportsMintRewards(contractVersion, "ERC1155")) {
5718
- return (0, import_viem8.encodeFunctionData)({
5719
- abi: import_protocol_deployments9.zoraCreator1155ImplABI,
5720
- functionName: "setupNewTokenWithCreateReferral",
5721
- args: [tokenURI, BigInt(maxSupply), createReferral]
5722
- });
5707
+ var Codec = class {
5708
+ constructor(name, prefix, baseEncode, baseDecode) {
5709
+ __publicField(this, "name");
5710
+ __publicField(this, "prefix");
5711
+ __publicField(this, "baseEncode");
5712
+ __publicField(this, "baseDecode");
5713
+ __publicField(this, "encoder");
5714
+ __publicField(this, "decoder");
5715
+ this.name = name;
5716
+ this.prefix = prefix;
5717
+ this.baseEncode = baseEncode;
5718
+ this.baseDecode = baseDecode;
5719
+ this.encoder = new Encoder(name, prefix, baseEncode);
5720
+ this.decoder = new Decoder(name, prefix, baseDecode);
5723
5721
  }
5724
- if (createReferral !== import_viem8.zeroAddress) {
5725
- throw new Error(
5726
- "Contract does not support create referral, but one was provided"
5727
- );
5722
+ encode(input) {
5723
+ return this.encoder.encode(input);
5728
5724
  }
5729
- return (0, import_viem8.encodeFunctionData)({
5730
- abi: import_protocol_deployments9.zoraCreator1155ImplABI,
5731
- functionName: "setupNewToken",
5732
- args: [tokenURI, BigInt(maxSupply)]
5725
+ decode(input) {
5726
+ return this.decoder.decode(input);
5727
+ }
5728
+ };
5729
+ function from({ name, prefix, encode: encode3, decode: decode5 }) {
5730
+ return new Codec(name, prefix, encode3, decode5);
5731
+ }
5732
+ function baseX({ name, prefix, alphabet }) {
5733
+ const { encode: encode3, decode: decode5 } = base_x_default(alphabet, name);
5734
+ return from({
5735
+ prefix,
5736
+ name,
5737
+ encode: encode3,
5738
+ decode: (text) => coerce3(decode5(text))
5733
5739
  });
5734
5740
  }
5735
- function setupRoyaltyConfig({
5736
- royaltyBPS,
5737
- royaltyRecipient,
5738
- nextTokenId
5739
- }) {
5740
- if (royaltyBPS > 0 && royaltyRecipient != import_viem8.zeroAddress) {
5741
- return (0, import_viem8.encodeFunctionData)({
5742
- abi: import_protocol_deployments9.zoraCreator1155ImplABI,
5743
- functionName: "updateRoyaltiesForToken",
5744
- args: [
5745
- nextTokenId,
5746
- {
5747
- royaltyBPS,
5748
- royaltyRecipient,
5749
- royaltyMintSchedule: 0
5750
- }
5751
- ]
5752
- });
5741
+ function decode(string, alphabet, bitsPerChar, name) {
5742
+ const codes = {};
5743
+ for (let i = 0; i < alphabet.length; ++i) {
5744
+ codes[alphabet[i]] = i;
5753
5745
  }
5754
- return null;
5746
+ let end = string.length;
5747
+ while (string[end - 1] === "=") {
5748
+ --end;
5749
+ }
5750
+ const out = new Uint8Array(end * bitsPerChar / 8 | 0);
5751
+ let bits = 0;
5752
+ let buffer = 0;
5753
+ let written = 0;
5754
+ for (let i = 0; i < end; ++i) {
5755
+ const value = codes[string[i]];
5756
+ if (value === void 0) {
5757
+ throw new SyntaxError(`Non-${name} character`);
5758
+ }
5759
+ buffer = buffer << bitsPerChar | value;
5760
+ bits += bitsPerChar;
5761
+ if (bits >= 8) {
5762
+ bits -= 8;
5763
+ out[written++] = 255 & buffer >> bits;
5764
+ }
5765
+ }
5766
+ if (bits >= bitsPerChar || (255 & buffer << 8 - bits) !== 0) {
5767
+ throw new SyntaxError("Unexpected end of data");
5768
+ }
5769
+ return out;
5755
5770
  }
5756
- function makeAdminMintCall({
5757
- ownerAddress,
5758
- mintQuantity,
5759
- nextTokenId
5760
- }) {
5761
- if (!mintQuantity || mintQuantity <= 0 || !ownerAddress) {
5762
- return null;
5771
+ function encode(data, alphabet, bitsPerChar) {
5772
+ const pad = alphabet[alphabet.length - 1] === "=";
5773
+ const mask = (1 << bitsPerChar) - 1;
5774
+ let out = "";
5775
+ let bits = 0;
5776
+ let buffer = 0;
5777
+ for (let i = 0; i < data.length; ++i) {
5778
+ buffer = buffer << 8 | data[i];
5779
+ bits += 8;
5780
+ while (bits > bitsPerChar) {
5781
+ bits -= bitsPerChar;
5782
+ out += alphabet[mask & buffer >> bits];
5783
+ }
5763
5784
  }
5764
- return (0, import_viem8.encodeFunctionData)({
5765
- abi: import_protocol_deployments9.zoraCreator1155ImplABI,
5766
- functionName: "adminMint",
5767
- args: [ownerAddress, nextTokenId, BigInt(mintQuantity), import_viem8.zeroAddress]
5768
- });
5785
+ if (bits !== 0) {
5786
+ out += alphabet[mask & buffer << bitsPerChar - bits];
5787
+ }
5788
+ if (pad) {
5789
+ while ((out.length * bitsPerChar & 7) !== 0) {
5790
+ out += "=";
5791
+ }
5792
+ }
5793
+ return out;
5769
5794
  }
5770
- async function constructCreate1155TokenCalls(props) {
5771
- const {
5772
- chainId,
5773
- nextTokenId,
5774
- mintToCreatorCount,
5775
- ownerAddress,
5776
- contractVersion
5777
- } = props;
5778
- const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
5779
- props,
5780
- ownerAddress
5781
- );
5782
- const verifyTokenIdExpected = (0, import_viem8.encodeFunctionData)({
5783
- abi: import_protocol_deployments9.zoraCreator1155ImplABI,
5784
- functionName: "assumeLastTokenIdMatches",
5785
- args: [nextTokenId - 1n]
5786
- });
5787
- const setupNewToken = buildSetupNewToken({
5788
- tokenURI: new1155TokenPropsWithDefaults.tokenMetadataURI,
5789
- maxSupply: new1155TokenPropsWithDefaults.maxSupply,
5790
- createReferral: new1155TokenPropsWithDefaults.createReferral,
5791
- contractVersion
5792
- });
5793
- const royaltyConfig = setupRoyaltyConfig({
5794
- royaltyBPS: new1155TokenPropsWithDefaults.royaltyBPS,
5795
- royaltyRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
5796
- nextTokenId
5797
- });
5798
- const { minter, setupActions: mintersSetup } = setupMinters({
5799
- tokenId: nextTokenId,
5800
- chainId,
5801
- fundsRecipient: new1155TokenPropsWithDefaults.payoutRecipient,
5802
- salesConfig: new1155TokenPropsWithDefaults.salesConfig
5803
- });
5804
- const adminMintCall = makeAdminMintCall({
5805
- ownerAddress,
5806
- mintQuantity: mintToCreatorCount,
5807
- nextTokenId
5795
+ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
5796
+ return from({
5797
+ prefix,
5798
+ name,
5799
+ encode(input) {
5800
+ return encode(input, alphabet, bitsPerChar);
5801
+ },
5802
+ decode(input) {
5803
+ return decode(input, alphabet, bitsPerChar, name);
5804
+ }
5808
5805
  });
5809
- const setupActions = [
5810
- verifyTokenIdExpected,
5811
- setupNewToken,
5812
- ...mintersSetup,
5813
- royaltyConfig,
5814
- adminMintCall
5815
- ].filter((item) => item !== null);
5816
- return {
5817
- setupActions,
5818
- minter,
5819
- newToken: new1155TokenPropsWithDefaults
5820
- };
5821
5806
  }
5822
- var contractSupportsMintRewards = (contractVersion, contractStandard) => {
5823
- if (!contractStandard || !contractVersion) {
5824
- return false;
5825
- }
5826
- const semVerContractVersion = semver2.coerce(contractVersion)?.raw;
5827
- if (!semVerContractVersion)
5828
- return false;
5829
- if (contractStandard === "ERC1155") {
5830
- return semver2.gte(semVerContractVersion, "1.3.5");
5831
- } else {
5832
- return semver2.gte(semVerContractVersion, "14.0.0");
5833
- }
5834
- };
5835
5807
 
5836
- // src/create/mint-from-create.ts
5837
- var import_viem9 = require("viem");
5838
- var import_protocol_deployments10 = require("@zoralabs/protocol-deployments");
5839
- async function toSalesStrategyFromSubgraph({
5840
- minter,
5841
- salesConfig,
5842
- publicClient,
5843
- contractAddress
5844
- }) {
5845
- if (salesConfig.type === "timed") {
5846
- return {
5847
- saleType: "timed",
5848
- address: minter,
5849
- // for now we hardcode this
5850
- mintFeePerQuantity: (0, import_viem9.parseEther)("0.000111"),
5851
- saleStart: salesConfig.saleStart.toString(),
5852
- saleEnd: salesConfig.saleEnd.toString(),
5853
- // the following are not needed for now but we wanna satisfy concrete
5854
- erc20Z: import_viem9.zeroAddress,
5855
- mintFee: 0n,
5856
- pool: import_viem9.zeroAddress,
5857
- secondaryActivated: false
5858
- };
5859
- }
5860
- if (salesConfig.type === "erc20Mint") {
5861
- return {
5862
- saleType: "erc20",
5863
- address: minter,
5864
- mintFeePerQuantity: 0n,
5865
- saleStart: salesConfig.saleStart.toString(),
5866
- saleEnd: salesConfig.saleEnd.toString(),
5867
- currency: salesConfig.currency,
5868
- pricePerToken: salesConfig.pricePerToken,
5869
- maxTokensPerAddress: salesConfig.maxTokensPerAddress
5870
- };
5808
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base32.js
5809
+ var base32 = rfc4648({
5810
+ prefix: "b",
5811
+ name: "base32",
5812
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567",
5813
+ bitsPerChar: 5
5814
+ });
5815
+ var base32upper = rfc4648({
5816
+ prefix: "B",
5817
+ name: "base32upper",
5818
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
5819
+ bitsPerChar: 5
5820
+ });
5821
+ var base32pad = rfc4648({
5822
+ prefix: "c",
5823
+ name: "base32pad",
5824
+ alphabet: "abcdefghijklmnopqrstuvwxyz234567=",
5825
+ bitsPerChar: 5
5826
+ });
5827
+ var base32padupper = rfc4648({
5828
+ prefix: "C",
5829
+ name: "base32padupper",
5830
+ alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
5831
+ bitsPerChar: 5
5832
+ });
5833
+ var base32hex = rfc4648({
5834
+ prefix: "v",
5835
+ name: "base32hex",
5836
+ alphabet: "0123456789abcdefghijklmnopqrstuv",
5837
+ bitsPerChar: 5
5838
+ });
5839
+ var base32hexupper = rfc4648({
5840
+ prefix: "V",
5841
+ name: "base32hexupper",
5842
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
5843
+ bitsPerChar: 5
5844
+ });
5845
+ var base32hexpad = rfc4648({
5846
+ prefix: "t",
5847
+ name: "base32hexpad",
5848
+ alphabet: "0123456789abcdefghijklmnopqrstuv=",
5849
+ bitsPerChar: 5
5850
+ });
5851
+ var base32hexpadupper = rfc4648({
5852
+ prefix: "T",
5853
+ name: "base32hexpadupper",
5854
+ alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=",
5855
+ bitsPerChar: 5
5856
+ });
5857
+ var base32z = rfc4648({
5858
+ prefix: "h",
5859
+ name: "base32z",
5860
+ alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769",
5861
+ bitsPerChar: 5
5862
+ });
5863
+
5864
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/bases/base58.js
5865
+ var base58btc = baseX({
5866
+ name: "base58btc",
5867
+ prefix: "z",
5868
+ alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
5869
+ });
5870
+ var base58flickr = baseX({
5871
+ name: "base58flickr",
5872
+ prefix: "Z",
5873
+ alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
5874
+ });
5875
+
5876
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/vendor/varint.js
5877
+ var encode_1 = encode2;
5878
+ var MSB = 128;
5879
+ var REST = 127;
5880
+ var MSBALL = ~REST;
5881
+ var INT = Math.pow(2, 31);
5882
+ function encode2(num, out, offset) {
5883
+ out = out || [];
5884
+ offset = offset || 0;
5885
+ var oldOffset = offset;
5886
+ while (num >= INT) {
5887
+ out[offset++] = num & 255 | MSB;
5888
+ num /= 128;
5871
5889
  }
5872
- const contractMintFee = await publicClient.readContract({
5873
- abi: import_protocol_deployments10.zoraCreator1155ImplABI,
5874
- address: contractAddress,
5875
- functionName: "mintFee"
5876
- });
5877
- if (salesConfig.type === "fixedPrice") {
5878
- return {
5879
- saleType: "fixedPrice",
5880
- address: minter,
5881
- maxTokensPerAddress: salesConfig.maxTokensPerAddress,
5882
- mintFeePerQuantity: contractMintFee,
5883
- pricePerToken: salesConfig.pricePerToken,
5884
- saleStart: salesConfig.saleStart.toString(),
5885
- saleEnd: salesConfig.saleEnd.toString()
5886
- };
5890
+ while (num & MSBALL) {
5891
+ out[offset++] = num & 255 | MSB;
5892
+ num >>>= 7;
5887
5893
  }
5888
- return {
5889
- saleType: "allowlist",
5890
- address: minter,
5891
- saleStart: salesConfig.saleStart.toString(),
5892
- saleEnd: salesConfig.saleEnd.toString(),
5893
- merkleRoot: salesConfig.presaleMerkleRoot,
5894
- mintFeePerQuantity: contractMintFee
5895
- };
5896
- }
5897
- function makeOnchainPrepareMintFromCreate({
5898
- contractAddress,
5899
- tokenId,
5900
- result,
5901
- minter,
5902
- publicClient,
5903
- contractVersion
5904
- }) {
5905
- return async (params) => {
5906
- const subgraphSalesConfig = await toSalesStrategyFromSubgraph({
5907
- minter,
5908
- contractAddress,
5909
- publicClient,
5910
- salesConfig: result
5911
- });
5912
- return {
5913
- parameters: makePrepareMint1155TokenParams({
5914
- salesConfigAndTokenInfo: {
5915
- salesConfig: subgraphSalesConfig,
5916
- contractVersion
5917
- },
5918
- ...params,
5919
- tokenContract: contractAddress,
5920
- tokenId
5921
- }),
5922
- costs: parseMintCosts({
5923
- allowListEntry: params.allowListEntry,
5924
- quantityToMint: BigInt(params.quantityToMint),
5925
- salesConfig: subgraphSalesConfig
5926
- }),
5927
- erc20Approval: getRequiredErc20Approvals(params, subgraphSalesConfig)
5928
- };
5929
- };
5894
+ out[offset] = num | 0;
5895
+ encode2.bytes = offset - oldOffset + 1;
5896
+ return out;
5930
5897
  }
5931
-
5932
- // src/create/1155-create-helper.ts
5933
- var ROYALTY_BPS_DEFAULT = 1e3;
5934
- var getTokenIdFromCreateReceipt = (receipt) => {
5935
- for (const data of receipt.logs) {
5936
- try {
5937
- const decodedLog = (0, import_viem10.decodeEventLog)({
5938
- abi: import_protocol_deployments11.zoraCreator1155ImplABI,
5939
- eventName: "SetupNewToken",
5940
- ...data
5941
- });
5942
- if (decodedLog && decodedLog.eventName === "SetupNewToken") {
5943
- return decodedLog.args.tokenId;
5944
- }
5945
- } catch (err) {
5898
+ var decode2 = read;
5899
+ var MSB$1 = 128;
5900
+ var REST$1 = 127;
5901
+ function read(buf, offset) {
5902
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
5903
+ do {
5904
+ if (counter >= l) {
5905
+ read.bytes = 0;
5906
+ throw new RangeError("Could not decode varint");
5946
5907
  }
5947
- }
5948
- throw new Error(
5949
- "No event found in receipt that could be used to get tokenId"
5950
- );
5908
+ b = buf[counter++];
5909
+ res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift);
5910
+ shift += 7;
5911
+ } while (b >= MSB$1);
5912
+ read.bytes = counter - offset;
5913
+ return res;
5914
+ }
5915
+ var N1 = Math.pow(2, 7);
5916
+ var N2 = Math.pow(2, 14);
5917
+ var N3 = Math.pow(2, 21);
5918
+ var N4 = Math.pow(2, 28);
5919
+ var N5 = Math.pow(2, 35);
5920
+ var N6 = Math.pow(2, 42);
5921
+ var N7 = Math.pow(2, 49);
5922
+ var N8 = Math.pow(2, 56);
5923
+ var N9 = Math.pow(2, 63);
5924
+ var length = function(value) {
5925
+ return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
5951
5926
  };
5952
- var getContractAddressFromReceipt = (receipt) => {
5953
- for (const data of receipt.logs) {
5954
- try {
5955
- const decodedLog = (0, import_viem10.decodeEventLog)({
5956
- abi: import_protocol_deployments11.zoraCreator1155FactoryImplABI,
5957
- eventName: "SetupNewContract",
5958
- ...data
5959
- });
5960
- if (decodedLog && decodedLog.eventName === "SetupNewContract") {
5961
- return decodedLog.args.newContract;
5962
- }
5963
- } catch (err) {
5964
- }
5965
- }
5966
- throw new Error(
5967
- "No event found in receipt that could be used to get contract address"
5968
- );
5927
+ var varint = {
5928
+ encode: encode_1,
5929
+ decode: decode2,
5930
+ encodingLength: length
5969
5931
  };
5970
- function makeCreateContractAndTokenCall({
5971
- account,
5972
- contract,
5973
- royaltyBPS,
5974
- fundsRecipient,
5975
- tokenSetupActions,
5976
- chainId
5977
- }) {
5978
- const accountAddress = typeof account === "string" ? account : account.address;
5979
- return makeContractParameters({
5980
- abi: import_protocol_deployments11.zoraCreator1155FactoryImplABI,
5981
- functionName: "createContractDeterministic",
5982
- account,
5983
- address: import_protocol_deployments11.zoraCreator1155FactoryImplAddress[chainId],
5984
- args: [
5985
- contract.uri,
5986
- contract.name,
5987
- {
5988
- // deprecated
5989
- royaltyMintSchedule: 0,
5990
- royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
5991
- royaltyRecipient: fundsRecipient || accountAddress
5992
- },
5993
- contract.defaultAdmin || accountAddress,
5994
- tokenSetupActions
5995
- ]
5996
- });
5932
+ var _brrp_varint = varint;
5933
+ var varint_default = _brrp_varint;
5934
+
5935
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/varint.js
5936
+ function decode3(data, offset = 0) {
5937
+ const code = varint_default.decode(data, offset);
5938
+ return [code, varint_default.decode.bytes];
5997
5939
  }
5998
- function makeCreateTokenCall({
5999
- contractAddress,
6000
- account,
6001
- tokenSetupActions
6002
- }) {
6003
- return makeContractParameters({
6004
- abi: import_protocol_deployments11.zoraCreator1155ImplABI,
6005
- functionName: "multicall",
6006
- account,
6007
- address: contractAddress,
6008
- args: [tokenSetupActions]
6009
- });
5940
+ function encodeTo(int, target, offset = 0) {
5941
+ varint_default.encode(int, target, offset);
5942
+ return target;
5943
+ }
5944
+ function encodingLength(int) {
5945
+ return varint_default.encodingLength(int);
5946
+ }
5947
+
5948
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/hashes/digest.js
5949
+ function create(code, digest) {
5950
+ const size = digest.byteLength;
5951
+ const sizeOffset = encodingLength(code);
5952
+ const digestOffset = sizeOffset + encodingLength(size);
5953
+ const bytes = new Uint8Array(digestOffset + size);
5954
+ encodeTo(code, bytes, 0);
5955
+ encodeTo(size, bytes, sizeOffset);
5956
+ bytes.set(digest, digestOffset);
5957
+ return new Digest(code, size, digest, bytes);
6010
5958
  }
6011
- var Create1155Client = class {
6012
- constructor({
6013
- chainId,
6014
- publicClient
6015
- }) {
6016
- this.chainId = chainId;
6017
- this.publicClient = publicClient;
5959
+ function decode4(multihash) {
5960
+ const bytes = coerce3(multihash);
5961
+ const [code, sizeOffset] = decode3(bytes);
5962
+ const [size, digestOffset] = decode3(bytes.subarray(sizeOffset));
5963
+ const digest = bytes.subarray(sizeOffset + digestOffset);
5964
+ if (digest.byteLength !== size) {
5965
+ throw new Error("Incorrect length");
6018
5966
  }
6019
- async createNew1155(props) {
6020
- return createNew1155ContractAndToken({
6021
- ...props,
6022
- publicClient: this.publicClient,
6023
- chainId: this.chainId
6024
- });
5967
+ return new Digest(code, size, digest, bytes);
5968
+ }
5969
+ function equals2(a, b) {
5970
+ if (a === b) {
5971
+ return true;
5972
+ } else {
5973
+ const data = b;
5974
+ return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes);
6025
5975
  }
6026
- async createNew1155OnExistingContract({
6027
- contractAddress: contract,
6028
- account,
6029
- token,
6030
- getAdditionalSetupActions
6031
- }) {
6032
- return createNew1155Token({
6033
- contractAddress: contract,
6034
- account,
6035
- token,
6036
- getAdditionalSetupActions,
6037
- publicClient: this.publicClient,
6038
- chainId: this.chainId
6039
- });
5976
+ }
5977
+ var Digest = class {
5978
+ /**
5979
+ * Creates a multihash digest.
5980
+ */
5981
+ constructor(code, size, digest, bytes) {
5982
+ __publicField(this, "code");
5983
+ __publicField(this, "size");
5984
+ __publicField(this, "digest");
5985
+ __publicField(this, "bytes");
5986
+ this.code = code;
5987
+ this.size = size;
5988
+ this.digest = digest;
5989
+ this.bytes = bytes;
6040
5990
  }
6041
5991
  };
6042
- async function createNew1155ContractAndToken({
6043
- contract,
6044
- account,
6045
- chainId,
6046
- token,
6047
- publicClient,
6048
- getAdditionalSetupActions
6049
- }) {
6050
- const nextTokenId = 1n;
6051
- const contractVersion = new1155ContractVersion(chainId);
6052
- const {
6053
- minter,
6054
- newToken,
6055
- setupActions: tokenSetupActions
6056
- } = await prepareSetupActions({
6057
- chainId,
6058
- account,
6059
- contractVersion,
6060
- nextTokenId,
6061
- token,
6062
- getAdditionalSetupActions
6063
- });
6064
- const request = makeCreateContractAndTokenCall({
6065
- contract,
6066
- account,
6067
- chainId,
6068
- tokenSetupActions,
6069
- fundsRecipient: token.payoutRecipient,
6070
- royaltyBPS: token.royaltyBPS
6071
- });
6072
- const contractAddress = await getDeterministicContractAddress({
6073
- account,
6074
- publicClient,
6075
- setupActions: tokenSetupActions,
6076
- chainId,
6077
- contract
6078
- });
6079
- const prepareMint = makeOnchainPrepareMintFromCreate({
6080
- contractAddress,
6081
- contractVersion,
6082
- minter,
6083
- publicClient,
6084
- result: newToken.salesConfig,
6085
- tokenId: nextTokenId
6086
- });
6087
- return {
6088
- parameters: request,
6089
- tokenSetupActions,
6090
- newTokenId: nextTokenId,
6091
- newToken,
6092
- contractAddress,
6093
- contractVersion,
6094
- minter,
6095
- prepareMint
6096
- };
6097
- }
6098
- async function createNew1155Token({
6099
- contractAddress,
6100
- account,
6101
- getAdditionalSetupActions,
6102
- token,
6103
- publicClient,
6104
- chainId
6105
- }) {
6106
- const { nextTokenId, contractVersion } = await getContractInfoExistingContract({
6107
- publicClient,
6108
- contractAddress
6109
- });
6110
- const {
6111
- minter,
6112
- newToken,
6113
- setupActions: tokenSetupActions
6114
- } = await prepareSetupActions({
6115
- chainId,
6116
- account,
6117
- contractVersion,
6118
- nextTokenId,
6119
- token,
6120
- getAdditionalSetupActions
6121
- });
6122
- const request = makeCreateTokenCall({
6123
- contractAddress,
6124
- account,
6125
- tokenSetupActions
6126
- });
6127
- const prepareMint = makeOnchainPrepareMintFromCreate({
6128
- contractAddress,
6129
- contractVersion,
6130
- minter,
6131
- publicClient,
6132
- result: newToken.salesConfig,
6133
- tokenId: nextTokenId
6134
- });
6135
- return {
6136
- parameters: request,
6137
- tokenSetupActions,
6138
- newTokenId: nextTokenId,
6139
- newToken,
6140
- contractVersion,
6141
- minter,
6142
- prepareMint
6143
- };
5992
+
5993
+ // ../../node_modules/.pnpm/multiformats@13.2.1/node_modules/multiformats/dist/src/cid.js
5994
+ function format(link, base3) {
5995
+ const { bytes, version } = link;
5996
+ switch (version) {
5997
+ case 0:
5998
+ return toStringV0(bytes, baseCache(link), base3 ?? base58btc.encoder);
5999
+ default:
6000
+ return toStringV1(bytes, baseCache(link), base3 ?? base32.encoder);
6001
+ }
6144
6002
  }
6145
- async function prepareSetupActions({
6146
- chainId,
6147
- account,
6148
- contractVersion,
6149
- nextTokenId,
6150
- token,
6151
- getAdditionalSetupActions
6152
- }) {
6153
- const {
6154
- minter,
6155
- newToken,
6156
- setupActions: tokenSetupActions
6157
- } = await constructCreate1155TokenCalls({
6158
- chainId,
6159
- ownerAddress: account,
6160
- contractVersion,
6161
- nextTokenId,
6162
- ...token
6163
- });
6164
- const setupActions = getAdditionalSetupActions ? [
6165
- ...getAdditionalSetupActions({
6166
- tokenId: nextTokenId
6167
- }),
6168
- ...tokenSetupActions
6169
- ] : tokenSetupActions;
6170
- return { minter, newToken, setupActions };
6003
+ var cache = /* @__PURE__ */ new WeakMap();
6004
+ function baseCache(cid) {
6005
+ const baseCache2 = cache.get(cid);
6006
+ if (baseCache2 == null) {
6007
+ const baseCache3 = /* @__PURE__ */ new Map();
6008
+ cache.set(cid, baseCache3);
6009
+ return baseCache3;
6010
+ }
6011
+ return baseCache2;
6171
6012
  }
6172
-
6173
- // src/sparks/mints-queries.ts
6174
- var getMintsAccountBalanceWithPriceQuery = (account) => {
6175
- const query = `
6176
- query GetMintAccountBalances($account: String!) {
6177
- mintAccountBalances(where: { account: $account }) {
6178
- balance
6179
- mintToken {
6180
- id
6181
- pricePerToken
6013
+ var _a;
6014
+ var CID = class _CID {
6015
+ /**
6016
+ * @param version - Version of the CID
6017
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
6018
+ * @param multihash - (Multi)hash of the of the content.
6019
+ */
6020
+ constructor(version, code, multihash, bytes) {
6021
+ __publicField(this, "code");
6022
+ __publicField(this, "version");
6023
+ __publicField(this, "multihash");
6024
+ __publicField(this, "bytes");
6025
+ __publicField(this, "/");
6026
+ __publicField(this, _a, "CID");
6027
+ this.code = code;
6028
+ this.version = version;
6029
+ this.multihash = multihash;
6030
+ this.bytes = bytes;
6031
+ this["/"] = bytes;
6032
+ }
6033
+ /**
6034
+ * Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes`
6035
+ * please either use `CID.asCID(cid)` or switch to new signalling mechanism
6036
+ *
6037
+ * @deprecated
6038
+ */
6039
+ get asCID() {
6040
+ return this;
6041
+ }
6042
+ // ArrayBufferView
6043
+ get byteOffset() {
6044
+ return this.bytes.byteOffset;
6045
+ }
6046
+ // ArrayBufferView
6047
+ get byteLength() {
6048
+ return this.bytes.byteLength;
6049
+ }
6050
+ toV0() {
6051
+ switch (this.version) {
6052
+ case 0: {
6053
+ return this;
6054
+ }
6055
+ case 1: {
6056
+ const { code, multihash } = this;
6057
+ if (code !== DAG_PB_CODE) {
6058
+ throw new Error("Cannot convert a non dag-pb CID to CIDv0");
6059
+ }
6060
+ if (multihash.code !== SHA_256_CODE) {
6061
+ throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");
6182
6062
  }
6063
+ return _CID.createV0(multihash);
6064
+ }
6065
+ default: {
6066
+ throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`);
6183
6067
  }
6184
6068
  }
6185
- `;
6186
- return {
6187
- query,
6188
- variables: { account }
6189
- };
6190
- };
6191
- var selectMintsToCollectWithFromQueryResult = (mintAccountBalances, quantityToCollect) => {
6192
- const parsed = mintAccountBalances.map((r) => {
6193
- return {
6194
- tokenId: BigInt(r.mintToken.id),
6195
- quantity: BigInt(r.balance),
6196
- pricePerToken: BigInt(r.mintToken.pricePerToken)
6069
+ }
6070
+ toV1() {
6071
+ switch (this.version) {
6072
+ case 0: {
6073
+ const { code, digest } = this.multihash;
6074
+ const multihash = create(code, digest);
6075
+ return _CID.createV1(this.code, multihash);
6076
+ }
6077
+ case 1: {
6078
+ return this;
6079
+ }
6080
+ default: {
6081
+ throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`);
6082
+ }
6083
+ }
6084
+ }
6085
+ equals(other) {
6086
+ return _CID.equals(this, other);
6087
+ }
6088
+ static equals(self, other) {
6089
+ const unknown = other;
6090
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
6091
+ }
6092
+ toString(base3) {
6093
+ return format(this, base3);
6094
+ }
6095
+ toJSON() {
6096
+ return { "/": format(this) };
6097
+ }
6098
+ link() {
6099
+ return this;
6100
+ }
6101
+ // Legacy
6102
+ [(_a = Symbol.toStringTag, Symbol.for("nodejs.util.inspect.custom"))]() {
6103
+ return `CID(${this.toString()})`;
6104
+ }
6105
+ /**
6106
+ * Takes any input `value` and returns a `CID` instance if it was
6107
+ * a `CID` otherwise returns `null`. If `value` is instanceof `CID`
6108
+ * it will return value back. If `value` is not instance of this CID
6109
+ * class, but is compatible CID it will return new instance of this
6110
+ * `CID` class. Otherwise returns null.
6111
+ *
6112
+ * This allows two different incompatible versions of CID library to
6113
+ * co-exist and interop as long as binary interface is compatible.
6114
+ */
6115
+ static asCID(input) {
6116
+ if (input == null) {
6117
+ return null;
6118
+ }
6119
+ const value = input;
6120
+ if (value instanceof _CID) {
6121
+ return value;
6122
+ } else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) {
6123
+ const { version, code, multihash, bytes } = value;
6124
+ return new _CID(version, code, multihash, bytes ?? encodeCID(version, code, multihash.bytes));
6125
+ } else if (value[cidSymbol] === true) {
6126
+ const { version, multihash, code } = value;
6127
+ const digest = decode4(multihash);
6128
+ return _CID.create(version, code, digest);
6129
+ } else {
6130
+ return null;
6131
+ }
6132
+ }
6133
+ /**
6134
+ * @param version - Version of the CID
6135
+ * @param code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv
6136
+ * @param digest - (Multi)hash of the of the content.
6137
+ */
6138
+ static create(version, code, digest) {
6139
+ if (typeof code !== "number") {
6140
+ throw new Error("String codecs are no longer supported");
6141
+ }
6142
+ if (!(digest.bytes instanceof Uint8Array)) {
6143
+ throw new Error("Invalid digest");
6144
+ }
6145
+ switch (version) {
6146
+ case 0: {
6147
+ if (code !== DAG_PB_CODE) {
6148
+ throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);
6149
+ } else {
6150
+ return new _CID(version, code, digest, digest.bytes);
6151
+ }
6152
+ }
6153
+ case 1: {
6154
+ const bytes = encodeCID(version, code, digest.bytes);
6155
+ return new _CID(version, code, digest, bytes);
6156
+ }
6157
+ default: {
6158
+ throw new Error("Invalid version");
6159
+ }
6160
+ }
6161
+ }
6162
+ /**
6163
+ * Simplified version of `create` for CIDv0.
6164
+ */
6165
+ static createV0(digest) {
6166
+ return _CID.create(0, DAG_PB_CODE, digest);
6167
+ }
6168
+ /**
6169
+ * Simplified version of `create` for CIDv1.
6170
+ *
6171
+ * @param code - Content encoding format code.
6172
+ * @param digest - Multihash of the content.
6173
+ */
6174
+ static createV1(code, digest) {
6175
+ return _CID.create(1, code, digest);
6176
+ }
6177
+ /**
6178
+ * Decoded a CID from its binary representation. The byte array must contain
6179
+ * only the CID with no additional bytes.
6180
+ *
6181
+ * An error will be thrown if the bytes provided do not contain a valid
6182
+ * binary representation of a CID.
6183
+ */
6184
+ static decode(bytes) {
6185
+ const [cid, remainder] = _CID.decodeFirst(bytes);
6186
+ if (remainder.length !== 0) {
6187
+ throw new Error("Incorrect length");
6188
+ }
6189
+ return cid;
6190
+ }
6191
+ /**
6192
+ * Decoded a CID from its binary representation at the beginning of a byte
6193
+ * array.
6194
+ *
6195
+ * Returns an array with the first element containing the CID and the second
6196
+ * element containing the remainder of the original byte array. The remainder
6197
+ * will be a zero-length byte array if the provided bytes only contained a
6198
+ * binary CID representation.
6199
+ */
6200
+ static decodeFirst(bytes) {
6201
+ const specs = _CID.inspectBytes(bytes);
6202
+ const prefixSize = specs.size - specs.multihashSize;
6203
+ const multihashBytes = coerce3(bytes.subarray(prefixSize, prefixSize + specs.multihashSize));
6204
+ if (multihashBytes.byteLength !== specs.multihashSize) {
6205
+ throw new Error("Incorrect length");
6206
+ }
6207
+ const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize);
6208
+ const digest = new Digest(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes);
6209
+ const cid = specs.version === 0 ? _CID.createV0(digest) : _CID.createV1(specs.codec, digest);
6210
+ return [cid, bytes.subarray(specs.size)];
6211
+ }
6212
+ /**
6213
+ * Inspect the initial bytes of a CID to determine its properties.
6214
+ *
6215
+ * Involves decoding up to 4 varints. Typically this will require only 4 to 6
6216
+ * bytes but for larger multicodec code values and larger multihash digest
6217
+ * lengths these varints can be quite large. It is recommended that at least
6218
+ * 10 bytes be made available in the `initialBytes` argument for a complete
6219
+ * inspection.
6220
+ */
6221
+ static inspectBytes(initialBytes) {
6222
+ let offset = 0;
6223
+ const next = () => {
6224
+ const [i, length2] = decode3(initialBytes.subarray(offset));
6225
+ offset += length2;
6226
+ return i;
6197
6227
  };
6198
- });
6199
- const sorted = parsed.sort((a, b) => {
6200
- if (a.pricePerToken < b.pricePerToken) {
6201
- return -1;
6228
+ let version = next();
6229
+ let codec = DAG_PB_CODE;
6230
+ if (version === 18) {
6231
+ version = 0;
6232
+ offset = 0;
6233
+ } else {
6234
+ codec = next();
6202
6235
  }
6203
- return 1;
6204
- });
6205
- let remainingQuantity = quantityToCollect;
6206
- const tokenIds = [];
6207
- const quantities = [];
6208
- while (remainingQuantity > 0) {
6209
- const next = sorted.shift();
6210
- if (!next) {
6211
- throw new Error("Not enough MINTs to collect with");
6236
+ if (version !== 0 && version !== 1) {
6237
+ throw new RangeError(`Invalid CID version ${version}`);
6212
6238
  }
6213
- const quantityToUse = remainingQuantity > next.quantity ? next.quantity : remainingQuantity;
6214
- tokenIds.push(next.tokenId);
6215
- quantities.push(quantityToUse);
6216
- remainingQuantity -= quantityToUse;
6239
+ const prefixSize = offset;
6240
+ const multihashCode = next();
6241
+ const digestSize = next();
6242
+ const size = offset + digestSize;
6243
+ const multihashSize = size - prefixSize;
6244
+ return { version, codec, multihashCode, digestSize, multihashSize, size };
6245
+ }
6246
+ /**
6247
+ * Takes cid in a string representation and creates an instance. If `base`
6248
+ * decoder is not provided will use a default from the configuration. It will
6249
+ * throw an error if encoding of the CID is not compatible with supplied (or
6250
+ * a default decoder).
6251
+ */
6252
+ static parse(source, base3) {
6253
+ const [prefix, bytes] = parseCIDtoBytes(source, base3);
6254
+ const cid = _CID.decode(bytes);
6255
+ if (cid.version === 0 && source[0] !== "Q") {
6256
+ throw Error("Version 0 CID string must not include multibase prefix");
6257
+ }
6258
+ baseCache(cid).set(prefix, source);
6259
+ return cid;
6217
6260
  }
6218
- return {
6219
- tokenIds,
6220
- quantities
6221
- };
6222
- };
6223
- var sumBalances = (mintAccountBalances) => {
6224
- return mintAccountBalances.reduce((acc, curr) => {
6225
- return acc + BigInt(curr.balance);
6226
- }, BigInt(0));
6227
- };
6228
-
6229
- // src/sparks/sparks-contracts.ts
6230
- var import_protocol_deployments12 = require("@zoralabs/protocol-deployments");
6231
- var import_viem11 = require("viem");
6232
- var addressOrAccountAddress = (address) => typeof address === "string" ? address : address.address;
6233
- var mintWithEthParams = ({
6234
- tokenId,
6235
- quantity,
6236
- recipient,
6237
- chainId,
6238
- pricePerMint,
6239
- account
6240
- }) => makeContractParameters({
6241
- abi: import_protocol_deployments12.zoraSparksManagerImplABI,
6242
- address: import_protocol_deployments12.zoraSparksManagerImplAddress[chainId],
6243
- functionName: "mintWithEth",
6244
- args: [tokenId, quantity, recipient || addressOrAccountAddress(account)],
6245
- value: pricePerMint * quantity,
6246
- account
6247
- });
6248
- var getPaidMintValue = (quantities, pricePerMint) => {
6249
- if (!pricePerMint || pricePerMint === 0n)
6250
- return;
6251
- return quantities.reduce((a, b) => a + b, 0n) * pricePerMint;
6252
6261
  };
6253
- var mintsBalanceOfAccountParams = ({
6254
- account,
6255
- chainId
6256
- }) => ({
6257
- abi: import_protocol_deployments12.zoraMints1155Config.abi,
6258
- address: import_protocol_deployments12.zoraMints1155Config.address[chainId],
6259
- functionName: "balanceOfAccount",
6260
- args: [account]
6261
- });
6262
- var encodeCollectOnManager = ({
6263
- zoraCreator1155Contract,
6264
- minter,
6265
- zoraCreator1155TokenId,
6266
- mintArguments
6267
- }) => (0, import_viem11.encodeFunctionData)({
6268
- abi: import_protocol_deployments12.zoraMintsManagerImplConfig.abi,
6269
- functionName: "collect",
6270
- args: [
6271
- zoraCreator1155Contract,
6272
- minter,
6273
- zoraCreator1155TokenId,
6274
- mintArguments
6275
- ]
6276
- });
6277
- function collectWithMintsParams({
6278
- tokenIds,
6279
- quantities,
6280
- chainId,
6281
- paidMintPricePerToken,
6282
- account,
6283
- mintArguments,
6284
- minter,
6285
- zoraCreator1155Contract,
6286
- zoraCreator1155TokenId
6287
- }) {
6288
- const call = encodeCollectOnManager({
6289
- tokenIds,
6290
- quantities,
6291
- zoraCreator1155Contract,
6292
- zoraCreator1155TokenId,
6293
- minter,
6294
- mintArguments
6295
- });
6296
- return makeContractParameters({
6297
- abi: import_protocol_deployments12.zoraMints1155Config.abi,
6298
- address: import_protocol_deployments12.zoraMints1155Config.address[chainId],
6299
- functionName: "transferBatchToManagerAndCall",
6300
- args: [tokenIds, quantities, call],
6301
- // if it is a paid mint, the aadditional value will be sent to the manager contract and forwarded to the creator 1155 contract
6302
- // for the paid mint cost.
6303
- value: getPaidMintValue(quantities, paidMintPricePerToken),
6304
- account
6305
- });
6262
+ function parseCIDtoBytes(source, base3) {
6263
+ switch (source[0]) {
6264
+ case "Q": {
6265
+ const decoder = base3 ?? base58btc;
6266
+ return [
6267
+ base58btc.prefix,
6268
+ decoder.decode(`${base58btc.prefix}${source}`)
6269
+ ];
6270
+ }
6271
+ case base58btc.prefix: {
6272
+ const decoder = base3 ?? base58btc;
6273
+ return [base58btc.prefix, decoder.decode(source)];
6274
+ }
6275
+ case base32.prefix: {
6276
+ const decoder = base3 ?? base32;
6277
+ return [base32.prefix, decoder.decode(source)];
6278
+ }
6279
+ default: {
6280
+ if (base3 == null) {
6281
+ throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");
6282
+ }
6283
+ return [source[0], base3.decode(source)];
6284
+ }
6285
+ }
6306
6286
  }
6307
- function getMintsEthPrice({
6308
- publicClient
6309
- }) {
6310
- const chainId = publicClient.chain?.id;
6311
- if (!chainId || !import_protocol_deployments12.zoraMintsManagerImplAddress[chainId]) {
6312
- throw new Error(`Chain id ${chainId} not supported`);
6287
+ function toStringV0(bytes, cache2, base3) {
6288
+ const { prefix } = base3;
6289
+ if (prefix !== base58btc.prefix) {
6290
+ throw Error(`Cannot string encode V0 in ${base3.name} encoding`);
6291
+ }
6292
+ const cid = cache2.get(prefix);
6293
+ if (cid == null) {
6294
+ const cid2 = base3.encode(bytes).slice(1);
6295
+ cache2.set(prefix, cid2);
6296
+ return cid2;
6297
+ } else {
6298
+ return cid;
6313
6299
  }
6314
- return publicClient.readContract({
6315
- abi: import_protocol_deployments12.zoraMintsManagerImplABI,
6316
- address: import_protocol_deployments12.zoraMintsManagerImplAddress[chainId],
6317
- functionName: "getEthPrice"
6318
- });
6319
6300
  }
6320
- function makePermitTransferBatchAndTypeData({
6321
- tokenIds,
6322
- quantities,
6323
- chainId,
6324
- mintsOwner,
6325
- to,
6326
- nonce,
6327
- deadline,
6328
- safeTransferData
6329
- }) {
6330
- const permit = {
6331
- owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
6332
- to,
6333
- tokenIds,
6334
- quantities,
6335
- deadline,
6336
- nonce,
6337
- safeTransferData
6338
- };
6339
- const typedData = {
6340
- ...(0, import_protocol_deployments12.mintsSafeTransferBatchTypedDataDefinition)({
6341
- chainId,
6342
- message: permit
6343
- }),
6344
- account: mintsOwner
6345
- };
6346
- return {
6347
- permit,
6348
- typedData
6349
- };
6301
+ function toStringV1(bytes, cache2, base3) {
6302
+ const { prefix } = base3;
6303
+ const cid = cache2.get(prefix);
6304
+ if (cid == null) {
6305
+ const cid2 = base3.encode(bytes);
6306
+ cache2.set(prefix, cid2);
6307
+ return cid2;
6308
+ } else {
6309
+ return cid;
6310
+ }
6350
6311
  }
6351
- function makePermitTransferTypeData({
6352
- tokenId,
6353
- quantity,
6354
- chainId,
6355
- mintsOwner,
6356
- to,
6357
- nonce,
6358
- deadline,
6359
- safeTransferData
6360
- }) {
6361
- const permit = {
6362
- owner: typeof mintsOwner === "string" ? mintsOwner : mintsOwner.address,
6363
- to,
6364
- tokenId,
6365
- quantity,
6366
- deadline,
6367
- nonce,
6368
- safeTransferData
6369
- };
6370
- const typedData = {
6371
- ...(0, import_protocol_deployments12.mintsSafeTransferTypedDataDefinition)({
6372
- chainId,
6373
- message: permit
6374
- }),
6375
- account: mintsOwner
6376
- };
6377
- return {
6378
- permit,
6379
- typedData
6380
- };
6312
+ var DAG_PB_CODE = 112;
6313
+ var SHA_256_CODE = 18;
6314
+ function encodeCID(version, code, multihash) {
6315
+ const codeOffset = encodingLength(version);
6316
+ const hashOffset = codeOffset + encodingLength(code);
6317
+ const bytes = new Uint8Array(hashOffset + multihash.byteLength);
6318
+ encodeTo(version, bytes, 0);
6319
+ encodeTo(code, bytes, codeOffset);
6320
+ bytes.set(multihash, hashOffset);
6321
+ return bytes;
6381
6322
  }
6382
- var encodePremintOnManager = ({
6383
- contractCreationConfig,
6384
- premintConfig,
6385
- premintSignature,
6386
- mintArguments,
6387
- signerContract = import_viem11.zeroAddress
6388
- }) => (0, import_viem11.encodeFunctionData)({
6389
- abi: import_protocol_deployments12.zoraMintsManagerImplConfig.abi,
6390
- functionName: "collectPremintV2",
6391
- args: [
6392
- contractCreationConfig,
6393
- premintConfig,
6394
- premintSignature,
6395
- mintArguments,
6396
- signerContract
6397
- ]
6398
- });
6399
- var makePermitToCollectPremintOrNonPremint = ({
6400
- mintsOwner,
6401
- chainId,
6402
- deadline,
6403
- tokenIds,
6404
- // this quantity of MINTs will be used to collect premint
6405
- // and will be burned. This same quantity is the quantity of
6406
- // premint to collect.
6407
- quantities,
6408
- nonce,
6409
- premint,
6410
- collect
6411
- }) => {
6412
- let safeTransferData;
6413
- if (premint) {
6414
- safeTransferData = encodePremintOnManager(premint);
6415
- } else if (collect) {
6416
- safeTransferData = encodeCollectOnManager(collect);
6417
- } else {
6418
- throw new Error("Invalid operation");
6323
+ var cidSymbol = Symbol.for("@ipld/js-cid/CID");
6324
+
6325
+ // src/ipfs/ipfs.ts
6326
+ function isCID(str) {
6327
+ if (!str)
6328
+ return false;
6329
+ try {
6330
+ CID.parse(str);
6331
+ return true;
6332
+ } catch (e) {
6333
+ if (/^(bafy|Qm)/.test(str))
6334
+ return true;
6335
+ return false;
6336
+ }
6337
+ }
6338
+ function normalizeIPFSUrl(url) {
6339
+ if (!url || typeof url !== "string")
6340
+ return null;
6341
+ url = url.replace(/"/g, "");
6342
+ if (isNormalizedIPFSURL(url))
6343
+ return url;
6344
+ if (isCID(url))
6345
+ return `ipfs://${url}`;
6346
+ if (!isIPFSUrl(url))
6347
+ return null;
6348
+ if (isGatewayIPFSUrl(url)) {
6349
+ const parsed = new URL(url.replace(/^\/\//, "http://"));
6350
+ parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
6351
+ const cid = parsed.toString().replace(`${parsed.protocol}//${parsed.host}/`, "");
6352
+ return `ipfs://${cid}`;
6353
+ }
6354
+ return null;
6355
+ }
6356
+ function isNormalizedIPFSURL(url) {
6357
+ return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
6358
+ }
6359
+ function isGatewayIPFSUrl(url) {
6360
+ if (url && typeof url === "string") {
6361
+ try {
6362
+ const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
6363
+ return !isNormalizedIPFSURL(url) && parsed && parsed.pathname.startsWith("/ipfs/");
6364
+ } catch {
6365
+ return false;
6366
+ }
6367
+ }
6368
+ return false;
6369
+ }
6370
+ function isIPFSUrl(url) {
6371
+ return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
6372
+ }
6373
+ function isNormalizeableIPFSUrl(url) {
6374
+ return url ? isIPFSUrl(url) || isCID(url) : false;
6375
+ }
6376
+
6377
+ // src/ipfs/gateway.ts
6378
+ var IPFS_GATEWAY = "https://magic.decentralized-content.com";
6379
+ var ARWEAVE_GATEWAY = "https://arweave.net";
6380
+ function arweaveGatewayUrl(normalizedArweaveUrl) {
6381
+ if (!normalizedArweaveUrl || typeof normalizedArweaveUrl !== "string")
6382
+ return null;
6383
+ return normalizedArweaveUrl.replace("ar://", `${ARWEAVE_GATEWAY}/`);
6384
+ }
6385
+ function ipfsGatewayUrl(url) {
6386
+ if (!url || typeof url !== "string")
6387
+ return null;
6388
+ const normalizedIPFSUrl = normalizeIPFSUrl(url);
6389
+ if (normalizedIPFSUrl) {
6390
+ return normalizedIPFSUrl.replace("ipfs://", `${IPFS_GATEWAY}/ipfs/`);
6419
6391
  }
6420
- return makePermitTransferBatchAndTypeData({
6421
- tokenIds,
6422
- quantities,
6423
- chainId,
6424
- mintsOwner,
6425
- nonce,
6426
- deadline,
6427
- safeTransferData,
6428
- to: import_protocol_deployments12.zoraMintsManagerImplConfig.address[chainId]
6429
- });
6392
+ return null;
6393
+ }
6394
+ function getFetchableUrl(uri) {
6395
+ if (!uri || typeof uri !== "string")
6396
+ return null;
6397
+ if (uri.startsWith("http://"))
6398
+ return null;
6399
+ if (isNormalizeableIPFSUrl(uri)) {
6400
+ return ipfsGatewayUrl(uri);
6401
+ }
6402
+ if (isArweaveURL(uri)) {
6403
+ return arweaveGatewayUrl(uri);
6404
+ }
6405
+ if (/^(https|data|blob):/.test(uri)) {
6406
+ return uri;
6407
+ }
6408
+ return null;
6409
+ }
6410
+
6411
+ // src/ipfs/mimeTypes.ts
6412
+ var HTML = "text/html";
6413
+ var MARKDOWN = "text/markdown";
6414
+ var MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
6415
+ var TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
6416
+ var TEXT_PLAIN = "text/plain";
6417
+ var CSV = "text/csv";
6418
+ var NUMBERS = ".numbers";
6419
+ var EXCEL = ".xlsx";
6420
+ var PDF = "application/pdf";
6421
+ var JPG = "image/jpg";
6422
+ var JPEG = "image/jpeg";
6423
+ var PNG = "image/png";
6424
+ var WEBP = "image/webp";
6425
+ var SVG = "image/svg+xml";
6426
+ var TIFF = "image/tiff";
6427
+ var GIF = "image/gif";
6428
+ var isImage = (mimeType) => {
6429
+ if (!mimeType)
6430
+ return false;
6431
+ return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
6430
6432
  };
6431
- function collectPremintV2WithMintsParams({
6432
- tokenIds,
6433
- quantities,
6434
- paidMintPricePerToken,
6435
- account,
6436
- chainId,
6437
- ...rest
6438
- }) {
6439
- const call = encodePremintOnManager({
6440
- ...rest
6441
- });
6442
- return makeContractParameters({
6443
- abi: import_protocol_deployments12.zoraMints1155Config.abi,
6444
- address: import_protocol_deployments12.zoraMints1155Config.address[chainId],
6445
- functionName: "transferBatchToManagerAndCall",
6446
- args: [tokenIds, quantities, call],
6447
- value: getPaidMintValue(quantities, paidMintPricePerToken),
6448
- account
6449
- });
6433
+ var DEFAULT_THUMBNAIL_CID_HASHES = {
6434
+ ["AUDIO" /* AUDIO */]: "bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
6435
+ ["VIDEO" /* VIDEO */]: "bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
6436
+ ["HTML" /* HTML */]: "bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
6437
+ ["ZIP" /* ZIP */]: "bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq",
6438
+ // assuming all zip files are html directories
6439
+ ["TEXT" /* TEXT */]: "bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
6440
+ default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4"
6441
+ };
6442
+ var MP4 = "video/mp4";
6443
+ var QUICKTIME = "video/quicktime";
6444
+ var M4V = "video/x-m4v";
6445
+ var WEBM = "video/webm";
6446
+ var M4A = "audio/x-m4a";
6447
+ var MPEG = "audio/mpeg";
6448
+ var MP3 = "audio/mp3";
6449
+ var WAV = "audio/wav";
6450
+ var VND_WAV = "audio/vnd.wav";
6451
+ var VND_WAVE = "audio/vnd.wave";
6452
+ var WAVE = "audio/wave";
6453
+ var X_WAV = "audio/x-wav";
6454
+ var AIFF = "audio/aiff";
6455
+ var GLTF = "model/gltf+json";
6456
+ var GLB = "model/gltf-binary";
6457
+ var GLTF_EXT = ".gltf";
6458
+ var GLB_EXT = ".glb";
6459
+ var JSON_MIME_TYPE = "application/json";
6460
+ var ZIP = "application/zip";
6461
+ var mimeToMediaType = {
6462
+ [HTML]: "HTML" /* HTML */,
6463
+ [JPG]: "IMAGE" /* IMAGE */,
6464
+ [JPEG]: "IMAGE" /* IMAGE */,
6465
+ [PNG]: "IMAGE" /* IMAGE */,
6466
+ [WEBP]: "IMAGE" /* IMAGE */,
6467
+ [SVG]: "IMAGE" /* IMAGE */,
6468
+ [TIFF]: "TIFF" /* TIFF */,
6469
+ [GIF]: "IMAGE" /* IMAGE */,
6470
+ [MP4]: "VIDEO" /* VIDEO */,
6471
+ [WEBM]: "VIDEO" /* VIDEO */,
6472
+ [QUICKTIME]: "VIDEO" /* VIDEO */,
6473
+ [M4V]: "VIDEO" /* VIDEO */,
6474
+ [MPEG]: "AUDIO" /* AUDIO */,
6475
+ [MP3]: "AUDIO" /* AUDIO */,
6476
+ [M4A]: "AUDIO" /* AUDIO */,
6477
+ [VND_WAV]: "AUDIO" /* AUDIO */,
6478
+ [VND_WAVE]: "AUDIO" /* AUDIO */,
6479
+ [WAV]: "AUDIO" /* AUDIO */,
6480
+ [WAVE]: "AUDIO" /* AUDIO */,
6481
+ [X_WAV]: "AUDIO" /* AUDIO */,
6482
+ [AIFF]: "AUDIO" /* AUDIO */,
6483
+ [TEXT_PLAIN]: "TEXT" /* TEXT */,
6484
+ [TEXT_PLAIN_UTF8]: "TEXT" /* TEXT */,
6485
+ [MARKDOWN]: "TEXT" /* TEXT */,
6486
+ [MARKDOWN_UTF8]: "TEXT" /* TEXT */,
6487
+ [CSV]: "CSV" /* CSV */,
6488
+ [NUMBERS]: "NUMBERS" /* NUMBERS */,
6489
+ [EXCEL]: "EXCEL" /* EXCEL */,
6490
+ [PDF]: "PDF" /* PDF */,
6491
+ [ZIP]: "ZIP" /* ZIP */,
6492
+ [GLTF]: "MODEL" /* MODEL */,
6493
+ [GLTF_EXT]: "MODEL" /* MODEL */,
6494
+ [GLB]: "MODEL" /* MODEL */,
6495
+ // GLTF returns 'application/json' as the mimetype,
6496
+ // and as the only JSON-encoded media we currently support,
6497
+ // we assume that if the mimetype is JSON, it's a GLTF
6498
+ [JSON_MIME_TYPE]: "MODEL" /* MODEL */,
6499
+ [GLB_EXT]: "MODEL" /* MODEL */
6500
+ };
6501
+ function mimeTypeToMedia(mimeType) {
6502
+ if (!mimeType)
6503
+ return "UNKNOWN" /* UNKNOWN */;
6504
+ return mimeToMediaType[mimeType] || "UNKNOWN" /* UNKNOWN */;
6450
6505
  }
6451
- function decodeCallFailedError(error) {
6452
- if (error.data?.errorName !== "CallFailed")
6453
- throw new Error("Not a CallFailed error");
6454
- const internalErrorData = error.data?.args?.[0];
6455
- return (0, import_viem11.decodeErrorResult)({
6456
- abi: import_protocol_deployments12.zoraMintsManagerImplABI,
6457
- data: internalErrorData
6458
- });
6506
+ async function getMimeType(uri) {
6507
+ if (!uri)
6508
+ return uri;
6509
+ const res = await fetch(uri, { method: "HEAD" });
6510
+ let mimeType = res.headers.get("content-type");
6511
+ return mimeType;
6459
6512
  }
6460
6513
 
6461
- // src/sdk.ts
6462
- function createCreatorClient(clientConfig) {
6463
- const premintClient = new PremintClient({
6464
- chainId: clientConfig.chainId,
6465
- publicClient: clientConfig.publicClient,
6466
- premintApi: clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId)
6467
- });
6468
- const create1155CreatorClient = new Create1155Client({
6469
- chainId: clientConfig.chainId,
6470
- publicClient: clientConfig.publicClient
6471
- });
6514
+ // src/ipfs/token-metadata.ts
6515
+ var makeTextTokenMetadata = (parameters) => {
6516
+ const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
6517
+ const content = textFileUrl ? {
6518
+ mime: TEXT_PLAIN,
6519
+ uri: textFileUrl
6520
+ } : null;
6521
+ const image = thumbnailUrl;
6522
+ const animation_url = textFileUrl;
6472
6523
  return {
6473
- createPremint: (p) => premintClient.createPremint(p),
6474
- updatePremint: (p) => premintClient.updatePremint(p),
6475
- deletePremint: (p) => premintClient.deletePremint(p),
6476
- create1155: (p) => create1155CreatorClient.createNew1155(p),
6477
- create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
6524
+ name,
6525
+ image,
6526
+ animation_url,
6527
+ content,
6528
+ attributes
6478
6529
  };
6479
- }
6480
- function createCollectorClient(params) {
6481
- const premintGetterToUse = params.premintGetter || new PremintAPIClient(params.chainId);
6482
- const mintGetterToUse = params.mintGetter || new SubgraphMintGetter(params.chainId);
6483
- const mintClient = new MintClient({
6484
- publicClient: params.publicClient,
6485
- premintGetter: premintGetterToUse,
6486
- mintGetter: mintGetterToUse
6487
- });
6530
+ };
6531
+ var makeMediaTokenMetadata = async ({
6532
+ name,
6533
+ description,
6534
+ attributes = [],
6535
+ mediaUrl,
6536
+ thumbnailUrl
6537
+ }) => {
6538
+ const contentUrl = mediaUrl;
6539
+ const fetchableContentUrl = getFetchableUrl(contentUrl);
6540
+ if (!fetchableContentUrl)
6541
+ throw new Error(`Content url (${contentUrl}) is not fetchable`);
6542
+ const mimeType = await getMimeType(fetchableContentUrl);
6543
+ const mediaType = mimeTypeToMedia(mimeType);
6544
+ let image = void 0;
6545
+ let animation_url = null;
6546
+ if (isImage(mimeType)) {
6547
+ image = contentUrl;
6548
+ } else {
6549
+ image = thumbnailUrl;
6550
+ animation_url = mediaUrl;
6551
+ }
6552
+ if (!image)
6553
+ image = `ipfs://${DEFAULT_THUMBNAIL_CID_HASHES[mediaType] || DEFAULT_THUMBNAIL_CID_HASHES.default}`;
6554
+ const content = contentUrl ? {
6555
+ mime: mimeType || "application/octet-stream",
6556
+ uri: contentUrl
6557
+ } : null;
6488
6558
  return {
6489
- getPremint: (p) => premintGetterToUse.get({
6490
- collectionAddress: p.address,
6491
- uid: p.uid
6492
- }),
6493
- getCollectDataFromPremintReceipt: (p) => getDataFromPremintReceipt(p, params.chainId),
6494
- getToken: (p) => mintClient.get(p),
6495
- getTokensOfContract: (p) => mintClient.getOfContract(p),
6496
- mint: (p) => mintClient.mint(p),
6497
- getMintCosts: (p) => mintClient.getMintCosts(p)
6559
+ name,
6560
+ description,
6561
+ image,
6562
+ animation_url,
6563
+ content,
6564
+ attributes
6498
6565
  };
6499
- }
6566
+ };
6500
6567
 
6501
6568
  // src/ipfs/text-metadata.ts
6502
6569
  var CHAR_LIMIT = 1111;