@zoralabs/protocol-sdk 0.7.6 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4102,49 +4102,51 @@ function new1155ContractVersion(chainId) {
4102
4102
  }
4103
4103
  return address.CONTRACT_1155_IMPL_VERSION;
4104
4104
  }
4105
- async function getContractInfo({
4105
+ async function getContractInfoExistingContract({
4106
4106
  publicClient,
4107
- chainId,
4108
- contract,
4109
- account
4107
+ contractAddress
4110
4108
  }) {
4111
- const contractAddress = typeof contract === "string" ? contract : await publicClient.readContract({
4112
- abi: zoraCreator1155FactoryImplABI,
4113
- // Since this address is deterministic we can hardcode a chain id safely here.
4114
- address: zoraCreator1155FactoryImplAddress[chainId],
4115
- functionName: "deterministicContractAddress",
4116
- args: [
4117
- account,
4118
- contract.uri,
4119
- contract.name,
4120
- contract.defaultAdmin || account
4121
- ]
4122
- });
4123
4109
  let contractVersion;
4124
- let contractExists;
4125
4110
  try {
4126
4111
  contractVersion = await publicClient.readContract({
4127
4112
  abi: zoraCreator1155ImplABI3,
4128
4113
  address: contractAddress,
4129
4114
  functionName: "contractVersion"
4130
4115
  });
4131
- contractExists = true;
4132
4116
  } catch (e) {
4133
- contractVersion = new1155ContractVersion(chainId);
4134
- contractExists = false;
4117
+ throw new Error(`Contract does not exist at ${contractAddress}`);
4135
4118
  }
4136
- const nextTokenId = contractExists ? await publicClient.readContract({
4119
+ const nextTokenId = await publicClient.readContract({
4137
4120
  address: contractAddress,
4138
4121
  abi: zoraCreator1155ImplABI3,
4139
4122
  functionName: "nextTokenId"
4140
- }) : 1n;
4123
+ });
4141
4124
  return {
4142
- contractExists,
4143
- contractAddress,
4144
4125
  contractVersion,
4145
4126
  nextTokenId
4146
4127
  };
4147
4128
  }
4129
+ async function getDeterministicContractAddress({
4130
+ publicClient,
4131
+ account,
4132
+ setupActions,
4133
+ contract,
4134
+ chainId
4135
+ }) {
4136
+ const contractAddress = await publicClient.readContract({
4137
+ abi: zoraCreator1155FactoryImplABI,
4138
+ address: zoraCreator1155FactoryImplAddress[chainId],
4139
+ functionName: "deterministicContractAddressWithSetupActions",
4140
+ args: [
4141
+ account,
4142
+ contract.uri,
4143
+ contract.name,
4144
+ contract.defaultAdmin || account,
4145
+ setupActions
4146
+ ]
4147
+ });
4148
+ return contractAddress;
4149
+ }
4148
4150
 
4149
4151
  // src/create/token-setup.ts
4150
4152
  var semver3 = __toESM(require_semver2(), 1);
@@ -4432,43 +4434,61 @@ var getTokenIdFromCreateReceipt = (receipt) => {
4432
4434
  } catch (err) {
4433
4435
  }
4434
4436
  }
4437
+ throw new Error(
4438
+ "No event found in receipt that could be used to get tokenId"
4439
+ );
4440
+ };
4441
+ var getContractAddressFromReceipt = (receipt) => {
4442
+ for (const data of receipt.logs) {
4443
+ try {
4444
+ const decodedLog = decodeEventLog2({
4445
+ abi: zoraCreator1155FactoryImplABI2,
4446
+ eventName: "SetupNewContract",
4447
+ ...data
4448
+ });
4449
+ if (decodedLog && decodedLog.eventName === "SetupNewContract") {
4450
+ return decodedLog.args.newContract;
4451
+ }
4452
+ } catch (err) {
4453
+ }
4454
+ }
4455
+ throw new Error(
4456
+ "No event found in receipt that could be used to get contract address"
4457
+ );
4435
4458
  };
4436
4459
  function makeCreateContractAndTokenCall({
4437
- contractExists,
4438
- contractAddress,
4439
- contract,
4440
4460
  account,
4461
+ contract,
4441
4462
  royaltyBPS,
4463
+ fundsRecipient,
4442
4464
  tokenSetupActions,
4443
- fundsRecipient
4465
+ chainId
4466
+ }) {
4467
+ const accountAddress = typeof account === "string" ? account : account.address;
4468
+ return makeContractParameters({
4469
+ abi: zoraCreator1155FactoryImplABI2,
4470
+ functionName: "createContractDeterministic",
4471
+ account,
4472
+ address: zoraCreator1155FactoryImplAddress2[chainId],
4473
+ args: [
4474
+ contract.uri,
4475
+ contract.name,
4476
+ {
4477
+ // deprecated
4478
+ royaltyMintSchedule: 0,
4479
+ royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
4480
+ royaltyRecipient: fundsRecipient || accountAddress
4481
+ },
4482
+ contract.defaultAdmin || accountAddress,
4483
+ tokenSetupActions
4484
+ ]
4485
+ });
4486
+ }
4487
+ function makeCreateTokenCall({
4488
+ contractAddress,
4489
+ account,
4490
+ tokenSetupActions
4444
4491
  }) {
4445
- if (!contractAddress && typeof contract === "string") {
4446
- throw new Error("Invariant: contract cannot be missing and an address");
4447
- }
4448
- if (!contractExists) {
4449
- if (typeof contract === "string") {
4450
- throw new Error("Invariant: expected contract object");
4451
- }
4452
- const accountAddress = typeof account === "string" ? account : account.address;
4453
- return makeContractParameters({
4454
- abi: zoraCreator1155FactoryImplABI2,
4455
- functionName: "createContractDeterministic",
4456
- account,
4457
- address: zoraCreator1155FactoryImplAddress2[999],
4458
- args: [
4459
- contract.uri,
4460
- contract.name,
4461
- {
4462
- // deprecated
4463
- royaltyMintSchedule: 0,
4464
- royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
4465
- royaltyRecipient: fundsRecipient || accountAddress
4466
- },
4467
- contract.defaultAdmin || accountAddress,
4468
- tokenSetupActions
4469
- ]
4470
- });
4471
- }
4472
4492
  return makeContractParameters({
4473
4493
  abi: zoraCreator1155ImplABI5,
4474
4494
  functionName: "multicall",
@@ -4485,65 +4505,141 @@ var Create1155Client = class {
4485
4505
  this.chainId = chainId;
4486
4506
  this.publicClient = publicClient;
4487
4507
  }
4488
- async createNew1155Token(props) {
4489
- return createNew1155Token({
4508
+ async createNew1155(props) {
4509
+ return createNew1155ContractAndToken({
4490
4510
  ...props,
4491
4511
  publicClient: this.publicClient,
4492
4512
  chainId: this.chainId
4493
4513
  });
4494
4514
  }
4515
+ async createNew1155OnExistingContract({
4516
+ contractAddress: contract,
4517
+ account,
4518
+ token,
4519
+ getAdditionalSetupActions
4520
+ }) {
4521
+ return createNew1155Token({
4522
+ contractAddress: contract,
4523
+ account,
4524
+ token,
4525
+ getAdditionalSetupActions,
4526
+ publicClient: this.publicClient,
4527
+ chainId: this.chainId
4528
+ });
4529
+ }
4495
4530
  };
4496
- async function createNew1155Token({
4531
+ async function createNew1155ContractAndToken({
4497
4532
  contract,
4498
4533
  account,
4534
+ chainId,
4535
+ token,
4536
+ publicClient,
4537
+ getAdditionalSetupActions
4538
+ }) {
4539
+ const nextTokenId = 1n;
4540
+ const contractVersion = new1155ContractVersion(chainId);
4541
+ const {
4542
+ minter,
4543
+ newToken,
4544
+ setupActions: tokenSetupActions
4545
+ } = prepareSetupActions({
4546
+ chainId,
4547
+ account,
4548
+ contractVersion,
4549
+ nextTokenId,
4550
+ token,
4551
+ getAdditionalSetupActions
4552
+ });
4553
+ const request = makeCreateContractAndTokenCall({
4554
+ contract,
4555
+ account,
4556
+ chainId,
4557
+ tokenSetupActions,
4558
+ fundsRecipient: token.payoutRecipient,
4559
+ royaltyBPS: token.royaltyBPS
4560
+ });
4561
+ const contractAddress = await getDeterministicContractAddress({
4562
+ account,
4563
+ publicClient,
4564
+ setupActions: tokenSetupActions,
4565
+ chainId,
4566
+ contract
4567
+ });
4568
+ return {
4569
+ parameters: request,
4570
+ tokenSetupActions,
4571
+ newTokenId: nextTokenId,
4572
+ newToken,
4573
+ contractAddress,
4574
+ contractVersion,
4575
+ minter
4576
+ };
4577
+ }
4578
+ async function createNew1155Token({
4579
+ contractAddress,
4580
+ account,
4499
4581
  getAdditionalSetupActions,
4500
- token: tokenConfig,
4582
+ token,
4501
4583
  publicClient,
4502
4584
  chainId
4503
4585
  }) {
4504
- const { contractExists, contractAddress, nextTokenId, contractVersion } = await getContractInfo({
4586
+ const { nextTokenId, contractVersion } = await getContractInfoExistingContract({
4505
4587
  publicClient,
4506
- chainId,
4507
- contract,
4508
- account
4588
+ contractAddress
4509
4589
  });
4510
4590
  const {
4511
4591
  minter,
4512
4592
  newToken,
4513
4593
  setupActions: tokenSetupActions
4514
- } = constructCreate1155TokenCalls({
4594
+ } = prepareSetupActions({
4515
4595
  chainId,
4516
- ownerAddress: account,
4596
+ account,
4517
4597
  contractVersion,
4518
4598
  nextTokenId,
4519
- ...tokenConfig
4599
+ token,
4600
+ getAdditionalSetupActions
4520
4601
  });
4521
- const setupActions = getAdditionalSetupActions ? [
4522
- ...getAdditionalSetupActions({
4523
- tokenId: nextTokenId,
4524
- contractAddress
4525
- }),
4526
- ...tokenSetupActions
4527
- ] : tokenSetupActions;
4528
- const request = makeCreateContractAndTokenCall({
4529
- contractExists,
4602
+ const request = makeCreateTokenCall({
4530
4603
  contractAddress,
4531
- contract,
4532
4604
  account,
4533
- tokenSetupActions: setupActions,
4534
- royaltyBPS: tokenConfig.royaltyBPS,
4535
- fundsRecipient: tokenConfig.payoutRecipient
4605
+ tokenSetupActions
4536
4606
  });
4537
4607
  return {
4538
4608
  parameters: request,
4539
4609
  tokenSetupActions,
4540
- collectionAddress: contractAddress,
4541
- contractExists,
4542
4610
  newTokenId: nextTokenId,
4543
4611
  newToken,
4612
+ contractVersion,
4544
4613
  minter
4545
4614
  };
4546
4615
  }
4616
+ function prepareSetupActions({
4617
+ chainId,
4618
+ account,
4619
+ contractVersion,
4620
+ nextTokenId,
4621
+ token,
4622
+ getAdditionalSetupActions
4623
+ }) {
4624
+ const {
4625
+ minter,
4626
+ newToken,
4627
+ setupActions: tokenSetupActions
4628
+ } = constructCreate1155TokenCalls({
4629
+ chainId,
4630
+ ownerAddress: account,
4631
+ contractVersion,
4632
+ nextTokenId,
4633
+ ...token
4634
+ });
4635
+ const setupActions = getAdditionalSetupActions ? [
4636
+ ...getAdditionalSetupActions({
4637
+ tokenId: nextTokenId
4638
+ }),
4639
+ ...tokenSetupActions
4640
+ ] : tokenSetupActions;
4641
+ return { minter, newToken, setupActions };
4642
+ }
4547
4643
 
4548
4644
  // src/sparks/mints-queries.ts
4549
4645
  var getMintsAccountBalanceWithPriceQuery = (account) => {
@@ -4861,7 +4957,8 @@ function createCreatorClient(clientConfig) {
4861
4957
  createPremint: (p) => premintClient.createPremint(p),
4862
4958
  updatePremint: (p) => premintClient.updatePremint(p),
4863
4959
  deletePremint: (p) => premintClient.deletePremint(p),
4864
- create1155: (p) => create1155CreatorClient.createNew1155Token(p)
4960
+ create1155: (p) => create1155CreatorClient.createNew1155(p),
4961
+ create1155OnExistingContract: (p) => create1155CreatorClient.createNew1155OnExistingContract(p)
4865
4962
  };
4866
4963
  }
4867
4964
  function createCollectorClient(params) {
@@ -6107,6 +6204,7 @@ export {
6107
6204
  encodePremintForAPI,
6108
6205
  generateTextNftMetadataFiles,
6109
6206
  getApiNetworkConfigForChain,
6207
+ getContractAddressFromReceipt,
6110
6208
  getDataFromPremintReceipt,
6111
6209
  getDefaultFixedPriceMinterAddress,
6112
6210
  getMintsAccountBalanceWithPriceQuery,
@@ -6124,6 +6222,7 @@ export {
6124
6222
  isPremintConfigV1,
6125
6223
  isPremintConfigV2,
6126
6224
  isValidSignature,
6225
+ makeCreateContractAndTokenCall,
6127
6226
  makeMediaTokenMetadata,
6128
6227
  makeMintRewardsRecipient,
6129
6228
  makeNewPremint,