@zoralabs/protocol-sdk 0.7.6 → 0.9.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 +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 +14 -11
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/contract-setup.d.ts +13 -8
- package/dist/create/contract-setup.d.ts.map +1 -1
- 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 +53 -13
- 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 +1660 -1246
- 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 +1681 -1264
- 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 +3 -1
- 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 +32 -13
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/sdk.d.ts +2 -1
- package/dist/sdk.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 -3
- 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 +269 -113
- package/src/create/1155-create-helper.ts +204 -90
- package/src/create/contract-setup.ts +54 -44
- 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 +94 -25
- 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 +34 -13
- 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 +55 -16
- package/src/premint/premint-client.test.ts +6 -5
- package/src/sdk.ts +5 -2
- package/src/types.ts +1 -1
- package/src/utils.ts +1 -25
|
@@ -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
|
);
|
package/src/create/types.ts
CHANGED
|
@@ -1,57 +1,126 @@
|
|
|
1
1
|
import { Concrete } from "src/utils";
|
|
2
|
-
import { Address, Hex } from "viem";
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export type SalesConfigParamsType = {
|
|
13
|
-
// defaults to 0
|
|
14
|
-
pricePerToken?: bigint;
|
|
2
|
+
import { Account, Address, Hex, SimulateContractParameters } from "viem";
|
|
3
|
+
|
|
4
|
+
export type NewContractParams = {
|
|
5
|
+
name: string;
|
|
6
|
+
uri: string;
|
|
7
|
+
defaultAdmin?: Address;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type SaleStartAndEnd = {
|
|
15
11
|
// defaults to 0, in seconds
|
|
16
12
|
saleStart?: bigint;
|
|
17
13
|
// defaults to forever, in seconds
|
|
18
14
|
saleEnd?: bigint;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type MaxTokensPerAddress = {
|
|
19
18
|
// max tokens that can be minted per address
|
|
20
19
|
maxTokensPerAddress?: bigint;
|
|
21
|
-
// if an erc20 mint, the erc20 address. Leave null for eth mints
|
|
22
|
-
currency?: Address;
|
|
23
20
|
};
|
|
24
21
|
|
|
25
|
-
export type
|
|
22
|
+
export type FixedPriceParamsType = SaleStartAndEnd &
|
|
23
|
+
MaxTokensPerAddress & {
|
|
24
|
+
type?: "fixedPrice";
|
|
25
|
+
// the price per token, if it is a priced mint
|
|
26
|
+
pricePerToken: bigint;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type TimedSaleParamsType = SaleStartAndEnd & {
|
|
30
|
+
type?: "timed";
|
|
31
|
+
// Name of the erc20z token to create for the secondary sale. If not provided, fetches the metadata from the tokenMetadataURI and uses the name from it.
|
|
32
|
+
erc20Name?: string;
|
|
33
|
+
// Symbol of the erc20z token to create for the secondary sale. If not provided, extracts it from the name.
|
|
34
|
+
erc20Symbol?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type Erc20ParamsType = SaleStartAndEnd &
|
|
38
|
+
MaxTokensPerAddress & {
|
|
39
|
+
type: "erc20Mint";
|
|
40
|
+
// if the erc20 address of the token to mint against
|
|
41
|
+
currency: Address;
|
|
42
|
+
// price in currency per token
|
|
43
|
+
pricePerToken: bigint;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type AllowListParamType = SaleStartAndEnd & {
|
|
47
|
+
type: "allowlistMint";
|
|
48
|
+
// the merkle root of the allowlist
|
|
49
|
+
presaleMerkleRoot: `0x${string}`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type SalesConfigParamsType =
|
|
53
|
+
| AllowListParamType
|
|
54
|
+
| Erc20ParamsType
|
|
55
|
+
| FixedPriceParamsType
|
|
56
|
+
| TimedSaleParamsType;
|
|
57
|
+
|
|
58
|
+
export type CreateNew1155ParamsBase = {
|
|
26
59
|
account: Address;
|
|
27
|
-
|
|
28
|
-
getAdditionalSetupActions?: (args: {
|
|
29
|
-
tokenId: bigint;
|
|
30
|
-
contractAddress: Address;
|
|
31
|
-
}) => Hex[];
|
|
60
|
+
getAdditionalSetupActions?: (args: { tokenId: bigint }) => Hex[];
|
|
32
61
|
token: CreateNew1155TokenProps;
|
|
33
62
|
};
|
|
34
63
|
|
|
35
|
-
export
|
|
64
|
+
export type CreateNew1155ContractParams = CreateNew1155ParamsBase & {
|
|
65
|
+
contract: NewContractParams;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type CreateNew1155TokenParams = CreateNew1155ParamsBase & {
|
|
69
|
+
contractAddress: Address;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type AllowlistData = {
|
|
73
|
+
saleStart?: bigint;
|
|
74
|
+
saleEnd?: bigint;
|
|
75
|
+
presaleMerkleRoot: `0x${string}`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type CreateNew1155TokenProps = {
|
|
36
79
|
maxSupply?: bigint | number;
|
|
37
80
|
tokenMetadataURI: string;
|
|
38
81
|
royaltyBPS?: number;
|
|
39
|
-
salesConfig?: SalesConfigParamsType;
|
|
40
82
|
createReferral?: Address;
|
|
41
83
|
mintToCreatorCount?: number;
|
|
42
84
|
payoutRecipient?: Address;
|
|
43
|
-
|
|
85
|
+
salesConfig?: SalesConfigParamsType;
|
|
86
|
+
};
|
|
44
87
|
|
|
45
88
|
export interface ContractProps {
|
|
46
89
|
nextTokenId: bigint;
|
|
47
90
|
contractVersion: string;
|
|
48
91
|
}
|
|
49
92
|
|
|
93
|
+
export type ConcreteSalesConfig =
|
|
94
|
+
| Concrete<FixedPriceParamsType>
|
|
95
|
+
| Concrete<Erc20ParamsType>
|
|
96
|
+
| Concrete<AllowListParamType>
|
|
97
|
+
| Concrete<TimedSaleParamsType>;
|
|
98
|
+
|
|
50
99
|
export type New1155Token = {
|
|
51
100
|
payoutRecipient: Address;
|
|
52
101
|
createReferral: Address;
|
|
53
102
|
maxSupply: bigint;
|
|
54
103
|
royaltyBPS: number;
|
|
55
|
-
salesConfig: Concrete<SalesConfigParamsType>;
|
|
56
104
|
tokenMetadataURI: string;
|
|
105
|
+
salesConfig: ConcreteSalesConfig;
|
|
57
106
|
};
|
|
107
|
+
|
|
108
|
+
export type CreateNew1155TokenReturn = {
|
|
109
|
+
parameters: SimulateContractParameters<
|
|
110
|
+
any,
|
|
111
|
+
any,
|
|
112
|
+
any,
|
|
113
|
+
any,
|
|
114
|
+
any,
|
|
115
|
+
Account | Address
|
|
116
|
+
>;
|
|
117
|
+
tokenSetupActions: Hex[];
|
|
118
|
+
newTokenId: bigint;
|
|
119
|
+
newToken: New1155Token;
|
|
120
|
+
minter: Address;
|
|
121
|
+
contractVersion: string;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export type CreateNew1155ContractAndTokenReturn = {
|
|
125
|
+
contractAddress: Address;
|
|
126
|
+
} & CreateNew1155TokenReturn;
|