Skip to content

Commit

Permalink
Add contract upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Oct 20, 2023
1 parent a447fa7 commit 7ad2134
Show file tree
Hide file tree
Showing 38 changed files with 3,198 additions and 23 deletions.
2 changes: 1 addition & 1 deletion common/env/src/mock/validators.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/ethereum/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void async function () {
await functionsOracle.addAuthorizedSenders([donTransmitter.address, managerAddress])

const ssvViews = await ethers.getContractAt(ISSVViewsAbi, process.env.SSV_VIEWS_ADDRESS as string) as ISSVViews
const preregisteredOperatorIds = process.env.PREREGISTERED_OPERATOR_IDS?.split(',').map(id => parseInt(id)) || [208, 209, 210, 211, 212, 213, 214, 215]
const preregisteredOperatorIds = process.env.PREREGISTERED_OPERATOR_IDS?.split(',').map(id => parseInt(id)) || [208, 209, 210, 211/*, 212, 213, 214, 215*/]
if (preregisteredOperatorIds.length < 4) throw new Error('Not enough operator ids provided')
const preregisteredBalance = ethers.utils.parseEther('10')
for (const operatorId of preregisteredOperatorIds) {
Expand Down
14 changes: 14 additions & 0 deletions contracts/ethereum/src/v1/dev/CasimirCore.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache
pragma solidity 0.8.18;

import "./interfaces/ICasimirCore.sol";

/// @title Core shared methods
abstract contract CasimirCoreDev is ICasimirCoreDev {
/// @dev Validate an address is not the zero address
function onlyAddress(address checkAddress) internal pure {
if (checkAddress == address(0)) {
revert InvalidAddress();
}
}
}
143 changes: 143 additions & 0 deletions contracts/ethereum/src/v1/dev/CasimirFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// SPDX-License-Identifier: Apache
pragma solidity 0.8.18;

import "./CasimirCore.sol";
import "./interfaces/ICasimirFactory.sol";
import "./interfaces/ICasimirManager.sol";
import "./interfaces/ICasimirRegistry.sol";
import "./interfaces/ICasimirUpkeep.sol";
import "./libraries/CasimirBeacon.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

/// @title Factory that deploys and configures managers
contract CasimirFactoryDev is ICasimirFactoryDev, CasimirCoreDev, Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
/**
* @inheritdoc ICasimirFactoryDev
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
address public immutable managerBeaconAddress;
/**
* @inheritdoc ICasimirFactoryDev
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
address public immutable poolBeaconAddress;
/**
* @inheritdoc ICasimirFactoryDev
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
address public immutable registryBeaconAddress;
/**
* @inheritdoc ICasimirFactoryDev
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
address public immutable upkeepBeaconAddress;
/**
* @inheritdoc ICasimirFactoryDev
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
address public immutable viewsBeaconAddress;
/// @dev Deployed manager addresses
mapping(uint32 => address) private managerAddresses;
/// @dev Deployed views addresses
mapping(uint32 => address) private viewsAddresses;
/// @dev Last manager ID
uint32 private lastManagerId;
/// @dev Storage gap
uint256[50] private __gap;

/**
* @dev Constructor
* @param managerBeaconAddress_ Manager beacon address
* @param poolBeaconAddress_ Pool beacon address
* @param registryBeaconAddress_ Registry beacon address
* @param upkeepBeaconAddress_ Upkeep beacon address
* @param viewsBeaconAddress_ Views beacon address
* @custom:oz-upgrades-unsafe-allow constructor
*/
constructor(
address managerBeaconAddress_,
address poolBeaconAddress_,
address registryBeaconAddress_,
address upkeepBeaconAddress_,
address viewsBeaconAddress_
) {
onlyAddress(managerBeaconAddress_);
onlyAddress(poolBeaconAddress_);
onlyAddress(registryBeaconAddress_);
onlyAddress(upkeepBeaconAddress_);
onlyAddress(viewsBeaconAddress_);
managerBeaconAddress = managerBeaconAddress_;
poolBeaconAddress = poolBeaconAddress_;
registryBeaconAddress = registryBeaconAddress_;
upkeepBeaconAddress = upkeepBeaconAddress_;
viewsBeaconAddress = viewsBeaconAddress_;
_disableInitializers();
}

/**
* @notice Initialize the contract
*/
function initialize() public initializer {
__Ownable_init();
__ReentrancyGuard_init();
}

/// @inheritdoc ICasimirFactoryDev
function deployManager(
address daoOracleAddress,
address functionsOracleAddress,
Strategy memory strategy
) external onlyOwner {
onlyAddress(daoOracleAddress);
onlyAddress(functionsOracleAddress);
managerAddresses[++lastManagerId] = CasimirBeaconDev.createManager(
managerBeaconAddress,
daoOracleAddress,
functionsOracleAddress,
strategy
);
ICasimirManagerDev manager = ICasimirManagerDev(managerAddresses[lastManagerId]);
viewsAddresses[lastManagerId] = CasimirBeaconDev.createViews(viewsBeaconAddress, address(manager));
emit ManagerDeployed(lastManagerId);
}

/// @inheritdoc ICasimirFactoryDev
function getManagerConfig(uint32 managerId) external view returns (ManagerConfig memory) {
ICasimirManagerDev manager = ICasimirManagerDev(managerAddresses[managerId]);
ICasimirRegistryDev registry = ICasimirRegistryDev(manager.getRegistryAddress());
ICasimirUpkeepDev upkeep = ICasimirUpkeepDev(manager.getUpkeepAddress());
return
ManagerConfig({
managerAddress: managerAddresses[managerId],
registryAddress: address(registry),
upkeepAddress: address(upkeep),
viewsAddress: viewsAddresses[managerId],
strategy: Strategy({
minCollateral: registry.minCollateral(),
lockPeriod: manager.lockPeriod(),
userFee: manager.userFee(),
compoundStake: upkeep.compoundStake(),
eigenStake: manager.eigenStake(),
liquidStake: manager.liquidStake(),
privateOperators: registry.privateOperators(),
verifiedOperators: registry.verifiedOperators()
})
});
}

/// @inheritdoc ICasimirFactoryDev
function getManagerIds() external view returns (uint32[] memory) {
uint32[] memory managerIds = new uint32[](lastManagerId);
for (uint32 i; i < lastManagerId; i++) {
managerIds[i] = i + 1;
}
return managerIds;
}

/// @inheritdoc ICasimirFactoryDev
function getOwner() external view returns (address) {
return owner();
}
}
Loading

0 comments on commit 7ad2134

Please sign in to comment.