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

chore(style): forge fmt and add to ci #89

Merged
merged 2 commits into from
Oct 17, 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
5 changes: 5 additions & 0 deletions .github/workflows/contracts-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ jobs:
- name: Run tests
run: forge test -vvv
working-directory: ./contracts


- name: Enforce Formatting
run: forge fmt --check
working-directory: ./contracts
13 changes: 11 additions & 2 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./"}]
fs_permissions = [{ access = "read-write", path = "./" }]

remappings = [
"@eigenlayer/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/src/",
Expand All @@ -12,7 +12,7 @@ remappings = [
"@openzeppelin/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts/",
"@openzeppelin-upgrades/=lib/eigenlayer-middleware/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable/",
"forge-std/=lib/forge-std/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/"
"ds-test/=lib/forge-std/lib/ds-test/src/",
]

gas_reports = ["*"]
Expand All @@ -28,4 +28,13 @@ via_ir = false
# Override the Solidity version (this overrides `auto_detect_solc`)
solc_version = '0.8.12'

[fmt]
bracket_spacing = false
int_types = "long"
line_length = 100
multiline_func_header = "params_first"
number_underscore = "thousands"
quote_style = "double"
tab_width = 4

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
125 changes: 91 additions & 34 deletions contracts/script/IncredibleSquaringDeployer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ import {StrategyBaseTVLLimits} from "@eigenlayer/contracts/strategies/StrategyBa
import "@eigenlayer/test/mocks/EmptyContract.sol";

import "@eigenlayer-middleware/src/RegistryCoordinator.sol" as regcoord;
import {IBLSApkRegistry, IIndexRegistry, IStakeRegistry} from "@eigenlayer-middleware/src/RegistryCoordinator.sol";
import {
IBLSApkRegistry,
IIndexRegistry,
IStakeRegistry
} from "@eigenlayer-middleware/src/RegistryCoordinator.sol";
import {BLSApkRegistry} from "@eigenlayer-middleware/src/BLSApkRegistry.sol";
import {IndexRegistry} from "@eigenlayer-middleware/src/IndexRegistry.sol";
import {StakeRegistry} from "@eigenlayer-middleware/src/StakeRegistry.sol";
import "@eigenlayer-middleware/src/OperatorStateRetriever.sol";
import {IRewardsCoordinator} from "@eigenlayer/contracts/interfaces/IRewardsCoordinator.sol";
import {IncredibleSquaringServiceManager, IServiceManager} from "../src/IncredibleSquaringServiceManager.sol";
import {
IncredibleSquaringServiceManager,
IServiceManager
} from "../src/IncredibleSquaringServiceManager.sol";
import {IncredibleSquaringTaskManager} from "../src/IncredibleSquaringTaskManager.sol";
import {IIncredibleSquaringTaskManager} from "../src/IIncredibleSquaringTaskManager.sol";
import "../src/ERC20Mock.sol";
Expand Down Expand Up @@ -73,21 +80,29 @@ contract IncredibleSquaringDeployer is Script, Utils {
function run() external {
// Eigenlayer contracts
string memory eigenlayerDeployedContracts = readOutput("eigenlayer_deployment_output");
IStrategyManager strategyManager =
IStrategyManager(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.strategyManager"));
IDelegationManager delegationManager =
IDelegationManager(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.delegation"));
IAVSDirectory avsDirectory =
IAVSDirectory(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.avsDirectory"));
ProxyAdmin eigenLayerProxyAdmin =
ProxyAdmin(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerProxyAdmin"));
PauserRegistry eigenLayerPauserReg =
PauserRegistry(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerPauserReg"));
IStrategyManager strategyManager = IStrategyManager(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.strategyManager")
);
IDelegationManager delegationManager = IDelegationManager(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.delegation")
);
IAVSDirectory avsDirectory = IAVSDirectory(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.avsDirectory")
);
ProxyAdmin eigenLayerProxyAdmin = ProxyAdmin(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerProxyAdmin")
);
PauserRegistry eigenLayerPauserReg = PauserRegistry(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.eigenLayerPauserReg")
);
StrategyBaseTVLLimits baseStrategyImplementation = StrategyBaseTVLLimits(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.baseStrategyImplementation")
stdJson.readAddress(
eigenlayerDeployedContracts, ".addresses.baseStrategyImplementation"
)
);
IRewardsCoordinator rewardsCoordinator = IRewardsCoordinator(
stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.rewardsCoordinator")
);
IRewardsCoordinator rewardsCoordinator =
IRewardsCoordinator(stdJson.readAddress(eigenlayerDeployedContracts, ".addresses.rewardsCoordinator"));

address credibleSquaringCommunityMultisig = msg.sender;
address credibleSquaringPauser = msg.sender;
Expand Down Expand Up @@ -159,7 +174,8 @@ contract IncredibleSquaringDeployer is Script, Utils {
address[] memory pausers = new address[](2);
pausers[0] = credibleSquaringPauser;
pausers[1] = incredibleSquaringCommunityMultisig;
incredibleSquaringPauserReg = new PauserRegistry(pausers, incredibleSquaringCommunityMultisig);
incredibleSquaringPauserReg =
new PauserRegistry(pausers, incredibleSquaringCommunityMultisig);
}

EmptyContract emptyContract = new EmptyContract();
Expand All @@ -171,22 +187,46 @@ contract IncredibleSquaringDeployer is Script, Utils {
* not yet deployed, we give these proxies an empty contract as the initial implementation, to act as if they have no code.
*/
incredibleSquaringServiceManager = IncredibleSquaringServiceManager(
address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), ""))
address(
new TransparentUpgradeableProxy(
address(emptyContract), address(incredibleSquaringProxyAdmin), ""
)
)
);
incredibleSquaringTaskManager = IncredibleSquaringTaskManager(
address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), ""))
address(
new TransparentUpgradeableProxy(
address(emptyContract), address(incredibleSquaringProxyAdmin), ""
)
)
);
registryCoordinator = regcoord.RegistryCoordinator(
address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), ""))
address(
new TransparentUpgradeableProxy(
address(emptyContract), address(incredibleSquaringProxyAdmin), ""
)
)
);
blsApkRegistry = IBLSApkRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), ""))
address(
new TransparentUpgradeableProxy(
address(emptyContract), address(incredibleSquaringProxyAdmin), ""
)
)
);
indexRegistry = IIndexRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), ""))
address(
new TransparentUpgradeableProxy(
address(emptyContract), address(incredibleSquaringProxyAdmin), ""
)
)
);
stakeRegistry = IStakeRegistry(
address(new TransparentUpgradeableProxy(address(emptyContract), address(incredibleSquaringProxyAdmin), ""))
address(
new TransparentUpgradeableProxy(
address(emptyContract), address(incredibleSquaringProxyAdmin), ""
)
)
);

operatorStateRetriever = new OperatorStateRetriever();
Expand All @@ -196,19 +236,22 @@ contract IncredibleSquaringDeployer is Script, Utils {
stakeRegistryImplementation = new StakeRegistry(registryCoordinator, delegationManager);

incredibleSquaringProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(stakeRegistry))), address(stakeRegistryImplementation)
TransparentUpgradeableProxy(payable(address(stakeRegistry))),
address(stakeRegistryImplementation)
);

blsApkRegistryImplementation = new BLSApkRegistry(registryCoordinator);

incredibleSquaringProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(blsApkRegistry))), address(blsApkRegistryImplementation)
TransparentUpgradeableProxy(payable(address(blsApkRegistry))),
address(blsApkRegistryImplementation)
);

indexRegistryImplementation = new IndexRegistry(registryCoordinator);

incredibleSquaringProxyAdmin.upgrade(
TransparentUpgradeableProxy(payable(address(indexRegistry))), address(indexRegistryImplementation)
TransparentUpgradeableProxy(payable(address(indexRegistry))),
address(indexRegistryImplementation)
);
}

Expand All @@ -228,8 +271,8 @@ contract IncredibleSquaringDeployer is Script, Utils {
for (uint256 i = 0; i < numQuorums; i++) {
// hard code these for now
quorumsOperatorSetParams[i] = regcoord.IRegistryCoordinator.OperatorSetParam({
maxOperatorCount: 10000,
kickBIPsOfOperatorStake: 15000,
maxOperatorCount: 10_000,
kickBIPsOfOperatorStake: 15_000,
kickBIPsOfTotalStake: 100
});
}
Expand Down Expand Up @@ -269,7 +312,11 @@ contract IncredibleSquaringDeployer is Script, Utils {
}

incredibleSquaringServiceManagerImplementation = new IncredibleSquaringServiceManager(
avsDirectory, rewardsCoordinator, registryCoordinator, stakeRegistry, incredibleSquaringTaskManager
avsDirectory,
rewardsCoordinator,
registryCoordinator,
stakeRegistry,
incredibleSquaringTaskManager
);
// Third, upgrade the proxy contracts to use the correct implementation contracts and initialize them.
incredibleSquaringProxyAdmin.upgrade(
Expand Down Expand Up @@ -300,28 +347,38 @@ contract IncredibleSquaringDeployer is Script, Utils {
vm.serializeAddress(deployed_addresses, "erc20Mock", address(erc20Mock));
vm.serializeAddress(deployed_addresses, "erc20MockStrategy", address(erc20MockStrategy));
vm.serializeAddress(
deployed_addresses, "credibleSquaringServiceManager", address(incredibleSquaringServiceManager)
deployed_addresses,
"credibleSquaringServiceManager",
address(incredibleSquaringServiceManager)
);
vm.serializeAddress(
deployed_addresses,
"credibleSquaringServiceManagerImplementation",
address(incredibleSquaringServiceManagerImplementation)
);
vm.serializeAddress(deployed_addresses, "credibleSquaringTaskManager", address(incredibleSquaringTaskManager));
vm.serializeAddress(
deployed_addresses,
"credibleSquaringTaskManager",
address(incredibleSquaringTaskManager)
);
vm.serializeAddress(
deployed_addresses,
"credibleSquaringTaskManagerImplementation",
address(incredibleSquaringTaskManagerImplementation)
);
vm.serializeAddress(deployed_addresses, "registryCoordinator", address(registryCoordinator));
vm.serializeAddress(
deployed_addresses, "registryCoordinatorImplementation", address(registryCoordinatorImplementation)
deployed_addresses,
"registryCoordinatorImplementation",
address(registryCoordinatorImplementation)
);
string memory deployed_addresses_output = vm.serializeAddress(
deployed_addresses, "operatorStateRetriever", address(operatorStateRetriever)
);
string memory deployed_addresses_output =
vm.serializeAddress(deployed_addresses, "operatorStateRetriever", address(operatorStateRetriever));

// serialize all the data
string memory finalJson = vm.serializeString(parent_object, deployed_addresses, deployed_addresses_output);
string memory finalJson =
vm.serializeString(parent_object, deployed_addresses, deployed_addresses_output);

writeOutput(finalJson, "credible_squaring_avs_deployment_output");
}
Expand Down
29 changes: 19 additions & 10 deletions contracts/script/utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ import "forge-std/StdJson.sol";

contract Utils is Script {
// Note that this fct will only work for the ERC20Mock that has a public mint function
function _mintTokens(address strategyAddress, address[] memory tos, uint256[] memory amounts) internal {
function _mintTokens(
address strategyAddress,
address[] memory tos,
uint256[] memory amounts
) internal {
for (uint256 i = 0; i < tos.length; i++) {
ERC20Mock underlyingToken = ERC20Mock(address(StrategyBase(strategyAddress).underlyingToken()));
ERC20Mock underlyingToken =
ERC20Mock(address(StrategyBase(strategyAddress).underlyingToken()));
underlyingToken.mint(tos[i], amounts[i]);
}
}

function convertBoolToString(bool input) public pure returns (string memory) {
function convertBoolToString(
bool input
) public pure returns (string memory) {
if (input) {
return "true";
} else {
return "false";
}
}

function convertOperatorStatusToString(IRegistryCoordinator.OperatorStatus operatorStatus)
public
pure
returns (string memory)
{
function convertOperatorStatusToString(
IRegistryCoordinator.OperatorStatus operatorStatus
) public pure returns (string memory) {
if (operatorStatus == IRegistryCoordinator.OperatorStatus.NEVER_REGISTERED) {
return "NEVER_REGISTERED";
} else if (operatorStatus == IRegistryCoordinator.OperatorStatus.REGISTERED) {
Expand All @@ -42,14 +47,18 @@ contract Utils is Script {
}

// Forge scripts best practice: https://book.getfoundry.sh/tutorials/best-practices#scripts
function readInput(string memory inputFileName) internal view returns (string memory) {
function readInput(
string memory inputFileName
) internal view returns (string memory) {
string memory inputDir = string.concat(vm.projectRoot(), "/script/input/");
string memory chainDir = string.concat(vm.toString(block.chainid), "/");
string memory file = string.concat(inputFileName, ".json");
return vm.readFile(string.concat(inputDir, chainDir, file));
}

function readOutput(string memory outputFileName) internal view returns (string memory) {
function readOutput(
string memory outputFileName
) internal view returns (string memory) {
string memory inputDir = string.concat(vm.projectRoot(), "/script/output/");
string memory chainDir = string.concat(vm.toString(block.chainid), "/");
string memory file = string.concat(outputFileName, ".json");
Expand Down
20 changes: 16 additions & 4 deletions contracts/src/ERC20Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ contract ERC20Mock is Context, IERC20 {
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
function balanceOf(
address account
) public view virtual override returns (uint256) {
return _balances[account];
}

Expand All @@ -76,7 +78,10 @@ contract ERC20Mock is Context, IERC20 {
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
function allowance(
address owner,
address spender
) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}

Expand All @@ -90,7 +95,10 @@ contract ERC20Mock is Context, IERC20 {
*
* - `spender` cannot be the zero address.
*/
function approve(address, /*spender*/ uint256 /*amount*/ ) public virtual override returns (bool) {
function approve(
address, /*spender*/
uint256 /*amount*/
) public virtual override returns (bool) {
return true;
}

Expand All @@ -110,7 +118,11 @@ contract ERC20Mock is Context, IERC20 {
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
_transfer(from, to, amount);
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/src/IIncredibleSquaringTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ interface IIncredibleSquaringTaskManager {

// FUNCTIONS
// NOTE: this function creates new task.
function createNewTask(uint256 numberToBeSquared, uint32 quorumThresholdPercentage, bytes calldata quorumNumbers)
external;
function createNewTask(
uint256 numberToBeSquared,
uint32 quorumThresholdPercentage,
bytes calldata quorumNumbers
) external;

/// @notice Returns the current 'taskNumber' for the middleware
function taskNumber() external view returns (uint32);
Expand Down
Loading
Loading