Skip to content

Commit 688e03f

Browse files
authored
feat(protocol-contracts): adminSafeModule task on GovernanceOAppReceiver (#1288)
1 parent a8db34d commit 688e03f

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

protocol-contracts/deployment-cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Commands:
3636
```
3737

3838
Once the deployment configuration is complete, you can run the deployment with the following command:
39+
3940
```bash
4041
bun run start deploy --network testnet
4142
```

protocol-contracts/deployment-cli/src/steps/step-03-layerzero.ts

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from "node:path";
2-
import { Contract, ethers } from "ethers";
32
import { execa } from "execa";
43
import type { PackageName } from "../tasks/hardhat-runner.js";
54
import { ValidationError } from "../utils/errors.js";
@@ -156,32 +155,19 @@ export class Step03LayerzeroLink extends BaseStep {
156155
// Step 3b: Set adminSafeModule in GovernanceOAppReceiver (must be called by current owner)
157156
// We set it before ownership transfers to ensure we can call as the deployer if needed
158157
ctx.logger.info("Setting adminSafeModule on GovernanceOAppReceiver...");
159-
{
160-
const provider = new ethers.JsonRpcProvider(gatewayNetwork.rpcUrl);
161-
const signer = new ethers.Wallet(protocolPk, provider);
162-
const receiverArtifactPath = path.join(
163-
resolveProjectRoot(),
164-
this.pkgName,
165-
"artifacts",
166-
"contracts",
167-
"GovernanceOAppReceiver.sol",
168-
"GovernanceOAppReceiver.json",
169-
);
170-
const receiverAbi = (
171-
(await import(receiverArtifactPath, {
172-
with: { type: "json" },
173-
})) as any
174-
).default.abi;
175-
const receiver = new Contract(receiverAddress, receiverAbi, signer);
176-
const currentModule: string = await receiver.adminSafeModule();
177-
if (
178-
currentModule.toLowerCase() !== adminModuleAddress.toLowerCase()
179-
) {
180-
const tx =
181-
await receiver.setAdminSafeModule(adminModuleAddress);
182-
await tx.wait();
183-
}
184-
}
158+
await ctx.hardhat.runTask({
159+
pkg: this.pkgName,
160+
task: "task:setAdminSafeModule",
161+
args: [
162+
"--network",
163+
gatewayNetwork.name,
164+
"--module",
165+
adminModuleAddress,
166+
"--receiver",
167+
receiverAddress,
168+
],
169+
env: baseEnv,
170+
});
185171
ctx.logger.success(
186172
"adminSafeModule configured on GovernanceOAppReceiver",
187173
);

protocol-contracts/governance/hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { HardhatUserConfig, HttpNetworkAccountsUserConfig } from 'hardhat/types'
1414
import { EndpointId } from '@layerzerolabs/lz-definitions'
1515

1616
import './tasks/sendRemoteProposal'
17+
import './tasks/setAdminSafeModule'
1718

1819
// Set your preferred authentication method
1920
//
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { task, types } from 'hardhat/config'
2+
import { HardhatRuntimeEnvironment } from 'hardhat/types'
3+
import { createLogger } from '@layerzerolabs/io-devtools'
4+
const logger = createLogger()
5+
6+
task('task:setAdminSafeModule', 'Sets GovernanceOAppReceiver.adminSafeModule')
7+
.addParam('module', 'AdminModule address to authorize', undefined, types.string)
8+
.addOptionalParam('receiver', 'GovernanceOAppReceiver address (defaults to deployment)', undefined, types.string)
9+
.setAction(async ({ module, receiver }: { module: string, receiver: string }, hre: HardhatRuntimeEnvironment) => {
10+
const { deployments, ethers, getNamedAccounts } = hre
11+
12+
const moduleAddress = ethers.utils.getAddress(module)
13+
14+
const receiverDeploymentAddress = receiver
15+
? receiver
16+
: (await deployments.get('GovernanceOAppReceiver')).address
17+
const receiverAddress = ethers.utils.getAddress(receiverDeploymentAddress)
18+
19+
const { deployer } = await getNamedAccounts()
20+
const signer = await ethers.getSigner(deployer)
21+
const governanceReceiver = await ethers.getContractAt('GovernanceOAppReceiver', receiverAddress, signer)
22+
23+
const currentModule: string = await governanceReceiver.adminSafeModule()
24+
if (ethers.utils.getAddress(currentModule) === moduleAddress) {
25+
logger.info(`adminSafeModule already set to ${moduleAddress} on ${receiverAddress}`)
26+
return
27+
}
28+
29+
logger.info(`Setting adminSafeModule on ${receiverAddress} to ${moduleAddress}...`)
30+
const tx = await governanceReceiver.setAdminSafeModule(moduleAddress)
31+
const receipt = await tx.wait()
32+
logger.info(`✔ adminSafeModule updated in tx ${receipt?.hash ?? tx.hash}`)
33+
})

0 commit comments

Comments
 (0)