@zoralabs/protocol-sdk 0.4.0 → 0.4.2
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 +6 -6
- package/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/dist/apis/generated/premint-api-types.d.ts +117 -13
- package/dist/apis/generated/premint-api-types.d.ts.map +1 -1
- package/dist/index.cjs +183 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +184 -108
- package/dist/index.js.map +1 -1
- package/dist/premint/conversions.d.ts +78 -0
- package/dist/premint/conversions.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +2 -3
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +11 -83
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +15 -0
- package/dist/premint/preminter.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/anvil.ts +1 -1
- package/src/apis/generated/premint-api-types.ts +124 -12
- package/src/mint/mint-client.test.ts +5 -2
- package/src/premint/conversions.ts +155 -0
- package/src/premint/premint-api-client.ts +19 -125
- package/src/premint/premint-client.test.ts +5 -32
- package/src/premint/premint-client.ts +52 -22
- package/src/premint/preminter.test.ts +36 -20
- package/src/premint/preminter.ts +61 -12
|
@@ -9,19 +9,16 @@ import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
|
|
|
9
9
|
import {
|
|
10
10
|
ContractCreationConfig,
|
|
11
11
|
PremintConfigAndVersion,
|
|
12
|
-
PremintConfigForVersion,
|
|
13
|
-
PremintConfigV1,
|
|
14
|
-
PremintConfigV2,
|
|
15
12
|
PremintConfigVersion,
|
|
16
13
|
PremintConfigWithVersion,
|
|
17
14
|
} from "./contract-types";
|
|
18
15
|
import { Address, Hex } from "viem";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
import {
|
|
17
|
+
PremintSignatureRequestBody,
|
|
18
|
+
PremintSignatureResponse,
|
|
19
|
+
convertGetPremintApiResponse,
|
|
20
|
+
encodePostSignatureInput,
|
|
21
|
+
} from "./conversions";
|
|
25
22
|
|
|
26
23
|
type PremintNextUIDGetType =
|
|
27
24
|
paths["/signature/{chain_name}/{collection_address}/next_uid"]["get"];
|
|
@@ -82,83 +79,7 @@ const getSignature = async ({
|
|
|
82
79
|
),
|
|
83
80
|
);
|
|
84
81
|
|
|
85
|
-
return
|
|
86
|
-
...result,
|
|
87
|
-
// for now - we stub the backend api to simulate returning v1
|
|
88
|
-
premint_config_version: PremintConfigVersion.V1,
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
type OmitChainName<T> = Omit<T, "chain_name">;
|
|
93
|
-
|
|
94
|
-
const convertCollection = (
|
|
95
|
-
collection: PremintSignatureGetResponse["collection"],
|
|
96
|
-
): ContractCreationConfig => ({
|
|
97
|
-
...collection,
|
|
98
|
-
contractAdmin: collection.contractAdmin as Address,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Convert server to on-chain types for a premint
|
|
103
|
-
*
|
|
104
|
-
* @param premint Premint object from the server to convert to one that's compatible with viem
|
|
105
|
-
* @returns Viem type-compatible premint object
|
|
106
|
-
*/
|
|
107
|
-
const convertPremintV1 = (premint: PremintSignatureGetResponse["premint"]) => ({
|
|
108
|
-
...premint,
|
|
109
|
-
tokenConfig: {
|
|
110
|
-
...premint.tokenConfig,
|
|
111
|
-
fixedPriceMinter: premint.tokenConfig.fixedPriceMinter as Address,
|
|
112
|
-
royaltyRecipient: premint.tokenConfig.royaltyRecipient as Address,
|
|
113
|
-
maxSupply: BigInt(premint.tokenConfig.maxSupply),
|
|
114
|
-
pricePerToken: BigInt(premint.tokenConfig.pricePerToken),
|
|
115
|
-
mintStart: BigInt(premint.tokenConfig.mintStart),
|
|
116
|
-
mintDuration: BigInt(premint.tokenConfig.mintDuration),
|
|
117
|
-
maxTokensPerAddress: BigInt(premint.tokenConfig.maxTokensPerAddress),
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const encodePremintV1ForAPI = ({
|
|
122
|
-
tokenConfig,
|
|
123
|
-
...premint
|
|
124
|
-
}: PremintConfigV1): PremintSignatureGetResponse["premint"] => ({
|
|
125
|
-
...premint,
|
|
126
|
-
tokenConfig: {
|
|
127
|
-
...tokenConfig,
|
|
128
|
-
maxSupply: tokenConfig.maxSupply.toString(),
|
|
129
|
-
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
130
|
-
mintStart: tokenConfig.mintStart.toString(),
|
|
131
|
-
mintDuration: tokenConfig.mintDuration.toString(),
|
|
132
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString(),
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const encodePremintV2ForAPI = ({
|
|
137
|
-
tokenConfig,
|
|
138
|
-
...premint
|
|
139
|
-
}: PremintConfigV2) => ({
|
|
140
|
-
...premint,
|
|
141
|
-
tokenConfig: {
|
|
142
|
-
...tokenConfig,
|
|
143
|
-
maxSupply: tokenConfig.maxSupply.toString(),
|
|
144
|
-
pricePerToken: tokenConfig.pricePerToken.toString(),
|
|
145
|
-
mintStart: tokenConfig.mintStart.toString(),
|
|
146
|
-
mintDuration: tokenConfig.mintDuration.toString(),
|
|
147
|
-
maxTokensPerAddress: tokenConfig.maxTokensPerAddress.toString(),
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const encodePremintForAPI = <T extends PremintConfigVersion>({
|
|
152
|
-
premintConfig,
|
|
153
|
-
premintConfigVersion,
|
|
154
|
-
}: PremintConfigWithVersion<T>) => {
|
|
155
|
-
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
156
|
-
return encodePremintV1ForAPI(premintConfig as PremintConfigV1);
|
|
157
|
-
}
|
|
158
|
-
if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
159
|
-
return encodePremintV2ForAPI(premintConfig as PremintConfigV2);
|
|
160
|
-
}
|
|
161
|
-
throw new Error(`Invalid premint config version ${premintConfigVersion}`);
|
|
82
|
+
return result;
|
|
162
83
|
};
|
|
163
84
|
|
|
164
85
|
class PremintAPIClient {
|
|
@@ -171,31 +92,22 @@ class PremintAPIClient {
|
|
|
171
92
|
}
|
|
172
93
|
postSignature = async <T extends PremintConfigVersion>({
|
|
173
94
|
collection,
|
|
174
|
-
premintConfigVersion,
|
|
175
|
-
premintConfig,
|
|
176
95
|
signature,
|
|
96
|
+
...premintConfigAndVersion
|
|
177
97
|
}: {
|
|
178
98
|
collection: ContractCreationConfig;
|
|
179
99
|
signature: Hex;
|
|
180
100
|
} & PremintConfigWithVersion<T>): Promise<PremintSignatureResponse> => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
...data,
|
|
192
|
-
chain_name: this.networkConfig.zoraBackendChainName,
|
|
193
|
-
httpClient: this.httpClient,
|
|
194
|
-
});
|
|
195
|
-
} else {
|
|
196
|
-
// TODO: support posting premint v2 sig when backend is ready
|
|
197
|
-
throw new Error("Unsupported premint config version");
|
|
198
|
-
}
|
|
101
|
+
const data = encodePostSignatureInput({
|
|
102
|
+
collection,
|
|
103
|
+
...premintConfigAndVersion,
|
|
104
|
+
chainId: this.networkConfig.chainId,
|
|
105
|
+
signature,
|
|
106
|
+
});
|
|
107
|
+
return postSignature({
|
|
108
|
+
...data,
|
|
109
|
+
httpClient: this.httpClient,
|
|
110
|
+
});
|
|
199
111
|
};
|
|
200
112
|
|
|
201
113
|
getNextUID = async (collectionAddress: Address): Promise<number> =>
|
|
@@ -226,25 +138,7 @@ class PremintAPIClient {
|
|
|
226
138
|
httpClient: this.httpClient,
|
|
227
139
|
});
|
|
228
140
|
|
|
229
|
-
|
|
230
|
-
response.premint_config_version || PremintConfigVersion.V1;
|
|
231
|
-
|
|
232
|
-
let premintConfig: PremintConfigForVersion<typeof premintConfigVersion>;
|
|
233
|
-
|
|
234
|
-
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
235
|
-
premintConfig = convertPremintV1(response.premint);
|
|
236
|
-
} else {
|
|
237
|
-
throw new Error(
|
|
238
|
-
`Unsupported premint config version: ${premintConfigVersion}`,
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
signature: response.signature as Hex,
|
|
244
|
-
collection: convertCollection(response.collection),
|
|
245
|
-
premintConfig,
|
|
246
|
-
premintConfigVersion: premintConfigVersion,
|
|
247
|
-
};
|
|
141
|
+
return convertGetPremintApiResponse(response);
|
|
248
142
|
};
|
|
249
143
|
}
|
|
250
144
|
|
|
@@ -3,20 +3,15 @@ import { describe, expect, vi } from "vitest";
|
|
|
3
3
|
|
|
4
4
|
import { Address, Hex } from "viem";
|
|
5
5
|
import { createPremintClient } from "./premint-client";
|
|
6
|
-
import {
|
|
6
|
+
import { anvilTest } from "src/anvil";
|
|
7
7
|
import {
|
|
8
8
|
ContractCreationConfig,
|
|
9
9
|
PremintConfigV1,
|
|
10
10
|
PremintConfigVersion,
|
|
11
11
|
} from "./contract-types";
|
|
12
12
|
|
|
13
|
-
const zoraMainnetForkAnvilTest = makeAnvilTest({
|
|
14
|
-
forkUrl: forkUrls.zoraMainnet,
|
|
15
|
-
forkBlockNumber: 7550118,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
13
|
describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
19
|
-
|
|
14
|
+
anvilTest(
|
|
20
15
|
"can sign by default v1 on the forked premint contract",
|
|
21
16
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
22
17
|
const [deployerAccount] = await walletClient.getAddresses();
|
|
@@ -87,7 +82,7 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
87
82
|
20 * 1000,
|
|
88
83
|
);
|
|
89
84
|
|
|
90
|
-
|
|
85
|
+
anvilTest(
|
|
91
86
|
"can validate premint on network",
|
|
92
87
|
async ({ viemClients: { publicClient } }) => {
|
|
93
88
|
const premintClient = createPremintClient({
|
|
@@ -133,7 +128,7 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
133
128
|
},
|
|
134
129
|
);
|
|
135
130
|
|
|
136
|
-
|
|
131
|
+
anvilTest(
|
|
137
132
|
"can execute premint on network",
|
|
138
133
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
139
134
|
const [deployerAccount] = await walletClient.getAddresses();
|
|
@@ -206,28 +201,9 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
206
201
|
|
|
207
202
|
expect(premintedLog).toEqual({
|
|
208
203
|
contractAddress: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
|
|
209
|
-
contractConfig: {
|
|
210
|
-
contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
211
|
-
contractName: "Testing Contract",
|
|
212
|
-
contractURI:
|
|
213
|
-
"ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
|
|
214
|
-
},
|
|
215
204
|
createdNewContract: expect.any(Boolean),
|
|
216
205
|
minter: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
217
206
|
quantityMinted: 1n,
|
|
218
|
-
tokenConfig: {
|
|
219
|
-
fixedPriceMinter: "0x04E2516A2c207E84a1839755675dfd8eF6302F0a",
|
|
220
|
-
maxSupply: 18446744073709551615n,
|
|
221
|
-
maxTokensPerAddress: 0n,
|
|
222
|
-
mintDuration: 604800n,
|
|
223
|
-
mintStart: 0n,
|
|
224
|
-
pricePerToken: 0n,
|
|
225
|
-
royaltyBPS: 1000,
|
|
226
|
-
royaltyMintSchedule: 0,
|
|
227
|
-
royaltyRecipient: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
228
|
-
tokenURI:
|
|
229
|
-
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
|
|
230
|
-
},
|
|
231
207
|
tokenId: 1n,
|
|
232
208
|
uid: 3,
|
|
233
209
|
});
|
|
@@ -237,10 +213,7 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
237
213
|
});
|
|
238
214
|
|
|
239
215
|
describe("ZoraCreator1155Premint - v2 signatures", () => {
|
|
240
|
-
|
|
241
|
-
forkUrl: forkUrls.zoraSepolia,
|
|
242
|
-
forkBlockNumber: 1865004,
|
|
243
|
-
})(
|
|
216
|
+
anvilTest(
|
|
244
217
|
"can sign on the forked premint contract",
|
|
245
218
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
246
219
|
const [creatorAccount, createReferralAccount] =
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
markPremintDeleted,
|
|
24
24
|
makeNewPremint,
|
|
25
25
|
supportsPremintVersion,
|
|
26
|
+
getPremintMintCosts,
|
|
27
|
+
makeMintRewardsRecipient,
|
|
26
28
|
} from "./preminter";
|
|
27
29
|
import {
|
|
28
30
|
PremintConfigV2,
|
|
@@ -34,18 +36,18 @@ import {
|
|
|
34
36
|
TokenCreationConfigV2,
|
|
35
37
|
TokenCreationConfig,
|
|
36
38
|
PremintConfigForVersion,
|
|
39
|
+
MintArguments,
|
|
37
40
|
} from "./contract-types";
|
|
38
|
-
import type { PremintSignatureResponse } from "./premint-api-client";
|
|
39
41
|
import { PremintAPIClient } from "./premint-api-client";
|
|
40
42
|
import type { DecodeEventLogReturnType } from "viem";
|
|
41
43
|
import { OPEN_EDITION_MINT_SIZE } from "../constants";
|
|
42
|
-
import { REWARD_PER_TOKEN } from "src/apis/chain-constants";
|
|
43
44
|
import { IHttpClient } from "src/apis/http-api-base";
|
|
44
45
|
import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
|
|
46
|
+
import { MintCosts } from "src/mint/mint-client";
|
|
45
47
|
|
|
46
|
-
type
|
|
48
|
+
type PremintedV2LogType = DecodeEventLogReturnType<
|
|
47
49
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
48
|
-
"
|
|
50
|
+
"PremintedV2"
|
|
49
51
|
>["args"];
|
|
50
52
|
|
|
51
53
|
type URLSReturnType = {
|
|
@@ -58,7 +60,6 @@ type SignedPremintResponse = {
|
|
|
58
60
|
urls: URLSReturnType;
|
|
59
61
|
uid: number;
|
|
60
62
|
verifyingContract: Address;
|
|
61
|
-
premint: PremintSignatureResponse;
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
export const defaultTokenConfigV1MintArguments = (): Omit<
|
|
@@ -126,15 +127,15 @@ const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
|
|
|
126
127
|
*/
|
|
127
128
|
export function getPremintedLogFromReceipt(
|
|
128
129
|
receipt: TransactionReceipt,
|
|
129
|
-
):
|
|
130
|
+
): PremintedV2LogType | undefined {
|
|
130
131
|
for (const data of receipt.logs) {
|
|
131
132
|
try {
|
|
132
133
|
const decodedLog = decodeEventLog({
|
|
133
134
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
134
|
-
eventName: "
|
|
135
|
+
eventName: "PremintedV2",
|
|
135
136
|
...data,
|
|
136
137
|
});
|
|
137
|
-
if (decodedLog.eventName === "
|
|
138
|
+
if (decodedLog.eventName === "PremintedV2") {
|
|
138
139
|
return decodedLog.args;
|
|
139
140
|
}
|
|
140
141
|
} catch (err: any) {}
|
|
@@ -284,8 +285,8 @@ class PremintClient {
|
|
|
284
285
|
*/
|
|
285
286
|
private async signAndSubmitPremint<T extends PremintConfigVersion>(
|
|
286
287
|
params: SignAndSubmitPremintParams<T>,
|
|
287
|
-
) {
|
|
288
|
-
const {
|
|
288
|
+
): Promise<SignedPremintResponse> {
|
|
289
|
+
const { verifyingContract } = await signAndSubmitPremint({
|
|
289
290
|
...params,
|
|
290
291
|
chainId: this.chain.id,
|
|
291
292
|
apiClient: this.apiClient,
|
|
@@ -298,7 +299,6 @@ class PremintClient {
|
|
|
298
299
|
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
299
300
|
uid,
|
|
300
301
|
verifyingContract,
|
|
301
|
-
premint,
|
|
302
302
|
};
|
|
303
303
|
}
|
|
304
304
|
|
|
@@ -461,6 +461,23 @@ class PremintClient {
|
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
463
|
|
|
464
|
+
async getMintCosts({
|
|
465
|
+
tokenContract,
|
|
466
|
+
quantityToMint,
|
|
467
|
+
tokenCreationConfig,
|
|
468
|
+
}: {
|
|
469
|
+
quantityToMint: bigint;
|
|
470
|
+
tokenContract: Address;
|
|
471
|
+
tokenCreationConfig: TokenCreationConfig;
|
|
472
|
+
}): Promise<MintCosts> {
|
|
473
|
+
return await getPremintMintCosts({
|
|
474
|
+
publicClient: this.publicClient,
|
|
475
|
+
quantityToMint,
|
|
476
|
+
tokenContract,
|
|
477
|
+
tokenPrice: tokenCreationConfig.pricePerToken,
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
464
481
|
/**
|
|
465
482
|
* Execute premint on-chain
|
|
466
483
|
*
|
|
@@ -486,6 +503,7 @@ class PremintClient {
|
|
|
486
503
|
quantityToMint: number;
|
|
487
504
|
mintComment?: string;
|
|
488
505
|
mintReferral?: Address;
|
|
506
|
+
platformReferral?: Address;
|
|
489
507
|
mintRecipient?: Address;
|
|
490
508
|
};
|
|
491
509
|
}): Promise<SimulateContractParameters> {
|
|
@@ -505,13 +523,31 @@ class PremintClient {
|
|
|
505
523
|
|
|
506
524
|
const numberToMint = BigInt(mintArguments?.quantityToMint || 1);
|
|
507
525
|
|
|
508
|
-
const value =
|
|
526
|
+
const value = (
|
|
527
|
+
await getPremintMintCosts({
|
|
528
|
+
tokenContract,
|
|
529
|
+
quantityToMint: numberToMint,
|
|
530
|
+
publicClient: this.publicClient,
|
|
531
|
+
tokenPrice: premintConfig.tokenConfig.pricePerToken,
|
|
532
|
+
})
|
|
533
|
+
).totalCost;
|
|
534
|
+
|
|
535
|
+
const mintArgumentsContract: MintArguments = {
|
|
536
|
+
mintComment: mintArguments?.mintComment || "",
|
|
537
|
+
mintRecipient:
|
|
538
|
+
mintArguments?.mintRecipient ||
|
|
539
|
+
(typeof account === "string" ? account : account.address),
|
|
540
|
+
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
541
|
+
mintReferral: mintArguments?.mintReferral,
|
|
542
|
+
platformReferral: mintArguments?.platformReferral,
|
|
543
|
+
}),
|
|
544
|
+
};
|
|
509
545
|
|
|
510
546
|
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
511
547
|
return {
|
|
512
548
|
account,
|
|
513
549
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
514
|
-
functionName: "
|
|
550
|
+
functionName: "premintV1",
|
|
515
551
|
value,
|
|
516
552
|
address: getPremintExecutorAddress(),
|
|
517
553
|
args: [
|
|
@@ -519,16 +555,14 @@ class PremintClient {
|
|
|
519
555
|
premintConfig,
|
|
520
556
|
signature,
|
|
521
557
|
numberToMint,
|
|
522
|
-
|
|
558
|
+
mintArgumentsContract,
|
|
523
559
|
],
|
|
524
560
|
} satisfies SimulateContractParameters<
|
|
525
561
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
526
|
-
"
|
|
562
|
+
"premintV1"
|
|
527
563
|
>;
|
|
528
564
|
} else if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
529
565
|
const toPost = premintConfig as PremintConfigV2;
|
|
530
|
-
const accountAddress =
|
|
531
|
-
typeof account === "string" ? account : account.address;
|
|
532
566
|
|
|
533
567
|
return {
|
|
534
568
|
account,
|
|
@@ -542,11 +576,7 @@ class PremintClient {
|
|
|
542
576
|
toPost,
|
|
543
577
|
signature,
|
|
544
578
|
numberToMint,
|
|
545
|
-
|
|
546
|
-
mintComment: mintArguments?.mintComment || "",
|
|
547
|
-
mintRecipient: mintArguments?.mintRecipient || accountAddress,
|
|
548
|
-
mintReferral: mintArguments?.mintReferral || zeroAddress,
|
|
549
|
-
},
|
|
579
|
+
mintArgumentsContract,
|
|
550
580
|
],
|
|
551
581
|
} satisfies SimulateContractParameters<
|
|
552
582
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
isValidSignature,
|
|
15
15
|
recoverCreatorFromCreatorAttribution,
|
|
16
16
|
getPremintExecutorAddress,
|
|
17
|
+
getPremintMintCosts,
|
|
17
18
|
} from "./preminter";
|
|
18
19
|
import {
|
|
19
20
|
ContractCreationConfig,
|
|
@@ -102,8 +103,6 @@ const defaultPremintConfigV2 = ({
|
|
|
102
103
|
version: 0,
|
|
103
104
|
});
|
|
104
105
|
|
|
105
|
-
const ZORA_MINT_FEE = parseEther("0.000777");
|
|
106
|
-
|
|
107
106
|
const PREMINTER_ADDRESS = getPremintExecutorAddress();
|
|
108
107
|
|
|
109
108
|
const anvilTest = makeAnvilTest({
|
|
@@ -140,6 +139,11 @@ async function setupContracts({
|
|
|
140
139
|
};
|
|
141
140
|
}
|
|
142
141
|
|
|
142
|
+
const zoraSepoliaAnvilTest = makeAnvilTest({
|
|
143
|
+
forkUrl: forkUrls.zoraSepolia,
|
|
144
|
+
forkBlockNumber: 1905837,
|
|
145
|
+
});
|
|
146
|
+
|
|
143
147
|
describe("ZoraCreator1155Preminter", () => {
|
|
144
148
|
// skip for now - we need to make this work on zora testnet chain too
|
|
145
149
|
anvilTest(
|
|
@@ -186,7 +190,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
186
190
|
},
|
|
187
191
|
20 * 1000,
|
|
188
192
|
);
|
|
189
|
-
|
|
193
|
+
zoraSepoliaAnvilTest(
|
|
190
194
|
"can sign and recover a v1 premint config signature",
|
|
191
195
|
async ({ viemClients }) => {
|
|
192
196
|
const {
|
|
@@ -239,10 +243,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
239
243
|
|
|
240
244
|
20 * 1000,
|
|
241
245
|
);
|
|
242
|
-
|
|
243
|
-
forkUrl: forkUrls.zoraSepolia,
|
|
244
|
-
forkBlockNumber: 1262991,
|
|
245
|
-
})(
|
|
246
|
+
zoraSepoliaAnvilTest(
|
|
246
247
|
"can sign and recover a v2 premint config signature",
|
|
247
248
|
async ({ viemClients }) => {
|
|
248
249
|
const {
|
|
@@ -296,7 +297,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
296
297
|
|
|
297
298
|
20 * 1000,
|
|
298
299
|
);
|
|
299
|
-
|
|
300
|
+
zoraSepoliaAnvilTest(
|
|
300
301
|
"can sign and mint multiple tokens",
|
|
301
302
|
async ({ viemClients }) => {
|
|
302
303
|
const {
|
|
@@ -337,9 +338,14 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
337
338
|
|
|
338
339
|
const quantityToMint = 2n;
|
|
339
340
|
|
|
340
|
-
const valueToSend =
|
|
341
|
-
(
|
|
342
|
-
|
|
341
|
+
const valueToSend = (
|
|
342
|
+
await getPremintMintCosts({
|
|
343
|
+
publicClient: viemClients.publicClient,
|
|
344
|
+
quantityToMint,
|
|
345
|
+
tokenContract: contractAddress,
|
|
346
|
+
tokenPrice: premintConfig1.tokenConfig.pricePerToken,
|
|
347
|
+
})
|
|
348
|
+
).totalCost;
|
|
343
349
|
|
|
344
350
|
await viemClients.testClient.setBalance({
|
|
345
351
|
address: collectorAccount,
|
|
@@ -361,7 +367,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
361
367
|
const mintArguments: MintArguments = {
|
|
362
368
|
mintComment: "",
|
|
363
369
|
mintRecipient: collectorAccount,
|
|
364
|
-
|
|
370
|
+
mintRewardsRecipients: [],
|
|
365
371
|
};
|
|
366
372
|
|
|
367
373
|
// now have the collector execute the first signed message;
|
|
@@ -433,9 +439,14 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
433
439
|
|
|
434
440
|
const quantityToMint2 = 4n;
|
|
435
441
|
|
|
436
|
-
const valueToSend2 =
|
|
437
|
-
(
|
|
438
|
-
|
|
442
|
+
const valueToSend2 = (
|
|
443
|
+
await getPremintMintCosts({
|
|
444
|
+
publicClient: viemClients.publicClient,
|
|
445
|
+
quantityToMint: quantityToMint2,
|
|
446
|
+
tokenContract: contractAddress,
|
|
447
|
+
tokenPrice: premintConfig2.tokenConfig.pricePerToken,
|
|
448
|
+
})
|
|
449
|
+
).totalCost;
|
|
439
450
|
|
|
440
451
|
const simulationResult = await viemClients.publicClient.simulateContract({
|
|
441
452
|
abi: preminterAbi,
|
|
@@ -490,7 +501,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
490
501
|
40 * 1000,
|
|
491
502
|
);
|
|
492
503
|
|
|
493
|
-
|
|
504
|
+
zoraSepoliaAnvilTest(
|
|
494
505
|
"can decode the CreatorAttribution event",
|
|
495
506
|
async ({ viemClients }) => {
|
|
496
507
|
const {
|
|
@@ -532,9 +543,14 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
532
543
|
|
|
533
544
|
const quantityToMint = 2n;
|
|
534
545
|
|
|
535
|
-
const valueToSend =
|
|
536
|
-
(
|
|
537
|
-
|
|
546
|
+
const valueToSend = (
|
|
547
|
+
await getPremintMintCosts({
|
|
548
|
+
publicClient: viemClients.publicClient,
|
|
549
|
+
quantityToMint,
|
|
550
|
+
tokenContract: contractAddress,
|
|
551
|
+
tokenPrice: premintConfig.tokenConfig.pricePerToken,
|
|
552
|
+
})
|
|
553
|
+
).totalCost;
|
|
538
554
|
|
|
539
555
|
await viemClients.testClient.setBalance({
|
|
540
556
|
address: collectorAccount,
|
|
@@ -560,7 +576,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
560
576
|
{
|
|
561
577
|
mintComment: "",
|
|
562
578
|
mintRecipient: collectorAccount,
|
|
563
|
-
|
|
579
|
+
mintRewardsRecipients: [],
|
|
564
580
|
},
|
|
565
581
|
],
|
|
566
582
|
value: valueToSend,
|
package/src/premint/preminter.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
concat,
|
|
17
17
|
recoverAddress,
|
|
18
18
|
GetEventArgs,
|
|
19
|
+
parseEther,
|
|
19
20
|
} from "viem";
|
|
20
21
|
import {
|
|
21
22
|
ContractCreationConfig,
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
v1Types,
|
|
31
32
|
v2Types,
|
|
32
33
|
} from "./contract-types";
|
|
34
|
+
import { MintCosts } from "src/mint/mint-client";
|
|
33
35
|
|
|
34
36
|
export const getPremintExecutorAddress = () =>
|
|
35
37
|
zoraCreator1155PremintExecutorImplAddress[999];
|
|
@@ -300,18 +302,12 @@ export const supportedPremintVersions = async ({
|
|
|
300
302
|
tokenContract: Address;
|
|
301
303
|
publicClient: PublicClient;
|
|
302
304
|
}): Promise<readonly string[]> => {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
} catch (e) {
|
|
311
|
-
console.error(e);
|
|
312
|
-
// if the premint executor contract doesn't support the function, it must be v1
|
|
313
|
-
return ["1"];
|
|
314
|
-
}
|
|
305
|
+
return await publicClient.readContract({
|
|
306
|
+
abi: preminterAbi,
|
|
307
|
+
address: getPremintExecutorAddress(),
|
|
308
|
+
functionName: "supportedPremintSignatureVersions",
|
|
309
|
+
args: [tokenContract],
|
|
310
|
+
});
|
|
315
311
|
};
|
|
316
312
|
/**
|
|
317
313
|
* Checks if the 1155 contract at that address supports the given version of the premint config.
|
|
@@ -393,3 +389,56 @@ export function makeNewPremint<T extends TokenCreationConfig>({
|
|
|
393
389
|
tokenConfig,
|
|
394
390
|
} as PremintConfigForTokenCreationConfig<T>;
|
|
395
391
|
}
|
|
392
|
+
|
|
393
|
+
export async function getPremintMintFee({
|
|
394
|
+
tokenContract,
|
|
395
|
+
publicClient,
|
|
396
|
+
}: {
|
|
397
|
+
tokenContract: Address;
|
|
398
|
+
publicClient: PublicClient;
|
|
399
|
+
}) {
|
|
400
|
+
// try reading mint fee function from premint executor. this will revert
|
|
401
|
+
// if the abi is not up to date yet
|
|
402
|
+
try {
|
|
403
|
+
return await publicClient.readContract({
|
|
404
|
+
address: getPremintExecutorAddress(),
|
|
405
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
406
|
+
functionName: "mintFee",
|
|
407
|
+
args: [tokenContract],
|
|
408
|
+
});
|
|
409
|
+
} catch (e) {
|
|
410
|
+
console.error(e);
|
|
411
|
+
|
|
412
|
+
return parseEther("0.000777");
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export async function getPremintMintCosts({
|
|
417
|
+
publicClient,
|
|
418
|
+
tokenContract,
|
|
419
|
+
tokenPrice,
|
|
420
|
+
quantityToMint,
|
|
421
|
+
}: {
|
|
422
|
+
tokenContract: Address;
|
|
423
|
+
tokenPrice: bigint;
|
|
424
|
+
quantityToMint: bigint;
|
|
425
|
+
publicClient: PublicClient;
|
|
426
|
+
}): Promise<MintCosts> {
|
|
427
|
+
const mintFee = await getPremintMintFee({ tokenContract, publicClient });
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
mintFee: mintFee * quantityToMint,
|
|
431
|
+
tokenPurchaseCost: tokenPrice * quantityToMint,
|
|
432
|
+
totalCost: (mintFee + tokenPrice) * quantityToMint,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export function makeMintRewardsRecipient({
|
|
437
|
+
mintReferral = zeroAddress,
|
|
438
|
+
platformReferral = zeroAddress,
|
|
439
|
+
}: {
|
|
440
|
+
mintReferral?: Address;
|
|
441
|
+
platformReferral?: Address;
|
|
442
|
+
}): Address[] {
|
|
443
|
+
return [mintReferral, platformReferral];
|
|
444
|
+
}
|