Skip to content

Commit

Permalink
Merge pull request #87 from neutiyoo/style/fmt
Browse files Browse the repository at this point in the history
style: format contract codes
  • Loading branch information
stevennevins authored Oct 15, 2024
2 parents dc6ebff + 2d84e54 commit d05341e
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 413 deletions.
268 changes: 69 additions & 199 deletions contracts/script/IncredibleSquaringDeployer.s.sol

Large diffs are not rendered by default.

70 changes: 18 additions & 52 deletions contracts/script/utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,90 +10,56 @@ 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) {
if (
operatorStatus ==
IRegistryCoordinator.OperatorStatus.NEVER_REGISTERED
) {
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
) {
} else if (operatorStatus == IRegistryCoordinator.OperatorStatus.REGISTERED) {
return "REGISTERED";
} else if (
operatorStatus == IRegistryCoordinator.OperatorStatus.DEREGISTERED
) {
} else if (operatorStatus == IRegistryCoordinator.OperatorStatus.DEREGISTERED) {
return "DEREGISTERED";
} else {
return "UNKNOWN";
}
}

// Forge scripts best practice: https://book.getfoundry.sh/tutorials/best-practices#scripts
function readInput(
string memory inputFileName
) internal view returns (string memory) {
string memory inputDir = string.concat(
vm.projectRoot(),
"/script/input/"
);
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) {
string memory inputDir = string.concat(
vm.projectRoot(),
"/script/output/"
);
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");
return vm.readFile(string.concat(inputDir, chainDir, file));
}

function writeOutput(
string memory outputJson,
string memory outputFileName
) internal {
string memory outputDir = string.concat(
vm.projectRoot(),
"/script/output/"
);
function writeOutput(string memory outputJson, string memory outputFileName) internal {
string memory outputDir = string.concat(vm.projectRoot(), "/script/output/");
string memory chainDir = string.concat(vm.toString(block.chainid), "/");
string memory outputFilePath = string.concat(
outputDir,
chainDir,
outputFileName,
".json"
);
string memory outputFilePath = string.concat(outputDir, chainDir, outputFileName, ".json");
vm.writeJson(outputJson, outputFilePath);
}
}
68 changes: 14 additions & 54 deletions contracts/src/ERC20Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ 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 @@ -69,10 +67,7 @@ contract ERC20Mock is Context, IERC20 {
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(
address to,
uint256 amount
) public virtual override returns (bool) {
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
Expand All @@ -81,10 +76,7 @@ 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 @@ -98,10 +90,7 @@ 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 @@ -121,11 +110,7 @@ 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 All @@ -144,20 +129,13 @@ contract ERC20Mock is Context, IERC20 {
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");

_beforeTokenTransfer(from, to, amount);

require(
_balances[from] >= amount,
"ERC20: transfer amount exceeds balance"
);
require(_balances[from] >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = _balances[from] - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
Expand All @@ -170,7 +148,8 @@ contract ERC20Mock is Context, IERC20 {
_afterTokenTransfer(from, to, amount);
}

/** @dev Creates `amount` tokens and assigns them to `account`, increasing
/**
* @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
Expand Down Expand Up @@ -232,11 +211,7 @@ contract ERC20Mock is Context, IERC20 {
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");

Expand All @@ -252,17 +227,10 @@ contract ERC20Mock is Context, IERC20 {
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(
currentAllowance >= amount,
"ERC20: insufficient allowance"
);
require(currentAllowance >= amount, "ERC20: insufficient allowance");
}
}

Expand All @@ -280,11 +248,7 @@ contract ERC20Mock is Context, IERC20 {
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

/**
* @dev Hook that is called after any transfer of tokens. This includes
Expand All @@ -300,9 +264,5 @@ contract ERC20Mock is Context, IERC20 {
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
24 changes: 6 additions & 18 deletions contracts/src/IIncredibleSquaringTaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@ interface IIncredibleSquaringTaskManager {
// EVENTS
event NewTaskCreated(uint32 indexed taskIndex, Task task);

event TaskResponded(
TaskResponse taskResponse,
TaskResponseMetadata taskResponseMetadata
);
event TaskResponded(TaskResponse taskResponse, TaskResponseMetadata taskResponseMetadata);

event TaskCompleted(uint32 indexed taskIndex);

event TaskChallengedSuccessfully(
uint32 indexed taskIndex,
address indexed challenger
);
event TaskChallengedSuccessfully(uint32 indexed taskIndex, address indexed challenger);

event TaskChallengedUnsuccessfully(
uint32 indexed taskIndex,
address indexed challenger
);
event TaskChallengedUnsuccessfully(uint32 indexed taskIndex, address indexed challenger);

event AggregatorUpdated(address indexed oldAggregator, address indexed newAggregator);

event GeneratorUpdated(address indexed oldGenerator, address indexed newGenerator);

// STRUCTS
Expand Down Expand Up @@ -61,11 +52,8 @@ 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
7 changes: 2 additions & 5 deletions contracts/src/IncredibleSquaringServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import "@eigenlayer-middleware/src/ServiceManagerBase.sol";
contract IncredibleSquaringServiceManager is ServiceManagerBase {
using BytesLib for bytes;

IIncredibleSquaringTaskManager
public immutable incredibleSquaringTaskManager;
IIncredibleSquaringTaskManager public immutable incredibleSquaringTaskManager;

/// @notice when applied to a function, ensures that the function is only callable by the `registryCoordinator`.
modifier onlyIncredibleSquaringTaskManager() {
Expand Down Expand Up @@ -43,9 +42,7 @@ contract IncredibleSquaringServiceManager is ServiceManagerBase {
/// @notice Called in the event of challenge resolution, in order to forward a call to the Slasher, which 'freezes' the `operator`.
/// @dev The Slasher contract is under active development and its interface expected to change.
/// We recommend writing slashing logic without integrating with the Slasher at this point in time.
function freezeOperator(
address operatorAddr
) external onlyIncredibleSquaringTaskManager {
function freezeOperator(address operatorAddr) external onlyIncredibleSquaringTaskManager {
// slasher.freezeOperator(operatorAddr);
}
}
Loading

0 comments on commit d05341e

Please sign in to comment.