@zoralabs/protocol-sdk 0.5.17 → 0.7.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 +19 -0
- package/README.md +1 -416
- package/dist/constants.d.ts +0 -1
- package/dist/constants.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 +1745 -891
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1698 -858
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-client.d.ts +48 -51
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +38 -0
- package/dist/mint/mint-queries.d.ts.map +1 -0
- package/dist/mint/mint-transactions.d.ts +20 -0
- package/dist/mint/mint-transactions.d.ts.map +1 -0
- package/dist/mint/subgraph-mint-getter.d.ts +24 -0
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -0
- package/dist/mint/subgraph-queries.d.ts +55 -0
- package/dist/mint/subgraph-queries.d.ts.map +1 -0
- package/dist/mint/types.d.ts +177 -0
- package/dist/mint/types.d.ts.map +1 -0
- package/dist/mint/utils.d.ts +2 -0
- package/dist/mint/utils.d.ts.map +1 -0
- package/dist/mints/mints-contracts.d.ts +27 -4518
- package/dist/mints/mints-contracts.d.ts.map +1 -1
- package/dist/premint/contract-types.d.ts +4 -4
- package/dist/premint/contract-types.d.ts.map +1 -1
- package/dist/premint/conversions.d.ts +15 -16
- package/dist/premint/conversions.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +32 -16
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +76 -50
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +20 -8
- package/dist/premint/preminter.d.ts.map +1 -1
- package/dist/sdk.d.ts +45 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +24 -6869
- package/dist/utils.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/constants.ts +0 -36
- package/src/create/1155-create-helper.test.ts +236 -55
- 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 +5 -1
- package/src/mint/mint-client.test.ts +116 -78
- package/src/mint/mint-client.ts +130 -234
- package/src/mint/mint-queries.ts +320 -0
- package/src/mint/mint-transactions.ts +253 -0
- package/src/mint/subgraph-mint-getter.ts +247 -0
- package/src/mint/subgraph-queries.ts +170 -0
- package/src/mint/types.ts +239 -0
- package/src/mint/utils.ts +14 -0
- package/src/mints/mints-contracts.test.ts +1 -1
- package/src/mints/mints-contracts.ts +4 -4
- package/src/premint/contract-types.ts +4 -4
- package/src/premint/conversions.ts +38 -4
- package/src/premint/premint-api-client.ts +92 -48
- package/src/premint/premint-client.test.ts +100 -84
- package/src/premint/premint-client.ts +186 -185
- package/src/premint/preminter.test.ts +4 -5
- package/src/premint/preminter.ts +63 -14
- package/src/sdk.ts +101 -0
- package/src/types.ts +18 -0
- package/src/utils.ts +54 -46
- package/test-integration/setup-test-contracts.ts +96 -0
- 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-api-client.ts +0 -177
- package/test-integration/premint-client.test.ts +0 -148
package/src/mint/mint-client.ts
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
+
import { Address, Account, SimulateContractParameters } from "viem";
|
|
2
|
+
import { IPublicClient } from "src/types";
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
zeroAddress,
|
|
7
|
-
Account,
|
|
8
|
-
SimulateContractParameters,
|
|
9
|
-
} from "viem";
|
|
10
|
-
import {
|
|
11
|
-
erc20MinterABI,
|
|
12
|
-
erc20MinterAddress,
|
|
13
|
-
zoraCreator1155ImplABI,
|
|
14
|
-
zoraCreatorFixedPriceSaleStrategyAddress,
|
|
15
|
-
} from "@zoralabs/protocol-deployments";
|
|
16
|
-
import { IHttpClient } from "src/apis/http-api-base";
|
|
17
|
-
import { zora721Abi } from "src/constants";
|
|
18
|
-
import { GenericTokenIdTypes } from "src/types";
|
|
19
|
-
import {
|
|
20
|
-
MintAPIClient,
|
|
21
|
-
SalesConfigAndTokenInfo,
|
|
4
|
+
GetMintParameters,
|
|
5
|
+
IOnchainMintGetter,
|
|
6
|
+
MintCosts,
|
|
7
|
+
PrepareMintReturn,
|
|
22
8
|
SaleType,
|
|
23
|
-
} from "./
|
|
9
|
+
} from "./types";
|
|
24
10
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
MakeMintParametersArguments,
|
|
12
|
+
Make1155MintArguments,
|
|
13
|
+
Make721MintArguments,
|
|
14
|
+
GetMintCostsParameters,
|
|
15
|
+
is1155Mint,
|
|
16
|
+
} from "./types";
|
|
17
|
+
import { IPremintGetter } from "src/premint/premint-api-client";
|
|
18
|
+
|
|
19
|
+
import { makeOnchainMintCall } from "./mint-transactions";
|
|
20
|
+
import { getMint, getMintCosts, getMintsOfContract } from "./mint-queries";
|
|
30
21
|
|
|
31
22
|
class MintError extends Error {}
|
|
32
23
|
class MintInactiveError extends Error {}
|
|
@@ -36,235 +27,140 @@ export const Errors = {
|
|
|
36
27
|
MintInactiveError,
|
|
37
28
|
};
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
minterAccount: Address | Account;
|
|
54
|
-
/** Contract address of token to mint */
|
|
55
|
-
tokenAddress: Address;
|
|
56
|
-
/** Id of token to mint */
|
|
57
|
-
tokenId?: GenericTokenIdTypes;
|
|
58
|
-
/** Mint settings */
|
|
59
|
-
mintArguments: MintArguments;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
class MintClient {
|
|
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);
|
|
30
|
+
export class MintClient {
|
|
31
|
+
private readonly publicClient: IPublicClient;
|
|
32
|
+
private readonly mintGetter: IOnchainMintGetter;
|
|
33
|
+
private readonly premintGetter: IPremintGetter;
|
|
34
|
+
|
|
35
|
+
constructor({
|
|
36
|
+
publicClient,
|
|
37
|
+
premintGetter,
|
|
38
|
+
mintGetter,
|
|
39
|
+
}: {
|
|
40
|
+
publicClient: IPublicClient;
|
|
41
|
+
premintGetter: IPremintGetter;
|
|
42
|
+
mintGetter: IOnchainMintGetter;
|
|
43
|
+
}) {
|
|
72
44
|
this.publicClient = publicClient;
|
|
45
|
+
this.mintGetter = mintGetter;
|
|
46
|
+
this.premintGetter = premintGetter;
|
|
73
47
|
}
|
|
74
48
|
|
|
75
49
|
/**
|
|
76
50
|
* Returns the parameters needed to prepare a transaction mint a token.
|
|
51
|
+
* Works with premint, onchain 1155, and onchain 721.
|
|
77
52
|
*
|
|
78
|
-
* @param parameters - Parameters for collecting the token {@link
|
|
79
|
-
* @returns Parameters for simulating/executing the mint transaction
|
|
53
|
+
* @param parameters - Parameters for collecting the token {@link MakeMintParametersArguments}
|
|
54
|
+
* @returns Parameters for simulating/executing the mint transaction, any necessary erc20 approval, and costs to mint
|
|
80
55
|
*/
|
|
81
|
-
async
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
56
|
+
async mint(
|
|
57
|
+
parameters: MakeMintParametersArguments,
|
|
58
|
+
): Promise<PrepareMintReturn> {
|
|
59
|
+
return mint({
|
|
60
|
+
parameters,
|
|
85
61
|
publicClient: this.publicClient,
|
|
62
|
+
mintGetter: this.mintGetter,
|
|
63
|
+
premintGetter: this.premintGetter,
|
|
86
64
|
});
|
|
87
65
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Creates a new MintClient.
|
|
92
|
-
* @param param0.chain The chain to use for the mint client.
|
|
93
|
-
* @param param0.publicClient Optional viem public client
|
|
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);
|
|
100
|
-
}
|
|
101
66
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
mintArguments: MintArguments;
|
|
117
|
-
apiClient: MintAPIClient;
|
|
118
|
-
}): Promise<
|
|
119
|
-
SimulateContractParameters<any, any, any, any, any, Account | Address>
|
|
120
|
-
> {
|
|
121
|
-
const salesConfigAndTokenInfo = await apiClient.getSalesConfigAndTokenInfo({
|
|
122
|
-
tokenId,
|
|
123
|
-
tokenAddress,
|
|
124
|
-
saleType: mintArguments.saleType,
|
|
125
|
-
});
|
|
67
|
+
/**
|
|
68
|
+
* Gets an 1155, 721, or premint, and returns both information about it, and a function
|
|
69
|
+
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
70
|
+
* @param parameters - Token to get {@link GetMintParameters}
|
|
71
|
+
* @Returns Information about the mint and a function to build a mint transaction {@link MintableReturn}
|
|
72
|
+
*/
|
|
73
|
+
async get(parameters: GetMintParameters) {
|
|
74
|
+
return getMint({
|
|
75
|
+
params: parameters,
|
|
76
|
+
mintGetter: this.mintGetter,
|
|
77
|
+
premintGetter: this.premintGetter,
|
|
78
|
+
publicClient: this.publicClient,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
126
81
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Gets onchain and premint tokens of an 1155 contract. For each token returns both information about it, and a function
|
|
84
|
+
* that can be used to build a mint transaction for a quantity of items to mint.
|
|
85
|
+
* @param parameters - Contract address to get tokens for {@link GetMintsOfContractParameters}
|
|
86
|
+
* @Returns Array of tokens, each containing information about the token and a function to build a mint transaction.
|
|
87
|
+
*/
|
|
88
|
+
async getOfContract(params: {
|
|
89
|
+
tokenContract: Address;
|
|
90
|
+
preferredSaleType?: SaleType;
|
|
91
|
+
}) {
|
|
92
|
+
return getMintsOfContract({
|
|
93
|
+
params,
|
|
94
|
+
mintGetter: this.mintGetter,
|
|
95
|
+
premintGetter: this.premintGetter,
|
|
96
|
+
publicClient: this.publicClient,
|
|
133
97
|
});
|
|
134
98
|
}
|
|
135
99
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
100
|
+
/**
|
|
101
|
+
* Gets the costs to mint the quantity of tokens specified for a mint.
|
|
102
|
+
* @param parameters - Parameters for the mint {@link GetMintCostsParameters}
|
|
103
|
+
* @returns Costs to mint the quantity of tokens specified
|
|
104
|
+
*/
|
|
105
|
+
async getMintCosts(parameters: GetMintCostsParameters): Promise<MintCosts> {
|
|
106
|
+
return getMintCosts({
|
|
107
|
+
params: parameters,
|
|
108
|
+
mintGetter: this.mintGetter,
|
|
109
|
+
premintGetter: this.premintGetter,
|
|
110
|
+
publicClient: this.publicClient,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
143
113
|
}
|
|
144
114
|
|
|
145
|
-
async function
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
115
|
+
async function mint({
|
|
116
|
+
parameters,
|
|
117
|
+
publicClient,
|
|
118
|
+
mintGetter,
|
|
119
|
+
premintGetter,
|
|
150
120
|
}: {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}) {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return makeSimulateContractParamaters({
|
|
162
|
-
abi: zora721Abi,
|
|
163
|
-
address: tokenAddress,
|
|
164
|
-
account: minterAccount,
|
|
165
|
-
functionName: "mintWithRewards",
|
|
166
|
-
value: mintValue,
|
|
167
|
-
args: [
|
|
168
|
-
mintArguments.mintToAddress,
|
|
169
|
-
BigInt(mintArguments.quantityToMint),
|
|
170
|
-
mintArguments.mintComment || "",
|
|
171
|
-
mintArguments.mintReferral || zeroAddress,
|
|
172
|
-
],
|
|
121
|
+
parameters: MakeMintParametersArguments;
|
|
122
|
+
publicClient: IPublicClient;
|
|
123
|
+
mintGetter: IOnchainMintGetter;
|
|
124
|
+
premintGetter: IPremintGetter;
|
|
125
|
+
}): Promise<PrepareMintReturn> {
|
|
126
|
+
const { prepareMint } = await getMint({
|
|
127
|
+
params: parameters,
|
|
128
|
+
mintGetter,
|
|
129
|
+
premintGetter,
|
|
130
|
+
publicClient,
|
|
173
131
|
});
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export type MintCosts = {
|
|
177
|
-
mintFee: bigint;
|
|
178
|
-
tokenPurchaseCost: bigint;
|
|
179
|
-
totalCost: bigint;
|
|
180
|
-
};
|
|
181
132
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
salesConfigAndTokenInfo.mintFeePerQuantity * quantityToMint;
|
|
191
|
-
const tokenPurchaseCost =
|
|
192
|
-
BigInt(salesConfigAndTokenInfo.salesConfig.pricePerToken) * quantityToMint;
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
mintFee: mintFeeForTokens,
|
|
196
|
-
tokenPurchaseCost,
|
|
197
|
-
totalCost: mintFeeForTokens + tokenPurchaseCost,
|
|
198
|
-
};
|
|
133
|
+
return prepareMint({
|
|
134
|
+
minterAccount: parameters.minterAccount,
|
|
135
|
+
quantityToMint: parameters.quantityToMint,
|
|
136
|
+
firstMinter: parameters.firstMinter,
|
|
137
|
+
mintComment: parameters.mintComment,
|
|
138
|
+
mintRecipient: parameters.mintRecipient,
|
|
139
|
+
mintReferral: parameters.mintReferral,
|
|
140
|
+
});
|
|
199
141
|
}
|
|
200
142
|
|
|
201
|
-
async function
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
});
|
|
244
|
-
|
|
245
|
-
case "erc20":
|
|
246
|
-
const erc20Args = mintArguments;
|
|
247
|
-
|
|
248
|
-
return makeSimulateContractParamaters({
|
|
249
|
-
abi: erc20MinterABI,
|
|
250
|
-
functionName: "mint",
|
|
251
|
-
account: minterAccount,
|
|
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
|
-
});
|
|
143
|
+
export async function collectOnchain({
|
|
144
|
+
chainId,
|
|
145
|
+
mintGetter,
|
|
146
|
+
...parameters
|
|
147
|
+
}: (Make1155MintArguments | Make721MintArguments) & {
|
|
148
|
+
mintGetter: IOnchainMintGetter;
|
|
149
|
+
chainId: number;
|
|
150
|
+
}): Promise<
|
|
151
|
+
SimulateContractParameters<any, any, any, any, any, Account | Address>
|
|
152
|
+
> {
|
|
153
|
+
const { tokenContract: tokenContract, preferredSaleType: saleType } =
|
|
154
|
+
parameters;
|
|
155
|
+
const tokenId = is1155Mint(parameters) ? parameters.tokenId : undefined;
|
|
156
|
+
const salesConfigAndTokenInfo = await mintGetter.getMintable({
|
|
157
|
+
tokenId,
|
|
158
|
+
tokenAddress: tokenContract,
|
|
159
|
+
preferredSaleType: saleType,
|
|
160
|
+
});
|
|
266
161
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
162
|
+
return makeOnchainMintCall({
|
|
163
|
+
mintParams: parameters,
|
|
164
|
+
token: salesConfigAndTokenInfo,
|
|
165
|
+
});
|
|
270
166
|
}
|