@zoralabs/protocol-sdk 0.3.2 → 0.3.3
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 +21 -0
- package/README.md +243 -79
- package/dist/apis/http-api-base.d.ts +6 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/index.cjs +363 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +350 -226
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +216 -12
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +53 -14
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/premint-api-client.d.ts +13 -6
- package/dist/premint/premint-api-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +14 -16
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/apis/http-api-base.ts +12 -0
- package/src/mint/mint-api-client.ts +71 -34
- package/src/mint/mint-client.test.ts +23 -27
- package/src/mint/mint-client.ts +321 -153
- package/src/premint/premint-api-client.ts +72 -18
- package/src/premint/premint-client.test.ts +23 -18
- package/src/premint/premint-client.ts +35 -48
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Chain, PublicClient } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { IHttpClient } from "../apis/http-api-base";
|
|
3
3
|
import { MintAPIClient, MintableGetTokenResponse } from "./mint-api-client";
|
|
4
4
|
import { SimulateContractParameters } from "viem";
|
|
5
5
|
declare class MintError extends Error {
|
|
@@ -16,9 +16,16 @@ type MintArguments = {
|
|
|
16
16
|
mintReferral?: Address;
|
|
17
17
|
mintToAddress: Address;
|
|
18
18
|
};
|
|
19
|
-
declare class MintClient
|
|
20
|
-
apiClient:
|
|
21
|
-
|
|
19
|
+
declare class MintClient {
|
|
20
|
+
readonly apiClient: MintAPIClient;
|
|
21
|
+
readonly publicClient: PublicClient;
|
|
22
|
+
constructor(chain: Chain, publicClient?: PublicClient, httpClient?: IHttpClient);
|
|
23
|
+
/**
|
|
24
|
+
* Gets mintable information for a given token
|
|
25
|
+
* @param param0.tokenContract The contract address of the token to mint.
|
|
26
|
+
* @param param0.tokenId The token id to mint.
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
22
29
|
getMintable({ tokenContract, tokenId, }: {
|
|
23
30
|
tokenContract: Address;
|
|
24
31
|
tokenId?: bigint | number | string;
|
|
@@ -222,20 +229,52 @@ declare class MintClient extends ClientBase {
|
|
|
222
229
|
status?: "ACTIVE" | "BLOCKED" | "EXPIRED" | "INVALID_MEDIA" | "MINTED_OUT" | "DELETED" | undefined;
|
|
223
230
|
uuid?: string | undefined;
|
|
224
231
|
}>;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Returns the parameters needed to prepare a transaction mint a token.
|
|
234
|
+
* @param param0.minterAccount The account that will mint the token.
|
|
235
|
+
* @param param0.mintable The mintable token to mint.
|
|
236
|
+
* @param param0.mintArguments The arguments for the mint (mint recipient, comment, mint referral, quantity to mint)
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
239
|
+
makePrepareMintTokenParams({ ...rest }: {
|
|
228
240
|
minterAccount: Address;
|
|
241
|
+
mintable: MintableGetTokenResponse;
|
|
229
242
|
mintArguments: MintArguments;
|
|
230
|
-
}): Promise<
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
243
|
+
}): Promise<SimulateContractParameters>;
|
|
244
|
+
/**
|
|
245
|
+
* Returns the mintFee, sale fee, and total cost of minting x quantities of a token.
|
|
246
|
+
* @param param0.mintable The mintable token to mint.
|
|
247
|
+
* @param param0.quantityToMint The quantity of tokens to mint.
|
|
248
|
+
* @returns
|
|
249
|
+
*/
|
|
250
|
+
getMintCosts({ mintable, quantityToMint, }: {
|
|
251
|
+
mintable: Mintable;
|
|
252
|
+
quantityToMint: number | bigint;
|
|
253
|
+
}): Promise<MintCosts>;
|
|
235
254
|
}
|
|
236
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Creates a new MintClient.
|
|
257
|
+
* @param param0.chain The chain to use for the mint client.
|
|
258
|
+
* @param param0.publicClient Optional viem public client
|
|
259
|
+
* @param param0.httpClient Optional http client to override post, get, and retry methods
|
|
260
|
+
* @returns
|
|
261
|
+
*/
|
|
262
|
+
export declare function createMintClient({ chain, publicClient, httpClient, }: {
|
|
237
263
|
chain: Chain;
|
|
238
|
-
|
|
264
|
+
publicClient?: PublicClient;
|
|
265
|
+
httpClient?: IHttpClient;
|
|
239
266
|
}): MintClient;
|
|
267
|
+
export type TMintClient = ReturnType<typeof createMintClient>;
|
|
268
|
+
export type MintCosts = {
|
|
269
|
+
mintFee: bigint;
|
|
270
|
+
tokenPurchaseCost: bigint;
|
|
271
|
+
totalCost: bigint;
|
|
272
|
+
};
|
|
273
|
+
export declare function get1155MintCosts({ mintable, publicClient, quantityToMint, }: {
|
|
274
|
+
mintable: MintableGetTokenResponse;
|
|
275
|
+
publicClient: PublicClient;
|
|
276
|
+
quantityToMint: bigint;
|
|
277
|
+
}): Promise<MintCosts>;
|
|
278
|
+
export type Mintable = MintableGetTokenResponse;
|
|
240
279
|
export {};
|
|
241
280
|
//# sourceMappingURL=mint-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mint-client.d.ts","sourceRoot":"","sources":["../../src/mint/mint-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,EACL,YAAY,
|
|
1
|
+
{"version":3,"file":"mint-client.d.ts","sourceRoot":"","sources":["../../src/mint/mint-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,KAAK,EACL,YAAY,EAOb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAA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AQ,EAAE,QAAQ,CAAC;QACnB,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;KACjC,GAAG,OAAO,CAAC,SAAS,CAAC;CAsBvB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,YAAY,EACZ,UAAU,GACX,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,cAEA;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAwJ9D,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAAsB,gBAAgB,CAAC,EACrC,QAAQ,EACR,YAAY,EACZ,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,wBAAwB,CAAC;IACnC,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CAAC,SAAS,CAAC,CAiBrB;AAgED,MAAM,MAAM,QAAQ,GAAG,wBAAwB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { IHttpClient } from "../apis/http-api-base";
|
|
1
2
|
import { components, paths } from "../apis/generated/premint-api-types";
|
|
2
3
|
import { ZORA_API_BASE } from "../constants";
|
|
4
|
+
import { NetworkConfig } from "src/apis/chain-constants";
|
|
3
5
|
type SignaturePostType = paths["/signature"]["post"];
|
|
4
6
|
type PremintSignatureRequestBody = SignaturePostType["requestBody"]["content"]["application/json"];
|
|
5
7
|
export type PremintSignatureResponse = SignaturePostType["responses"][200]["content"]["application/json"];
|
|
@@ -9,11 +11,16 @@ export type PremintNextUIDGetResponse = PremintNextUIDGetType["responses"][200][
|
|
|
9
11
|
type SignaturePremintGetType = paths["/signature/{chain_name}/{collection_address}/{uid}"]["get"];
|
|
10
12
|
type PremintSignatureGetPathParameters = SignaturePremintGetType["parameters"]["path"];
|
|
11
13
|
export type PremintSignatureGetResponse = SignaturePremintGetType["responses"][200]["content"]["application/json"];
|
|
14
|
+
export type PremintCollection = PremintSignatureGetResponse["collection"];
|
|
12
15
|
export type BackendChainNames = components["schemas"]["ChainName"];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
type OmitChainName<T> = Omit<T, "chain_name">;
|
|
17
|
+
declare class PremintAPIClient {
|
|
18
|
+
httpClient: IHttpClient;
|
|
19
|
+
networkConfig: NetworkConfig;
|
|
20
|
+
constructor(chainId: number, httpClient?: IHttpClient);
|
|
21
|
+
postSignature: (data: OmitChainName<PremintSignatureRequestBody>) => Promise<PremintSignatureResponse>;
|
|
22
|
+
getNextUID: (path: OmitChainName<PremintNextUIDGetPathParameters>) => Promise<PremintNextUIDGetResponse>;
|
|
23
|
+
getSignature: ({ collection_address, uid, }: OmitChainName<PremintSignatureGetPathParameters>) => Promise<PremintSignatureGetResponse>;
|
|
24
|
+
}
|
|
25
|
+
export { ZORA_API_BASE, PremintAPIClient };
|
|
19
26
|
//# sourceMappingURL=premint-api-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"premint-api-client.d.ts","sourceRoot":"","sources":["../../src/premint/premint-api-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"premint-api-client.d.ts","sourceRoot":"","sources":["../../src/premint/premint-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD,KAAK,iBA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,CAAC,KAC/C,QAAQ,wBAAwB,CAAC,CAK/B;IAEL,UAAU,SACF,cAAc,+BAA+B,CAAC,KACnD,QAAQ,yBAAyB,CAAC,CAKhC;IAEL,YAAY,iCAGT,cAAc,iCAAiC,CAAC,KAAG,QAAQ,2BAA2B,CAAC,CAMrF;CACN;AAED,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { PremintConfig } from "./preminter";
|
|
|
4
4
|
import type { PremintSignatureGetResponse, PremintSignatureResponse } from "./premint-api-client";
|
|
5
5
|
import { PremintAPIClient } from "./premint-api-client";
|
|
6
6
|
import type { DecodeEventLogReturnType } from "viem";
|
|
7
|
-
import {
|
|
7
|
+
import { IHttpClient } from "src/apis/http-api-base";
|
|
8
8
|
type MintArgumentsSettings = {
|
|
9
9
|
tokenURI: string;
|
|
10
10
|
maxSupply?: bigint;
|
|
@@ -100,9 +100,11 @@ export declare const encodePremintForAPI: ({ tokenConfig, ...premint }: PremintC
|
|
|
100
100
|
* Preminter API to access ZORA Premint functionality.
|
|
101
101
|
* Currently only supports V1 premints.
|
|
102
102
|
*/
|
|
103
|
-
declare class PremintClient
|
|
104
|
-
apiClient:
|
|
105
|
-
|
|
103
|
+
declare class PremintClient {
|
|
104
|
+
readonly apiClient: PremintAPIClient;
|
|
105
|
+
readonly publicClient: PublicClient;
|
|
106
|
+
readonly chain: Chain;
|
|
107
|
+
constructor(chain: Chain, publicClient?: PublicClient, httpClient?: IHttpClient);
|
|
106
108
|
/**
|
|
107
109
|
* The premint executor address is deployed to the same address across all chains.
|
|
108
110
|
* Can be overridden as needed by making a parent class.
|
|
@@ -185,9 +187,8 @@ declare class PremintClient extends ClientBase {
|
|
|
185
187
|
* @param settings.walletClient viem wallet client to use to sign
|
|
186
188
|
*
|
|
187
189
|
*/
|
|
188
|
-
deletePremint({ walletClient, uid, account, collection,
|
|
190
|
+
deletePremint({ walletClient, uid, account, collection, }: {
|
|
189
191
|
walletClient: WalletClient;
|
|
190
|
-
publicClient: PublicClient;
|
|
191
192
|
uid: number;
|
|
192
193
|
account?: Account | Address;
|
|
193
194
|
collection: Address;
|
|
@@ -244,13 +245,12 @@ declare class PremintClient extends ClientBase {
|
|
|
244
245
|
* @param settings.checkSignature if the signature should have a pre-flight check. Not required but helpful for debugging.
|
|
245
246
|
* @returns premint url, uid, newContractAddress, and premint object
|
|
246
247
|
*/
|
|
247
|
-
createPremint({ account, collection, token,
|
|
248
|
+
createPremint({ account, collection, token, walletClient, executionSettings, checkSignature, }: {
|
|
248
249
|
account: Address;
|
|
249
250
|
checkSignature?: boolean;
|
|
250
251
|
walletClient: WalletClient;
|
|
251
252
|
collection: PremintSignatureGetResponse["collection"];
|
|
252
253
|
token: MintArgumentsSettings;
|
|
253
|
-
publicClient?: PublicClient;
|
|
254
254
|
executionSettings?: {
|
|
255
255
|
deleted?: boolean;
|
|
256
256
|
uid?: number;
|
|
@@ -303,9 +303,8 @@ declare class PremintClient extends ClientBase {
|
|
|
303
303
|
* @param data Signature data from the API
|
|
304
304
|
* @returns isValid = signature is valid or not, contractAddress = assumed contract address, recoveredSigner = signer from contract
|
|
305
305
|
*/
|
|
306
|
-
isValidSignature({ data,
|
|
306
|
+
isValidSignature({ data, }: {
|
|
307
307
|
data: PremintSignatureGetResponse;
|
|
308
|
-
publicClient?: PublicClient;
|
|
309
308
|
}): Promise<{
|
|
310
309
|
isValid: boolean;
|
|
311
310
|
contractAddress: Address;
|
|
@@ -328,20 +327,19 @@ declare class PremintClient extends ClientBase {
|
|
|
328
327
|
* @param settings.publicClient Optional public client for preflight checks.
|
|
329
328
|
* @returns receipt, log, zoraURL
|
|
330
329
|
*/
|
|
331
|
-
|
|
330
|
+
makeMintParameters({ data, account, mintArguments, }: {
|
|
332
331
|
data: PremintSignatureGetResponse;
|
|
333
332
|
account: Account | Address;
|
|
334
333
|
mintArguments?: {
|
|
335
334
|
quantityToMint: number;
|
|
336
335
|
mintComment?: string;
|
|
337
336
|
};
|
|
338
|
-
}): Promise<
|
|
339
|
-
request: SimulateContractParameters;
|
|
340
|
-
}>;
|
|
337
|
+
}): Promise<SimulateContractParameters>;
|
|
341
338
|
}
|
|
342
|
-
export declare function createPremintClient({ chain,
|
|
339
|
+
export declare function createPremintClient({ chain, httpClient, publicClient, }: {
|
|
343
340
|
chain: Chain;
|
|
344
|
-
|
|
341
|
+
publicClient?: PublicClient;
|
|
342
|
+
httpClient?: IHttpClient;
|
|
345
343
|
}): PremintClient;
|
|
346
344
|
export {};
|
|
347
345
|
//# sourceMappingURL=premint-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"premint-client.d.ts","sourceRoot":"","sources":["../../src/premint/premint-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,KAAK,EAEL,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,EAClB,YAAY,EACb,MAAM,MAAM,CAAC;AACd,OAAO,EACL,qCAAqC,EAGtC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAgC,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EACV,2BAA2B,EAC3B,wBAAwB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"premint-client.d.ts","sourceRoot":"","sources":["../../src/premint/premint-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,KAAK,EAEL,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,EAClB,YAAY,EACb,MAAM,MAAM,CAAC;AACd,OAAO,EACL,qCAAqC,EAGtC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,aAAa,EAAgC,MAAM,aAAa,CAAC;AAC1E,OAAO,KAAK,EACV,2BAA2B,EAC3B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CAAC;QAC3B,aAAa,CAAC,EAAE;YACd,cAAc,EAAE,MAAM,CAAC;YACvB,WAAW,CAAC,EAAE,MAAM,CAAC;SACtB,CAAC;KACH,GAAG,OAAO,CAAC,0BAA0B,CAAC;CAgCxC;AAED,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,UAAU,EACV,YAAY,GACb,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,iBAEA"}
|
package/package.json
CHANGED
|
@@ -91,3 +91,15 @@ export const retries = async <T>(
|
|
|
91
91
|
throw err;
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
|
+
|
|
95
|
+
export interface IHttpClient {
|
|
96
|
+
get: typeof get;
|
|
97
|
+
post: typeof post;
|
|
98
|
+
retries: typeof retries;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const httpClient: IHttpClient = {
|
|
102
|
+
get,
|
|
103
|
+
post,
|
|
104
|
+
retries,
|
|
105
|
+
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
httpClient as defaultHttpClient,
|
|
3
|
+
IHttpClient,
|
|
4
|
+
} from "../apis/http-api-base";
|
|
2
5
|
import { paths } from "../apis/generated/discover-api-types";
|
|
3
6
|
import { ZORA_API_BASE } from "../constants";
|
|
7
|
+
import { NetworkConfig, networkConfigByChain } from "src/apis/chain-constants";
|
|
8
|
+
import { Address } from "viem";
|
|
4
9
|
|
|
5
10
|
export type MintableGetToken =
|
|
6
11
|
paths["/mintables/{chain_name}/{collection_address}"];
|
|
@@ -15,38 +20,70 @@ function encodeQueryParameters(params: Record<string, string>) {
|
|
|
15
20
|
return new URLSearchParams(params).toString();
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
|
|
24
|
+
if (!networkConfigByChain[chainId]) {
|
|
25
|
+
throw new Error(`chain id ${chainId} network not configured `);
|
|
26
|
+
}
|
|
27
|
+
return networkConfigByChain[chainId]!;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class MintAPIClient {
|
|
31
|
+
httpClient: IHttpClient;
|
|
32
|
+
networkConfig: NetworkConfig;
|
|
33
|
+
|
|
34
|
+
constructor(chainId: number, httpClient?: IHttpClient) {
|
|
35
|
+
this.httpClient = httpClient || defaultHttpClient;
|
|
36
|
+
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getMintable(
|
|
40
|
+
path: MintableGetTokenPathParameters,
|
|
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
|
+
);
|
|
44
50
|
});
|
|
45
|
-
|
|
46
|
-
?.fixedPriceMinterAddress;
|
|
47
|
-
});
|
|
51
|
+
}
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
+
async getSalesConfigFixedPrice({
|
|
54
|
+
contractAddress,
|
|
55
|
+
tokenId,
|
|
56
|
+
}: {
|
|
57
|
+
contractAddress: string;
|
|
58
|
+
tokenId: bigint;
|
|
59
|
+
}): Promise<undefined | string> {
|
|
60
|
+
const { retries, post } = this.httpClient;
|
|
61
|
+
return retries(async () => {
|
|
62
|
+
const response = await post<any>(this.networkConfig.subgraphUrl, {
|
|
63
|
+
query:
|
|
64
|
+
"query($id: ID!) {\n zoraCreateToken(id: $id) {\n id\n salesStrategies{\n fixedPrice {\n address\n }\n }\n }\n}",
|
|
65
|
+
variables: {
|
|
66
|
+
id: `${contractAddress.toLowerCase()}-${tokenId.toString()}`,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return response.zoraCreateToken?.salesStrategies?.find(() => true)
|
|
70
|
+
?.fixedPriceMinterAddress;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async getMintableForToken({
|
|
75
|
+
tokenContract,
|
|
76
|
+
tokenId,
|
|
77
|
+
}: {
|
|
78
|
+
tokenContract: Address;
|
|
79
|
+
tokenId?: bigint | number | string;
|
|
80
|
+
}) {
|
|
81
|
+
return await this.getMintable(
|
|
82
|
+
{
|
|
83
|
+
chain_name: this.networkConfig.zoraBackendChainName,
|
|
84
|
+
collection_address: tokenContract,
|
|
85
|
+
},
|
|
86
|
+
{ token_id: tokenId?.toString() },
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -23,19 +23,17 @@ describe("mint-helper", () => {
|
|
|
23
23
|
const targetTokenId = 1n;
|
|
24
24
|
const minter = createMintClient({ chain: zora });
|
|
25
25
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
});
|
|
26
|
+
const params = await minter.makePrepareMintTokenParams({
|
|
27
|
+
minterAccount: creatorAccount,
|
|
28
|
+
mintable: await minter.getMintable({
|
|
29
|
+
tokenId: targetTokenId,
|
|
30
|
+
tokenContract: targetContract,
|
|
31
|
+
}),
|
|
32
|
+
mintArguments: {
|
|
33
|
+
mintToAddress: creatorAccount,
|
|
34
|
+
quantityToMint: 1,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
39
37
|
|
|
40
38
|
const oldBalance = await publicClient.readContract({
|
|
41
39
|
abi: zoraCreator1155ImplABI,
|
|
@@ -75,19 +73,17 @@ describe("mint-helper", () => {
|
|
|
75
73
|
const targetTokenId = undefined;
|
|
76
74
|
const minter = createMintClient({ chain: zora });
|
|
77
75
|
|
|
78
|
-
const
|
|
79
|
-
await minter.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
},
|
|
90
|
-
});
|
|
76
|
+
const params = await minter.makePrepareMintTokenParams({
|
|
77
|
+
mintable: await minter.getMintable({
|
|
78
|
+
tokenContract: targetContract,
|
|
79
|
+
tokenId: targetTokenId,
|
|
80
|
+
}),
|
|
81
|
+
minterAccount: creatorAccount,
|
|
82
|
+
mintArguments: {
|
|
83
|
+
mintToAddress: creatorAccount,
|
|
84
|
+
quantityToMint: 1,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
91
87
|
const oldBalance = await publicClient.readContract({
|
|
92
88
|
abi: erc721ABI,
|
|
93
89
|
address: targetContract,
|
|
@@ -95,7 +91,7 @@ describe("mint-helper", () => {
|
|
|
95
91
|
args: [creatorAccount],
|
|
96
92
|
});
|
|
97
93
|
|
|
98
|
-
const simulated = await publicClient.simulateContract(
|
|
94
|
+
const simulated = await publicClient.simulateContract(params);
|
|
99
95
|
|
|
100
96
|
const hash = await walletClient.writeContract(simulated.request);
|
|
101
97
|
|