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

🤏 erc20: Init immutables don't hafta to be constructored #379

Open
wants to merge 50 commits into
base: v7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a902091
👷‍♂️ Update ds-test
transmissions11 Jun 15, 2022
3c73813
✅ Fix function names in WETH tests (#246)
jaglinux Jun 22, 2022
7272d0b
✍️ Fix typos in README.md (#285)
Jul 5, 2022
03e4254
♻️ Make bound virtual (#279)
vminkov Jul 5, 2022
ebd7418
👷‍♂️ Use new foundry.toml format (#289)
onbjerg Jul 18, 2022
34d20fc
♻️ New custodian
transmissions11 Jul 19, 2022
2979a7a
6.5.0
transmissions11 Jul 19, 2022
d155ee8
👷‍♂️ Update solc
transmissions11 Jul 21, 2022
47348f6
✅ Fix testBatchBalanceOf
transmissions11 Aug 3, 2022
478f9d0
✨ Add safeCastTo24
transmissions11 Aug 3, 2022
9cf1428
✅ Fix testSafeTransferFromToEOA
transmissions11 Aug 10, 2022
10fc959
✅ Add safeCastTo16 (#311)
Sep 1, 2022
1c48742
✨ New utils
transmissions11 Sep 8, 2022
9bd6c18
👷‍♂️ Update gas snapshot
transmissions11 Sep 8, 2022
92211f1
✨ unsafeMod
transmissions11 Sep 8, 2022
3342f4f
6.6.0
transmissions11 Sep 8, 2022
e10aa1b
✨ toDaysWadUnsafe/fromDaysWadUnsafe
transmissions11 Sep 8, 2022
2781a2c
6.6.1
transmissions11 Sep 8, 2022
b8853da
📝 Fix links
transmissions11 Sep 8, 2022
b864dac
6.6.2
transmissions11 Sep 8, 2022
a13635d
📝 Attribute Solady
transmissions11 Sep 8, 2022
1d50fa0
📝 Attribute Solady
transmissions11 Sep 8, 2022
01a5235
👷‍♂️ Update invariant signatures (#315)
mattsse Sep 8, 2022
9266c69
✅ More sqrt tests
transmissions11 Sep 11, 2022
2657280
⚡️ Optimized sqrt
transmissions11 Sep 11, 2022
18a482c
👷‍♂️ More fuzz runs
transmissions11 Sep 11, 2022
911b1f4
👷‍♂️ Even more fuzz runs
transmissions11 Sep 11, 2022
8323eeb
👷‍♂️ Fix config
transmissions11 Sep 11, 2022
bff24e8
👷‍♂️ Lower fuzz runs
transmissions11 Sep 11, 2022
62e0943
📝 Credit Remco
transmissions11 Oct 4, 2022
576a89d
♻️ Make Owned.sol EIP-713 compatible
transmissions11 Oct 12, 2022
352e1e9
♻️ More EIP-713 compatibility
transmissions11 Oct 12, 2022
c2594bf
⚡️ Optimize gas consumption for `mulDivUp` and `mulDivDown` (#306)
MerlinEgalite Oct 17, 2022
f2833c7
⚡️ Memory safe assembly (#333)
axic Oct 27, 2022
8d910d8
✅ Fix test to fail from old deadline not arithmetic underflow (#340)
heyskylark Nov 4, 2022
3a752b8
✨ wadPow
transmissions11 Dec 1, 2022
a115360
🐛 Mask address args in STL
transmissions11 Dec 12, 2022
b1db79b
✨ toString(int256) (#350)
transmissions11 Dec 30, 2022
3998897
⚡️ Optimize toString(int256) (#351)
transmissions11 Dec 31, 2022
564e9f1
👷‍♂️ Delete Solidity linguist git attribute (#358)
PaulRBerg Jan 19, 2023
267c744
6.7.0
transmissions11 Jan 31, 2023
1b3adf6
Merge branch 'release'
transmissions11 Jan 31, 2023
2001af4
✨ Every possible safeCast (#355)
haydenshively Mar 27, 2023
bceeec7
Merge branch 'main' into mask-address-args-STL
transmissions11 Jun 13, 2023
6e48caa
Update .gas-snapshot
transmissions11 Jun 13, 2023
50e15bb
🐛 Mask address args in STL (#347)
transmissions11 Jun 13, 2023
27545b0
6.1.0
transmissions11 Jun 13, 2023
bfc9c25
Merge branch 'mask-address-args-STL'
transmissions11 Jun 13, 2023
1994f47
🤏 erc20: Init immutables don't hafta to be constructored
z0r0z Aug 2, 2023
42f697a
🤏 fmt & snap
z0r0z Aug 2, 2023
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
550 changes: 433 additions & 117 deletions .gas-snapshot

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.sol linguist-language=Solidity
.gas-snapshot linguist-language=Julia
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib",
"solidity.compileUsingRemoteVersion": "v0.8.10",
"solidity.compileUsingRemoteVersion": "v0.8.15",
"search.exclude": { "lib": true },
"files.associations": {
".gas-snapshot": "julia"
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ tokens
├─ ERC721 — "Modern, minimalist, and gas efficient ERC721 implementation"
├─ ERC1155 — "Minimalist and gas efficient standard ERC1155 implementation"
utils
├─ SSTORE2 - "Library for cheaper reads and writes to persistent storage"
├─ SSTORE2 "Library for cheaper reads and writes to persistent storage"
├─ CREATE3 — "Deploy to deterministic addresses without an initcode factor"
├─ SafeCastLib - "Safe unsigned integer casting lib that reverts on overflow"
├─ LibString — "Library for creating string representations of uint values"
├─ SafeCastLib — "Safe unsigned integer casting lib that reverts on overflow"
├─ SignedWadMath — "Signed integer 18 decimal fixed point arithmetic library"
├─ MerkleProofLib — "Efficient merkle tree inclusion proof verification library"
├─ ReentrancyGuard — "Gas optimized reentrancy protection for smart contracts"
├─ FixedPointMathLib — "Arithmetic library with operations for fixed-point numbers"
├─ Bytes32AddressLib — "Library for converting between addresses and bytes32 values"
Expand All @@ -45,13 +48,13 @@ We **do not give any warranties** and **will not be liable for any loss** incurr
To install with [**Foundry**](https://github.com/gakonst/foundry):

```sh
forge install rari-capital/solmate
forge install transmissions11/solmate
```

To install with [**Hardhat**](https://github.com/nomiclabs/hardhat) or [**Truffle**](https://github.com/trufflesuite/truffle):

```sh
npm install @rari-capital/solmate
npm install solmate
```

## Acknowledgements
Expand Down
8 changes: 4 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[default]
solc = "0.8.10"
[profile.default]
solc = "0.8.15"
bytecode_hash = "none"
optimizer_runs = 1000000

[intense]
fuzz_runs = 10000
[profile.intense.fuzz]
runs = 10000
2 changes: 1 addition & 1 deletion lib/ds-test
Submodule ds-test updated 2 files
+21 −22 demo/demo.sol
+15 −0 package.json
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "@rari-capital/solmate",
"name": "solmate",
"license": "AGPL-3.0-only",
"version": "6.4.0",
"version": "6.1.0",
"description": "Modern, opinionated and gas optimized building blocks for smart contract development.",
"files": [
"src/**/*.sol"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Rari-Capital/solmate.git"
"url": "git+https://github.com/transmissions11/solmate.git"
},
"devDependencies": {
"prettier": "^2.3.1",
Expand Down
12 changes: 6 additions & 6 deletions src/auth/Auth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity >=0.8.0;

/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Auth.sol)
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnerUpdated(address indexed user, address indexed newOwner);
event OwnershipTransferred(address indexed user, address indexed newOwner);

event AuthorityUpdated(address indexed user, Authority indexed newAuthority);

Expand All @@ -17,7 +17,7 @@ abstract contract Auth {
owner = _owner;
authority = _authority;

emit OwnerUpdated(msg.sender, _owner);
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}

Expand Down Expand Up @@ -45,15 +45,15 @@ abstract contract Auth {
emit AuthorityUpdated(msg.sender, newAuthority);
}

function setOwner(address newOwner) public virtual requiresAuth {
function transferOwnership(address newOwner) public virtual requiresAuth {
owner = newOwner;

emit OwnerUpdated(msg.sender, newOwner);
emit OwnershipTransferred(msg.sender, newOwner);
}
}

/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Auth.sol)
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
Expand Down
10 changes: 5 additions & 5 deletions src/auth/Owned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity >=0.8.0;

/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Owned.sol)
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

event OwnerUpdated(address indexed user, address indexed newOwner);
event OwnershipTransferred(address indexed user, address indexed newOwner);

/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
Expand All @@ -29,16 +29,16 @@ abstract contract Owned {
constructor(address _owner) {
owner = _owner;

emit OwnerUpdated(address(0), _owner);
emit OwnershipTransferred(address(0), _owner);
}

/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/

function setOwner(address newOwner) public virtual onlyOwner {
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;

emit OwnerUpdated(msg.sender, newOwner);
emit OwnershipTransferred(msg.sender, newOwner);
}
}
2 changes: 1 addition & 1 deletion src/auth/authorities/MultiRolesAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.0;
import {Auth, Authority} from "../Auth.sol";

/// @notice Flexible and target agnostic role based Authority that supports up to 256 roles.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/authorities/MultiRolesAuthority.sol)
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/authorities/MultiRolesAuthority.sol)
contract MultiRolesAuthority is Auth, Authority {
/*//////////////////////////////////////////////////////////////
EVENTS
Expand Down
2 changes: 1 addition & 1 deletion src/auth/authorities/RolesAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.0;
import {Auth, Authority} from "../Auth.sol";

/// @notice Role based Authority that supports up to 256 roles.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/authorities/RolesAuthority.sol)
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/authorities/RolesAuthority.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-roles/blob/master/src/roles.sol)
contract RolesAuthority is Auth, Authority {
/*//////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/mixins/ERC4626.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
import {FixedPointMathLib} from "../utils/FixedPointMathLib.sol";

/// @notice Minimal ERC4626 tokenized Vault implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol)
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/mixins/ERC4626.sol)
abstract contract ERC4626 is ERC20 {
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
Expand Down
78 changes: 39 additions & 39 deletions src/test/Auth.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.10;
pragma solidity 0.8.15;

import {DSTestPlus} from "./utils/DSTestPlus.sol";
import {MockAuthChild} from "./utils/mocks/MockAuthChild.sol";
Expand All @@ -24,8 +24,8 @@ contract AuthTest is DSTestPlus {
mockAuthChild = new MockAuthChild();
}

function testSetOwnerAsOwner() public {
mockAuthChild.setOwner(address(0xBEEF));
function testTransferOwnershipAsOwner() public {
mockAuthChild.transferOwnership(address(0xBEEF));
assertEq(mockAuthChild.owner(), address(0xBEEF));
}

Expand All @@ -38,21 +38,21 @@ contract AuthTest is DSTestPlus {
mockAuthChild.updateFlag();
}

function testSetOwnerWithPermissiveAuthority() public {
function testTransferOwnershipWithPermissiveAuthority() public {
mockAuthChild.setAuthority(new MockAuthority(true));
mockAuthChild.setOwner(address(0));
mockAuthChild.setOwner(address(this));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.transferOwnership(address(this));
}

function testSetAuthorityWithPermissiveAuthority() public {
mockAuthChild.setAuthority(new MockAuthority(true));
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.setAuthority(Authority(address(0xBEEF)));
}

function testCallFunctionWithPermissiveAuthority() public {
mockAuthChild.setAuthority(new MockAuthority(true));
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.updateFlag();
}

Expand All @@ -61,51 +61,51 @@ contract AuthTest is DSTestPlus {
mockAuthChild.setAuthority(new MockAuthority(true));
}

function testFailSetOwnerAsNonOwner() public {
mockAuthChild.setOwner(address(0));
mockAuthChild.setOwner(address(0xBEEF));
function testFailTransferOwnershipAsNonOwner() public {
mockAuthChild.transferOwnership(address(0));
mockAuthChild.transferOwnership(address(0xBEEF));
}

function testFailSetAuthorityAsNonOwner() public {
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.setAuthority(Authority(address(0xBEEF)));
}

function testFailCallFunctionAsNonOwner() public {
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.updateFlag();
}

function testFailSetOwnerWithRestrictiveAuthority() public {
function testFailTransferOwnershipWithRestrictiveAuthority() public {
mockAuthChild.setAuthority(new MockAuthority(false));
mockAuthChild.setOwner(address(0));
mockAuthChild.setOwner(address(this));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.transferOwnership(address(this));
}

function testFailSetAuthorityWithRestrictiveAuthority() public {
mockAuthChild.setAuthority(new MockAuthority(false));
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.setAuthority(Authority(address(0xBEEF)));
}

function testFailCallFunctionWithRestrictiveAuthority() public {
mockAuthChild.setAuthority(new MockAuthority(false));
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
mockAuthChild.updateFlag();
}

function testFailSetOwnerAsOwnerWithOutOfOrderAuthority() public {
function testFailTransferOwnershipAsOwnerWithOutOfOrderAuthority() public {
mockAuthChild.setAuthority(new OutOfOrderAuthority());
mockAuthChild.setOwner(address(0));
mockAuthChild.transferOwnership(address(0));
}

function testFailCallFunctionAsOwnerWithOutOfOrderAuthority() public {
mockAuthChild.setAuthority(new OutOfOrderAuthority());
mockAuthChild.updateFlag();
}

function testSetOwnerAsOwner(address newOwner) public {
mockAuthChild.setOwner(newOwner);
function testTransferOwnershipAsOwner(address newOwner) public {
mockAuthChild.transferOwnership(newOwner);
assertEq(mockAuthChild.owner(), newOwner);
}

Expand All @@ -114,79 +114,79 @@ contract AuthTest is DSTestPlus {
assertEq(address(mockAuthChild.authority()), address(newAuthority));
}

function testSetOwnerWithPermissiveAuthority(address deadOwner, address newOwner) public {
function testTransferOwnershipWithPermissiveAuthority(address deadOwner, address newOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new MockAuthority(true));
mockAuthChild.setOwner(deadOwner);
mockAuthChild.setOwner(newOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.transferOwnership(newOwner);
}

function testSetAuthorityWithPermissiveAuthority(address deadOwner, Authority newAuthority) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new MockAuthority(true));
mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.setAuthority(newAuthority);
}

function testCallFunctionWithPermissiveAuthority(address deadOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new MockAuthority(true));
mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.updateFlag();
}

function testFailSetOwnerAsNonOwner(address deadOwner, address newOwner) public {
function testFailTransferOwnershipAsNonOwner(address deadOwner, address newOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setOwner(deadOwner);
mockAuthChild.setOwner(newOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.transferOwnership(newOwner);
}

function testFailSetAuthorityAsNonOwner(address deadOwner, Authority newAuthority) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.setAuthority(newAuthority);
}

function testFailCallFunctionAsNonOwner(address deadOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.updateFlag();
}

function testFailSetOwnerWithRestrictiveAuthority(address deadOwner, address newOwner) public {
function testFailTransferOwnershipWithRestrictiveAuthority(address deadOwner, address newOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new MockAuthority(false));
mockAuthChild.setOwner(deadOwner);
mockAuthChild.setOwner(newOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.transferOwnership(newOwner);
}

function testFailSetAuthorityWithRestrictiveAuthority(address deadOwner, Authority newAuthority) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new MockAuthority(false));
mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.setAuthority(newAuthority);
}

function testFailCallFunctionWithRestrictiveAuthority(address deadOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new MockAuthority(false));
mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
mockAuthChild.updateFlag();
}

function testFailSetOwnerAsOwnerWithOutOfOrderAuthority(address deadOwner) public {
function testFailTransferOwnershipAsOwnerWithOutOfOrderAuthority(address deadOwner) public {
if (deadOwner == address(this)) deadOwner = address(0);

mockAuthChild.setAuthority(new OutOfOrderAuthority());
mockAuthChild.setOwner(deadOwner);
mockAuthChild.transferOwnership(deadOwner);
}
}
Loading