feat: implement HyperlaneHaasGovernor (#4435)
feat: implement HyperlaneHaasGovernor - allows one-time governance of actions resulting from both ICA+Core checkers - updates check-deploy to support the `-m haas` module - also fixes a bug to do with submitting calls to the current SAFE owner when a new ICA owner has just been configured example: ![image](https://github.com/user-attachments/assets/8d92053b-d3eb-4ac0-86b0-7330305719df) ![image](https://github.com/user-attachments/assets/f3db2d48-0995-404f-8861-fb34c6fd08f1) --------- Signed-off-by: pbio <10051819+paulbalaji@users.noreply.github.com>pull/4442/head
parent
15c1e3ba9e
commit
24ac8de29c
@ -0,0 +1,105 @@ |
||||
import { |
||||
ChainName, |
||||
CheckerViolation, |
||||
CoreConfig, |
||||
HyperlaneCore, |
||||
HyperlaneCoreChecker, |
||||
InterchainAccount, |
||||
InterchainAccountChecker, |
||||
} from '@hyperlane-xyz/sdk'; |
||||
|
||||
import { |
||||
AnnotatedCallData, |
||||
HyperlaneAppGovernor, |
||||
} from './HyperlaneAppGovernor.js'; |
||||
import { HyperlaneCoreGovernor } from './HyperlaneCoreGovernor.js'; |
||||
import { ProxiedRouterGovernor } from './ProxiedRouterGovernor.js'; |
||||
|
||||
export class HyperlaneHaasGovernor extends HyperlaneAppGovernor< |
||||
HyperlaneCore, |
||||
CoreConfig |
||||
> { |
||||
protected readonly icaGovernor: ProxiedRouterGovernor<any, any>; |
||||
protected readonly coreGovernor: HyperlaneCoreGovernor; |
||||
|
||||
constructor( |
||||
ica: InterchainAccount, |
||||
private readonly icaChecker: InterchainAccountChecker, |
||||
private readonly coreChecker: HyperlaneCoreChecker, |
||||
) { |
||||
super(coreChecker, ica); |
||||
|
||||
this.icaGovernor = new ProxiedRouterGovernor(this.icaChecker); |
||||
this.coreGovernor = new HyperlaneCoreGovernor(this.coreChecker, this.ica); |
||||
} |
||||
|
||||
protected mapViolationToCall( |
||||
_: CheckerViolation, |
||||
): Promise<{ chain: string; call: AnnotatedCallData } | undefined> { |
||||
throw new Error(`HyperlaneHaasGovernor has no native map of violations.`); |
||||
} |
||||
|
||||
// Handle ICA violations before Core violations
|
||||
protected async mapViolationsToCalls(): Promise<void> { |
||||
// Handle ICA violations first
|
||||
const icaCallObjs = await Promise.all( |
||||
this.icaChecker.violations.map((violation) => |
||||
this.icaGovernor.mapViolationToCall(violation), |
||||
), |
||||
); |
||||
|
||||
// Process ICA call objects
|
||||
for (const callObj of icaCallObjs) { |
||||
if (callObj) { |
||||
this.pushCall(callObj.chain, callObj.call); |
||||
} |
||||
} |
||||
|
||||
// Then handle Core violations
|
||||
const coreCallObjs = await Promise.all( |
||||
this.coreChecker.violations.map((violation) => |
||||
this.coreGovernor.mapViolationToCall(violation), |
||||
), |
||||
); |
||||
|
||||
// Process Core call objects
|
||||
for (const callObj of coreCallObjs) { |
||||
if (callObj) { |
||||
this.pushCall(callObj.chain, callObj.call); |
||||
} |
||||
} |
||||
} |
||||
|
||||
async check() { |
||||
await this.icaChecker.check(); |
||||
await this.coreChecker.check(); |
||||
} |
||||
|
||||
async checkChain(chain: ChainName) { |
||||
await this.icaChecker.checkChain(chain); |
||||
await this.coreChecker.checkChain(chain); |
||||
} |
||||
|
||||
getCheckerViolations() { |
||||
return [...this.icaChecker.violations, ...this.coreChecker.violations]; |
||||
} |
||||
|
||||
async govern(confirm = true, chain?: ChainName) { |
||||
const totalViolations = |
||||
this.icaChecker.violations.length + this.coreChecker.violations.length; |
||||
if (totalViolations === 0) return; |
||||
|
||||
// 1. Map violations to calls
|
||||
await this.mapViolationsToCalls(); |
||||
|
||||
// 2. For each call, infer how it should be submitted on-chain.
|
||||
await this.inferCallSubmissionTypes(); |
||||
|
||||
// 3. Prompt the user to confirm that the count, description,
|
||||
// and submission methods look correct before submitting.
|
||||
const chains = chain ? [chain] : Object.keys(this.calls); |
||||
for (const chain of chains) { |
||||
await this.sendCalls(chain, confirm); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue