Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0' into merge/deploy/v1.0.0-mainnet
Browse files Browse the repository at this point in the history
Signed-off-by: Thai Xuan Dang <59406756+thaixuandang@users.noreply.github.com>
  • Loading branch information
thaixuandang authored Dec 27, 2024
2 parents e96ca3c + 1e4a184 commit d943d3c
Show file tree
Hide file tree
Showing 42 changed files with 6,523 additions and 4,678 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ yarn-error.log
.yarnrc.yml

# Soldeer
dependencies/
dependencies/

# Hardhat
artifacts/
typechain/
cache_hardhat/
117 changes: 22 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,41 @@
## 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 router and governance contracts for the Katana decentralized exchange.

## Documentation
## Development

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

## 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).
To work with this repository, ensure you have the following tools installed:
- Node.js (version 16 or later)
- Yarn or npm
- Hardhat

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

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Simulate

```shell
$ ./run.sh <path/to/file.s.sol> -f <network>
```

### Broadcast

```shell
$ ./run.sh <path/to/file.s.sol> -f <network> --broadcast --log <subcommand>
yarn
```

### Verify

```shell
$ ./verify.sh -c <network>
And Foundry dependencies:
```

### Debug

#### Debug on-chain transaction hash

```shell
$ cast run -e istanbul -r <network> <tx_hash>
forge install
forge soldeer update
```

#### Debug raw call data
### Compiling

```shell
# Create a debug file
$ touch .debug.env
To compile the contracts, 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
forge build
```
This will generate the compiled artifacts in the out directory.

#### Inspect error selectors
### Testing

```shell
$ forge inspect <contract> errors --pretty
You can run tests to ensure the contracts work as expected.
```

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

#### Decode call data
```shell
$ cast pretty-calldata <calldata>
With Hardhat tests, run:
```

### Help

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import "hardhat-deploy";
import "@nomicfoundation/hardhat-foundry";
import 'hardhat-typechain'
import '@nomiclabs/hardhat-ethers'
import '@nomicfoundation/hardhat-chai-matchers'
import {
HardhatUserConfig,
NetworkUserConfig,
Expand All @@ -19,6 +22,26 @@ const mainnet: NetworkUserConfig = {
url: MAINNET_URL || "https://api.roninchain.com/rpc",
};

const PERMIT2X_SETTINGS = {
version: '0.8.17',
settings: {
viaIR: true,
optimizer: {
enabled: true,
runs: 1_000_000,
},
},
}

const GOVERNANCE_SETTINGS = {
version: '0.8.26',
settings: {
optimizer: {
enabled: true,
runs: 1_000_000,
},
},
}
const config: HardhatUserConfig = {
paths: {
sources: "./src",
Expand All @@ -28,6 +51,22 @@ const config: HardhatUserConfig = {
"ronin-testnet": testnet,
"ronin-mainnet": mainnet,
},

solidity: {
compilers: [PERMIT2X_SETTINGS],
overrides: {
"src/governance/KatanaGovernance.sol": GOVERNANCE_SETTINGS,
"@openzeppelin/contracts/utils/structs/EnumerableSet.sol": GOVERNANCE_SETTINGS,
"@openzeppelin/contracts/utils/Address.sol": GOVERNANCE_SETTINGS,
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": GOVERNANCE_SETTINGS,
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": GOVERNANCE_SETTINGS,
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": GOVERNANCE_SETTINGS
},
},

mocha: {
timeout: 200000,
},
};

export default config;
1 change: 0 additions & 1 deletion logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
| StorageSlot | 58 | 87 | 24,518 | 49,065 |
| TransparentUpgradeableProxy | 1,223 | 3,788 | 23,353 | 45,364 |
| V3Path.0.8.27 | 58 | 87 | 24,518 | 49,065 |

2 changes: 0 additions & 2 deletions logs/storage/AggregateRouter.sol:AggregateRouter.log

This file was deleted.

2 changes: 0 additions & 2 deletions logs/storage/Dispatcher.sol:Dispatcher.log

This file was deleted.

1 change: 0 additions & 1 deletion logs/storage/LockAndMsgSender.sol:LockAndMsgSender.log

This file was deleted.

1 change: 0 additions & 1 deletion logs/storage/V3SwapRouter.sol:V3SwapRouter.log

This file was deleted.

31 changes: 26 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,40 @@
],
"devDependencies": {
"dotenv": "^16.3.1",
"hardhat": "^2.12.7",
"hardhat-deploy": "0.11.29",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
"@nomicfoundation/hardhat-foundry": "^1.1.2",
"@nomicfoundation/hardhat-chai-matchers": "1.0.4",
"@nomiclabs/hardhat-ethers": "^2.2.2",
"@typechain/ethers-v5": "^4.0.0",
"@types/chai": "^4.2.6",
"@types/mocha": "^5.2.7",
"@uniswap/router-sdk": "^1.3.0",
"@uniswap/sdk-core": "^3.0.1",
"@uniswap/snapshot-gas-cost": "^1.0.0",
"@uniswap/v2-sdk": "^3.0.1",
"@uniswap/v3-sdk": "^3.8.3",
"bignumber.js": "^9.0.0",
"chai": "^4.3.4",
"ethers": "^5.7.2",
"hardhat": "^2.12.2",
"hardhat-typechain": "^0.3.5",
"mocha-chai-jest-snapshot": "^1.1.0",
"prettier": "^2.0.5",
"prettier-plugin-solidity": "^1.0.0-alpha.59",
"ts-generator": "^0.1.1",
"ts-node": "^8.5.4",
"typechain": "^4.0.0",
"typescript": "^3.7.3"
},
"lint-staged": {
"{src,script,test}/**/*.sol": [
"forge fmt"
]
},
"scripts": {
"prepare": "husky install"
"prepare": "husky install",
"compile": "hardhat compile",
"test": "hardhat test"
}
}
26 changes: 26 additions & 0 deletions script/ronin-testnet/20241118_DeployFixedRouter.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

import { Script, console } from "forge-std/Script.sol";
import { RouterParameters } from "@katana/operation-contracts/aggregate-router/base/RouterImmutables.sol";
import { AggregateRouter } from "@katana/operation-contracts/aggregate-router/AggregateRouter.sol";

contract Migration__20241118_DeployFixedRouter is Script {
function run() public {
RouterParameters memory params = RouterParameters({
permit2: 0xCcf4a457E775f317e0Cf306EFDda14Cc8084F82C,
weth9: 0xA959726154953bAe111746E265E6d754F48570E6,
governance: 0x247F12836A421CDC5e22B93Bf5A9AAa0f521f986,
v2Factory: 0x86587380C4c815Ba0066c90aDB2B45CC9C15E72c,
v3Factory: 0x4E7236ff45d69395DDEFE1445040A8f3C7CD8819,
pairInitCodeHash: 0x1cc97ead4d6949b7a6ecb28652b21159b9fd5608ae51a1960224099caab07dca,
poolInitCodeHash: 0xb381dabeb6037396a764deb39e57a4a3f75b641ce3e9944b1e4b18d036e322e1
});

vm.rememberKey(vm.envUint("TESTNET_PK"));
vm.broadcast();

address router = address(new AggregateRouter(params));
console.log("Aggregate Router deployed:", router);
}
}
4 changes: 2 additions & 2 deletions soldeer.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[dependencies]]
name = "@openzeppelin-contracts"
version = "4.7.0"
source = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.7.0.zip"
url = "https://github.com/OpenZeppelin/openzeppelin-contracts/archive/refs/tags/v4.7.0.zip"
checksum = "7a88a52b70872f3e428e595a03aed77c3323b118338d7256ce57dfc99eeab9e9"
integrity = "e47aca6d7bf9d4e13aba827a315bac2ab10708d1a2d219bff645a20e5d78ff85"
integrity = "40bc5e663f19cf42c5ab0ddfc049ca44d58a9f1236cef417c370af79fa8ac3a7"
16 changes: 16 additions & 0 deletions src/aggregate-router/test/ExampleModule.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

contract ExampleModule {
event ExampleModuleEvent(string message);

error CauseRevert();

function logEvent() public {
emit ExampleModuleEvent("testEvent");
}

function causeRevert() public pure {
revert CauseRevert();
}
}
10 changes: 10 additions & 0 deletions src/aggregate-router/test/ImportsForTypechain.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

import { ERC1155 } from "solmate/tokens/ERC1155.sol";
import { Permit2 } from "permit2/src/Permit2.sol";
import { TransparentUpgradeableProxy } from "@openzeppelin-contracts-4.7.0/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

// this contract only exists to pull ERC1155 and Permit2 into the hardhat build pipeline
// so that typechain artifacts are generated for it
abstract contract ImportsForTypechain is ERC1155, Permit2 { }
8 changes: 8 additions & 0 deletions src/aggregate-router/test/TestCustomErrors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.17;

contract TestCustomErrors {
// adding so that hardhat knows this custom signature selector for external contracts
error InvalidSignature();
error UnsafeCast();
}
9 changes: 0 additions & 9 deletions test/Dummy.t.sol

This file was deleted.

Loading

0 comments on commit d943d3c

Please sign in to comment.