-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bitcoin-portal/new-farms
SimpleFarm2X + PrivateFarm2X
- Loading branch information
Showing
111 changed files
with
74,954 additions
and
13,314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Test sizes | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Install Foundry | ||
uses: bitcoin-portal/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge Version | ||
run: forge --version | ||
|
||
- name: Run Forge Build | ||
run: forge build --sizes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Report gas differ | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
# Optionally configure to run only for changes in specific files. For example: | ||
# paths: | ||
# - src/** | ||
# - test/** | ||
# - foundry.toml | ||
# - remappings.txt | ||
# - .github/workflows/foundry-gas-diff.yml | ||
|
||
jobs: | ||
compare_gas_reports: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Dependencies | ||
run: npm install | ||
|
||
- name: Install Foundry | ||
uses: bitcoin-portal/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
# Add any step generating a gas report to a temporary file named gasreport.ansi. For example: | ||
- name: Run tests | ||
run: forge test --gas-report > gasreport.ansi -vvv # <- this file name should be unique in your repository! | ||
env: | ||
# make fuzzing semi-deterministic to avoid noisy gas cost estimation | ||
# due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds) | ||
FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }} | ||
|
||
- name: Compare gas reports | ||
uses: Rubilmax/[email protected] | ||
with: | ||
summaryQuantile: 0.9 # only display the 10% most significant gas diffs in the summary (defaults to 20%) | ||
sortCriteria: avg,max # sort diff rows by criteria | ||
sortOrders: desc,asc # and directions | ||
ignore: test-foundry/**/* # filter out gas reports from specific paths (test/ is included by default) | ||
id: gas_diff | ||
|
||
- name: Add gas diff to sticky comment | ||
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
# delete the comment in case changes no longer impact gas costs | ||
delete: ${{ !steps.gas_diff.outputs.markdown }} | ||
message: ${{ steps.gas_diff.outputs.markdown }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: test | ||
|
||
on: workflow_dispatch | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Run Forge build | ||
run: | | ||
forge --version | ||
forge build --sizes | ||
id: build | ||
|
||
- name: Run Forge tests | ||
run: | | ||
forge test -vvv | ||
id: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,3 +105,5 @@ dist | |
|
||
artifacts/* | ||
cache/* | ||
out/ | ||
forge-cache/solidity-files-cache.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,66 @@ | ||
## Foundry | ||
|
||
### Process and Testing | ||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
|
||
The package can be run as a CLI for testing purposes. | ||
Foundry consists of: | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
|
||
💰 This command runs farm tests: | ||
``` | ||
yarn test-farms | ||
``` | ||
## Documentation | ||
|
||
### Test coverage | ||
https://book.getfoundry.sh/ | ||
|
||
🧪 To generate test-coverage report simply run this command (without starting local chain) | ||
## Usage | ||
|
||
### Build | ||
|
||
```shell | ||
$ forge build | ||
``` | ||
yarn coverage | ||
|
||
### Test | ||
|
||
```shell | ||
$ forge test | ||
``` | ||
|
||
🧪 expected-latest test coverage results for farms: | ||
### Format | ||
|
||
```shell | ||
$ forge fmt | ||
``` | ||
-------------------|----------|----------|----------|----------|----------------| | ||
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines | | ||
-------------------|----------|----------|----------|----------|----------------| | ||
contracts/ | 100 | 95.24 | 100 | 100 | | | ||
IERC20.sol | 100 | 100 | 100 | 100 | | | ||
SafeERC20.sol | 100 | 66.67 | 100 | 100 | | | ||
SimpleFarm.sol | 100 | 100 | 100 | 100 | | | ||
TestToken.sol | 100 | 100 | 100 | 100 | | | ||
TokenWrapper.sol | 100 | 100 | 100 | 100 | | | ||
-------------------|----------|----------|----------|----------|----------------| | ||
All files | 100 | 95.24 | 100 | 100 | | | ||
-------------------|----------|----------|----------|----------|----------------| | ||
|
||
### Gas Snapshots | ||
|
||
```shell | ||
$ forge snapshot | ||
``` | ||
|
||
⛽ expected-latest gas consumption for farms: | ||
### Anvil | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
·------------------------------------|---------------------------|-------------|------------------------------· | ||
| Solc version: 0.8.17 · Optimizer enabled: true · Runs: 200 · Block limit: 100000000 gas │ | ||
·····································|···························|·············|······························· | ||
| Methods │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| Contract · Method · Min · Max · Avg · # calls · eur (avg) │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · approve · - · - · 46267 · 3 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · changeManager · - · - · 30047 · 2 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · claimOwnership · - · - · 29639 · 2 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · claimReward · - · - · 104218 · 1 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · exitFarm · - · - · 110999 · 1 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · farmDeposit · 73560 · 135760 · 116896 · 38 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · farmWithdraw · 66301 · 106723 · 79775 · 3 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · proposeNewOwner · - · - · 47157 · 3 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · recoverToken · - · - · 37424 · 1 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · setRewardDuration · 31911 · 31923 · 31913 · 5 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · setRewardRate · 91729 · 140229 · 135102 · 18 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · transfer · - · - · 46578 · 3 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| SimpleFarm · transferFrom · - · - · 47834 · 2 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| TestToken · approve · 46194 · 46218 · 46217 · 74 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| TestToken · mint · - · - · 50821 · 6 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| TestToken · transfer · - · - · 51577 · 3 · - │ | ||
···············|·····················|·············|·············|·············|···············|··············· | ||
| Deployments · · % of limit · │ | ||
·····································|·············|·············|·············|···············|··············· | ||
| SimpleFarm · 1487042 · 1487066 · 1487064 · 1.5 % · - │ | ||
·····································|·············|·············|·············|···············|··············· | ||
| TestToken · - · - · 627932 · 0.6 % · - │ | ||
·------------------------------------|-------------|-------------|-------------|---------------|--------------· | ||
|
||
### Deploy | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
|
||
### SimpleFarm | ||
🏭 expected creationCode hash: | ||
### Cast | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
0xfa923415d0153dc464f55b9793bb4a9c530c95f5808d935906d37f586c8f011c | ||
|
||
### Help | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: -- BCOM -- | ||
|
||
pragma solidity =0.8.23; | ||
|
||
library Babylonian { | ||
|
||
function sqrt( | ||
uint256 x | ||
) | ||
internal | ||
pure | ||
returns (uint256) | ||
{ | ||
if (x == 0) return 0; | ||
|
||
uint256 xx = x; | ||
uint256 r = 1; | ||
if (xx >= 0x100000000000000000000000000000000) { | ||
xx >>= 128; | ||
r <<= 64; | ||
} | ||
if (xx >= 0x10000000000000000) { | ||
xx >>= 64; | ||
r <<= 32; | ||
} | ||
if (xx >= 0x100000000) { | ||
xx >>= 32; | ||
r <<= 16; | ||
} | ||
if (xx >= 0x10000) { | ||
xx >>= 16; | ||
r <<= 8; | ||
} | ||
if (xx >= 0x100) { | ||
xx >>= 8; | ||
r <<= 4; | ||
} | ||
if (xx >= 0x10) { | ||
xx >>= 4; | ||
r <<= 2; | ||
} | ||
if (xx >= 0x8) { | ||
r <<= 1; | ||
} | ||
r = (r + (x / r)) >> 1; | ||
r = (r + (x / r)) >> 1; | ||
r = (r + (x / r)) >> 1; | ||
r = (r + (x / r)) >> 1; | ||
r = (r + (x / r)) >> 1; | ||
r = (r + (x / r)) >> 1; | ||
r = (r + (x / r)) >> 1; | ||
|
||
uint256 r1 = x / r; | ||
return (r < r1 ? r : r1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: -- WISE -- | ||
|
||
pragma solidity =0.8.23; | ||
|
||
contract Counter { | ||
|
||
uint256 public number; | ||
uint256 public duplicate; | ||
|
||
function setNumber( | ||
uint256 _newNumber | ||
) | ||
external | ||
{ | ||
number = _newNumber; | ||
} | ||
|
||
function increment() | ||
public | ||
{ | ||
number++; | ||
|
||
duplicate = duplicate | ||
+ duplicate | ||
+ duplicate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: -- WISE -- | ||
|
||
pragma solidity =0.8.23; | ||
|
||
import "lib/forge-std/src/Test.sol"; | ||
import "./Counter.sol"; | ||
|
||
contract CounterTest is Test { | ||
|
||
Counter public counter; | ||
|
||
function setUp() | ||
public | ||
{ | ||
counter = new Counter(); | ||
counter.setNumber(0); | ||
} | ||
|
||
function testIncrement() | ||
public | ||
{ | ||
counter.increment(); | ||
assertEq(counter.number(), 1); | ||
} | ||
|
||
function testSetNumber(uint256 x) | ||
public | ||
{ | ||
counter.setNumber(x); | ||
assertEq(counter.number(), x); | ||
} | ||
} |
Oops, something went wrong.