@zoralabs/protocol-sdk 0.5.16 → 0.6.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 +6 -6
- package/CHANGELOG.md +24 -0
- package/README.md +1 -416
- package/dist/apis/generated/premint-api-types.d.ts +9 -2
- package/dist/apis/generated/premint-api-types.d.ts.map +1 -1
- package/dist/create/1155-create-helper.d.ts +16 -55
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/contract-setup.d.ts +14 -0
- package/dist/create/contract-setup.d.ts.map +1 -0
- package/dist/create/token-setup.d.ts +27 -0
- package/dist/create/token-setup.d.ts.map +1 -0
- package/dist/create/types.d.ts +45 -0
- package/dist/create/types.d.ts.map +1 -0
- package/dist/index.cjs +1392 -931
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1356 -907
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +4083 -43
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +17 -0
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
- package/dist/mint/types.d.ts +79 -0
- package/dist/mint/types.d.ts.map +1 -0
- package/dist/mints/mints-contracts.d.ts +24 -24
- package/dist/premint/contract-types.d.ts +21 -0
- package/dist/premint/contract-types.d.ts.map +1 -1
- package/dist/premint/conversions.d.ts +12 -22
- package/dist/premint/conversions.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +28 -14
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +83 -67
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +42 -18
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/sdk.d.ts +43 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/utils.d.ts +17 -6870
- package/dist/utils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/apis/generated/premint-api-types.ts +9 -2
- package/src/create/1155-create-helper.test.ts +235 -56
- package/src/create/1155-create-helper.ts +141 -309
- package/src/create/contract-setup.ts +88 -0
- package/src/create/token-setup.ts +379 -0
- package/src/create/types.ts +57 -0
- package/src/index.ts +11 -1
- package/src/mint/mint-client.test.ts +50 -61
- package/src/mint/mint-client.ts +321 -157
- package/src/mint/{mint-api-client.ts → subgraph-mint-getter.ts} +2 -25
- package/src/mint/types.ts +122 -0
- package/src/mints/mints-contracts.test.ts +3 -3
- package/src/mints/mints-contracts.ts +4 -4
- package/src/premint/contract-types.ts +32 -1
- package/src/premint/conversions.ts +31 -9
- package/src/premint/premint-api-client.ts +58 -46
- package/src/premint/premint-client.test.ts +153 -125
- package/src/premint/premint-client.ts +316 -330
- package/src/premint/preminter.test.ts +156 -5
- package/src/premint/preminter.ts +145 -44
- package/src/sdk.ts +98 -0
- package/src/utils.ts +30 -23
- package/test-integration/premint-client.test.ts +8 -8
- package/dist/mint/mint-api-client.d.ts +0 -35
- package/dist/mint/mint-api-client.d.ts.map +0 -1
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
hashTypedData,
|
|
4
|
+
keccak256,
|
|
5
|
+
stringToBytes,
|
|
6
|
+
zeroAddress,
|
|
7
|
+
} from "viem";
|
|
2
8
|
import { zoraSepolia } from "viem/chains";
|
|
3
9
|
import { describe, expect } from "vitest";
|
|
4
10
|
import { parseEther } from "viem";
|
|
@@ -24,6 +30,20 @@ import {
|
|
|
24
30
|
getPremintMintCosts,
|
|
25
31
|
} from "./preminter";
|
|
26
32
|
import { AnvilViemClientsTest, forkUrls, makeAnvilTest } from "src/anvil";
|
|
33
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
34
|
+
|
|
35
|
+
const erc1271Abi = [
|
|
36
|
+
{
|
|
37
|
+
type: "function",
|
|
38
|
+
name: "isValidSignature",
|
|
39
|
+
inputs: [
|
|
40
|
+
{ name: "_hash", type: "bytes32", internalType: "bytes32" },
|
|
41
|
+
{ name: "_signature", type: "bytes", internalType: "bytes" },
|
|
42
|
+
],
|
|
43
|
+
outputs: [{ name: "", type: "bytes4", internalType: "bytes4" }],
|
|
44
|
+
stateMutability: "view",
|
|
45
|
+
},
|
|
46
|
+
] as const;
|
|
27
47
|
|
|
28
48
|
// create token and contract creation config:
|
|
29
49
|
export const defaultContractConfig = ({
|
|
@@ -152,7 +172,7 @@ async function setupContracts({
|
|
|
152
172
|
|
|
153
173
|
const zoraSepoliaAnvilTest = makeAnvilTest({
|
|
154
174
|
forkUrl: forkUrls.zoraSepolia,
|
|
155
|
-
forkBlockNumber:
|
|
175
|
+
forkBlockNumber: 9467979,
|
|
156
176
|
anvilChainId: zoraSepolia.id,
|
|
157
177
|
});
|
|
158
178
|
|
|
@@ -239,6 +259,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
239
259
|
// recover and verify address is correct
|
|
240
260
|
const { recoveredAddress, isAuthorized } = await isValidSignature({
|
|
241
261
|
collection: contractConfig,
|
|
262
|
+
collectionAddress: tokenContract,
|
|
242
263
|
chainId: viemClients.publicClient.chain!.id,
|
|
243
264
|
premintConfig,
|
|
244
265
|
premintConfigVersion: PremintConfigVersion.V1,
|
|
@@ -293,6 +314,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
293
314
|
// recover and verify address is correct
|
|
294
315
|
const { recoveredAddress, isAuthorized } = await isValidSignature({
|
|
295
316
|
collection: contractConfig,
|
|
317
|
+
collectionAddress: tokenContract,
|
|
296
318
|
chainId: viemClients.publicClient.chain!.id,
|
|
297
319
|
premintConfig,
|
|
298
320
|
premintConfigVersion: PremintConfigVersion.V2,
|
|
@@ -356,7 +378,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
356
378
|
tokenContract: contractAddress,
|
|
357
379
|
tokenPrice: premintConfig1.tokenConfig.pricePerToken,
|
|
358
380
|
})
|
|
359
|
-
).
|
|
381
|
+
).totalCostEth;
|
|
360
382
|
|
|
361
383
|
await viemClients.testClient.setBalance({
|
|
362
384
|
address: collectorAccount,
|
|
@@ -465,7 +487,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
465
487
|
tokenContract: contractAddress,
|
|
466
488
|
tokenPrice: premintConfig2.tokenConfig.pricePerToken,
|
|
467
489
|
})
|
|
468
|
-
).
|
|
490
|
+
).totalCostEth;
|
|
469
491
|
|
|
470
492
|
const simulationResult = await viemClients.publicClient.simulateContract({
|
|
471
493
|
abi: preminterAbi,
|
|
@@ -524,6 +546,135 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
524
546
|
},
|
|
525
547
|
40 * 1000,
|
|
526
548
|
),
|
|
549
|
+
zoraSepoliaAnvilTest(
|
|
550
|
+
"can sign a premint from an smart contract account and mint tokens against that premint",
|
|
551
|
+
async ({ viemClients }) => {
|
|
552
|
+
const {
|
|
553
|
+
fixedPriceMinterAddress,
|
|
554
|
+
accounts: { collectorAccount },
|
|
555
|
+
} = await setupContracts({ viemClients });
|
|
556
|
+
|
|
557
|
+
// this test shows how to create a premint that is signed by an EOA, but the premint
|
|
558
|
+
// contract admin will be a smart wallet owned by the EOA.
|
|
559
|
+
// contract admin is set as the smart wallet. Smart wallet owner is the EOA.
|
|
560
|
+
// EOA signs the premint.
|
|
561
|
+
// When calling `premint` smart wallets address must be passed as an argument
|
|
562
|
+
|
|
563
|
+
// this was an AA contract that was deployed that has has the owner below as the
|
|
564
|
+
// valid signer. See https://sepolia.explorer.zora.energy/address/0x74F5fAf983d54FEd6D937654Aa4FD258534F2d4B?tab=contract
|
|
565
|
+
// it was deployed via the script `packages/1155-deployments/script/DeploySimpleAA.s.sol`
|
|
566
|
+
const smartWalletAddress = "0x74F5fAf983d54FEd6D937654Aa4FD258534F2d4B";
|
|
567
|
+
const ownerAddress = "0x7c8999dC9a822c1f0Df42023113EDB4FDd543266";
|
|
568
|
+
const ownerPrivateKey =
|
|
569
|
+
"0x02016836a56b71f0d02689e69e326f4f4c1b9057164ef592671cf0d37c8040c0";
|
|
570
|
+
|
|
571
|
+
const ownerAccount = privateKeyToAccount(ownerPrivateKey);
|
|
572
|
+
|
|
573
|
+
const premintConfig = defaultPremintConfigV2({
|
|
574
|
+
fixedPriceMinter: fixedPriceMinterAddress,
|
|
575
|
+
// we set the creator to the AA contract
|
|
576
|
+
creatorAccount: smartWalletAddress,
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
expect(ownerAccount.address).toBe(ownerAddress);
|
|
580
|
+
|
|
581
|
+
const contractConfig = defaultContractConfig({
|
|
582
|
+
// for the contract config, we set the smart wallet as the admin
|
|
583
|
+
contractAdmin: smartWalletAddress,
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
let contractAddress = await viemClients.publicClient.readContract({
|
|
587
|
+
abi: preminterAbi,
|
|
588
|
+
address: PREMINTER_ADDRESS,
|
|
589
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
590
|
+
args: [contractConfig],
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
const typedData = premintTypedDataDefinition({
|
|
594
|
+
verifyingContract: contractAddress,
|
|
595
|
+
// we need to sign here for the anvil chain, cause thats where it is run on
|
|
596
|
+
chainId: viemClients.chain.id,
|
|
597
|
+
premintConfig: premintConfig,
|
|
598
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
// have creator sign the message to create the contract
|
|
602
|
+
// and the token
|
|
603
|
+
const signedMessage = await viemClients.walletClient.signTypedData({
|
|
604
|
+
...typedData,
|
|
605
|
+
account: ownerAccount,
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// sanity check - validate the signature on the smart wallet contract
|
|
609
|
+
const result = await viemClients.publicClient.readContract({
|
|
610
|
+
abi: erc1271Abi,
|
|
611
|
+
address: smartWalletAddress,
|
|
612
|
+
functionName: "isValidSignature",
|
|
613
|
+
args: [hashTypedData(typedData), signedMessage],
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// if is a valid signature, signature should return `bytes4(keccak256("isValidSignature(bytes32,bytes)"))`
|
|
617
|
+
const expectedMagicValue = keccak256(
|
|
618
|
+
stringToBytes("isValidSignature(bytes32,bytes)"),
|
|
619
|
+
).slice(0, 10);
|
|
620
|
+
|
|
621
|
+
expect(result).toBe(expectedMagicValue);
|
|
622
|
+
|
|
623
|
+
const quantityToMint = 2n;
|
|
624
|
+
|
|
625
|
+
const valueToSend = (
|
|
626
|
+
await getPremintMintCosts({
|
|
627
|
+
publicClient: viemClients.publicClient,
|
|
628
|
+
quantityToMint,
|
|
629
|
+
tokenContract: contractAddress,
|
|
630
|
+
tokenPrice: premintConfig.tokenConfig.pricePerToken,
|
|
631
|
+
})
|
|
632
|
+
).totalCostEth;
|
|
633
|
+
|
|
634
|
+
await viemClients.testClient.setBalance({
|
|
635
|
+
address: collectorAccount,
|
|
636
|
+
value: parseEther("10"),
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
const mintArguments: PremintMintArguments = {
|
|
640
|
+
mintComment: "",
|
|
641
|
+
mintRecipient: collectorAccount,
|
|
642
|
+
mintRewardsRecipients: [],
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const firstMinter = collectorAccount;
|
|
646
|
+
|
|
647
|
+
// now have the collector execute the first signed message;
|
|
648
|
+
// it should create the contract, the token,
|
|
649
|
+
// and min the quantity to mint tokens to the collector
|
|
650
|
+
// the signature along with contract + token creation
|
|
651
|
+
// parameters are required to call this function
|
|
652
|
+
await viemClients.publicClient.simulateContract({
|
|
653
|
+
abi: preminterAbi,
|
|
654
|
+
functionName: "premint",
|
|
655
|
+
account: collectorAccount,
|
|
656
|
+
chain: viemClients.chain,
|
|
657
|
+
address: PREMINTER_ADDRESS,
|
|
658
|
+
args: [
|
|
659
|
+
contractConfig,
|
|
660
|
+
zeroAddress,
|
|
661
|
+
encodePremintConfig({
|
|
662
|
+
premintConfig: premintConfig,
|
|
663
|
+
premintConfigVersion: PremintConfigVersion.V2,
|
|
664
|
+
}),
|
|
665
|
+
signedMessage,
|
|
666
|
+
quantityToMint,
|
|
667
|
+
mintArguments,
|
|
668
|
+
firstMinter,
|
|
669
|
+
// we must specify the smart wallet address in the call, so that the 1155 contract
|
|
670
|
+
// knows to have the smart wallet validate the signature
|
|
671
|
+
smartWalletAddress,
|
|
672
|
+
],
|
|
673
|
+
value: valueToSend,
|
|
674
|
+
});
|
|
675
|
+
},
|
|
676
|
+
40 * 1000,
|
|
677
|
+
),
|
|
527
678
|
zoraSepoliaAnvilTest(
|
|
528
679
|
"can have collaborators create premints that can be executed on existing contracts",
|
|
529
680
|
async ({ viemClients }) => {
|
|
@@ -600,7 +751,7 @@ describe("ZoraCreator1155Preminter", () => {
|
|
|
600
751
|
tokenContract: contractAddress,
|
|
601
752
|
tokenPrice: premintConfig.tokenConfig.pricePerToken,
|
|
602
753
|
})
|
|
603
|
-
).
|
|
754
|
+
).totalCostEth;
|
|
604
755
|
|
|
605
756
|
const mintArguments: PremintMintArguments = {
|
|
606
757
|
mintComment: "",
|
package/src/premint/preminter.ts
CHANGED
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
zoraCreator1155PremintExecutorImplAddress,
|
|
7
7
|
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
8
8
|
premintTypedDataDefinition,
|
|
9
|
+
ContractCreationConfig,
|
|
10
|
+
PremintConfigForVersion,
|
|
9
11
|
} from "@zoralabs/protocol-deployments";
|
|
10
12
|
import {
|
|
11
13
|
recoverTypedDataAddress,
|
|
@@ -17,11 +19,10 @@ import {
|
|
|
17
19
|
recoverAddress,
|
|
18
20
|
GetEventArgs,
|
|
19
21
|
parseEther,
|
|
22
|
+
Account,
|
|
20
23
|
} from "viem";
|
|
21
24
|
import {
|
|
22
|
-
ContractCreationConfig,
|
|
23
25
|
PremintConfig,
|
|
24
|
-
PremintConfigForTokenCreationConfig,
|
|
25
26
|
PremintConfigV1,
|
|
26
27
|
PremintConfigV2,
|
|
27
28
|
PremintConfigVersion,
|
|
@@ -30,6 +31,13 @@ import {
|
|
|
30
31
|
} from "@zoralabs/protocol-deployments";
|
|
31
32
|
import { MintCosts } from "src/mint/mint-client";
|
|
32
33
|
import { PublicClient } from "src/utils";
|
|
34
|
+
import {
|
|
35
|
+
ContractCreationConfigAndAddress,
|
|
36
|
+
ContractCreationConfigOrAddress,
|
|
37
|
+
ContractCreationConfigWithOptionalAdditionalAdmins,
|
|
38
|
+
} from "./contract-types";
|
|
39
|
+
import { IPremintGetter } from "./premint-api-client";
|
|
40
|
+
import { isPremintConfigV1, isPremintConfigV2 } from "./conversions";
|
|
33
41
|
|
|
34
42
|
export const getPremintExecutorAddress = () =>
|
|
35
43
|
zoraCreator1155PremintExecutorImplAddress[999] as Address;
|
|
@@ -40,28 +48,28 @@ export type IsValidSignatureReturn = {
|
|
|
40
48
|
};
|
|
41
49
|
|
|
42
50
|
export async function isAuthorizedToCreatePremint({
|
|
43
|
-
|
|
51
|
+
contractAdmin = zeroAddress,
|
|
52
|
+
additionalAdmins = [],
|
|
44
53
|
collectionAddress,
|
|
45
54
|
publicClient,
|
|
46
55
|
signer,
|
|
47
56
|
}: {
|
|
48
|
-
|
|
57
|
+
contractAdmin?: Address;
|
|
58
|
+
additionalAdmins?: Address[];
|
|
49
59
|
collectionAddress: Address;
|
|
50
60
|
publicClient: PublicClient;
|
|
51
|
-
signer: Address;
|
|
61
|
+
signer: Address | Account;
|
|
52
62
|
}) {
|
|
53
|
-
if (collection.additionalAdmins.length > 0)
|
|
54
|
-
throw new Error("additionalAdmins not supported yet.");
|
|
55
63
|
// otherwize, we must assume the newer version of premint executor is deployed, so we call that.
|
|
56
64
|
return await publicClient.readContract({
|
|
57
65
|
abi: preminterAbi,
|
|
58
66
|
address: getPremintExecutorAddress(),
|
|
59
67
|
functionName: "isAuthorizedToCreatePremintWithAdditionalAdmins",
|
|
60
68
|
args: [
|
|
61
|
-
signer,
|
|
62
|
-
|
|
69
|
+
typeof signer === "string" ? signer : signer.address,
|
|
70
|
+
contractAdmin,
|
|
63
71
|
collectionAddress,
|
|
64
|
-
|
|
72
|
+
additionalAdmins,
|
|
65
73
|
],
|
|
66
74
|
});
|
|
67
75
|
}
|
|
@@ -106,22 +114,19 @@ export async function isValidSignature<T extends PremintConfigVersion>({
|
|
|
106
114
|
signature,
|
|
107
115
|
publicClient,
|
|
108
116
|
collection,
|
|
117
|
+
collectionAddress,
|
|
109
118
|
chainId,
|
|
110
119
|
...premintConfigAndVersion
|
|
111
120
|
}: {
|
|
112
|
-
collection: ContractCreationConfig;
|
|
113
121
|
signature: Hex;
|
|
114
122
|
chainId: number;
|
|
115
123
|
publicClient: PublicClient;
|
|
116
|
-
} & PremintConfigWithVersion<T>
|
|
117
|
-
|
|
118
|
-
collection,
|
|
119
|
-
publicClient,
|
|
120
|
-
});
|
|
124
|
+
} & PremintConfigWithVersion<T> &
|
|
125
|
+
ContractCreationConfigAndAddress): Promise<IsValidSignatureReturn> {
|
|
121
126
|
const recoveredAddress = await tryRecoverPremintSigner({
|
|
122
127
|
...premintConfigAndVersion,
|
|
123
128
|
signature,
|
|
124
|
-
verifyingContract:
|
|
129
|
+
verifyingContract: collectionAddress,
|
|
125
130
|
chainId,
|
|
126
131
|
});
|
|
127
132
|
|
|
@@ -133,8 +138,9 @@ export async function isValidSignature<T extends PremintConfigVersion>({
|
|
|
133
138
|
|
|
134
139
|
const isAuthorized = await isAuthorizedToCreatePremint({
|
|
135
140
|
signer: recoveredAddress!,
|
|
136
|
-
collection,
|
|
137
|
-
|
|
141
|
+
additionalAdmins: collection?.additionalAdmins,
|
|
142
|
+
contractAdmin: collection?.contractAdmin,
|
|
143
|
+
collectionAddress: collectionAddress,
|
|
138
144
|
publicClient,
|
|
139
145
|
});
|
|
140
146
|
|
|
@@ -240,13 +246,13 @@ export const supportedPremintVersions = async ({
|
|
|
240
246
|
}: {
|
|
241
247
|
tokenContract: Address;
|
|
242
248
|
publicClient: PublicClient;
|
|
243
|
-
}): Promise<
|
|
244
|
-
return await publicClient.readContract({
|
|
249
|
+
}): Promise<PremintConfigVersion[]> => {
|
|
250
|
+
return (await publicClient.readContract({
|
|
245
251
|
abi: preminterAbi,
|
|
246
252
|
address: getPremintExecutorAddress(),
|
|
247
253
|
functionName: "supportedPremintSignatureVersions",
|
|
248
254
|
args: [tokenContract],
|
|
249
|
-
});
|
|
255
|
+
})) as PremintConfigVersion[];
|
|
250
256
|
};
|
|
251
257
|
/**
|
|
252
258
|
* Checks if the 1155 contract at that address supports the given version of the premint config.
|
|
@@ -266,18 +272,27 @@ export const supportsPremintVersion = async ({
|
|
|
266
272
|
};
|
|
267
273
|
|
|
268
274
|
export async function getPremintCollectionAddress({
|
|
269
|
-
collection,
|
|
270
275
|
publicClient,
|
|
276
|
+
contract: collection,
|
|
277
|
+
contractAddress: collectionAddress,
|
|
271
278
|
}: {
|
|
272
|
-
collection: ContractCreationConfig;
|
|
273
279
|
publicClient: PublicClient;
|
|
274
|
-
}): Promise<Address> {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
} & ContractCreationConfigOrAddress): Promise<Address> {
|
|
281
|
+
if (typeof collection !== "undefined") {
|
|
282
|
+
return publicClient.readContract({
|
|
283
|
+
address: getPremintExecutorAddress(),
|
|
284
|
+
abi: zoraCreator1155PremintExecutorImplABI,
|
|
285
|
+
functionName: "getContractWithAdditionalAdminsAddress",
|
|
286
|
+
args: [
|
|
287
|
+
{
|
|
288
|
+
...collection,
|
|
289
|
+
additionalAdmins: collection.additionalAdmins || [],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return collectionAddress;
|
|
281
296
|
}
|
|
282
297
|
|
|
283
298
|
export function applyUpdateToPremint({
|
|
@@ -304,19 +319,19 @@ export function applyUpdateToPremint({
|
|
|
304
319
|
return result;
|
|
305
320
|
}
|
|
306
321
|
|
|
307
|
-
export function makeNewPremint<T extends
|
|
322
|
+
export function makeNewPremint<T extends PremintConfigVersion>({
|
|
308
323
|
tokenConfig,
|
|
309
324
|
uid,
|
|
310
325
|
}: {
|
|
311
|
-
tokenConfig: T;
|
|
326
|
+
tokenConfig: PremintConfigForVersion<T>["tokenConfig"];
|
|
312
327
|
uid: number;
|
|
313
|
-
}):
|
|
328
|
+
}): PremintConfigForVersion<T> {
|
|
314
329
|
return {
|
|
315
330
|
deleted: false,
|
|
316
331
|
uid,
|
|
317
332
|
version: 0,
|
|
318
333
|
tokenConfig,
|
|
319
|
-
} as
|
|
334
|
+
} as PremintConfigForVersion<T>;
|
|
320
335
|
}
|
|
321
336
|
|
|
322
337
|
export async function getPremintMintFee({
|
|
@@ -342,26 +357,74 @@ export async function getPremintMintFee({
|
|
|
342
357
|
}
|
|
343
358
|
}
|
|
344
359
|
|
|
360
|
+
type GetMintCostsParams = {
|
|
361
|
+
tokenContract: Address;
|
|
362
|
+
tokenPrice: bigint;
|
|
363
|
+
quantityToMint: bigint | number;
|
|
364
|
+
publicClient: PublicClient;
|
|
365
|
+
};
|
|
366
|
+
|
|
345
367
|
export async function getPremintMintCosts({
|
|
346
368
|
publicClient,
|
|
347
369
|
tokenContract,
|
|
348
370
|
tokenPrice,
|
|
349
371
|
quantityToMint,
|
|
350
|
-
}: {
|
|
351
|
-
tokenContract: Address;
|
|
352
|
-
tokenPrice: bigint;
|
|
353
|
-
quantityToMint: bigint;
|
|
354
|
-
publicClient: PublicClient;
|
|
355
|
-
}): Promise<MintCosts> {
|
|
372
|
+
}: GetMintCostsParams): Promise<MintCosts> {
|
|
356
373
|
const mintFee = await getPremintMintFee({ tokenContract, publicClient });
|
|
357
374
|
|
|
375
|
+
const quantityToMintBigInt = BigInt(quantityToMint);
|
|
376
|
+
|
|
358
377
|
return {
|
|
359
|
-
mintFee: mintFee *
|
|
360
|
-
|
|
361
|
-
|
|
378
|
+
mintFee: mintFee * quantityToMintBigInt,
|
|
379
|
+
totalPurchaseCost: tokenPrice * quantityToMintBigInt,
|
|
380
|
+
totalCostEth: (mintFee + tokenPrice) * quantityToMintBigInt,
|
|
362
381
|
};
|
|
363
382
|
}
|
|
364
383
|
|
|
384
|
+
export async function getPremintPricePerToken({
|
|
385
|
+
collection,
|
|
386
|
+
uid,
|
|
387
|
+
premintGetter,
|
|
388
|
+
}: {
|
|
389
|
+
collection: Address;
|
|
390
|
+
uid: number;
|
|
391
|
+
premintGetter: IPremintGetter;
|
|
392
|
+
}) {
|
|
393
|
+
const premintConfigWithVersion = await premintGetter.getSignature({
|
|
394
|
+
collectionAddress: collection,
|
|
395
|
+
uid,
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
if (
|
|
399
|
+
isPremintConfigV1(premintConfigWithVersion) ||
|
|
400
|
+
isPremintConfigV2(premintConfigWithVersion)
|
|
401
|
+
) {
|
|
402
|
+
return premintConfigWithVersion.premintConfig.tokenConfig.pricePerToken;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
throw new Error("Premint version not supported to get price");
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export async function getPremintMintCostsWithUnknownTokenPrice({
|
|
409
|
+
premintGetter,
|
|
410
|
+
uid,
|
|
411
|
+
...rest
|
|
412
|
+
}: Omit<GetMintCostsParams, "tokenPrice"> & {
|
|
413
|
+
premintGetter: IPremintGetter;
|
|
414
|
+
uid: number;
|
|
415
|
+
}) {
|
|
416
|
+
const pricePerToken = await getPremintPricePerToken({
|
|
417
|
+
uid,
|
|
418
|
+
premintGetter,
|
|
419
|
+
collection: rest.tokenContract,
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
return await getPremintMintCosts({
|
|
423
|
+
...rest,
|
|
424
|
+
tokenPrice: pricePerToken,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
365
428
|
export function makeMintRewardsRecipient({
|
|
366
429
|
mintReferral = zeroAddress,
|
|
367
430
|
platformReferral = zeroAddress,
|
|
@@ -377,3 +440,41 @@ export function getDefaultFixedPriceMinterAddress(chainId: number): Address {
|
|
|
377
440
|
chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress
|
|
378
441
|
]!;
|
|
379
442
|
}
|
|
443
|
+
|
|
444
|
+
export const emptyContractCreationConfig = (): ContractCreationConfig => ({
|
|
445
|
+
contractAdmin: zeroAddress,
|
|
446
|
+
contractURI: "",
|
|
447
|
+
contractName: "",
|
|
448
|
+
additionalAdmins: [],
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
export function defaultAdditionalAdmins(
|
|
452
|
+
collection: ContractCreationConfigWithOptionalAdditionalAdmins,
|
|
453
|
+
): ContractCreationConfig {
|
|
454
|
+
return {
|
|
455
|
+
...collection,
|
|
456
|
+
additionalAdmins: collection.additionalAdmins || [],
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export const toContractCreationConfigOrAddress = ({
|
|
461
|
+
collection,
|
|
462
|
+
collectionAddress,
|
|
463
|
+
}: {
|
|
464
|
+
collection?: ContractCreationConfigWithOptionalAdditionalAdmins;
|
|
465
|
+
collectionAddress?: Address;
|
|
466
|
+
}) => {
|
|
467
|
+
if (typeof collection !== "undefined") {
|
|
468
|
+
return {
|
|
469
|
+
contract: collection,
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (typeof collectionAddress !== "undefined") {
|
|
474
|
+
return {
|
|
475
|
+
contractAddress: collectionAddress,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
throw new Error("Must provide either a collection or a collection address");
|
|
480
|
+
};
|
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PremintClient,
|
|
3
|
+
getDataFromPremintReceipt,
|
|
4
|
+
} from "./premint/premint-client";
|
|
5
|
+
import { Create1155Client } from "./create/1155-create-helper";
|
|
6
|
+
import { MintClient } from "./mint/mint-client";
|
|
7
|
+
import { ClientConfig } from "./utils";
|
|
8
|
+
import { IPremintAPI, PremintAPIClient } from "./premint/premint-api-client";
|
|
9
|
+
import { SubgraphMintGetter } from "./mint/subgraph-mint-getter";
|
|
10
|
+
import { IMintGetter } from "./mint/types";
|
|
11
|
+
|
|
12
|
+
export type CreatorClient = {
|
|
13
|
+
createPremint: PremintClient["createPremint"];
|
|
14
|
+
updatePremint: PremintClient["updatePremint"];
|
|
15
|
+
deletePremint: PremintClient["deletePremint"];
|
|
16
|
+
create1155: Create1155Client["createNew1155Token"];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type CollectorClient = {
|
|
20
|
+
getPremint: PremintClient["getPremint"];
|
|
21
|
+
getCollectDataFromPremintReceipt: PremintClient["getDataFromPremintReceipt"];
|
|
22
|
+
mint: MintClient["mint"];
|
|
23
|
+
getMintCosts: MintClient["getMintCosts"];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type CreatorClientConfig = ClientConfig & {
|
|
27
|
+
/** API for submitting and getting premints. Defaults to the Zora Premint API */
|
|
28
|
+
premintApi?: IPremintAPI;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Builds the sdk for creating/managing 1155 contracts and tokens
|
|
33
|
+
*
|
|
34
|
+
* @param clientConfig - Configuration for the client {@link CreatorClientConfig}
|
|
35
|
+
* @returns CreatorClient {@link CreatorClient}
|
|
36
|
+
* */
|
|
37
|
+
export function createCreatorClient(
|
|
38
|
+
clientConfig: CreatorClientConfig,
|
|
39
|
+
): CreatorClient {
|
|
40
|
+
const premintClient = new PremintClient({
|
|
41
|
+
chainId: clientConfig.chainId,
|
|
42
|
+
publicClient: clientConfig.publicClient,
|
|
43
|
+
premintApi:
|
|
44
|
+
clientConfig.premintApi || new PremintAPIClient(clientConfig.chainId),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const create1155CreatorClient = new Create1155Client({
|
|
48
|
+
chainId: clientConfig.chainId,
|
|
49
|
+
publicClient: clientConfig.publicClient,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
createPremint: (p) => premintClient.createPremint(p),
|
|
54
|
+
updatePremint: (p) => premintClient.updatePremint(p),
|
|
55
|
+
deletePremint: (p) => premintClient.deletePremint(p),
|
|
56
|
+
create1155: (p) => create1155CreatorClient.createNew1155Token(p),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type CollectorClientConfig = ClientConfig & {
|
|
61
|
+
/** API for getting premints. Defaults to the Zora Premint API */
|
|
62
|
+
premintGetter?: IPremintAPI;
|
|
63
|
+
/** API for getting onchain mints. Defaults to the Zora Creator Subgraph */
|
|
64
|
+
mintGetter?: IMintGetter;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Builds the sdk for collecting Premints, 1155, and 721 tokens.
|
|
69
|
+
*
|
|
70
|
+
* @param clientConfig - Configuration for the client {@link CollectorClientConfig}
|
|
71
|
+
* @returns CollectorClient {@link CollectorClient}
|
|
72
|
+
*/
|
|
73
|
+
export function createCollectorClient(
|
|
74
|
+
params: CollectorClientConfig,
|
|
75
|
+
): CollectorClient {
|
|
76
|
+
const premintGetterToUse =
|
|
77
|
+
params.premintGetter || new PremintAPIClient(params.chainId);
|
|
78
|
+
const mintGetterToUse =
|
|
79
|
+
params.mintGetter || new SubgraphMintGetter(params.chainId);
|
|
80
|
+
const mintClient = new MintClient({
|
|
81
|
+
chainId: params.chainId,
|
|
82
|
+
publicClient: params.publicClient,
|
|
83
|
+
premintGetter: premintGetterToUse,
|
|
84
|
+
mintGetter: mintGetterToUse,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
getPremint: (p) =>
|
|
89
|
+
premintGetterToUse.getSignature({
|
|
90
|
+
collectionAddress: p.address,
|
|
91
|
+
uid: p.uid,
|
|
92
|
+
}),
|
|
93
|
+
getCollectDataFromPremintReceipt: (p) =>
|
|
94
|
+
getDataFromPremintReceipt(p, params.chainId),
|
|
95
|
+
mint: (p) => mintClient.mint(p),
|
|
96
|
+
getMintCosts: (p) => mintClient.getMintCosts(p),
|
|
97
|
+
};
|
|
98
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -7,23 +7,14 @@ import {
|
|
|
7
7
|
ContractFunctionName,
|
|
8
8
|
PublicClient as BasePublicClient,
|
|
9
9
|
SimulateContractParameters,
|
|
10
|
-
|
|
11
|
-
createPublicClient,
|
|
12
|
-
http,
|
|
10
|
+
AbiStateMutability,
|
|
13
11
|
} from "viem";
|
|
14
|
-
import {
|
|
15
|
-
IHttpClient,
|
|
16
|
-
httpClient as defaultHttpClient,
|
|
17
|
-
} from "./apis/http-api-base";
|
|
18
12
|
|
|
19
|
-
export const
|
|
13
|
+
export const makeContractParameters = <
|
|
20
14
|
const abi extends Abi | readonly unknown[],
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"nonpayable" | "payable",
|
|
25
|
-
functionName
|
|
26
|
-
>,
|
|
15
|
+
stateMutabiliy extends AbiStateMutability,
|
|
16
|
+
functionName extends ContractFunctionName<abi, stateMutabiliy>,
|
|
17
|
+
args extends ContractFunctionArgs<abi, stateMutabiliy, functionName>,
|
|
27
18
|
chainOverride extends Chain | undefined,
|
|
28
19
|
accountOverride extends Account | Address | undefined = undefined,
|
|
29
20
|
>(
|
|
@@ -37,19 +28,35 @@ export const makeSimulateContractParamaters = <
|
|
|
37
28
|
>,
|
|
38
29
|
) => args;
|
|
39
30
|
|
|
40
|
-
export type PublicClient = BasePublicClient
|
|
31
|
+
export type PublicClient = Pick<BasePublicClient, "readContract">;
|
|
41
32
|
|
|
42
33
|
export type ClientConfig = {
|
|
43
|
-
chain
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
/** The chain that the client is to run on. */
|
|
35
|
+
chainId: number;
|
|
36
|
+
/** Optional public client for the chain. If not provide, it is created. */
|
|
37
|
+
publicClient: PublicClient;
|
|
46
38
|
};
|
|
47
39
|
|
|
48
|
-
export function setupClient({
|
|
40
|
+
export function setupClient({ chainId, publicClient }: ClientConfig) {
|
|
49
41
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
publicClient:
|
|
53
|
-
publicClient || createPublicClient({ chain, transport: http() }),
|
|
42
|
+
chainId,
|
|
43
|
+
publicClient,
|
|
54
44
|
};
|
|
55
45
|
}
|
|
46
|
+
|
|
47
|
+
export function mintRecipientOrAccount({
|
|
48
|
+
mintRecipient,
|
|
49
|
+
minterAccount,
|
|
50
|
+
}: {
|
|
51
|
+
mintRecipient?: Address;
|
|
52
|
+
minterAccount: Address | Account;
|
|
53
|
+
}): Address {
|
|
54
|
+
return (
|
|
55
|
+
mintRecipient ||
|
|
56
|
+
(typeof minterAccount === "string" ? minterAccount : minterAccount.address)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type Concrete<Type> = {
|
|
61
|
+
[Property in keyof Type]-?: Type[Property];
|
|
62
|
+
};
|