@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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Account, Address } from "viem";
|
|
2
|
+
import { GenericTokenIdTypes } from "src/types";
|
|
3
|
+
|
|
4
|
+
export type MintParameters<MintType> = {
|
|
5
|
+
/** Type of the collection to be minted. */
|
|
6
|
+
mintType: MintType;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type Erc1155MintParameters = MintParameters<"1155"> & {
|
|
10
|
+
/** Token id to mint */
|
|
11
|
+
tokenId: GenericTokenIdTypes;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type Erc721MintParameters = MintParameters<"721">;
|
|
15
|
+
|
|
16
|
+
export type OnChainMintParameters =
|
|
17
|
+
| Erc1155MintParameters
|
|
18
|
+
| Erc721MintParameters;
|
|
19
|
+
|
|
20
|
+
export type PremintMintParameters = MintParameters<"premint"> & {
|
|
21
|
+
/** uid of the Premint to mint */
|
|
22
|
+
uid: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type MintType = "1155" | "721" | "premint";
|
|
26
|
+
|
|
27
|
+
export type MintTypes =
|
|
28
|
+
| Erc1155MintParameters
|
|
29
|
+
| Erc721MintParameters
|
|
30
|
+
| PremintMintParameters;
|
|
31
|
+
|
|
32
|
+
export const isOnChainMint = (mint: MintTypes): mint is OnChainMintParameters =>
|
|
33
|
+
mint.mintType !== "premint";
|
|
34
|
+
|
|
35
|
+
export const is1155Mint = (mint: MintTypes): mint is Erc1155MintParameters =>
|
|
36
|
+
mint.mintType === "1155";
|
|
37
|
+
|
|
38
|
+
export type MakeMintParametersArgumentsBase = {
|
|
39
|
+
/** Premint contract address */
|
|
40
|
+
tokenContract: Address;
|
|
41
|
+
/** Account to execute the mint */
|
|
42
|
+
minterAccount: Account | Address;
|
|
43
|
+
/** Quantity of tokens to mint. Defaults to 1 */
|
|
44
|
+
quantityToMint: number | bigint;
|
|
45
|
+
/** Comment to add to the mint */
|
|
46
|
+
mintComment?: string;
|
|
47
|
+
/** Address to receive the mint referral reward */
|
|
48
|
+
mintReferral?: Address;
|
|
49
|
+
/** Address to receive the minted tokens. Defaults to the minting account */
|
|
50
|
+
mintRecipient?: Address;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type Make1155MintArguments = MakeMintParametersArgumentsBase &
|
|
54
|
+
Erc1155MintParameters & {
|
|
55
|
+
saleType?: SaleType;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type Make721MintArguments = MakeMintParametersArgumentsBase &
|
|
59
|
+
Erc721MintParameters & {
|
|
60
|
+
saleType?: SaleType;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type MakePremintMintParametersArguments =
|
|
64
|
+
MakeMintParametersArgumentsBase &
|
|
65
|
+
PremintMintParameters & {
|
|
66
|
+
/** Account to receive first minter reward, if this mint brings the premint onchain */
|
|
67
|
+
firstMinter?: Address;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type MakeMintParametersArguments =
|
|
71
|
+
| Make1155MintArguments
|
|
72
|
+
| Make721MintArguments
|
|
73
|
+
| MakePremintMintParametersArguments;
|
|
74
|
+
|
|
75
|
+
export type GetMintCostsParameters = {
|
|
76
|
+
/** Address of token contract/collection to get the mint costs for */
|
|
77
|
+
collection: Address;
|
|
78
|
+
/** Quantity of tokens that will be minted */
|
|
79
|
+
quantityMinted: number | bigint;
|
|
80
|
+
} & MintTypes;
|
|
81
|
+
|
|
82
|
+
export type SaleType = "fixedPrice" | "erc20";
|
|
83
|
+
|
|
84
|
+
type SaleStrategy<T extends SaleType> = {
|
|
85
|
+
saleType: T;
|
|
86
|
+
address: Address;
|
|
87
|
+
pricePerToken: bigint;
|
|
88
|
+
saleEnd: string;
|
|
89
|
+
saleStart: string;
|
|
90
|
+
maxTokensPerAddress: bigint;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
type FixedPriceSaleStrategy = SaleStrategy<"fixedPrice">;
|
|
94
|
+
|
|
95
|
+
type ERC20SaleStrategy = SaleStrategy<"erc20"> & {
|
|
96
|
+
currency: Address;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
type SaleStrategies = FixedPriceSaleStrategy | ERC20SaleStrategy;
|
|
100
|
+
|
|
101
|
+
export function isErc20SaleStrategy(
|
|
102
|
+
salesConfig: SaleStrategies,
|
|
103
|
+
): salesConfig is ERC20SaleStrategy {
|
|
104
|
+
return salesConfig.saleType === "erc20";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type SalesConfigAndTokenInfo = {
|
|
108
|
+
salesConfig: SaleStrategies;
|
|
109
|
+
mintFeePerQuantity: bigint;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export interface IMintGetter {
|
|
113
|
+
getSalesConfigAndTokenInfo({
|
|
114
|
+
tokenAddress,
|
|
115
|
+
tokenId,
|
|
116
|
+
saleType,
|
|
117
|
+
}: {
|
|
118
|
+
tokenAddress: Address;
|
|
119
|
+
tokenId?: GenericTokenIdTypes;
|
|
120
|
+
saleType?: SaleType;
|
|
121
|
+
}): Promise<SalesConfigAndTokenInfo>;
|
|
122
|
+
}
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
Address,
|
|
19
19
|
BaseError,
|
|
20
20
|
ContractFunctionRevertedError,
|
|
21
|
-
PublicClient,
|
|
22
21
|
WalletClient,
|
|
23
22
|
parseEther,
|
|
24
23
|
} from "viem";
|
|
@@ -39,8 +38,9 @@ import {
|
|
|
39
38
|
getFixedPricedMinter,
|
|
40
39
|
waitForSuccess,
|
|
41
40
|
} from "src/test-utils";
|
|
41
|
+
import { PublicClient } from "src/utils";
|
|
42
42
|
|
|
43
|
-
const mintsMainnetDeployedBlock =
|
|
43
|
+
const mintsMainnetDeployedBlock = 15372992;
|
|
44
44
|
|
|
45
45
|
const anvilTest = makeAnvilTest({
|
|
46
46
|
forkUrl: forkUrls.zoraMainnet,
|
|
@@ -77,7 +77,7 @@ const setupContractUsingPremint = async ({
|
|
|
77
77
|
contractConfig.contractName = "Testing contract for MINTS";
|
|
78
78
|
|
|
79
79
|
const contractAddress = await getPremintCollectionAddress({
|
|
80
|
-
|
|
80
|
+
contract: contractConfig,
|
|
81
81
|
publicClient,
|
|
82
82
|
});
|
|
83
83
|
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
PremintConfigV2,
|
|
13
13
|
} from "@zoralabs/protocol-deployments";
|
|
14
14
|
import { ContractCreationConfig } from "src/preminter";
|
|
15
|
-
import {
|
|
15
|
+
import { makeContractParameters } from "src/utils";
|
|
16
16
|
import {
|
|
17
17
|
Account,
|
|
18
18
|
Address,
|
|
@@ -53,7 +53,7 @@ export const mintWithEthParams = ({
|
|
|
53
53
|
pricePerMint: bigint;
|
|
54
54
|
account: Address | Account;
|
|
55
55
|
}) =>
|
|
56
|
-
|
|
56
|
+
makeContractParameters({
|
|
57
57
|
abi: zoraMintsManagerImplConfig.abi,
|
|
58
58
|
address: zoraMintsManagerImplConfig.address[chainId],
|
|
59
59
|
functionName: "mintWithEth",
|
|
@@ -152,7 +152,7 @@ export function collectWithMintsParams({
|
|
|
152
152
|
mintArguments,
|
|
153
153
|
});
|
|
154
154
|
|
|
155
|
-
return
|
|
155
|
+
return makeContractParameters({
|
|
156
156
|
abi: zoraMints1155Config.abi,
|
|
157
157
|
address: zoraMints1155Config.address[chainId],
|
|
158
158
|
functionName: "transferBatchToManagerAndCall",
|
|
@@ -416,7 +416,7 @@ export function collectPremintV2WithMintsParams({
|
|
|
416
416
|
...rest,
|
|
417
417
|
});
|
|
418
418
|
|
|
419
|
-
return
|
|
419
|
+
return makeContractParameters({
|
|
420
420
|
abi: zoraMints1155Config.abi,
|
|
421
421
|
address: zoraMints1155Config.address[chainId],
|
|
422
422
|
functionName: "transferBatchToManagerAndCall",
|
|
@@ -1,7 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ContractCreationConfig,
|
|
3
|
+
PremintConfigVersion as PremintConfigVersionOrig,
|
|
4
|
+
} from "@zoralabs/protocol-deployments";
|
|
5
|
+
import { Address } from "viem";
|
|
2
6
|
|
|
3
7
|
export enum PremintConfigVersion {
|
|
4
8
|
V1 = PremintConfigVersionOrig.V1,
|
|
5
9
|
V2 = PremintConfigVersionOrig.V2,
|
|
6
10
|
V3 = PremintConfigVersionOrig.V3,
|
|
7
11
|
}
|
|
12
|
+
|
|
13
|
+
export type ContractCreationConfigWithOptionalAdditionalAdmins = Omit<
|
|
14
|
+
ContractCreationConfig,
|
|
15
|
+
"additionalAdmins"
|
|
16
|
+
> & {
|
|
17
|
+
/** Optional: if there are additional admins accounts that should be added as contract wide admins upon contract creation. */
|
|
18
|
+
additionalAdmins?: Address[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type ContractCreationConfigAndAddress = {
|
|
22
|
+
/** Parameters for creating the contract for new premints. */
|
|
23
|
+
collection?: ContractCreationConfigWithOptionalAdditionalAdmins;
|
|
24
|
+
/** Premint collection address */
|
|
25
|
+
collectionAddress: Address;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ContractCreationConfigOrAddress =
|
|
29
|
+
| {
|
|
30
|
+
/** Parameters for creating the contract for new premints. */
|
|
31
|
+
contract: ContractCreationConfigWithOptionalAdditionalAdmins;
|
|
32
|
+
contractAddress?: undefined;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
contract?: undefined;
|
|
36
|
+
/** Premint collection address */
|
|
37
|
+
contractAddress: Address;
|
|
38
|
+
};
|
|
@@ -10,14 +10,21 @@ import {
|
|
|
10
10
|
PremintConfigWithVersion,
|
|
11
11
|
} from "@zoralabs/protocol-deployments";
|
|
12
12
|
import { PremintSignatureGetResponse } from "./premint-api-client";
|
|
13
|
+
import { ContractCreationConfigOrAddress } from "./contract-types";
|
|
13
14
|
|
|
14
15
|
export const convertCollectionFromApi = (
|
|
15
16
|
collection: PremintSignatureGetResponse["collection"],
|
|
16
|
-
): ContractCreationConfig =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
): ContractCreationConfig | undefined => {
|
|
18
|
+
if (!collection) return undefined;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
additionalAdmins:
|
|
22
|
+
(collection.additionalAdmins as Address[] | undefined) || [],
|
|
23
|
+
contractAdmin: collection.contractAdmin as Address,
|
|
24
|
+
contractName: collection.contractName,
|
|
25
|
+
contractURI: collection.contractURI,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
21
28
|
|
|
22
29
|
/**
|
|
23
30
|
* Convert server to on-chain types for a premint
|
|
@@ -82,6 +89,7 @@ export const convertGetPremintApiResponse = (
|
|
|
82
89
|
) => ({
|
|
83
90
|
...convertPremintFromApi(response.premint),
|
|
84
91
|
collection: convertCollectionFromApi(response.collection),
|
|
92
|
+
collectionAddress: response.collection_address as Address,
|
|
85
93
|
signature: response.signature as Hex,
|
|
86
94
|
});
|
|
87
95
|
|
|
@@ -142,21 +150,35 @@ export type PremintSignatureResponse =
|
|
|
142
150
|
* @returns
|
|
143
151
|
*/
|
|
144
152
|
export const encodePostSignatureInput = <T extends PremintConfigVersion>({
|
|
145
|
-
collection,
|
|
153
|
+
contract: collection,
|
|
154
|
+
contractAddress: collectionAddress,
|
|
146
155
|
premintConfigVersion,
|
|
147
156
|
premintConfig,
|
|
148
157
|
signature,
|
|
149
158
|
chainId,
|
|
150
159
|
}: {
|
|
151
|
-
collection: ContractCreationConfig;
|
|
152
160
|
signature: Hex;
|
|
153
161
|
chainId: number;
|
|
154
|
-
} & PremintConfigWithVersion<T>
|
|
162
|
+
} & PremintConfigWithVersion<T> &
|
|
163
|
+
ContractCreationConfigOrAddress): PremintSignatureRequestBody => ({
|
|
155
164
|
premint: encodePremintForAPI({
|
|
156
165
|
premintConfig,
|
|
157
166
|
premintConfigVersion,
|
|
158
167
|
}),
|
|
159
168
|
signature,
|
|
160
|
-
collection
|
|
169
|
+
collection: collection as
|
|
170
|
+
| PremintSignatureRequestBody["collection"]
|
|
171
|
+
| undefined,
|
|
172
|
+
collection_address: collectionAddress,
|
|
161
173
|
chain_name: networkConfigByChain[chainId]!.zoraBackendChainName,
|
|
162
174
|
});
|
|
175
|
+
|
|
176
|
+
export const isPremintConfigV1 = (
|
|
177
|
+
premintConfigAndVersion: PremintConfigAndVersion,
|
|
178
|
+
): premintConfigAndVersion is PremintConfigWithVersion<PremintConfigVersion.V1> =>
|
|
179
|
+
premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V1;
|
|
180
|
+
|
|
181
|
+
export const isPremintConfigV2 = (
|
|
182
|
+
premintConfigAndVersion: PremintConfigAndVersion,
|
|
183
|
+
): premintConfigAndVersion is PremintConfigWithVersion<PremintConfigVersion.V2> =>
|
|
184
|
+
premintConfigAndVersion.premintConfigVersion === PremintConfigVersion.V2;
|
|
@@ -4,8 +4,7 @@ import {
|
|
|
4
4
|
} from "../apis/http-api-base";
|
|
5
5
|
import { components, paths } from "../apis/generated/premint-api-types";
|
|
6
6
|
import { ZORA_API_BASE } from "../constants";
|
|
7
|
-
import {
|
|
8
|
-
import { getApiNetworkConfigForChain } from "src/mint/mint-api-client";
|
|
7
|
+
import { getApiNetworkConfigForChain } from "src/mint/subgraph-mint-getter";
|
|
9
8
|
import {
|
|
10
9
|
ContractCreationConfig,
|
|
11
10
|
PremintConfigAndVersion,
|
|
@@ -19,6 +18,7 @@ import {
|
|
|
19
18
|
convertGetPremintApiResponse,
|
|
20
19
|
encodePostSignatureInput,
|
|
21
20
|
} from "./conversions";
|
|
21
|
+
import { ContractCreationConfigOrAddress } from "./contract-types";
|
|
22
22
|
|
|
23
23
|
type PremintNextUIDGetType =
|
|
24
24
|
paths["/signature/{chain_name}/{collection_address}/next_uid"]["get"];
|
|
@@ -29,8 +29,6 @@ export type PremintNextUIDGetResponse =
|
|
|
29
29
|
|
|
30
30
|
type SignaturePremintGetType =
|
|
31
31
|
paths["/signature/{chain_name}/{collection_address}/{uid}"]["get"];
|
|
32
|
-
type PremintSignatureGetPathParameters =
|
|
33
|
-
SignaturePremintGetType["parameters"]["path"];
|
|
34
32
|
export type PremintSignatureGetResponse =
|
|
35
33
|
SignaturePremintGetType["responses"][200]["content"]["application/json"];
|
|
36
34
|
|
|
@@ -49,59 +47,83 @@ const postSignature = async ({
|
|
|
49
47
|
);
|
|
50
48
|
|
|
51
49
|
const getNextUID = async ({
|
|
52
|
-
|
|
50
|
+
chainId,
|
|
53
51
|
collection_address,
|
|
54
52
|
httpClient: { retries, get } = defaultHttpClient,
|
|
55
|
-
}: PremintNextUIDGetPathParameters & {
|
|
53
|
+
}: Omit<PremintNextUIDGetPathParameters, "chain_name"> & {
|
|
54
|
+
chainId: number;
|
|
56
55
|
httpClient?: Pick<IHttpClient, "retries" | "get">;
|
|
57
56
|
}): Promise<PremintNextUIDGetResponse> =>
|
|
58
57
|
retries(() =>
|
|
59
58
|
get<PremintNextUIDGetResponse>(
|
|
60
|
-
`${ZORA_API_BASE}premint/signature/${
|
|
59
|
+
`${ZORA_API_BASE}premint/signature/${
|
|
60
|
+
getApiNetworkConfigForChain(chainId).zoraBackendChainName
|
|
61
|
+
}/${collection_address}/next_uid`,
|
|
61
62
|
),
|
|
62
63
|
);
|
|
63
64
|
|
|
64
|
-
const getSignature = async ({
|
|
65
|
-
|
|
65
|
+
export const getSignature = async ({
|
|
66
|
+
collectionAddress,
|
|
66
67
|
uid,
|
|
67
|
-
|
|
68
|
+
chainId,
|
|
68
69
|
httpClient: { retries, get } = defaultHttpClient,
|
|
69
|
-
}:
|
|
70
|
+
}: {
|
|
71
|
+
collectionAddress: Address;
|
|
72
|
+
uid: number;
|
|
73
|
+
chainId: number;
|
|
70
74
|
httpClient?: Pick<IHttpClient, "retries" | "get">;
|
|
71
75
|
}): Promise<
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
{
|
|
77
|
+
signature: Hex;
|
|
78
|
+
collection: ContractCreationConfig | undefined;
|
|
79
|
+
collectionAddress: Address;
|
|
80
|
+
} & PremintConfigAndVersion
|
|
75
81
|
> => {
|
|
82
|
+
const chainName = getApiNetworkConfigForChain(chainId).zoraBackendChainName;
|
|
76
83
|
const result = await retries(() =>
|
|
77
84
|
get<PremintSignatureGetResponse>(
|
|
78
|
-
`${ZORA_API_BASE}premint/signature/${
|
|
85
|
+
`${ZORA_API_BASE}premint/signature/${chainName}/${collectionAddress.toLowerCase()}/${uid}`,
|
|
79
86
|
),
|
|
80
87
|
);
|
|
81
88
|
|
|
82
|
-
return result;
|
|
89
|
+
return convertGetPremintApiResponse(result);
|
|
83
90
|
};
|
|
84
91
|
|
|
85
|
-
|
|
92
|
+
export interface IPremintGetter {
|
|
93
|
+
getSignature(params: {
|
|
94
|
+
collectionAddress: Address;
|
|
95
|
+
uid: number;
|
|
96
|
+
}): ReturnType<typeof getSignature>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface IPremintAPI {
|
|
100
|
+
getSignature: IPremintGetter["getSignature"];
|
|
101
|
+
|
|
102
|
+
getNextUID(collectionAddress: Address): Promise<number>;
|
|
103
|
+
|
|
104
|
+
postSignature<T extends PremintConfigVersion>(
|
|
105
|
+
params: {
|
|
106
|
+
signature: Hex;
|
|
107
|
+
} & PremintConfigWithVersion<T> &
|
|
108
|
+
ContractCreationConfigOrAddress,
|
|
109
|
+
): Promise<PremintSignatureResponse>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class PremintAPIClient implements IPremintAPI {
|
|
113
|
+
chainId: number;
|
|
86
114
|
httpClient: IHttpClient;
|
|
87
|
-
networkConfig: NetworkConfig;
|
|
88
115
|
|
|
89
116
|
constructor(chainId: number, httpClient?: IHttpClient) {
|
|
117
|
+
this.chainId = chainId;
|
|
90
118
|
this.httpClient = httpClient || defaultHttpClient;
|
|
91
|
-
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
92
119
|
}
|
|
93
|
-
postSignature =
|
|
94
|
-
collection,
|
|
120
|
+
postSignature: IPremintAPI["postSignature"] = ({
|
|
95
121
|
signature,
|
|
96
|
-
...
|
|
97
|
-
}: {
|
|
98
|
-
collection: ContractCreationConfig;
|
|
99
|
-
signature: Hex;
|
|
100
|
-
} & PremintConfigWithVersion<T>): Promise<PremintSignatureResponse> => {
|
|
122
|
+
...rest
|
|
123
|
+
}): Promise<PremintSignatureResponse> => {
|
|
101
124
|
const data = encodePostSignatureInput({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
chainId: this.networkConfig.chainId,
|
|
125
|
+
...rest,
|
|
126
|
+
chainId: this.chainId,
|
|
105
127
|
signature,
|
|
106
128
|
});
|
|
107
129
|
return postSignature({
|
|
@@ -110,35 +132,25 @@ class PremintAPIClient {
|
|
|
110
132
|
});
|
|
111
133
|
};
|
|
112
134
|
|
|
113
|
-
getNextUID = async (collectionAddress
|
|
135
|
+
getNextUID: IPremintAPI["getNextUID"] = async (collectionAddress) =>
|
|
114
136
|
(
|
|
115
137
|
await getNextUID({
|
|
116
138
|
collection_address: collectionAddress.toLowerCase(),
|
|
117
|
-
|
|
139
|
+
chainId: this.chainId,
|
|
118
140
|
httpClient: this.httpClient,
|
|
119
141
|
})
|
|
120
142
|
).next_uid;
|
|
121
143
|
|
|
122
|
-
getSignature = async ({
|
|
144
|
+
getSignature: IPremintAPI["getSignature"] = async ({
|
|
123
145
|
collectionAddress,
|
|
124
146
|
uid,
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}): Promise<
|
|
129
|
-
{
|
|
130
|
-
signature: Hex;
|
|
131
|
-
collection: ContractCreationConfig;
|
|
132
|
-
} & PremintConfigAndVersion
|
|
133
|
-
> => {
|
|
134
|
-
const response = await getSignature({
|
|
135
|
-
collection_address: collectionAddress.toLowerCase(),
|
|
147
|
+
}) => {
|
|
148
|
+
return getSignature({
|
|
149
|
+
collectionAddress,
|
|
136
150
|
uid,
|
|
137
|
-
|
|
151
|
+
chainId: this.chainId,
|
|
138
152
|
httpClient: this.httpClient,
|
|
139
153
|
});
|
|
140
|
-
|
|
141
|
-
return convertGetPremintApiResponse(response);
|
|
142
154
|
};
|
|
143
155
|
}
|
|
144
156
|
|