Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/venn/enable/enable.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ export class EnableVennCommand extends CommandRunner {
parseSubnets(subnet: string, subnetsAccumulator: string[] = []): number[] {
return [...subnetsAccumulator, subnet].map(Number).sort();
}

@Option({
flags: '-p, --policy <address>',
description: 'use a custom policy address instead of deploying a new one',
})
parsePolicy(policy: string): string {
return policy;
}
}
29 changes: 24 additions & 5 deletions src/venn/enable/enable.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type EnableVennOptions = {
network: SupportedVennNetworks;
dryRun: boolean;
subnets?: number[];
policy?: string;
};

type ContractInformation = {
Expand All @@ -49,17 +50,27 @@ export class EnableVennService {

const contracts = await this.getContractsInformation(networkConfig, provider, options.network);

const newPolicyAddress = await this.deployNewVennPolicy(contracts, wallet, networkConfig, provider);
let policyAddress: string;
if (options.policy) {
// Use custom policy address
policyAddress = await this.validatePolicyAddress(options.policy);
this.logger.step('Using custom policy address');
this.logger.log(` -> Policy address: ${colors.cyan(policyAddress)}`);
} else {
// Deploy new policy with default configuration
policyAddress = await this.deployNewVennPolicy(contracts, wallet, networkConfig, provider);
}

await this.setFirewallOnConsumers(contracts, networkConfig, wallet, options.network, provider);

if (options.dryRun) {
await this.enableDryRun(contracts, networkConfig, wallet, provider);
}

await this.setAttestationCenterProxyOnConsumers(contracts, networkConfig, wallet, newPolicyAddress, provider);
await this.subscribeConsumersToNewPolicy(contracts, newPolicyAddress, wallet, networkConfig, provider);
await this.registerContractsInProtocolRegistry(newPolicyAddress, networkConfig, wallet, provider);
await this.subscribeToRootSubnet(newPolicyAddress, networkConfig, wallet, provider, subnets);
await this.setAttestationCenterProxyOnConsumers(contracts, networkConfig, wallet, policyAddress, provider);
await this.subscribeConsumersToNewPolicy(contracts, policyAddress, wallet, networkConfig, provider);
await this.registerContractsInProtocolRegistry(policyAddress, networkConfig, wallet, provider);
await this.subscribeToRootSubnet(policyAddress, networkConfig, wallet, provider, subnets);
}

private async deployNewVennPolicy(
Expand Down Expand Up @@ -578,4 +589,12 @@ export class EnableVennService {
this.logger.debug(` -> Network Safe Call Target address: ${networkAddress}`);
return setAddress === networkAddress;
}

private async validatePolicyAddress(policyAddress: string): Promise<string> {
if (!this.ethers.isAddress(policyAddress)) {
throw new Error(`Invalid policy address: ${colors.red(policyAddress)}`);
}

return this.ethers.getAddress(policyAddress);
}
}