Skip to content

Commit

Permalink
fix: lint the code
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Feb 7, 2025
1 parent 4cb87fb commit 7d9a98b
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
lib
broadcast
cache
out
node_modules
zkout
48 changes: 23 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@ All notable changes to this project will be documented in this file. See [standa

## 1.1.0 (2022-11-15)


### Features

* add ierc20 with permit ([1093eaa](https://github.com/bgd-labs/solidity-utils/commit/1093eaa8c7ee3a605d1935da3b115e97960a61aa))
* added emergency consumer logic ([23a0c85](https://github.com/bgd-labs/solidity-utils/commit/23a0c855ac8a599b0bc3ea34fcebb134994b6aa2))
* added IERC20 and SafeERC20 oz contracts ([ba4d85f](https://github.com/bgd-labs/solidity-utils/commit/ba4d85f14cc2cf94e403c56395cda5e705877b38))
* added IERC20Metadata interface ([3afcba2](https://github.com/bgd-labs/solidity-utils/commit/3afcba2a81dc916f18c3411eb0329ee40d6b5f41))
* added test workflow ([03028a7](https://github.com/bgd-labs/solidity-utils/commit/03028a7b6fc1b94eeafbb828bbcff23b9266542d))
* deploy on npm ([#11](https://github.com/bgd-labs/solidity-utils/issues/11)) ([0bece64](https://github.com/bgd-labs/solidity-utils/commit/0bece649ec134950634b80b255772a0eacab7746))

- add ierc20 with permit ([1093eaa](https://github.com/bgd-labs/solidity-utils/commit/1093eaa8c7ee3a605d1935da3b115e97960a61aa))
- added emergency consumer logic ([23a0c85](https://github.com/bgd-labs/solidity-utils/commit/23a0c855ac8a599b0bc3ea34fcebb134994b6aa2))
- added IERC20 and SafeERC20 oz contracts ([ba4d85f](https://github.com/bgd-labs/solidity-utils/commit/ba4d85f14cc2cf94e403c56395cda5e705877b38))
- added IERC20Metadata interface ([3afcba2](https://github.com/bgd-labs/solidity-utils/commit/3afcba2a81dc916f18c3411eb0329ee40d6b5f41))
- added test workflow ([03028a7](https://github.com/bgd-labs/solidity-utils/commit/03028a7b6fc1b94eeafbb828bbcff23b9266542d))
- deploy on npm ([#11](https://github.com/bgd-labs/solidity-utils/issues/11)) ([0bece64](https://github.com/bgd-labs/solidity-utils/commit/0bece649ec134950634b80b255772a0eacab7746))

### Bug Fixes

* add 20 to filename to be consistent ([0c5a8b8](https://github.com/bgd-labs/solidity-utils/commit/0c5a8b894b6bd9e434c9e8b5b355469c6c306228))
* add indexed to few fields on events ([7a6fd00](https://github.com/bgd-labs/solidity-utils/commit/7a6fd00a06def5fdbc33cb0759efd18f5865500a))
* add lockfile ([6d07157](https://github.com/bgd-labs/solidity-utils/commit/6d071575f3085c4f45d084429a6bced227a155c6))
* add natspec for cl oracle interface ([ee1fcfd](https://github.com/bgd-labs/solidity-utils/commit/ee1fcfde4b47426e2370bbc54ce3e365b1cae7bb))
* added deterministic method to create proxy, also creating admin and transfering ownership of deployed admin to specified address ([37a0f96](https://github.com/bgd-labs/solidity-utils/commit/37a0f967166bbe893a810c7b2014c939e1ad72ac))
* added deterministic proxy admin ([23892f3](https://github.com/bgd-labs/solidity-utils/commit/23892f362de15e1cad1166fd881b159fa463bd15))
* added predictive proxy admin deployment ([b18f754](https://github.com/bgd-labs/solidity-utils/commit/b18f754af61d65ab6951dfb4f5418ff67e0f740e))
* added solved event ([82832ba](https://github.com/bgd-labs/solidity-utils/commit/82832baf8cc3d289a69dba57039a7f7fc38902c4))
* **ci:** better triggers ([c097977](https://github.com/bgd-labs/solidity-utils/commit/c09797758e76103f41840c8ecc7acb5e142bfa18))
* fixed imports ([f3bbb92](https://github.com/bgd-labs/solidity-utils/commit/f3bbb92d2420ebadcfbc9bf68ec239849f52e0ac))
* removed comments ([eca9e94](https://github.com/bgd-labs/solidity-utils/commit/eca9e94ba34c53743ab650255787bddf1cb27316))
* removed highly recomended ([394dbce](https://github.com/bgd-labs/solidity-utils/commit/394dbce5f078bb363deb6617469a285f090a2e31))
* removed highly recomended from all comments ([3a5bdf3](https://github.com/bgd-labs/solidity-utils/commit/3a5bdf34dc764136f2154993482877574dd26805))
* removed mock contract ([e266d70](https://github.com/bgd-labs/solidity-utils/commit/e266d708c969f59ebff052156692ce058819c0e3))
* updated docs ([d07d705](https://github.com/bgd-labs/solidity-utils/commit/d07d705d83d7bae0511b53b46fa1b1bbca0c22cb))
* updated tests ([8570de9](https://github.com/bgd-labs/solidity-utils/commit/8570de9e6aa7868ea277dc1627da745c3add4e10))
* updated with virtual update method, and moved solve emergency to modifier ([1a86eb3](https://github.com/bgd-labs/solidity-utils/commit/1a86eb3fcc65e267ff67bb72888eb65a35f83542))
- add 20 to filename to be consistent ([0c5a8b8](https://github.com/bgd-labs/solidity-utils/commit/0c5a8b894b6bd9e434c9e8b5b355469c6c306228))
- add indexed to few fields on events ([7a6fd00](https://github.com/bgd-labs/solidity-utils/commit/7a6fd00a06def5fdbc33cb0759efd18f5865500a))
- add lockfile ([6d07157](https://github.com/bgd-labs/solidity-utils/commit/6d071575f3085c4f45d084429a6bced227a155c6))
- add natspec for cl oracle interface ([ee1fcfd](https://github.com/bgd-labs/solidity-utils/commit/ee1fcfde4b47426e2370bbc54ce3e365b1cae7bb))
- added deterministic method to create proxy, also creating admin and transfering ownership of deployed admin to specified address ([37a0f96](https://github.com/bgd-labs/solidity-utils/commit/37a0f967166bbe893a810c7b2014c939e1ad72ac))
- added deterministic proxy admin ([23892f3](https://github.com/bgd-labs/solidity-utils/commit/23892f362de15e1cad1166fd881b159fa463bd15))
- added predictive proxy admin deployment ([b18f754](https://github.com/bgd-labs/solidity-utils/commit/b18f754af61d65ab6951dfb4f5418ff67e0f740e))
- added solved event ([82832ba](https://github.com/bgd-labs/solidity-utils/commit/82832baf8cc3d289a69dba57039a7f7fc38902c4))
- **ci:** better triggers ([c097977](https://github.com/bgd-labs/solidity-utils/commit/c09797758e76103f41840c8ecc7acb5e142bfa18))
- fixed imports ([f3bbb92](https://github.com/bgd-labs/solidity-utils/commit/f3bbb92d2420ebadcfbc9bf68ec239849f52e0ac))
- removed comments ([eca9e94](https://github.com/bgd-labs/solidity-utils/commit/eca9e94ba34c53743ab650255787bddf1cb27316))
- removed highly recomended ([394dbce](https://github.com/bgd-labs/solidity-utils/commit/394dbce5f078bb363deb6617469a285f090a2e31))
- removed highly recomended from all comments ([3a5bdf3](https://github.com/bgd-labs/solidity-utils/commit/3a5bdf34dc764136f2154993482877574dd26805))
- removed mock contract ([e266d70](https://github.com/bgd-labs/solidity-utils/commit/e266d708c969f59ebff052156692ce058819c0e3))
- updated docs ([d07d705](https://github.com/bgd-labs/solidity-utils/commit/d07d705d83d7bae0511b53b46fa1b1bbca0c22cb))
- updated tests ([8570de9](https://github.com/bgd-labs/solidity-utils/commit/8570de9e6aa7868ea277dc1627da745c3add4e10))
- updated with virtual update method, and moved solve emergency to modifier ([1a86eb3](https://github.com/bgd-labs/solidity-utils/commit/1a86eb3fcc65e267ff67bb72888eb65a35f83542))
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

Common contracts we use almost everywhere


## Create3

Contracts to deploy a Create3 Factory which so that contract addresses can be predicted without influence from
constructor arguments.

These contracts where modified from:

- Create3 lib:
Modified from https://github.com/0xsequence/create3/blob/5a4a152e6be4e0ecfbbbe546992a5aaa43a4c1b0/contracts/Create3.sol by Agustin Aguilar <[email protected]>
Modified from https://github.com/0xsequence/create3/blob/5a4a152e6be4e0ecfbbbe546992a5aaa43a4c1b0/contracts/Create3.sol by Agustin Aguilar <[email protected]>
- Modifications consist on:
- removal of named returns
- moved logic of addressOf method to addressOfWithPreDeployedFactory so that factory address can be abstracted
- Create3Factory:
Modified from https://github.com/lifinance/create3-factory/blob/main/src/CREATE3Factory.sol
Modified from https://github.com/lifinance/create3-factory/blob/main/src/CREATE3Factory.sol
- Modifications consist on:
- removal of named returns
- changed name of getDeployed for predictAddress
Expand All @@ -29,7 +30,9 @@ as expected.
- Tests specific for ZkSync network can be found [here](test-zksync)

To build and test the contracts use `FOUNDRY_PROFILE=zksync` and the flag `--zksync`

- Example:

```solidity
FOUNDRY_PROFILE=zksync forge test -vvv --zksync
```
2 changes: 1 addition & 1 deletion script/DeployCreate3Factory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.0;

import {Script} from 'forge-std/Script.sol';
import {TransparentProxyFactory} from '../src/contracts/transparent-proxy/TransparentProxyFactory.sol';
import {Create3Factory} from "../src/contracts/create3/Create3Factory.sol";
import {Create3Factory} from '../src/contracts/create3/Create3Factory.sol';

contract DeployCreate3Factory is Script {
bytes32 public constant CREATE3_FACTORY_SALT = keccak256(bytes('Create3 Factory'));
Expand Down
28 changes: 5 additions & 23 deletions src/contracts/create3/Create3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
/**
* @title A library for deploying contracts EIP-3171 style.
* @author BGD Labs
*/
*/
library Create3 {
error ErrorCreatingProxy();
error ErrorCreatingContract();
Expand Down Expand Up @@ -59,10 +59,7 @@ library Create3 {
* @param creationCode Creation code (constructor) of the contract to be deployed, this value doesn't affect the resulting address
* @return address of the deployed contract, reverts on error
*/
function create3(
bytes32 salt,
bytes memory creationCode
) internal returns (address) {
function create3(bytes32 salt, bytes memory creationCode) internal returns (address) {
return create3(salt, creationCode, 0);
}

Expand All @@ -88,12 +85,7 @@ library Create3 {
// Create CREATE2 proxy
address proxy;
assembly {
proxy := create2(
value,
add(proxyCreationCode, 32),
mload(proxyCreationCode),
salt
)
proxy := create2(value, add(proxyCreationCode, 32), mload(proxyCreationCode), salt)
}
if (proxy == address(0)) revert ErrorCreatingProxy();

Expand Down Expand Up @@ -128,22 +120,12 @@ library Create3 {
uint160(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
preDeployedFactory,
salt,
KECCAK256_PROXY_CHILD_BYTECODE
)
abi.encodePacked(hex'ff', preDeployedFactory, salt, KECCAK256_PROXY_CHILD_BYTECODE)
)
)
)
);

return
address(
uint160(
uint256(keccak256(abi.encodePacked(hex'd6_94', proxy, hex'01')))
)
);
return address(uint160(uint256(keccak256(abi.encodePacked(hex'd6_94', proxy, hex'01')))));
}
}
18 changes: 6 additions & 12 deletions src/contracts/create3/Create3Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@ import {Create3} from './Create3.sol';
import {ICreate3Factory} from './interfaces/ICreate3Factory.sol';

/**
* @title Factory for deploying contracts to deterministic addresses via Create3
* @author BGD Labs
* @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has its own namespace for deployed addresses.
*/
* @title Factory for deploying contracts to deterministic addresses via Create3
* @author BGD Labs
* @notice Enables deploying contracts using CREATE3. Each deployer (msg.sender) has its own namespace for deployed addresses.
*/
contract Create3Factory is ICreate3Factory {
/// @inheritdoc ICreate3Factory
function create(
bytes32 salt,
bytes memory creationCode
) external payable returns (address) {
function create(bytes32 salt, bytes memory creationCode) external payable returns (address) {
// hash salt with the deployer address to give each deployer its own namespace
salt = keccak256(abi.encodePacked(msg.sender, salt));
return Create3.create3(salt, creationCode, msg.value);
}

/// @inheritdoc ICreate3Factory
function predictAddress(
address deployer,
bytes32 salt
) external view returns (address) {
function predictAddress(address deployer, bytes32 salt) external view returns (address) {
// hash salt with the deployer address to give each deployer its own namespace
salt = keccak256(abi.encodePacked(deployer, salt));
return Create3.addressOf(salt);
Expand Down
10 changes: 2 additions & 8 deletions src/contracts/create3/interfaces/ICreate3Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ interface ICreate3Factory {
* @param creationCode The creation code of the contract to deploy
* @return The address of the deployed contract
*/
function create(
bytes32 salt,
bytes memory creationCode
) external payable returns (address);
function create(bytes32 salt, bytes memory creationCode) external payable returns (address);

/**
* @notice Predicts the address of a deployed contract
Expand All @@ -27,8 +24,5 @@ interface ICreate3Factory {
* @param salt The deployer-specific salt for determining the deployed contract's address
* @return The address of the contract that will be deployed
*/
function predictAddress(
address deployer,
bytes32 salt
) external view returns (address);
function predictAddress(address deployer, bytes32 salt) external view returns (address);
}
1 change: 0 additions & 1 deletion src/contracts/utils/Rescuable721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {Rescuable} from './Rescuable.sol';
* @notice abstract contract that extend Rescuable with the methods to rescue ERC721 tokens from a contract
*/
abstract contract Rescuable721 is Rescuable, IRescuable721 {

/// @inheritdoc IRescuable721
function emergency721TokenTransfer(
address erc721Token,
Expand Down
30 changes: 17 additions & 13 deletions zksync/src/contracts/utils/ScriptUtilsZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ library Create2UtilsZkSync {
address public constant CREATE2_FACTORY = 0x0000000000000000000000000000000000010000;

// @dev the bytecodeHash is the unsanitized input we get via `type(Contract).creationCode`
function create2Deploy(bytes32 salt, bytes memory bytecodeHash, bytes memory arguments) internal returns (address) {
function create2Deploy(
bytes32 salt,
bytes memory bytecodeHash,
bytes memory arguments
) internal returns (address) {
return create2Deploy(salt, bytes32(sliceBytes(bytecodeHash, 36, 32)), arguments);
}

Expand All @@ -30,11 +34,7 @@ library Create2UtilsZkSync {
if (isContractDeployed(computed)) {
return computed;
} else {
address deployedAt = ICreate2Factory(CREATE2_FACTORY).create2(
salt,
bytecodeHash,
arguments
);
address deployedAt = ICreate2Factory(CREATE2_FACTORY).create2(salt, bytecodeHash, arguments);

require(deployedAt == computed, 'failure at create2 address derivation');
return deployedAt;
Expand All @@ -50,11 +50,7 @@ library Create2UtilsZkSync {
if (isContractDeployed(computed)) {
return computed;
} else {
address deployedAt = ICreate2Factory(CREATE2_FACTORY).create2(
salt,
bytecodeHash,
''
);
address deployedAt = ICreate2Factory(CREATE2_FACTORY).create2(salt, bytecodeHash, '');

require(deployedAt == computed, 'failure at create2 address derivation');
return deployedAt;
Expand Down Expand Up @@ -90,7 +86,11 @@ library Create2UtilsZkSync {
return (_addr.code.length > 0);
}

function sliceBytes(bytes memory data, uint256 start, uint256 length) internal pure returns (bytes memory) {
function sliceBytes(
bytes memory data,
uint256 start,
uint256 length
) internal pure returns (bytes memory) {
require(start + length <= data.length, 'Slice out of bounds');
bytes memory result = new bytes(length);

Expand All @@ -102,7 +102,11 @@ library Create2UtilsZkSync {
let words := div(add(length, 31), 32)
let srcPtr := add(dataPtr, start)

for { let i := 0 } lt(i, words) { i := add(i, 1) } {
for {
let i := 0
} lt(i, words) {
i := add(i, 1)
} {
mstore(add(resultPtr, mul(i, 32)), mload(add(srcPtr, mul(i, 32))))
}

Expand Down

0 comments on commit 7d9a98b

Please sign in to comment.