Skip to content

Commit 65c38aa

Browse files
committed
format with prettier
1 parent acb8fef commit 65c38aa

28 files changed

+993
-830
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import '@solidstate/contracts/token/ERC20/ERC20Base.sol';
2929
contract CustomToken is ERC20Base {
3030
// custom code...
3131
}
32+
3233
```
3334

3435
Rather than rewrite the `ERC20Base` tests or assume that all core behavior remains untouched, one can import the included tests and run them against the custom implementation:

contracts/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ yarn add --dev @solidstate/contracts
1414

1515
## Layout
1616

17-
SolidState maintains "recommended" implementations of various EIP standards, which are suitable for most users. Internally, these implementations may be composed of several modules, which themselves may be composed of several visibility layers. Layers are subject to a consistent naming convention so that their purposes may be easily identified.
17+
SolidState maintains "recommended" implementations of various EIP standards, which are suitable for most users. Internally, these implementations may be composed of several modules, which themselves may be composed of several visibility layers. Layers are subject to a consistent naming convention so that their purposes may be easily identified.
1818

19-
For example, the `ERC20` contract contains `ERC20Base`, `ERC20Extended` and `ERC20Metadata` modules. The `ERC20Base` module is composed of the external functions specified by the `IERC20` interface, `ERC20BaseInternal`, and `ERC20BaseStorage`.
19+
For example, the `ERC20` contract contains `ERC20Base`, `ERC20Extended` and `ERC20Metadata` modules. The `ERC20Base` module is composed of the external functions specified by the `IERC20` interface, `ERC20BaseInternal`, and `ERC20BaseStorage`.
2020

2121
An overview of the uses of each visibility layer is as follows:
2222

23-
| layer | contents | description | example |
24-
|-|-|-|-|
25-
| `external` | external and public functions | set of functions that constitute a module's external interface; useful for most common situations | `ERC20Base.sol` |
26-
| `internal` | internal functions, events | set of internal functions that define a module's core logic; may be called by inheriting contracts | `ERC20BaseInternal.sol` |
27-
| `storage` | internal library functions, structs | library for accessing and modifying storage; useful when sharing access to storage between implementation contracts that will be deployed separately (such as in the "diamond" proxy architecture) | `ERC20BaseStorage.sol` |
23+
| layer | contents | description | example |
24+
| ---------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
25+
| `external` | external and public functions | set of functions that constitute a module's external interface; useful for most common situations | `ERC20Base.sol` |
26+
| `internal` | internal functions, events | set of internal functions that define a module's core logic; may be called by inheriting contracts | `ERC20BaseInternal.sol` |
27+
| `storage` | internal library functions, structs | library for accessing and modifying storage; useful when sharing access to storage between implementation contracts that will be deployed separately (such as in the "diamond" proxy architecture) | `ERC20BaseStorage.sol` |

contracts/access/OwnableInternal.sol

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {OwnableStorage} from './OwnableStorage.sol';
5+
import { OwnableStorage } from './OwnableStorage.sol';
66

77
abstract contract OwnableInternal {
8-
using OwnableStorage for OwnableStorage.Layout;
8+
using OwnableStorage for OwnableStorage.Layout;
99

10-
modifier onlyOwner {
11-
require(
12-
msg.sender == OwnableStorage.layout().owner,
13-
'Ownable: sender must be owner'
14-
);
15-
_;
16-
}
10+
modifier onlyOwner() {
11+
require(
12+
msg.sender == OwnableStorage.layout().owner,
13+
'Ownable: sender must be owner'
14+
);
15+
_;
16+
}
1717
}

contracts/access/OwnableMock.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {Ownable, OwnableStorage} from './Ownable.sol';
5+
import { Ownable, OwnableStorage } from './Ownable.sol';
66

77
contract OwnableMock is Ownable {
8-
using OwnableStorage for OwnableStorage.Layout;
8+
using OwnableStorage for OwnableStorage.Layout;
99

10-
constructor (address owner) {
11-
OwnableStorage.layout().setOwner(owner);
12-
}
10+
constructor(address owner) {
11+
OwnableStorage.layout().setOwner(owner);
12+
}
1313
}

contracts/access/SafeOwnableInternal.sol

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {SafeOwnableStorage} from './SafeOwnableStorage.sol';
5+
import { SafeOwnableStorage } from './SafeOwnableStorage.sol';
66

77
abstract contract SafeOwnableInternal {
8-
using SafeOwnableStorage for SafeOwnableStorage.Layout;
8+
using SafeOwnableStorage for SafeOwnableStorage.Layout;
99

10-
modifier onlyNomineeOwner () {
11-
require(
12-
msg.sender == SafeOwnableStorage.layout().nomineeOwner,
13-
'SafeOwnable: sender must be nominee owner'
14-
);
15-
_;
16-
}
10+
modifier onlyNomineeOwner() {
11+
require(
12+
msg.sender == SafeOwnableStorage.layout().nomineeOwner,
13+
'SafeOwnable: sender must be nominee owner'
14+
);
15+
_;
16+
}
1717
}

contracts/access/SafeOwnableMock.sol

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {SafeOwnable, OwnableStorage} from './SafeOwnable.sol';
5+
import { SafeOwnable, OwnableStorage } from './SafeOwnable.sol';
66

77
contract SafeOwnableMock is SafeOwnable {
8-
using OwnableStorage for OwnableStorage.Layout;
8+
using OwnableStorage for OwnableStorage.Layout;
99

10-
constructor (address owner) {
11-
OwnableStorage.layout().setOwner(owner);
12-
}
10+
constructor(address owner) {
11+
OwnableStorage.layout().setOwner(owner);
12+
}
1313
}

contracts/cryptography/ECDSA.sol

+71-64
Original file line numberDiff line numberDiff line change
@@ -7,75 +7,82 @@ pragma solidity ^0.8.0;
77
* @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts (MIT license)
88
*/
99
library ECDSA {
10-
/**
11-
* @notice recover signer of hashed message from signature
12-
* @param hash hashed data payload
13-
* @param signature signed data payload
14-
* @return recovered message signer
15-
*/
16-
function recover(
17-
bytes32 hash,
18-
bytes memory signature
19-
) internal pure returns (address) {
20-
require(signature.length == 65, 'ECDSA: invalid signature length');
10+
/**
11+
* @notice recover signer of hashed message from signature
12+
* @param hash hashed data payload
13+
* @param signature signed data payload
14+
* @return recovered message signer
15+
*/
16+
function recover(bytes32 hash, bytes memory signature)
17+
internal
18+
pure
19+
returns (address)
20+
{
21+
require(signature.length == 65, 'ECDSA: invalid signature length');
2122

22-
bytes32 r;
23-
bytes32 s;
24-
uint8 v;
23+
bytes32 r;
24+
bytes32 s;
25+
uint8 v;
2526

26-
assembly {
27-
r := mload(add(signature, 0x20))
28-
s := mload(add(signature, 0x40))
29-
v := byte(0, mload(add(signature, 0x60)))
30-
}
27+
assembly {
28+
r := mload(add(signature, 0x20))
29+
s := mload(add(signature, 0x40))
30+
v := byte(0, mload(add(signature, 0x60)))
31+
}
3132

32-
return recover(hash, v, r, s);
33-
}
33+
return recover(hash, v, r, s);
34+
}
3435

35-
/**
36-
* @notice recover signer of hashed message from signature v, r, and s values
37-
* @param hash hashed data payload
38-
* @param v signature "v" value
39-
* @param r signature "r" value
40-
* @param s signature "s" value
41-
* @return recovered message signer
42-
*/
43-
function recover (
44-
bytes32 hash,
45-
uint8 v,
46-
bytes32 r,
47-
bytes32 s
48-
) internal pure returns (address) {
49-
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
50-
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
51-
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
52-
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
53-
//
54-
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
55-
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
56-
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
57-
// these malleable signatures as well.
58-
require(
59-
uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
60-
'ECDSA: invalid signature \'s\' value'
61-
);
62-
require(v == 27 || v == 28, 'ECDSA: invalid signature \'v\' value');
36+
/**
37+
* @notice recover signer of hashed message from signature v, r, and s values
38+
* @param hash hashed data payload
39+
* @param v signature "v" value
40+
* @param r signature "r" value
41+
* @param s signature "s" value
42+
* @return recovered message signer
43+
*/
44+
function recover(
45+
bytes32 hash,
46+
uint8 v,
47+
bytes32 r,
48+
bytes32 s
49+
) internal pure returns (address) {
50+
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
51+
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
52+
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
53+
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
54+
//
55+
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
56+
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
57+
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
58+
// these malleable signatures as well.
59+
require(
60+
uint256(s) <=
61+
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
62+
"ECDSA: invalid signature 's' value"
63+
);
64+
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
6365

64-
// If the signature is valid (and not malleable), return the signer address
65-
address signer = ecrecover(hash, v, r, s);
66-
require(signer != address(0), 'ECDSA: invalid signature');
66+
// If the signature is valid (and not malleable), return the signer address
67+
address signer = ecrecover(hash, v, r, s);
68+
require(signer != address(0), 'ECDSA: invalid signature');
6769

68-
return signer;
69-
}
70+
return signer;
71+
}
7072

71-
/**
72-
* @notice generate an "Ethereum Signed Message" in the format returned by the eth_sign JSON-RPC method
73-
* @param hash hashed data payload
74-
* @return signed message
75-
*/
76-
function toEthSignedMessageHash (
77-
bytes32 hash
78-
) internal pure returns (bytes32) {
79-
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
80-
}
73+
/**
74+
* @notice generate an "Ethereum Signed Message" in the format returned by the eth_sign JSON-RPC method
75+
* @param hash hashed data payload
76+
* @return signed message
77+
*/
78+
function toEthSignedMessageHash(bytes32 hash)
79+
internal
80+
pure
81+
returns (bytes32)
82+
{
83+
return
84+
keccak256(
85+
abi.encodePacked('\x19Ethereum Signed Message:\n32', hash)
86+
);
87+
}
8188
}

contracts/factory/Factory.sol

+60-41
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,69 @@ pragma solidity ^0.8.0;
66
* @title Factory for arbitrary code deployment using the "CREATE" and "CREATE2" opcodes
77
*/
88
abstract contract Factory {
9-
/**
10-
* @notice deploy contract code using "CREATE" opcode
11-
* @param initCode contract initialization code
12-
* @return deployment address of deployed contract
13-
*/
14-
function _deploy (bytes memory initCode) internal returns (address deployment) {
15-
assembly {
16-
let encoded_data := add(0x20, initCode)
17-
let encoded_size := mload(initCode)
18-
deployment := create(0, encoded_data, encoded_size)
9+
/**
10+
* @notice deploy contract code using "CREATE" opcode
11+
* @param initCode contract initialization code
12+
* @return deployment address of deployed contract
13+
*/
14+
function _deploy(bytes memory initCode)
15+
internal
16+
returns (address deployment)
17+
{
18+
assembly {
19+
let encoded_data := add(0x20, initCode)
20+
let encoded_size := mload(initCode)
21+
deployment := create(0, encoded_data, encoded_size)
22+
}
23+
24+
require(deployment != address(0), 'Factory: failed deployment');
1925
}
2026

21-
require(deployment != address(0), 'Factory: failed deployment');
22-
}
27+
/**
28+
* @notice deploy contract code using "CREATE2" opcode
29+
* @dev reverts if deployment is not successful (likely because salt has already been used)
30+
* @param initCode contract initialization code
31+
* @param salt input for deterministic address calculation
32+
* @return deployment address of deployed contract
33+
*/
34+
function _deploy(bytes memory initCode, bytes32 salt)
35+
internal
36+
returns (address deployment)
37+
{
38+
assembly {
39+
let encoded_data := add(0x20, initCode)
40+
let encoded_size := mload(initCode)
41+
deployment := create2(0, encoded_data, encoded_size, salt)
42+
}
2343

24-
/**
25-
* @notice deploy contract code using "CREATE2" opcode
26-
* @dev reverts if deployment is not successful (likely because salt has already been used)
27-
* @param initCode contract initialization code
28-
* @param salt input for deterministic address calculation
29-
* @return deployment address of deployed contract
30-
*/
31-
function _deploy (bytes memory initCode, bytes32 salt) internal returns (address deployment) {
32-
assembly {
33-
let encoded_data := add(0x20, initCode)
34-
let encoded_size := mload(initCode)
35-
deployment := create2(0, encoded_data, encoded_size, salt)
44+
require(deployment != address(0), 'Factory: failed deployment');
3645
}
3746

38-
require(deployment != address(0), 'Factory: failed deployment');
39-
}
40-
41-
/**
42-
* @notice calculate the _deployMetamorphicContract deployment address for a given salt
43-
* @param initCodeHash hash of contract initialization code
44-
* @param salt input for deterministic address calculation
45-
* @return deployment address
46-
*/
47-
function _calculateDeploymentAddress (bytes32 initCodeHash, bytes32 salt) internal view returns (address) {
48-
return address(uint160(uint256(keccak256(abi.encodePacked(
49-
hex'ff',
50-
address(this),
51-
salt,
52-
initCodeHash
53-
)))));
54-
}
47+
/**
48+
* @notice calculate the _deployMetamorphicContract deployment address for a given salt
49+
* @param initCodeHash hash of contract initialization code
50+
* @param salt input for deterministic address calculation
51+
* @return deployment address
52+
*/
53+
function _calculateDeploymentAddress(bytes32 initCodeHash, bytes32 salt)
54+
internal
55+
view
56+
returns (address)
57+
{
58+
return
59+
address(
60+
uint160(
61+
uint256(
62+
keccak256(
63+
abi.encodePacked(
64+
hex'ff',
65+
address(this),
66+
salt,
67+
initCodeHash
68+
)
69+
)
70+
)
71+
)
72+
);
73+
}
5574
}

contracts/introspection/ERC165Mock.sol

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {ERC165, ERC165Storage, IERC165} from './ERC165.sol';
5+
import { ERC165, ERC165Storage, IERC165 } from './ERC165.sol';
66

77
contract ERC165Mock is ERC165 {
8-
using ERC165Storage for ERC165Storage.Layout;
8+
using ERC165Storage for ERC165Storage.Layout;
99

10-
constructor () {
11-
ERC165Storage.layout().setSupportedInterface(type(IERC165).interfaceId, true);
12-
}
10+
constructor() {
11+
ERC165Storage.layout().setSupportedInterface(
12+
type(IERC165).interfaceId,
13+
true
14+
);
15+
}
1316
}

0 commit comments

Comments
 (0)