-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove the need for
--via-ir
in our contracts (#502)
### Description After getting more and more annoyed with the CI time and other small issues around this I decided to really understand how big is our need for `--via-ir` compilation. Turns out it's really small. I mean really small. There are just a couple of places where this is causing issues: 1. `Airgrab#claim` has too many variables. I fixed this with a `struct` for the fractal proof, and an internal function to do the lock. Changing it is ok in my opinion. If we want to reuse this contract we'll have to redeploy it anyway, we have a tag for the version when it was deployed, all is well. 2. `GovernanceFactory#createGovernance` has too many variables. I just broke it down in internal functions. Again, I don't see a problem in changing this, even if it's deployed and etc. 3. `StableTokenV2#initialize` has too many arguments. When we made StableTokenV2 we wanted to keep the same interface for the `initialize` method to keep the interfaces between stable tokens consistent, but it was actually a bad call. There's no good reason why we have it that way and it's a method that can anyway only be called once. I would say it's ok to also change this without making a StableTokenV3 for it. Basically we will have a few contracts which will have a different signature for the initialize method that anyway can't be called anymore. But this is the one change the feels least nice. 4. A couple of tests with many variables where I used structs for grouping or broke down into internal functions. What happens afterwards, well: ``` ╰─ forge test [⠊] Compiling... [⠒] Compiling 64 files with Solc 0.5.17 [⠢] Compiling 55 files with Solc 0.8.26 [⠒] Compiling 223 files with Solc 0.8.18 [⠒] Solc 0.5.17 finished in 307.90ms [⠘] Solc 0.8.26 finished in 1.75s [⠒] Solc 0.8.18 finished in 5.50s Compiler run successful with warnings: ``` The whole fucking shabang runs in 5.5s. Jesus. CI takes ~1minute instead of ~15minutes. P.S. Thank you Claude for the bash script. ### Other changes It changed my life. ### Tested Thoroughly. ### Related issues Sleep deprivation. ### Backwards compatibility Who are you calling backward? ### Documentation I read it, yes. --------- Co-authored-by: Bayological <6872903+bayological@users.noreply.github.com> Co-authored-by: chapati <philip.paetz@me.com> Co-authored-by: philbow61 <80156619+philbow61@users.noreply.github.com> Co-authored-by: baroooo <baranseltekin@gmail.com>
- Loading branch information
1 parent
45a551d
commit d916e50
Showing
16 changed files
with
386 additions
and
255 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
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,65 @@ | ||
#!/bin/bash | ||
############################################################################## | ||
# Sometimes when hitting AST compiler errors, the output doesn't tell you | ||
# what file is causing the issue. This script helps you identify which | ||
# contract is failing by compiling each contract individually. | ||
############################################################################## | ||
|
||
# Get all contract files | ||
IFS=$'\n' read -r -d '' -a contract_files < <(find contracts test -name "*.sol" && printf '\0') | ||
|
||
# Initialize an array to store contracts that need --via-ir | ||
via_ir_contracts=() | ||
|
||
# Function to check if a contract builds without --via-ir | ||
check_contract() { | ||
local target_contract=$1 | ||
local skip_contracts=() | ||
|
||
for contract in "${contract_files[@]}"; do | ||
if [ "$contract" != "$target_contract" ]; then | ||
skip_contracts+=("$contract") | ||
fi | ||
done | ||
|
||
forge clean | ||
if forge build --skip ${skip_contracts[*]}; then | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
# Iterate through each contract | ||
for contract in "${contract_files[@]}"; do | ||
echo "----------------------------------------" | ||
echo "Checking $contract..." | ||
if check_contract "$contract"; then | ||
echo "$contract does not require --via-ir" | ||
else | ||
echo "$contract requires --via-ir" | ||
via_ir_contracts+=("$contract") | ||
fi | ||
echo "----------------------------------------" | ||
echo | ||
done | ||
|
||
# Print the results | ||
if [ ${#via_ir_contracts[@]} -eq 0 ]; then | ||
echo "All contracts can be built without --via-ir." | ||
else | ||
echo "The following contracts require --via-ir:" | ||
printf '%s\n' "${via_ir_contracts[@]}" | ||
echo | ||
echo "Use the following command to build:" | ||
echo -n "forge build --via-ir --skip " | ||
|
||
contracts_to_skip=() | ||
for contract in "${contract_files[@]}"; do | ||
if [[ ! " ${via_ir_contracts[*]} " =~ " ${contract} " ]]; then | ||
contracts_to_skip+=("$contract") | ||
fi | ||
done | ||
|
||
echo "${contracts_to_skip[*]} test/**/*" | ||
fi |
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
Oops, something went wrong.