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: merge from branch 'release/v0.1.0' #9

Merged
merged 44 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9926c61
feat: refactor migration scripts
TuDo1403 Oct 10, 2023
529915f
feat: add migration config && remove unused code
TuDo1403 Oct 14, 2023
f34dcf6
fix: resolve some issue with migration script
TuDo1403 Oct 15, 2023
c684c2b
feat: minor refactor & change run interface & remove redundant file
TuDo1403 Oct 17, 2023
35ffdea
fix: interface IScript
TuDo1403 Oct 17, 2023
89f8bf1
feat: override testnet proxy admin contract
TuDo1403 Oct 17, 2023
83cff06
fix: fix upgrade logic
TuDo1403 Oct 20, 2023
6f1e5ad
feat: refactort script
TuDo1403 Nov 4, 2023
a1a4fab
feat: add minor refactor
TuDo1403 Nov 4, 2023
75fa83f
fix: minor bug fix
TuDo1403 Nov 5, 2023
a61a3e1
forge install: openzeppelin-contracts
TuDo1403 Nov 17, 2023
5ef3edc
feat: update package
TuDo1403 Nov 17, 2023
255431b
feat: update package + minor refactor
TuDo1403 Nov 17, 2023
dbacb2d
fix: remove remappings
TuDo1403 Nov 20, 2023
e2329e3
fix: use relative mapping
TuDo1403 Nov 20, 2023
da94287
fix: use relative mapping
TuDo1403 Nov 20, 2023
c005e36
fix: use relative mapping
TuDo1403 Nov 20, 2023
cb33f0e
feat: refactor and add example script
TuDo1403 Nov 28, 2023
02d524d
chore: add virtual keyword
TuDo1403 Nov 28, 2023
b91ee76
feat: allow override artifact name with contract type, add explorer l…
TuDo1403 Nov 28, 2023
a2aa308
fix: fix overriding artifact name for _deployImmutable
TuDo1403 Nov 28, 2023
23ea6de
fix: minor bug fix
TuDo1403 Nov 28, 2023
5afc0e8
feat: add get all addresses by chain id
TuDo1403 Nov 28, 2023
dbb2a70
feat: add getter for addr => contract type
TuDo1403 Nov 29, 2023
2d3ed2a
fix: getAddress function
TuDo1403 Nov 29, 2023
bf883b1
fix: minor bug fix
TuDo1403 Nov 29, 2023
0d4962c
forge install: openzeppelin-contracts
TuDo1403 Dec 4, 2023
d674bc1
feat: add networl utilities and fn logging
TuDo1403 Dec 4, 2023
3f32848
chore: remove artifact
TuDo1403 Dec 4, 2023
84db4df
chore: fix openzeppelin version import
TuDo1403 Dec 4, 2023
67b3559
chore: add mockUpgrade function
TuDo1403 Dec 5, 2023
e9a54cc
chore: update forge-std
TuDo1403 Dec 5, 2023
8d66968
chore: add multichain example
TuDo1403 Dec 5, 2023
a20d23b
feat: add OnchainDebugger and handle different cases for proxy upgrade
TuDo1403 Dec 11, 2023
3ebdcf3
forge install: contract-libs
TuDo1403 Dec 11, 2023
13f00bb
chore: import contract-libs
TuDo1403 Dec 11, 2023
407c5fb
fix: estimate gas by default
TuDo1403 Dec 11, 2023
7c7891b
chore: setup ci/cd
TuDo1403 Dec 11, 2023
7c7da0e
Merge pull request #2 from axieinfinity/implement-feature/migration-s…
TuDo1403 Dec 11, 2023
cc92d20
Merge pull request #4 from axieinfinity/feature/migration-script
TuDo1403 Dec 11, 2023
37f5284
Merge pull request #5 from axieinfinity/merge/release/v0.1.0-feature/…
TuDo1403 Dec 11, 2023
a3715e5
chore: minor refactor
TuDo1403 Dec 12, 2023
63507d8
Merge pull request #6 from axieinfinity/implement-feature/migration-s…
TuDo1403 Dec 12, 2023
6c87d57
Merge pull request #7 from axieinfinity/feature/migration-script
TuDo1403 Dec 12, 2023
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
10 changes: 10 additions & 0 deletions .debug.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Fork block number to debug
BLOCK=0x0
# Caller
FROM=0x0000000000000000000000000000000000000000
# Callee
TO=0x0000000000000000000000000000000000000000
# Sent Value
VALUE=0x27cdb0997a65b2de99
# Call Data
CALLDATA=0x0
2 changes: 2 additions & 0 deletions .github/template/create-pull-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Description
PR to merge from [{{ .fromBranch }}](/axieinfinity/foundry-deployment-kit/tree/{{ .fromBranch }}) to [{{ .toBranch }}](/axieinfinity/foundry-deployment-kit/tree/{{ .toBranch }}).
50 changes: 50 additions & 0 deletions .github/workflows/create-PR-implement.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create Pull Request From Implement To Feature
on:
push:
branches:
- 'implement-feature/**'
- 'implement-feature/**/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- name: Set env
run: |
echo "FEATURE_NAME=$(echo ${HEAD_BRANCH} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "FEATURE_BRANCH=feature/$(echo ${HEAD_BRANCH} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "IMPLEMENT_NAME=$(echo ${HEAD_BRANCH} | cut -d'/' -f3)" >> $GITHUB_ENV

- uses: actions/checkout@v3
with:
ref: ${{env.FEATURE_BRANCH}}

- name: Reset promotion branch
run: |
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
git reset --hard ${HEAD_BRANCH}

- name: Render template
id: template
uses: chuhlomin/[email protected]
with:
template: .github/template/create-pull-request.md
vars: |
fromBranch: ${{env.HEAD_BRANCH}}
toBranch: ${{ env.FEATURE_BRANCH }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
branch: ${{ env.HEAD_BRANCH }}
base: ${{env.FEATURE_BRANCH}}
labels: automated PR
title: 'feat(${{env.FEATURE_NAME}}): implement `${{env.IMPLEMENT_NAME}}`'
body: ${{ steps.template.outputs.result }}
84 changes: 84 additions & 0 deletions .github/workflows/create-PR-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Create Pull Request From Release to Feature
on:
push:
branches:
- 'release/*'
- 'release*/*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
fetchAllFeatureBranches:
runs-on: ubuntu-latest

steps:
- id: step1
name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- id: step2
name: List all the remote feature branches
run: |
branches=$(git branch -r | grep -E '.*origin\/feature\/.*' | sed -e "s/.*origin\///" | tr "\n" " ")
JSON="["
for branch in ${branches[@]}; do
echo $branch
JSONline="\"$branch\","
# we don't need to iterate on the same branch over and over, so
# onnly include it when it wasn't included
if [[ "$JSON" != *"$JSONline"* ]]; then
JSON="$JSON$JSONline"
fi
done
# Remove last "," and add the closing bracket
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]"
echo $JSON
echo "BRANCHES={\"branch_name\": $( echo "$JSON" )}" >> "$GITHUB_OUTPUT"
outputs:
BRANCHES: ${{ steps.step2.outputs.BRANCHES }}

mergeRelease2FeatureRepo:
runs-on: ubuntu-latest
needs: fetchAllFeatureBranches
strategy:
matrix: ${{ fromJSON(needs.fetchAllFeatureBranches.outputs.BRANCHES) }}
steps:
- name: Set env
run: |
echo "PR_BRANCH=merge/${HEAD_BRANCH}-${{matrix.branch_name}}" >> $GITHUB_ENV
echo "FEATURE_NAME=$(echo ${{matrix.branch_name}} | cut -d'/' -f2)" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: ${{matrix.branch_name}}
- name: Reset promotion branch
run: |
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
git reset --hard ${HEAD_BRANCH}

- name: Render template
id: template
uses: chuhlomin/[email protected]
with:
template: .github/template/create-pull-request.md
vars: |
fromBranch: ${{env.HEAD_BRANCH}}
toBranch: ${{matrix.branch_name}}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
labels: automated PR
delete-branch: true
title: 'chore(`${{env.FEATURE_NAME}}`): merge from `${{env.HEAD_BRANCH}}`'
body: ${{ steps.template.outputs.result }}
branch: ${{env.PR_BRANCH}}
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: test

on:
push:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'
pull_request:
branches:
- mainnet
- testnet
- 'feature/*'
- 'features/*'

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

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

- name: Run Forge build
run: |
forge --version
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ out/
docs/

# Dotenv file
.env
*.env
.vscode

node_modules/
Expand Down
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/Vectorized/solady
[submodule "lib/contract-libs"]
path = lib/contract-libs
url = https://github.com/axieinfinity/contract-libs
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
16 changes: 16 additions & 0 deletions .husky/generate-layout.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

rm -rf logs/storage/*
dirOutputs=$(ls out | grep '^[^.]*\.sol$') # assuming the out dir is at 'out'
while IFS= read -r contractDir; do
innerdirOutputs=$(ls out/$contractDir)

while IFS= read -r jsonFile; do
fileIn=out/$contractDir/$jsonFile
fileOut=logs/storage/$contractDir:${jsonFile%.json}.log
node .husky/storage-logger.js $fileIn $fileOut &
done <<< "$innerdirOutputs"
done <<< "$dirOutputs"

# Wait for all background jobs to finish
wait
Empty file modified .husky/pre-commit
100755 → 100644
Empty file.
26 changes: 26 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

set -ex

# Workaround: git stash no changes doesn't cause failure but git stash pop cause
output=$(git stash)
stashed=true
if [[ $output == *"No local changes to save"* ]]; then
stashed=false
fi

forge build --sizes 2>&1 | sed -n '/Contract/,$p' > logs/contract-code-sizes.log
.husky/generate-layout.sh

git add logs

output=$(git status -s)
line_count=$(echo "$output" | wc -l)
if [ "$line_count" -gt 1 ]; then
git commit -m "chore: storage layout"
fi

if $stashed; then
git stash pop
fi
46 changes: 46 additions & 0 deletions .husky/storage-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const fs = require('fs');
const fileIn = process.argv[2];
const fileOut = process.argv[3];

if (!fileIn) {
console.error('Invalid input');
}

fs.readFile(fileIn, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}

try {
const jsonData = JSON.parse(data);
if (typeof jsonData.storageLayout == 'undefined') {
return;
}

if (jsonData.storageLayout.storage.length == 0) {
return;
}

const outputData = jsonData.storageLayout.storage
.map(({ contract, label, offset, slot, type: typeId }) => {
const typeObj = jsonData.storageLayout.types[typeId];
const typeLabel = typeObj.label;
const numberOfBytes = typeObj.numberOfBytes;
return `${contract}:${label} (storage_slot: ${slot}) (offset: ${offset}) (type: ${typeLabel}) (numberOfBytes: ${numberOfBytes})`;
})
.join('\n');
if (!fileOut) {
console.log(outputData);
} else {
fs.writeFile(fileOut, outputData, 'utf-8', err => {
if (err) {
console.error('Error writing file:', err);
return;
}
});
}
} catch (err) {
console.error('Error parsing JSON:', err);
}
});
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# foundry-deployment-kit

The collections of smart contracts that support writing deployment scripts.

## Development

### Requirement

- [Foundry forge@^0.2.0](https://book.getfoundry.sh/)

### Build & Test

- Install packages

```shell
$ forge install
```

- Build contracts

```shell
$ forge build
```

- Run test

```shell
$ forge test
```

### Deploy

```shell
$ forge script <path/to/file.s.sol> -f --private-key <your_private_key>
```
39 changes: 39 additions & 0 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Source (or "dot") the .env file to load environment variables
if [ -f .env ]; then
source .debug.env
else
echo "Error: .debug.env file not found."
fi

verify_arg=""
extra_argument=""
op_command=""

for arg in "$@"; do
case $arg in
--trezor)
op_command=""
extra_argument+=trezor@
;;
--broadcast)
op_command="op run --env-file="./.env" --"
;;
--log)
set -- "${@/#--log/}"
extra_argument+=log@
;;
*) ;;
esac
done

# Remove the @ character from the end of extra_argument
extra_argument="${extra_argument%%@}"

echo Debug Tx...
echo From: ${FROM}
echo To: ${TO}
echo Value: ${VALUE}
echo Calldata:
cast pretty-calldata ${CALLDATA}
calldata=$(cast calldata 'trace(uint256,address,address,uint256,bytes)' ${BLOCK} ${FROM} ${TO} ${VALUE} ${CALLDATA})
${op_command} forge script ${verify_arg} --legacy ${@} script/OnchainDebugger.s.sol --sig 'run(bytes,string)' ${calldata} "${extra_argument}"
1 change: 1 addition & 0 deletions deployments/ronin-mainnet/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2020
1 change: 1 addition & 0 deletions deployments/ronin-testnet/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2021
Loading
Loading