|
1 | | -import { Fr } from '@aztec/foundation/curves/bn254'; |
2 | | -import type { ProtocolContract } from '@aztec/protocol-contracts'; |
3 | | -import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi'; |
4 | | -import { AztecAddress } from '@aztec/stdlib/aztec-address'; |
5 | | -import { computeInitializationHash, getContractClassFromArtifact } from '@aztec/stdlib/contract'; |
6 | | -import { PublicKeys } from '@aztec/stdlib/keys'; |
| 1 | +import { loadContractArtifact } from '@aztec/stdlib/abi'; |
7 | 2 | import type { NoirCompiledContract } from '@aztec/stdlib/noir'; |
8 | 3 |
|
9 | 4 | import AuthRegistryJson from '../../artifacts/AuthRegistry.json' with { type: 'json' }; |
10 | | -import { AUTH_REGISTRY_ADDRESS, AUTH_REGISTRY_CLASS_ID } from './address.gen.js'; |
| 5 | +import { makeStandardContract } from '../make_standard_contract.js'; |
| 6 | +import type { StandardContract } from '../standard_contract.js'; |
11 | 7 |
|
12 | | -export { AUTH_REGISTRY_ADDRESS, AUTH_REGISTRY_CLASS_ID } from './address.gen.js'; |
| 8 | +export { AUTH_REGISTRY_ADDRESS, AUTH_REGISTRY_CLASS_ID } from './address.js'; |
13 | 9 |
|
14 | | -let protocolContract: ProtocolContract; |
| 10 | +export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract); |
15 | 11 |
|
16 | | -export const AuthRegistryArtifact: ContractArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract); |
| 12 | +let standardContract: StandardContract; |
17 | 13 |
|
18 | 14 | /** Returns the standard deployment of the auth registry. */ |
19 | | -export async function getStandardAuthRegistry(): Promise<ProtocolContract> { |
20 | | - if (!protocolContract) { |
21 | | - protocolContract = await buildAuthRegistryProtocolContract(AuthRegistryArtifact); |
| 15 | +export function getStandardAuthRegistry(): Promise<StandardContract> { |
| 16 | + if (!standardContract) { |
| 17 | + standardContract = makeStandardContract('AuthRegistry', AuthRegistryArtifact); |
22 | 18 | } |
23 | | - return protocolContract; |
24 | | -} |
25 | | - |
26 | | -async function buildAuthRegistryProtocolContract(artifact: ContractArtifact): Promise<ProtocolContract> { |
27 | | - const contractClass = await getContractClassFromArtifact(artifact); |
28 | | - if (!contractClass.id.equals(AUTH_REGISTRY_CLASS_ID)) { |
29 | | - throw new Error( |
30 | | - `auth_registry artifact class id ${contractClass.id.toString()} does not match committed ` + |
31 | | - `AUTH_REGISTRY_CLASS_ID ${AUTH_REGISTRY_CLASS_ID.toString()}; regenerate via ` + |
32 | | - `\`yarn workspace @aztec/standard-contracts run regen:auth-registry-address\`.`, |
33 | | - ); |
34 | | - } |
35 | | - const constructorArtifact = artifact.functions.find(f => f.name === 'constructor'); |
36 | | - const initializationHash = await computeInitializationHash(constructorArtifact, []); |
37 | | - |
38 | | - const instance = { |
39 | | - version: 1 as const, |
40 | | - currentContractClassId: AUTH_REGISTRY_CLASS_ID, |
41 | | - originalContractClassId: AUTH_REGISTRY_CLASS_ID, |
42 | | - initializationHash, |
43 | | - publicKeys: PublicKeys.default(), |
44 | | - salt: new Fr(1), |
45 | | - deployer: AztecAddress.ZERO, |
46 | | - address: AUTH_REGISTRY_ADDRESS, |
47 | | - }; |
48 | | - |
49 | | - return { instance, contractClass, artifact, address: AUTH_REGISTRY_ADDRESS }; |
| 19 | + return Promise.resolve(standardContract); |
50 | 20 | } |
0 commit comments