@zoralabs/protocol-sdk 0.3.3 → 0.3.5
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 +28 -0
- package/README.md +7 -26
- 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 +476 -323
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +447 -298
- package/dist/index.js.map +1 -1
- package/dist/mint/mint-api-client.d.ts +16 -213
- package/dist/mint/mint-api-client.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +7 -226
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +63 -17
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/dist/premint/preminter.d.ts +106 -19
- 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 +2 -1
- package/src/anvil.ts +7 -4
- package/src/constants.ts +7 -0
- package/src/create/1155-create-helper.ts +1 -1
- package/src/mint/mint-api-client.ts +79 -53
- package/src/mint/mint-client.test.ts +9 -11
- package/src/mint/mint-client.ts +50 -215
- package/src/premint/premint-client.test.ts +9 -8
- package/src/premint/premint-client.ts +113 -61
- package/src/premint/preminter.test.ts +207 -130
- package/src/premint/preminter.ts +388 -51
- package/src/types.ts +1 -0
- package/tsconfig.json +2 -17
- 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
|
@@ -1,25 +1,112 @@
|
|
|
1
1
|
import { Address } from "abitype";
|
|
2
2
|
import { ExtractAbiFunction, AbiParametersToPrimitiveTypes } from "abitype";
|
|
3
|
-
import { zoraCreator1155PremintExecutorImplABI as preminterAbi } from "@zoralabs/protocol-deployments";
|
|
4
|
-
import { TypedDataDefinition } from "viem";
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
export type ContractCreationConfig =
|
|
8
|
-
export type
|
|
9
|
-
export type
|
|
10
|
-
export
|
|
3
|
+
import { zoraCreator1155PremintExecutorImplABI as preminterAbi, zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
|
|
4
|
+
import { TypedDataDefinition, Hex, PublicClient, GetEventArgs } from "viem";
|
|
5
|
+
type PremintV1Inputs = ExtractAbiFunction<typeof preminterAbi, "premintV1">["inputs"];
|
|
6
|
+
type PremintV1HashDataTypes = AbiParametersToPrimitiveTypes<PremintV1Inputs>;
|
|
7
|
+
export type ContractCreationConfig = PremintV1HashDataTypes[0];
|
|
8
|
+
export type PremintConfigV1 = PremintV1HashDataTypes[1];
|
|
9
|
+
export type TokenCreationConfigV1 = PremintConfigV1["tokenConfig"];
|
|
10
|
+
export type MintArguments = PremintV1HashDataTypes[4];
|
|
11
|
+
type PremintV2Inputs = ExtractAbiFunction<typeof preminterAbi, "premintV2">["inputs"];
|
|
12
|
+
type PremintV2HashDataTypes = AbiParametersToPrimitiveTypes<PremintV2Inputs>;
|
|
13
|
+
export type PremintConfigV2 = PremintV2HashDataTypes[1];
|
|
14
|
+
export type TokenCreationConfigV2 = PremintConfigV2["tokenConfig"];
|
|
15
|
+
export declare const PreminterDomain = "Preminter";
|
|
16
|
+
type PremintConfigVersion = "1" | "2";
|
|
17
|
+
export declare const PremintConfigVersion: {
|
|
18
|
+
readonly V1: "1";
|
|
19
|
+
readonly V2: "2";
|
|
20
|
+
};
|
|
21
|
+
type PremintConfigForVersion<T extends PremintConfigVersion> = T extends "1" ? PremintConfigV1 : PremintConfigV2;
|
|
22
|
+
type PremintConfigWithVersion<T extends PremintConfigVersion> = {
|
|
23
|
+
premintConfig: PremintConfigForVersion<T>;
|
|
24
|
+
premintConfigVersion: T;
|
|
25
|
+
};
|
|
26
|
+
export type PremintConfigAndVersion = PremintConfigWithVersion<"1"> | PremintConfigWithVersion<"2">;
|
|
27
|
+
export declare const getPremintExecutorAddress: () => "0x7777773606e7e46C8Ba8B98C08f5cD218e31d340";
|
|
28
|
+
/**
|
|
29
|
+
* Creates a typed data definition for a premint config. Works for all versions of the premint config by specifying the premintConfigVersion.
|
|
30
|
+
*
|
|
31
|
+
* @param params.verifyingContract the address of the 1155 contract
|
|
32
|
+
* @param params.chainId the chain id the premint is signed for
|
|
33
|
+
* @param params.premintConfigVersion the version of the premint config
|
|
34
|
+
* @param params.premintConfig the premint config
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
export declare const premintTypedDataDefinition: ({ verifyingContract, chainId, premintConfigVersion: version, premintConfig, }: {
|
|
11
38
|
verifyingContract: Address;
|
|
12
|
-
premintConfig: PremintConfig;
|
|
13
39
|
chainId: number;
|
|
14
|
-
}) => TypedDataDefinition
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
40
|
+
} & PremintConfigAndVersion) => TypedDataDefinition;
|
|
41
|
+
export type IsValidSignatureReturn = {
|
|
42
|
+
isAuthorized: boolean;
|
|
43
|
+
recoveredAddress?: Address;
|
|
44
|
+
};
|
|
45
|
+
export declare function isAuthorizedToCreatePremint({ collection, collectionAddress, publicClient, premintConfig, premintConfigVersion, signature, signer, }: {
|
|
46
|
+
collection: ContractCreationConfig;
|
|
47
|
+
collectionAddress: Address;
|
|
48
|
+
publicClient: PublicClient;
|
|
49
|
+
signature: Hex;
|
|
50
|
+
signer: Address;
|
|
51
|
+
} & PremintConfigAndVersion): Promise<boolean>;
|
|
52
|
+
export declare function recoverPremintSigner({ signature, ...rest }: {
|
|
53
|
+
signature: Hex;
|
|
54
|
+
chainId: number;
|
|
55
|
+
verifyingContract: Address;
|
|
56
|
+
} & PremintConfigAndVersion): Promise<Address>;
|
|
57
|
+
export declare function tryRecoverPremintSigner(params: Parameters<typeof recoverPremintSigner>[0]): Promise<`0x${string}` | undefined>;
|
|
58
|
+
/**
|
|
59
|
+
* Recovers the address from a typed data signature and then checks if the recovered address is authorized to create a premint
|
|
60
|
+
*
|
|
61
|
+
* @param params validationProperties
|
|
62
|
+
* @param params.typedData typed data definition for premint config
|
|
63
|
+
* @param params.signature signature to validate
|
|
64
|
+
* @param params.publicClient public rpc read-only client
|
|
65
|
+
* @param params.premintConfigContractAdmin the original contractAdmin on the ContractCreationConfig for the premint; this is usually the original creator of the premint
|
|
66
|
+
* @param params.tokenContract the address of the 1155 contract
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export declare function isValidSignature({ signature, publicClient, collection, chainId, ...premintConfigAndVersion }: {
|
|
70
|
+
collection: ContractCreationConfig;
|
|
71
|
+
signature: Hex;
|
|
72
|
+
chainId: number;
|
|
73
|
+
publicClient: PublicClient;
|
|
74
|
+
} & PremintConfigAndVersion): Promise<IsValidSignatureReturn>;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a premint config from v1 to v2
|
|
77
|
+
*
|
|
78
|
+
* @param premintConfig premint config to convert
|
|
79
|
+
* @param createReferral address that referred the creator, that will receive create referral rewards for the created token
|
|
80
|
+
*/
|
|
81
|
+
export declare function migratePremintConfigToV2({ premintConfig, createReferral, }: {
|
|
82
|
+
premintConfig: PremintConfigV1;
|
|
83
|
+
createReferral: Address;
|
|
84
|
+
}): PremintConfigV2;
|
|
85
|
+
export type CreatorAttributionEventParams = GetEventArgs<typeof zoraCreator1155ImplABI, "CreatorAttribution", {
|
|
86
|
+
EnableUnion: false;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Recovers the address from a CreatorAttribution event emitted from a ZoraCreator1155 contract
|
|
90
|
+
* Useful for verifying that the creator of a token is the one who signed a premint for its creation.
|
|
91
|
+
*
|
|
92
|
+
|
|
93
|
+
* @param creatorAttribution parameters from the CreatorAttribution event
|
|
94
|
+
* @param chainId the chain id of the current chain
|
|
95
|
+
* @param tokenContract the address of the 1155 contract
|
|
96
|
+
* @returns the address of the signer
|
|
97
|
+
*/
|
|
98
|
+
export declare const recoverCreatorFromCreatorAttribution: ({ creatorAttribution: { version, domainName, structHash, signature }, chainId, tokenContract, }: {
|
|
99
|
+
creatorAttribution: CreatorAttributionEventParams;
|
|
100
|
+
tokenContract: Address;
|
|
101
|
+
chainId: number;
|
|
102
|
+
}) => Promise<`0x${string}`>;
|
|
103
|
+
/**
|
|
104
|
+
* Checks if the 1155 contract at that address supports the given version of the premint config.
|
|
105
|
+
*/
|
|
106
|
+
export declare const supportsPremintVersion: (version: PremintConfigVersion, tokenContract: Address, publicClient: PublicClient) => Promise<boolean>;
|
|
107
|
+
export declare function getPremintCollectionAddress({ collection, publicClient, }: {
|
|
108
|
+
collection: ContractCreationConfig;
|
|
109
|
+
publicClient: PublicClient;
|
|
110
|
+
}): Promise<Address>;
|
|
24
111
|
export {};
|
|
25
112
|
//# sourceMappingURL=preminter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preminter.d.ts","sourceRoot":"","sources":["../../src/premint/preminter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"preminter.d.ts","sourceRoot":"","sources":["../../src/premint/preminter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EACL,qCAAqC,IAAI,YAAY,EACrD,sBAAsB,EAGvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EAEnB,GAAG,EACH,YAAY,EAMZ,YAAY,EACb,MAAM,MAAM,CAAC;AAEd,KAAK,eAAe,GAAG,kBAAkB,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CAAC;CACzB,GAAG,eAAe,CAgBlB;AAED,MAAM,MAAM,6BAA6B,GAAG,YAAY,CACtD,OAAO,sBAAsB,EAC7B,oBAAoB,EACpB;IAAE,WAAW,EAAE,KAAK,CAAA;CAAE,CACvB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oCAAoC;wBAK3B,6BAA6B;mBAClC,OAAO;aACb,MAAM;4BAmChB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,YACxB,oBAAoB,iBACd,OAAO,gBACR,YAAY,KACzB,QAAQ,OAAO,CASjB,CAAC;AAEF,wBAAsB,2BAA2B,CAAC,EAChD,UAAU,EACV,YAAY,GACb,EAAE;IACD,UAAU,EAAE,sBAAsB,CAAC;IACnC,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoralabs/protocol-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"repository": "https://github.com/ourzora/zora-protocol",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"viem": "^1.16.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"zoralabs-tsconfig": "*",
|
|
26
27
|
"typescript": "^5.2.2",
|
|
27
28
|
"vite": "4.5.0",
|
|
28
29
|
"vitest": "0.34.6"
|
package/src/anvil.ts
CHANGED
|
@@ -28,13 +28,15 @@ async function waitForAnvilInit(anvil: any) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export type AnvilTestForkSettings = {
|
|
32
|
+
forkUrl: string;
|
|
33
|
+
forkBlockNumber: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
31
36
|
export const makeAnvilTest = ({
|
|
32
37
|
forkUrl,
|
|
33
38
|
forkBlockNumber,
|
|
34
|
-
}:
|
|
35
|
-
forkUrl: string;
|
|
36
|
-
forkBlockNumber: number;
|
|
37
|
-
}) =>
|
|
39
|
+
}: AnvilTestForkSettings) =>
|
|
38
40
|
test.extend<AnvilViemClientsTest>({
|
|
39
41
|
viemClients: async ({ task }, use) => {
|
|
40
42
|
console.log("setting up clients for ", task.name);
|
|
@@ -93,6 +95,7 @@ export const makeAnvilTest = ({
|
|
|
93
95
|
export const forkUrls = {
|
|
94
96
|
zoraMainnet: "https://rpc.zora.co/",
|
|
95
97
|
zoraGoerli: "https://testnet.rpc.zora.co",
|
|
98
|
+
zoraSepoli: "https://sepolia.rpc.zora.energy",
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
export const anvilTest = makeAnvilTest({
|
package/src/constants.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parseAbi } from "viem";
|
|
2
|
+
|
|
1
3
|
export const ZORA_API_BASE = "https://api.zora.co/";
|
|
2
4
|
export const OPEN_EDITION_MINT_SIZE = BigInt("18446744073709551615");
|
|
3
5
|
|
|
@@ -8,3 +10,8 @@ const SUBGRAPH_CONFIG_BASE =
|
|
|
8
10
|
export function getSubgraph(name: string, version: string): string {
|
|
9
11
|
return `${SUBGRAPH_CONFIG_BASE}/${name}/${version}/gn`;
|
|
10
12
|
}
|
|
13
|
+
|
|
14
|
+
export const zora721Abi = parseAbi([
|
|
15
|
+
"function mintWithRewards(address recipient, uint256 quantity, string calldata comment, address mintReferral) external payable",
|
|
16
|
+
"function zoraFeeForAmount(uint256 amount) public view returns (address, uint256)",
|
|
17
|
+
] as const);
|
|
@@ -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,54 +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
|
-
|
|
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
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
65
79
|
variables: {
|
|
66
|
-
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`,
|
|
67
85
|
},
|
|
68
86
|
});
|
|
69
|
-
return response.zoraCreateToken?.salesStrategies?.find(() => true)
|
|
70
|
-
?.fixedPriceMinterAddress;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
87
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
}
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
fixedPrice,
|
|
111
|
+
mintFeePerQuantity: BigInt(token.contract.mintFeePerQuantity),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
88
114
|
}
|
|
89
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,
|