-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d55b604
commit 8248b10
Showing
3 changed files
with
126 additions
and
81 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
56 changes: 56 additions & 0 deletions
56
packages/contracts/deploy/30_upgrade_repo/31b_upgrade_and_reinitialize_repo.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,56 @@ | ||
import {upgradeCommon as commonUpgradeSteps, skipUpgrade} from './_common'; | ||
import {PLUGIN_REPO_PERMISSIONS} from '@aragon/osx-commons-sdk'; | ||
import {BytesLike} from 'ethers'; | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
|
||
/** | ||
* Upgrades the plugin repo to the latest implementation and reinitializes the proxy. | ||
* @param {HardhatRuntimeEnvironment} hre | ||
*/ | ||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const {deployer, pluginRepo, latestPluginRepoImplementation, current} = | ||
await commonUpgradeSteps(hre); | ||
|
||
// Define the `_initData` arguments | ||
const initData: BytesLike[] = []; | ||
|
||
// Encode the call to `function initializeFrom(uint8[3] calldata _previousProtocolVersion, bytes calldata _initData)` with `initData`. | ||
const initializeFromCalldata = | ||
latestPluginRepoImplementation.interface.encodeFunctionData( | ||
// Re-initialization will happen through a call to `function initializeFrom(uint8[3] calldata _previousProtocolVersion, bytes calldata _initData)` | ||
// that Aragon will add to the `PluginRepo` contract once it's required. | ||
'initializeFrom', | ||
[current, initData] | ||
); | ||
|
||
// Check if deployer has the permission to upgrade the plugin repo | ||
if ( | ||
await pluginRepo.isGranted( | ||
pluginRepo.address, | ||
deployer.address, | ||
PLUGIN_REPO_PERMISSIONS.UPGRADE_REPO_PERMISSION_ID, | ||
[] | ||
) | ||
) { | ||
// Use `upgradeToAndCall` to reinitialize the new `PluginRepo` implementation after the update. | ||
if (initializeFromCalldata.length > 0) { | ||
await pluginRepo.upgradeToAndCall( | ||
latestPluginRepoImplementation.address, | ||
initializeFromCalldata | ||
); | ||
} else { | ||
throw Error( | ||
`Initialization data is missing for 'upgradeToAndCall'. Stopping repo upgrade and reinitialization...` | ||
); | ||
} | ||
} else { | ||
throw Error( | ||
`The new version cannot be published because the deployer ('${deployer.address}') | ||
is lacking the ${PLUGIN_REPO_PERMISSIONS.UPGRADE_REPO_PERMISSION_ID} permission.` | ||
); | ||
} | ||
}; | ||
export default func; | ||
func.tags = ['UpgradeAndReinitializeRepo']; | ||
func.skip = skipUpgrade; |
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