@zoralabs/protocol-sdk 0.2.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/.turbo/turbo-build.log +15 -0
- package/CHANGELOG.md +47 -0
- package/README.md +163 -0
- package/dist/anvil.d.ts +16 -0
- package/dist/anvil.d.ts.map +1 -0
- package/dist/apis/chain-constants.d.ts +21 -0
- package/dist/apis/chain-constants.d.ts.map +1 -0
- package/dist/apis/client-base.d.ts +15 -0
- package/dist/apis/client-base.d.ts.map +1 -0
- package/dist/apis/generated/discover-api-types.d.ts +2131 -0
- package/dist/apis/generated/discover-api-types.d.ts.map +1 -0
- package/dist/apis/generated/premint-api-types.d.ts +356 -0
- package/dist/apis/generated/premint-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts +26 -0
- package/dist/apis/http-api-base.d.ts.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/create/1155-create-helper.d.ts +63 -0
- package/dist/create/1155-create-helper.d.ts.map +1 -0
- package/dist/create/1155-create-helper.test.d.ts +2 -0
- package/dist/create/1155-create-helper.test.d.ts.map +1 -0
- package/dist/index.cjs +1006 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +984 -0
- package/dist/index.js.map +1 -0
- package/dist/mint/mint-api-client.d.ts +20 -0
- package/dist/mint/mint-api-client.d.ts.map +1 -0
- package/dist/mint/mint-client.d.ts +237 -0
- package/dist/mint/mint-client.d.ts.map +1 -0
- package/dist/mint/mint-client.test.d.ts +2 -0
- package/dist/mint/mint-client.test.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +19 -0
- package/dist/premint/premint-api-client.d.ts.map +1 -0
- package/dist/premint/premint-client.d.ts +320 -0
- package/dist/premint/premint-client.d.ts.map +1 -0
- package/dist/premint/premint-client.test.d.ts +2 -0
- package/dist/premint/premint-client.test.d.ts.map +1 -0
- package/dist/premint/preminter.d.ts +25 -0
- package/dist/premint/preminter.d.ts.map +1 -0
- package/dist/premint/preminter.test.d.ts +2 -0
- package/dist/premint/preminter.test.d.ts.map +1 -0
- package/dist/preminter.d.ts +25 -0
- package/dist/preminter.d.ts.map +1 -0
- package/dist/preminter.test.d.ts +451 -0
- package/dist/preminter.test.d.ts.map +1 -0
- package/package.json +28 -0
- package/src/anvil.ts +84 -0
- package/src/apis/chain-constants.ts +101 -0
- package/src/apis/client-base.ts +29 -0
- package/src/apis/generated/discover-api-types.ts +2138 -0
- package/src/apis/generated/premint-api-types.ts +363 -0
- package/src/apis/http-api-base.ts +93 -0
- package/src/constants.ts +10 -0
- package/src/create/1155-create-helper.test.ts +90 -0
- package/src/create/1155-create-helper.ts +342 -0
- package/src/index.ts +9 -0
- package/src/mint/mint-api-client.ts +52 -0
- package/src/mint/mint-client.test.ts +117 -0
- package/src/mint/mint-client.ts +218 -0
- package/src/premint/premint-api-client.ts +57 -0
- package/src/premint/premint-client.test.ts +196 -0
- package/src/premint/premint-client.ts +619 -0
- package/src/premint/preminter.test.ts +502 -0
- package/src/premint/preminter.ts +72 -0
- package/src/preminter.test.ts +510 -0
- package/src/preminter.ts +72 -0
- package/tsconfig.json +25 -0
- package/tsup.config.js +10 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1006 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
DEFAULT_SALE_SETTINGS: () => DEFAULT_SALE_SETTINGS,
|
|
24
|
+
DefaultMintArguments: () => DefaultMintArguments,
|
|
25
|
+
MintAPIClient: () => MintAPIClient,
|
|
26
|
+
PremintAPIClient: () => PremintAPIClient,
|
|
27
|
+
PremintClient: () => PremintClient,
|
|
28
|
+
ZORA_API_BASE: () => ZORA_API_BASE,
|
|
29
|
+
convertCollection: () => convertCollection,
|
|
30
|
+
convertPremint: () => convertPremint,
|
|
31
|
+
create1155TokenSetupArgs: () => create1155TokenSetupArgs,
|
|
32
|
+
createNew1155Token: () => createNew1155Token,
|
|
33
|
+
encodePremintForAPI: () => encodePremintForAPI,
|
|
34
|
+
getPremintedLogFromReceipt: () => getPremintedLogFromReceipt,
|
|
35
|
+
getSalesConfigFixedPrice: () => getSalesConfigFixedPrice,
|
|
36
|
+
getTokenIdFromCreateReceipt: () => getTokenIdFromCreateReceipt,
|
|
37
|
+
preminterTypedDataDefinition: () => preminterTypedDataDefinition
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
|
|
41
|
+
// src/premint/premint-client.ts
|
|
42
|
+
var import_viem3 = require("viem");
|
|
43
|
+
var import_protocol_deployments = require("@zoralabs/protocol-deployments");
|
|
44
|
+
|
|
45
|
+
// src/premint/preminter.ts
|
|
46
|
+
var preminterTypedDataDefinition = ({
|
|
47
|
+
verifyingContract,
|
|
48
|
+
premintConfig,
|
|
49
|
+
chainId
|
|
50
|
+
}) => {
|
|
51
|
+
const { tokenConfig, uid, version, deleted } = premintConfig;
|
|
52
|
+
const types = {
|
|
53
|
+
CreatorAttribution: [
|
|
54
|
+
{ name: "tokenConfig", type: "TokenCreationConfig" },
|
|
55
|
+
// unique id scoped to the contract and token to create.
|
|
56
|
+
// ensure that a signature can be replaced, as long as the replacement
|
|
57
|
+
// has the same uid, and a newer version.
|
|
58
|
+
{ name: "uid", type: "uint32" },
|
|
59
|
+
{ name: "version", type: "uint32" },
|
|
60
|
+
// if this update should result in the signature being deleted.
|
|
61
|
+
{ name: "deleted", type: "bool" }
|
|
62
|
+
],
|
|
63
|
+
TokenCreationConfig: [
|
|
64
|
+
{ name: "tokenURI", type: "string" },
|
|
65
|
+
{ name: "maxSupply", type: "uint256" },
|
|
66
|
+
{ name: "maxTokensPerAddress", type: "uint64" },
|
|
67
|
+
{ name: "pricePerToken", type: "uint96" },
|
|
68
|
+
{ name: "mintStart", type: "uint64" },
|
|
69
|
+
{ name: "mintDuration", type: "uint64" },
|
|
70
|
+
{ name: "royaltyMintSchedule", type: "uint32" },
|
|
71
|
+
{ name: "royaltyBPS", type: "uint32" },
|
|
72
|
+
{ name: "royaltyRecipient", type: "address" },
|
|
73
|
+
{ name: "fixedPriceMinter", type: "address" }
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
const result = {
|
|
77
|
+
domain: {
|
|
78
|
+
chainId,
|
|
79
|
+
name: "Preminter",
|
|
80
|
+
version: "1",
|
|
81
|
+
verifyingContract
|
|
82
|
+
},
|
|
83
|
+
types,
|
|
84
|
+
message: {
|
|
85
|
+
tokenConfig,
|
|
86
|
+
uid,
|
|
87
|
+
version,
|
|
88
|
+
deleted
|
|
89
|
+
},
|
|
90
|
+
primaryType: "CreatorAttribution"
|
|
91
|
+
};
|
|
92
|
+
return result;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// src/apis/http-api-base.ts
|
|
96
|
+
var BadResponseError = class extends Error {
|
|
97
|
+
constructor(message, status, json) {
|
|
98
|
+
super(message);
|
|
99
|
+
this.name = "BadResponseError";
|
|
100
|
+
this.status = status;
|
|
101
|
+
this.json = json;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
async function wait(delayMs) {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
setTimeout(resolve, delayMs);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
var get = async (url) => {
|
|
110
|
+
const response = await fetch(url, { method: "GET" });
|
|
111
|
+
if (response.status !== 200) {
|
|
112
|
+
let json;
|
|
113
|
+
try {
|
|
114
|
+
json = await response.json();
|
|
115
|
+
} catch (e) {
|
|
116
|
+
}
|
|
117
|
+
throw new BadResponseError(
|
|
118
|
+
`Invalid response, status ${response.status}`,
|
|
119
|
+
response.status,
|
|
120
|
+
json
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return await response.json();
|
|
124
|
+
};
|
|
125
|
+
var post = async (url, data) => {
|
|
126
|
+
const response = await fetch(url, {
|
|
127
|
+
method: "POST",
|
|
128
|
+
headers: {
|
|
129
|
+
"content-type": "application/json",
|
|
130
|
+
accept: "application/json"
|
|
131
|
+
},
|
|
132
|
+
body: JSON.stringify(data)
|
|
133
|
+
});
|
|
134
|
+
if (response.status !== 200) {
|
|
135
|
+
let json;
|
|
136
|
+
try {
|
|
137
|
+
json = await response.json();
|
|
138
|
+
} catch (e) {
|
|
139
|
+
}
|
|
140
|
+
throw new BadResponseError(
|
|
141
|
+
`Bad response: ${response.status}`,
|
|
142
|
+
response.status,
|
|
143
|
+
json
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return await response.json();
|
|
147
|
+
};
|
|
148
|
+
var retries = async (tryFn, maxTries = 3, atTry = 1, linearBackoffMS = 200) => {
|
|
149
|
+
try {
|
|
150
|
+
return await tryFn();
|
|
151
|
+
} catch (err) {
|
|
152
|
+
if (err instanceof BadResponseError) {
|
|
153
|
+
if (err.status >= 500) {
|
|
154
|
+
if (atTry <= maxTries) {
|
|
155
|
+
await wait(atTry * linearBackoffMS);
|
|
156
|
+
return await retries(tryFn, maxTries, atTry + 1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/constants.ts
|
|
165
|
+
var ZORA_API_BASE = "https://api.zora.co/";
|
|
166
|
+
var OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
167
|
+
var SUBGRAPH_CONFIG_BASE = "https://api.goldsky.com/api/public/project_clhk16b61ay9t49vm6ntn4mkz/subgraphs";
|
|
168
|
+
function getSubgraph(name, version) {
|
|
169
|
+
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/premint/premint-api-client.ts
|
|
173
|
+
var postSignature = async (data) => retries(
|
|
174
|
+
() => post(`${ZORA_API_BASE}premint/signature`, data)
|
|
175
|
+
);
|
|
176
|
+
var getNextUID = async (path) => retries(
|
|
177
|
+
() => get(
|
|
178
|
+
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/next_uid`
|
|
179
|
+
)
|
|
180
|
+
);
|
|
181
|
+
var getSignature = async (path) => retries(
|
|
182
|
+
() => get(
|
|
183
|
+
`${ZORA_API_BASE}premint/signature/${path.chain_name}/${path.collection_address}/${path.uid}`
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
var PremintAPIClient = {
|
|
187
|
+
postSignature,
|
|
188
|
+
getSignature,
|
|
189
|
+
getNextUID
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// src/apis/client-base.ts
|
|
193
|
+
var import_viem2 = require("viem");
|
|
194
|
+
|
|
195
|
+
// src/apis/chain-constants.ts
|
|
196
|
+
var import_chains = require("viem/chains");
|
|
197
|
+
var import_viem = require("viem");
|
|
198
|
+
var REWARD_PER_TOKEN = (0, import_viem.parseEther)("0.000777");
|
|
199
|
+
var BackendChainNamesLookup = {
|
|
200
|
+
ZORA_MAINNET: "ZORA-MAINNET",
|
|
201
|
+
ZORA_GOERLI: "ZORA-GOERLI",
|
|
202
|
+
OPTIMISM_MAINNET: "OPTIMISM-MAINNET",
|
|
203
|
+
OPTIMISM_GOERLI: "OPTIMISM-GOERLI",
|
|
204
|
+
ETHEREUM_MAINNET: "ETHEREUM-MAINNET",
|
|
205
|
+
ETHEREUM_GOERLI: "ETHEREUM-GOERLI",
|
|
206
|
+
BASE_MAINNET: "BASE-MAINNET",
|
|
207
|
+
BASE_GOERLI: "BASE-GOERLI"
|
|
208
|
+
};
|
|
209
|
+
var networkConfigByChain = {
|
|
210
|
+
[import_chains.mainnet.id]: {
|
|
211
|
+
chainId: import_chains.mainnet.id,
|
|
212
|
+
isTestnet: false,
|
|
213
|
+
zoraPathChainName: "eth",
|
|
214
|
+
zoraBackendChainName: BackendChainNamesLookup.ETHEREUM_MAINNET,
|
|
215
|
+
subgraphUrl: getSubgraph("zora-create-mainnet", "stable")
|
|
216
|
+
},
|
|
217
|
+
[import_chains.goerli.id]: {
|
|
218
|
+
chainId: import_chains.goerli.id,
|
|
219
|
+
isTestnet: true,
|
|
220
|
+
zoraPathChainName: "gor",
|
|
221
|
+
zoraBackendChainName: BackendChainNamesLookup.ETHEREUM_GOERLI,
|
|
222
|
+
subgraphUrl: getSubgraph("zora-create-goerli", "stable")
|
|
223
|
+
},
|
|
224
|
+
[import_chains.zora.id]: {
|
|
225
|
+
chainId: import_chains.zora.id,
|
|
226
|
+
isTestnet: false,
|
|
227
|
+
zoraPathChainName: "zora",
|
|
228
|
+
zoraBackendChainName: BackendChainNamesLookup.ZORA_MAINNET,
|
|
229
|
+
subgraphUrl: getSubgraph("zora-create-zora-mainnet", "stable")
|
|
230
|
+
},
|
|
231
|
+
[import_chains.zoraTestnet.id]: {
|
|
232
|
+
chainId: import_chains.zora.id,
|
|
233
|
+
isTestnet: true,
|
|
234
|
+
zoraPathChainName: "zgor",
|
|
235
|
+
zoraBackendChainName: BackendChainNamesLookup.ZORA_GOERLI,
|
|
236
|
+
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
237
|
+
},
|
|
238
|
+
[import_chains.optimism.id]: {
|
|
239
|
+
chainId: import_chains.optimism.id,
|
|
240
|
+
isTestnet: false,
|
|
241
|
+
zoraPathChainName: "opt",
|
|
242
|
+
zoraBackendChainName: BackendChainNamesLookup.OPTIMISM_MAINNET,
|
|
243
|
+
subgraphUrl: getSubgraph("zora-create-optimism", "stable")
|
|
244
|
+
},
|
|
245
|
+
[import_chains.optimismGoerli.id]: {
|
|
246
|
+
chainId: import_chains.optimismGoerli.id,
|
|
247
|
+
isTestnet: true,
|
|
248
|
+
zoraPathChainName: "ogor",
|
|
249
|
+
zoraBackendChainName: BackendChainNamesLookup.OPTIMISM_GOERLI,
|
|
250
|
+
subgraphUrl: getSubgraph("zora-create-optimism-goerli", "stable")
|
|
251
|
+
},
|
|
252
|
+
[import_chains.base.id]: {
|
|
253
|
+
chainId: import_chains.base.id,
|
|
254
|
+
isTestnet: false,
|
|
255
|
+
zoraPathChainName: "base",
|
|
256
|
+
zoraBackendChainName: BackendChainNamesLookup.BASE_MAINNET,
|
|
257
|
+
subgraphUrl: getSubgraph("zora-create-base-mainnet", "stable")
|
|
258
|
+
},
|
|
259
|
+
[import_chains.baseGoerli.id]: {
|
|
260
|
+
chainId: import_chains.baseGoerli.id,
|
|
261
|
+
isTestnet: true,
|
|
262
|
+
zoraPathChainName: "bgor",
|
|
263
|
+
zoraBackendChainName: BackendChainNamesLookup.BASE_GOERLI,
|
|
264
|
+
subgraphUrl: getSubgraph("zora-create-base-goerli", "stable")
|
|
265
|
+
},
|
|
266
|
+
[import_chains.foundry.id]: {
|
|
267
|
+
chainId: import_chains.foundry.id,
|
|
268
|
+
isTestnet: true,
|
|
269
|
+
zoraPathChainName: "zgor",
|
|
270
|
+
zoraBackendChainName: BackendChainNamesLookup.ZORA_GOERLI,
|
|
271
|
+
subgraphUrl: getSubgraph("zora-create-zora-testnet", "stable")
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/apis/client-base.ts
|
|
276
|
+
var ClientBase = class {
|
|
277
|
+
constructor(chain) {
|
|
278
|
+
this.chain = chain;
|
|
279
|
+
const networkConfig = networkConfigByChain[chain.id];
|
|
280
|
+
if (!networkConfig) {
|
|
281
|
+
throw new Error(`Not configured for chain ${chain.id}`);
|
|
282
|
+
}
|
|
283
|
+
this.network = networkConfig;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Getter for public client that instantiates a publicClient as needed
|
|
287
|
+
*
|
|
288
|
+
* @param publicClient Optional viem public client
|
|
289
|
+
* @returns Existing public client or makes a new one for the given chain as needed.
|
|
290
|
+
*/
|
|
291
|
+
getPublicClient(publicClient) {
|
|
292
|
+
if (publicClient) {
|
|
293
|
+
return publicClient;
|
|
294
|
+
}
|
|
295
|
+
return (0, import_viem2.createPublicClient)({ chain: this.chain, transport: (0, import_viem2.http)() });
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/premint/premint-client.ts
|
|
300
|
+
var DefaultMintArguments = {
|
|
301
|
+
maxSupply: OPEN_EDITION_MINT_SIZE,
|
|
302
|
+
maxTokensPerAddress: 0n,
|
|
303
|
+
pricePerToken: 0n,
|
|
304
|
+
mintDuration: BigInt(60 * 60 * 24 * 7),
|
|
305
|
+
// 1 week
|
|
306
|
+
mintStart: 0n,
|
|
307
|
+
royaltyMintSchedule: 0,
|
|
308
|
+
royaltyBPS: 1e3
|
|
309
|
+
// 10%,
|
|
310
|
+
};
|
|
311
|
+
function getPremintedLogFromReceipt(receipt) {
|
|
312
|
+
for (const data of receipt.logs) {
|
|
313
|
+
try {
|
|
314
|
+
const decodedLog = (0, import_viem3.decodeEventLog)({
|
|
315
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
316
|
+
eventName: "Preminted",
|
|
317
|
+
...data
|
|
318
|
+
});
|
|
319
|
+
if (decodedLog.eventName === "Preminted") {
|
|
320
|
+
return decodedLog.args;
|
|
321
|
+
}
|
|
322
|
+
} catch (err) {
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
var convertPremint = (premint) => ({
|
|
327
|
+
...premint,
|
|
328
|
+
tokenConfig: {
|
|
329
|
+
...premint.tokenConfig,
|
|
330
|
+
fixedPriceMinter: premint.tokenConfig.fixedPriceMinter,
|
|
331
|
+
royaltyRecipient: premint.tokenConfig.royaltyRecipient,
|
|
332
|
+
maxSupply: BigInt(premint.tokenConfig.maxSupply),
|
|
333
|
+
pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
|
|
334
|
+
mintStart: BigInt(premint.tokenConfig.mintStart),
|
|
335
|
+
mintDuration: BigInt(premint.tokenConfig.mintDuration),
|
|
336
|
+
maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress)
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
var convertCollection = (collection) => ({
|
|
340
|
+
...collection,
|
|
341
|
+
contractAdmin: collection.contractAdmin
|
|
342
|
+
});
|
|
343
|
+
var encodePremintForAPI = ({
|
|
344
|
+
tokenConfig,
|
|
345
|
+
...premint
|
|
346
|
+
}) => ({
|
|
347
|
+
...premint,
|
|
348
|
+
tokenConfig: {
|
|
349
|
+
...tokenConfig,
|
|
350
|
+
maxSupply: tokenConfig.maxSupply.toString(),
|
|
351
|
+
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
352
|
+
mintStart: tokenConfig.mintStart.toString(),
|
|
353
|
+
mintDuration: tokenConfig.mintDuration.toString(),
|
|
354
|
+
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString()
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
var PremintClient = class extends ClientBase {
|
|
358
|
+
constructor(chain, apiClient) {
|
|
359
|
+
super(chain);
|
|
360
|
+
if (!apiClient) {
|
|
361
|
+
apiClient = PremintAPIClient;
|
|
362
|
+
}
|
|
363
|
+
this.apiClient = apiClient;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* The premint executor address is deployed to the same address across all chains.
|
|
367
|
+
* Can be overridden as needed by making a parent class.
|
|
368
|
+
*
|
|
369
|
+
* @returns Executor address for premints
|
|
370
|
+
*/
|
|
371
|
+
getExecutorAddress() {
|
|
372
|
+
return import_protocol_deployments.zoraCreator1155PremintExecutorImplAddress[999];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The fixed price minter address is the same across all chains for our current
|
|
376
|
+
* deployer strategy.
|
|
377
|
+
* Can be overridden as needed by making a parent class.
|
|
378
|
+
*
|
|
379
|
+
* @returns Fixed price sale strategy
|
|
380
|
+
*/
|
|
381
|
+
getFixedPriceMinterAddress() {
|
|
382
|
+
return import_protocol_deployments.zoraCreatorFixedPriceSaleStrategyAddress[999];
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Update existing premint given collection address and UID of existing premint.
|
|
386
|
+
*
|
|
387
|
+
* 1. Loads existing premint token
|
|
388
|
+
* 2. Updates with settings passed into function
|
|
389
|
+
* 3. Increments the version field
|
|
390
|
+
* 4. Re-signs the premint
|
|
391
|
+
* 5. Uploads the premint to the ZORA API
|
|
392
|
+
*
|
|
393
|
+
* Updates existing premint
|
|
394
|
+
* @param settings Settings for the new premint
|
|
395
|
+
* @param settings.account Account to sign the premint update from. Taken from walletClient if none passed in.
|
|
396
|
+
* @param settings.collection Collection information for the mint
|
|
397
|
+
* @param settings.walletClient viem wallet client to use to sign
|
|
398
|
+
* @param settings.uid UID
|
|
399
|
+
* @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
|
|
400
|
+
*
|
|
401
|
+
*/
|
|
402
|
+
async updatePremint({
|
|
403
|
+
walletClient,
|
|
404
|
+
uid,
|
|
405
|
+
collection,
|
|
406
|
+
token,
|
|
407
|
+
account
|
|
408
|
+
}) {
|
|
409
|
+
const signatureResponse = await this.apiClient.getSignature({
|
|
410
|
+
chain_name: this.network.zoraBackendChainName,
|
|
411
|
+
collection_address: collection.toLowerCase(),
|
|
412
|
+
uid
|
|
413
|
+
});
|
|
414
|
+
const convertedPremint = convertPremint(signatureResponse.premint);
|
|
415
|
+
const signerData = {
|
|
416
|
+
...signatureResponse,
|
|
417
|
+
premint: {
|
|
418
|
+
...convertedPremint,
|
|
419
|
+
tokenConfig: {
|
|
420
|
+
...convertedPremint.tokenConfig,
|
|
421
|
+
...token
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
return await this.signAndSubmitPremint({
|
|
426
|
+
walletClient,
|
|
427
|
+
account,
|
|
428
|
+
checkSignature: false,
|
|
429
|
+
verifyingContract: collection,
|
|
430
|
+
publicClient: this.getPublicClient(),
|
|
431
|
+
uid,
|
|
432
|
+
collection: {
|
|
433
|
+
...signerData.collection,
|
|
434
|
+
contractAdmin: signerData.collection.contractAdmin
|
|
435
|
+
},
|
|
436
|
+
premintConfig: signerData.premint
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Delete premint.
|
|
441
|
+
*
|
|
442
|
+
* 1. Loads current premint from collection address with UID
|
|
443
|
+
* 2. Increments version and marks as deleted
|
|
444
|
+
* 3. Signs new premint version
|
|
445
|
+
* 4. Sends to ZORA Premint API
|
|
446
|
+
*
|
|
447
|
+
* Deletes existing premint
|
|
448
|
+
* @param settings.collection collection address
|
|
449
|
+
* @param settings.uid UID
|
|
450
|
+
* @param settings.walletClient viem wallet client to use to sign
|
|
451
|
+
*
|
|
452
|
+
*/
|
|
453
|
+
async deletePremint({
|
|
454
|
+
walletClient,
|
|
455
|
+
uid,
|
|
456
|
+
account,
|
|
457
|
+
collection,
|
|
458
|
+
publicClient
|
|
459
|
+
}) {
|
|
460
|
+
const signatureResponse = await this.apiClient.getSignature({
|
|
461
|
+
chain_name: this.network.zoraBackendChainName,
|
|
462
|
+
collection_address: collection.toLowerCase(),
|
|
463
|
+
uid
|
|
464
|
+
});
|
|
465
|
+
const signerData = {
|
|
466
|
+
...signatureResponse,
|
|
467
|
+
collection: convertCollection(signatureResponse.collection),
|
|
468
|
+
premint: {
|
|
469
|
+
...convertPremint(signatureResponse.premint),
|
|
470
|
+
deleted: true
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
return await this.signAndSubmitPremint({
|
|
474
|
+
walletClient,
|
|
475
|
+
account,
|
|
476
|
+
checkSignature: false,
|
|
477
|
+
verifyingContract: collection,
|
|
478
|
+
publicClient: this.getPublicClient(publicClient),
|
|
479
|
+
uid,
|
|
480
|
+
collection: signerData.collection,
|
|
481
|
+
premintConfig: signerData.premint
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Internal function to sign and submit a premint request.
|
|
486
|
+
*
|
|
487
|
+
* @param premintArguments Arguments to premint
|
|
488
|
+
* @returns
|
|
489
|
+
*/
|
|
490
|
+
async signAndSubmitPremint({
|
|
491
|
+
walletClient,
|
|
492
|
+
publicClient,
|
|
493
|
+
verifyingContract,
|
|
494
|
+
premintConfig,
|
|
495
|
+
uid,
|
|
496
|
+
account,
|
|
497
|
+
checkSignature,
|
|
498
|
+
collection
|
|
499
|
+
}) {
|
|
500
|
+
if (!account) {
|
|
501
|
+
account = walletClient.account;
|
|
502
|
+
}
|
|
503
|
+
if (!account) {
|
|
504
|
+
throw new Error("No account provided");
|
|
505
|
+
}
|
|
506
|
+
const signature = await walletClient.signTypedData({
|
|
507
|
+
account,
|
|
508
|
+
...preminterTypedDataDefinition({
|
|
509
|
+
verifyingContract,
|
|
510
|
+
premintConfig,
|
|
511
|
+
chainId: this.chain.id
|
|
512
|
+
})
|
|
513
|
+
});
|
|
514
|
+
if (checkSignature) {
|
|
515
|
+
const [isValidSignature] = await publicClient.readContract({
|
|
516
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
517
|
+
address: this.getExecutorAddress(),
|
|
518
|
+
functionName: "isValidSignature",
|
|
519
|
+
args: [convertCollection(collection), premintConfig, signature]
|
|
520
|
+
});
|
|
521
|
+
if (!isValidSignature) {
|
|
522
|
+
throw new Error("Invalid signature");
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
const apiData = {
|
|
526
|
+
collection,
|
|
527
|
+
premint: encodePremintForAPI(premintConfig),
|
|
528
|
+
chain_name: this.network.zoraBackendChainName,
|
|
529
|
+
signature
|
|
530
|
+
};
|
|
531
|
+
const premint = await this.apiClient.postSignature(apiData);
|
|
532
|
+
return {
|
|
533
|
+
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
534
|
+
uid,
|
|
535
|
+
verifyingContract,
|
|
536
|
+
premint
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Create premint
|
|
541
|
+
*
|
|
542
|
+
* @param settings Settings for the new premint
|
|
543
|
+
* @param settings.account Account to sign the premint with. Taken from walletClient if none passed in.
|
|
544
|
+
* @param settings.collection Collection information for the mint
|
|
545
|
+
* @param settings.token Mint argument settings, optional settings are overridden with sensible defaults.
|
|
546
|
+
* @param settings.publicClient Public client (optional) – instantiated if not passed in with defaults.
|
|
547
|
+
* @param settings.walletClient Required wallet client for signing the premint message.
|
|
548
|
+
* @param settings.executionSettings Execution settings for premint options
|
|
549
|
+
* @param settings.executionSettings.deleted If this UID should be deleted. If omitted, set to false.
|
|
550
|
+
* @param settings.executionSettings.uid the UID to use – optional and retrieved as a fresh UID from ZORA by default.
|
|
551
|
+
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
552
|
+
* @returns premint url, uid, newContractAddress, and premint object
|
|
553
|
+
*/
|
|
554
|
+
async createPremint({
|
|
555
|
+
account,
|
|
556
|
+
collection,
|
|
557
|
+
token,
|
|
558
|
+
publicClient,
|
|
559
|
+
walletClient,
|
|
560
|
+
executionSettings,
|
|
561
|
+
checkSignature = false
|
|
562
|
+
}) {
|
|
563
|
+
publicClient = this.getPublicClient(publicClient);
|
|
564
|
+
const newContractAddress = await publicClient.readContract({
|
|
565
|
+
address: this.getExecutorAddress(),
|
|
566
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
567
|
+
functionName: "getContractAddress",
|
|
568
|
+
args: [convertCollection(collection)]
|
|
569
|
+
});
|
|
570
|
+
const tokenConfig = {
|
|
571
|
+
...DefaultMintArguments,
|
|
572
|
+
fixedPriceMinter: this.getFixedPriceMinterAddress(),
|
|
573
|
+
royaltyRecipient: account,
|
|
574
|
+
...token
|
|
575
|
+
};
|
|
576
|
+
let uid = executionSettings?.uid;
|
|
577
|
+
if (!uid) {
|
|
578
|
+
const uidResponse = await this.apiClient.getNextUID({
|
|
579
|
+
chain_name: this.network.zoraBackendChainName,
|
|
580
|
+
collection_address: newContractAddress.toLowerCase()
|
|
581
|
+
});
|
|
582
|
+
uid = uidResponse.next_uid;
|
|
583
|
+
}
|
|
584
|
+
if (!uid) {
|
|
585
|
+
throw new Error("UID is missing but required");
|
|
586
|
+
}
|
|
587
|
+
let deleted = executionSettings?.deleted || false;
|
|
588
|
+
const premintConfig = {
|
|
589
|
+
tokenConfig,
|
|
590
|
+
uid,
|
|
591
|
+
version: 1,
|
|
592
|
+
deleted
|
|
593
|
+
};
|
|
594
|
+
return await this.signAndSubmitPremint({
|
|
595
|
+
uid,
|
|
596
|
+
verifyingContract: newContractAddress,
|
|
597
|
+
premintConfig,
|
|
598
|
+
checkSignature,
|
|
599
|
+
account,
|
|
600
|
+
publicClient,
|
|
601
|
+
walletClient,
|
|
602
|
+
collection
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Fetches given premint data from the ZORA API.
|
|
607
|
+
*
|
|
608
|
+
* @param address Address for the premint contract
|
|
609
|
+
* @param uid UID for the desired premint
|
|
610
|
+
* @returns PremintSignatureGetResponse of premint data from the API
|
|
611
|
+
*/
|
|
612
|
+
async getPremintData({
|
|
613
|
+
address,
|
|
614
|
+
uid
|
|
615
|
+
}) {
|
|
616
|
+
return await this.apiClient.getSignature({
|
|
617
|
+
chain_name: this.network.zoraBackendChainName,
|
|
618
|
+
collection_address: address,
|
|
619
|
+
uid
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Check user signature for v1
|
|
624
|
+
*
|
|
625
|
+
* @param data Signature data from the API
|
|
626
|
+
* @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
|
|
627
|
+
*/
|
|
628
|
+
async isValidSignature({
|
|
629
|
+
data,
|
|
630
|
+
publicClient
|
|
631
|
+
}) {
|
|
632
|
+
publicClient = this.getPublicClient(publicClient);
|
|
633
|
+
const [isValid, contractAddress, recoveredSigner] = await publicClient.readContract({
|
|
634
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
635
|
+
address: this.getExecutorAddress(),
|
|
636
|
+
functionName: "isValidSignature",
|
|
637
|
+
args: [
|
|
638
|
+
convertCollection(data.collection),
|
|
639
|
+
convertPremint(data.premint),
|
|
640
|
+
data.signature
|
|
641
|
+
]
|
|
642
|
+
});
|
|
643
|
+
return { isValid, contractAddress, recoveredSigner };
|
|
644
|
+
}
|
|
645
|
+
makeUrls({
|
|
646
|
+
uid,
|
|
647
|
+
address,
|
|
648
|
+
tokenId
|
|
649
|
+
}) {
|
|
650
|
+
if ((!uid || !tokenId) && !address) {
|
|
651
|
+
return { explorer: null, zoraCollect: null, zoraManage: null };
|
|
652
|
+
}
|
|
653
|
+
const zoraTokenPath = uid ? `premint-${uid}` : tokenId;
|
|
654
|
+
return {
|
|
655
|
+
explorer: tokenId ? `https://${this.chain.blockExplorers?.default.url}/token/${address}/instance/${tokenId}` : null,
|
|
656
|
+
zoraCollect: `https://${this.network.isTestnet ? "testnet." : ""}zora.co/collect/${this.network.zoraPathChainName}:${address}/${zoraTokenPath}`,
|
|
657
|
+
zoraManage: `https://${this.network.isTestnet ? "testnet." : ""}zora.co/collect/${this.network.zoraPathChainName}:${address}/${zoraTokenPath}`
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Execute premint on-chain
|
|
662
|
+
*
|
|
663
|
+
* @param settings.data Data from the API for the mint
|
|
664
|
+
* @param settings.account Optional account (if omitted taken from wallet client) for the account executing the premint.
|
|
665
|
+
* @param settings.walletClient WalletClient to send execution from.
|
|
666
|
+
* @param settings.mintArguments User minting arguments.
|
|
667
|
+
* @param settings.mintArguments.quantityToMint Quantity to mint, optional, defaults to 1.
|
|
668
|
+
* @param settings.mintArguments.mintComment Optional mint comment, optional, omits when not included.
|
|
669
|
+
* @param settings.publicClient Optional public client for preflight checks.
|
|
670
|
+
* @returns receipt, log, zoraURL
|
|
671
|
+
*/
|
|
672
|
+
async executePremintWithWallet({
|
|
673
|
+
data,
|
|
674
|
+
account,
|
|
675
|
+
walletClient,
|
|
676
|
+
mintArguments,
|
|
677
|
+
publicClient
|
|
678
|
+
}) {
|
|
679
|
+
publicClient = this.getPublicClient(publicClient);
|
|
680
|
+
if (mintArguments && mintArguments?.quantityToMint < 1) {
|
|
681
|
+
throw new Error("Quantity to mint cannot be below 1");
|
|
682
|
+
}
|
|
683
|
+
const targetAddress = this.getExecutorAddress();
|
|
684
|
+
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
685
|
+
const args = [
|
|
686
|
+
convertCollection(data.collection),
|
|
687
|
+
convertPremint(data.premint),
|
|
688
|
+
data.signature,
|
|
689
|
+
numberToMint,
|
|
690
|
+
mintArguments?.mintComment || ""
|
|
691
|
+
];
|
|
692
|
+
if (!account) {
|
|
693
|
+
account = walletClient.account;
|
|
694
|
+
}
|
|
695
|
+
if (!account) {
|
|
696
|
+
throw new Error("Wallet not passed in");
|
|
697
|
+
}
|
|
698
|
+
const value = numberToMint * REWARD_PER_TOKEN;
|
|
699
|
+
const { request } = await publicClient.simulateContract({
|
|
700
|
+
account,
|
|
701
|
+
abi: import_protocol_deployments.zoraCreator1155PremintExecutorImplABI,
|
|
702
|
+
functionName: "premint",
|
|
703
|
+
value,
|
|
704
|
+
address: targetAddress,
|
|
705
|
+
args
|
|
706
|
+
});
|
|
707
|
+
const hash = await walletClient.writeContract(request);
|
|
708
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
709
|
+
const premintedLog = getPremintedLogFromReceipt(receipt);
|
|
710
|
+
return {
|
|
711
|
+
receipt,
|
|
712
|
+
premintedLog,
|
|
713
|
+
urls: this.makeUrls({
|
|
714
|
+
address: premintedLog?.contractAddress,
|
|
715
|
+
tokenId: premintedLog?.tokenId
|
|
716
|
+
})
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
// src/mint/mint-api-client.ts
|
|
722
|
+
function encodeQueryParameters(params) {
|
|
723
|
+
return new URLSearchParams(params).toString();
|
|
724
|
+
}
|
|
725
|
+
var getMintable = async (path, query) => retries(() => {
|
|
726
|
+
return get(
|
|
727
|
+
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${path.collection_address}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`
|
|
728
|
+
);
|
|
729
|
+
});
|
|
730
|
+
var getSalesConfigFixedPrice = async ({
|
|
731
|
+
contractAddress,
|
|
732
|
+
tokenId,
|
|
733
|
+
subgraphUrl
|
|
734
|
+
}) => retries(async () => {
|
|
735
|
+
const response = await post(subgraphUrl, {
|
|
736
|
+
query: "query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
|
|
737
|
+
variables: { id: `${contractAddress.toLowerCase()}-${tokenId}` }
|
|
738
|
+
});
|
|
739
|
+
return response.zoraCreateToken?.salesStrategies?.find(() => true)?.fixedPriceMinterAddress;
|
|
740
|
+
});
|
|
741
|
+
var MintAPIClient = {
|
|
742
|
+
getMintable,
|
|
743
|
+
getSalesConfigFixedPrice
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
// src/create/1155-create-helper.ts
|
|
747
|
+
var import_protocol_deployments2 = require("@zoralabs/protocol-deployments");
|
|
748
|
+
var import_viem4 = require("viem");
|
|
749
|
+
var SALE_END_FOREVER = 18446744073709551615n;
|
|
750
|
+
var ROYALTY_BPS_DEFAULT = 1e3;
|
|
751
|
+
var DEFAULT_SALE_SETTINGS = {
|
|
752
|
+
fundsRecipient: import_viem4.zeroAddress,
|
|
753
|
+
// Free Mint
|
|
754
|
+
pricePerToken: 0n,
|
|
755
|
+
// Sale start time – defaults to beginning of unix time
|
|
756
|
+
saleStart: 0n,
|
|
757
|
+
// This is the end of uint64, plenty of time
|
|
758
|
+
saleEnd: SALE_END_FOREVER,
|
|
759
|
+
// 0 Here means no limit
|
|
760
|
+
maxTokensPerAddress: 0n
|
|
761
|
+
};
|
|
762
|
+
var PERMISSION_BIT_MINTER = 2n ** 2n;
|
|
763
|
+
function create1155TokenSetupArgs({
|
|
764
|
+
nextTokenId,
|
|
765
|
+
// How many NFTs upon initialization to mint to the creator
|
|
766
|
+
mintToCreatorCount,
|
|
767
|
+
tokenMetadataURI,
|
|
768
|
+
// Fixed price minter address – required minter
|
|
769
|
+
fixedPriceMinterAddress,
|
|
770
|
+
// Address to use as the create referral, optional.
|
|
771
|
+
createReferral,
|
|
772
|
+
// Optional max supply of the token. Default unlimited
|
|
773
|
+
maxSupply,
|
|
774
|
+
// wallet sending the transaction
|
|
775
|
+
account,
|
|
776
|
+
salesConfig,
|
|
777
|
+
royaltySettings
|
|
778
|
+
}) {
|
|
779
|
+
if (!maxSupply) {
|
|
780
|
+
maxSupply = OPEN_EDITION_MINT_SIZE;
|
|
781
|
+
}
|
|
782
|
+
maxSupply = BigInt(maxSupply);
|
|
783
|
+
mintToCreatorCount = BigInt(mintToCreatorCount);
|
|
784
|
+
const salesConfigWithDefaults = {
|
|
785
|
+
// Set static sales default.
|
|
786
|
+
...DEFAULT_SALE_SETTINGS,
|
|
787
|
+
// Override with user settings.
|
|
788
|
+
...salesConfig
|
|
789
|
+
};
|
|
790
|
+
const setupActions = [
|
|
791
|
+
(0, import_viem4.encodeFunctionData)({
|
|
792
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
793
|
+
functionName: "addPermission",
|
|
794
|
+
args: [0n, fixedPriceMinterAddress, PERMISSION_BIT_MINTER]
|
|
795
|
+
}),
|
|
796
|
+
(0, import_viem4.encodeFunctionData)({
|
|
797
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
798
|
+
functionName: "assumeLastTokenIdMatches",
|
|
799
|
+
args: [nextTokenId - 1n]
|
|
800
|
+
}),
|
|
801
|
+
createReferral ? (0, import_viem4.encodeFunctionData)({
|
|
802
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
803
|
+
functionName: "setupNewTokenWithCreateReferral",
|
|
804
|
+
args: [tokenMetadataURI, maxSupply, createReferral]
|
|
805
|
+
}) : (0, import_viem4.encodeFunctionData)({
|
|
806
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
807
|
+
functionName: "setupNewToken",
|
|
808
|
+
args: [tokenMetadataURI, maxSupply]
|
|
809
|
+
}),
|
|
810
|
+
(0, import_viem4.encodeFunctionData)({
|
|
811
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
812
|
+
functionName: "callSale",
|
|
813
|
+
args: [
|
|
814
|
+
nextTokenId,
|
|
815
|
+
fixedPriceMinterAddress,
|
|
816
|
+
(0, import_viem4.encodeFunctionData)({
|
|
817
|
+
abi: import_protocol_deployments2.zoraCreatorFixedPriceSaleStrategyABI,
|
|
818
|
+
functionName: "setSale",
|
|
819
|
+
args: [nextTokenId, salesConfigWithDefaults]
|
|
820
|
+
})
|
|
821
|
+
]
|
|
822
|
+
})
|
|
823
|
+
];
|
|
824
|
+
if (mintToCreatorCount) {
|
|
825
|
+
setupActions.push(
|
|
826
|
+
(0, import_viem4.encodeFunctionData)({
|
|
827
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
828
|
+
functionName: "adminMint",
|
|
829
|
+
args: [account, nextTokenId, mintToCreatorCount, "0x"]
|
|
830
|
+
})
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
if (royaltySettings) {
|
|
834
|
+
setupActions.push(
|
|
835
|
+
(0, import_viem4.encodeFunctionData)({
|
|
836
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
837
|
+
functionName: "updateRoyaltiesForToken",
|
|
838
|
+
args: [
|
|
839
|
+
nextTokenId,
|
|
840
|
+
{
|
|
841
|
+
royaltyMintSchedule: 0,
|
|
842
|
+
royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
843
|
+
royaltyRecipient: royaltySettings?.royaltyRecipient || account
|
|
844
|
+
}
|
|
845
|
+
]
|
|
846
|
+
})
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
return setupActions;
|
|
850
|
+
}
|
|
851
|
+
var getTokenIdFromCreateReceipt = (receipt) => {
|
|
852
|
+
for (const data of receipt.logs) {
|
|
853
|
+
try {
|
|
854
|
+
const decodedLog = (0, import_viem4.decodeEventLog)({
|
|
855
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
856
|
+
eventName: "SetupNewToken",
|
|
857
|
+
...data
|
|
858
|
+
});
|
|
859
|
+
if (decodedLog && decodedLog.eventName === "SetupNewToken") {
|
|
860
|
+
return decodedLog.args.tokenId;
|
|
861
|
+
}
|
|
862
|
+
} catch (err) {
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
async function getContractExists(publicClient, contract, account) {
|
|
867
|
+
let contractAddress;
|
|
868
|
+
let contractExists = false;
|
|
869
|
+
if (typeof contract !== "string") {
|
|
870
|
+
contractAddress = await publicClient.readContract({
|
|
871
|
+
abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
|
|
872
|
+
// Since this address is deterministic we can hardcode a chain id safely here.
|
|
873
|
+
address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
|
|
874
|
+
functionName: "deterministicContractAddress",
|
|
875
|
+
args: [
|
|
876
|
+
account,
|
|
877
|
+
contract.uri,
|
|
878
|
+
contract.name,
|
|
879
|
+
contract.defaultAdmin || account
|
|
880
|
+
]
|
|
881
|
+
});
|
|
882
|
+
try {
|
|
883
|
+
await publicClient.readContract({
|
|
884
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
885
|
+
address: contractAddress,
|
|
886
|
+
functionName: "contractVersion"
|
|
887
|
+
});
|
|
888
|
+
contractExists = true;
|
|
889
|
+
} catch (e) {
|
|
890
|
+
}
|
|
891
|
+
return { contractAddress, contractExists };
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
contractExists: true,
|
|
895
|
+
contractAddress: contract
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
async function createNew1155Token({
|
|
899
|
+
publicClient,
|
|
900
|
+
contract,
|
|
901
|
+
tokenMetadataURI,
|
|
902
|
+
mintToCreatorCount = 1,
|
|
903
|
+
salesConfig = {},
|
|
904
|
+
maxSupply,
|
|
905
|
+
account,
|
|
906
|
+
royaltySettings,
|
|
907
|
+
getAdditionalSetupActions
|
|
908
|
+
}) {
|
|
909
|
+
const { contractExists, contractAddress } = await getContractExists(
|
|
910
|
+
publicClient,
|
|
911
|
+
contract,
|
|
912
|
+
account
|
|
913
|
+
);
|
|
914
|
+
let nextTokenId = 1n;
|
|
915
|
+
if (contractExists) {
|
|
916
|
+
nextTokenId = await publicClient.readContract({
|
|
917
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
918
|
+
functionName: "nextTokenId",
|
|
919
|
+
address: contractAddress
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
const fixedPriceMinterAddress = await publicClient.readContract({
|
|
923
|
+
abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
|
|
924
|
+
address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
|
|
925
|
+
functionName: "fixedPriceMinter"
|
|
926
|
+
});
|
|
927
|
+
let tokenSetupActions = create1155TokenSetupArgs({
|
|
928
|
+
tokenMetadataURI,
|
|
929
|
+
nextTokenId,
|
|
930
|
+
salesConfig,
|
|
931
|
+
maxSupply,
|
|
932
|
+
fixedPriceMinterAddress,
|
|
933
|
+
account,
|
|
934
|
+
mintToCreatorCount,
|
|
935
|
+
royaltySettings
|
|
936
|
+
});
|
|
937
|
+
if (getAdditionalSetupActions) {
|
|
938
|
+
tokenSetupActions = [
|
|
939
|
+
...getAdditionalSetupActions({ tokenId: nextTokenId, contractAddress }),
|
|
940
|
+
...tokenSetupActions
|
|
941
|
+
];
|
|
942
|
+
}
|
|
943
|
+
if (!contractAddress && typeof contract === "string") {
|
|
944
|
+
throw new Error("Invariant: contract cannot be missing and an address");
|
|
945
|
+
}
|
|
946
|
+
if (!contractExists && typeof contract !== "string") {
|
|
947
|
+
const { request } = await publicClient.simulateContract({
|
|
948
|
+
abi: import_protocol_deployments2.zoraCreator1155FactoryImplABI,
|
|
949
|
+
functionName: "createContractDeterministic",
|
|
950
|
+
account,
|
|
951
|
+
address: import_protocol_deployments2.zoraCreator1155FactoryImplAddress[999],
|
|
952
|
+
args: [
|
|
953
|
+
contract.uri,
|
|
954
|
+
contract.name,
|
|
955
|
+
{
|
|
956
|
+
// deprecated
|
|
957
|
+
royaltyMintSchedule: 0,
|
|
958
|
+
royaltyBPS: royaltySettings?.royaltyBPS || ROYALTY_BPS_DEFAULT,
|
|
959
|
+
royaltyRecipient: royaltySettings?.royaltyRecipient || account
|
|
960
|
+
},
|
|
961
|
+
contract.defaultAdmin || account,
|
|
962
|
+
tokenSetupActions
|
|
963
|
+
]
|
|
964
|
+
});
|
|
965
|
+
return {
|
|
966
|
+
send: (walletClient) => walletClient.writeContract(request),
|
|
967
|
+
tokenSetupActions,
|
|
968
|
+
contractAddress,
|
|
969
|
+
contractExists
|
|
970
|
+
};
|
|
971
|
+
} else if (contractExists) {
|
|
972
|
+
const { request } = await publicClient.simulateContract({
|
|
973
|
+
abi: import_protocol_deployments2.zoraCreator1155ImplABI,
|
|
974
|
+
functionName: "multicall",
|
|
975
|
+
account,
|
|
976
|
+
address: contractAddress,
|
|
977
|
+
args: [tokenSetupActions]
|
|
978
|
+
});
|
|
979
|
+
return {
|
|
980
|
+
send: (walletClient) => walletClient.writeContract(request),
|
|
981
|
+
tokenSetupActions,
|
|
982
|
+
contractAddress,
|
|
983
|
+
contractExists
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
throw new Error("Unsupported contract argument type");
|
|
987
|
+
}
|
|
988
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
989
|
+
0 && (module.exports = {
|
|
990
|
+
DEFAULT_SALE_SETTINGS,
|
|
991
|
+
DefaultMintArguments,
|
|
992
|
+
MintAPIClient,
|
|
993
|
+
PremintAPIClient,
|
|
994
|
+
PremintClient,
|
|
995
|
+
ZORA_API_BASE,
|
|
996
|
+
convertCollection,
|
|
997
|
+
convertPremint,
|
|
998
|
+
create1155TokenSetupArgs,
|
|
999
|
+
createNew1155Token,
|
|
1000
|
+
encodePremintForAPI,
|
|
1001
|
+
getPremintedLogFromReceipt,
|
|
1002
|
+
getSalesConfigFixedPrice,
|
|
1003
|
+
getTokenIdFromCreateReceipt,
|
|
1004
|
+
preminterTypedDataDefinition
|
|
1005
|
+
});
|
|
1006
|
+
//# sourceMappingURL=index.cjs.map
|