@aztec/protocol-contracts 0.0.0-test.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/artifacts/AuthRegistry.d.json.ts +5 -0
- package/artifacts/AuthRegistry.json +2725 -0
- package/artifacts/ContractClassRegisterer.d.json.ts +5 -0
- package/artifacts/ContractClassRegisterer.json +7219 -0
- package/artifacts/ContractInstanceDeployer.d.json.ts +5 -0
- package/artifacts/ContractInstanceDeployer.json +2984 -0
- package/artifacts/FeeJuice.d.json.ts +5 -0
- package/artifacts/FeeJuice.json +4281 -0
- package/artifacts/MultiCallEntrypoint.d.json.ts +5 -0
- package/artifacts/MultiCallEntrypoint.json +2005 -0
- package/artifacts/Router.d.json.ts +5 -0
- package/artifacts/Router.json +3798 -0
- package/dest/auth-registry/index.d.ts +5 -0
- package/dest/auth-registry/index.d.ts.map +1 -0
- package/dest/auth-registry/index.js +13 -0
- package/dest/auth-registry/lazy.d.ts +6 -0
- package/dest/auth-registry/lazy.d.ts.map +1 -0
- package/dest/auth-registry/lazy.js +23 -0
- package/dest/build_protocol_contract_tree.d.ts +10 -0
- package/dest/build_protocol_contract_tree.d.ts.map +1 -0
- package/dest/build_protocol_contract_tree.js +20 -0
- package/dest/class-registerer/contract_class_registered_event.d.ts +18 -0
- package/dest/class-registerer/contract_class_registered_event.d.ts.map +1 -0
- package/dest/class-registerer/contract_class_registered_event.js +63 -0
- package/dest/class-registerer/index.d.ts +8 -0
- package/dest/class-registerer/index.d.ts.map +1 -0
- package/dest/class-registerer/index.js +17 -0
- package/dest/class-registerer/lazy.d.ts +9 -0
- package/dest/class-registerer/lazy.d.ts.map +1 -0
- package/dest/class-registerer/lazy.js +26 -0
- package/dest/class-registerer/private_function_broadcasted_event.d.ts +46 -0
- package/dest/class-registerer/private_function_broadcasted_event.d.ts.map +1 -0
- package/dest/class-registerer/private_function_broadcasted_event.js +85 -0
- package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts +40 -0
- package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts.map +1 -0
- package/dest/class-registerer/unconstrained_function_broadcasted_event.js +81 -0
- package/dest/fee-juice/index.d.ts +15 -0
- package/dest/fee-juice/index.d.ts.map +1 -0
- package/dest/fee-juice/index.js +26 -0
- package/dest/fee-juice/lazy.d.ts +6 -0
- package/dest/fee-juice/lazy.d.ts.map +1 -0
- package/dest/fee-juice/lazy.js +23 -0
- package/dest/index.d.ts +4 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +3 -0
- package/dest/instance-deployer/contract_instance_deployed_event.d.ts +20 -0
- package/dest/instance-deployer/contract_instance_deployed_event.d.ts.map +1 -0
- package/dest/instance-deployer/contract_instance_deployed_event.js +53 -0
- package/dest/instance-deployer/contract_instance_updated_event.d.ts +16 -0
- package/dest/instance-deployer/contract_instance_updated_event.d.ts.map +1 -0
- package/dest/instance-deployer/contract_instance_updated_event.js +36 -0
- package/dest/instance-deployer/index.d.ts +7 -0
- package/dest/instance-deployer/index.d.ts.map +1 -0
- package/dest/instance-deployer/index.js +15 -0
- package/dest/instance-deployer/lazy.d.ts +8 -0
- package/dest/instance-deployer/lazy.d.ts.map +1 -0
- package/dest/instance-deployer/lazy.js +25 -0
- package/dest/make_protocol_contract.d.ts +9 -0
- package/dest/make_protocol_contract.d.ts.map +1 -0
- package/dest/make_protocol_contract.js +23 -0
- package/dest/multi-call-entrypoint/index.d.ts +5 -0
- package/dest/multi-call-entrypoint/index.d.ts.map +1 -0
- package/dest/multi-call-entrypoint/index.js +13 -0
- package/dest/multi-call-entrypoint/lazy.d.ts +6 -0
- package/dest/multi-call-entrypoint/lazy.d.ts.map +1 -0
- package/dest/multi-call-entrypoint/lazy.js +23 -0
- package/dest/protocol_contract.d.ts +17 -0
- package/dest/protocol_contract.d.ts.map +1 -0
- package/dest/protocol_contract.js +4 -0
- package/dest/protocol_contract_data.d.ts +21 -0
- package/dest/protocol_contract_data.d.ts.map +1 -0
- package/dest/protocol_contract_data.js +41 -0
- package/dest/protocol_contract_tree.d.ts +7 -0
- package/dest/protocol_contract_tree.d.ts.map +1 -0
- package/dest/protocol_contract_tree.js +34 -0
- package/dest/provider/bundle.d.ts +9 -0
- package/dest/provider/bundle.d.ts.map +1 -0
- package/dest/provider/bundle.js +20 -0
- package/dest/provider/lazy.d.ts +7 -0
- package/dest/provider/lazy.d.ts.map +1 -0
- package/dest/provider/lazy.js +26 -0
- package/dest/provider/protocol_contracts_provider.d.ts +7 -0
- package/dest/provider/protocol_contracts_provider.d.ts.map +1 -0
- package/dest/provider/protocol_contracts_provider.js +1 -0
- package/dest/router/index.d.ts +5 -0
- package/dest/router/index.d.ts.map +1 -0
- package/dest/router/index.js +13 -0
- package/dest/router/lazy.d.ts +6 -0
- package/dest/router/lazy.d.ts.map +1 -0
- package/dest/router/lazy.js +23 -0
- package/dest/scripts/cleanup_artifacts.js +16 -0
- package/dest/scripts/generate_data.js +173 -0
- package/dest/tests/fixtures.d.ts +8 -0
- package/dest/tests/fixtures.d.ts.map +1 -0
- package/dest/tests/fixtures.js +26 -0
- package/package.json +103 -0
- package/src/auth-registry/index.ts +18 -0
- package/src/auth-registry/lazy.ts +29 -0
- package/src/build_protocol_contract_tree.ts +29 -0
- package/src/class-registerer/contract_class_registered_event.ts +83 -0
- package/src/class-registerer/index.ts +25 -0
- package/src/class-registerer/lazy.ts +33 -0
- package/src/class-registerer/private_function_broadcasted_event.ts +105 -0
- package/src/class-registerer/unconstrained_function_broadcasted_event.ts +99 -0
- package/src/fee-juice/index.ts +37 -0
- package/src/fee-juice/lazy.ts +29 -0
- package/src/index.ts +3 -0
- package/src/instance-deployer/contract_instance_deployed_event.ts +64 -0
- package/src/instance-deployer/contract_instance_updated_event.ts +44 -0
- package/src/instance-deployer/index.ts +23 -0
- package/src/instance-deployer/lazy.ts +32 -0
- package/src/make_protocol_contract.ts +26 -0
- package/src/multi-call-entrypoint/index.ts +18 -0
- package/src/multi-call-entrypoint/lazy.ts +29 -0
- package/src/protocol_contract.ts +23 -0
- package/src/protocol_contract_data.ts +63 -0
- package/src/protocol_contract_tree.ts +44 -0
- package/src/provider/bundle.ts +27 -0
- package/src/provider/lazy.ts +30 -0
- package/src/provider/protocol_contracts_provider.ts +7 -0
- package/src/router/index.ts +18 -0
- package/src/router/lazy.ts +29 -0
- package/src/tests/fixtures.ts +31 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
|
|
3
|
+
MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS,
|
|
4
|
+
} from '@aztec/constants';
|
|
5
|
+
import { removeArrayPaddingEnd } from '@aztec/foundation/collection';
|
|
6
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
7
|
+
import type { Tuple } from '@aztec/foundation/serialize';
|
|
8
|
+
import { FieldReader } from '@aztec/foundation/serialize';
|
|
9
|
+
import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
|
|
10
|
+
import type { UnconstrainedFunction, UnconstrainedFunctionWithMembershipProof } from '@aztec/stdlib/contract';
|
|
11
|
+
import type { ContractClassLog } from '@aztec/stdlib/logs';
|
|
12
|
+
|
|
13
|
+
import { REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG } from '../protocol_contract_data.js';
|
|
14
|
+
|
|
15
|
+
/** Event emitted from the ContractClassRegisterer. */
|
|
16
|
+
export class UnconstrainedFunctionBroadcastedEvent {
|
|
17
|
+
constructor(
|
|
18
|
+
public readonly contractClassId: Fr,
|
|
19
|
+
public readonly artifactMetadataHash: Fr,
|
|
20
|
+
public readonly privateFunctionsArtifactTreeRoot: Fr,
|
|
21
|
+
public readonly artifactFunctionTreeSiblingPath: Tuple<Fr, typeof ARTIFACT_FUNCTION_TREE_MAX_HEIGHT>,
|
|
22
|
+
public readonly artifactFunctionTreeLeafIndex: number,
|
|
23
|
+
public readonly unconstrainedFunction: BroadcastedUnconstrainedFunction,
|
|
24
|
+
) {}
|
|
25
|
+
|
|
26
|
+
static isUnconstrainedFunctionBroadcastedEvent(log: ContractClassLog) {
|
|
27
|
+
return log.fields[0].equals(REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static fromLog(log: ContractClassLog) {
|
|
31
|
+
const reader = new FieldReader(log.fields.slice(1));
|
|
32
|
+
const event = UnconstrainedFunctionBroadcastedEvent.fromFields(reader);
|
|
33
|
+
while (!reader.isFinished()) {
|
|
34
|
+
const field = reader.readField();
|
|
35
|
+
if (!field.isZero()) {
|
|
36
|
+
throw new Error(`Unexpected data after parsing UnconstrainedFunctionBroadcastedEvent: ${field.toString()}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return event;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static fromFields(fields: Fr[] | FieldReader) {
|
|
44
|
+
const reader = FieldReader.asReader(fields);
|
|
45
|
+
const contractClassId = reader.readField();
|
|
46
|
+
const artifactMetadataHash = reader.readField();
|
|
47
|
+
const privateFunctionsArtifactTreeRoot = reader.readField();
|
|
48
|
+
const artifactFunctionTreeSiblingPath = reader.readFieldArray(ARTIFACT_FUNCTION_TREE_MAX_HEIGHT);
|
|
49
|
+
const artifactFunctionTreeLeafIndex = reader.readField().toNumber();
|
|
50
|
+
const unconstrainedFunction = BroadcastedUnconstrainedFunction.fromFields(reader);
|
|
51
|
+
|
|
52
|
+
return new UnconstrainedFunctionBroadcastedEvent(
|
|
53
|
+
contractClassId,
|
|
54
|
+
artifactMetadataHash,
|
|
55
|
+
privateFunctionsArtifactTreeRoot,
|
|
56
|
+
artifactFunctionTreeSiblingPath,
|
|
57
|
+
artifactFunctionTreeLeafIndex,
|
|
58
|
+
unconstrainedFunction,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
toFunctionWithMembershipProof(): UnconstrainedFunctionWithMembershipProof {
|
|
63
|
+
// We should be able to safely remove the zero elements that pad the variable-length sibling path,
|
|
64
|
+
// since a sibling with value zero can only occur on the tree leaves, so the sibling path will never end
|
|
65
|
+
// in a zero. The only exception is a tree with depth 2 with one non-zero leaf, where the sibling path would
|
|
66
|
+
// be a single zero element, but in that case the artifact tree should be just the single leaf.
|
|
67
|
+
const artifactTreeSiblingPath = removeArrayPaddingEnd(this.artifactFunctionTreeSiblingPath, Fr.isZero);
|
|
68
|
+
return {
|
|
69
|
+
...this.unconstrainedFunction,
|
|
70
|
+
bytecode: this.unconstrainedFunction.bytecode,
|
|
71
|
+
functionMetadataHash: this.unconstrainedFunction.metadataHash,
|
|
72
|
+
artifactMetadataHash: this.artifactMetadataHash,
|
|
73
|
+
privateFunctionsArtifactTreeRoot: this.privateFunctionsArtifactTreeRoot,
|
|
74
|
+
artifactTreeSiblingPath,
|
|
75
|
+
artifactTreeLeafIndex: this.artifactFunctionTreeLeafIndex,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class BroadcastedUnconstrainedFunction implements UnconstrainedFunction {
|
|
81
|
+
constructor(
|
|
82
|
+
/** Selector of the function. Calculated as the hash of the method name and parameters. The specification of this is not enforced by the protocol. */
|
|
83
|
+
public readonly selector: FunctionSelector,
|
|
84
|
+
/** Artifact metadata hash */
|
|
85
|
+
public readonly metadataHash: Fr,
|
|
86
|
+
/** Brillig bytecode */
|
|
87
|
+
public readonly bytecode: Buffer,
|
|
88
|
+
) {}
|
|
89
|
+
|
|
90
|
+
static fromFields(fields: Fr[] | FieldReader) {
|
|
91
|
+
const reader = FieldReader.asReader(fields);
|
|
92
|
+
const selector = FunctionSelector.fromField(reader.readField());
|
|
93
|
+
const metadataHash = reader.readField();
|
|
94
|
+
// The '* 1' removes the 'Type instantiation is excessively deep and possibly infinite. ts(2589)' err
|
|
95
|
+
const encodedBytecode = reader.readFieldArray(MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS * 1);
|
|
96
|
+
const bytecode = bufferFromFields(encodedBytecode);
|
|
97
|
+
return new BroadcastedUnconstrainedFunction(selector, metadataHash, bytecode);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
3
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/stdlib/hash';
|
|
5
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
6
|
+
|
|
7
|
+
import FeeJuiceJson from '../../artifacts/FeeJuice.json' assert { type: 'json' };
|
|
8
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
9
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
10
|
+
import { ProtocolContractAddress } from '../protocol_contract_data.js';
|
|
11
|
+
|
|
12
|
+
export const FeeJuiceArtifact = loadContractArtifact(FeeJuiceJson as NoirCompiledContract);
|
|
13
|
+
|
|
14
|
+
let protocolContract: ProtocolContract;
|
|
15
|
+
|
|
16
|
+
/** Returns the canonical deployment of the contract. */
|
|
17
|
+
export async function getCanonicalFeeJuice(): Promise<ProtocolContract> {
|
|
18
|
+
if (!protocolContract) {
|
|
19
|
+
protocolContract = await makeProtocolContract('FeeJuice', FeeJuiceArtifact);
|
|
20
|
+
}
|
|
21
|
+
return protocolContract;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Computes the storage slot within the Fee Juice contract for the balance of the fee payer.
|
|
26
|
+
*/
|
|
27
|
+
export function computeFeePayerBalanceStorageSlot(feePayer: AztecAddress): Promise<Fr> {
|
|
28
|
+
return deriveStorageSlotInMap(FeeJuiceArtifact.storageLayout.balances.slot, feePayer);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Computes the leaf slot in the public data tree for the balance of the fee payer in the Fee Juice.
|
|
33
|
+
*/
|
|
34
|
+
export async function computeFeePayerBalanceLeafSlot(feePayer: AztecAddress): Promise<Fr> {
|
|
35
|
+
const balanceSlot = await computeFeePayerBalanceStorageSlot(feePayer);
|
|
36
|
+
return computePublicDataTreeLeafSlot(ProtocolContractAddress.FeeJuice, balanceSlot);
|
|
37
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
|
|
3
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
4
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
5
|
+
|
|
6
|
+
let protocolContract: ProtocolContract;
|
|
7
|
+
let protocolContractArtifact: ContractArtifact;
|
|
8
|
+
|
|
9
|
+
export async function getFeeJuiceArtifact(): Promise<ContractArtifact> {
|
|
10
|
+
if (!protocolContractArtifact) {
|
|
11
|
+
// Cannot assert this import as it's incompatible with browsers
|
|
12
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
13
|
+
// Use the new "with" syntax once supported by firefox
|
|
14
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
15
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
16
|
+
const { default: feeJuiceJson } = await import('../../artifacts/FeeJuice.json');
|
|
17
|
+
protocolContractArtifact = loadContractArtifact(feeJuiceJson);
|
|
18
|
+
}
|
|
19
|
+
return protocolContractArtifact;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Returns the canonical deployment of the auth registry. */
|
|
23
|
+
export async function getCanonicalFeeJuice(): Promise<ProtocolContract> {
|
|
24
|
+
if (!protocolContract) {
|
|
25
|
+
const feeJuiceArtifact = await getFeeJuiceArtifact();
|
|
26
|
+
protocolContract = await makeProtocolContract('FeeJuice', feeJuiceArtifact);
|
|
27
|
+
}
|
|
28
|
+
return protocolContract;
|
|
29
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
import { PublicKeys } from '@aztec/stdlib/keys';
|
|
6
|
+
import type { PrivateLog } from '@aztec/stdlib/logs';
|
|
7
|
+
|
|
8
|
+
import { DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG } from '../protocol_contract_data.js';
|
|
9
|
+
|
|
10
|
+
/** Event emitted from the ContractInstanceDeployer. */
|
|
11
|
+
export class ContractInstanceDeployedEvent {
|
|
12
|
+
constructor(
|
|
13
|
+
public readonly address: AztecAddress,
|
|
14
|
+
public readonly version: number,
|
|
15
|
+
public readonly salt: Fr,
|
|
16
|
+
public readonly contractClassId: Fr,
|
|
17
|
+
public readonly initializationHash: Fr,
|
|
18
|
+
public readonly publicKeys: PublicKeys,
|
|
19
|
+
public readonly deployer: AztecAddress,
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
static isContractInstanceDeployedEvent(log: PrivateLog) {
|
|
23
|
+
return log.fields[0].equals(DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static fromLog(log: PrivateLog) {
|
|
27
|
+
const bufferWithoutTag = log.toBuffer().subarray(32);
|
|
28
|
+
const reader = new BufferReader(bufferWithoutTag);
|
|
29
|
+
const address = reader.readObject(AztecAddress);
|
|
30
|
+
const version = reader.readObject(Fr).toNumber();
|
|
31
|
+
const salt = reader.readObject(Fr);
|
|
32
|
+
const contractClassId = reader.readObject(Fr);
|
|
33
|
+
const initializationHash = reader.readObject(Fr);
|
|
34
|
+
const publicKeys = reader.readObject(PublicKeys);
|
|
35
|
+
const deployer = reader.readObject(AztecAddress);
|
|
36
|
+
|
|
37
|
+
return new ContractInstanceDeployedEvent(
|
|
38
|
+
address,
|
|
39
|
+
version,
|
|
40
|
+
salt,
|
|
41
|
+
contractClassId,
|
|
42
|
+
initializationHash,
|
|
43
|
+
publicKeys,
|
|
44
|
+
deployer,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
toContractInstance(): ContractInstanceWithAddress {
|
|
49
|
+
if (this.version !== 1) {
|
|
50
|
+
throw new Error(`Unexpected contract instance version ${this.version}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
address: this.address,
|
|
55
|
+
version: this.version,
|
|
56
|
+
currentContractClassId: this.contractClassId,
|
|
57
|
+
originalContractClassId: this.contractClassId,
|
|
58
|
+
initializationHash: this.initializationHash,
|
|
59
|
+
publicKeys: this.publicKeys,
|
|
60
|
+
salt: this.salt,
|
|
61
|
+
deployer: this.deployer,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader } from '@aztec/foundation/serialize';
|
|
3
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
|
+
import type { ContractInstanceUpdateWithAddress } from '@aztec/stdlib/contract';
|
|
5
|
+
import type { PublicLog } from '@aztec/stdlib/logs';
|
|
6
|
+
|
|
7
|
+
import { DEPLOYER_CONTRACT_INSTANCE_UPDATED_TAG, ProtocolContractAddress } from '../protocol_contract_data.js';
|
|
8
|
+
|
|
9
|
+
/** Event emitted from the ContractInstanceDeployer. */
|
|
10
|
+
export class ContractInstanceUpdatedEvent {
|
|
11
|
+
constructor(
|
|
12
|
+
public readonly address: AztecAddress,
|
|
13
|
+
public readonly prevContractClassId: Fr,
|
|
14
|
+
public readonly newContractClassId: Fr,
|
|
15
|
+
public readonly blockOfChange: number,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
static isContractInstanceUpdatedEvent(log: PublicLog) {
|
|
19
|
+
return (
|
|
20
|
+
log.contractAddress.equals(ProtocolContractAddress.ContractInstanceDeployer) &&
|
|
21
|
+
log.log[0].equals(DEPLOYER_CONTRACT_INSTANCE_UPDATED_TAG)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static fromLog(log: PublicLog) {
|
|
26
|
+
const bufferWithoutAddressAndTag = log.toBuffer().subarray(64);
|
|
27
|
+
const reader = new BufferReader(bufferWithoutAddressAndTag);
|
|
28
|
+
const address = reader.readObject(AztecAddress);
|
|
29
|
+
const prevContractClassId = reader.readObject(Fr);
|
|
30
|
+
const newContractClassId = reader.readObject(Fr);
|
|
31
|
+
const blockOfChange = reader.readObject(Fr).toNumber();
|
|
32
|
+
|
|
33
|
+
return new ContractInstanceUpdatedEvent(address, prevContractClassId, newContractClassId, blockOfChange);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toContractInstanceUpdate(): ContractInstanceUpdateWithAddress {
|
|
37
|
+
return {
|
|
38
|
+
address: this.address,
|
|
39
|
+
prevContractClassId: this.prevContractClassId,
|
|
40
|
+
newContractClassId: this.newContractClassId,
|
|
41
|
+
blockOfChange: this.blockOfChange,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
|
+
|
|
4
|
+
import ContractInstanceDeployerJson from '../../artifacts/ContractInstanceDeployer.json' assert { type: 'json' };
|
|
5
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
+
|
|
8
|
+
export * from './contract_instance_deployed_event.js';
|
|
9
|
+
export * from './contract_instance_updated_event.js';
|
|
10
|
+
|
|
11
|
+
export const ContractInstanceDeployerArtifact = loadContractArtifact(
|
|
12
|
+
ContractInstanceDeployerJson as NoirCompiledContract,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
let protocolContract: ProtocolContract;
|
|
16
|
+
|
|
17
|
+
/** Returns the canonical deployment of the contract. */
|
|
18
|
+
export async function getCanonicalInstanceDeployer(): Promise<ProtocolContract> {
|
|
19
|
+
if (!protocolContract) {
|
|
20
|
+
protocolContract = await makeProtocolContract('ContractInstanceDeployer', ContractInstanceDeployerArtifact);
|
|
21
|
+
}
|
|
22
|
+
return protocolContract;
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
|
|
3
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
4
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
5
|
+
|
|
6
|
+
export * from './contract_instance_deployed_event.js';
|
|
7
|
+
export * from './contract_instance_updated_event.js';
|
|
8
|
+
|
|
9
|
+
let protocolContract: ProtocolContract;
|
|
10
|
+
let protocolContractArtifact: ContractArtifact;
|
|
11
|
+
|
|
12
|
+
export async function getContractInstanceDeployerArtifact(): Promise<ContractArtifact> {
|
|
13
|
+
if (!protocolContractArtifact) {
|
|
14
|
+
// Cannot assert this import as it's incompatible with browsers
|
|
15
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
16
|
+
// Use the new "with" syntax once supported by firefox
|
|
17
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
18
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
19
|
+
const { default: contractInstanceDeployerJson } = await import('../../artifacts/ContractInstanceDeployer.json');
|
|
20
|
+
protocolContractArtifact = loadContractArtifact(contractInstanceDeployerJson);
|
|
21
|
+
}
|
|
22
|
+
return protocolContractArtifact;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Returns the canonical deployment of the auth registry. */
|
|
26
|
+
export async function getCanonicalInstanceDeployer(): Promise<ProtocolContract> {
|
|
27
|
+
if (!protocolContract) {
|
|
28
|
+
const contractInstanceDeployerArtifact = await getContractInstanceDeployerArtifact();
|
|
29
|
+
protocolContract = await makeProtocolContract('ContractInstanceDeployer', contractInstanceDeployerArtifact);
|
|
30
|
+
}
|
|
31
|
+
return protocolContract;
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import { getContractClassFromArtifact, getContractInstanceFromDeployParams } from '@aztec/stdlib/contract';
|
|
3
|
+
|
|
4
|
+
import type { ProtocolContract } from './protocol_contract.js';
|
|
5
|
+
import { ProtocolContractAddress, type ProtocolContractName, ProtocolContractSalt } from './protocol_contract_data.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the canonical deployment given its name and artifact.
|
|
9
|
+
* To be used internally within the protocol-contracts package.
|
|
10
|
+
*/
|
|
11
|
+
export async function makeProtocolContract(
|
|
12
|
+
name: ProtocolContractName,
|
|
13
|
+
artifact: ContractArtifact,
|
|
14
|
+
): Promise<ProtocolContract> {
|
|
15
|
+
const address = ProtocolContractAddress[name];
|
|
16
|
+
const salt = ProtocolContractSalt[name];
|
|
17
|
+
// TODO(@spalladino): This computes the contract class from the artifact twice.
|
|
18
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
19
|
+
const instance = await getContractInstanceFromDeployParams(artifact, { salt });
|
|
20
|
+
return {
|
|
21
|
+
instance: { ...instance, address },
|
|
22
|
+
contractClass,
|
|
23
|
+
artifact,
|
|
24
|
+
address,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
|
+
|
|
4
|
+
import MultiCallEntrypointJson from '../../artifacts/MultiCallEntrypoint.json' assert { type: 'json' };
|
|
5
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
+
|
|
8
|
+
export const MultiCallEntrypointArtifact = loadContractArtifact(MultiCallEntrypointJson as NoirCompiledContract);
|
|
9
|
+
|
|
10
|
+
let protocolContract: ProtocolContract;
|
|
11
|
+
|
|
12
|
+
/** Returns the canonical deployment of the contract. */
|
|
13
|
+
export async function getCanonicalMultiCallEntrypoint(): Promise<ProtocolContract> {
|
|
14
|
+
if (!protocolContract) {
|
|
15
|
+
protocolContract = await makeProtocolContract('MultiCallEntrypoint', MultiCallEntrypointArtifact);
|
|
16
|
+
}
|
|
17
|
+
return protocolContract;
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
|
|
3
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
4
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
5
|
+
|
|
6
|
+
let protocolContract: ProtocolContract;
|
|
7
|
+
let protocolContractArtifact: ContractArtifact;
|
|
8
|
+
|
|
9
|
+
export async function getMultiCallEntrypointArtifact(): Promise<ContractArtifact> {
|
|
10
|
+
if (!protocolContractArtifact) {
|
|
11
|
+
// Cannot assert this import as it's incompatible with browsers
|
|
12
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
13
|
+
// Use the new "with" syntax once supported by firefox
|
|
14
|
+
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
15
|
+
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
16
|
+
const { default: multiCallEntrypointJson } = await import('../../artifacts/MultiCallEntrypoint.json');
|
|
17
|
+
protocolContractArtifact = loadContractArtifact(multiCallEntrypointJson);
|
|
18
|
+
}
|
|
19
|
+
return protocolContractArtifact;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Returns the canonical deployment of the auth registry. */
|
|
23
|
+
export async function getCanonicalMultiCallEntrypoint(): Promise<ProtocolContract> {
|
|
24
|
+
if (!protocolContract) {
|
|
25
|
+
const multiCallEntrypointArtifact = await getMultiCallEntrypointArtifact();
|
|
26
|
+
protocolContract = await makeProtocolContract('MultiCallEntrypoint', multiCallEntrypointArtifact);
|
|
27
|
+
}
|
|
28
|
+
return protocolContract;
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
+
import type { ContractClassIdPreimage, ContractClassWithId, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
4
|
+
|
|
5
|
+
import { ProtocolContractAddress } from './protocol_contract_data.js';
|
|
6
|
+
|
|
7
|
+
/** Represents a canonical contract in the protocol. */
|
|
8
|
+
export interface ProtocolContract {
|
|
9
|
+
/** Canonical deployed instance. */
|
|
10
|
+
instance: ContractInstanceWithAddress;
|
|
11
|
+
/** Contract class of this contract. */
|
|
12
|
+
contractClass: ContractClassWithId & ContractClassIdPreimage;
|
|
13
|
+
/** Complete contract artifact. */
|
|
14
|
+
artifact: ContractArtifact;
|
|
15
|
+
/** Deployment address for the canonical instance. */
|
|
16
|
+
address: AztecAddress;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isProtocolContract(address: AztecAddress) {
|
|
20
|
+
return Object.values(ProtocolContractAddress).some(a => a.equals(address));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { type ProtocolContractsProvider } from './provider/protocol_contracts_provider.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
// GENERATED FILE - DO NOT EDIT. RUN `yarn generate` or `yarn generate:data`
|
|
3
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const protocolContractNames = [
|
|
8
|
+
'AuthRegistry',
|
|
9
|
+
'ContractInstanceDeployer',
|
|
10
|
+
'ContractClassRegisterer',
|
|
11
|
+
'MultiCallEntrypoint',
|
|
12
|
+
'FeeJuice',
|
|
13
|
+
'Router'
|
|
14
|
+
] as const;
|
|
15
|
+
|
|
16
|
+
export type ProtocolContractName = typeof protocolContractNames[number];
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
export const ProtocolContractSalt: Record<ProtocolContractName, Fr> = {
|
|
21
|
+
AuthRegistry: new Fr(1),
|
|
22
|
+
ContractInstanceDeployer: new Fr(1),
|
|
23
|
+
ContractClassRegisterer: new Fr(1),
|
|
24
|
+
MultiCallEntrypoint: new Fr(1),
|
|
25
|
+
FeeJuice: new Fr(1),
|
|
26
|
+
Router: new Fr(1)
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export const ProtocolContractAddress: Record<ProtocolContractName, AztecAddress> = {
|
|
32
|
+
AuthRegistry: AztecAddress.fromBigInt(1n),
|
|
33
|
+
ContractInstanceDeployer: AztecAddress.fromBigInt(2n),
|
|
34
|
+
ContractClassRegisterer: AztecAddress.fromBigInt(3n),
|
|
35
|
+
MultiCallEntrypoint: AztecAddress.fromBigInt(4n),
|
|
36
|
+
FeeJuice: AztecAddress.fromBigInt(5n),
|
|
37
|
+
Router: AztecAddress.fromBigInt(6n)
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export const ProtocolContractLeaves = {
|
|
43
|
+
AuthRegistry: Fr.fromHexString('0x1dc70bdab08ce08aef9f6ddcc8fd54fb91fdb72a6433c2dd6b69b33cf1fb87a2'),
|
|
44
|
+
ContractInstanceDeployer: Fr.fromHexString('0x005d6d6addbbda03dcad6fc9a3c3b7de457c30990ec2acaaf74f139a3a506e06'),
|
|
45
|
+
ContractClassRegisterer: Fr.fromHexString('0x110ef3d93e27fd61a5a56e479a9f9cbdb099d2d968cdcc16c01d2bdfd6cb0ddd'),
|
|
46
|
+
MultiCallEntrypoint: Fr.fromHexString('0x121f834b03a64d38463ae18ddebceeb4dce8192cc289052e175ad754a883a7fe'),
|
|
47
|
+
FeeJuice: Fr.fromHexString('0x141a566ade0bef915526762c2c2fb19b2a756ad7c82e83fde6dbf86848ecc131'),
|
|
48
|
+
Router: Fr.fromHexString('0x2c20bd328fbd33c01fbcda9e6299c31da5d5b29ea30e9c7b9d631618b839bca9')
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export const protocolContractTreeRoot = Fr.fromHexString('0x093cc9324e5a7b44883f515ac490e7294ef8cb1e6d2d8c503255b1b3a9409262');
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export const REGISTERER_CONTRACT_CLASS_REGISTERED_TAG = Fr.fromHexString('0x20cd27645f65c15a38720ca984aef936592f3938a705db706d068ad13fc58ae9');
|
|
58
|
+
export const REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG = Fr.fromHexString('0x0abf338154e355442d9916d630da0491036d5a7b23c42b477c1395ba3bf9b42d');
|
|
59
|
+
export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG = Fr.fromHexString('0x27774539896271d6dbe0c1de45ddc44709d1e8d9a9fb686ca3c105d87c417bb8');
|
|
60
|
+
export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG = Fr.fromHexString('0x2ec28b91a5f838506d6042915005ff55cf7a0a5f889a83b11faed33a31b486f2');
|
|
61
|
+
export const DEPLOYER_CONTRACT_INSTANCE_UPDATED_TAG = new Fr(1534834688047131268740281708431107902615560100979874281215533519862n);
|
|
62
|
+
|
|
63
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { PROTOCOL_CONTRACT_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
3
|
+
import type { IndexedMerkleTree } from '@aztec/foundation/trees';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { ProtocolContractLeafPreimage } from '@aztec/stdlib/trees';
|
|
6
|
+
|
|
7
|
+
import { buildProtocolContractTree } from './build_protocol_contract_tree.js';
|
|
8
|
+
import { isProtocolContract } from './protocol_contract.js';
|
|
9
|
+
import { ProtocolContractAddress, ProtocolContractLeaves, protocolContractNames } from './protocol_contract_data.js';
|
|
10
|
+
|
|
11
|
+
let protocolContractTree:
|
|
12
|
+
| IndexedMerkleTree<ProtocolContractLeafPreimage, typeof PROTOCOL_CONTRACT_TREE_HEIGHT>
|
|
13
|
+
| undefined;
|
|
14
|
+
|
|
15
|
+
async function getTree() {
|
|
16
|
+
if (!protocolContractTree) {
|
|
17
|
+
const leaves = protocolContractNames.map(name => ({
|
|
18
|
+
address: ProtocolContractAddress[name],
|
|
19
|
+
leaf: ProtocolContractLeaves[name],
|
|
20
|
+
}));
|
|
21
|
+
protocolContractTree = await buildProtocolContractTree(leaves);
|
|
22
|
+
}
|
|
23
|
+
return protocolContractTree;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Computed address can be different from contract address due to upgrades
|
|
27
|
+
export async function getProtocolContractLeafAndMembershipWitness(
|
|
28
|
+
contractAddress: AztecAddress,
|
|
29
|
+
computedAddress: AztecAddress,
|
|
30
|
+
) {
|
|
31
|
+
const tree = await getTree();
|
|
32
|
+
let lowLeaf;
|
|
33
|
+
let witness;
|
|
34
|
+
if (isProtocolContract(contractAddress)) {
|
|
35
|
+
const index = contractAddress.toField().toNumber();
|
|
36
|
+
lowLeaf = tree.leafPreimages[index];
|
|
37
|
+
witness = tree.getMembershipWitness(index);
|
|
38
|
+
} else {
|
|
39
|
+
lowLeaf = tree.getLowLeaf(computedAddress.toBigInt());
|
|
40
|
+
const hashed = (await poseidon2Hash(lowLeaf.toHashInputs())).toBuffer();
|
|
41
|
+
witness = tree.getMembershipWitness(hashed);
|
|
42
|
+
}
|
|
43
|
+
return { lowLeaf, witness };
|
|
44
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
|
|
3
|
+
import { AuthRegistryArtifact } from '../auth-registry/index.js';
|
|
4
|
+
import { ContractClassRegistererArtifact } from '../class-registerer/index.js';
|
|
5
|
+
import { FeeJuiceArtifact } from '../fee-juice/index.js';
|
|
6
|
+
import { ContractInstanceDeployerArtifact } from '../instance-deployer/index.js';
|
|
7
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
8
|
+
import { MultiCallEntrypointArtifact } from '../multi-call-entrypoint/index.js';
|
|
9
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
10
|
+
import type { ProtocolContractName } from '../protocol_contract_data.js';
|
|
11
|
+
import { RouterArtifact } from '../router/index.js';
|
|
12
|
+
import type { ProtocolContractsProvider } from './protocol_contracts_provider.js';
|
|
13
|
+
|
|
14
|
+
export const ProtocolContractArtifact: Record<ProtocolContractName, ContractArtifact> = {
|
|
15
|
+
AuthRegistry: AuthRegistryArtifact,
|
|
16
|
+
ContractInstanceDeployer: ContractInstanceDeployerArtifact,
|
|
17
|
+
ContractClassRegisterer: ContractClassRegistererArtifact,
|
|
18
|
+
MultiCallEntrypoint: MultiCallEntrypointArtifact,
|
|
19
|
+
FeeJuice: FeeJuiceArtifact,
|
|
20
|
+
Router: RouterArtifact,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class BundledProtocolContractsProvider implements ProtocolContractsProvider {
|
|
24
|
+
getProtocolContractArtifact(name: ProtocolContractName): Promise<ProtocolContract> {
|
|
25
|
+
return makeProtocolContract(name, ProtocolContractArtifact[name]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getCanonicalAuthRegistry } from '../auth-registry/lazy.js';
|
|
2
|
+
import { getCanonicalClassRegisterer } from '../class-registerer/lazy.js';
|
|
3
|
+
import { getCanonicalFeeJuice } from '../fee-juice/lazy.js';
|
|
4
|
+
import { getCanonicalInstanceDeployer } from '../instance-deployer/lazy.js';
|
|
5
|
+
import { getCanonicalMultiCallEntrypoint } from '../multi-call-entrypoint/lazy.js';
|
|
6
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
+
import type { ProtocolContractName } from '../protocol_contract_data.js';
|
|
8
|
+
import { getCanonicalRouter } from '../router/lazy.js';
|
|
9
|
+
import type { ProtocolContractsProvider } from './protocol_contracts_provider.js';
|
|
10
|
+
|
|
11
|
+
export class LazyProtocolContractsProvider implements ProtocolContractsProvider {
|
|
12
|
+
getProtocolContractArtifact(name: ProtocolContractName): Promise<ProtocolContract> {
|
|
13
|
+
switch (name) {
|
|
14
|
+
case 'AuthRegistry':
|
|
15
|
+
return getCanonicalAuthRegistry();
|
|
16
|
+
case 'ContractInstanceDeployer':
|
|
17
|
+
return getCanonicalInstanceDeployer();
|
|
18
|
+
case 'ContractClassRegisterer':
|
|
19
|
+
return getCanonicalClassRegisterer();
|
|
20
|
+
case 'MultiCallEntrypoint':
|
|
21
|
+
return getCanonicalMultiCallEntrypoint();
|
|
22
|
+
case 'FeeJuice':
|
|
23
|
+
return getCanonicalFeeJuice();
|
|
24
|
+
case 'Router':
|
|
25
|
+
return getCanonicalRouter();
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`Unknown protocol contract name: ${name}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
2
|
+
import type { ProtocolContractName } from '../protocol_contract_data.js';
|
|
3
|
+
|
|
4
|
+
/** Returns the canonical deployment of a given artifact. */
|
|
5
|
+
export interface ProtocolContractsProvider {
|
|
6
|
+
getProtocolContractArtifact(name: ProtocolContractName): Promise<ProtocolContract>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
+
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
|
+
|
|
4
|
+
import RouterJson from '../../artifacts/Router.json' assert { type: 'json' };
|
|
5
|
+
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
+
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
+
|
|
8
|
+
export const RouterArtifact = loadContractArtifact(RouterJson as NoirCompiledContract);
|
|
9
|
+
|
|
10
|
+
let protocolContract: ProtocolContract;
|
|
11
|
+
|
|
12
|
+
/** Returns the canonical deployment of the contract. */
|
|
13
|
+
export async function getCanonicalRouter(): Promise<ProtocolContract> {
|
|
14
|
+
if (!protocolContract) {
|
|
15
|
+
protocolContract = await makeProtocolContract('Router', RouterArtifact);
|
|
16
|
+
}
|
|
17
|
+
return protocolContract;
|
|
18
|
+
}
|