@zoralabs/protocol-sdk 0.8.0 → 0.9.1
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 +7 -7
- package/CHANGELOG.md +17 -0
- package/dist/allow-list/allow-list-client.d.ts +26 -0
- package/dist/allow-list/allow-list-client.d.ts.map +1 -0
- package/dist/allow-list/types.d.ts +14 -0
- package/dist/allow-list/types.d.ts.map +1 -0
- package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
- package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/apis/subgraph-querier.d.ts +18 -0
- package/dist/apis/subgraph-querier.d.ts.map +1 -0
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/contract-setup.d.ts +1 -0
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/mint-from-create.d.ts +12 -0
- package/dist/create/mint-from-create.d.ts.map +1 -0
- package/dist/create/minter-defaults.d.ts +5 -0
- package/dist/create/minter-defaults.d.ts.map +1 -0
- package/dist/create/minter-setup.d.ts +14 -0
- package/dist/create/minter-setup.d.ts.map +1 -0
- package/dist/create/token-setup.d.ts +4 -19
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/create/types.d.ts +34 -7
- package/dist/create/types.d.ts.map +1 -1
- package/dist/create/update.d.ts +15 -0
- package/dist/create/update.d.ts.map +1 -0
- package/dist/index.cjs +2359 -1932
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2379 -1947
- package/dist/index.js.map +1 -1
- package/dist/ipfs/token-metadata.d.ts +1 -0
- package/dist/ipfs/token-metadata.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +2 -6
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +6 -2
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +9 -7
- package/dist/mint/mint-transactions.d.ts.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +5 -4
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +42 -15
- package/dist/mint/subgraph-queries.d.ts.map +1 -1
- package/dist/mint/types.d.ts +33 -13
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/sparks/sparks-contracts.d.ts +96 -96
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -8
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/allow-list/allow-list-client.ts +105 -0
- package/src/allow-list/types.ts +15 -0
- package/src/apis/generated/allow-list-api-types.ts +288 -0
- package/src/apis/http-api-base.ts +12 -0
- package/src/apis/subgraph-querier.ts +38 -0
- package/src/create/1155-create-helper.test.ts +217 -89
- package/src/create/1155-create-helper.ts +25 -4
- package/src/create/contract-setup.ts +8 -0
- package/src/create/mint-from-create.ts +119 -0
- package/src/create/minter-defaults.test.ts +21 -0
- package/src/create/minter-defaults.ts +134 -0
- package/src/create/minter-setup.ts +293 -0
- package/src/create/token-setup.ts +14 -190
- package/src/create/types.ts +58 -9
- package/src/create/update.ts +93 -0
- package/src/index.ts +4 -0
- package/src/ipfs/token-metadata.ts +18 -0
- package/src/mint/mint-client.test.ts +219 -15
- package/src/mint/mint-client.ts +2 -34
- package/src/mint/mint-queries.ts +40 -19
- package/src/mint/mint-transactions.ts +104 -17
- package/src/mint/subgraph-mint-getter.ts +107 -50
- package/src/mint/subgraph-queries.ts +67 -37
- package/src/mint/types.ts +58 -16
- package/src/premint/premint-client.test.ts +6 -5
- package/src/types.ts +1 -1
- package/src/utils.ts +1 -25
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Concrete } from "src/utils";
|
|
2
|
+
import {
|
|
3
|
+
SalesConfigParamsType,
|
|
4
|
+
AllowListParamType,
|
|
5
|
+
Erc20ParamsType,
|
|
6
|
+
FixedPriceParamsType,
|
|
7
|
+
SaleStartAndEnd,
|
|
8
|
+
MaxTokensPerAddress,
|
|
9
|
+
ConcreteSalesConfig,
|
|
10
|
+
TimedSaleParamsType,
|
|
11
|
+
} from "./types";
|
|
12
|
+
import { fetchTokenMetadata } from "src/ipfs/token-metadata";
|
|
13
|
+
|
|
14
|
+
// Sales end forever amount (uint64 max)
|
|
15
|
+
export const SALE_END_FOREVER = 18446744073709551615n;
|
|
16
|
+
|
|
17
|
+
const DEFAULT_SALE_START_AND_END: Concrete<SaleStartAndEnd> = {
|
|
18
|
+
// Sale start time – defaults to beginning of unix time
|
|
19
|
+
saleStart: 0n,
|
|
20
|
+
// This is the end of uint64, plenty of time
|
|
21
|
+
saleEnd: SALE_END_FOREVER,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const DEFAULT_MAX_TOKENS_PER_ADDRESS: Concrete<MaxTokensPerAddress> = {
|
|
25
|
+
maxTokensPerAddress: 0n,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const erc20SaleSettingsWithDefaults = (
|
|
29
|
+
params: Erc20ParamsType,
|
|
30
|
+
): Concrete<Erc20ParamsType> => ({
|
|
31
|
+
...DEFAULT_SALE_START_AND_END,
|
|
32
|
+
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
33
|
+
...params,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const allowListWithDefaults = (
|
|
37
|
+
allowlist: AllowListParamType,
|
|
38
|
+
): Concrete<AllowListParamType> => {
|
|
39
|
+
return {
|
|
40
|
+
...DEFAULT_SALE_START_AND_END,
|
|
41
|
+
...allowlist,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const fixedPriceSettingsWithDefaults = (
|
|
46
|
+
params: FixedPriceParamsType,
|
|
47
|
+
): Concrete<FixedPriceParamsType> => ({
|
|
48
|
+
...DEFAULT_SALE_START_AND_END,
|
|
49
|
+
...DEFAULT_MAX_TOKENS_PER_ADDRESS,
|
|
50
|
+
type: "fixedPrice",
|
|
51
|
+
...params,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export const parseNameIntoSymbol = (name: string) => {
|
|
55
|
+
if (name === "") {
|
|
56
|
+
throw new Error("Name must be provided to generate a symbol");
|
|
57
|
+
}
|
|
58
|
+
const result =
|
|
59
|
+
"$" +
|
|
60
|
+
name
|
|
61
|
+
// Remove all non-alphanumeric characters
|
|
62
|
+
.replace(/[^a-zA-Z0-9]/g, "")
|
|
63
|
+
// and leading dollar signs
|
|
64
|
+
.replace(/^\$+/, "")
|
|
65
|
+
.toUpperCase()
|
|
66
|
+
// Remove all vowels and spaces
|
|
67
|
+
.replace(/[AEIOU\s]/g, "")
|
|
68
|
+
// Strip down to 4 characters
|
|
69
|
+
.slice(0, 4);
|
|
70
|
+
|
|
71
|
+
if (result === "$") {
|
|
72
|
+
throw new Error("Not enough valid characters to generate a symbol");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
async function fetchTokenNameFromMetadata(
|
|
79
|
+
tokenMetadataURI: string,
|
|
80
|
+
): Promise<string> {
|
|
81
|
+
const tokenMetadata = await fetchTokenMetadata(tokenMetadataURI);
|
|
82
|
+
|
|
83
|
+
if (!tokenMetadata.name) {
|
|
84
|
+
throw new Error("No name found in token metadata");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return tokenMetadata.name;
|
|
88
|
+
}
|
|
89
|
+
const timedSaleSettingsWithDefaults = async (
|
|
90
|
+
params: TimedSaleParamsType,
|
|
91
|
+
tokenMetadataURI: string,
|
|
92
|
+
): Promise<Concrete<TimedSaleParamsType>> => {
|
|
93
|
+
// If the name is not provided, try to fetch it from the metadata
|
|
94
|
+
const erc20Name =
|
|
95
|
+
params.erc20Name || (await fetchTokenNameFromMetadata(tokenMetadataURI));
|
|
96
|
+
const symbol = params.erc20Symbol || parseNameIntoSymbol(erc20Name);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
type: "timed",
|
|
100
|
+
...DEFAULT_SALE_START_AND_END,
|
|
101
|
+
erc20Name,
|
|
102
|
+
erc20Symbol: symbol,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const isAllowList = (
|
|
107
|
+
salesConfig: SalesConfigParamsType,
|
|
108
|
+
): salesConfig is AllowListParamType => salesConfig.type === "allowlistMint";
|
|
109
|
+
const isErc20 = (
|
|
110
|
+
salesConfig: SalesConfigParamsType,
|
|
111
|
+
): salesConfig is Erc20ParamsType => salesConfig.type === "erc20Mint";
|
|
112
|
+
const isFixedPrice = (
|
|
113
|
+
salesConfig: SalesConfigParamsType,
|
|
114
|
+
): salesConfig is FixedPriceParamsType => {
|
|
115
|
+
return (salesConfig as FixedPriceParamsType).pricePerToken > 0n;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const getSalesConfigWithDefaults = async (
|
|
119
|
+
salesConfig: SalesConfigParamsType | undefined,
|
|
120
|
+
tokenMetadataURI: string,
|
|
121
|
+
): Promise<ConcreteSalesConfig> => {
|
|
122
|
+
if (!salesConfig) return timedSaleSettingsWithDefaults({}, tokenMetadataURI);
|
|
123
|
+
if (isAllowList(salesConfig)) {
|
|
124
|
+
return allowListWithDefaults(salesConfig);
|
|
125
|
+
}
|
|
126
|
+
if (isErc20(salesConfig)) {
|
|
127
|
+
return erc20SaleSettingsWithDefaults(salesConfig);
|
|
128
|
+
}
|
|
129
|
+
if (isFixedPrice(salesConfig)) {
|
|
130
|
+
return fixedPriceSettingsWithDefaults(salesConfig);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return timedSaleSettingsWithDefaults(salesConfig, tokenMetadataURI);
|
|
134
|
+
};
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import {
|
|
2
|
+
erc20MinterABI,
|
|
3
|
+
erc20MinterAddress as erc20MinterAddresses,
|
|
4
|
+
zoraCreator1155ImplABI,
|
|
5
|
+
zoraCreatorFixedPriceSaleStrategyABI,
|
|
6
|
+
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
7
|
+
zoraCreatorMerkleMinterStrategyABI,
|
|
8
|
+
zoraCreatorMerkleMinterStrategyAddress,
|
|
9
|
+
zoraTimedSaleStrategyABI,
|
|
10
|
+
zoraTimedSaleStrategyAddress,
|
|
11
|
+
} from "@zoralabs/protocol-deployments";
|
|
12
|
+
import { Address, encodeFunctionData, Hex } from "viem";
|
|
13
|
+
import {
|
|
14
|
+
AllowlistData,
|
|
15
|
+
ConcreteSalesConfig,
|
|
16
|
+
AllowListParamType,
|
|
17
|
+
Erc20ParamsType,
|
|
18
|
+
FixedPriceParamsType,
|
|
19
|
+
TimedSaleParamsType,
|
|
20
|
+
} from "./types";
|
|
21
|
+
import { Concrete } from "src/utils";
|
|
22
|
+
|
|
23
|
+
const PERMISSION_BITS = {
|
|
24
|
+
MINTER: 2n ** 2n,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type SetupErc20MinterProps = {
|
|
28
|
+
chainId: number;
|
|
29
|
+
tokenId: bigint;
|
|
30
|
+
fundsRecipient: Address;
|
|
31
|
+
} & Concrete<Erc20ParamsType>;
|
|
32
|
+
|
|
33
|
+
type SetupMintersProps = {
|
|
34
|
+
tokenId: bigint;
|
|
35
|
+
chainId: number;
|
|
36
|
+
fundsRecipient: Address;
|
|
37
|
+
salesConfig: ConcreteSalesConfig;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function setupErc20Minter({
|
|
41
|
+
pricePerToken,
|
|
42
|
+
chainId,
|
|
43
|
+
tokenId: nextTokenId,
|
|
44
|
+
currency,
|
|
45
|
+
saleStart,
|
|
46
|
+
saleEnd,
|
|
47
|
+
maxTokensPerAddress: mintLimit,
|
|
48
|
+
fundsRecipient,
|
|
49
|
+
}: SetupErc20MinterProps): {
|
|
50
|
+
minter: Address;
|
|
51
|
+
setupActions: Hex[];
|
|
52
|
+
} {
|
|
53
|
+
const erc20MinterAddress =
|
|
54
|
+
erc20MinterAddresses[chainId as keyof typeof erc20MinterAddresses];
|
|
55
|
+
if (!erc20MinterAddress)
|
|
56
|
+
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
57
|
+
|
|
58
|
+
const erc20MinterApproval = encodeFunctionData({
|
|
59
|
+
abi: zoraCreator1155ImplABI,
|
|
60
|
+
functionName: "addPermission",
|
|
61
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const saleData = encodeFunctionData({
|
|
65
|
+
abi: erc20MinterABI,
|
|
66
|
+
functionName: "setSale",
|
|
67
|
+
args: [
|
|
68
|
+
BigInt(nextTokenId),
|
|
69
|
+
{
|
|
70
|
+
saleStart: saleStart || BigInt(0),
|
|
71
|
+
saleEnd: saleEnd || BigInt(0),
|
|
72
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
73
|
+
pricePerToken: pricePerToken,
|
|
74
|
+
fundsRecipient,
|
|
75
|
+
currency: currency,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const callSale = encodeFunctionData({
|
|
81
|
+
abi: zoraCreator1155ImplABI,
|
|
82
|
+
functionName: "callSale",
|
|
83
|
+
args: [BigInt(nextTokenId), erc20MinterAddress, saleData],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
minter: erc20MinterAddress,
|
|
88
|
+
setupActions: [erc20MinterApproval, callSale],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type SetupFixedPriceMinterProps = {
|
|
93
|
+
fundsRecipient: Address;
|
|
94
|
+
tokenId: bigint;
|
|
95
|
+
chainId: number;
|
|
96
|
+
} & Concrete<FixedPriceParamsType>;
|
|
97
|
+
|
|
98
|
+
function setupFixedPriceMinter({
|
|
99
|
+
pricePerToken: price,
|
|
100
|
+
tokenId: nextTokenId,
|
|
101
|
+
chainId,
|
|
102
|
+
saleStart,
|
|
103
|
+
saleEnd,
|
|
104
|
+
maxTokensPerAddress: mintLimit,
|
|
105
|
+
fundsRecipient,
|
|
106
|
+
}: SetupFixedPriceMinterProps): { minter: Address; setupActions: Hex[] } {
|
|
107
|
+
const fixedPriceStrategyAddress =
|
|
108
|
+
zoraCreatorFixedPriceSaleStrategyAddress[
|
|
109
|
+
chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress
|
|
110
|
+
];
|
|
111
|
+
const fixedPriceApproval = encodeFunctionData({
|
|
112
|
+
abi: zoraCreator1155ImplABI,
|
|
113
|
+
functionName: "addPermission",
|
|
114
|
+
args: [
|
|
115
|
+
BigInt(nextTokenId),
|
|
116
|
+
fixedPriceStrategyAddress,
|
|
117
|
+
PERMISSION_BITS.MINTER,
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const saleData = encodeFunctionData({
|
|
122
|
+
abi: zoraCreatorFixedPriceSaleStrategyABI,
|
|
123
|
+
functionName: "setSale",
|
|
124
|
+
args: [
|
|
125
|
+
BigInt(nextTokenId),
|
|
126
|
+
{
|
|
127
|
+
pricePerToken: price,
|
|
128
|
+
saleStart: saleStart || BigInt(0),
|
|
129
|
+
saleEnd: saleEnd || BigInt(0),
|
|
130
|
+
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
131
|
+
fundsRecipient,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const callSale = encodeFunctionData({
|
|
137
|
+
abi: zoraCreator1155ImplABI,
|
|
138
|
+
functionName: "callSale",
|
|
139
|
+
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
minter: fixedPriceStrategyAddress,
|
|
144
|
+
setupActions: [fixedPriceApproval, callSale],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
type SetupTimedMinterProps = {
|
|
149
|
+
tokenId: bigint;
|
|
150
|
+
chainId: number;
|
|
151
|
+
} & Concrete<TimedSaleParamsType>;
|
|
152
|
+
|
|
153
|
+
function setupTimedSaleMinter({
|
|
154
|
+
chainId,
|
|
155
|
+
tokenId,
|
|
156
|
+
erc20Name: erc20zName,
|
|
157
|
+
erc20Symbol: erc20zSymbol,
|
|
158
|
+
saleStart,
|
|
159
|
+
saleEnd,
|
|
160
|
+
}: SetupTimedMinterProps): {
|
|
161
|
+
minter: Address;
|
|
162
|
+
setupActions: Hex[];
|
|
163
|
+
} {
|
|
164
|
+
const minterAddress =
|
|
165
|
+
zoraTimedSaleStrategyAddress[
|
|
166
|
+
chainId as keyof typeof zoraTimedSaleStrategyAddress
|
|
167
|
+
];
|
|
168
|
+
const fixedPriceApproval = encodeFunctionData({
|
|
169
|
+
abi: zoraCreator1155ImplABI,
|
|
170
|
+
functionName: "addPermission",
|
|
171
|
+
args: [BigInt(tokenId), minterAddress, PERMISSION_BITS.MINTER],
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const saleData = encodeFunctionData({
|
|
175
|
+
abi: zoraTimedSaleStrategyABI,
|
|
176
|
+
functionName: "setSale",
|
|
177
|
+
args: [
|
|
178
|
+
BigInt(tokenId),
|
|
179
|
+
{
|
|
180
|
+
saleStart,
|
|
181
|
+
saleEnd,
|
|
182
|
+
name: erc20zName,
|
|
183
|
+
symbol: erc20zSymbol,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const callSale = encodeFunctionData({
|
|
189
|
+
abi: zoraCreator1155ImplABI,
|
|
190
|
+
functionName: "callSale",
|
|
191
|
+
args: [BigInt(tokenId), minterAddress, saleData],
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
minter: minterAddress,
|
|
196
|
+
setupActions: [fixedPriceApproval, callSale],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function setupAllowListMinter({
|
|
201
|
+
chainId,
|
|
202
|
+
tokenId: nextTokenId,
|
|
203
|
+
allowlist,
|
|
204
|
+
fundsRecipient,
|
|
205
|
+
}: {
|
|
206
|
+
chainId: number;
|
|
207
|
+
tokenId: bigint;
|
|
208
|
+
allowlist: Concrete<AllowlistData>;
|
|
209
|
+
fundsRecipient: Address;
|
|
210
|
+
}) {
|
|
211
|
+
const merkleSaleStrategyAddress =
|
|
212
|
+
zoraCreatorMerkleMinterStrategyAddress[
|
|
213
|
+
chainId as keyof typeof zoraCreatorMerkleMinterStrategyAddress
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
const merkleApproval = encodeFunctionData({
|
|
217
|
+
abi: zoraCreator1155ImplABI,
|
|
218
|
+
functionName: "addPermission",
|
|
219
|
+
args: [nextTokenId, merkleSaleStrategyAddress, PERMISSION_BITS.MINTER],
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const merkleRoot = allowlist.presaleMerkleRoot.startsWith("0x")
|
|
223
|
+
? allowlist.presaleMerkleRoot
|
|
224
|
+
: (`0x${allowlist.presaleMerkleRoot}` as Hex);
|
|
225
|
+
|
|
226
|
+
const saleData = encodeFunctionData({
|
|
227
|
+
abi: zoraCreatorMerkleMinterStrategyABI,
|
|
228
|
+
functionName: "setSale",
|
|
229
|
+
args: [
|
|
230
|
+
BigInt(nextTokenId),
|
|
231
|
+
{
|
|
232
|
+
presaleStart: allowlist.saleStart,
|
|
233
|
+
presaleEnd: allowlist.saleEnd,
|
|
234
|
+
merkleRoot,
|
|
235
|
+
fundsRecipient: fundsRecipient,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const callSaleMerkle = encodeFunctionData({
|
|
241
|
+
abi: zoraCreator1155ImplABI,
|
|
242
|
+
functionName: "callSale",
|
|
243
|
+
args: [BigInt(nextTokenId), merkleSaleStrategyAddress, saleData],
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
minter: merkleSaleStrategyAddress,
|
|
248
|
+
setupActions: [merkleApproval, callSaleMerkle],
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const isAllowList = (
|
|
253
|
+
salesConfig: ConcreteSalesConfig,
|
|
254
|
+
): salesConfig is Concrete<AllowListParamType> =>
|
|
255
|
+
salesConfig.type === "allowlistMint";
|
|
256
|
+
const isErc20 = (
|
|
257
|
+
salesConfig: ConcreteSalesConfig,
|
|
258
|
+
): salesConfig is Concrete<Erc20ParamsType> => salesConfig.type === "erc20Mint";
|
|
259
|
+
const isFixedPrice = (
|
|
260
|
+
salesConfig: ConcreteSalesConfig,
|
|
261
|
+
): salesConfig is Concrete<FixedPriceParamsType> =>
|
|
262
|
+
salesConfig.type === "fixedPrice" ||
|
|
263
|
+
(salesConfig as unknown as Concrete<FixedPriceParamsType>).pricePerToken >
|
|
264
|
+
BigInt(0);
|
|
265
|
+
|
|
266
|
+
export function setupMinters({ salesConfig, ...rest }: SetupMintersProps): {
|
|
267
|
+
minter: Address;
|
|
268
|
+
setupActions: Hex[];
|
|
269
|
+
} {
|
|
270
|
+
if (isErc20(salesConfig)) {
|
|
271
|
+
return setupErc20Minter({
|
|
272
|
+
...salesConfig,
|
|
273
|
+
...rest,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (isAllowList(salesConfig)) {
|
|
277
|
+
return setupAllowListMinter({
|
|
278
|
+
allowlist: salesConfig,
|
|
279
|
+
...rest,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (isFixedPrice(salesConfig))
|
|
284
|
+
return setupFixedPriceMinter({
|
|
285
|
+
...salesConfig,
|
|
286
|
+
...rest,
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return setupTimedSaleMinter({
|
|
290
|
+
...salesConfig,
|
|
291
|
+
...rest,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
@@ -1,60 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
erc20MinterABI,
|
|
3
|
-
erc20MinterAddress as erc20MinterAddresses,
|
|
4
|
-
zoraCreator1155ImplABI,
|
|
5
|
-
zoraCreatorFixedPriceSaleStrategyABI,
|
|
6
|
-
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
7
|
-
} from "@zoralabs/protocol-deployments";
|
|
1
|
+
import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
|
|
8
2
|
import { Address, encodeFunctionData, zeroAddress, Hex } from "viem";
|
|
9
3
|
import * as semver from "semver";
|
|
10
|
-
import {
|
|
11
|
-
ContractProps,
|
|
12
|
-
CreateNew1155TokenProps,
|
|
13
|
-
New1155Token,
|
|
14
|
-
SalesConfigParamsType,
|
|
15
|
-
} from "./types";
|
|
4
|
+
import { ContractProps, CreateNew1155TokenProps, New1155Token } from "./types";
|
|
16
5
|
import { OPEN_EDITION_MINT_SIZE } from "src/constants";
|
|
17
|
-
import {
|
|
6
|
+
import { getSalesConfigWithDefaults } from "./minter-defaults";
|
|
7
|
+
import { setupMinters } from "./minter-setup";
|
|
18
8
|
|
|
19
|
-
|
|
20
|
-
MINTER: 2n ** 2n,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type SetupMintersProps = {
|
|
24
|
-
tokenId: bigint;
|
|
25
|
-
chainId: number;
|
|
26
|
-
fundsRecipient: Address;
|
|
27
|
-
salesConfig: Concrete<SalesConfigParamsType>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Sales end forever amount (uint64 max)
|
|
31
|
-
|
|
32
|
-
const saleSettingsOrDefault = (
|
|
33
|
-
saleSettings?: SalesConfigParamsType,
|
|
34
|
-
): Concrete<SalesConfigParamsType> => {
|
|
35
|
-
const SALE_END_FOREVER = 18446744073709551615n;
|
|
36
|
-
|
|
37
|
-
const DEFAULT_SALE_SETTINGS: Concrete<SalesConfigParamsType> = {
|
|
38
|
-
currency: zeroAddress,
|
|
39
|
-
// Free Mint
|
|
40
|
-
pricePerToken: 0n,
|
|
41
|
-
// Sale start time – defaults to beginning of unix time
|
|
42
|
-
saleStart: 0n,
|
|
43
|
-
// This is the end of uint64, plenty of time
|
|
44
|
-
saleEnd: SALE_END_FOREVER,
|
|
45
|
-
// 0 Here means no limit
|
|
46
|
-
maxTokensPerAddress: 0n,
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
...DEFAULT_SALE_SETTINGS,
|
|
50
|
-
...saleSettings,
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function applyNew1155Defaults(
|
|
9
|
+
async function applyNew1155Defaults(
|
|
55
10
|
props: CreateNew1155TokenProps,
|
|
56
11
|
ownerAddress: Address,
|
|
57
|
-
): New1155Token {
|
|
12
|
+
): Promise<New1155Token> {
|
|
58
13
|
const { payoutRecipient: fundsRecipient } = props;
|
|
59
14
|
const fundsRecipientOrOwner =
|
|
60
15
|
fundsRecipient && fundsRecipient !== zeroAddress
|
|
@@ -68,145 +23,14 @@ function applyNew1155Defaults(
|
|
|
68
23
|
? OPEN_EDITION_MINT_SIZE
|
|
69
24
|
: BigInt(props.maxSupply),
|
|
70
25
|
royaltyBPS: props.royaltyBPS || 1000,
|
|
71
|
-
salesConfig: saleSettingsOrDefault(props.salesConfig),
|
|
72
26
|
tokenMetadataURI: props.tokenMetadataURI,
|
|
27
|
+
salesConfig: await getSalesConfigWithDefaults(
|
|
28
|
+
props.salesConfig,
|
|
29
|
+
props.tokenMetadataURI,
|
|
30
|
+
),
|
|
73
31
|
};
|
|
74
32
|
}
|
|
75
33
|
|
|
76
|
-
type SetupErc20MinterProps = {
|
|
77
|
-
chainId: number;
|
|
78
|
-
tokenId: bigint;
|
|
79
|
-
fundsRecipient: Address;
|
|
80
|
-
} & Concrete<SalesConfigParamsType>;
|
|
81
|
-
|
|
82
|
-
function setupErc20Minter({
|
|
83
|
-
pricePerToken,
|
|
84
|
-
chainId,
|
|
85
|
-
tokenId: nextTokenId,
|
|
86
|
-
currency,
|
|
87
|
-
saleStart,
|
|
88
|
-
saleEnd,
|
|
89
|
-
maxTokensPerAddress: mintLimit,
|
|
90
|
-
fundsRecipient,
|
|
91
|
-
}: SetupErc20MinterProps): {
|
|
92
|
-
minter: Address;
|
|
93
|
-
setupActions: Hex[];
|
|
94
|
-
} {
|
|
95
|
-
const erc20MinterAddress =
|
|
96
|
-
erc20MinterAddresses[chainId as keyof typeof erc20MinterAddresses];
|
|
97
|
-
if (!erc20MinterAddress)
|
|
98
|
-
throw new Error(`ERC20Minter not deployed on chainId ${chainId}`);
|
|
99
|
-
|
|
100
|
-
const erc20MinterApproval = encodeFunctionData({
|
|
101
|
-
abi: zoraCreator1155ImplABI,
|
|
102
|
-
functionName: "addPermission",
|
|
103
|
-
args: [BigInt(nextTokenId), erc20MinterAddress, PERMISSION_BITS.MINTER],
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const saleData = encodeFunctionData({
|
|
107
|
-
abi: erc20MinterABI,
|
|
108
|
-
functionName: "setSale",
|
|
109
|
-
args: [
|
|
110
|
-
BigInt(nextTokenId),
|
|
111
|
-
{
|
|
112
|
-
saleStart: saleStart || BigInt(0),
|
|
113
|
-
saleEnd: saleEnd || BigInt(0),
|
|
114
|
-
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
115
|
-
pricePerToken: pricePerToken,
|
|
116
|
-
fundsRecipient,
|
|
117
|
-
currency: currency,
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const callSale = encodeFunctionData({
|
|
123
|
-
abi: zoraCreator1155ImplABI,
|
|
124
|
-
functionName: "callSale",
|
|
125
|
-
args: [BigInt(nextTokenId), erc20MinterAddress, saleData],
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
minter: erc20MinterAddress,
|
|
130
|
-
setupActions: [erc20MinterApproval, callSale],
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
type SetupFixedPriceMinterProps = {
|
|
135
|
-
fundsRecipient: Address;
|
|
136
|
-
tokenId: bigint;
|
|
137
|
-
chainId: number;
|
|
138
|
-
} & Concrete<Omit<SalesConfigParamsType, "currency">>;
|
|
139
|
-
|
|
140
|
-
function setupFixedPriceMinter({
|
|
141
|
-
pricePerToken: price,
|
|
142
|
-
tokenId: nextTokenId,
|
|
143
|
-
chainId,
|
|
144
|
-
saleStart,
|
|
145
|
-
saleEnd,
|
|
146
|
-
maxTokensPerAddress: mintLimit,
|
|
147
|
-
fundsRecipient,
|
|
148
|
-
}: SetupFixedPriceMinterProps): { minter: Address; setupActions: Hex[] } {
|
|
149
|
-
const fixedPriceStrategyAddress =
|
|
150
|
-
zoraCreatorFixedPriceSaleStrategyAddress[
|
|
151
|
-
chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress
|
|
152
|
-
];
|
|
153
|
-
const fixedPriceApproval = encodeFunctionData({
|
|
154
|
-
abi: zoraCreator1155ImplABI,
|
|
155
|
-
functionName: "addPermission",
|
|
156
|
-
args: [
|
|
157
|
-
BigInt(nextTokenId),
|
|
158
|
-
fixedPriceStrategyAddress,
|
|
159
|
-
PERMISSION_BITS.MINTER,
|
|
160
|
-
],
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
const saleData = encodeFunctionData({
|
|
164
|
-
abi: zoraCreatorFixedPriceSaleStrategyABI,
|
|
165
|
-
functionName: "setSale",
|
|
166
|
-
args: [
|
|
167
|
-
BigInt(nextTokenId),
|
|
168
|
-
{
|
|
169
|
-
pricePerToken: price,
|
|
170
|
-
saleStart: saleStart || BigInt(0),
|
|
171
|
-
saleEnd: saleEnd || BigInt(0),
|
|
172
|
-
maxTokensPerAddress: BigInt(mintLimit || 0),
|
|
173
|
-
fundsRecipient,
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const callSale = encodeFunctionData({
|
|
179
|
-
abi: zoraCreator1155ImplABI,
|
|
180
|
-
functionName: "callSale",
|
|
181
|
-
args: [BigInt(nextTokenId), fixedPriceStrategyAddress, saleData],
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
minter: fixedPriceStrategyAddress,
|
|
186
|
-
setupActions: [fixedPriceApproval, callSale],
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function setupMinters({ salesConfig, ...rest }: SetupMintersProps): {
|
|
191
|
-
minter: Address;
|
|
192
|
-
setupActions: Hex[];
|
|
193
|
-
} {
|
|
194
|
-
if (!salesConfig) throw new Error("No sales config for token");
|
|
195
|
-
const { currency: currencyAddress } = salesConfig;
|
|
196
|
-
|
|
197
|
-
if (currencyAddress === zeroAddress) {
|
|
198
|
-
return setupFixedPriceMinter({
|
|
199
|
-
...salesConfig,
|
|
200
|
-
...rest,
|
|
201
|
-
});
|
|
202
|
-
} else {
|
|
203
|
-
return setupErc20Minter({
|
|
204
|
-
...salesConfig,
|
|
205
|
-
...rest,
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
34
|
function buildSetupNewToken({
|
|
211
35
|
tokenURI,
|
|
212
36
|
maxSupply = OPEN_EDITION_MINT_SIZE,
|
|
@@ -288,17 +112,17 @@ function makeAdminMintCall({
|
|
|
288
112
|
});
|
|
289
113
|
}
|
|
290
114
|
|
|
291
|
-
export function constructCreate1155TokenCalls(
|
|
115
|
+
export async function constructCreate1155TokenCalls(
|
|
292
116
|
props: CreateNew1155TokenProps &
|
|
293
117
|
ContractProps & {
|
|
294
118
|
ownerAddress: Address;
|
|
295
119
|
chainId: number;
|
|
296
120
|
},
|
|
297
|
-
): {
|
|
121
|
+
): Promise<{
|
|
298
122
|
setupActions: `0x${string}`[];
|
|
299
123
|
newToken: New1155Token;
|
|
300
124
|
minter: Address;
|
|
301
|
-
} {
|
|
125
|
+
}> {
|
|
302
126
|
const {
|
|
303
127
|
chainId,
|
|
304
128
|
nextTokenId,
|
|
@@ -307,7 +131,7 @@ export function constructCreate1155TokenCalls(
|
|
|
307
131
|
contractVersion,
|
|
308
132
|
} = props;
|
|
309
133
|
|
|
310
|
-
const new1155TokenPropsWithDefaults = applyNew1155Defaults(
|
|
134
|
+
const new1155TokenPropsWithDefaults = await applyNew1155Defaults(
|
|
311
135
|
props,
|
|
312
136
|
ownerAddress,
|
|
313
137
|
);
|