Skip to content

Commit

Permalink
Merge pull request #51 from axieinfinity/release/v0.1.2
Browse files Browse the repository at this point in the history
chore: merge all features from 'release/v0.1.2'
  • Loading branch information
TuDo1403 authored May 21, 2024
2 parents f177e3b + a8d8ba0 commit 5f06e29
Show file tree
Hide file tree
Showing 20 changed files with 548 additions and 41 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/create-PR-deploy-to-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Create PR Deploy to Release

on:
push:
branches:
- deploy/*
pull_request:
branches:
- deploy/*

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

permissions:
contents: write
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set Env
run: |
echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: 'release/${{ env.VERSION }}'
fetch-depth: 0
fetch-tags: 'true'

- name: Get Testnet Latest Tag
if: ${{ env.NETWORK == 'testnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*testnet*" --abbrev=0)" >> $GITHUB_ENV
- name: Get Mainnet Latest Tag
if: ${{ env.NETWORK == 'mainnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*mainnet*" --abbrev=0)" >> $GITHUB_ENV
- name: Reset promotion branch
run: |
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
git reset --hard ${HEAD_BRANCH}
- name: Generate Release note
id: template
run: |
echo "VERSION=${{ env.VERSION }} - SHA: ${{ github.sha }}" > CHANGELOG.md
- name: Create Pull Request
id: cpr
uses: peter-evans/[email protected]
with:
labels: automated PR
delete-branch: true
title: 'chore(`release/${{ env.VERSION }}`): merge from `${{ env.HEAD_BRANCH}}`'
body: ${{ steps.template.outputs.result }}
branch: ${{ env.PR_BRANCH }}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
toBranch: ${{ env.FEATURE_BRANCH }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6.0.1
with:
branch: ${{ env.HEAD_BRANCH }}
base: ${{env.FEATURE_BRANCH}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
toBranch: ${{matrix.branch_name}}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6.0.1
with:
labels: automated PR
delete-branch: true
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/create-PR-release-to-network.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Create PR from release to network

on:
pull_request:
branches:
- release/*
types:
- closed

permissions:
contents: write
pull-requests: write

env:
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}
RELEASE_BRANCH: ${{ github.event.pull_request.base.ref}}

jobs:
merge-release-to-network:
runs-on: ubuntu-latest
if: ${{ (github.event.pull_request.merged == true) && (contains(github.head_ref, 'deploy') || contains(github.ref_name, 'deploy')) }}
steps:
- name: Set Env
run: |
echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env.NETWORK }}

- name: Reset promotion branch
run: |
git fetch origin ${RELEASE_BRANCH}:${RELEASE_BRANCH}
git reset --hard ${RELEASE_BRANCH}
- name: Create Pull Request
id: cpr
uses: peter-evans/[email protected]
with:
labels: automated PR
delete-branch: true
title: 'chore(`${{ env.NETWORK }}`): merge from `${{ env.HEAD_BRANCH}}`'
body: ${{ steps.template.outputs.result }}
branch: ${{env.PR_BRANCH}}
64 changes: 64 additions & 0 deletions .github/workflows/create-release-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Create Release Tag

on:
pull_request:
types: [closed]
branches:
- mainnet
- testnet

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

permissions:
contents: write
pull-requests: write

jobs:
create-release-tag:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Set Env
run: |
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ env.NETWORK }}
fetch-depth: 0
fetch-tags: 'true'

- name: Set Mainnet Tag
if: ${{ env.NETWORK == 'mainnet' }}
run: |
echo "TAG=${{ env.VERSION }}" >> $GITHUB_ENV
- name: Set Testnet Tag
if: ${{ env.NETWORK == 'testnet' }}
run: |
echo "TAG=${{ env.VERSION }}-testnet" >> $GITHUB_ENV
- name: Get Testnet Latest Tag
if: ${{ env.NETWORK == 'testnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*testnet*" --abbrev=0)" >> $GITHUB_ENV
- name: Get Mainnet Latest Tag
if: ${{ env.NETWORK == 'mainnet' }}
run: |
echo "LATESTTAG=$(git describe --tags --match "*mainnet*" --abbrev=0)" >> $GITHUB_ENV
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.TAG }}
run: |
gh release create "$tag" \
--repo "$GITHUB_REPOSITORY" \
--title "${{ env.NETWORK }} release ${{ env.VERSION }}" \
--target "${{ env.NETWORK }}" \
--notes-start-tag "${{ env.LATESTTAG }}" \
--generate-notes
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
shallow = true
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/lib/openzeppelin-contracts"]
shallow = true
8 changes: 4 additions & 4 deletions .husky/generate-layout.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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)
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 &
fileIn=out/"$contractDir"/$jsonFile
fileOut=logs/storage/"$contractDir":${jsonFile%.json}.log
node .husky/storage-logger.js "$fileIn" "$fileOut" &
done <<< "$innerdirOutputs"
done <<< "$dirOutputs"

Expand Down
4 changes: 2 additions & 2 deletions .husky/pre-push
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ forge build --sizes 2>&1 | sed -n '/Contract/,$p' > logs/contract-code-sizes.log
git add logs

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

Expand Down
67 changes: 36 additions & 31 deletions .husky/storage-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,49 @@ const fileIn = process.argv[2];
const fileOut = process.argv[3];

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

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

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

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

if (jsonData.storageLayout.storage.length == 0) {
return;
}
// Skip generating storage layout for files locate in the directory "src"
if (!jsonData.ast.absolutePath.startsWith('src')) {
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;
}
});
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);
});
}
} catch (err) {
console.error('Error parsing JSON:', err);
}
});
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
16 changes: 16 additions & 0 deletions logs/contract-code-sizes.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
| Contract | Size (B) | Margin (B) |
|---------------------------|----------|------------|
| LibErrorHandler | 86 | 24,490 |
| LibEventRange | 86 | 24,490 |
| LibNativeTransfer | 86 | 24,490 |
| LibSafeRange | 86 | 24,490 |
| Math | 86 | 24,490 |
| Panic | 86 | 24,490 |
| RONTransferHelper | 86 | 24,490 |
| RONTransferHelperExtended | 86 | 24,490 |
| SafeCast | 86 | 24,490 |
| SignedMath | 86 | 24,490 |
| Strings | 86 | 24,490 |
| TransferFromHelper | 86 | 24,490 |
| TransferHelper | 86 | 24,490 |

1 change: 1 addition & 0 deletions logs/storage/Counter.sol:Counter.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/Counter.sol:Counter:number (storage_slot: 0) (offset: 0) (type: uint256) (numberOfBytes: 32)
42 changes: 42 additions & 0 deletions src/LibEventRange.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

struct EventRange {
// uint40 is enough to represent the timestamp until year 36812
uint40 startedAt;
uint40 endedAt;
/// @dev Reserved space for future upgrades
uint176 __reserved;
}

using LibEventRange for EventRange global;

library LibEventRange {
/**
* @dev Checks whether the event range is valid.
*/
function valid(EventRange memory range) internal pure returns (bool) {
return range.startedAt <= range.endedAt;
}

/**
* @dev Returns whether the current range is not yet started.
*/
function isNotYetStarted(EventRange memory range) internal view returns (bool) {
return block.timestamp < range.startedAt;
}

/**
* @dev Returns whether the current range is ended or not.
*/
function isEnded(EventRange memory range) internal view returns (bool) {
return range.endedAt <= block.timestamp;
}

/**
* @dev Returns whether the current block is in period.
*/
function isInPeriod(EventRange memory range) internal view returns (bool) {
return range.startedAt <= block.timestamp && block.timestamp < range.endedAt;
}
}
Loading

0 comments on commit 5f06e29

Please sign in to comment.