@zoralabs/protocol-sdk 0.4.1 → 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 +5 -5
- package/CHANGELOG.md +8 -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 +124 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +124 -107
- 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 +4 -83
- package/dist/premint/premint-client.d.ts.map +1 -1
- 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 -34
- package/src/premint/premint-client.ts +23 -23
- package/src/premint/preminter.ts +6 -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,25 +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
|
-
const zoraSepoliaAnvilTest = makeAnvilTest({
|
|
19
|
-
forkUrl: forkUrls.zoraSepolia,
|
|
20
|
-
forkBlockNumber: 1904731,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
13
|
describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
24
|
-
|
|
14
|
+
anvilTest(
|
|
25
15
|
"can sign by default v1 on the forked premint contract",
|
|
26
16
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
27
17
|
const [deployerAccount] = await walletClient.getAddresses();
|
|
@@ -92,7 +82,7 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
92
82
|
20 * 1000,
|
|
93
83
|
);
|
|
94
84
|
|
|
95
|
-
|
|
85
|
+
anvilTest(
|
|
96
86
|
"can validate premint on network",
|
|
97
87
|
async ({ viemClients: { publicClient } }) => {
|
|
98
88
|
const premintClient = createPremintClient({
|
|
@@ -138,7 +128,7 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
138
128
|
},
|
|
139
129
|
);
|
|
140
130
|
|
|
141
|
-
|
|
131
|
+
anvilTest(
|
|
142
132
|
"can execute premint on network",
|
|
143
133
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
144
134
|
const [deployerAccount] = await walletClient.getAddresses();
|
|
@@ -211,28 +201,9 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
211
201
|
|
|
212
202
|
expect(premintedLog).toEqual({
|
|
213
203
|
contractAddress: "0xf8dA7f53c283d898818af7FB9d98103F559bDac2",
|
|
214
|
-
contractConfig: {
|
|
215
|
-
contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
216
|
-
contractName: "Testing Contract",
|
|
217
|
-
contractURI:
|
|
218
|
-
"ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
|
|
219
|
-
},
|
|
220
204
|
createdNewContract: expect.any(Boolean),
|
|
221
205
|
minter: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
222
206
|
quantityMinted: 1n,
|
|
223
|
-
tokenConfig: {
|
|
224
|
-
fixedPriceMinter: "0x04E2516A2c207E84a1839755675dfd8eF6302F0a",
|
|
225
|
-
maxSupply: 18446744073709551615n,
|
|
226
|
-
maxTokensPerAddress: 0n,
|
|
227
|
-
mintDuration: 604800n,
|
|
228
|
-
mintStart: 0n,
|
|
229
|
-
pricePerToken: 0n,
|
|
230
|
-
royaltyBPS: 1000,
|
|
231
|
-
royaltyMintSchedule: 0,
|
|
232
|
-
royaltyRecipient: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
233
|
-
tokenURI:
|
|
234
|
-
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
|
|
235
|
-
},
|
|
236
207
|
tokenId: 1n,
|
|
237
208
|
uid: 3,
|
|
238
209
|
});
|
|
@@ -242,7 +213,7 @@ describe("ZoraCreator1155Premint - v1 signatures", () => {
|
|
|
242
213
|
});
|
|
243
214
|
|
|
244
215
|
describe("ZoraCreator1155Premint - v2 signatures", () => {
|
|
245
|
-
|
|
216
|
+
anvilTest(
|
|
246
217
|
"can sign on the forked premint contract",
|
|
247
218
|
async ({ viemClients: { walletClient, publicClient } }) => {
|
|
248
219
|
const [creatorAccount, createReferralAccount] =
|
|
@@ -36,8 +36,8 @@ import {
|
|
|
36
36
|
TokenCreationConfigV2,
|
|
37
37
|
TokenCreationConfig,
|
|
38
38
|
PremintConfigForVersion,
|
|
39
|
+
MintArguments,
|
|
39
40
|
} from "./contract-types";
|
|
40
|
-
import type { PremintSignatureResponse } from "./premint-api-client";
|
|
41
41
|
import { PremintAPIClient } from "./premint-api-client";
|
|
42
42
|
import type { DecodeEventLogReturnType } from "viem";
|
|
43
43
|
import { OPEN_EDITION_MINT_SIZE } from "../constants";
|
|
@@ -45,9 +45,9 @@ import { IHttpClient } from "src/apis/http-api-base";
|
|
|
45
45
|
import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
|
|
46
46
|
import { MintCosts } from "src/mint/mint-client";
|
|
47
47
|
|
|
48
|
-
type
|
|
48
|
+
type PremintedV2LogType = DecodeEventLogReturnType<
|
|
49
49
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
50
|
-
"
|
|
50
|
+
"PremintedV2"
|
|
51
51
|
>["args"];
|
|
52
52
|
|
|
53
53
|
type URLSReturnType = {
|
|
@@ -60,7 +60,6 @@ type SignedPremintResponse = {
|
|
|
60
60
|
urls: URLSReturnType;
|
|
61
61
|
uid: number;
|
|
62
62
|
verifyingContract: Address;
|
|
63
|
-
premint: PremintSignatureResponse;
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
export const defaultTokenConfigV1MintArguments = (): Omit<
|
|
@@ -128,15 +127,15 @@ const makeTokenConfigWithDefaults = <T extends PremintConfigVersion>({
|
|
|
128
127
|
*/
|
|
129
128
|
export function getPremintedLogFromReceipt(
|
|
130
129
|
receipt: TransactionReceipt,
|
|
131
|
-
):
|
|
130
|
+
): PremintedV2LogType | undefined {
|
|
132
131
|
for (const data of receipt.logs) {
|
|
133
132
|
try {
|
|
134
133
|
const decodedLog = decodeEventLog({
|
|
135
134
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
136
|
-
eventName: "
|
|
135
|
+
eventName: "PremintedV2",
|
|
137
136
|
...data,
|
|
138
137
|
});
|
|
139
|
-
if (decodedLog.eventName === "
|
|
138
|
+
if (decodedLog.eventName === "PremintedV2") {
|
|
140
139
|
return decodedLog.args;
|
|
141
140
|
}
|
|
142
141
|
} catch (err: any) {}
|
|
@@ -286,8 +285,8 @@ class PremintClient {
|
|
|
286
285
|
*/
|
|
287
286
|
private async signAndSubmitPremint<T extends PremintConfigVersion>(
|
|
288
287
|
params: SignAndSubmitPremintParams<T>,
|
|
289
|
-
) {
|
|
290
|
-
const {
|
|
288
|
+
): Promise<SignedPremintResponse> {
|
|
289
|
+
const { verifyingContract } = await signAndSubmitPremint({
|
|
291
290
|
...params,
|
|
292
291
|
chainId: this.chain.id,
|
|
293
292
|
apiClient: this.apiClient,
|
|
@@ -300,7 +299,6 @@ class PremintClient {
|
|
|
300
299
|
urls: this.makeUrls({ address: verifyingContract, uid }),
|
|
301
300
|
uid,
|
|
302
301
|
verifyingContract,
|
|
303
|
-
premint,
|
|
304
302
|
};
|
|
305
303
|
}
|
|
306
304
|
|
|
@@ -534,11 +532,22 @@ class PremintClient {
|
|
|
534
532
|
})
|
|
535
533
|
).totalCost;
|
|
536
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
|
+
};
|
|
545
|
+
|
|
537
546
|
if (premintConfigVersion === PremintConfigVersion.V1) {
|
|
538
547
|
return {
|
|
539
548
|
account,
|
|
540
549
|
abi: zoraCreator1155PremintExecutorImplABI,
|
|
541
|
-
functionName: "
|
|
550
|
+
functionName: "premintV1",
|
|
542
551
|
value,
|
|
543
552
|
address: getPremintExecutorAddress(),
|
|
544
553
|
args: [
|
|
@@ -546,16 +555,14 @@ class PremintClient {
|
|
|
546
555
|
premintConfig,
|
|
547
556
|
signature,
|
|
548
557
|
numberToMint,
|
|
549
|
-
|
|
558
|
+
mintArgumentsContract,
|
|
550
559
|
],
|
|
551
560
|
} satisfies SimulateContractParameters<
|
|
552
561
|
typeof zoraCreator1155PremintExecutorImplABI,
|
|
553
|
-
"
|
|
562
|
+
"premintV1"
|
|
554
563
|
>;
|
|
555
564
|
} else if (premintConfigVersion === PremintConfigVersion.V2) {
|
|
556
565
|
const toPost = premintConfig as PremintConfigV2;
|
|
557
|
-
const accountAddress =
|
|
558
|
-
typeof account === "string" ? account : account.address;
|
|
559
566
|
|
|
560
567
|
return {
|
|
561
568
|
account,
|
|
@@ -569,14 +576,7 @@ class PremintClient {
|
|
|
569
576
|
toPost,
|
|
570
577
|
signature,
|
|
571
578
|
numberToMint,
|
|
572
|
-
|
|
573
|
-
mintComment: mintArguments?.mintComment || "",
|
|
574
|
-
mintRecipient: mintArguments?.mintRecipient || accountAddress,
|
|
575
|
-
mintRewardsRecipients: makeMintRewardsRecipient({
|
|
576
|
-
mintReferral: mintArguments?.mintReferral,
|
|
577
|
-
platformReferral: mintArguments?.platformReferral,
|
|
578
|
-
}),
|
|
579
|
-
},
|
|
579
|
+
mintArgumentsContract,
|
|
580
580
|
],
|
|
581
581
|
} satisfies SimulateContractParameters<
|
|
582
582
|
typeof zoraCreator1155PremintExecutorImplABI,
|
package/src/premint/preminter.ts
CHANGED
|
@@ -302,18 +302,12 @@ export const supportedPremintVersions = async ({
|
|
|
302
302
|
tokenContract: Address;
|
|
303
303
|
publicClient: PublicClient;
|
|
304
304
|
}): Promise<readonly string[]> => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
});
|
|
312
|
-
} catch (e) {
|
|
313
|
-
console.error(e);
|
|
314
|
-
// if the premint executor contract doesn't support the function, it must be v1
|
|
315
|
-
return ["1"];
|
|
316
|
-
}
|
|
305
|
+
return await publicClient.readContract({
|
|
306
|
+
abi: preminterAbi,
|
|
307
|
+
address: getPremintExecutorAddress(),
|
|
308
|
+
functionName: "supportedPremintSignatureVersions",
|
|
309
|
+
args: [tokenContract],
|
|
310
|
+
});
|
|
317
311
|
};
|
|
318
312
|
/**
|
|
319
313
|
* Checks if the 1155 contract at that address supports the given version of the premint config.
|