Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 17x 17x 17x 17x 17x 4x 17x 1x 24x 15x 17x 1x 17x 17x 17x 1x 17x 4x 17x 2x 17x 1x 17x 2x 17x 8x 17x | import { ContractSchema, ContractStorageField } from "../contractSchema";
import { Generator } from "../generator";
import { Feature } from "../../types";
export class HeaderGen implements Generator {
gen(schema: ContractSchema): string {
let header =
`// SPDX-License-Identifier: UNLICENSED\n` +
`pragma solidity ^0.8.23;\n` +
`\n`;
if (schema.imageURI && schema.imageURI.includes('{tokenID}')) {
header += `import "@openzeppelin/contracts/utils/Strings.sol";\n`
}
header += this.getBaseImports(schema.features).join("");
if (schema.hasLiteRef()) {
header += `import "@patchwork/PatchworkLiteRef.sol";\n`;
}
if (schema.features.some((feature: Feature) => feature === Feature.MINTABLE)) {
header += `import "@patchwork/interfaces/IPatchworkMintable.sol";\n`;
}
if (schema.storage.fields.some((field: ContractStorageField) => field.isString)) {
header += `import "@patchwork/PatchworkUtils.sol";\n`;
}
if (schema.hasLiteRef() && schema.features.includes(Feature.DYNAMICREFLIBRARY)) {
header += `import "@patchwork/libraries/PatchworkDynamicRefs.sol";\n`;
}
return header;
}
colophon(): string[] {
return [
`\n/* ___ __ __ __ `,
`** / _ \\___ _/ /_____/ / _ _____ ____/ /__`,
`** / ___/ _ \`/ __/ __/ _ \\ |/|/ / _ \\/ __/ '_/`,
`** /_/ \\_,_/\\__/\\__/_//_/__,__/\\___/_/ /_/\\_\\`,
`**`,
`** Generated by Patchwork PDK`,
`*/\n\n`,
]
}
getBaseImports(features: Feature[]): string[] {
let imports: string[] = [];
if (features.some((feature: Feature) => feature === Feature.FRAGMENTMULTI)) {
imports.push(`import "@patchwork/PatchworkFragmentMulti.sol";\n`);
}
if (features.some((feature: Feature) => feature === Feature.FRAGMENTSINGLE)) {
imports.push(`import "@patchwork/PatchworkFragmentSingle.sol";\n`);
}
if (features.some((feature: Feature) => feature === Feature.PATCH)) {
imports.push(`import "@patchwork/PatchworkPatch.sol";\n`);
}
if (features.some((feature: Feature) => feature === Feature['1155PATCH'])) {
imports.push(`import "@patchwork/Patchwork1155Patch.sol";\n`);
}
if (features.some((feature: Feature) => feature === Feature.ACCOUNTPATCH)) {
imports.push(`import "@patchwork/PatchworkAccountPatch.sol";\n`);
}
// If no specific feature is found, default to Patchwork721
if (imports.length === 0) {
imports.push(`import "@patchwork/Patchwork721.sol";\n`);
}
// Join all imports with a newline
return imports;
}
} |