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

chore(mainnet): merge from merge/deploy/v1.0.0-mainnet #43

Closed
wants to merge 100 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
d031f7e
forge install: openzeppelin-contracts
thaixuandang Jul 4, 2024
18bd181
forge install: solidity-lib
thaixuandang Jul 4, 2024
4cbe4e5
forge install: base64
thaixuandang Jul 4, 2024
9218a74
forge install: v2-core
thaixuandang Jul 4, 2024
0656e7f
feat: add Uniswap v3-core & v3-periphery contracts
thaixuandang Jul 4, 2024
f6bc9be
forge install: forge-std
thaixuandang Jul 4, 2024
893bd6a
chore: add a dummy test to pass CI
thaixuandang Jul 4, 2024
985dcbd
Merge pull request #1 from ronin-chain/feature/fork-uniswap-v3
thaixuandang Jul 4, 2024
dbb7490
BREAKING CHANGES: rename Uniswap to Katana
thaixuandang Jul 5, 2024
235b6b6
chore: run forge fmt to format all files
thaixuandang Jul 5, 2024
8d5c5de
BREAKING CHANGES: replace uniswap by katana (lower case)
thaixuandang Jul 5, 2024
fc11546
feat: upgradeable beacon proxy for pools, remove noDelegateCall
thaixuandang Jul 8, 2024
a793b97
feat: implement fee tiers
thaixuandang Jul 10, 2024
7b4788c
feat: automatically transfer protocol fees to the treasury for swaps …
thaixuandang Jul 10, 2024
3251bb9
fix: optimize caching
thaixuandang Jul 15, 2024
ff226c1
fix: tick spacing of 1 for the 0.01% fee tier
thaixuandang Jul 15, 2024
dd82739
feat: flag to enable/disable flash loans
thaixuandang Jul 15, 2024
06948f2
feat: return collected fees of a position
thaixuandang Jul 19, 2024
698368a
feat: burn the position NFT when no liquidity and no tokens owed in t…
thaixuandang Jul 19, 2024
9e56c6f
feat: proxy for KatanaV3Factory
thaixuandang Jul 24, 2024
0229678
feat: modify NonfungiblePositionManager to be able behind Transparent…
thaixuandang Jul 24, 2024
ead7514
feat: return bytecode instead of extcodecopy, so that POOL_PROXY_BYTE…
thaixuandang Jul 29, 2024
251d698
feat: add MixedRouteQuoterV1
thaixuandang Jul 25, 2024
c55d731
feat: remove Uniswap/v2-core
thaixuandang Jul 25, 2024
fcb7bbf
chore: remove @uniswap/v2-core in remappings
thaixuandang Jul 25, 2024
371f273
feat: add IKatanaGovernance.sol file
thaixuandang Jul 30, 2024
746b629
feat: authorization for KatanaV3Pool, KatanaV3Factory, NonfungiblePos…
thaixuandang Jul 31, 2024
021c723
script: deploy core & periphery on local, ronin{mainnet, testnet}
thaixuandang Jul 31, 2024
7f44b99
test: update factory and pool test
thaixuandang Jul 31, 2024
82998f2
script: add deploy QuoterV2
thaixuandang Jul 31, 2024
ea4374d
fix: initialize function for NonfungiblePositionManager, reduce bytec…
thaixuandang Jul 31, 2024
03bdc53
feat: using the governance contract as an immutable in logic contracts
thaixuandang Aug 1, 2024
a61849f
chore(AuthorizationLib): range solc version
thaixuandang Aug 1, 2024
32ab672
fix: no need to check authorization when quoting
thaixuandang Aug 7, 2024
3d17556
Merge pull request #3 from ronin-chain/feature/rename-and-format
thaixuandang Aug 19, 2024
5baf0db
Merge pull request #16 from ronin-chain/merge/release/v1.0.0-feature/…
thaixuandang Aug 19, 2024
92643d4
Merge pull request #14 from ronin-chain/merge/release/v1.0.0-feature/…
thaixuandang Aug 19, 2024
e6d12b5
Merge pull request #15 from ronin-chain/merge/release/v1.0.0-feature/…
thaixuandang Aug 19, 2024
b5dad8d
Merge pull request #17 from ronin-chain/merge/release/v1.0.0-feature/…
thaixuandang Aug 19, 2024
296e920
Merge pull request #21 from ronin-chain/merge/release/v1.0.0-feature/…
thaixuandang Aug 19, 2024
a5a1003
Merge pull request #22 from ronin-chain/merge/release/v1.0.0-feature/…
thaixuandang Aug 19, 2024
295c9ef
fix: migrator must create pools through position manager
thaixuandang Aug 21, 2024
b163de1
chore: storage layout
thaixuandang Aug 21, 2024
df2a9ff
fix: authorization for migrator
thaixuandang Aug 23, 2024
ff771e7
Merge pull request #11 from ronin-chain/feature/upgradeable-beacon-proxy
thaixuandang Aug 26, 2024
3747c28
Merge pull request #4 from ronin-chain/feature/fee-tiers
thaixuandang Aug 26, 2024
1697ba1
Merge pull request #5 from ronin-chain/feature/flash-loans
thaixuandang Aug 26, 2024
921a1b6
Merge pull request #31 from ronin-chain/feature/statistic
thaixuandang Aug 26, 2024
df1ce8f
Merge pull request #7 from ronin-chain/feature/proxy
thaixuandang Aug 26, 2024
e04a962
Merge pull request #8 from ronin-chain/feature/mixed-route-quoter
thaixuandang Aug 26, 2024
18265ab
Merge pull request #10 from ronin-chain/feature/innovation-zone
thaixuandang Aug 26, 2024
262d728
BREAKING CHANGE: restructure factory to be behind TransparentUpgradea…
thaixuandang Aug 16, 2024
92d6672
chore: storage layout
thaixuandang Aug 16, 2024
165e5cb
fix: record only fees, not burned liquidity in the collectedFees method
thaixuandang Aug 19, 2024
fca3e10
chore: storage layout
thaixuandang Aug 19, 2024
a9196ef
chore: replace remapping by src directory
thaixuandang Aug 20, 2024
b841b15
chore: resolve comments
thaixuandang Aug 27, 2024
4dba1f6
fix: call msg.sender to get beacon when deploy pool proxy for compati…
thaixuandang Aug 27, 2024
d82d5d2
forge install: openzeppelin-contracts
thaixuandang Aug 28, 2024
ef1af86
fix: transfer protocol fees at the end of the swap to ensure pools ha…
thaixuandang Aug 29, 2024
333416f
chore: fix typo
thaixuandang Sep 6, 2024
f2a6905
feat: use storage variables instead of immutables in logic contracts
thaixuandang Sep 16, 2024
a786f73
feat(KatanaV3Pool): remove setFeeProtocol, collectProtocol functions
thaixuandang Sep 16, 2024
84b67dd
feat: split feeProtocol from single variable to 2 variables (numerato…
thaixuandang Sep 16, 2024
c8d1883
chore: storage layout
thaixuandang Sep 16, 2024
d86c4cf
chore(NonfungibleTokenPositionDescriptor): prioritized display of wel…
thaixuandang Sep 16, 2024
c60307b
chore: storage layout
thaixuandang Sep 16, 2024
54107fd
feat: update IKatanaGovernance
thaixuandang Sep 17, 2024
ecee4fb
chore: storage layout
thaixuandang Sep 17, 2024
3ffd563
feat(KatanaV3Factory): remove setOwner function
thaixuandang Sep 18, 2024
d772337
feat: update IKatanaGovernance
thaixuandang Sep 18, 2024
39a6e9d
chore: storage layout
thaixuandang Sep 18, 2024
0f0bb47
Merge pull request #13 from ronin-chain/feat/refactor
thaixuandang Sep 18, 2024
a980750
fix: resolve internal audit concerns
thaixuandang Sep 24, 2024
7779101
chore: storage layout
thaixuandang Sep 24, 2024
f5bed7f
Merge pull request #32 from ronin-chain/fix/internal-audit
thaixuandang Sep 24, 2024
5f8ff03
chore(NonfungiblePositionManager): remove redundant burn method
thaixuandang Oct 1, 2024
03c8017
chore: storage layout
thaixuandang Oct 1, 2024
787b6f6
chore: add deployment artifacts
thaixuandang Oct 7, 2024
d9e235f
feat: add a check by getting pool from the factory in verifyCallback
thaixuandang Nov 12, 2024
c680dc7
chore: storage layout
thaixuandang Nov 12, 2024
e59ece0
Merge pull request #34 from ronin-chain/feature/c4-issue-32
thaixuandang Nov 18, 2024
1d58b1b
chore: script to deploy fixed peripheries & deployment artifacts
Nov 18, 2024
2569cd6
feat: transfer ownership of the beacon in mainnet deploy script
thaixuandang Nov 20, 2024
3e364c5
chore: storage layout
thaixuandang Nov 20, 2024
1e197e8
Merge pull request #36 from ronin-chain/feature/mainnet-deploy-script
thaixuandang Nov 21, 2024
b474284
test: core libraries Echidna
thaixuandang Aug 13, 2024
00e7ee9
chore: forge format Echidna test files
thaixuandang Aug 13, 2024
b981feb
test: core libraries Hardhat
thaixuandang Aug 20, 2024
4aaa75f
test: core specification Hardhat
thaixuandang Sep 5, 2024
f280ff0
test: periphery Hardhat
thaixuandang Sep 16, 2024
5d26a28
chore: add Hardhat test workflow
thaixuandang Sep 9, 2024
9ba7115
docs: update README
thaixuandang Dec 24, 2024
56489c6
chore: storage layout
thaixuandang Dec 24, 2024
4c771f3
Merge pull request #12 from ronin-chain/test/core
thaixuandang Dec 24, 2024
005d6c3
[create-pull-request] automated change
thaixuandang Dec 24, 2024
a93f2a3
Merge pull request #40 from ronin-chain/merge/deploy/v1.0.0-testnet
thaixuandang Dec 24, 2024
92f1bdb
chore: add artifact for release-v1.0.0-mainnet
TuDo1403 Nov 21, 2024
cd75b2c
[create-pull-request] automated change
thaixuandang Dec 24, 2024
77c9590
Merge pull request #42 from ronin-chain/merge/deploy/v1.0.0-mainnet
thaixuandang Dec 24, 2024
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
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: 92f1bdb60e8a537ff1b69234a925dddca76d6fd8
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.

311 changes: 311 additions & 0 deletions broadcast/DeployKatanaV3Mainnet.s.sol/2020/run-1732163873.json

Large diffs are not rendered by default.

614 changes: 614 additions & 0 deletions broadcast/DeployKatanaV3Mainnet.s.sol/2020/run-1732163881.json

Large diffs are not rendered by default.

614 changes: 614 additions & 0 deletions broadcast/DeployKatanaV3Mainnet.s.sol/2020/run-1732163922.json

Large diffs are not rendered by default.

614 changes: 614 additions & 0 deletions broadcast/DeployKatanaV3Mainnet.s.sol/2020/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
Loading