Skip to content

Commit

Permalink
feat: implement BEP294 and BEP297 (#436)
Browse files Browse the repository at this point in the history
* feat: implement BEP294 and BEP297 (#404)

* feat: implement BEP294

* feat: add BSCGovernor and GovToken contracts for bc-fusion (#403)

* feat: implement BEP294

---------

Co-authored-by: Ethan <[email protected]>

* feat: implement BEP299 (#391)

* chore: add init lock amount (#425)

* chore: add init lock amount

* add annotations

* more comment

---------

Co-authored-by: zjubfd <[email protected]>

* chore: add redelegate fee (#426)

* feat: add comments and pause for governor (#428)

* chore: fix typo and update scripts (#429)

* feat: add apy and reward record of validators (#430)

* feat: add apy and reward record of validators

* fix review comments

* feat: add ci to bc-fusion contracts and lint code (#431)

* feat: add ci and add lint check script

* chore: lint code in BC_fusion

* chore: add bc-fusion branch to ci

* fix: test error in SlashIndicator.t.sol

* feat: add python script (#433)

* chore: fix typo

* feat: add python script

* fix review comments

* fix review comments

* chore: fix bugs and add annotation for error msgs

* fix: init params error in BSCGovernor (#439)

* chore: update storages and generate.py (#440)

* chore: disable editing moniker (#442)

* fix: update slash logic to avoid malicious slash (#444)

* chore: add check for moniker and update script (#445)

* chore: ensure burnRatio plus systemRewardRatio not greater than 100% (#446)

* fix: ensure validator incoming will be clear after distribution (#447)

* chore: add view function and update annotations (#448)

* fix: recover sig failed in token recover portal  (#451)

* fix: token recover contract recover approval sig

* docs: update abi

* fix: add generate option to tokenhub

* fix: lint

* fix: `felonySlashScope` not initialized (#452)

* fix: resolve review comments (#454)

* fix: resolve review comments

* add check to `_jailValidator`

* fix lint issue

* fix review comments

* fix: audit report (#455)

* feat: add whenNotPaused for queue in BSCGovernor (#456)

* feat: add whenNotPaused for queue in BSCGovernor

* chores: lint code

* feat: add comments

* fix: lint

* feat: add `handleSynPackage` to `StakeHub` (#457)

* feat: add `handleSynPackage` to `StakeHub`

* fix lint issue

* fix review comments

* fix unit tests

* remove `delegateVotingPower` from `StakeMigrationPackage`

* fix review comments

* update annotations

* feat: add comment for governorProtector (#460)

* feat: add comment for governorProtector

* feat: add comment for assetProtector

* chore: revert transaction when delegator in blacklist (#461)

* chore: add `tmpValidatorSetUpdated` event (#462)

* fix: sync govToken in `_doMigration` (#463)

* fix: add `isAutoUndelegate` for auto `DistributeUndelegatedSynPackage` (#464)

* fix: add `isAutoUndelegate` for auto `DistributeUndelegatedSynPackage`

* add annotation

* chore: fix issues from audit report (#465)

* chore: fix issues from audit report

* fix unit tests

* feat: deprecate `transferOut` in `TokenHub` (#466)

* feat: deprecate `transferOut` in `TokenHub`

* fix review comments

* fix: wrong jail time in `_checkValidatorSelfDelegation` (#471)

* feat: add `whenNotPaused` to slash functions (#472)

* chore: add annotation (#474)

* chore: add annotation

* chore: add annotation

* fix: disable burn in GovToken (#473)

* fix: disable burn in GovToken contract

* chores: add comments

* fix: check approval address is not 0x0 (#476)

* feat: emit NotBoundToken event (#479)

* feat: emit NotBoundToken event

* chore: add comments

* chore: update contracts init params to be consistent with mainnet setting (#480)

* docs: update tokenhub abi (#482)

* fix: add upper limit for some params (#481)

* fix: add upper limit for some params

* fix lint issue

* chore: fix review comments (#483)

* chore: fix audit issues (#485)

* chore: fix audit issues

* fix review comments

* fix review comments

* fix review comments

* chore: refactor codes (#486)

* chore: refactor codes

* fix review comments

* fmt script

* chore: fix review comments (#489)

* fix: wrong flags passed in generate:dev (#490)

* feat: add governor test (#491)

* feat: add governor test

* fix: rebase interface for stakeHub in latest bc-fusion

* fix test cases

* rename modifier name

---------

Co-authored-by: Roshan <[email protected]>

* test: add unit-test for TokenRecoverPortal (#492)

* fix report 8 issue 1

* fix report 8 issue 2

* fix report 9 issue 2

* fix report 9 issue 4

* fix report 9 issue 7

* fix ToB report issue 5

* fix ToB report issue 1

* test: add failed cases to TokenRecoverPortal unit-test (#495)

* test: add failed cases to token recover portal ut

* chore: emit owner address after TokenRecoverRequested

* docs: update token recover portal abi (#498)

* fix review comments

* fix lint issue

* fix: improve the code readablity (#499)

* fix: improve the code readablity

* fix: change the wrong comment

* fix: add check in `_forceMaintainingValidatorsExit` (#500)

* fix: add check in `_forceMaintainingValidatorsExit`

* add `latestConsensusAddress`

* chore: update npm script (#501)

* chore: update generate script

* change default `SOURCE_CHAIN_ID` in `TokenRecoverPortal`

* update testnet asset protector address

* update testnet INIT_VOTING_DELAY

* fix ut

* feat: add more tests for governor (#502)

* feat: remove whitelist check while propose, move the check to queue and execute (#503)

* fix: add check to make sure there is at least one validator in `_forceMaintainingValidatorsExit` (#504)

* fix: add check to make sure there is at least one validator in `_forceMaintainingValidatorsExit`

* optimize code

* fix: add empty address check and clear state before extracall (#507)

* chore: update tokenrecoverportal.abi (#508)

* chore: update testnet legacy address bytes (#509)

---------

Co-authored-by: Roshan <[email protected]>
Co-authored-by: Ethan <[email protected]>
Co-authored-by: dylanhuang <[email protected]>
Co-authored-by: Roshan <[email protected]>
Co-authored-by: buddho <[email protected]>
  • Loading branch information
6 people authored Feb 26, 2024
1 parent c7512be commit a563781
Show file tree
Hide file tree
Showing 135 changed files with 26,463 additions and 10,206 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
RPC_BSC=https://bsc-dataseed1.ninicoin.io

UNLOCK_RECEIVER=
OPERATOR_PRIVATE_KEY=
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Description

add a description of your changes here...

### Rationale

tell us why we need these changes...

### Example

add an example CLI or API response...

### Changes

Notable changes:
* add each change in a bullet point here
* ...
30 changes: 30 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
types: |
feat
fix
docs
style
refactor
perf
test
build
ci
chore
revert
release
59 changes: 59 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Unit Test
on:
push:
branches:
- master
- develop
- bc-fusion
pull_request:
branches:
- master
- develop
- bc-fusion
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Install Project Dependencies
run: |
npm install
forge install --no-git --no-commit foundry-rs/[email protected]
- name: Lint Check
run: |
npm run lint:check
- name: Build
run: |
forge build
- name: Start Local Chain
run: |
npm install pm2 -g
pm2 start --name local-chain "anvil -f https://bsc-dataseed1.ninicoin.io"
sleep 5
env:
PORT: 8545

- name: Unit Test
run: |
forge test --rpc-url http://127.0.0.1:8545
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ out/
pids/
logs/
cache/
broadcast/

contracts/flattened/*.sol

# foundry lib
lib/forge-std/

.env
**/.bak
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ Install foundry:
```shell script
curl -L https://foundry.paradigm.xyz | bash
foundryup
forge install --no-git --no-commit foundry-rs/forge-std@v1.1.1
forge install --no-git --no-commit foundry-rs/forge-std@v1.7.3
```

Please make sure your dependency version is as follows:

Node: v12.18.3

Install poetry:
```shell script
curl -sSL https://install.python-poetry.org | python3 -
poetry install
```

Tips: You can manage multi version of Node:
```Shell
Expand All @@ -46,7 +47,7 @@ forge test
## Flatten all system contracts

```shell script
bash flatten.sh
bash scripts/flatten.sh
```

All system contracts will be flattened and output into `${workspace}/contracts/flattened/`.
Expand All @@ -55,18 +56,18 @@ All system contracts will be flattened and output into `${workspace}/contracts/f

1. Edit `init_holders.js` file to alloc the initial BNB holder.
2. Edit `validators.js` file to alloc the initial validator set.
3. Run `bash scripts/generate-*.sh` to change system contracts setting.
3. Edit system contracts setting as needed.
4. Run `node scripts/generate-genesis.js` will generate genesis.json

## How to generate mainnet/testnet/QA genesis file
## How to generate mainnet/testnet/dev genesis file

```shell
bash scripts/generate.sh mainnet
bash scripts/generate.sh testnet
bash scripts/generate.sh QA
bash scripts/generate.sh local
poetry run python -m scripts.generate ${network}
```
Check the `genesis.json` file, and you can get the exact compiled bytecode for different network.
(`poetry run python -m scripts.generate --help ` for more details)

You can refer to `generate:dev` in `package.json` for more details about how to custom params for local dev-net.

## How to update contract interface for test

Expand Down
10 changes: 8 additions & 2 deletions abi/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ABI Files for Build-In System Contracts

| Contract Name | Address | ABI file name |
|-----------------------|--------------------------------------------|----------------------------------------------------|
| --------------------- | ------------------------------------------ | -------------------------------------------------- |
| BSCValidatorSet | 0x0000000000000000000000000000000000001000 | [bscvalidatorset](bscvalidatorset.abi) |
| SlashIndicator | 0x0000000000000000000000000000000000001001 | [slashindicator](slashindicator.abi) |
| SystemReward | 0x0000000000000000000000000000000000001002 | [systemreward](systemreward.abi) |
Expand All @@ -12,4 +12,10 @@
| GovHub | 0x0000000000000000000000000000000000001007 | [govhub](govhub.abi) |
| TokenManager | 0x0000000000000000000000000000000000001008 | [tokenmanager](tokenmanager.abi) |
| CrossChain | 0x0000000000000000000000000000000000002000 | [crosschain](crosschain.abi) |
| Staking | 0x0000000000000000000000000000000000002001 | [staking](staking.abi) |
| Staking | 0x0000000000000000000000000000000000002001 | [staking](staking.abi) |
| StakeHub | 0x0000000000000000000000000000000000002002 | [stakehub](staking.abi) |
| StakeCredit | 0x0000000000000000000000000000000000002003 | [stakecredit](stakecredit.abi) |
| BSCGovernor | 0x0000000000000000000000000000000000002004 | [bscgovernor](bscgovernor.abi) |
| GovToken | 0x0000000000000000000000000000000000002005 | [govtoken](govtoken.abi) |
| BSCTimelock | 0x0000000000000000000000000000000000002006 | [bsctimelock](bsctimelock.abi) |
| TokenRecoverPortal | 0x0000000000000000000000000000000000003000 | [tokenrecoverportal](tokenrecoverportal.abi) |
Loading

0 comments on commit a563781

Please sign in to comment.