-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex.ts
More file actions
108 lines (95 loc) · 3.93 KB
/
Copy pathindex.ts
File metadata and controls
108 lines (95 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { MintContractOptions, MintIngestor, MintIngestorResources } from '../../lib/types/mint-ingestor';
import { MintIngestionErrorName, MintIngestorError } from '../../lib/types/mint-ingestor-error';
import { MintInstructionType, MintTemplate } from '../../lib/types/mint-template';
import { MintTemplateBuilder } from '../../lib/builder/mint-template-builder';
import { MINTCLUB_ZAP_ABI } from './abi';
import {
MINTCLUB_BASE_CHAIN_ID,
MINTCLUB_ZAP_ADDRESS,
getMintClubTokenDetails,
mintClubDescription,
mintClubFeaturedImageUrl,
mintClubSymbolFromUrl,
mintClubUrlForSymbol,
resolveMintClubTokenForSymbol,
} from './offchain-metadata';
import { MintClubTokenDetails } from './types';
export class MintClubIngestor implements MintIngestor {
configuration = {
supportsContractIsExpensive: true,
supportsUrlIsExpensive: true,
};
async supportsUrl(resources: MintIngestorResources, url: string): Promise<boolean> {
const symbol = mintClubSymbolFromUrl(url);
if (!symbol) {
return false;
}
return !!(await resolveMintClubTokenForSymbol(resources, symbol));
}
async supportsContract(resources: MintIngestorResources, contractOptions: MintContractOptions): Promise<boolean> {
if (contractOptions.chainId !== MINTCLUB_BASE_CHAIN_ID) {
return false;
}
return !!(await getMintClubTokenDetails(resources, contractOptions.contractAddress));
}
async createMintTemplateForUrl(resources: MintIngestorResources, url: string): Promise<MintTemplate> {
const symbol = mintClubSymbolFromUrl(url);
if (!symbol) {
throw new MintIngestorError(MintIngestionErrorName.IncompatibleUrl, 'Incompatible URL');
}
const details = await resolveMintClubTokenForSymbol(resources, symbol);
if (!details) {
throw new MintIngestorError(MintIngestionErrorName.CouldNotResolveMint, 'Mint Club token not found');
}
return this.createMintTemplate(details, url);
}
async createMintForContract(
resources: MintIngestorResources,
contractOptions: MintContractOptions,
): Promise<MintTemplate> {
if (contractOptions.chainId !== MINTCLUB_BASE_CHAIN_ID) {
throw new MintIngestorError(MintIngestionErrorName.IncompatibleUrl, 'Incompatible chain');
}
const details = await getMintClubTokenDetails(resources, contractOptions.contractAddress);
if (!details) {
throw new MintIngestorError(MintIngestionErrorName.CouldNotResolveMint, 'Mint Club token not found');
}
return this.createMintTemplate(details, contractOptions.url || mintClubUrlForSymbol(details.info.symbol));
}
private createMintTemplate(details: MintClubTokenDetails, marketingUrl: string): MintTemplate {
const startDate = details.info.createdAt
? new Date(details.info.createdAt * 1000)
: new Date();
const liveDate = new Date() > startDate ? new Date() : startDate;
return new MintTemplateBuilder()
.setMintInstructionType(MintInstructionType.EVM_MINT)
.setPartnerName('Mint Club')
.setMarketingUrl(marketingUrl)
.setName(details.info.name)
.setDescription(mintClubDescription(details))
.setFeaturedImageUrl(mintClubFeaturedImageUrl(details))
.setMintOutputContract({
chainId: MINTCLUB_BASE_CHAIN_ID,
address: details.info.token,
tokenId: 0,
})
.setCreator({
name: 'Mint Club Creator',
walletAddress: details.info.creator,
websiteUrl: details.metadata?.website || undefined,
})
.setMintInstructions({
chainId: MINTCLUB_BASE_CHAIN_ID,
contractAddress: MINTCLUB_ZAP_ADDRESS,
contractMethod: 'mintWithEth',
contractParams: `["${details.info.token}", 1, address]`,
abi: MINTCLUB_ZAP_ABI,
priceWei: details.reserveAmount.toString(),
supportsQuantity: false,
})
.setAvailableForPurchaseStart(startDate)
.setAvailableForPurchaseEnd(new Date('2030-01-01T00:00:00Z'))
.setLiveDate(liveDate)
.build();
}
}