Skip to content

Commit

Permalink
fix(fmt): fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
sambacha committed Feb 13, 2024
1 parent 3d8cb12 commit 6559876
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 240 deletions.
18 changes: 9 additions & 9 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ via_ir = false
no_storage_caching = false
no_rpc_rate_limit = false
use_literal_content = false
bytecode_hash = "none"
cbor_metadata = false
bytecode_hash = "ipfs"
cbor_metadata = true
sparse_mode = false
build_info = true
build_info = false

[[profile.default.fs_permissions]]
access = "read"
Expand All @@ -62,18 +62,18 @@ chains = "all"
endpoints = "all"

[fmt]
line_length = 120
line_length = 80
tab_width = 4
bracket_spacing = false
int_types = "long"
multiline_func_header = "all"
multiline_func_header = "params_first"
quote_style = "double"
number_underscore = "thousands"
number_underscore = "preserve"
hex_underscore = "remove"
single_line_statement_blocks = "preserve"
single_line_statement_blocks = "multi"
override_spacing = false
wrap_comments = true
ignore = ["libs/*","*.t.sol"]
wrap_comments = false
ignore = []
contract_new_lines = false
sort_imports = true

Expand Down
102 changes: 57 additions & 45 deletions src/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,50 @@ pragma solidity >=0.8.0;
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/**
EVENTS
/*/

* EVENTS
* /
*/
event Transfer(address indexed from, address indexed to, uint256 amount);

event Approval(address indexed owner, address indexed spender, uint256 amount);
event Approval(
address indexed owner, address indexed spender, uint256 amount
);

/**
METADATA STORAGE
/*/

* METADATA STORAGE
* /
*/
string public name;

string public symbol;

uint8 public immutable decimals;

/**
ERC20 STORAGE
/*/

* ERC20 STORAGE
* /
*/
uint256 public totalSupply;

mapping(address => uint256) public balanceOf;

mapping(address => mapping(address => uint256)) public allowance;

/**
EIP-2612 STORAGE
/*/

* EIP-2612 STORAGE
* /
*/
uint256 internal immutable INITIAL_CHAIN_ID;

bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

mapping(address => uint256) public nonces;

/**
CONSTRUCTOR
/*/

constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
* CONSTRUCTOR
* /
*/
constructor(string memory _name, string memory _symbol, uint8 _decimals) {
name = _name;
symbol = _symbol;
decimals = _decimals;
Expand All @@ -62,18 +60,24 @@ abstract contract ERC20 {
}

/**
ERC20 LOGIC
/*/

function approve(address spender, uint256 amount) public virtual returns (bool) {
* ERC20 LOGIC
* /
*/
function approve(
address spender,
uint256 amount
) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;

emit Approval(msg.sender, spender, amount);

return true;
}

function transfer(address to, uint256 amount) public virtual returns (bool) {
function transfer(
address to,
uint256 amount
) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;

// Cannot overflow because the sum of all user
Expand All @@ -94,7 +98,9 @@ abstract contract ERC20 {
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
if (allowed != type(uint256).max) {
allowance[from][msg.sender] = allowed - amount;
}

balanceOf[from] -= amount;

Expand All @@ -110,9 +116,9 @@ abstract contract ERC20 {
}

/**
EIP-2612 LOGIC
/*/

* EIP-2612 LOGIC
* /
*/
function permit(
address owner,
address spender,
Expand Down Expand Up @@ -151,7 +157,10 @@ abstract contract ERC20 {
s
);

require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
require(
recoveredAddress != address(0) && recoveredAddress == owner,
"INVALID_SIGNER"
);

allowance[recoveredAddress][spender] = value;
}
Expand All @@ -160,26 +169,29 @@ abstract contract ERC20 {
}

function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
return block.chainid == INITIAL_CHAIN_ID
? INITIAL_DOMAIN_SEPARATOR
: computeDomainSeparator();
}

function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
return keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}

/**
INTERNAL MINT/BURN LOGIC
/*/

* INTERNAL MINT/BURN LOGIC
* /
*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;

Expand Down
63 changes: 38 additions & 25 deletions src/ERC6909.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,37 @@ pragma solidity >=0.8.0;
/// @notice Minimalist and gas efficient standard ERC6909 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC6909.sol)
abstract contract ERC6909 {

// EVENTS

// EVENTS

event OperatorSet(address indexed owner, address indexed operator, bool approved);
event OperatorSet(
address indexed owner, address indexed operator, bool approved
);

event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);
event Approval(
address indexed owner,
address indexed spender,
uint256 indexed id,
uint256 amount
);

event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount);
event Transfer(
address caller,
address indexed from,
address indexed to,
uint256 indexed id,
uint256 amount
);


// ERC6909 STORAGE

// ERC6909 STORAGE

mapping(address => mapping(address => bool)) public isOperator;

mapping(address => mapping(uint256 => uint256)) public balanceOf;

mapping(address => mapping(address => mapping(uint256 => uint256))) public allowance;
mapping(address => mapping(address => mapping(uint256 => uint256))) public
allowance;


// ERC6909 LOGIC

// ERC6909 LOGIC

function transfer(
address receiver,
Expand All @@ -50,7 +58,9 @@ abstract contract ERC6909 {
) public virtual returns (bool) {
if (msg.sender != sender && !isOperator[sender][msg.sender]) {
uint256 allowed = allowance[sender][msg.sender][id];
if (allowed != type(uint256).max) allowance[sender][msg.sender][id] = allowed - amount;
if (allowed != type(uint256).max) {
allowance[sender][msg.sender][id] = allowed - amount;
}
}

balanceOf[sender][id] -= amount;
Expand All @@ -74,27 +84,30 @@ abstract contract ERC6909 {
return true;
}

function setOperator(address operator, bool approved) public virtual returns (bool) {
function setOperator(
address operator,
bool approved
) public virtual returns (bool) {
isOperator[msg.sender][operator] = approved;

emit OperatorSet(msg.sender, operator, approved);

return true;
}


// ERC165 LOGIC

// ERC165 LOGIC

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
interfaceId == 0x0f632fb3; // ERC165 Interface ID for ERC6909
function supportsInterface(bytes4 interfaceId)
public
view
virtual
returns (bool)
{
return interfaceId == 0x01ffc9a7 // ERC165 Interface ID for ERC165
|| interfaceId == 0x0f632fb3; // ERC165 Interface ID for ERC6909
}


// INTERNAL MINT/BURN LOGIC

// INTERNAL MINT/BURN LOGIC

function _mint(
address receiver,
Expand Down
Loading

0 comments on commit 6559876

Please sign in to comment.