Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pause #138

Merged
merged 11 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
HARDHAT_NETWORK=
VERIFY_API_KEY=
# Custom gas price for deployments
GAS_PRICE=
GAS_PRICE=auto

# Config for Tenderly - testing environment
TENDERLY_FORK_ID=
Expand All @@ -13,6 +13,6 @@ TENDERLY_TEST_PROJECT=
TENDERLY_TEMP_PROJECT=

# What network to fork from, default to 'mainnet'
TENDERLY_NETWORK_NAME=
TENDERLY_NETWORK_NAME=mainnet
# Dev addresses to fund on tenderly forks or testnets
DEV_ADDRESSES=
58 changes: 11 additions & 47 deletions contracts/carbon/CarbonController.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.19;
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { IVersioned } from "../utility/interfaces/IVersioned.sol";
import { Pairs, Pair } from "./Pairs.sol";
import { Token } from "../token/Token.sol";
Expand All @@ -22,18 +21,18 @@ contract CarbonController is
Strategies,
Upgradeable,
ReentrancyGuardUpgradeable,
PausableUpgradeable,
OnlyProxyDelegate,
Utils
{
// the emergency manager role is required to pause/unpause
lbeder marked this conversation as resolved.
Show resolved Hide resolved
bytes32 private constant ROLE_EMERGENCY_STOPPER = keccak256("ROLE_EMERGENCY_STOPPER");
lbeder marked this conversation as resolved.
Show resolved Hide resolved

// the fees manager role is required to withdraw fees
bytes32 private constant ROLE_FEES_MANAGER = keccak256("ROLE_FEES_MANAGER");

uint16 private constant CONTROLLER_TYPE = 1;

// deprecated parent storage vars
bool private _deprecated;
uint256[49] private __deprecated;
barakman marked this conversation as resolved.
Show resolved Hide resolved

// the voucher contract
IVoucher private immutable _voucher;

Expand Down Expand Up @@ -72,7 +71,6 @@ contract CarbonController is
__Strategies_init();
__Upgradeable_init();
__ReentrancyGuard_init();
__Pausable_init();

__CarbonController_init_unchained();
}
Expand All @@ -82,7 +80,6 @@ contract CarbonController is
*/
function __CarbonController_init_unchained() internal onlyInitializing {
// set up administrative roles
_setRoleAdmin(ROLE_EMERGENCY_STOPPER, ROLE_ADMIN);
_setRoleAdmin(ROLE_FEES_MANAGER, ROLE_ADMIN);
}

Expand All @@ -92,14 +89,7 @@ contract CarbonController is
* @inheritdoc Upgradeable
*/
function version() public pure virtual override(IVersioned, Upgradeable) returns (uint16) {
return 5;
}

/**
* @dev returns the emergency stopper role
*/
function roleEmergencyStopper() external pure returns (bytes32) {
return ROLE_EMERGENCY_STOPPER;
return 6;
}

/**
Expand Down Expand Up @@ -161,10 +151,7 @@ contract CarbonController is
/**
* @inheritdoc ICarbonController
*/
function createPair(
Token token0,
Token token1
) external nonReentrant whenNotPaused onlyProxyDelegate returns (Pair memory) {
function createPair(Token token0, Token token1) external nonReentrant onlyProxyDelegate returns (Pair memory) {
_validateInputTokens(token0, token1);
return _createPair(token0, token1);
}
Expand Down Expand Up @@ -193,7 +180,7 @@ contract CarbonController is
Token token0,
Token token1,
Order[2] calldata orders
) external payable nonReentrant whenNotPaused onlyProxyDelegate returns (uint256) {
) external payable nonReentrant onlyProxyDelegate returns (uint256) {
_validateInputTokens(token0, token1);

// don't allow unnecessary eth
Expand Down Expand Up @@ -223,7 +210,7 @@ contract CarbonController is
uint256 strategyId,
Order[2] calldata currentOrders,
Order[2] calldata newOrders
) external payable nonReentrant whenNotPaused onlyProxyDelegate {
) external payable nonReentrant onlyProxyDelegate {
Pair memory strategyPair = _pairById(_pairIdByStrategyId(strategyId));

// only the owner of the strategy is allowed to delete it
Expand All @@ -248,7 +235,7 @@ contract CarbonController is
/**
* @inheritdoc ICarbonController
*/
function deleteStrategy(uint256 strategyId) external nonReentrant whenNotPaused onlyProxyDelegate {
function deleteStrategy(uint256 strategyId) external nonReentrant onlyProxyDelegate {
// find strategy, reverts if none
Pair memory strategyPair = _pairById(_pairIdByStrategyId(strategyId));

Expand Down Expand Up @@ -303,7 +290,7 @@ contract CarbonController is
TradeAction[] calldata tradeActions,
uint256 deadline,
uint128 minReturn
) external payable nonReentrant whenNotPaused onlyProxyDelegate returns (uint128) {
) external payable nonReentrant onlyProxyDelegate returns (uint128) {
_validateTradeParams(sourceToken, targetToken, deadline, msg.value, minReturn);
Pair memory _pair = _pair(sourceToken, targetToken);
TradeParams memory params = TradeParams({
Expand All @@ -329,7 +316,7 @@ contract CarbonController is
TradeAction[] calldata tradeActions,
uint256 deadline,
uint128 maxInput
) external payable nonReentrant whenNotPaused onlyProxyDelegate returns (uint128) {
) external payable nonReentrant onlyProxyDelegate returns (uint128) {
_validateTradeParams(sourceToken, targetToken, deadline, msg.value, maxInput);

if (sourceToken.isNative()) {
Expand Down Expand Up @@ -400,7 +387,6 @@ contract CarbonController is
address recipient
)
external
whenNotPaused
onlyRoleMember(ROLE_FEES_MANAGER)
validAddress(recipient)
validAddress(Token.unwrap(token))
Expand All @@ -411,28 +397,6 @@ contract CarbonController is
return _withdrawFees(msg.sender, amount, token, recipient);
}

/**
* @dev pauses the CarbonController
*
* requirements:
*
* - the caller must have the ROLE_EMERGENCY_STOPPER privilege
*/
function pause() external onlyRoleMember(ROLE_EMERGENCY_STOPPER) {
_pause();
}

/**
* @dev resumes the CarbonController
*
* requirements:
*
* - the caller must have the ROLE_EMERGENCY_STOPPER privilege
*/
function unpause() external onlyRoleMember(ROLE_EMERGENCY_STOPPER) {
_unpause();
}

/**
* @dev validates both tokens are valid addresses and unique
*/
Expand Down
7 changes: 3 additions & 4 deletions data/named-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const TestNamedAccounts = {
...getAddress(mantle, '0xf89d7b9c864f589bbF53a82105107622B35EaA40')
},
daiWhale: {
...getAddress(mainnet, '0x1B7BAa734C00298b9429b518D621753Bb0f6efF2'),
...getAddress(mainnet, '0x66F62574ab04989737228D18C3624f7FC1edAe14'),
...getAddress(base, '0xe9b14a1Be94E70900EDdF1E22A4cB8c56aC9e10a'),
...getAddress(arbitrum, '0xd85E038593d7A098614721EaE955EC2022B9B91B'),
...getAddress(mantle, ZERO_ADDRESS)
Expand All @@ -99,7 +99,7 @@ const TestNamedAccounts = {
...getAddress(mantle, '0xa6b12425F236EE85c6E0E60df9c422C9e603cf80')
},
bntWhale: {
...getAddress(mainnet, '0x221A0e3C9AcEa6B3f1CC9DfC7063509c89bE7BC3'),
...getAddress(mainnet, '0x6cC5F688a315f3dC28A7781717a9A798a59fDA7b'),
...getAddress(mantle, ZERO_ADDRESS)
},
linkWhale: {
Expand Down Expand Up @@ -149,7 +149,7 @@ const TokenNamedAccounts = {
};

const BancorNamedAccounts = {
bancorNetworkV3: {
bancorNetworkV3: {
...getAddress(mainnet, '0xeEF417e1D5CC832e619ae18D2F140De2999dD4fB')
}
};
Expand All @@ -172,7 +172,6 @@ export const NamedAccounts = {
foundationMultisig: { ...getAddress(mainnet, '0xeBeD45Ca22fcF70AdCcAb7618C51A3Dbb06C8d83') },
foundationMultisig2: { ...getAddress(mainnet, '0x0c333d48Af19c2b42577f3C8f4779F0347F8C819') },
daoMultisig: { ...getAddress(mainnet, '0x7e3692a6d8c34a762079fa9057aed87be7e67cb8') },
daoPauserMultisig: { ...getAddress(mainnet, '0xc140c1CD2e587fC04DAa780d49b616F768476660') },

...TokenNamedAccounts,
...TestNamedAccounts,
Expand Down
22 changes: 22 additions & 0 deletions deploy/scripts/mainnet/0013-CarbonController-upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DeployedContracts, InstanceName, setDeploymentMetadata, upgradeProxy } from '../../../utils/Deploy';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

/**
* @dev remove pause functionality
*/
const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironment) => {
const { deployer } = await getNamedAccounts();
const voucher = await DeployedContracts.Voucher.deployed();

const carbonController = await DeployedContracts.CarbonController.deployed();
await upgradeProxy({
name: InstanceName.CarbonController,
from: deployer,
args: [voucher.address, carbonController.address]
});

return true;
};

export default setDeploymentMetadata(__filename, func);
7 changes: 0 additions & 7 deletions deploy/scripts/mainnet/0100-revoke-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironm
from: deployer
});

// renounce CarbonController's ROLE_EMERGENCY_STOPPER role from the deployer
await renounceRole({
name: InstanceName.CarbonController,
id: Roles.CarbonController.ROLE_EMERGENCY_STOPPER,
from: deployer
});

// renounce CarbonController's ROLE_FEES_MANAGER role from the deployer
await renounceRole({
name: InstanceName.CarbonController,
Expand Down
30 changes: 30 additions & 0 deletions deploy/tests/mainnet/0013-carbon-controller-upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CarbonController, ProxyAdmin } from '../../../components/Contracts';
import { DeployedContracts, describeDeployment } from '../../../utils/Deploy';
import { expect } from 'chai';
import { ethers } from 'hardhat';

describeDeployment(__filename, () => {
let proxyAdmin: ProxyAdmin;
let carbonController: CarbonController;

beforeEach(async () => {
proxyAdmin = await DeployedContracts.ProxyAdmin.deployed();
carbonController = await DeployedContracts.CarbonController.deployed();
});

it('should deploy and configure the carbon controller contract', async () => {
expect(await proxyAdmin.getProxyAdmin(carbonController.address)).to.equal(proxyAdmin.address);
expect(await carbonController.version()).to.equal(6);
});

it('carbon controller implementation should be initialized', async () => {
const implementationAddress = await proxyAdmin.getProxyImplementation(carbonController.address);
const carbonControllerImpl: CarbonController = await ethers.getContractAt(
'CarbonController',
implementationAddress
);
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted)
const tx = await carbonControllerImpl.initialize({ gasLimit: 6000000 });
await expect(tx.wait()).to.be.reverted;
});
});
2 changes: 0 additions & 2 deletions deploy/tests/mainnet/0100-revoke-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ describeDeployment(
expect(await voucher.hasRole(Roles.Upgradeable.ROLE_ADMIN, deployer)).to.be.false;
expect(await carbonVortex.hasRole(Roles.Upgradeable.ROLE_ADMIN, deployer)).to.be.false;

// expect deployer not to have the emergency stopper role
expect(await carbon.hasRole(Roles.CarbonController.ROLE_EMERGENCY_STOPPER, deployer)).to.be.false;
// expect deployer not to have the fee manager role
expect(await carbon.hasRole(Roles.CarbonController.ROLE_FEES_MANAGER, deployer)).to.be.false;
});
Expand Down
10 changes: 8 additions & 2 deletions deploy/tests/mainnet/carbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ import {
STRATEGY_UPDATE_REASON_TRADE,
ZERO_ADDRESS
} from '../../../utils/Constants';
import { DeployedContracts, fundAccount, getNamedSigners, isLive, runPendingDeployments } from '../../../utils/Deploy';
import {
DeployedContracts,
fundAccount,
getNamedSigners,
isTenderly,
runPendingDeployments
} from '../../../utils/Deploy';
import { NATIVE_TOKEN_ADDRESS, TokenData, TokenSymbol } from '../../../utils/TokenData';
import { toWei } from '../../../utils/Types';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
Expand All @@ -35,7 +41,7 @@ import Decimal from 'decimal.js';
import { BigNumber, BigNumberish } from 'ethers';
import { ethers, getNamedAccounts } from 'hardhat';

(isLive() ? describe : describe.skip)('network', async () => {
(isTenderly() ? describe : describe.skip)('network', async () => {
let carbonController: CarbonController;
let voucher: Voucher;
let carbonVortex: CarbonVortex;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:coverage:nightly": "NIGHTLY=1 pnpm test:coverage",
"test:nightly": "NIGHTLY=1 CI=1 forge test",
"test:deploy": "TEST_FORK=1 ./deployments/run-fork.sh HARDHAT_NETWORK=tenderly mocha --require hardhat/register --extension ts --recursive --exit --timeout 600000 --bail --no-exit 'deploy/tests/network/**/*.ts'",
"test:deploy:mainnet": "TEST_FORK=1 ./deployments/run-fork.sh HARDHAT_NETWORK=tenderly mocha --require hardhat/register --extension ts --recursive --exit --timeout 600000 --bail --no-exit 'deploy/tests/mainnet/**/*.ts'",
"test:health": "pnpm test:deploy",
"export:storage": "pnpm cleanbuild && hardhat run deployments/storage-layout.ts",
"deploy:prepare": "rm -rf ./node_modules && rm pnpm-lock.yaml && pnpm install && pnpm cleanbuild",
Expand Down
Loading
Loading