@zoralabs/protocol-sdk 0.8.0 → 0.9.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 +7 -7
- package/CHANGELOG.md +11 -0
- package/dist/allow-list/allow-list-client.d.ts +26 -0
- package/dist/allow-list/allow-list-client.d.ts.map +1 -0
- package/dist/allow-list/types.d.ts +14 -0
- package/dist/allow-list/types.d.ts.map +1 -0
- package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
- package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/apis/subgraph-querier.d.ts +18 -0
- package/dist/apis/subgraph-querier.d.ts.map +1 -0
- package/dist/create/contract-setup.d.ts +1 -0
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/minter-defaults.d.ts +5 -0
- package/dist/create/minter-defaults.d.ts.map +1 -0
- package/dist/create/minter-setup.d.ts +14 -0
- package/dist/create/minter-setup.d.ts.map +1 -0
- package/dist/create/token-setup.d.ts +4 -19
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/create/types.d.ts +32 -7
- package/dist/create/types.d.ts.map +1 -1
- package/dist/create/update.d.ts +15 -0
- package/dist/create/update.d.ts.map +1 -0
- package/dist/index.cjs +2249 -1936
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2284 -1966
- package/dist/index.js.map +1 -1
- package/dist/ipfs/token-metadata.d.ts +1 -0
- package/dist/ipfs/token-metadata.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +2 -6
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +3 -1
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +9 -7
- package/dist/mint/mint-transactions.d.ts.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +5 -4
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +42 -15
- package/dist/mint/subgraph-queries.d.ts.map +1 -1
- package/dist/mint/types.d.ts +32 -13
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/sparks/sparks-contracts.d.ts +96 -96
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -8
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/allow-list/allow-list-client.ts +105 -0
- package/src/allow-list/types.ts +15 -0
- package/src/apis/generated/allow-list-api-types.ts +288 -0
- package/src/apis/http-api-base.ts +12 -0
- package/src/apis/subgraph-querier.ts +38 -0
- package/src/create/1155-create-helper.test.ts +216 -66
- package/src/create/1155-create-helper.ts +4 -4
- package/src/create/contract-setup.ts +8 -0
- package/src/create/minter-defaults.test.ts +21 -0
- package/src/create/minter-defaults.ts +134 -0
- package/src/create/minter-setup.ts +293 -0
- package/src/create/token-setup.ts +14 -190
- package/src/create/types.ts +56 -9
- package/src/create/update.ts +93 -0
- package/src/index.ts +4 -0
- package/src/ipfs/token-metadata.ts +18 -0
- package/src/mint/mint-client.test.ts +219 -15
- package/src/mint/mint-client.ts +2 -34
- package/src/mint/mint-queries.ts +34 -13
- package/src/mint/mint-transactions.ts +104 -17
- package/src/mint/subgraph-mint-getter.ts +107 -50
- package/src/mint/subgraph-queries.ts +67 -37
- package/src/mint/types.ts +55 -16
- package/src/premint/premint-client.test.ts +6 -5
- package/src/types.ts +1 -1
- package/src/utils.ts +1 -25
|
@@ -5,28 +5,35 @@ import {
|
|
|
5
5
|
zeroAddress,
|
|
6
6
|
Account,
|
|
7
7
|
SimulateContractParameters,
|
|
8
|
+
Hex,
|
|
8
9
|
} from "viem";
|
|
9
10
|
import {
|
|
10
11
|
erc20MinterABI,
|
|
11
12
|
zoraCreator1155ImplABI,
|
|
13
|
+
zoraTimedSaleStrategyABI,
|
|
12
14
|
} from "@zoralabs/protocol-deployments";
|
|
13
15
|
import { zora721Abi, zora1155LegacyAbi } from "src/constants";
|
|
14
16
|
import {
|
|
15
17
|
GenericTokenIdTypes,
|
|
16
18
|
SimulateContractParametersWithAccount,
|
|
17
19
|
} from "src/types";
|
|
18
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
Concrete,
|
|
22
|
+
makeContractParameters,
|
|
23
|
+
mintRecipientOrAccount,
|
|
24
|
+
} from "src/utils";
|
|
19
25
|
import { MintCosts, SaleStrategies, isErc20SaleStrategy } from "./types";
|
|
20
26
|
import { MakeMintParametersArgumentsBase } from "./types";
|
|
21
27
|
|
|
22
28
|
import { contractSupportsNewMintFunction } from "./utils";
|
|
23
29
|
import { OnchainSalesConfigAndTokenInfo } from "./types";
|
|
30
|
+
import { AllowListEntry } from "src/allow-list/types";
|
|
24
31
|
|
|
25
32
|
export function makeOnchainMintCall({
|
|
26
33
|
token,
|
|
27
34
|
mintParams,
|
|
28
35
|
}: {
|
|
29
|
-
token: OnchainSalesConfigAndTokenInfo
|
|
36
|
+
token: Concrete<OnchainSalesConfigAndTokenInfo>;
|
|
30
37
|
mintParams: Omit<MakeMintParametersArgumentsBase, "tokenContract">;
|
|
31
38
|
}): SimulateContractParametersWithAccount {
|
|
32
39
|
if (token.mintType === "721") {
|
|
@@ -47,7 +54,7 @@ export function makeOnchainMintCall({
|
|
|
47
54
|
|
|
48
55
|
export type MintableParameters = Pick<
|
|
49
56
|
OnchainSalesConfigAndTokenInfo,
|
|
50
|
-
"contractVersion" | "
|
|
57
|
+
"contractVersion" | "salesConfig"
|
|
51
58
|
>;
|
|
52
59
|
|
|
53
60
|
export function makePrepareMint1155TokenParams({
|
|
@@ -59,8 +66,9 @@ export function makePrepareMint1155TokenParams({
|
|
|
59
66
|
mintReferral,
|
|
60
67
|
mintRecipient,
|
|
61
68
|
quantityToMint,
|
|
69
|
+
allowListEntry,
|
|
62
70
|
}: {
|
|
63
|
-
salesConfigAndTokenInfo: MintableParameters
|
|
71
|
+
salesConfigAndTokenInfo: Concrete<MintableParameters>;
|
|
64
72
|
tokenId: GenericTokenIdTypes;
|
|
65
73
|
} & Pick<
|
|
66
74
|
MakeMintParametersArgumentsBase,
|
|
@@ -70,6 +78,7 @@ export function makePrepareMint1155TokenParams({
|
|
|
70
78
|
| "mintReferral"
|
|
71
79
|
| "quantityToMint"
|
|
72
80
|
| "mintRecipient"
|
|
81
|
+
| "allowListEntry"
|
|
73
82
|
>): SimulateContractParameters<any, any, any, any, any, Address | Account> {
|
|
74
83
|
const mintQuantity = BigInt(quantityToMint || 1);
|
|
75
84
|
|
|
@@ -77,7 +86,7 @@ export function makePrepareMint1155TokenParams({
|
|
|
77
86
|
|
|
78
87
|
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
79
88
|
|
|
80
|
-
if (saleType === "fixedPrice") {
|
|
89
|
+
if (saleType === "fixedPrice" || saleType === "allowlist") {
|
|
81
90
|
return makeEthMintCall({
|
|
82
91
|
mintComment,
|
|
83
92
|
minterAccount,
|
|
@@ -87,6 +96,27 @@ export function makePrepareMint1155TokenParams({
|
|
|
87
96
|
salesConfigAndTokenInfo,
|
|
88
97
|
tokenContract,
|
|
89
98
|
tokenId,
|
|
99
|
+
allowListEntry,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (saleType === "timed") {
|
|
104
|
+
return makeContractParameters({
|
|
105
|
+
abi: zoraTimedSaleStrategyABI,
|
|
106
|
+
functionName: "mint",
|
|
107
|
+
account: minterAccount,
|
|
108
|
+
address: salesConfigAndTokenInfo.salesConfig.address,
|
|
109
|
+
value:
|
|
110
|
+
salesConfigAndTokenInfo.salesConfig.mintFeePerQuantity * mintQuantity,
|
|
111
|
+
/* args: mintTo, quantity, collection, tokenId, mintReferral, comment */
|
|
112
|
+
args: [
|
|
113
|
+
mintTo,
|
|
114
|
+
mintQuantity,
|
|
115
|
+
tokenContract,
|
|
116
|
+
BigInt(tokenId),
|
|
117
|
+
mintReferral || zeroAddress,
|
|
118
|
+
mintComment || "",
|
|
119
|
+
],
|
|
90
120
|
});
|
|
91
121
|
}
|
|
92
122
|
|
|
@@ -122,7 +152,7 @@ function makePrepareMint721TokenParams({
|
|
|
122
152
|
mintRecipient,
|
|
123
153
|
quantityToMint,
|
|
124
154
|
}: {
|
|
125
|
-
salesConfigAndTokenInfo: MintableParameters
|
|
155
|
+
salesConfigAndTokenInfo: Concrete<MintableParameters>;
|
|
126
156
|
} & Pick<
|
|
127
157
|
MakeMintParametersArgumentsBase,
|
|
128
158
|
| "minterAccount"
|
|
@@ -134,9 +164,9 @@ function makePrepareMint721TokenParams({
|
|
|
134
164
|
>): SimulateContractParametersWithAccount {
|
|
135
165
|
const actualQuantityToMint = BigInt(quantityToMint || 1);
|
|
136
166
|
const mintValue = parseMintCosts({
|
|
137
|
-
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
138
167
|
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
139
168
|
quantityToMint: actualQuantityToMint,
|
|
169
|
+
allowListEntry: undefined,
|
|
140
170
|
}).totalCostEth;
|
|
141
171
|
|
|
142
172
|
return makeContractParameters({
|
|
@@ -154,6 +184,37 @@ function makePrepareMint721TokenParams({
|
|
|
154
184
|
});
|
|
155
185
|
}
|
|
156
186
|
|
|
187
|
+
function makeFixedPriceMinterArguments({
|
|
188
|
+
mintTo,
|
|
189
|
+
mintComment,
|
|
190
|
+
}: {
|
|
191
|
+
mintTo: Address;
|
|
192
|
+
mintComment?: string;
|
|
193
|
+
}) {
|
|
194
|
+
return encodeAbiParameters(parseAbiParameters("address, string"), [
|
|
195
|
+
mintTo,
|
|
196
|
+
mintComment || "",
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function makeAllowListMinterArguments({
|
|
201
|
+
mintTo,
|
|
202
|
+
allowListEntry,
|
|
203
|
+
}: {
|
|
204
|
+
mintTo: Address;
|
|
205
|
+
allowListEntry: AllowListEntry;
|
|
206
|
+
}) {
|
|
207
|
+
return encodeAbiParameters(
|
|
208
|
+
parseAbiParameters("address, uint256, uint256, bytes32[]"),
|
|
209
|
+
[
|
|
210
|
+
mintTo,
|
|
211
|
+
BigInt(allowListEntry.maxCanMint),
|
|
212
|
+
allowListEntry.price,
|
|
213
|
+
allowListEntry.proof,
|
|
214
|
+
],
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
157
218
|
function makeEthMintCall({
|
|
158
219
|
tokenContract,
|
|
159
220
|
tokenId,
|
|
@@ -163,26 +224,35 @@ function makeEthMintCall({
|
|
|
163
224
|
mintReferral,
|
|
164
225
|
mintQuantity,
|
|
165
226
|
mintTo,
|
|
227
|
+
allowListEntry,
|
|
166
228
|
}: {
|
|
167
229
|
minterAccount: Account | Address;
|
|
168
230
|
tokenContract: Address;
|
|
169
231
|
mintTo: Address;
|
|
170
|
-
salesConfigAndTokenInfo: MintableParameters
|
|
232
|
+
salesConfigAndTokenInfo: Concrete<MintableParameters>;
|
|
171
233
|
tokenId: GenericTokenIdTypes;
|
|
172
234
|
mintQuantity: bigint;
|
|
173
235
|
mintComment?: string;
|
|
174
236
|
mintReferral?: Address;
|
|
237
|
+
allowListEntry?: AllowListEntry;
|
|
175
238
|
}): SimulateContractParametersWithAccount {
|
|
176
239
|
const mintValue = parseMintCosts({
|
|
177
|
-
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
178
240
|
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
179
241
|
quantityToMint: mintQuantity,
|
|
242
|
+
allowListEntry,
|
|
180
243
|
}).totalCostEth;
|
|
181
244
|
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
)
|
|
245
|
+
const saleType = salesConfigAndTokenInfo.salesConfig.saleType;
|
|
246
|
+
let minterArguments: Hex;
|
|
247
|
+
|
|
248
|
+
if (saleType === "fixedPrice") {
|
|
249
|
+
minterArguments = makeFixedPriceMinterArguments({ mintTo, mintComment });
|
|
250
|
+
} else if (saleType === "allowlist") {
|
|
251
|
+
if (!allowListEntry) throw new Error("Missing allowListEntry");
|
|
252
|
+
minterArguments = makeAllowListMinterArguments({ mintTo, allowListEntry });
|
|
253
|
+
} else {
|
|
254
|
+
throw new Error("Unsupported sale type");
|
|
255
|
+
}
|
|
186
256
|
|
|
187
257
|
// if based on contract version it has the new mint function,
|
|
188
258
|
// call the new mint function.
|
|
@@ -223,18 +293,35 @@ function makeEthMintCall({
|
|
|
223
293
|
});
|
|
224
294
|
}
|
|
225
295
|
|
|
296
|
+
function paidMintCost(
|
|
297
|
+
salesConfig: SaleStrategies,
|
|
298
|
+
allowListEntry?: Pick<AllowListEntry, "price">,
|
|
299
|
+
) {
|
|
300
|
+
if (
|
|
301
|
+
salesConfig.saleType === "erc20" ||
|
|
302
|
+
salesConfig.saleType === "fixedPrice"
|
|
303
|
+
) {
|
|
304
|
+
return salesConfig.pricePerToken;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (allowListEntry) return allowListEntry.price;
|
|
308
|
+
|
|
309
|
+
return 0n;
|
|
310
|
+
}
|
|
311
|
+
|
|
226
312
|
export function parseMintCosts({
|
|
227
313
|
salesConfig,
|
|
228
|
-
mintFeePerQuantity,
|
|
229
314
|
quantityToMint,
|
|
315
|
+
allowListEntry,
|
|
230
316
|
}: {
|
|
231
317
|
salesConfig: SaleStrategies;
|
|
232
|
-
mintFeePerQuantity: bigint;
|
|
233
318
|
quantityToMint: bigint;
|
|
319
|
+
allowListEntry: Pick<AllowListEntry, "price"> | undefined;
|
|
234
320
|
}): MintCosts {
|
|
235
|
-
const mintFeeForTokens = mintFeePerQuantity * quantityToMint;
|
|
321
|
+
const mintFeeForTokens = salesConfig.mintFeePerQuantity * quantityToMint;
|
|
236
322
|
|
|
237
|
-
const tokenPurchaseCost =
|
|
323
|
+
const tokenPurchaseCost =
|
|
324
|
+
paidMintCost(salesConfig, allowListEntry) * quantityToMint;
|
|
238
325
|
|
|
239
326
|
const totalPurchaseCostCurrency = isErc20SaleStrategy(salesConfig)
|
|
240
327
|
? salesConfig.currency
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Address } from "viem";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
IHttpClient,
|
|
5
|
-
} from "../apis/http-api-base";
|
|
2
|
+
import { httpClient as defaultHttpClient } from "../apis/http-api-base";
|
|
3
|
+
import { ISubgraphQuerier, SubgraphQuerier } from "../apis/subgraph-querier";
|
|
6
4
|
import { NetworkConfig, networkConfigByChain } from "src/apis/chain-constants";
|
|
7
5
|
import { GenericTokenIdTypes } from "src/types";
|
|
8
6
|
import {
|
|
@@ -11,19 +9,15 @@ import {
|
|
|
11
9
|
OnchainMintable,
|
|
12
10
|
OnchainSalesConfigAndTokenInfo,
|
|
13
11
|
OnchainSalesStrategies,
|
|
14
|
-
isErc20SaleStrategy,
|
|
15
12
|
} from "./types";
|
|
16
|
-
import { querySubgraphWithRetries } from "src/utils";
|
|
17
13
|
import {
|
|
18
14
|
buildContractTokensQuery,
|
|
19
|
-
buildGetDefaultMintPriceQuery,
|
|
20
15
|
buildNftTokenSalesQuery,
|
|
21
16
|
buildPremintsOfContractQuery,
|
|
22
17
|
ISubgraphQuery,
|
|
23
18
|
SalesStrategyResult,
|
|
24
19
|
TokenQueryResult,
|
|
25
20
|
} from "./subgraph-queries";
|
|
26
|
-
import * as semver from "semver";
|
|
27
21
|
|
|
28
22
|
export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
|
|
29
23
|
if (!networkConfigByChain[chainId]) {
|
|
@@ -34,6 +28,7 @@ export const getApiNetworkConfigForChain = (chainId: number): NetworkConfig => {
|
|
|
34
28
|
|
|
35
29
|
function parseSalesConfig(
|
|
36
30
|
targetStrategy: SalesStrategyResult,
|
|
31
|
+
contractMintFee: bigint,
|
|
37
32
|
): OnchainSalesStrategies {
|
|
38
33
|
if (targetStrategy.type === "FIXED_PRICE")
|
|
39
34
|
return {
|
|
@@ -43,6 +38,7 @@ function parseSalesConfig(
|
|
|
43
38
|
targetStrategy.fixedPrice.maxTokensPerAddress,
|
|
44
39
|
),
|
|
45
40
|
pricePerToken: BigInt(targetStrategy.fixedPrice.pricePerToken),
|
|
41
|
+
mintFeePerQuantity: contractMintFee,
|
|
46
42
|
};
|
|
47
43
|
|
|
48
44
|
if (targetStrategy.type === "ERC_20_MINTER") {
|
|
@@ -53,6 +49,30 @@ function parseSalesConfig(
|
|
|
53
49
|
targetStrategy.erc20Minter.maxTokensPerAddress,
|
|
54
50
|
),
|
|
55
51
|
pricePerToken: BigInt(targetStrategy.erc20Minter.pricePerToken),
|
|
52
|
+
mintFeePerQuantity: 0n,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (targetStrategy.type === "PRESALE") {
|
|
56
|
+
return {
|
|
57
|
+
saleType: "allowlist",
|
|
58
|
+
address: targetStrategy.presale.address,
|
|
59
|
+
merkleRoot: targetStrategy.presale.merkleRoot,
|
|
60
|
+
saleStart: targetStrategy.presale.presaleStart,
|
|
61
|
+
saleEnd: targetStrategy.presale.presaleEnd,
|
|
62
|
+
mintFeePerQuantity: contractMintFee,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (targetStrategy.type === "ZORA_TIMED") {
|
|
66
|
+
return {
|
|
67
|
+
saleType: "timed",
|
|
68
|
+
address: targetStrategy.zoraTimedMinter.address,
|
|
69
|
+
mintFee: BigInt(targetStrategy.zoraTimedMinter.mintFee),
|
|
70
|
+
saleStart: targetStrategy.zoraTimedMinter.saleStart,
|
|
71
|
+
saleEnd: targetStrategy.zoraTimedMinter.saleEnd,
|
|
72
|
+
erc20Z: targetStrategy.zoraTimedMinter.erc20Z.id,
|
|
73
|
+
pool: targetStrategy.zoraTimedMinter.erc20Z.pool,
|
|
74
|
+
secondaryActivated: targetStrategy.zoraTimedMinter.secondaryActivated,
|
|
75
|
+
mintFeePerQuantity: BigInt(targetStrategy.zoraTimedMinter.mintFee),
|
|
56
76
|
};
|
|
57
77
|
}
|
|
58
78
|
|
|
@@ -60,36 +80,56 @@ function parseSalesConfig(
|
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
function getSaleEnd(a: SalesStrategyResult) {
|
|
63
|
-
return BigInt(
|
|
64
|
-
|
|
65
|
-
);
|
|
83
|
+
if (a.type === "FIXED_PRICE") return BigInt(a.fixedPrice.saleEnd);
|
|
84
|
+
if (a.type === "ERC_20_MINTER") return BigInt(a.erc20Minter.saleEnd);
|
|
85
|
+
if (a.type === "ZORA_TIMED") return BigInt(a.zoraTimedMinter.saleEnd);
|
|
86
|
+
return BigInt(a.presale.presaleEnd);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function strategyIsStillValid(
|
|
90
|
+
strategy: SalesStrategyResult,
|
|
91
|
+
blockTime: bigint,
|
|
92
|
+
): boolean {
|
|
93
|
+
if (strategy.type === "FIXED_PRICE") {
|
|
94
|
+
return BigInt(strategy.fixedPrice.saleEnd) > blockTime;
|
|
95
|
+
}
|
|
96
|
+
if (strategy.type === "ERC_20_MINTER") {
|
|
97
|
+
return BigInt(strategy.erc20Minter.saleEnd) > blockTime;
|
|
98
|
+
}
|
|
99
|
+
if (strategy.type === "ZORA_TIMED") {
|
|
100
|
+
return BigInt(strategy.zoraTimedMinter.saleEnd) > blockTime;
|
|
101
|
+
}
|
|
102
|
+
return BigInt(strategy.presale.presaleEnd) > blockTime;
|
|
66
103
|
}
|
|
67
104
|
|
|
68
105
|
function getTargetStrategy({
|
|
69
106
|
tokenId,
|
|
70
107
|
preferredSaleType,
|
|
71
108
|
token,
|
|
109
|
+
blockTime,
|
|
72
110
|
}: {
|
|
73
111
|
tokenId?: GenericTokenIdTypes;
|
|
74
112
|
preferredSaleType?: SaleType;
|
|
75
113
|
token: TokenQueryResult;
|
|
76
|
-
|
|
114
|
+
blockTime: bigint;
|
|
115
|
+
}): SalesStrategyResult | undefined {
|
|
77
116
|
const allStrategies =
|
|
78
117
|
(typeof tokenId !== "undefined"
|
|
79
118
|
? token.salesStrategies
|
|
80
119
|
: token.contract.salesStrategies) || [];
|
|
81
120
|
|
|
82
|
-
const
|
|
121
|
+
const stillValidSalesStrategies = allStrategies.filter((strategy) =>
|
|
122
|
+
strategyIsStillValid(strategy, blockTime),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const saleStrategies = stillValidSalesStrategies.sort((a, b) =>
|
|
83
126
|
getSaleEnd(a) > getSaleEnd(b) ? 1 : -1,
|
|
84
127
|
);
|
|
85
128
|
|
|
86
129
|
let targetStrategy: SalesStrategyResult | undefined;
|
|
87
130
|
|
|
88
131
|
if (!preferredSaleType) {
|
|
89
|
-
|
|
90
|
-
if (!targetStrategy) {
|
|
91
|
-
throw new Error("Cannot find sale strategy");
|
|
92
|
-
}
|
|
132
|
+
return saleStrategies[0];
|
|
93
133
|
} else {
|
|
94
134
|
const mappedSaleType =
|
|
95
135
|
preferredSaleType === "erc20" ? "ERC_20_MINTER" : "FIXED_PRICE";
|
|
@@ -110,24 +150,17 @@ function getTargetStrategy({
|
|
|
110
150
|
}
|
|
111
151
|
|
|
112
152
|
export class SubgraphMintGetter implements IOnchainMintGetter {
|
|
113
|
-
|
|
153
|
+
public readonly subgraphQuerier: ISubgraphQuerier;
|
|
114
154
|
networkConfig: NetworkConfig;
|
|
115
155
|
|
|
116
|
-
constructor(chainId: number,
|
|
117
|
-
this.
|
|
156
|
+
constructor(chainId: number, subgraphQuerier?: ISubgraphQuerier) {
|
|
157
|
+
this.subgraphQuerier =
|
|
158
|
+
subgraphQuerier || new SubgraphQuerier(defaultHttpClient);
|
|
118
159
|
this.networkConfig = getApiNetworkConfigForChain(chainId);
|
|
119
160
|
}
|
|
120
161
|
|
|
121
162
|
async getContractMintFee(contract: TokenQueryResult["contract"]) {
|
|
122
|
-
|
|
123
|
-
if (!contractUsesMintCardsForMintFee(contract.contractVersion)) {
|
|
124
|
-
return storedMintFee;
|
|
125
|
-
}
|
|
126
|
-
const defaultMintFee = await this.querySubgraphWithRetries(
|
|
127
|
-
buildGetDefaultMintPriceQuery({}),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return defaultMintFee || storedMintFee;
|
|
163
|
+
return BigInt(contract.mintFeePerQuantity);
|
|
131
164
|
}
|
|
132
165
|
|
|
133
166
|
async querySubgraphWithRetries<T>({
|
|
@@ -135,8 +168,7 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
|
|
|
135
168
|
variables,
|
|
136
169
|
parseResponseData,
|
|
137
170
|
}: ISubgraphQuery<T>) {
|
|
138
|
-
const responseData = await
|
|
139
|
-
httpClient: this.httpClient,
|
|
171
|
+
const responseData = await this.subgraphQuerier.query({
|
|
140
172
|
subgraphUrl: this.networkConfig.subgraphUrl,
|
|
141
173
|
query,
|
|
142
174
|
variables,
|
|
@@ -149,6 +181,7 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
|
|
|
149
181
|
tokenAddress,
|
|
150
182
|
tokenId,
|
|
151
183
|
preferredSaleType: saleType,
|
|
184
|
+
blockTime,
|
|
152
185
|
}) => {
|
|
153
186
|
const token = await this.querySubgraphWithRetries(
|
|
154
187
|
buildNftTokenSalesQuery({
|
|
@@ -168,15 +201,18 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
|
|
|
168
201
|
defaultMintFee,
|
|
169
202
|
tokenId,
|
|
170
203
|
preferredSaleType: saleType,
|
|
204
|
+
blockTime,
|
|
171
205
|
});
|
|
172
206
|
};
|
|
173
207
|
|
|
174
208
|
async getContractMintable({
|
|
175
209
|
tokenAddress,
|
|
176
210
|
preferredSaleType,
|
|
211
|
+
blockTime,
|
|
177
212
|
}: {
|
|
178
213
|
tokenAddress: Address;
|
|
179
214
|
preferredSaleType?: SaleType;
|
|
215
|
+
blockTime: bigint;
|
|
180
216
|
}) {
|
|
181
217
|
const tokens = await this.querySubgraphWithRetries(
|
|
182
218
|
buildContractTokensQuery({
|
|
@@ -196,6 +232,7 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
|
|
|
196
232
|
tokenId: token.tokenId,
|
|
197
233
|
preferredSaleType,
|
|
198
234
|
defaultMintFee,
|
|
235
|
+
blockTime,
|
|
199
236
|
}),
|
|
200
237
|
);
|
|
201
238
|
}
|
|
@@ -220,30 +257,57 @@ export class SubgraphMintGetter implements IOnchainMintGetter {
|
|
|
220
257
|
}
|
|
221
258
|
}
|
|
222
259
|
|
|
223
|
-
function
|
|
260
|
+
function getTargetStrategyAndMintFee({
|
|
224
261
|
token,
|
|
225
262
|
tokenId,
|
|
226
263
|
preferredSaleType,
|
|
227
264
|
defaultMintFee,
|
|
265
|
+
blockTime,
|
|
228
266
|
}: {
|
|
229
267
|
token: TokenQueryResult;
|
|
230
268
|
tokenId?: GenericTokenIdTypes;
|
|
231
269
|
preferredSaleType?: SaleType;
|
|
232
270
|
defaultMintFee: bigint;
|
|
233
|
-
|
|
271
|
+
blockTime: bigint;
|
|
272
|
+
}) {
|
|
234
273
|
const targetStrategy = getTargetStrategy({
|
|
235
274
|
tokenId,
|
|
236
275
|
preferredSaleType: preferredSaleType,
|
|
237
276
|
token,
|
|
277
|
+
blockTime,
|
|
238
278
|
});
|
|
239
279
|
|
|
240
|
-
|
|
280
|
+
if (!targetStrategy) return undefined;
|
|
241
281
|
|
|
242
|
-
const salesConfig = parseSalesConfig(targetStrategy);
|
|
282
|
+
const salesConfig = parseSalesConfig(targetStrategy, defaultMintFee);
|
|
243
283
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
284
|
+
return salesConfig;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function parseTokenQueryResult({
|
|
288
|
+
token,
|
|
289
|
+
tokenId,
|
|
290
|
+
preferredSaleType,
|
|
291
|
+
defaultMintFee,
|
|
292
|
+
blockTime,
|
|
293
|
+
}: {
|
|
294
|
+
token: TokenQueryResult;
|
|
295
|
+
tokenId?: GenericTokenIdTypes;
|
|
296
|
+
preferredSaleType?: SaleType;
|
|
297
|
+
defaultMintFee: bigint;
|
|
298
|
+
blockTime: bigint;
|
|
299
|
+
}): OnchainSalesConfigAndTokenInfo {
|
|
300
|
+
const salesConfig = getTargetStrategyAndMintFee({
|
|
301
|
+
token,
|
|
302
|
+
tokenId,
|
|
303
|
+
preferredSaleType,
|
|
304
|
+
defaultMintFee,
|
|
305
|
+
blockTime,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
const tokenInfo = parseTokenInfo({
|
|
309
|
+
token,
|
|
310
|
+
});
|
|
247
311
|
|
|
248
312
|
return {
|
|
249
313
|
...tokenInfo,
|
|
@@ -251,17 +315,11 @@ function parseTokenQueryResult({
|
|
|
251
315
|
};
|
|
252
316
|
}
|
|
253
317
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
function parseTokenInfo(
|
|
262
|
-
token: TokenQueryResult,
|
|
263
|
-
defaultMintFee: bigint,
|
|
264
|
-
): OnchainMintable {
|
|
318
|
+
function parseTokenInfo({
|
|
319
|
+
token,
|
|
320
|
+
}: {
|
|
321
|
+
token: TokenQueryResult;
|
|
322
|
+
}): OnchainMintable {
|
|
265
323
|
return {
|
|
266
324
|
contract: {
|
|
267
325
|
address: token.contract.address,
|
|
@@ -274,7 +332,6 @@ function parseTokenInfo(
|
|
|
274
332
|
creator: token.creator,
|
|
275
333
|
totalMinted: BigInt(token.totalMinted),
|
|
276
334
|
maxSupply: BigInt(token.maxSupply),
|
|
277
|
-
mintFeePerQuantity: defaultMintFee,
|
|
278
335
|
contractVersion: token.contract.contractVersion,
|
|
279
336
|
};
|
|
280
337
|
}
|
|
@@ -2,26 +2,58 @@ import { GenericTokenIdTypes } from "src/types";
|
|
|
2
2
|
import { Address } from "viem";
|
|
3
3
|
|
|
4
4
|
export type FixedPriceSaleStrategyResult = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
type: "FIXED_PRICE";
|
|
6
|
+
fixedPrice: {
|
|
7
|
+
address: Address;
|
|
8
|
+
pricePerToken: string;
|
|
9
|
+
saleEnd: string;
|
|
10
|
+
saleStart: string;
|
|
11
|
+
maxTokensPerAddress: string;
|
|
12
|
+
};
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
export type ERC20SaleStrategyResult =
|
|
13
|
-
|
|
15
|
+
export type ERC20SaleStrategyResult = {
|
|
16
|
+
type: "ERC_20_MINTER";
|
|
17
|
+
erc20Minter: {
|
|
18
|
+
address: Address;
|
|
19
|
+
pricePerToken: string;
|
|
20
|
+
saleEnd: string;
|
|
21
|
+
saleStart: string;
|
|
22
|
+
maxTokensPerAddress: string;
|
|
23
|
+
currency: Address;
|
|
24
|
+
};
|
|
14
25
|
};
|
|
15
26
|
|
|
16
|
-
export type
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
export type PresaleSalesStrategyResult = {
|
|
28
|
+
type: "PRESALE";
|
|
29
|
+
presale: {
|
|
30
|
+
address: Address;
|
|
31
|
+
presaleStart: string;
|
|
32
|
+
presaleEnd: string;
|
|
33
|
+
merkleRoot: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type ZoraTimedMinterSaleStrategyResult = {
|
|
38
|
+
type: "ZORA_TIMED";
|
|
39
|
+
zoraTimedMinter: {
|
|
40
|
+
address: Address;
|
|
41
|
+
mintFee: string;
|
|
42
|
+
saleStart: string;
|
|
43
|
+
saleEnd: string;
|
|
44
|
+
erc20Z: {
|
|
45
|
+
id: Address;
|
|
46
|
+
pool: Address;
|
|
24
47
|
};
|
|
48
|
+
secondaryActivated: boolean;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type SalesStrategyResult =
|
|
53
|
+
| FixedPriceSaleStrategyResult
|
|
54
|
+
| ERC20SaleStrategyResult
|
|
55
|
+
| PresaleSalesStrategyResult
|
|
56
|
+
| ZoraTimedMinterSaleStrategyResult;
|
|
25
57
|
|
|
26
58
|
export type TokenQueryResult = {
|
|
27
59
|
tokenId?: string;
|
|
@@ -32,7 +64,7 @@ export type TokenQueryResult = {
|
|
|
32
64
|
salesStrategies?: SalesStrategyResult[];
|
|
33
65
|
tokenStandard: "ERC1155" | "ERC721";
|
|
34
66
|
contract: {
|
|
35
|
-
mintFeePerQuantity:
|
|
67
|
+
mintFeePerQuantity: string;
|
|
36
68
|
salesStrategies: SalesStrategyResult[];
|
|
37
69
|
address: Address;
|
|
38
70
|
contractVersion: string;
|
|
@@ -59,6 +91,23 @@ fragment SaleStrategy on SalesStrategyConfig {
|
|
|
59
91
|
saleStart
|
|
60
92
|
maxTokensPerAddress
|
|
61
93
|
}
|
|
94
|
+
presale {
|
|
95
|
+
address
|
|
96
|
+
presaleStart
|
|
97
|
+
presaleEnd
|
|
98
|
+
merkleRoot
|
|
99
|
+
}
|
|
100
|
+
zoraTimedMinter {
|
|
101
|
+
address
|
|
102
|
+
mintFee
|
|
103
|
+
saleStart
|
|
104
|
+
saleEnd
|
|
105
|
+
erc20Z {
|
|
106
|
+
id
|
|
107
|
+
pool
|
|
108
|
+
}
|
|
109
|
+
secondaryActivated
|
|
110
|
+
}
|
|
62
111
|
}`;
|
|
63
112
|
|
|
64
113
|
const TOKEN_FRAGMENT = `
|
|
@@ -69,7 +118,7 @@ fragment Token on ZoraCreateToken {
|
|
|
69
118
|
totalMinted
|
|
70
119
|
maxSupply
|
|
71
120
|
tokenStandard
|
|
72
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
121
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
73
122
|
...SaleStrategy
|
|
74
123
|
}
|
|
75
124
|
contract {
|
|
@@ -78,7 +127,7 @@ fragment Token on ZoraCreateToken {
|
|
|
78
127
|
contractVersion
|
|
79
128
|
contractURI
|
|
80
129
|
name
|
|
81
|
-
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER"]}) {
|
|
130
|
+
salesStrategies(where: {type_in: ["FIXED_PRICE", "ERC_20_MINTER", "PRESALE", "ZORA_TIMED"]}) {
|
|
82
131
|
...SaleStrategy
|
|
83
132
|
}
|
|
84
133
|
}
|
|
@@ -117,25 +166,6 @@ query ($id: ID!) {
|
|
|
117
166
|
};
|
|
118
167
|
}
|
|
119
168
|
|
|
120
|
-
export function buildGetDefaultMintPriceQuery({}): ISubgraphQuery<
|
|
121
|
-
bigint | undefined
|
|
122
|
-
> {
|
|
123
|
-
return {
|
|
124
|
-
query: `
|
|
125
|
-
{
|
|
126
|
-
defaultMintPrice(id: "0x0000000000000000000000000000000000000000") {
|
|
127
|
-
pricePerToken
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
`,
|
|
131
|
-
variables: {},
|
|
132
|
-
parseResponseData: (responseData: any | undefined) =>
|
|
133
|
-
responseData?.defaultMintPrice?.pricePerToken
|
|
134
|
-
? BigInt(responseData?.defaultMintPrice?.pricePerToken)
|
|
135
|
-
: undefined,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
169
|
export function buildContractTokensQuery({
|
|
140
170
|
tokenAddress,
|
|
141
171
|
}: {
|