@zoralabs/protocol-sdk 0.7.5 → 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/sdk.d.ts CHANGED
@@ -8,7 +8,8 @@ export type CreatorClient = {
8
8
  createPremint: PremintClient["createPremint"];
9
9
  updatePremint: PremintClient["updatePremint"];
10
10
  deletePremint: PremintClient["deletePremint"];
11
- create1155: Create1155Client["createNew1155Token"];
11
+ create1155: Create1155Client["createNew1155"];
12
+ create1155OnExistingContract: Create1155Client["createNew1155OnExistingContract"];
12
13
  };
13
14
  export type CollectorClient = {
14
15
  getPremint: PremintClient["getPremint"];
package/dist/sdk.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAoB,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,UAAU,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACxC,gCAAgC,EAAE,aAAa,CAAC,2BAA2B,CAAC,CAAC;IAC7E,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,YAAY,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;IACzC,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,mBAAmB,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG;IAC/C,iFAAiF;IACjF,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF;;;;;KAKK;AACL,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,mBAAmB,GAChC,aAAa,CAmBf;AAED,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAAG;IACjD,kEAAkE;IAClE,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,GAC5B,eAAe,CAwBjB"}
1
+ {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,WAAW,EAAoB,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,UAAU,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC9C,4BAA4B,EAAE,gBAAgB,CAAC,iCAAiC,CAAC,CAAC;CACnF,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACxC,gCAAgC,EAAE,aAAa,CAAC,2BAA2B,CAAC,CAAC;IAC7E,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACzB,YAAY,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;IACzC,QAAQ,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,mBAAmB,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG;IAC/C,iFAAiF;IACjF,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF;;;;;KAKK;AACL,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,mBAAmB,GAChC,aAAa,CAqBf;AAED,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAAG;IACjD,kEAAkE;IAClE,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,GAC5B,eAAe,CAwBjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoralabs/protocol-sdk",
3
- "version": "0.7.5",
3
+ "version": "0.8.0",
4
4
  "repository": "https://github.com/ourzora/zora-protocol",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,13 +17,12 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "abitype": "^1.0.2",
20
- "@zoralabs/protocol-deployments": "^0.2.2"
20
+ "@zoralabs/protocol-deployments": "^0.3.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "viem": "^2.13.2"
24
24
  },
25
25
  "devDependencies": {
26
- "@fleekhq/fleek-storage-js": "^1.0.24",
27
26
  "@lavamoat/preinstall-always-fail": "2.0.0",
28
27
  "@reservoir0x/relay-sdk": "^0.3.8",
29
28
  "@reservoir0x/reservoir-sdk": "^2.0.11",
@@ -1,6 +1,8 @@
1
1
  import { describe, expect } from "vitest";
2
- import { getTokenIdFromCreateReceipt } from "./1155-create-helper";
3
- import { anvilTest } from "src/anvil";
2
+ import {
3
+ getContractAddressFromReceipt,
4
+ getTokenIdFromCreateReceipt,
5
+ } from "./1155-create-helper";
4
6
  import { createCreatorClient } from "src/sdk";
5
7
  import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
6
8
  import { waitForSuccess } from "src/test-utils";
@@ -9,10 +11,18 @@ import {
9
11
  MintableParameters,
10
12
  makePrepareMint1155TokenParams,
11
13
  } from "src/mint/mint-transactions";
14
+ import { forkUrls, makeAnvilTest } from "src/anvil";
15
+ import { zora } from "viem/chains";
12
16
 
13
17
  const demoTokenMetadataURI = "ipfs://DUMMY/token.json";
14
18
  const demoContractMetadataURI = "ipfs://DUMMY/contract.json";
15
19
 
20
+ const anvilTest = makeAnvilTest({
21
+ forkUrl: forkUrls.zoraMainnet,
22
+ forkBlockNumber: 18094820,
23
+ anvilChainId: zora.id,
24
+ });
25
+
16
26
  describe("create-helper", () => {
17
27
  anvilTest(
18
28
  "creates a new 1155 contract and token",
@@ -24,24 +34,27 @@ describe("create-helper", () => {
24
34
  chainId: chain.id,
25
35
  publicClient: publicClient,
26
36
  });
27
- const { parameters: request } = await creatorClient.create1155({
28
- contract: {
29
- name: "testContract",
30
- uri: demoContractMetadataURI,
31
- },
32
- token: {
33
- tokenMetadataURI: demoTokenMetadataURI,
34
- mintToCreatorCount: 1,
35
- },
36
- account: creatorAddress,
37
- });
38
- const { request: simulationResponse } =
39
- await publicClient.simulateContract(request);
40
- const hash = await walletClient.writeContract(simulationResponse);
37
+ const { parameters, contractAddress: collectionAddress } =
38
+ await creatorClient.create1155({
39
+ contract: {
40
+ name: "testContract",
41
+ uri: demoContractMetadataURI,
42
+ },
43
+ token: {
44
+ tokenMetadataURI: demoTokenMetadataURI,
45
+ mintToCreatorCount: 1,
46
+ },
47
+ account: creatorAddress,
48
+ });
49
+ const { request } = await publicClient.simulateContract(parameters);
50
+ const hash = await walletClient.writeContract(request);
41
51
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
42
52
  expect(receipt).not.toBeNull();
43
53
  expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
44
54
  expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(1n);
55
+ expect(getContractAddressFromReceipt(receipt)).to.be.equal(
56
+ collectionAddress,
57
+ );
45
58
  },
46
59
  20 * 1000,
47
60
  );
@@ -56,25 +69,18 @@ describe("create-helper", () => {
56
69
  publicClient: publicClient,
57
70
  });
58
71
 
59
- const {
60
- parameters: request,
61
- collectionAddress: contractAddress,
62
- contractExists,
63
- } = await creatorClient.create1155({
64
- contract: {
65
- name: "testContract2",
66
- uri: demoContractMetadataURI,
67
- },
68
- token: {
69
- tokenMetadataURI: demoTokenMetadataURI,
70
- mintToCreatorCount: 3,
71
- },
72
- account: creatorAccount,
73
- });
74
- expect(contractAddress).to.be.equal(
75
- "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
76
- );
77
- expect(contractExists).to.be.false;
72
+ const { parameters: request, contractAddress: contractAddress } =
73
+ await creatorClient.create1155({
74
+ contract: {
75
+ name: "testContract2",
76
+ uri: demoContractMetadataURI,
77
+ },
78
+ token: {
79
+ tokenMetadataURI: demoTokenMetadataURI,
80
+ mintToCreatorCount: 3,
81
+ },
82
+ account: creatorAccount,
83
+ });
78
84
  const { request: simulateResponse } =
79
85
  await publicClient.simulateContract(request);
80
86
  const hash = await walletClient.writeContract(simulateResponse);
@@ -93,21 +99,15 @@ describe("create-helper", () => {
93
99
  }),
94
100
  ).toBe(3n);
95
101
 
96
- const newTokenOnExistingContract = await creatorClient.create1155({
97
- contract: {
98
- name: "testContract2",
99
- uri: demoContractMetadataURI,
100
- },
101
- token: {
102
- tokenMetadataURI: demoTokenMetadataURI,
103
- mintToCreatorCount: 2,
104
- },
105
- account: creatorAccount,
106
- });
107
- expect(newTokenOnExistingContract.collectionAddress).to.be.equal(
108
- "0xb1A8928dF830C21eD682949Aa8A83C1C215194d3",
109
- );
110
- expect(newTokenOnExistingContract.contractExists).to.be.true;
102
+ const newTokenOnExistingContract =
103
+ await creatorClient.create1155OnExistingContract({
104
+ contractAddress: contractAddress,
105
+ token: {
106
+ tokenMetadataURI: demoTokenMetadataURI,
107
+ mintToCreatorCount: 2,
108
+ },
109
+ account: creatorAccount,
110
+ });
111
111
  const { request: simulateRequest } = await publicClient.simulateContract(
112
112
  newTokenOnExistingContract.parameters,
113
113
  );
@@ -132,7 +132,11 @@ describe("create-helper", () => {
132
132
  chainId: chain.id,
133
133
  publicClient: publicClient,
134
134
  });
135
- const { parameters: request } = await creatorClient.create1155({
135
+ const {
136
+ parameters: request,
137
+ contractAddress: collectionAddress,
138
+ newTokenId,
139
+ } = await creatorClient.create1155({
136
140
  contract: {
137
141
  name: "testContract",
138
142
  uri: demoContractMetadataURI,
@@ -148,15 +152,15 @@ describe("create-helper", () => {
148
152
  const hash = await walletClient.writeContract(simulationResponse);
149
153
  const receipt = await publicClient.waitForTransactionReceipt({ hash });
150
154
  expect(receipt).not.toBeNull();
151
- expect(receipt.to).to.equal("0xa72724cc3dcef210141a1b84c61824074151dc99");
152
- expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(2n);
155
+ expect(receipt.to).to.equal("0x777777c338d93e2c7adf08d102d45ca7cc4ed021");
156
+ expect(getTokenIdFromCreateReceipt(receipt)).to.be.equal(newTokenId);
153
157
 
154
158
  expect(
155
159
  await publicClient.readContract({
156
160
  abi: zoraCreator1155ImplABI,
157
- address: "0xa72724cc3dcef210141a1b84c61824074151dc99",
161
+ address: collectionAddress,
158
162
  functionName: "createReferrals",
159
- args: [2n],
163
+ args: [newTokenId],
160
164
  }),
161
165
  ).to.be.equal(createReferral);
162
166
  },
@@ -177,10 +181,11 @@ describe("create-helper", () => {
177
181
  });
178
182
  const {
179
183
  parameters: request,
180
- collectionAddress,
181
184
  newTokenId,
182
185
  newToken,
183
186
  minter,
187
+ contractAddress: collectionAddress,
188
+ contractVersion,
184
189
  } = await creatorClient.create1155({
185
190
  contract: {
186
191
  name: "testContract",
@@ -200,7 +205,7 @@ describe("create-helper", () => {
200
205
 
201
206
  const salesConfigAndTokenInfo: MintableParameters = {
202
207
  mintFeePerQuantity: parseEther("0.000777"),
203
- contractVersion: "2.8.0",
208
+ contractVersion,
204
209
  salesConfig: {
205
210
  saleType: "fixedPrice",
206
211
  address: minter,
@@ -257,10 +262,11 @@ describe("create-helper", () => {
257
262
 
258
263
  const {
259
264
  parameters: request,
260
- collectionAddress,
265
+ contractAddress: collectionAddress,
261
266
  newTokenId,
262
267
  newToken,
263
268
  minter,
269
+ contractVersion,
264
270
  } = await creatorClient.create1155({
265
271
  contract: {
266
272
  name: "testContract",
@@ -283,7 +289,7 @@ describe("create-helper", () => {
283
289
 
284
290
  const salesConfigAndTokenInfo: MintableParameters = {
285
291
  mintFeePerQuantity: parseEther("0.000777"),
286
- contractVersion: "2.8.0",
292
+ contractVersion,
287
293
  salesConfig: {
288
294
  saleType: "fixedPrice",
289
295
  address: minter,
@@ -8,13 +8,23 @@ import type {
8
8
  Address,
9
9
  Hex,
10
10
  PublicClient,
11
- SimulateContractParameters,
12
11
  TransactionReceipt,
13
12
  } from "viem";
14
13
  import { decodeEventLog } from "viem";
15
14
  import { makeContractParameters } from "src/utils";
16
- import { getContractInfo } from "./contract-setup";
17
- import { ContractType, CreateNew1155Params, New1155Token } from "./types";
15
+ import {
16
+ getContractInfoExistingContract,
17
+ getDeterministicContractAddress,
18
+ new1155ContractVersion,
19
+ } from "./contract-setup";
20
+ import {
21
+ CreateNew1155ContractAndTokenReturn,
22
+ CreateNew1155ContractParams,
23
+ CreateNew1155ParamsBase,
24
+ CreateNew1155TokenParams,
25
+ CreateNew1155TokenReturn,
26
+ NewContractParams,
27
+ } from "./types";
18
28
  import { constructCreate1155TokenCalls } from "./token-setup";
19
29
 
20
30
  // Default royalty bps
@@ -22,7 +32,7 @@ const ROYALTY_BPS_DEFAULT = 1000;
22
32
 
23
33
  export const getTokenIdFromCreateReceipt = (
24
34
  receipt: TransactionReceipt,
25
- ): bigint | undefined => {
35
+ ): bigint => {
26
36
  for (const data of receipt.logs) {
27
37
  try {
28
38
  const decodedLog = decodeEventLog({
@@ -35,73 +45,84 @@ export const getTokenIdFromCreateReceipt = (
35
45
  }
36
46
  } catch (err: any) {}
37
47
  }
48
+
49
+ throw new Error(
50
+ "No event found in receipt that could be used to get tokenId",
51
+ );
52
+ };
53
+
54
+ export const getContractAddressFromReceipt = (
55
+ receipt: TransactionReceipt,
56
+ ): Address => {
57
+ for (const data of receipt.logs) {
58
+ try {
59
+ const decodedLog = decodeEventLog({
60
+ abi: zoraCreator1155FactoryImplABI,
61
+ eventName: "SetupNewContract",
62
+ ...data,
63
+ });
64
+ if (decodedLog && decodedLog.eventName === "SetupNewContract") {
65
+ return decodedLog.args.newContract;
66
+ }
67
+ } catch (err: any) {}
68
+ }
69
+
70
+ throw new Error(
71
+ "No event found in receipt that could be used to get contract address",
72
+ );
38
73
  };
39
74
 
40
- type CreateNew1155TokenReturn = {
41
- parameters: SimulateContractParameters<
42
- any,
43
- any,
44
- any,
45
- any,
46
- any,
47
- Account | Address
48
- >;
75
+ type MakeContractParametersBase = {
76
+ account: Address | Account;
77
+
49
78
  tokenSetupActions: Hex[];
50
- collectionAddress: Address;
51
- newTokenId: bigint;
52
- newToken: New1155Token;
53
- minter: Address;
54
- contractExists: boolean;
55
79
  };
56
80
 
57
- function makeCreateContractAndTokenCall({
58
- contractExists,
59
- contractAddress,
60
- contract,
81
+ export function makeCreateContractAndTokenCall({
61
82
  account,
83
+ contract,
62
84
  royaltyBPS,
63
- tokenSetupActions,
64
85
  fundsRecipient,
86
+ tokenSetupActions,
87
+ chainId,
65
88
  }: {
66
- contractExists: boolean;
67
- contractAddress: Address;
68
- contract: ContractType;
69
- account: Address | Account;
89
+ chainId: number;
90
+ contract: NewContractParams;
70
91
  royaltyBPS?: number;
71
92
  fundsRecipient?: Address;
72
- tokenSetupActions: Hex[];
73
- }) {
74
- if (!contractAddress && typeof contract === "string") {
75
- throw new Error("Invariant: contract cannot be missing and an address");
76
- }
77
-
78
- if (!contractExists) {
79
- if (typeof contract === "string") {
80
- throw new Error("Invariant: expected contract object");
81
- }
82
-
83
- const accountAddress =
84
- typeof account === "string" ? account : account.address;
85
- return makeContractParameters({
86
- abi: zoraCreator1155FactoryImplABI,
87
- functionName: "createContractDeterministic",
88
- account,
89
- address: zoraCreator1155FactoryImplAddress[999],
90
- args: [
91
- contract.uri,
92
- contract.name,
93
- {
94
- // deprecated
95
- royaltyMintSchedule: 0,
96
- royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
97
- royaltyRecipient: fundsRecipient || accountAddress,
98
- },
99
- contract.defaultAdmin || accountAddress,
100
- tokenSetupActions,
93
+ } & MakeContractParametersBase) {
94
+ const accountAddress =
95
+ typeof account === "string" ? account : account.address;
96
+ return makeContractParameters({
97
+ abi: zoraCreator1155FactoryImplABI,
98
+ functionName: "createContractDeterministic",
99
+ account,
100
+ address:
101
+ zoraCreator1155FactoryImplAddress[
102
+ chainId as keyof typeof zoraCreator1155FactoryImplAddress
101
103
  ],
102
- });
103
- }
104
+ args: [
105
+ contract.uri,
106
+ contract.name,
107
+ {
108
+ // deprecated
109
+ royaltyMintSchedule: 0,
110
+ royaltyBPS: royaltyBPS || ROYALTY_BPS_DEFAULT,
111
+ royaltyRecipient: fundsRecipient || accountAddress,
112
+ },
113
+ contract.defaultAdmin || accountAddress,
114
+ tokenSetupActions,
115
+ ],
116
+ });
117
+ }
104
118
 
119
+ function makeCreateTokenCall({
120
+ contractAddress,
121
+ account,
122
+ tokenSetupActions,
123
+ }: {
124
+ contractAddress: Address;
125
+ } & MakeContractParametersBase) {
105
126
  return makeContractParameters({
106
127
  abi: zoraCreator1155ImplABI,
107
128
  functionName: "multicall",
@@ -126,34 +147,146 @@ export class Create1155Client {
126
147
  this.publicClient = publicClient;
127
148
  }
128
149
 
129
- async createNew1155Token(props: CreateNew1155Params) {
130
- return createNew1155Token({
150
+ async createNew1155(
151
+ props: CreateNew1155ContractParams,
152
+ ): Promise<CreateNew1155ContractAndTokenReturn> {
153
+ return createNew1155ContractAndToken({
131
154
  ...props,
132
155
  publicClient: this.publicClient,
133
156
  chainId: this.chainId,
134
157
  });
135
158
  }
159
+
160
+ async createNew1155OnExistingContract({
161
+ contractAddress: contract,
162
+ account,
163
+ token,
164
+ getAdditionalSetupActions,
165
+ }: CreateNew1155TokenParams): Promise<CreateNew1155TokenReturn> {
166
+ return createNew1155Token({
167
+ contractAddress: contract,
168
+ account,
169
+ token,
170
+ getAdditionalSetupActions,
171
+ publicClient: this.publicClient,
172
+ chainId: this.chainId,
173
+ });
174
+ }
136
175
  }
137
176
 
138
- async function createNew1155Token({
177
+ async function createNew1155ContractAndToken({
139
178
  contract,
140
179
  account,
180
+ chainId,
181
+ token,
182
+ publicClient,
183
+ getAdditionalSetupActions,
184
+ }: CreateNew1155ContractParams & {
185
+ publicClient: Pick<PublicClient, "readContract">;
186
+ chainId: number;
187
+ }): Promise<CreateNew1155ContractAndTokenReturn> {
188
+ const nextTokenId = 1n;
189
+ const contractVersion = new1155ContractVersion(chainId);
190
+
191
+ const {
192
+ minter,
193
+ newToken,
194
+ setupActions: tokenSetupActions,
195
+ } = prepareSetupActions({
196
+ chainId,
197
+ account,
198
+ contractVersion,
199
+ nextTokenId,
200
+ token,
201
+ getAdditionalSetupActions,
202
+ });
203
+
204
+ const request = makeCreateContractAndTokenCall({
205
+ contract,
206
+ account,
207
+ chainId,
208
+ tokenSetupActions,
209
+ fundsRecipient: token.payoutRecipient,
210
+ royaltyBPS: token.royaltyBPS,
211
+ });
212
+
213
+ const contractAddress = await getDeterministicContractAddress({
214
+ account,
215
+ publicClient,
216
+ setupActions: tokenSetupActions,
217
+ chainId,
218
+ contract,
219
+ });
220
+
221
+ return {
222
+ parameters: request,
223
+ tokenSetupActions,
224
+ newTokenId: nextTokenId,
225
+ newToken,
226
+ contractAddress: contractAddress,
227
+ contractVersion,
228
+ minter,
229
+ };
230
+ }
231
+
232
+ async function createNew1155Token({
233
+ contractAddress: contractAddress,
234
+ account,
141
235
  getAdditionalSetupActions,
142
- token: tokenConfig,
236
+ token,
143
237
  publicClient,
144
238
  chainId,
145
- }: CreateNew1155Params & {
239
+ }: CreateNew1155TokenParams & {
146
240
  publicClient: Pick<PublicClient, "readContract">;
147
241
  chainId: number;
148
242
  }): Promise<CreateNew1155TokenReturn> {
149
- const { contractExists, contractAddress, nextTokenId, contractVersion } =
150
- await getContractInfo({
243
+ const { nextTokenId, contractVersion } =
244
+ await getContractInfoExistingContract({
151
245
  publicClient,
152
- chainId: chainId,
153
- contract,
154
- account,
246
+ contractAddress: contractAddress,
155
247
  });
156
248
 
249
+ const {
250
+ minter,
251
+ newToken,
252
+ setupActions: tokenSetupActions,
253
+ } = prepareSetupActions({
254
+ chainId,
255
+ account,
256
+ contractVersion,
257
+ nextTokenId,
258
+ token,
259
+ getAdditionalSetupActions,
260
+ });
261
+
262
+ const request = makeCreateTokenCall({
263
+ contractAddress,
264
+ account,
265
+ tokenSetupActions,
266
+ });
267
+
268
+ return {
269
+ parameters: request,
270
+ tokenSetupActions,
271
+ newTokenId: nextTokenId,
272
+ newToken,
273
+ contractVersion,
274
+ minter,
275
+ };
276
+ }
277
+
278
+ function prepareSetupActions({
279
+ chainId,
280
+ account,
281
+ contractVersion,
282
+ nextTokenId,
283
+ token,
284
+ getAdditionalSetupActions,
285
+ }: {
286
+ chainId: number;
287
+ contractVersion: string;
288
+ nextTokenId: bigint;
289
+ } & CreateNew1155ParamsBase) {
157
290
  const {
158
291
  minter,
159
292
  newToken,
@@ -163,36 +296,17 @@ async function createNew1155Token({
163
296
  ownerAddress: account,
164
297
  contractVersion,
165
298
  nextTokenId,
166
- ...tokenConfig,
299
+ ...token,
167
300
  });
168
301
 
169
302
  const setupActions = getAdditionalSetupActions
170
303
  ? [
171
304
  ...getAdditionalSetupActions({
172
305
  tokenId: nextTokenId,
173
- contractAddress,
174
306
  }),
175
307
  ...tokenSetupActions,
176
308
  ]
177
309
  : tokenSetupActions;
178
310
 
179
- const request = makeCreateContractAndTokenCall({
180
- contractExists,
181
- contractAddress,
182
- contract,
183
- account,
184
- tokenSetupActions: setupActions,
185
- royaltyBPS: tokenConfig.royaltyBPS,
186
- fundsRecipient: tokenConfig.payoutRecipient,
187
- });
188
-
189
- return {
190
- parameters: request,
191
- tokenSetupActions,
192
- collectionAddress: contractAddress,
193
- contractExists,
194
- newTokenId: nextTokenId,
195
- newToken,
196
- minter,
197
- };
311
+ return { minter, newToken, setupActions };
198
312
  }