@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
package/src/mint/mint-client.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Address,
|
|
3
|
-
Chain,
|
|
4
3
|
encodeAbiParameters,
|
|
5
4
|
parseAbiParameters,
|
|
6
5
|
zeroAddress,
|
|
7
6
|
Account,
|
|
8
7
|
SimulateContractParameters,
|
|
8
|
+
erc20Abi,
|
|
9
9
|
} from "viem";
|
|
10
10
|
import {
|
|
11
11
|
erc20MinterABI,
|
|
@@ -13,20 +13,31 @@ import {
|
|
|
13
13
|
zoraCreator1155ImplABI,
|
|
14
14
|
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
15
15
|
} from "@zoralabs/protocol-deployments";
|
|
16
|
-
import { IHttpClient } from "src/apis/http-api-base";
|
|
17
16
|
import { zora721Abi } from "src/constants";
|
|
18
17
|
import { GenericTokenIdTypes } from "src/types";
|
|
19
18
|
import {
|
|
20
|
-
|
|
21
|
-
SalesConfigAndTokenInfo,
|
|
22
|
-
SaleType,
|
|
23
|
-
} from "./mint-api-client";
|
|
24
|
-
import {
|
|
25
|
-
makeSimulateContractParamaters,
|
|
26
|
-
ClientConfig,
|
|
27
|
-
setupClient,
|
|
19
|
+
makeContractParameters,
|
|
28
20
|
PublicClient,
|
|
21
|
+
mintRecipientOrAccount,
|
|
29
22
|
} from "src/utils";
|
|
23
|
+
import {
|
|
24
|
+
IMintGetter,
|
|
25
|
+
SalesConfigAndTokenInfo,
|
|
26
|
+
isErc20SaleStrategy,
|
|
27
|
+
} from "./types";
|
|
28
|
+
import {
|
|
29
|
+
MakeMintParametersArguments,
|
|
30
|
+
MakeMintParametersArgumentsBase,
|
|
31
|
+
Make1155MintArguments,
|
|
32
|
+
MakePremintMintParametersArguments,
|
|
33
|
+
Make721MintArguments,
|
|
34
|
+
GetMintCostsParameters,
|
|
35
|
+
isOnChainMint,
|
|
36
|
+
is1155Mint,
|
|
37
|
+
} from "./types";
|
|
38
|
+
import { collectPremint } from "src/premint/premint-client";
|
|
39
|
+
import { IPremintGetter } from "src/premint/premint-api-client";
|
|
40
|
+
import { getPremintMintCostsWithUnknownTokenPrice } from "src/premint/preminter";
|
|
30
41
|
|
|
31
42
|
class MintError extends Error {}
|
|
32
43
|
class MintInactiveError extends Error {}
|
|
@@ -36,150 +47,247 @@ export const Errors = {
|
|
|
36
47
|
MintInactiveError,
|
|
37
48
|
};
|
|
38
49
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/** Optional address to receive the mint referral reward */
|
|
45
|
-
mintReferral?: Address;
|
|
46
|
-
/** Address to receive the minted tokens */
|
|
47
|
-
mintToAddress: Address;
|
|
48
|
-
saleType?: SaleType;
|
|
49
|
-
};
|
|
50
|
+
export class MintClient {
|
|
51
|
+
private readonly chainId: number;
|
|
52
|
+
private readonly publicClient: PublicClient;
|
|
53
|
+
private readonly mintGetter: IMintGetter;
|
|
54
|
+
private readonly premintGetter: IPremintGetter;
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
readonly apiClient: MintAPIClient;
|
|
64
|
-
readonly publicClient: PublicClient;
|
|
65
|
-
|
|
66
|
-
constructor(
|
|
67
|
-
chain: Chain,
|
|
68
|
-
publicClient: PublicClient,
|
|
69
|
-
httpClient: IHttpClient,
|
|
70
|
-
) {
|
|
71
|
-
this.apiClient = new MintAPIClient(chain.id, httpClient);
|
|
56
|
+
constructor({
|
|
57
|
+
chainId,
|
|
58
|
+
publicClient,
|
|
59
|
+
premintGetter,
|
|
60
|
+
mintGetter,
|
|
61
|
+
}: {
|
|
62
|
+
chainId: number;
|
|
63
|
+
publicClient: PublicClient;
|
|
64
|
+
premintGetter: IPremintGetter;
|
|
65
|
+
mintGetter: IMintGetter;
|
|
66
|
+
}) {
|
|
67
|
+
this.chainId = chainId;
|
|
72
68
|
this.publicClient = publicClient;
|
|
69
|
+
this.mintGetter = mintGetter;
|
|
70
|
+
this.premintGetter = premintGetter;
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
74
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
75
|
+
* Works with premint, onchain 1155, and onchain 721.
|
|
77
76
|
*
|
|
78
|
-
* @param parameters - Parameters for collecting the token {@link
|
|
77
|
+
* @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
|
|
79
78
|
* @returns Parameters for simulating/executing the mint transaction
|
|
80
79
|
*/
|
|
81
|
-
async
|
|
82
|
-
return
|
|
80
|
+
async mint(parameters: MakeMintParametersArguments) {
|
|
81
|
+
return mint({
|
|
82
|
+
parameters,
|
|
83
|
+
chainId: this.chainId,
|
|
84
|
+
publicClient: this.publicClient,
|
|
85
|
+
mintGetter: this.mintGetter,
|
|
86
|
+
premintGetter: this.premintGetter,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
92
|
+
* @param parameters - Parameters for the mint {@link GetMintCostsParameters}
|
|
93
|
+
* @returns Costs to mint the quantity of tokens specified
|
|
94
|
+
*/
|
|
95
|
+
async getMintCosts(parameters: GetMintCostsParameters): Promise<MintCosts> {
|
|
96
|
+
return getMintCosts({
|
|
83
97
|
...parameters,
|
|
84
|
-
|
|
98
|
+
mintGetter: this.mintGetter,
|
|
99
|
+
premintGetter: this.premintGetter,
|
|
85
100
|
publicClient: this.publicClient,
|
|
86
101
|
});
|
|
87
102
|
}
|
|
88
103
|
}
|
|
89
104
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
* @param param0.httpClient Optional http client to override post, get, and retry methods
|
|
95
|
-
* @returns
|
|
96
|
-
*/
|
|
97
|
-
export function createMintClient(clientConfig: ClientConfig) {
|
|
98
|
-
const { chain, publicClient, httpClient } = setupClient(clientConfig);
|
|
99
|
-
return new MintClient(chain, publicClient, httpClient);
|
|
105
|
+
function isPremintCollect(
|
|
106
|
+
parameters: MakeMintParametersArguments,
|
|
107
|
+
): parameters is MakePremintMintParametersArguments {
|
|
108
|
+
return parameters.mintType === "premint";
|
|
100
109
|
}
|
|
101
110
|
|
|
102
|
-
|
|
111
|
+
function is721Collect(
|
|
112
|
+
parameters: MakeMintParametersArguments,
|
|
113
|
+
): parameters is Make721MintArguments {
|
|
114
|
+
return parameters.mintType === "721";
|
|
115
|
+
}
|
|
103
116
|
|
|
104
|
-
async function
|
|
117
|
+
async function mint({
|
|
118
|
+
parameters,
|
|
119
|
+
chainId,
|
|
105
120
|
publicClient,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
tokenAddress,
|
|
109
|
-
mintArguments,
|
|
110
|
-
...rest
|
|
121
|
+
mintGetter,
|
|
122
|
+
premintGetter,
|
|
111
123
|
}: {
|
|
124
|
+
parameters: MakeMintParametersArguments;
|
|
112
125
|
publicClient: PublicClient;
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
mintGetter: IMintGetter;
|
|
127
|
+
premintGetter: IPremintGetter;
|
|
128
|
+
chainId: number;
|
|
129
|
+
}) {
|
|
130
|
+
if (isPremintCollect(parameters)) {
|
|
131
|
+
return {
|
|
132
|
+
parameters: await collectPremint({
|
|
133
|
+
...parameters,
|
|
134
|
+
premintGetter: premintGetter,
|
|
135
|
+
publicClient,
|
|
136
|
+
}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
parameters: await collectOnchain({
|
|
142
|
+
...parameters,
|
|
143
|
+
mintGetter: mintGetter,
|
|
144
|
+
chainId,
|
|
145
|
+
}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function requestErc20ApprovalForMint({
|
|
150
|
+
account,
|
|
151
|
+
tokenAddress,
|
|
152
|
+
quantityErc20,
|
|
153
|
+
erc20MinterAddress,
|
|
154
|
+
}: {
|
|
155
|
+
account: Account | Address;
|
|
115
156
|
tokenAddress: Address;
|
|
116
|
-
|
|
117
|
-
|
|
157
|
+
quantityErc20: bigint;
|
|
158
|
+
erc20MinterAddress: Address;
|
|
159
|
+
}) {
|
|
160
|
+
return makeContractParameters({
|
|
161
|
+
abi: erc20Abi,
|
|
162
|
+
address: tokenAddress,
|
|
163
|
+
account,
|
|
164
|
+
functionName: "approve",
|
|
165
|
+
args: [erc20MinterAddress, quantityErc20],
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export async function getNecessaryErc20Approval({
|
|
170
|
+
chainId,
|
|
171
|
+
account,
|
|
172
|
+
tokenAddress,
|
|
173
|
+
quantityErc20,
|
|
174
|
+
publicClient,
|
|
175
|
+
}: {
|
|
176
|
+
chainId: number;
|
|
177
|
+
account: Account | Address;
|
|
178
|
+
tokenAddress: Address;
|
|
179
|
+
quantityErc20: bigint;
|
|
180
|
+
publicClient: PublicClient;
|
|
181
|
+
}) {
|
|
182
|
+
const destination =
|
|
183
|
+
erc20MinterAddress[chainId as keyof typeof erc20MinterAddress];
|
|
184
|
+
const allowance = await publicClient.readContract({
|
|
185
|
+
abi: erc20Abi,
|
|
186
|
+
address: tokenAddress,
|
|
187
|
+
functionName: "allowance",
|
|
188
|
+
account,
|
|
189
|
+
args: [
|
|
190
|
+
destination,
|
|
191
|
+
erc20MinterAddress[chainId as keyof typeof erc20MinterAddress],
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (allowance < quantityErc20) {
|
|
196
|
+
return requestErc20ApprovalForMint({
|
|
197
|
+
erc20MinterAddress: destination,
|
|
198
|
+
account,
|
|
199
|
+
tokenAddress,
|
|
200
|
+
quantityErc20: quantityErc20 - allowance,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function collectOnchain({
|
|
208
|
+
chainId,
|
|
209
|
+
mintGetter,
|
|
210
|
+
...parameters
|
|
211
|
+
}: (Make1155MintArguments | Make721MintArguments) & {
|
|
212
|
+
mintGetter: IMintGetter;
|
|
213
|
+
chainId: number;
|
|
118
214
|
}): Promise<
|
|
119
215
|
SimulateContractParameters<any, any, any, any, any, Account | Address>
|
|
120
216
|
> {
|
|
121
|
-
const
|
|
217
|
+
const { tokenContract: tokenContract, saleType } = parameters;
|
|
218
|
+
const tokenId = is1155Mint(parameters) ? parameters.tokenId : undefined;
|
|
219
|
+
const salesConfigAndTokenInfo = await mintGetter.getSalesConfigAndTokenInfo({
|
|
122
220
|
tokenId,
|
|
123
|
-
tokenAddress,
|
|
124
|
-
saleType
|
|
221
|
+
tokenAddress: tokenContract,
|
|
222
|
+
saleType,
|
|
125
223
|
});
|
|
126
224
|
|
|
127
|
-
if (
|
|
225
|
+
if (is721Collect(parameters)) {
|
|
128
226
|
return makePrepareMint721TokenParams({
|
|
129
227
|
salesConfigAndTokenInfo,
|
|
130
|
-
|
|
131
|
-
mintArguments,
|
|
132
|
-
...rest,
|
|
228
|
+
...parameters,
|
|
133
229
|
});
|
|
134
230
|
}
|
|
135
231
|
|
|
136
232
|
return makePrepareMint1155TokenParams({
|
|
137
233
|
salesConfigAndTokenInfo,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
mintArguments,
|
|
141
|
-
...rest,
|
|
234
|
+
chainId,
|
|
235
|
+
...parameters,
|
|
142
236
|
});
|
|
143
237
|
}
|
|
144
238
|
|
|
145
239
|
async function makePrepareMint721TokenParams({
|
|
146
|
-
tokenAddress,
|
|
147
240
|
salesConfigAndTokenInfo,
|
|
148
241
|
minterAccount,
|
|
149
|
-
|
|
242
|
+
tokenContract,
|
|
243
|
+
mintComment,
|
|
244
|
+
mintReferral,
|
|
245
|
+
mintRecipient,
|
|
246
|
+
quantityToMint,
|
|
150
247
|
}: {
|
|
151
|
-
tokenAddress: Address;
|
|
152
248
|
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
249
|
+
} & Pick<
|
|
250
|
+
MakeMintParametersArgumentsBase,
|
|
251
|
+
| "minterAccount"
|
|
252
|
+
| "tokenContract"
|
|
253
|
+
| "mintComment"
|
|
254
|
+
| "mintReferral"
|
|
255
|
+
| "quantityToMint"
|
|
256
|
+
| "mintRecipient"
|
|
257
|
+
>) {
|
|
258
|
+
const actualQuantityToMint = BigInt(quantityToMint || 1);
|
|
259
|
+
const mintValue = parseMintCosts({
|
|
157
260
|
salesConfigAndTokenInfo,
|
|
158
|
-
quantityToMint:
|
|
159
|
-
}).
|
|
261
|
+
quantityToMint: actualQuantityToMint,
|
|
262
|
+
}).totalCostEth;
|
|
160
263
|
|
|
161
|
-
return
|
|
264
|
+
return makeContractParameters({
|
|
162
265
|
abi: zora721Abi,
|
|
163
|
-
address:
|
|
266
|
+
address: tokenContract,
|
|
164
267
|
account: minterAccount,
|
|
165
268
|
functionName: "mintWithRewards",
|
|
166
269
|
value: mintValue,
|
|
167
270
|
args: [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
271
|
+
mintRecipientOrAccount({ mintRecipient, minterAccount }),
|
|
272
|
+
actualQuantityToMint,
|
|
273
|
+
mintComment || "",
|
|
274
|
+
mintReferral || zeroAddress,
|
|
172
275
|
],
|
|
173
276
|
});
|
|
174
277
|
}
|
|
175
278
|
|
|
176
279
|
export type MintCosts = {
|
|
280
|
+
/** The total of the mint fee, in eth */
|
|
177
281
|
mintFee: bigint;
|
|
178
|
-
|
|
179
|
-
|
|
282
|
+
/** If it is a paid or erc20 mint, the total price of the paid or erc20 mint in eth or erc20 value correspondingly. */
|
|
283
|
+
totalPurchaseCost: bigint;
|
|
284
|
+
/** If it is an erc20 mint, the erc20 address */
|
|
285
|
+
totalPurchaseCostCurrency?: Address;
|
|
286
|
+
/** The total cost in eth (mint fee + purchase cost) to mint */
|
|
287
|
+
totalCostEth: bigint;
|
|
180
288
|
};
|
|
181
289
|
|
|
182
|
-
export function
|
|
290
|
+
export function parseMintCosts({
|
|
183
291
|
salesConfigAndTokenInfo,
|
|
184
292
|
quantityToMint,
|
|
185
293
|
}: {
|
|
@@ -188,83 +296,139 @@ export function getMintCosts({
|
|
|
188
296
|
}): MintCosts {
|
|
189
297
|
const mintFeeForTokens =
|
|
190
298
|
salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
299
|
+
|
|
191
300
|
const tokenPurchaseCost =
|
|
192
301
|
BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
|
|
193
302
|
|
|
303
|
+
const totalPurchaseCostCurrency = isErc20SaleStrategy(
|
|
304
|
+
salesConfigAndTokenInfo.salesConfig,
|
|
305
|
+
)
|
|
306
|
+
? salesConfigAndTokenInfo.salesConfig.currency
|
|
307
|
+
: undefined;
|
|
308
|
+
|
|
309
|
+
const totalPurchaseCostEth = totalPurchaseCostCurrency
|
|
310
|
+
? 0n
|
|
311
|
+
: tokenPurchaseCost;
|
|
312
|
+
|
|
194
313
|
return {
|
|
195
314
|
mintFee: mintFeeForTokens,
|
|
196
|
-
tokenPurchaseCost,
|
|
197
|
-
|
|
315
|
+
totalPurchaseCost: tokenPurchaseCost,
|
|
316
|
+
totalPurchaseCostCurrency,
|
|
317
|
+
totalCostEth: mintFeeForTokens + totalPurchaseCostEth,
|
|
198
318
|
};
|
|
199
319
|
}
|
|
200
320
|
|
|
201
|
-
async function
|
|
321
|
+
export async function getMintCosts(
|
|
322
|
+
params: GetMintCostsParameters & {
|
|
323
|
+
mintGetter: IMintGetter;
|
|
324
|
+
premintGetter: IPremintGetter;
|
|
325
|
+
publicClient: PublicClient;
|
|
326
|
+
},
|
|
327
|
+
) {
|
|
328
|
+
const { quantityMinted: quantityToMint, collection, publicClient } = params;
|
|
329
|
+
if (isOnChainMint(params)) {
|
|
330
|
+
const tokenId = is1155Mint(params) ? params.tokenId : undefined;
|
|
331
|
+
const salesConfigAndTokenInfo =
|
|
332
|
+
await params.mintGetter.getSalesConfigAndTokenInfo({
|
|
333
|
+
tokenId,
|
|
334
|
+
tokenAddress: collection,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
return parseMintCosts({
|
|
338
|
+
salesConfigAndTokenInfo,
|
|
339
|
+
quantityToMint: BigInt(quantityToMint),
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return getPremintMintCostsWithUnknownTokenPrice({
|
|
344
|
+
premintGetter: params.premintGetter,
|
|
345
|
+
publicClient: publicClient,
|
|
346
|
+
quantityToMint: BigInt(quantityToMint),
|
|
347
|
+
uid: params.uid,
|
|
348
|
+
tokenContract: collection,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function makePrepareMint1155TokenParams({
|
|
353
|
+
tokenContract: tokenContract,
|
|
202
354
|
tokenId,
|
|
203
355
|
salesConfigAndTokenInfo,
|
|
204
356
|
minterAccount,
|
|
205
|
-
|
|
206
|
-
|
|
357
|
+
mintComment,
|
|
358
|
+
mintReferral,
|
|
359
|
+
mintRecipient,
|
|
360
|
+
quantityToMint,
|
|
361
|
+
chainId,
|
|
207
362
|
}: {
|
|
208
363
|
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
364
|
+
chainId: number;
|
|
209
365
|
tokenId: GenericTokenIdTypes;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
366
|
+
} & Pick<
|
|
367
|
+
MakeMintParametersArgumentsBase,
|
|
368
|
+
| "minterAccount"
|
|
369
|
+
| "tokenContract"
|
|
370
|
+
| "mintComment"
|
|
371
|
+
| "mintReferral"
|
|
372
|
+
| "quantityToMint"
|
|
373
|
+
| "mintRecipient"
|
|
374
|
+
>) {
|
|
375
|
+
const mintQuantity = BigInt(quantityToMint || 1);
|
|
215
376
|
|
|
216
|
-
const
|
|
217
|
-
salesConfigAndTokenInfo,
|
|
218
|
-
quantityToMint: mintQuantity,
|
|
219
|
-
}).totalCost;
|
|
220
|
-
|
|
221
|
-
switch (salesConfigAndTokenInfo.salesConfig.saleType) {
|
|
222
|
-
case "fixedPrice":
|
|
223
|
-
const fixedPriceArgs = mintArguments;
|
|
224
|
-
|
|
225
|
-
return makeSimulateContractParamaters({
|
|
226
|
-
abi: zoraCreator1155ImplABI,
|
|
227
|
-
functionName: "mintWithRewards",
|
|
228
|
-
account: minterAccount,
|
|
229
|
-
value: mintValue,
|
|
230
|
-
address: tokenAddress,
|
|
231
|
-
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
232
|
-
args: [
|
|
233
|
-
(salesConfigAndTokenInfo.salesConfig.address ||
|
|
234
|
-
zoraCreatorFixedPriceSaleStrategyAddress[999999999]) as Address,
|
|
235
|
-
BigInt(tokenId),
|
|
236
|
-
mintQuantity,
|
|
237
|
-
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
238
|
-
fixedPriceArgs.mintToAddress,
|
|
239
|
-
fixedPriceArgs.mintComment || "",
|
|
240
|
-
]),
|
|
241
|
-
fixedPriceArgs.mintReferral || zeroAddress,
|
|
242
|
-
],
|
|
243
|
-
});
|
|
377
|
+
const mintTo = mintRecipientOrAccount({ mintRecipient, minterAccount });
|
|
244
378
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
address: (salesConfigAndTokenInfo?.salesConfig.address ||
|
|
253
|
-
erc20MinterAddress[999999999]) as Address,
|
|
254
|
-
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
255
|
-
args: [
|
|
256
|
-
mintArguments.mintToAddress,
|
|
257
|
-
mintQuantity,
|
|
258
|
-
tokenAddress,
|
|
259
|
-
BigInt(tokenId),
|
|
260
|
-
salesConfigAndTokenInfo.salesConfig.pricePerToken,
|
|
261
|
-
salesConfigAndTokenInfo.salesConfig.currency,
|
|
262
|
-
erc20Args.mintReferral || zeroAddress,
|
|
263
|
-
erc20Args.mintComment || "",
|
|
264
|
-
],
|
|
265
|
-
});
|
|
379
|
+
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
380
|
+
|
|
381
|
+
if (saleType === "fixedPrice") {
|
|
382
|
+
const mintValue = parseMintCosts({
|
|
383
|
+
salesConfigAndTokenInfo,
|
|
384
|
+
quantityToMint: mintQuantity,
|
|
385
|
+
}).totalCostEth;
|
|
266
386
|
|
|
267
|
-
|
|
268
|
-
|
|
387
|
+
return makeContractParameters({
|
|
388
|
+
abi: zoraCreator1155ImplABI,
|
|
389
|
+
functionName: "mintWithRewards",
|
|
390
|
+
account: minterAccount,
|
|
391
|
+
value: mintValue,
|
|
392
|
+
address: tokenContract,
|
|
393
|
+
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
394
|
+
args: [
|
|
395
|
+
(salesConfigAndTokenInfo.salesConfig.address ||
|
|
396
|
+
zoraCreatorFixedPriceSaleStrategyAddress[
|
|
397
|
+
chainId as keyof typeof zoraCreatorFixedPriceSaleStrategyAddress
|
|
398
|
+
]) as Address,
|
|
399
|
+
BigInt(tokenId),
|
|
400
|
+
mintQuantity,
|
|
401
|
+
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
402
|
+
mintTo,
|
|
403
|
+
mintComment || "",
|
|
404
|
+
]),
|
|
405
|
+
mintReferral || zeroAddress,
|
|
406
|
+
],
|
|
407
|
+
});
|
|
269
408
|
}
|
|
409
|
+
|
|
410
|
+
if (saleType === "erc20") {
|
|
411
|
+
return makeContractParameters({
|
|
412
|
+
abi: erc20MinterABI,
|
|
413
|
+
functionName: "mint",
|
|
414
|
+
account: minterAccount,
|
|
415
|
+
address: (salesConfigAndTokenInfo?.salesConfig.address ||
|
|
416
|
+
erc20MinterAddress[
|
|
417
|
+
chainId as keyof typeof erc20MinterAddress
|
|
418
|
+
]) as Address,
|
|
419
|
+
/* args: mintTo, quantity, tokenAddress, tokenId, totalValue, currency, mintReferral, comment */
|
|
420
|
+
args: [
|
|
421
|
+
mintTo,
|
|
422
|
+
mintQuantity,
|
|
423
|
+
tokenContract,
|
|
424
|
+
BigInt(tokenId),
|
|
425
|
+
salesConfigAndTokenInfo.salesConfig.pricePerToken * mintQuantity,
|
|
426
|
+
salesConfigAndTokenInfo.salesConfig.currency,
|
|
427
|
+
mintReferral || zeroAddress,
|
|
428
|
+
mintComment || "",
|
|
429
|
+
],
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
throw new MintError("Unsupported sale type");
|
|
270
434
|
}
|
|
@@ -5,10 +5,9 @@ import {
|
|
|
5
5
|
} from "../apis/http-api-base";
|
|
6
6
|
import { NetworkConfig, networkConfigByChain } from "src/apis/chain-constants";
|
|
7
7
|
import { GenericTokenIdTypes } from "src/types";
|
|
8
|
+
import { IMintGetter, SalesConfigAndTokenInfo, SaleType } from "./types";
|
|
8
9
|
import { NFT_SALE_QUERY } from "src/constants";
|
|
9
10
|
|
|
10
|
-
export type SaleType = "fixedPrice" | "erc20";
|
|
11
|
-
|
|
12
11
|
type FixedPriceSaleStrategyResult = {
|
|
13
12
|
address: Address;
|
|
14
13
|
pricePerToken: string;
|
|
@@ -40,28 +39,6 @@ type TokenQueryResult = {
|
|
|
40
39
|
};
|
|
41
40
|
};
|
|
42
41
|
|
|
43
|
-
type SaleStrategy<T extends SaleType> = {
|
|
44
|
-
saleType: T;
|
|
45
|
-
address: Address;
|
|
46
|
-
pricePerToken: bigint;
|
|
47
|
-
saleEnd: string;
|
|
48
|
-
saleStart: string;
|
|
49
|
-
maxTokensPerAddress: bigint;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice">;
|
|
53
|
-
|
|
54
|
-
type ERC20SaleStrategy = SaleStrategy<"erc20"> & {
|
|
55
|
-
currency: Address;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
type SaleStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
|
|
59
|
-
|
|
60
|
-
export type SalesConfigAndTokenInfo = {
|
|
61
|
-
salesConfig: SaleStrategies;
|
|
62
|
-
mintFeePerQuantity: bigint;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
42
|
export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
|
|
66
43
|
if (!networkConfigByChain[chainId]) {
|
|
67
44
|
throw new Error(`chain id ${chainId} network not configured `);
|
|
@@ -69,7 +46,7 @@ export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
|
|
|
69
46
|
return networkConfigByChain[chainId]!;
|
|
70
47
|
};
|
|
71
48
|
|
|
72
|
-
export class
|
|
49
|
+
export class SubgraphMintGetter implements IMintGetter {
|
|
73
50
|
httpClient: IHttpClient;
|
|
74
51
|
networkConfig: NetworkConfig;
|
|
75
52
|
|