Skip to content

Commit

Permalink
Merge pull request #41 from ronin-chain/release/v1.0.0
Browse files Browse the repository at this point in the history
Release/v1.0.0
  • Loading branch information
thaixuandang authored Dec 24, 2024
2 parents 8d49db6 + a93f2a3 commit f840040
Show file tree
Hide file tree
Showing 270 changed files with 43,382 additions and 4,674 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/core-libraries-echidna.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Core Libraries Fuzz Testing

on:
push:
branches:
- mainnet
- testnet
pull_request:

jobs:
echidna:
name: Echidna
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
testName:
- TickBitmapEchidnaTest
- TickMathEchidnaTest
- SqrtPriceMathEchidnaTest
- SwapMathEchidnaTest
- TickEchidnaTest
- TickOverflowSafetyEchidnaTest
- OracleEchidnaTest
- BitMathEchidnaTest
- LowGasSafeMathEchidnaTest
- UnsafeMathEchidnaTest
- FullMathEchidnaTest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install pip3
run: |
python -m pip install --upgrade pip
- name: Install slither
run: |
pip3 install slither-analyzer
- name: Install echidna
run: |
sudo wget -O /tmp/echidna-test.tar.gz https://github.com/crytic/echidna/releases/download/v1.7.3/echidna-test-1.7.3-Ubuntu-18.04.tar.gz
sudo tar -xf /tmp/echidna-test.tar.gz -C /usr/bin
sudo chmod +x /usr/bin/echidna-test
- name: Run ${{ matrix.testName }}
run: echidna-test src/core/test/** --contract ${{ matrix.testName }} --config echidna.config.yml
22 changes: 18 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'
- "feature/*"
- "features/*"
pull_request:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'
- "feature/*"
- "features/*"
- "test/*"

env:
FOUNDRY_PROFILE: ci
Expand Down Expand Up @@ -44,3 +45,16 @@ jobs:
run: |
forge test -vvv
id: test

- uses: actions/setup-node@v1
with:
node-version: 18.x

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Run Hardhat compile
run: yarn compile

- name: Run Hardhat unit tests
run: yarn test
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ docs/
node_modules/
yarn-error.log
.yarn
.yarnrc.yml
.yarnrc.yml

.vscode/

cache_hardhat/
artifacts/
typechain/
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/solidity-lib"]
path = lib/solidity-lib
url = https://github.com/Uniswap/solidity-lib
[submodule "lib/base64"]
path = lib/base64
url = https://github.com/Brechtpd/base64
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=v1.0.0 - SHA: 1d58b1b5f46f0eb9e450ee1097eaaa0ee79e8503
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
deploy-testnet:
op run --env-file="./.env" -- \
forge script DeployKatanaV3Testnet -f ronin-testnet

deploy-testnet-broadcast:
op run --env-file="./.env" -- \
forge script DeployKatanaV3Testnet -f ronin-testnet --verify --verifier sourcify --verifier-url https://sourcify.roninchain.com/server/ --legacy --broadcast

deploy-mainnet:
op run --env-file="./.env" -- \
forge script DeployKatanaV3Mainnet -f ronin-mainnet

deploy-mainnet-broadcast:
op run --env-file="./.env" -- \
forge script DeployKatanaV3Mainnet -f ronin-mainnet --verify --verifier sourcify --verifier-url https://sourcify.roninchain.com/server/ --legacy --broadcast
116 changes: 20 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,38 @@
## Template Smart Contract Project
# Katana V3 Smart Contracts

This repository serves as a template for building robust and efficient smart contracts, providing developers with a structured foundation to accelerate the process of developing, testing and upgrading contracts.
This repository contains the smart contracts for Katana V3, a decentralized exchange forked from Uniswap V3 and deployed on the Ronin blockchain.

## Documentation
It includes both core and peripheral contracts. However, the router for swapping tokens, which supports both V2 and V3 pools, is hosted in [a separate repository](https://github.com/ronin-chain/katana-operation-contracts).

https://book.getfoundry.sh/
## Development

## Usage
For a comprehensive guide on writing migrations, refer to [foundry-deployment-kit example](https://github.com/axieinfinity/foundry-deployment-kit/tree/testnet/script/sample).
### Prerequisites

## Install
```shell
$ yarn install
$ forge install
```

### Build
To work with this repository, ensure you have the following tools installed:
- Node.js (version 16 or later)
- Yarn or npm
- Hardhat

```shell
$ forge build
After cloning the repository, install the required JavaScript dependencies for testing by running:
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
yarn
```

### Simulate
### Compiling

```shell
$ ./run.sh <path/to/file.s.sol> -f <network>
To compile the contracts, run:
```

### Broadcast

```shell
$ ./run.sh <path/to/file.s.sol> -f <network> --broadcast --log <subcommand>
forge build
```
This will generate the compiled artifacts in the out directory.

### Verify
### Testing

```shell
$ ./verify.sh -c <network>
You can run tests to ensure the contracts work as expected.
```

### Debug

#### Debug on-chain transaction hash

```shell
$ cast run -e istanbul -r <network> <tx_hash>
forge test
```

#### Debug raw call data

```shell
# Create a debug file
$ touch .debug.env
With Hardhat tests, run:
```
Fill in the necessary variables in the .debug.env file. Refer to the provided .debug.env.example for guidance. Here's an example of how to set the variables:
```shell
BLOCK=21224300
FROM=0x412d4d69122839fccad0180e9358d157c3876f3c
TO=0x512699b52ac2dc2b2ad505d9f29dcdad078fa799
VALUE=0x27cdb0997a65b2de99
CALLDATA=0xcb80fe2f00000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000412d4d69122839fccad0180e9358d157c3876f3c0000000000000000000000000000000000000000000000000000000001e133809923eb94000000032ef4aeab07d3fac5770bd31775496da5b39fa2215aee1494000000000000000000000000803c459dcb8771e5354d1fc567ecc6885a9fd5e600000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000374686900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
```
Debug command:
```shell
chmod +x debug.sh
./debug.sh -f <network>
```

### Miscellaneous

#### Inspect Storage layout

```shell
$ forge inspect <contract> storage-layout --pretty
```

#### Inspect error selectors

```shell
$ forge inspect <contract> errors --pretty
```

#### Decode errors
```shell
$ cast 4byte <error_codes>
# or
$ cast 4byte-decode <long_bytes_error_codes>
```

#### Decode call data
```shell
$ cast pretty-calldata <calldata>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
yarn test
```

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

126 changes: 126 additions & 0 deletions broadcast/20241118_DeployFixedPeripheries.s.sol/2021/run-latest.json

Large diffs are not rendered by default.

289 changes: 289 additions & 0 deletions broadcast/DeployKatanaV3Testnet.s.sol/2021/run-1728296705.json

Large diffs are not rendered by default.

561 changes: 561 additions & 0 deletions broadcast/DeployKatanaV3Testnet.s.sol/2021/run-1728296713.json

Large diffs are not rendered by default.

561 changes: 561 additions & 0 deletions broadcast/DeployKatanaV3Testnet.s.sol/2021/run-1728296754.json

Large diffs are not rendered by default.

561 changes: 561 additions & 0 deletions broadcast/DeployKatanaV3Testnet.s.sol/2021/run-latest.json

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions echidna.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#format can be "text" or "json" for different output (human or machine readable)
format: 'text'
#checkAsserts checks assertions
checkAsserts: true
#coverage controls coverage guided testing
coverage: false
# #psender is the sender for property transactions; by default intentionally
# #the same as contract deployer
# psender: "0x00a329c0648769a73afac7f9381e08fb43dbea70"
# #prefix is the prefix for Boolean functions that are properties to be checked
# prefix: "echidna_"
# #propMaxGas defines gas cost at which a property fails
# propMaxGas: 8000030
# #testMaxGas is a gas limit; does not cause failure, but terminates sequence
# testMaxGas: 8000030
# #maxGasprice is the maximum gas price
# maxGasprice: 100000000000
# #testLimit is the number of test sequences to run
# testLimit: 50000
# #stopOnFail makes echidna terminate as soon as any property fails and has been shrunk
# stopOnFail: false
# #estimateGas makes echidna perform analysis of maximum gas costs for functions (experimental)
# estimateGas: false
# #seqLen defines how many transactions are in a test sequence
# seqLen: 100
# #shrinkLimit determines how much effort is spent shrinking failing sequences
# shrinkLimit: 5000
# #contractAddr is the address of the contract itself
# contractAddr: "0x00a329c0648769a73afac7f9381e08fb43dbea72"
# #deployer is address of the contract deployer (who often is privileged owner, etc.)
# deployer: "0x00a329c0648769a73afac7f9381e08fb43dbea70"
# #sender is set of addresses transactions may originate from
# sender: ["0x10000", "0x20000", "0x00a329c0648769a73afac7f9381e08fb43dbea70"]
# #balanceAddr is default balance for addresses
# balanceAddr: 0xffffffff
# #balanceContract overrides balanceAddr for the contract address
# balanceContract: 0
# #solcArgs allows special args to solc
# solcArgs: ""
# #solcLibs is solc libraries
# solcLibs: []
# #cryticArgs allows special args to crytic
# cryticArgs: []
# #quiet produces (much) less verbose output
# quiet: false
# #initialize the blockchain with some data
# initialize: null
# #whether ot not to use the multi-abi mode of testing
# multi-abi: false
# #benchmarkMode enables benchmark mode
# benchmarkMode: false
# #timeout controls test timeout settings
# timeout: null
# #seed not defined by default, is the random seed
# #seed: 0
# #dictFreq controls how often to use echidna's internal dictionary vs random
# #values
# dictFreq: 0.40
# maxTimeDelay: 604800
# #maximum time between generated txs; default is one week
# maxBlockDelay: 60480
# #maximum number of blocks elapsed between generated txs; default is expected increment in one week
# # timeout:
# #campaign timeout (in seconds)
# # list of methods to filter
# filterFunctions: []
# # by default, blacklist methods in filterFunctions
# filterBlacklist: true
# #directory to save the corpus; by default is disabled
# corpusDir: null
# # constants for corpus mutations (for experimentation only)
# mutConsts: [100, 1, 1]
# # maximum value to send to payable functions
# maxValue: 100000000000000000000 # 100 eth
6 changes: 2 additions & 4 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ src = "src"
out = "out"
script = "script"
libs = ["lib"]
ffi = true

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

solc = '0.8.23'
solc = '0.7.6'
optimizer_runs = 250
evm_version = 'istanbul'
use_literal_content = true
extra_output = ["devdoc", "userdoc", "storagelayout"]
fs_permissions = [{ access = "read-write", path = "./" }]

[fmt]
tab_width = 2
Expand Down
Loading

0 comments on commit f840040

Please sign in to comment.