MCPcopy Create free account
hub / github.com/circlefin/arc-node / ContractLoader

Class ContractLoader

scripts/genesis/context.ts:56–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54export type Network = z.infer<typeof schemaNetwork>
55
56export class ContractLoader {
57 static load(_network: Network, chainId: number) {
58 // call forge script to get the contract code
59 fs.mkdirSync(cacheDir, { recursive: true })
60 const outputPath = path.join(cacheDir, `storage-code.${chainId}.json`)
61 console.log(`Write storage code to ${outputPath}...`)
62 const result = spawnSync(
63 'forge',
64 [
65 'script',
66 './contracts/scripts/ArtifactHelper.s.sol',
67 '--sig',
68 'run(uint256,string,address)',
69 `${chainId}`,
70 outputPath,
71 validatorRegistryAddress,
72 ],
73 { cwd: projectRoot, stdio: 'inherit' },
74 )
75 if (result.status !== 0) {
76 throw new Error(`Failed to generate storage code`)
77 }
78 const data = schemaContractRepo.parse(JSON.parse(fs.readFileSync(outputPath, 'utf-8')))
79 const manifest = schemaManifest.parse(
80 JSON.parse(fs.readFileSync(path.join(projectRoot, 'assets/artifacts/manifest.json'), 'utf-8')),
81 )
82 return new ContractLoader(data, manifest)
83 }
84
85 constructor(
86 public repo: ContractRepo,
87 public manifest: Manifest,
88 ) {}
89
90 getCode = async (name: string) => {
91 try {
92 return schemaHex.parse(this.repo[name]?.code)
93 } catch (e) {
94 /* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */
95 throw new Error(`Failed to parse contract code for ${name}: ${e}`)
96 }
97 }
98
99 getDeterministicAddress = async (name: string) => {
100 try {
101 return schemaAddress.parse(this.repo[name]?.address)
102 } catch (e) {
103 /* eslint-disable-next-line @typescript-eslint/restrict-template-expressions */
104 throw new Error(`Failed to parse contract address for ${name}: ${e}`)
105 }
106 }
107}
108
109export const createBuilderContext = async ({ network, chainId }: { network: Network; chainId: number }) => {
110 return {

Callers

nothing calls this directly

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected