-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Split up protocol contract artifacts
- Loading branch information
1 parent
b086c52
commit b0096dd
Showing
22 changed files
with
177 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
yarn-project/protocol-contracts/src/auth-registry/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; | ||
import { loadContractArtifact } from '@aztec/types/abi'; | ||
import { type NoirCompiledContract } from '@aztec/types/noir'; | ||
|
||
import AuthRegistryJson from '../../artifacts/AuthRegistry.json' assert { type: 'json' }; | ||
import { makeProtocolContract } from '../make_protocol_contract.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
|
||
let protocolContract: ProtocolContract; | ||
|
||
export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract); | ||
|
||
/** Returns the canonical deployment of the auth registry. */ | ||
export function getCanonicalAuthRegistry(): ProtocolContract { | ||
return getCanonicalProtocolContract('AuthRegistry'); | ||
if (!protocolContract) { | ||
protocolContract = makeProtocolContract('AuthRegistry', AuthRegistryArtifact); | ||
} | ||
return protocolContract; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/circuits.js'; | ||
import { type ContractArtifact } from '@aztec/foundation/abi'; | ||
|
||
import { AuthRegistryArtifact } from '../auth-registry/index.js'; | ||
import { ContractClassRegistererArtifact } from '../class-registerer/index.js'; | ||
import { FeeJuiceArtifact } from '../fee-juice/index.js'; | ||
import { ContractInstanceDeployerArtifact } from '../instance-deployer/index.js'; | ||
import { MultiCallEntrypointArtifact } from '../multi-call-entrypoint/index.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
import { ProtocolContractAddress, type ProtocolContractName, ProtocolContractSalt } from '../protocol_contract_data.js'; | ||
import { RouterArtifact } from '../router/index.js'; | ||
|
||
/** Returns the canonical deployment a given artifact. */ | ||
export function getCanonicalProtocolContract(name: ProtocolContractName): ProtocolContract { | ||
const artifact = ProtocolContractArtifact[name]; | ||
const address = ProtocolContractAddress[name]; | ||
const salt = ProtocolContractSalt[name]; | ||
// TODO(@spalladino): This computes the contract class from the artifact twice. | ||
const contractClass = getContractClassFromArtifact(artifact); | ||
const instance = getContractInstanceFromDeployParams(artifact, { salt }); | ||
return { | ||
instance: { ...instance, address }, | ||
contractClass, | ||
artifact, | ||
address, | ||
}; | ||
} | ||
|
||
export const ProtocolContractArtifact: Record<ProtocolContractName, ContractArtifact> = { | ||
AuthRegistry: AuthRegistryArtifact, | ||
ContractInstanceDeployer: ContractInstanceDeployerArtifact, | ||
ContractClassRegisterer: ContractClassRegistererArtifact, | ||
MultiCallEntrypoint: MultiCallEntrypointArtifact, | ||
FeeJuice: FeeJuiceArtifact, | ||
Router: RouterArtifact, | ||
}; |
21 changes: 18 additions & 3 deletions
21
yarn-project/protocol-contracts/src/class-registerer/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; | ||
import { loadContractArtifact } from '@aztec/types/abi'; | ||
import { type NoirCompiledContract } from '@aztec/types/noir'; | ||
|
||
import ContractClassRegistererJson from '../../artifacts/ContractClassRegisterer.json' assert { type: 'json' }; | ||
import { makeProtocolContract } from '../make_protocol_contract.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
|
||
export * from './contract_class_registered_event.js'; | ||
export * from './private_function_broadcasted_event.js'; | ||
export * from './unconstrained_function_broadcasted_event.js'; | ||
|
||
/** Returns the canonical deployment of the class registerer contract. */ | ||
export const ContractClassRegistererArtifact = loadContractArtifact( | ||
ContractClassRegistererJson as NoirCompiledContract, | ||
); | ||
|
||
let protocolContract: ProtocolContract; | ||
|
||
/** Returns the canonical deployment of the contract. */ | ||
export function getCanonicalClassRegisterer(): ProtocolContract { | ||
return getCanonicalProtocolContract('ContractClassRegisterer'); | ||
if (!protocolContract) { | ||
const artifact = ContractClassRegistererArtifact; | ||
protocolContract = makeProtocolContract('ContractClassRegisterer', artifact); | ||
} | ||
return protocolContract; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; | ||
import { loadContractArtifact } from '@aztec/types/abi'; | ||
import { type NoirCompiledContract } from '@aztec/types/noir'; | ||
|
||
/** Returns the canonical deployment of the Fee Juice. */ | ||
import FeeJuiceJson from '../../artifacts/FeeJuice.json' assert { type: 'json' }; | ||
import { makeProtocolContract } from '../make_protocol_contract.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
|
||
export const FeeJuiceArtifact = loadContractArtifact(FeeJuiceJson as NoirCompiledContract); | ||
|
||
let protocolContract: ProtocolContract; | ||
|
||
/** Returns the canonical deployment of the contract. */ | ||
export function getCanonicalFeeJuice(): ProtocolContract { | ||
return getCanonicalProtocolContract('FeeJuice'); | ||
if (!protocolContract) { | ||
protocolContract = makeProtocolContract('FeeJuice', FeeJuiceArtifact); | ||
} | ||
return protocolContract; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
export * from './auth-registry/index.js'; | ||
export * from './class-registerer/index.js'; | ||
export * from './fee-juice/index.js'; | ||
export * from './instance-deployer/index.js'; | ||
export * from './multi-call-entrypoint/index.js'; | ||
export * from './protocol_contract.js'; | ||
export * from './protocol_contract_data.js'; | ||
export * from './protocol_contract_tree.js'; |
20 changes: 17 additions & 3 deletions
20
yarn-project/protocol-contracts/src/instance-deployer/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; | ||
import { loadContractArtifact } from '@aztec/types/abi'; | ||
import { type NoirCompiledContract } from '@aztec/types/noir'; | ||
|
||
import ContractInstanceDeployerJson from '../../artifacts/ContractInstanceDeployer.json' assert { type: 'json' }; | ||
import { makeProtocolContract } from '../make_protocol_contract.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
|
||
export * from './contract_instance_deployed_event.js'; | ||
|
||
/** Returns the canonical deployment of the instance deployer contract. */ | ||
export const ContractInstanceDeployerArtifact = loadContractArtifact( | ||
ContractInstanceDeployerJson as NoirCompiledContract, | ||
); | ||
|
||
let protocolContract: ProtocolContract; | ||
|
||
/** Returns the canonical deployment of the contract. */ | ||
export function getCanonicalInstanceDeployer(): ProtocolContract { | ||
return getCanonicalProtocolContract('ContractInstanceDeployer'); | ||
if (!protocolContract) { | ||
protocolContract = makeProtocolContract('ContractInstanceDeployer', ContractInstanceDeployerArtifact); | ||
} | ||
return protocolContract; | ||
} |
23 changes: 23 additions & 0 deletions
23
yarn-project/protocol-contracts/src/make_protocol_contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/circuits.js'; | ||
import { type ContractArtifact } from '@aztec/foundation/abi'; | ||
|
||
import { type ProtocolContract } from './protocol_contract.js'; | ||
import { ProtocolContractAddress, type ProtocolContractName, ProtocolContractSalt } from './protocol_contract_data.js'; | ||
|
||
/** | ||
* Returns the canonical deployment given its name and artifact. | ||
* To be used internally within the protocol-contracts package. | ||
*/ | ||
export function makeProtocolContract(name: ProtocolContractName, artifact: ContractArtifact): ProtocolContract { | ||
const address = ProtocolContractAddress[name]; | ||
const salt = ProtocolContractSalt[name]; | ||
// TODO(@spalladino): This computes the contract class from the artifact twice. | ||
const contractClass = getContractClassFromArtifact(artifact); | ||
const instance = getContractInstanceFromDeployParams(artifact, { salt }); | ||
return { | ||
instance: { ...instance, address }, | ||
contractClass, | ||
artifact, | ||
address, | ||
}; | ||
} |
19 changes: 16 additions & 3 deletions
19
yarn-project/protocol-contracts/src/multi-call-entrypoint/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; | ||
import { loadContractArtifact } from '@aztec/types/abi'; | ||
import { type NoirCompiledContract } from '@aztec/types/noir'; | ||
|
||
export function getCanonicalMultiCallEntrypointContract(): ProtocolContract { | ||
return getCanonicalProtocolContract('MultiCallEntrypoint'); | ||
import MultiCallEntrypointJson from '../../artifacts/MultiCallEntrypoint.json' assert { type: 'json' }; | ||
import { makeProtocolContract } from '../make_protocol_contract.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
|
||
export const MultiCallEntrypointArtifact = loadContractArtifact(MultiCallEntrypointJson as NoirCompiledContract); | ||
|
||
let protocolContract: ProtocolContract; | ||
|
||
/** Returns the canonical deployment of the contract. */ | ||
export function getCanonicalMultiCallEntrypoint(): ProtocolContract { | ||
if (!protocolContract) { | ||
protocolContract = makeProtocolContract('MultiCallEntrypoint', MultiCallEntrypointArtifact); | ||
} | ||
return protocolContract; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; | ||
import { loadContractArtifact } from '@aztec/types/abi'; | ||
import { type NoirCompiledContract } from '@aztec/types/noir'; | ||
|
||
/** Returns the canonical deployment of the router. */ | ||
import RouterJson from '../../artifacts/Router.json' assert { type: 'json' }; | ||
import { makeProtocolContract } from '../make_protocol_contract.js'; | ||
import { type ProtocolContract } from '../protocol_contract.js'; | ||
|
||
export const RouterArtifact = loadContractArtifact(RouterJson as NoirCompiledContract); | ||
|
||
let protocolContract: ProtocolContract; | ||
|
||
/** Returns the canonical deployment of the contract. */ | ||
export function getCanonicalRouter(): ProtocolContract { | ||
return getCanonicalProtocolContract('Router'); | ||
if (!protocolContract) { | ||
protocolContract = makeProtocolContract('Router', RouterArtifact); | ||
} | ||
return protocolContract; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.