Skip to content

Commit

Permalink
Merge pull request #55 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
chechu authored Dec 27, 2023
2 parents f3196a0 + 9f85320 commit 0d12b98
Show file tree
Hide file tree
Showing 21 changed files with 4,981 additions and 556 deletions.
21 changes: 16 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# true or false
FORK=false
FORKED_NETWORK=bscmainnet

MNEMONIC="here is where your twelve words mnemonic should be put my friend"
BSCSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
BSC_ARCHIVE_NODE="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
DEPLOYER_PRIVATE_KEY="E9873D79C6D87DC0FB6A5778633389F4453213303DA61F20BD67FC233AA33262"
BSC_TESTNET_NODE="https://data-seed-prebsc-1-s1.binance.org:8545"
BSC_MAINNET_NODE="https://bsc-dataseed.binance.org/"
DEPLOYER_PRIVATE_KEY=

## Archive nodes
#ARCHIVE_NODE_bsctestnet=https://bsc-testnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_bscmainnet=https://bsc-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_bscmainnet=http://127.0.0.1:1248
#ARCHIVE_NODE_sepolia=https://ethereum-sepolia.blockpi.network/v1/rpc/public
#ARCHIVE_NODE_ethereum=https://eth-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_ethereum=http://127.0.0.1:1248

ETHERSCAN_API_KEY=
REPORT_GAS=
78 changes: 78 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ jobs:
- name: "Test the contracts and generate the coverage report"
run: "npx hardhat coverage"

- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: coverage/**/cobertura-coverage.xml
badge: true
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "50 80"

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md

docgen:
name: Docgen
runs-on: ubuntu-latest
Expand All @@ -69,3 +89,61 @@ jobs:

- name: Create docgen
run: yarn docgen

deploy:
name: Deploy
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 18
cache: "yarn"

- name: Install dependencies
# Hack to get around failing "ethereumjs-abi The remote archive doesn't match the expected checksum" error
run: YARN_CHECKSUM_BEHAVIOR=update yarn

- name: Build
run: yarn build

- name: Verify deployments work
run: yarn hardhat deploy

export-deployments:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Check out code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.VENUS_TOOLS_TOKEN }}

- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 18
cache: "yarn"

- name: Install dependencies
# Hack to get around failing "ethereumjs-abi The remote archive doesn't match the expected checksum" error
run: YARN_CHECKSUM_BEHAVIOR=update yarn

- name: Export deployments
run: |
for NETWORK in bsctestnet bscmainnet ethereum sepolia; do
EXPORT=true yarn hardhat export --network ${NETWORK} --export ./deployments/${NETWORK}.json
jq -M '{name, chainId, addresses: .contracts | map_values(.address)}' ./deployments/${NETWORK}.json > ./deployments/${NETWORK}_addresses.json
done
yarn prettier
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "feat: updating deployment files"
file_pattern: "deployments/*.json"
2 changes: 1 addition & 1 deletion .solcover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
istanbulReporter: ["html", "lcov"],
istanbulReporter: ["html", "lcov", "cobertura"],
providerOptions: {
mnemonic: process.env.MNEMONIC,
},
Expand Down
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "solhint:recommended",
"rules": {
"code-complexity": ["error", 8],
"compiler-version": ["error", ">=0.5.0"],
"compiler-version": ["error", ">=0.8.0"],
"const-name-snakecase": "off",
"constructor-syntax": "error",
"func-visibility": ["error", { "ignoreConstructors": true }],
Expand Down
84 changes: 84 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
## [1.2.0-dev.7](https://github.com/VenusProtocol/protocol-reserve/compare/v1.2.0-dev.6...v1.2.0-dev.7) (2023-12-22)


### Bug Fixes

* remove compiler version 0.5.16 ([cdb9c51](https://github.com/VenusProtocol/protocol-reserve/commit/cdb9c5120af9436646647276d4fc29e2e471041d))

## [1.2.0-dev.6](https://github.com/VenusProtocol/protocol-reserve/compare/v1.2.0-dev.5...v1.2.0-dev.6) (2023-12-12)


### Features

* build and package typescript deployment files ([2361ca0](https://github.com/VenusProtocol/protocol-reserve/commit/2361ca09c7b7ca015ad2d5295fad34a7fd68c38b))
* generate file only with addresses of deployed contracts ([0858c7e](https://github.com/VenusProtocol/protocol-reserve/commit/0858c7e0c6949798e45234b5ae301581bd5caaa2))
* updating deployment files ([4d69337](https://github.com/VenusProtocol/protocol-reserve/commit/4d69337e4a36e80d7bf95d2cfa4a4b667fe5a49d))
* updating deployment files ([4027513](https://github.com/VenusProtocol/protocol-reserve/commit/402751354f9c7d900560fe3627f1ba3b27b03592))
* updating deployment files ([b9c516c](https://github.com/VenusProtocol/protocol-reserve/commit/b9c516cf3d0f4405f2412d6dc80f2d9e21454043))
* updating deployment files ([11c43ae](https://github.com/VenusProtocol/protocol-reserve/commit/11c43aea6728ee865494d2d379022202afa4b05b))
* updating deployment files ([c295957](https://github.com/VenusProtocol/protocol-reserve/commit/c295957d7ae1471124d4a131045c235fc93aae2b))
* updating deployment files ([d6d9557](https://github.com/VenusProtocol/protocol-reserve/commit/d6d9557c01173350d29b7c10fe6020935f776d48))


### Bug Fixes

* add coverage report ([1ebdf3d](https://github.com/VenusProtocol/protocol-reserve/commit/1ebdf3d37d42db35c95fb17880f972ec7ff99cdd))
* added cobertura report ([70ed511](https://github.com/VenusProtocol/protocol-reserve/commit/70ed511ec928935450d6c30fce5d1625f649c6a3))
* added types ([ac83c2c](https://github.com/VenusProtocol/protocol-reserve/commit/ac83c2c718762d8faf3ebc75a6ff3c4587acac4b))
* exclude external deployments when exporting ([da32649](https://github.com/VenusProtocol/protocol-reserve/commit/da32649a69c4b9eebcb8b563b94ea694c993efa3))
* fix build with missing type ([1c71743](https://github.com/VenusProtocol/protocol-reserve/commit/1c71743f918ffd6f0d697fab0aef7609665d42c4))
* fixed compile and lint issues ([41cdc93](https://github.com/VenusProtocol/protocol-reserve/commit/41cdc938fc2ef079169ca93ced621b90e6b28824))
* fixed compile and lint issues ([77de73a](https://github.com/VenusProtocol/protocol-reserve/commit/77de73a37e50eb3b25cb57d0981bc90d31940a58))
* fixed lint ([dbf1864](https://github.com/VenusProtocol/protocol-reserve/commit/dbf1864819bf4c04eb66d21aba27922dc227a594))
* fixed lint ([f269468](https://github.com/VenusProtocol/protocol-reserve/commit/f26946885c46bcf100a0f3922effd71f11bcb56b))
* fixed proxy address ([de9df20](https://github.com/VenusProtocol/protocol-reserve/commit/de9df206c4d2ba903e50dd6f553bc16ab8241e3a))
* remove exports from package.json ([747eabf](https://github.com/VenusProtocol/protocol-reserve/commit/747eabf1d2ec34137d26ecb8063f9b8c3fff11e5))
* removed path and fixed lint ([753b565](https://github.com/VenusProtocol/protocol-reserve/commit/753b565822b4d1c6c06bc14da5a14d8d98afc518))
* removed report formats ([88ece40](https://github.com/VenusProtocol/protocol-reserve/commit/88ece407529d703139cfd8b8ae51e52c1752e730))
* resolved conflict ([a4efd48](https://github.com/VenusProtocol/protocol-reserve/commit/a4efd48e0f0cf0c478aade1857dd40e591db2bce))
* revert DefaultProxyAdmin addr ([89b916a](https://github.com/VenusProtocol/protocol-reserve/commit/89b916a95701621148ab0cc3cc567b1499989068))
* unify the use of the env variable DEPLOYER_PRIVATE_KEY ([e766787](https://github.com/VenusProtocol/protocol-reserve/commit/e7667879c9a9a8dc1cfd8060ebcc0864ccdacd87))
* use imported address and change export ([9aa8473](https://github.com/VenusProtocol/protocol-reserve/commit/9aa8473193f0398a2abe208fa55d13308ca49739))

## [1.2.0-dev.5](https://github.com/VenusProtocol/protocol-reserve/compare/v1.2.0-dev.4...v1.2.0-dev.5) (2023-12-11)


### Bug Fixes

* max percent in psr ([0914d83](https://github.com/VenusProtocol/protocol-reserve/commit/0914d83a70807138a395110dbf30934c7b6eb12b))

## [1.2.0-dev.4](https://github.com/VenusProtocol/protocol-reserve/compare/v1.2.0-dev.3...v1.2.0-dev.4) (2023-12-05)


### Features

* build and package typescript deployment files ([70ea3f9](https://github.com/VenusProtocol/protocol-reserve/commit/70ea3f9c32d8fb6f8a519027c9118ec520b366bc))

## [1.2.0-dev.3](https://github.com/VenusProtocol/protocol-reserve/compare/v1.2.0-dev.2...v1.2.0-dev.3) (2023-12-01)


### Features

* generate file only with addresses of deployed contracts ([063d8d2](https://github.com/VenusProtocol/protocol-reserve/commit/063d8d2dd5405330f30b523bd56829be074fef9e))
* updating deployment files ([c2a2296](https://github.com/VenusProtocol/protocol-reserve/commit/c2a2296d8e81299c5ffad64b3060f6a7a809b8b8))


### Bug Fixes

* unify the use of the env variable DEPLOYER_PRIVATE_KEY ([59ee4ad](https://github.com/VenusProtocol/protocol-reserve/commit/59ee4ad49f8b950fb36a1da307431dc11aa980c8))

## [1.2.0-dev.2](https://github.com/VenusProtocol/protocol-reserve/compare/v1.2.0-dev.1...v1.2.0-dev.2) (2023-11-28)


### Bug Fixes

* remove exports from package.json ([e61df95](https://github.com/VenusProtocol/protocol-reserve/commit/e61df958c0bb272b72cb634c6e09cbcba6cbc548))

## [1.2.0-dev.1](https://github.com/VenusProtocol/protocol-reserve/compare/v1.1.0...v1.2.0-dev.1) (2023-11-17)


### Features

* add github job to export and commit deployment by network ([475fe58](https://github.com/VenusProtocol/protocol-reserve/commit/475fe5845aca75b9f47a11ada68f2090d4a45bb6))
* updating deployment files ([94151cd](https://github.com/VenusProtocol/protocol-reserve/commit/94151cd6d0ea37b6765833c767392bcbbd687e43))

## [1.1.0](https://github.com/VenusProtocol/protocol-reserve/compare/v1.0.0...v1.1.0) (2023-11-01)


Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ MNEMONIC="<>" BSC_API_KEY="<>" npx hardhat run ./script/hardhat/deploy.ts --netw
Documentation is autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).

They can be generated by running `yarn docgen`

### Deployments

Deployments are managed using [hardhat-deploy](https://github.com/wighawag/hardhat-deploy).
Deployment scripts are in the `deploy` directory and run automatically when starting the hardhat node.

Deployed contract abis and addresses are exported in the `deployments` directory. To create a summary export of all contracts deployed to a network run

```
$ yarn hardhat export --network <network-name> --export ./deployments/<network-name>.json
```
14 changes: 7 additions & 7 deletions contracts/ProtocolReserve/ProtocolShareReserve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract ProtocolShareReserve is
struct DistributionConfig {
Schema schema;
/// @dev percenatge is represented without any scale
uint8 percentage;
uint16 percentage;
address destination;
}

Expand All @@ -55,7 +55,7 @@ contract ProtocolShareReserve is
/// @notice address of pool registry contract
address public poolRegistry;

uint8 public constant MAX_PERCENT = 100;
uint16 public constant MAX_PERCENT = 1e4;

/// @notice comptroller => asset => schema => balance
mapping(address => mapping(address => mapping(Schema => uint256))) public assetsReserves;
Expand Down Expand Up @@ -99,16 +99,16 @@ contract ProtocolShareReserve is
/// @notice Event emitted when distribution configuration is updated
event DistributionConfigUpdated(
address indexed destination,
uint8 oldPercentage,
uint8 newPercentage,
uint16 oldPercentage,
uint16 newPercentage,
Schema schema
);

/// @notice Event emitted when distribution configuration is added
event DistributionConfigAdded(address indexed destination, uint8 percentage, Schema schema);
event DistributionConfigAdded(address indexed destination, uint16 percentage, Schema schema);

/// @notice Event emitted when distribution configuration is removed
event DistributionConfigRemoved(address indexed destination, uint8 percentage, Schema schema);
event DistributionConfigRemoved(address indexed destination, uint16 percentage, Schema schema);

/**
* @dev Constructor to initialize the immutable variables
Expand Down Expand Up @@ -424,7 +424,7 @@ contract ProtocolShareReserve is
*/
function _ensurePercentages() internal view {
uint256 totalSchemas = uint256(type(Schema).max) + 1;
uint8[] memory totalPercentages = new uint8[](totalSchemas);
uint16[] memory totalPercentages = new uint16[](totalSchemas);

uint256 distributionTargetsLength = distributionTargets.length;
for (uint256 i = 0; i < distributionTargetsLength; ) {
Expand Down
54 changes: 19 additions & 35 deletions deploy/1-deploy.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
import mainnetDeployments from "@venusprotocol/venus-protocol/networks/mainnet.json";
import testnetDeployments from "@venusprotocol/venus-protocol/networks/testnet.json";
import hre, { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const ADDRESSES: any = {
bsctestnet: {
vBNBAddress: testnetDeployments.Contracts.vBNB,
comptroller: testnetDeployments.Contracts.Unitroller,
WBNBAddress: "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
timelock: testnetDeployments.Contracts.Timelock,
acm: "0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA",
},
bscmainnet: {
vBNBAddress: mainnetDeployments.Contracts.vBNB,
comptroller: mainnetDeployments.Contracts.Unitroller,
WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
timelock: mainnetDeployments.Contracts.Timelock,
acm: "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555",
},
sepolia: {
vBNBAddress: ethers.constants.AddressZero,
comptroller: ethers.constants.AddressZero,
WBNBAddress: ethers.constants.AddressZero,
timelock: ethers.constants.AddressZero,
acm: ethers.constants.AddressZero,
},
};

module.exports = async ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => {
const func: DeployFunction = async ({
network: { live },
getNamedAccounts,
deployments,
}: HardhatRuntimeEnvironment) => {
const MOCK_ADDRESS = live ? undefined : "0x0000000000000000000000000000000000000001";
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const networkName = network.name;

const { vBNBAddress, comptroller, WBNBAddress, timelock, acm } = ADDRESSES[networkName];
const vBNBAddress = (await ethers.getContractOrNull("vBNB"))?.address || MOCK_ADDRESS;
const comptrollerAddress = (await ethers.getContractOrNull("Unitroller"))?.address || MOCK_ADDRESS;
const WBNBAddress = (await ethers.getContractOrNull("WBNB"))?.address || MOCK_ADDRESS;
const timelockAddress = (await ethers.getContractOrNull("NormalTimelock"))?.address || MOCK_ADDRESS;
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || MOCK_ADDRESS;
const loopsLimit = 20;

await deploy("ProtocolShareReserve", {
from: deployer,
log: true,
deterministicDeployment: false,
args: [comptroller, WBNBAddress, vBNBAddress],
args: [comptrollerAddress, WBNBAddress, vBNBAddress],
proxy: {
owner: timelock,
owner: timelockAddress,
proxyContract: "OpenZeppelinTransparentProxy",
execute: {
methodName: "initialize",
args: [acm, loopsLimit],
args: [acmAddress, loopsLimit],
},
},
});
Expand All @@ -55,10 +37,12 @@ module.exports = async ({ getNamedAccounts, deployments, network }: HardhatRunti
const psrOwner = await psr.owner();

if (psrOwner === deployer) {
const tx = await psr.transferOwnership(ADDRESSES[networkName].timelock);
const tx = await psr.transferOwnership(timelockAddress);
await tx.wait();
console.log("Transferred ownership of PSR to Timelock");
}
};

module.exports.tags = ["deploy"];
func.tags = ["deploy"];

export default func;
Loading

0 comments on commit 0d12b98

Please sign in to comment.