Skip to content

Commit

Permalink
𝐙𝔃ᢻ 𝗓 𐰁ᢻ
Browse files Browse the repository at this point in the history
𝐙𝔃ᢻ 𝗓 𐰁ᢻ
  • Loading branch information
z0r0z authored Feb 17, 2025
2 parents 51c4e91 + c5992ca commit f365bcd
Show file tree
Hide file tree
Showing 24 changed files with 663 additions and 1,097 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/solbase"]
path = lib/solbase
url = https://github.com/Sol-DAO/solbase
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022, 2023 z0r0z.
Copyright (c) 2022-2025 Zolidity.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
# Zolidity
Zero-fuss smart contracts.
# [zolidity](https://github.com/z0r0z/zolidity) [![License: MIT](https://img.shields.io/badge/License-MIT-black.svg)](https://opensource.org/license/mit) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.28-black)](https://docs.soliditylang.org/en/v0.8.28/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/z0r0z/zzz/actions/workflows/ci.yml/badge.svg)

Experiments on Ethereum.
`Zolidity`: Zero-to-One Solidity with Simplicity-first.

## Getting Started

Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup`

Build the foundry project with `forge build`. Run tests with `forge test`. Measure gas with `forge snapshot`. Format with `forge fmt`.

## GitHub Actions

Contracts will be tested and gas measured on every push and pull request.

You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).

## Blueprint

```txt
lib
β”œβ”€ forge-std β€” https://github.com/foundry-rs/forge-std
β”œβ”€ solady β€” https://github.com/vectorized/solady
src
β”œβ”€ ERC20 β€” Standard fungible token.
β”œβ”€ ERC173 β€” Standard contract ownership.
β”œβ”€ ReentrancyGuard β€” Reentrant call guard.
test
β”œβ”€ ERC20.t - Test standard fungible token.
β”œβ”€ ERC173.t β€” Test standard contract ownership.
└─ ReentrancyGuard.t β€” Test reentrant call guard.
```

## Inspiration

- [solady](https://github.com/Vectorized/solady)
- [solmate](https://github.com/transmissions11/solmate)
- [snekmate](https://github.com/pcaversaccio/snekmate)

## Disclaimer

*These smart contracts and testing suite are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of anything provided herein or through related user interfaces. This repository and related code have not been audited and as such there can be no assurance anything will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk.*

## License

See [LICENSE](./LICENSE) for more details.
13 changes: 7 additions & 6 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
[profile.default]
solc = "0.8.19"
solc_version = "0.8.28"
evm_version = "cancun"

optimizer = true
optimizer_runs = 9_999_999

# Configure remappings
remappings = [
"@std=lib/forge-std/src/",
"@solbase=lib/solbase/"
"@solady=lib/solady/",
"@forge=lib/forge-std/src/"
]

[profile.intense.fuzz]
runs = 5_000
[profile.via-ir]
via_ir = true

[fmt]
line_length = 100
1 change: 0 additions & 1 deletion lib/forge-std
Submodule forge-std deleted from 8b092b
1 change: 0 additions & 1 deletion lib/solbase
Submodule solbase deleted from e12d00
13 changes: 0 additions & 13 deletions package-lock.json

This file was deleted.

13 changes: 0 additions & 13 deletions package.json

This file was deleted.

25 changes: 25 additions & 0 deletions src/ERC173.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @notice Standard contract ownership.
/// @author Zolidity (https://github.com/z0r0z/zolidity/blob/main/src/ERC173.sol)
abstract contract ERC173 {
event OwnershipTransferred(address indexed from, address indexed to);

error Unauthorized();

address public owner;

modifier onlyOwner() virtual {
require(msg.sender == owner, Unauthorized());
_;
}

function _setOwner(address to) internal virtual {
emit OwnershipTransferred(msg.sender, owner = to);
}

function transferOwnership(address to) public virtual onlyOwner {
_setOwner(to);
}
}
62 changes: 62 additions & 0 deletions src/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @notice Standard fungible token.
/// @author Zolidity (https://github.com/z0r0z/zolidity/blob/main/src/ERC20.sol)
abstract contract ERC20 {
event Approval(address indexed from, address indexed to, uint256 amount);
event Transfer(address indexed from, address indexed to, uint256 amount);

string public name;
string public symbol;
uint256 public constant decimals = 18;

uint256 public totalSupply;

mapping(address holder => uint256) public balanceOf;
mapping(address holder => mapping(address spender => uint256)) public allowance;

constructor(string memory _name, string memory _symbol) payable {
(name, symbol) = (_name, _symbol);
}

function approve(address to, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][to] = amount;
emit Approval(msg.sender, to, amount);
return true;
}

function transfer(address to, uint256 amount) public virtual returns (bool) {
return transferFrom(msg.sender, to, amount);
}

function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
if (from != msg.sender) {
if (allowance[from][msg.sender] != type(uint256).max) {
allowance[from][msg.sender] -= amount;
}
}
balanceOf[from] -= amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}

function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}

function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
25 changes: 25 additions & 0 deletions src/ReentrancyGuard.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/// @notice Reentrant call guard.
/// @author Zolidity (https://github.com/z0r0z/zolidity/blob/main/src/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
error Reentrancy();

uint256 internal _guard = 1;

modifier nonReentrant() virtual {
_setReentrancyGuard();
_;
_clearReentrancyGuard();
}

function _setReentrancyGuard() internal virtual {
require(_guard != 2, Reentrancy());
_guard = 2;
}

function _clearReentrancyGuard() internal virtual {
_guard = 1;
}
}
Loading

0 comments on commit f365bcd

Please sign in to comment.