@zoralabs/protocol-sdk 0.3.4 → 0.4.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 +34 -0
- package/README.md +30 -58
- package/dist/anvil.d.ts +4 -2
- package/dist/anvil.d.ts.map +1 -1
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.cjs +819 -518
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +788 -493
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +16 -216
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +7 -227
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/contract-types.d.ts +125 -0
- package/dist/premint/contract-types.d.ts.map +1 -0
- package/dist/premint/premint-api-client.d.ts +14 -7
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +45 -115
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +102 -21
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/anvil.ts +7 -4
- package/src/constants.ts +7 -0
- package/src/index.ts +2 -0
- package/src/mint/mint-api-client.ts +72 -68
- package/src/mint/mint-client.test.ts +9 -11
- package/src/mint/mint-client.ts +51 -221
- package/src/premint/contract-types.ts +109 -0
- package/src/premint/premint-api-client.ts +162 -22
- package/src/premint/premint-client.test.ts +186 -84
- package/src/premint/premint-client.ts +357 -289
- package/src/premint/preminter.test.ts +209 -130
- package/src/premint/preminter.ts +377 -54
- package/src/types.ts +1 -0
- package/dist/apis/generated/discover-api-types.d.ts +0 -2131
- package/dist/apis/generated/discover-api-types.d.ts.map +0 -1
- package/src/apis/generated/discover-api-types.ts +0 -2180
|
@@ -2,23 +2,26 @@ import {
|
|
|
2
2
|
httpClient as defaultHttpClient,
|
|
3
3
|
IHttpClient,
|
|
4
4
|
} from "../apis/http-api-base";
|
|
5
|
-
import { paths } from "../apis/generated/discover-api-types";
|
|
6
|
-
import { ZORA_API_BASE } from "../constants";
|
|
7
5
|
import { NetworkConfig, networkConfigByChain } from "src/apis/chain-constants";
|
|
6
|
+
import { GenericTokenIdTypes } from "src/types";
|
|
8
7
|
import { Address } from "viem";
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
MintableGetToken["get"]["responses"][200]["content"]["application/json"];
|
|
9
|
+
type FixedPriceSaleStrategyResult = {
|
|
10
|
+
address: Address;
|
|
11
|
+
pricePerToken: string;
|
|
12
|
+
saleEnd: string;
|
|
13
|
+
saleStart: string;
|
|
14
|
+
maxTokensPerAddress: string;
|
|
15
|
+
};
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
17
|
+
type SaleStrategyResult = {
|
|
18
|
+
fixedPrice: FixedPriceSaleStrategyResult;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type SalesConfigAndTokenInfo = {
|
|
22
|
+
fixedPrice: FixedPriceSaleStrategyResult;
|
|
23
|
+
mintFeePerQuantity: bigint;
|
|
24
|
+
};
|
|
22
25
|
|
|
23
26
|
export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
|
|
24
27
|
if (!networkConfigByChain[chainId]) {
|
|
@@ -36,76 +39,77 @@ export class MintAPIClient {
|
|
|
36
39
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
async
|
|
40
|
-
|
|
41
|
-
query: MintableGetTokenGetQueryParameters,
|
|
42
|
-
): Promise<MintableGetTokenResponse> {
|
|
43
|
-
const httpClient = this.httpClient;
|
|
44
|
-
return httpClient.retries(() => {
|
|
45
|
-
return httpClient.get<MintableGetTokenResponse>(
|
|
46
|
-
`${ZORA_API_BASE}discover/mintables/${path.chain_name}/${
|
|
47
|
-
path.collection_address
|
|
48
|
-
}${query?.token_id ? `?${encodeQueryParameters(query)}` : ""}`,
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async getSalesConfigFixedPrice({
|
|
54
|
-
contractAddress,
|
|
42
|
+
async getSalesConfigAndTokenInfo({
|
|
43
|
+
tokenAddress,
|
|
55
44
|
tokenId,
|
|
56
45
|
}: {
|
|
57
|
-
|
|
58
|
-
tokenId
|
|
59
|
-
}): Promise<
|
|
46
|
+
tokenAddress: Address;
|
|
47
|
+
tokenId?: GenericTokenIdTypes;
|
|
48
|
+
}): Promise<SalesConfigAndTokenInfo> {
|
|
60
49
|
const { retries, post } = this.httpClient;
|
|
61
50
|
return retries(async () => {
|
|
62
51
|
const response = await post<any>(this.networkConfig.subgraphUrl, {
|
|
63
|
-
query: `
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
52
|
+
query: `
|
|
53
|
+
fragment SaleStrategy on SalesStrategyConfig {
|
|
54
|
+
type
|
|
55
|
+
fixedPrice {
|
|
56
|
+
address
|
|
57
|
+
pricePerToken
|
|
58
|
+
saleEnd
|
|
59
|
+
saleStart
|
|
60
|
+
maxTokensPerAddress
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
query ($id: ID!) {
|
|
65
|
+
zoraCreateToken(id: $id) {
|
|
66
|
+
id
|
|
67
|
+
contract {
|
|
68
|
+
mintFeePerQuantity
|
|
69
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
70
|
+
...SaleStrategy
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
salesStrategies(where: {type: "FIXED_PRICE"}) {
|
|
74
|
+
...SaleStrategy
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
+
`,
|
|
78
79
|
variables: {
|
|
79
|
-
id:
|
|
80
|
+
id:
|
|
81
|
+
tokenId !== undefined
|
|
82
|
+
? // Generic Token ID types all stringify down to the base numeric equivalent.
|
|
83
|
+
`${tokenAddress.toLowerCase()}-${tokenId}`
|
|
84
|
+
: `${tokenAddress.toLowerCase()}-0`,
|
|
80
85
|
},
|
|
81
86
|
});
|
|
82
87
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
const token = response.data?.zoraCreateToken;
|
|
89
|
+
|
|
90
|
+
if (!token) {
|
|
91
|
+
throw new Error("Cannot find a token to mint");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const saleStrategies: SaleStrategyResult[] =
|
|
95
|
+
tokenId !== undefined
|
|
96
|
+
? token.salesStrategies
|
|
97
|
+
: token.contract.salesStrategies;
|
|
98
|
+
|
|
99
|
+
const fixedPrice = saleStrategies
|
|
100
|
+
?.sort((a: SaleStrategyResult, b: SaleStrategyResult) =>
|
|
101
|
+
BigInt(a.fixedPrice.saleEnd) > BigInt(b.fixedPrice.saleEnd) ? 1 : -1,
|
|
102
|
+
)
|
|
103
|
+
?.find(() => true)?.fixedPrice;
|
|
104
|
+
|
|
105
|
+
if (!fixedPrice) {
|
|
106
|
+
throw new Error("Cannot find fixed price sale strategy");
|
|
107
|
+
}
|
|
88
108
|
|
|
89
109
|
return {
|
|
90
|
-
|
|
91
|
-
|
|
110
|
+
fixedPrice,
|
|
111
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
|
|
92
112
|
};
|
|
93
113
|
});
|
|
94
114
|
}
|
|
95
|
-
|
|
96
|
-
async getMintableForToken({
|
|
97
|
-
tokenContract,
|
|
98
|
-
tokenId,
|
|
99
|
-
}: {
|
|
100
|
-
tokenContract: Address;
|
|
101
|
-
tokenId?: bigint | number | string;
|
|
102
|
-
}) {
|
|
103
|
-
return await this.getMintable(
|
|
104
|
-
{
|
|
105
|
-
chain_name: this.networkConfig.zoraBackendChainName,
|
|
106
|
-
collection_address: tokenContract,
|
|
107
|
-
},
|
|
108
|
-
{ token_id: tokenId?.toString() },
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
115
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseAbi, parseEther } from "viem";
|
|
1
|
+
import { Address, parseAbi, parseEther } from "viem";
|
|
2
2
|
import { zora } from "viem/chains";
|
|
3
3
|
import { describe, expect } from "vitest";
|
|
4
4
|
import { createMintClient } from "./mint-client";
|
|
@@ -19,16 +19,15 @@ describe("mint-helper", () => {
|
|
|
19
19
|
address: creatorAccount,
|
|
20
20
|
value: parseEther("2000"),
|
|
21
21
|
});
|
|
22
|
-
const targetContract =
|
|
22
|
+
const targetContract: Address =
|
|
23
|
+
"0xa2fea3537915dc6c7c7a97a82d1236041e6feb2e";
|
|
23
24
|
const targetTokenId = 1n;
|
|
24
25
|
const minter = createMintClient({ chain: zora });
|
|
25
26
|
|
|
26
27
|
const params = await minter.makePrepareMintTokenParams({
|
|
27
28
|
minterAccount: creatorAccount,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
tokenContract: targetContract,
|
|
31
|
-
}),
|
|
29
|
+
tokenId: targetTokenId,
|
|
30
|
+
tokenAddress: targetContract,
|
|
32
31
|
mintArguments: {
|
|
33
32
|
mintToAddress: creatorAccount,
|
|
34
33
|
quantityToMint: 1,
|
|
@@ -69,15 +68,14 @@ describe("mint-helper", () => {
|
|
|
69
68
|
value: parseEther("2000"),
|
|
70
69
|
});
|
|
71
70
|
|
|
72
|
-
const targetContract =
|
|
71
|
+
const targetContract: Address =
|
|
72
|
+
"0x7aae7e67515A2CbB8585C707Ca6db37BDd3EA839";
|
|
73
73
|
const targetTokenId = undefined;
|
|
74
74
|
const minter = createMintClient({ chain: zora });
|
|
75
75
|
|
|
76
76
|
const params = await minter.makePrepareMintTokenParams({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
tokenId: targetTokenId,
|
|
80
|
-
}),
|
|
77
|
+
tokenId: targetTokenId,
|
|
78
|
+
tokenAddress: targetContract,
|
|
81
79
|
minterAccount: creatorAccount,
|
|
82
80
|
mintArguments: {
|
|
83
81
|
mintToAddress: creatorAccount,
|
package/src/mint/mint-client.ts
CHANGED
|
@@ -4,18 +4,19 @@ import {
|
|
|
4
4
|
PublicClient,
|
|
5
5
|
createPublicClient,
|
|
6
6
|
encodeAbiParameters,
|
|
7
|
-
parseAbi,
|
|
8
7
|
parseAbiParameters,
|
|
9
8
|
zeroAddress,
|
|
10
9
|
http,
|
|
11
10
|
} from "viem";
|
|
12
11
|
import { IHttpClient } from "../apis/http-api-base";
|
|
13
|
-
import { MintAPIClient,
|
|
12
|
+
import { MintAPIClient, SalesConfigAndTokenInfo } from "./mint-api-client";
|
|
14
13
|
import { SimulateContractParameters } from "viem";
|
|
15
14
|
import {
|
|
16
15
|
zoraCreator1155ImplABI,
|
|
17
16
|
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
18
17
|
} from "@zoralabs/protocol-deployments";
|
|
18
|
+
import { GenericTokenIdTypes } from "src/types";
|
|
19
|
+
import { zora721Abi } from "src/constants";
|
|
19
20
|
|
|
20
21
|
class MintError extends Error {}
|
|
21
22
|
class MintInactiveError extends Error {}
|
|
@@ -32,11 +33,6 @@ type MintArguments = {
|
|
|
32
33
|
mintToAddress: Address;
|
|
33
34
|
};
|
|
34
35
|
|
|
35
|
-
const zora721Abi = parseAbi([
|
|
36
|
-
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
37
|
-
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)",
|
|
38
|
-
] as const);
|
|
39
|
-
|
|
40
36
|
class MintClient {
|
|
41
37
|
readonly apiClient: MintAPIClient;
|
|
42
38
|
readonly publicClient: PublicClient;
|
|
@@ -51,25 +47,6 @@ class MintClient {
|
|
|
51
47
|
publicClient || createPublicClient({ chain, transport: http() });
|
|
52
48
|
}
|
|
53
49
|
|
|
54
|
-
/**
|
|
55
|
-
* Gets mintable information for a given token
|
|
56
|
-
* @param param0.tokenContract The contract address of the token to mint.
|
|
57
|
-
* @param param0.tokenId The token id to mint.
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
async getMintable({
|
|
61
|
-
tokenContract,
|
|
62
|
-
tokenId,
|
|
63
|
-
}: {
|
|
64
|
-
tokenContract: Address;
|
|
65
|
-
tokenId?: bigint | number | string;
|
|
66
|
-
}) {
|
|
67
|
-
return await this.apiClient.getMintableForToken({
|
|
68
|
-
tokenContract,
|
|
69
|
-
tokenId: tokenId?.toString(),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
50
|
/**
|
|
74
51
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
75
52
|
* @param param0.minterAccount The account that will mint the token.
|
|
@@ -81,7 +58,8 @@ class MintClient {
|
|
|
81
58
|
...rest
|
|
82
59
|
}: {
|
|
83
60
|
minterAccount: Address;
|
|
84
|
-
|
|
61
|
+
tokenAddress: Address;
|
|
62
|
+
tokenId?: GenericTokenIdTypes;
|
|
85
63
|
mintArguments: MintArguments;
|
|
86
64
|
}): Promise<SimulateContractParameters> {
|
|
87
65
|
return makePrepareMintTokenParams({
|
|
@@ -90,42 +68,6 @@ class MintClient {
|
|
|
90
68
|
publicClient: this.publicClient,
|
|
91
69
|
});
|
|
92
70
|
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
96
|
-
* @param param0.mintable The mintable token to mint.
|
|
97
|
-
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
98
|
-
* @returns
|
|
99
|
-
*/
|
|
100
|
-
async getMintCosts({
|
|
101
|
-
mintable,
|
|
102
|
-
quantityToMint,
|
|
103
|
-
}: {
|
|
104
|
-
mintable: Mintable;
|
|
105
|
-
quantityToMint: number | bigint;
|
|
106
|
-
}): Promise<MintCosts> {
|
|
107
|
-
const mintContextType = validateMintableAndGetContextType(mintable);
|
|
108
|
-
|
|
109
|
-
if (mintContextType === "zora_create_1155") {
|
|
110
|
-
return await get1155MintCosts({
|
|
111
|
-
mintable,
|
|
112
|
-
price: BigInt(mintable.cost.native_price.raw),
|
|
113
|
-
publicClient: this.publicClient,
|
|
114
|
-
quantityToMint: BigInt(quantityToMint),
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
if (mintContextType === "zora_create") {
|
|
118
|
-
return await get721MintCosts({
|
|
119
|
-
mintable,
|
|
120
|
-
publicClient: this.publicClient,
|
|
121
|
-
quantityToMint: BigInt(quantityToMint),
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
throw new MintError(
|
|
126
|
-
`Mintable type ${mintContextType} is currently unsupported.`,
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
71
|
}
|
|
130
72
|
|
|
131
73
|
/**
|
|
@@ -149,128 +91,60 @@ export function createMintClient({
|
|
|
149
91
|
|
|
150
92
|
export type TMintClient = ReturnType<typeof createMintClient>;
|
|
151
93
|
|
|
152
|
-
function validateMintableAndGetContextType(
|
|
153
|
-
mintable: MintableGetTokenResponse | undefined,
|
|
154
|
-
) {
|
|
155
|
-
if (!mintable) {
|
|
156
|
-
throw new MintError("No mintable found");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!mintable.is_active) {
|
|
160
|
-
throw new MintInactiveError("Minting token is inactive");
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (!mintable.mint_context) {
|
|
164
|
-
throw new MintError("No minting context data from zora API");
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (
|
|
168
|
-
!["zora_create", "zora_create_1155"].includes(
|
|
169
|
-
mintable.mint_context?.mint_context_type!,
|
|
170
|
-
)
|
|
171
|
-
) {
|
|
172
|
-
throw new MintError(
|
|
173
|
-
`Mintable type ${mintable.mint_context.mint_context_type} is currently unsupported.`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return mintable.mint_context.mint_context_type;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
94
|
async function makePrepareMintTokenParams({
|
|
181
95
|
publicClient,
|
|
182
|
-
mintable,
|
|
183
96
|
apiClient,
|
|
97
|
+
tokenId,
|
|
98
|
+
tokenAddress,
|
|
184
99
|
...rest
|
|
185
100
|
}: {
|
|
186
101
|
publicClient: PublicClient;
|
|
187
102
|
minterAccount: Address;
|
|
188
|
-
|
|
103
|
+
tokenId?: GenericTokenIdTypes;
|
|
104
|
+
tokenAddress: Address;
|
|
189
105
|
mintArguments: MintArguments;
|
|
190
106
|
apiClient: MintAPIClient;
|
|
191
107
|
}): Promise<SimulateContractParameters> {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
108
|
+
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
109
|
+
tokenId,
|
|
110
|
+
tokenAddress,
|
|
111
|
+
});
|
|
195
112
|
|
|
196
|
-
if (
|
|
197
|
-
return makePrepareMint1155TokenParams({
|
|
198
|
-
apiClient,
|
|
199
|
-
publicClient: thisPublicClient,
|
|
200
|
-
mintable,
|
|
201
|
-
mintContextType,
|
|
202
|
-
...rest,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
if (mintContextType === "zora_create") {
|
|
113
|
+
if (tokenId === undefined) {
|
|
206
114
|
return makePrepareMint721TokenParams({
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
mintContextType,
|
|
115
|
+
salesConfigAndTokenInfo,
|
|
116
|
+
tokenAddress,
|
|
210
117
|
...rest,
|
|
211
118
|
});
|
|
212
119
|
}
|
|
213
120
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
async function get721MintCosts({
|
|
220
|
-
mintable,
|
|
221
|
-
publicClient,
|
|
222
|
-
quantityToMint,
|
|
223
|
-
}: {
|
|
224
|
-
mintable: MintableGetTokenResponse;
|
|
225
|
-
publicClient: PublicClient;
|
|
226
|
-
quantityToMint: bigint;
|
|
227
|
-
}): Promise<MintCosts> {
|
|
228
|
-
const address = mintable.collection.address as Address;
|
|
229
|
-
|
|
230
|
-
const [_, mintFee] = await publicClient.readContract({
|
|
231
|
-
abi: zora721Abi,
|
|
232
|
-
address,
|
|
233
|
-
functionName: "zoraFeeForAmount",
|
|
234
|
-
args: [BigInt(quantityToMint)],
|
|
121
|
+
return makePrepareMint1155TokenParams({
|
|
122
|
+
salesConfigAndTokenInfo,
|
|
123
|
+
tokenAddress,
|
|
124
|
+
tokenId,
|
|
125
|
+
...rest,
|
|
235
126
|
});
|
|
236
|
-
|
|
237
|
-
const tokenPurchaseCost =
|
|
238
|
-
BigInt(mintable.cost.native_price.raw) * quantityToMint;
|
|
239
|
-
return {
|
|
240
|
-
mintFee,
|
|
241
|
-
tokenPurchaseCost,
|
|
242
|
-
totalCost: mintFee + tokenPurchaseCost,
|
|
243
|
-
};
|
|
244
127
|
}
|
|
245
128
|
|
|
246
129
|
async function makePrepareMint721TokenParams({
|
|
247
|
-
|
|
130
|
+
tokenAddress,
|
|
131
|
+
salesConfigAndTokenInfo,
|
|
248
132
|
minterAccount,
|
|
249
|
-
mintable,
|
|
250
|
-
mintContextType,
|
|
251
133
|
mintArguments,
|
|
252
134
|
}: {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
mintContextType: ReturnType<typeof validateMintableAndGetContextType>;
|
|
135
|
+
tokenAddress: Address;
|
|
136
|
+
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
256
137
|
minterAccount: Address;
|
|
257
138
|
mintArguments: MintArguments;
|
|
258
139
|
}): Promise<SimulateContractParameters<typeof zora721Abi, "mintWithRewards">> {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const mintValue = (
|
|
264
|
-
await get721MintCosts({
|
|
265
|
-
mintable,
|
|
266
|
-
publicClient,
|
|
267
|
-
quantityToMint: BigInt(mintArguments.quantityToMint),
|
|
268
|
-
})
|
|
269
|
-
).totalCost;
|
|
140
|
+
const mintValue = getMintCosts({
|
|
141
|
+
salesConfigAndTokenInfo,
|
|
142
|
+
quantityToMint: BigInt(mintArguments.quantityToMint),
|
|
143
|
+
}).totalCost;
|
|
270
144
|
|
|
271
145
|
const result = {
|
|
272
146
|
abi: zora721Abi,
|
|
273
|
-
address:
|
|
147
|
+
address: tokenAddress,
|
|
274
148
|
account: minterAccount,
|
|
275
149
|
functionName: "mintWithRewards",
|
|
276
150
|
value: mintValue,
|
|
@@ -285,46 +159,23 @@ async function makePrepareMint721TokenParams({
|
|
|
285
159
|
return result;
|
|
286
160
|
}
|
|
287
161
|
|
|
288
|
-
async function get1155MintFee({
|
|
289
|
-
collectionAddress,
|
|
290
|
-
publicClient,
|
|
291
|
-
}: {
|
|
292
|
-
collectionAddress: Address;
|
|
293
|
-
publicClient: PublicClient;
|
|
294
|
-
}) {
|
|
295
|
-
return await publicClient.readContract({
|
|
296
|
-
abi: zoraCreator1155ImplABI,
|
|
297
|
-
functionName: "mintFee",
|
|
298
|
-
address: collectionAddress,
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
162
|
export type MintCosts = {
|
|
303
163
|
mintFee: bigint;
|
|
304
164
|
tokenPurchaseCost: bigint;
|
|
305
165
|
totalCost: bigint;
|
|
306
166
|
};
|
|
307
167
|
|
|
308
|
-
export
|
|
309
|
-
|
|
310
|
-
price,
|
|
311
|
-
publicClient,
|
|
168
|
+
export function getMintCosts({
|
|
169
|
+
salesConfigAndTokenInfo,
|
|
312
170
|
quantityToMint,
|
|
313
171
|
}: {
|
|
314
|
-
|
|
315
|
-
price: bigint;
|
|
316
|
-
publicClient: PublicClient;
|
|
172
|
+
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
317
173
|
quantityToMint: bigint;
|
|
318
|
-
}):
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
publicClient,
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
const mintFeeForTokens = mintFee * quantityToMint;
|
|
327
|
-
const tokenPurchaseCost = price * quantityToMint;
|
|
174
|
+
}): MintCosts {
|
|
175
|
+
const mintFeeForTokens =
|
|
176
|
+
salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
177
|
+
const tokenPurchaseCost =
|
|
178
|
+
BigInt(salesConfigAndTokenInfo.fixedPrice.pricePerToken) * quantityToMint;
|
|
328
179
|
|
|
329
180
|
return {
|
|
330
181
|
mintFee: mintFeeForTokens,
|
|
@@ -334,55 +185,36 @@ export async function get1155MintCosts({
|
|
|
334
185
|
}
|
|
335
186
|
|
|
336
187
|
async function makePrepareMint1155TokenParams({
|
|
337
|
-
|
|
338
|
-
|
|
188
|
+
tokenId,
|
|
189
|
+
salesConfigAndTokenInfo,
|
|
339
190
|
minterAccount,
|
|
340
|
-
|
|
341
|
-
mintContextType,
|
|
191
|
+
tokenAddress,
|
|
342
192
|
mintArguments,
|
|
343
193
|
}: {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
mintable: Mintable;
|
|
347
|
-
mintContextType: ReturnType<typeof validateMintableAndGetContextType>;
|
|
194
|
+
salesConfigAndTokenInfo: SalesConfigAndTokenInfo;
|
|
195
|
+
tokenId: GenericTokenIdTypes;
|
|
348
196
|
minterAccount: Address;
|
|
197
|
+
tokenAddress: Address;
|
|
349
198
|
mintArguments: MintArguments;
|
|
350
199
|
}) {
|
|
351
|
-
if (mintContextType !== "zora_create_1155") {
|
|
352
|
-
throw new Error("Minted token type must be for 1155");
|
|
353
|
-
}
|
|
354
|
-
|
|
355
200
|
const mintQuantity = BigInt(mintArguments.quantityToMint);
|
|
356
201
|
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
tokenId: BigInt(mintable.token_id!),
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
const mintValue = (
|
|
365
|
-
await get1155MintCosts({
|
|
366
|
-
mintable,
|
|
367
|
-
price:
|
|
368
|
-
tokenFixedPriceMinter?.pricePerToken ||
|
|
369
|
-
BigInt(mintable.cost.native_price.raw),
|
|
370
|
-
publicClient,
|
|
371
|
-
quantityToMint: mintQuantity,
|
|
372
|
-
})
|
|
373
|
-
).totalCost;
|
|
202
|
+
const mintValue = getMintCosts({
|
|
203
|
+
salesConfigAndTokenInfo,
|
|
204
|
+
quantityToMint: mintQuantity,
|
|
205
|
+
}).totalCost;
|
|
374
206
|
|
|
375
207
|
const result = {
|
|
376
208
|
abi: zoraCreator1155ImplABI,
|
|
377
209
|
functionName: "mintWithRewards",
|
|
378
210
|
account: minterAccount,
|
|
379
211
|
value: mintValue,
|
|
380
|
-
address,
|
|
212
|
+
address: tokenAddress,
|
|
381
213
|
/* args: minter, tokenId, quantity, minterArguments, mintReferral */
|
|
382
214
|
args: [
|
|
383
|
-
(
|
|
215
|
+
(salesConfigAndTokenInfo?.fixedPrice.address ||
|
|
384
216
|
zoraCreatorFixedPriceSaleStrategyAddress[999]) as Address,
|
|
385
|
-
BigInt(
|
|
217
|
+
BigInt(tokenId),
|
|
386
218
|
mintQuantity,
|
|
387
219
|
encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
388
220
|
mintArguments.mintToAddress,
|
|
@@ -397,5 +229,3 @@ async function makePrepareMint1155TokenParams({
|
|
|
397
229
|
|
|
398
230
|
return result;
|
|
399
231
|
}
|
|
400
|
-
|
|
401
|
-
export type Mintable = MintableGetTokenResponse;
|