Skip to content

Commit

Permalink
added solhint and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Sep 8, 2024
1 parent d64144b commit d8bc0d4
Show file tree
Hide file tree
Showing 22 changed files with 956 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "solhint:default"
}
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This repository includes:
- **Smart Contracts**: Contracts for Yieldnest's cross-chain tokens.
- **Deployment Scripts**: Scripts for deploying and configuring the contracts across multiple chains.
- **Testing Framework**: Tests using Foundry's Forge tool.

### Key Contracts and Scripts

- **Main Contracts**:
Expand Down Expand Up @@ -70,22 +70,30 @@ forge compile
Run the tests with the following command:

```bash
forge test -vvv
yarn test
```

### Lint

To lint Solidity files using `solhint`, run:

```bash
yarn lint
```

The `-vvv` flag provides verbose output for more detailed test results.
This will check all Solidity files in the `src/`, `test/`, and `scripts/` directories for issues, adhering to the project's `solhint` configuration.

### Format

You can format your Solidity code using:

```bash
forge fmt
yarn format
```

### Deploy
### Scripts

To deploy one of the main scripts (e.g., `DeployMultiChainDeployer`), use the following pattern:
To run one of the scripts (e.g., `DeployMultiChainDeployer`), use the following pattern:

```bash
forge script script/DeployMultiChainDeployer.s.sol:DeployMultiChainDeployer \
Expand All @@ -104,14 +112,6 @@ To generate gas usage reports for the contracts, run:
forge snapshot
```

### Anvil

You can use Anvil, the local Ethereum testnet, with:

```bash
anvil
```

## Project Structure

- `src/`: Contains the core smart contracts for the project.
Expand All @@ -126,6 +126,8 @@ anvil

This project uses `husky` for Git hooks and `forge fmt` for Solidity file formatting. Pre-commit hooks are set up using `lint-staged` to automatically format `.sol` files on commit.

In addition, `solhint` is used to lint Solidity files. You can run `yarn lint` to manually check the code for common issues and enforce style guidelines.

## Documentation

For more information on Foundry and how to use it, please refer to the [Foundry Book](https://book.getfoundry.sh/).
Expand Down
7 changes: 7 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ evm_version = "cancun"
solc_version = "0.8.24"
prompt_timeout = 120

[fmt]
single_line_statement_blocks = "multi"
multiline_func_header = "all"
sort_imports = true
line_length = 115
wrap_comments = true

[rpc_endpoints]
mainnet = "${MAINNET_RPC_URL}"
arbitrum = "${ARBITRUM_RPC_URL}"
Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@
"@layerzerolabs/lz-evm-messagelib-v2": "^2.1.27",
"@layerzerolabs/lz-evm-oapp-v2": "^2.1.18",
"@layerzerolabs/lz-evm-protocol-v2": "^2.1.27",
"@layerzerolabs/lz-evm-v1-0.7": "^2.3.40",
"@openzeppelin/contracts": "4.9.2",
"@openzeppelin/contracts-upgradeable": "4.9.2",
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
"hardhat-deploy": "^0.12.4",
"husky": "^9.1.5",
"layerzero-v2": "github:JorgeAtPaladin/LayerZero-v2#lz-upgrade",
"solidity-bytes-utils": "^0.8.2"
"lint-staged": "^15.2.10",
"solhint": "^5.0.3",
"solidity-bytes-utils": "^0.8.2",
"solmate": "^6.2.0"
},
"license": "MIT",
"lint-staged": {
"*.sol": [
"forge fmt",
"solhint --fix --noPrompt"
]
},
"main": "index.js",
"repository": "https://github.com/yieldnest/yieldnest-cross-chain",
"scripts": {
"build": "yarn install && forge build",
"compile": "forge compile",
"format": "forge fmt --root .",
"test": "forge test -vvv",
"prepare": "husky"
},
"lint-staged": {
"*.sol": [
"forge fmt"
]
},
"dependencies": {
"@layerzerolabs/lz-evm-v1-0.7": "^2.3.40",
"hardhat-deploy": "^0.12.4",
"lint-staged": "^15.2.10",
"solmate": "^6.2.0"
"lint": "solhint \"src/**/*.sol\" && solhint \"test/**/*.sol\" && solhint \"script/**/*.sol\"",
"prepare": "husky",
"test": "forge test -vvv"
}
}
7 changes: 4 additions & 3 deletions script/BaseData.s.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* solhint-disable no-console */
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

Expand Down Expand Up @@ -75,9 +76,9 @@ contract BaseData is Script {
}

function isSupportedChainId(uint256 chainId) internal view returns (bool) {
bool isSupported = chainId == __chainIds.mainnet || chainId == __chainIds.base || chainId == __chainIds.fraxtal
|| chainId == __chainIds.optimism || chainId == __chainIds.arbitrum || chainId == __chainIds.holesky
|| chainId == __chainIds.fraxtalTestnet;
bool isSupported = chainId == __chainIds.mainnet || chainId == __chainIds.base
|| chainId == __chainIds.fraxtal || chainId == __chainIds.optimism || chainId == __chainIds.arbitrum
|| chainId == __chainIds.holesky || chainId == __chainIds.fraxtalTestnet;
bool isEID = __chainIdToLzEID[chainId] != 0;
return isSupported && isEID;
}
Expand Down
11 changes: 9 additions & 2 deletions script/BaseScript.s.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* solhint-disable no-console */
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

Expand Down Expand Up @@ -113,7 +114,12 @@ contract BaseScript is BaseData {
function _getDeploymentFilePath() internal view returns (string memory) {
return string(
abi.encodePacked(
vm.projectRoot(), "/deployments/", baseInput.erc20Symbol, "-", vm.toString(baseInput.l1ChainId), ".json"
vm.projectRoot(),
"/deployments/",
baseInput.erc20Symbol,
"-",
vm.toString(baseInput.l1ChainId),
".json"
)
);
}
Expand Down Expand Up @@ -142,7 +148,8 @@ contract BaseScript is BaseData {
chainJson = vm.serializeUint(chainKey, "chainId", deployment.chains[i].chainId);
chainJson = vm.serializeAddress(chainKey, "lzEndpoint", deployment.chains[i].lzEndpoint);
chainJson = vm.serializeUint(chainKey, "lzEID", deployment.chains[i].lzEID);
chainJson = vm.serializeAddress(chainKey, "multiChainDeployer", deployment.chains[i].multiChainDeployer);
chainJson =
vm.serializeAddress(chainKey, "multiChainDeployer", deployment.chains[i].multiChainDeployer);
chainJson = vm.serializeAddress(chainKey, "erc20Address", deployment.chains[i].erc20Address);
chainJson = vm.serializeAddress(chainKey, "oftAdapter", deployment.chains[i].oftAdapter);

Expand Down
12 changes: 9 additions & 3 deletions script/DeployL1OFTAdapter.s.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/* solhint-disable no-console */
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {BaseScript} from "./BaseScript.s.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";

import {L1YnOFTAdapterUpgradeable} from "@/L1YnOFTAdapterUpgradeable.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {TransparentUpgradeableProxy} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {console} from "forge-std/console.sol";

// forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter --rpc-url ${rpc} --sig "run(string calldata)" ${path} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify
// forge script script/DeployL1OFTAdapter.s.sol:DeployL1OFTAdapter \
// --rpc-url ${rpc} --sig "run(string calldata)" ${path} \
// --account ${deployerAccountName} --sender ${deployer} \
// --broadcast --etherscan-api-key ${api} --verify

contract DeployL1OFTAdapter is BaseScript {
L1YnOFTAdapterUpgradeable public l1OFTAdapter;
Expand Down
15 changes: 11 additions & 4 deletions script/DeployL2OFTAdapter.s.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/* solhint-disable no-console */
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {BaseScript} from "./BaseScript.s.sol";

import {L2YnERC20Upgradeable} from "@/L2YnERC20Upgradeable.sol";
import {L2YnOFTAdapterUpgradeable} from "@/L2YnOFTAdapterUpgradeable.sol";
import {IImmutableMultiChainDeployer} from "@interfaces/IImmutableMultiChainDeployer.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {L2YnOFTAdapterUpgradeable} from "@/L2YnOFTAdapterUpgradeable.sol";
import {L2YnERC20Upgradeable} from "@/L2YnERC20Upgradeable.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import {TransparentUpgradeableProxy} from
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {console} from "forge-std/console.sol";

// forge script script/DeployL2OFTAdapter.s.sol:DeployL2Adapter --rpc-url ${rpc} --sig "run(string memory, string memory)" ${path2ERC20Input} ${path2OFTAdapterInput} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify
// forge script script/DeployL2OFTAdapter.s.sol:DeployL2Adapter \
// --rpc-url ${rpc} --sig "run(string calldata)" ${path} \
// --account ${deployerAccountName} --sender ${deployer} \
// --broadcast --etherscan-api-key ${api} --verify

contract DeployL2OFTAdapter is BaseScript {
L2YnOFTAdapterUpgradeable l2OFTAdapter;
Expand Down
6 changes: 5 additions & 1 deletion script/DeployMultiChainDeployer.s.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* solhint-disable no-console */
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {BaseScript} from "./BaseScript.s.sol";
import {ImmutableMultiChainDeployer} from "@factory/ImmutableMultiChainDeployer.sol";
import {console} from "forge-std/console.sol";

//forge script script/DeployMultiChainDeployer.s.sol:DeployMultiChainDeployer --rpc-url ${rpc} --sig "run(string calldata)" ${path} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify
// forge script script/DeployMultiChainDeployer.s.sol:DeployMultiChainDeployer \
// --rpc-url ${rpc} --sig "run(string calldata)" ${path} \
// --account ${deployerAccountName} --sender ${deployer} \
// --broadcast --etherscan-api-key ${api} --verify

contract DeployMultiChainDeployer is BaseScript {
address public multiChainDeployerAddress;
Expand Down
10 changes: 8 additions & 2 deletions script/SetPeersOFTAdapter.s.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/* solhint-disable no-console */
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {BaseScript} from "./BaseScript.s.sol";

import {OFTAdapterUpgradeable} from
"@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oft/OFTAdapterUpgradeable.sol";
import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {OFTAdapterUpgradeable} from "@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oft/OFTAdapterUpgradeable.sol";
import "forge-std/console.sol";

// forge script script/SetPeersOFTAdapter.s.sol:SetPeersOFTAdapter --rpc-url ${rpc} --sig "run(string calldata)" ${path} --account ${deployerAccountName} --sender ${deployer} --broadcast --etherscan-api-key ${api} --verify
// forge script script/SetPeersOFTAdapter.s.sol:SetPeersOFTAdapter \
// --rpc-url ${rpc} --sig "run(string calldata)" ${path} \
// --account ${deployerAccountName} --sender ${deployer} \
// --broadcast --etherscan-api-key ${api} --verify

contract SetPeersOFTAdapter is BaseScript {
OFTAdapterUpgradeable public oftAdapter;
Expand Down
21 changes: 17 additions & 4 deletions src/L1YnOFTAdapterUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {OFTAdapterUpgradeable} from "@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oft/OFTAdapterUpgradeable.sol";
import {OFTAdapterUpgradeable} from
"@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oft/OFTAdapterUpgradeable.sol";
import {OFTUpgradeable} from "@layerzerolabs/lz-evm-oapp-v2/contracts-upgradeable/oft/OFTUpgradeable.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

import {RateLimiter} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/utils/RateLimiter.sol";
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

contract L1YnOFTAdapterUpgradeable is OFTAdapterUpgradeable, AccessControlUpgradeable, RateLimiter {
bytes32 public constant LIMITER_ROLE = keccak256("LIMITER_ROLE");
Expand All @@ -23,7 +25,14 @@ contract L1YnOFTAdapterUpgradeable is OFTAdapterUpgradeable, AccessControlUpgrad
* @param _owner The delegate capable of making OApp configurations inside of the endpoint.
* @param _rateLimitConfigs The rate limit configurations.
*/
function initialize(address _owner, RateLimitConfig[] calldata _rateLimitConfigs) external virtual initializer {
function initialize(
address _owner,
RateLimitConfig[] calldata _rateLimitConfigs
)
external
virtual
initializer
{
__OFTAdapter_init(_owner);
__Ownable_init();
__AccessControl_init();
Expand All @@ -48,7 +57,11 @@ contract L1YnOFTAdapterUpgradeable is OFTAdapterUpgradeable, AccessControlUpgrad
* @return amountSentLD The amount sent in local decimals.
* @return amountReceivedLD The amount received in local decimals on the remote.
*/
function _debit(uint256 _amountLD, uint256 _minAmountLD, uint32 _dstEid)
function _debit(
uint256 _amountLD,
uint256 _minAmountLD,
uint32 _dstEid
)
internal
virtual
override
Expand Down
2 changes: 1 addition & 1 deletion src/L2YnERC20Upgradeable.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

import {IMintableBurnableERC20} from "./interfaces/IMintableBurnableERC20.sol";

Expand Down
Loading

0 comments on commit d8bc0d4

Please sign in to comment.