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 all features from 'release/v0.1.2' #51

Merged
merged 35 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
98deb3b
Merge pull request #19 from axieinfinity/merge/release/v0.1.0-feature…
TuDo1403 Dec 11, 2023
4101852
Merge pull request #24 from axieinfinity/merge/release/v0.1.0-feature…
TuDo1403 Dec 11, 2023
f90720a
Merge pull request #29 from axieinfinity/merge/release/v0.1.0-feature…
TuDo1403 Dec 11, 2023
64ab683
Merge pull request #32 from axieinfinity/merge/release/v0.1.0-feature…
TuDo1403 Dec 11, 2023
3dbf045
feat: add token transfer libs
huyhuynh3103 Dec 30, 2023
7e3786b
feat: add ron transfer libs
huyhuynh3103 Dec 30, 2023
301210e
feat: add legacy transfer utils
huyhuynh3103 Jan 2, 2024
7768fd1
chore: fix convention
huyhuynh3103 Jan 2, 2024
1af4175
chore: fix convention
huyhuynh3103 Jan 2, 2024
0e00588
chore: use string.concat for string combination instead
huyhuynh3103 Jan 2, 2024
adb78b0
chore: use relative import and add docs
huyhuynh3103 Jan 2, 2024
5b6a631
Merge pull request #35 from axieinfinity/implement-feature/transfer/s…
huyhuynh3103 Jan 2, 2024
2141612
Merge pull request #36 from axieinfinity/feature/transfer
TuDo1403 Jan 2, 2024
e493095
chore: remove deep clone oz
TuDo1403 Mar 14, 2024
c482e1c
chore: remove deep clone forge-std
TuDo1403 Mar 14, 2024
03cca4d
forge install: forge-std
TuDo1403 Mar 14, 2024
ffcc91e
forge install: openzeppelin-contracts
TuDo1403 Mar 14, 2024
2404114
submodule: add shallow config
TuDo1403 Mar 14, 2024
463a082
chore: uncomment sol files
TuDo1403 Mar 14, 2024
a297690
chore: add permisison for husky files
TuDo1403 Mar 14, 2024
02804a1
chore: storage layout
TuDo1403 Mar 14, 2024
e5a96dd
chore: update husky files
TuDo1403 Mar 14, 2024
2e19e0e
chore: storage layout
TuDo1403 Mar 14, 2024
ba93be9
ci: bump create pull request package version
TuDo1403 Mar 14, 2024
68388fc
ci: bump create pull request package version
TuDo1403 Mar 14, 2024
8977377
Merge pull request #40 from axieinfinity/implement-feature/lib/shallo…
TuDo1403 Mar 14, 2024
e5fdb79
Merge pull request #41 from axieinfinity/feature/lib
TuDo1403 Mar 14, 2024
b7f66ed
feat: remove send zero checks
huyhuynh3103 Mar 19, 2024
ef0f90d
Merge pull request #43 from axieinfinity/feature/remove-send-zero-checks
TuDo1403 Mar 19, 2024
9870510
Merge pull request #44 from axieinfinity/release/v0.1.0
TuDo1403 Mar 19, 2024
07d4305
Merge pull request #47 from axieinfinity/release/v0.1.1
TuDo1403 Mar 19, 2024
27aee4a
feat(LibEventRange): add LibEventRange
TuDo1403 May 21, 2024
d9d7ddb
chore: storage layout
TuDo1403 May 21, 2024
c71cab3
Merge pull request #48 from axieinfinity/implement-feature/lib-event-…
TuDo1403 May 21, 2024
a8d8ba0
Merge pull request #49 from axieinfinity/feature/lib-event-range
TuDo1403 May 21, 2024
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
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
Loading