Files
staking-reward-streamer/script/UpgradeToKarmaWithAccessControl.s.sol
r4bbit 51357d89df feat(Karma): introduce KarmaWithAccessControl
This commit introduces a new `Karma` extension that adds `AccessControl`
capabilities. The reason this is done so that there can be multiple
actors in the system with different privileges.

The main changes done here are:

- Introduce internal functions for most of the Karma specific logic
  (this is necessary to allow properly extending the contract's
  functionality via modifiers)
- Add a `KarmaWithAccessControl` contract that inherits `Karma` and
  overrides the necessary functions
- Introduce `OPERATOR_ROLE` next to the already provided
  `DEFAULT_ADMIN_ROLE`

Due to storage layout conflicts, the extension is implemented by
inheriting `Karma` instead of adding the `AccessControl` functionality
to the `Karma` contract directly.

Closes #207
2025-05-02 06:38:03 +02:00

35 lines
1.4 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { BaseScript } from "./Base.s.sol";
import { DeploymentConfig } from "./DeploymentConfig.s.sol";
import { KarmaWithAccessControl } from "../src/KarmaWithAccessControl.sol";
contract UpgradeToKarmaWithAccessControlScript is BaseScript {
error ProxyAddressNotSet();
function run() public returns (address) {
address currentImplProxy = vm.envAddress("KARMA_PROXY_ADDRESS");
if (currentImplProxy == address(0)) {
revert ProxyAddressNotSet();
}
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster);
(address deployer,) = deploymentConfig.activeNetworkConfig();
return runWithAdminAndProxy(deployer, currentImplProxy);
}
function runWithAdminAndProxy(address admin, address currentImplProxy) public returns (address) {
address deployer = broadcaster;
if (admin != address(0)) {
deployer = admin;
}
vm.startBroadcast(deployer);
address nextImpl = address(new KarmaWithAccessControl());
UUPSUpgradeable(address(currentImplProxy)).upgradeTo(nextImpl);
KarmaWithAccessControl(currentImplProxy).initializeAccessControl();
vm.stopBroadcast();
return nextImpl;
}
}