Skip to content

Commit

Permalink
add checkVersion flag to Upgradeable
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanzhelyazkov committed Aug 23, 2024
1 parent 88915fa commit 658260b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
13 changes: 6 additions & 7 deletions contracts/utility/Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,17 @@ abstract contract Upgradeable is IUpgradeable, AccessControlEnumerableUpgradeabl
*
* - this must and can be called only once per-upgrade
*/
function postUpgrade(bytes calldata data) external {
function postUpgrade(bool checkVersion, bytes calldata data) external {
uint16 initializations = _initializations + 1;
uint16 _version = version();
if (initializations < _version) {
initializations = _version;
}
if (initializations != _version) {
if (checkVersion && initializations != _version) {
revert AlreadyInitialized();
} else if (!checkVersion) {
initializations = _version;
} else {
initializations = initializations;
}

_initializations = initializations;

_postUpgrade(data);
}

Expand Down
2 changes: 1 addition & 1 deletion deploy/scripts/network/0002-Voucher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironm
await execute({
name: InstanceName.Voucher,
methodName: 'postUpgrade',
args: ["0x"],
args: ['0x'],
from: deployer
});

Expand Down
5 changes: 4 additions & 1 deletion deploy/tests/mainnet/carbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ import { ethers, getNamedAccounts } from 'hardhat';
await expectRoleMembers(carbonVortex, Roles.Upgradeable.ROLE_ADMIN, [daoMultisig.address]);

// expect carbon vortex to have fee manager role in Carbon
await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [oldVortex, carbonVortex.address]);
await expectRoleMembers(carbonController, Roles.CarbonController.ROLE_FEES_MANAGER, [
oldVortex,
carbonVortex.address
]);

// expect carbonController to have minter role in voucher
await expectRoleMembers(voucher, Roles.Voucher.ROLE_MINTER, [carbonController.address]);
Expand Down
2 changes: 1 addition & 1 deletion deploy/tests/network/0002-voucher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describeDeployment(__filename, () => {

it('cannot call postUpgrade on voucher', async () => {
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted)
const tx = await voucher.postUpgrade("0x", { gasLimit: 6000000 });
const tx = await voucher.postUpgrade('0x', { gasLimit: 6000000 });

Check failure on line 30 in deploy/tests/network/0002-voucher.ts

View workflow job for this annotation

GitHub Actions / Test

Argument of type 'string' is not assignable to parameter of type 'boolean'.
await expect(tx.wait()).to.be.reverted;
});
});
2 changes: 1 addition & 1 deletion deploy/tests/network/0003-carbon-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describeDeployment(__filename, () => {

it('cannot call postUpgrade on carbon controller', async () => {
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted)
const tx = await carbonController.postUpgrade("0x", { gasLimit: 6000000 });
const tx = await carbonController.postUpgrade('0x', { gasLimit: 6000000 });

Check failure on line 33 in deploy/tests/network/0003-carbon-controller.ts

View workflow job for this annotation

GitHub Actions / Test

Argument of type 'string' is not assignable to parameter of type 'boolean'.
await expect(tx.wait()).to.be.reverted;
});
});
8 changes: 5 additions & 3 deletions utils/Deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ export const deployProxy = async (options: DeployOptions, proxy: ProxyOptions =
// ]
interface UpgradeProxyOptions extends DeployOptions {
postUpgradeArgs?: TypedParam[];
checkVersion?: boolean;
}

export const upgradeProxy = async (options: UpgradeProxyOptions) => {
Expand All @@ -351,16 +352,17 @@ export const upgradeProxy = async (options: UpgradeProxyOptions) => {
const values = postUpgradeArgs.map(({ value }) => value);
const abiCoder = new AbiCoder();

upgradeCallData = [abiCoder.encode(types, values)];
upgradeCallData = abiCoder.encode(types, values);
} else {
upgradeCallData = [ZERO_BYTES];
upgradeCallData = ZERO_BYTES;
}
const checkVersion = options.checkVersion ?? true;

const proxyOptions = {
proxyContract: PROXY_CONTRACT,
owner: await proxyAdmin.owner(),
viaAdminContract: InstanceName.ProxyAdmin,
execute: { onUpgrade: { methodName: POST_UPGRADE, args: upgradeCallData } }
execute: { onUpgrade: { methodName: POST_UPGRADE, args: [checkVersion, upgradeCallData] } }
};

Logger.log(` upgrading proxy ${contractName} V${prevVersion}`);
Expand Down

0 comments on commit 658260b

Please sign in to comment.