Skip to content

Commit

Permalink
Merge pull request #104 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
chechu authored Sep 10, 2024
2 parents fb0f9fb + d01d2d4 commit c2a0228
Show file tree
Hide file tree
Showing 77 changed files with 37,181 additions and 1,916 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ DEPLOYER_PRIVATE_KEY=
#ARCHIVE_NODE_opbnbmainnet=https://opbnb-mainnet.nodereal.io/v1/<YOUR_KEY_HERE>
#ARCHIVE_NODE_arbitrumsepolia=https://sepolia-rollup.arbitrum.io/rpc
#ARCHIVE_NODE_arbitrumone=https://open-platform.nodereal.io/<YOUR_KEY_HERE>/arbitrum-nitro/
#ARCHIVE_NODE_zksyncsepolia=https://zksync-sepolia.g.alchemy.com/v2/<YOUR_KEY_HERE>
#ARCHIVE_NODE_zksyncmainnet=https://open-platform.nodereal.io/<YOUR_KEY_HERE>/zksync

ETHERSCAN_API_KEY=
REPORT_GAS=
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
**/.coverage_cache
**/.coverage_contracts
**/artifacts
**/artifacts-zk
**/build
**/cache
**/cache-zk
**/coverage
**/dist
**/node_modules
Expand Down
3 changes: 2 additions & 1 deletion .eslinttsconfigrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"jest.config.js",
"saddle.config.js",
"docgen-templates",
"commitlint.config.js"
"commitlint.config.js",
"./hardhat.config.zksync.ts"
]
}
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ jobs:
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
for NETWORK in zksyncsepolia zksyncmainnet; do
EXPORT=true yarn hardhat export --network ${NETWORK} --export ./deployments/${NETWORK}.json --config hardhat.config.zksync.ts
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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
!.yarn/sdks
!.yarn/versions
**/artifacts
**/artifacts-zk
**/build
**/cache
**/cache-zk
**/coverage
**/.coverage_artifacts
**/.coverage_cache
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
**/.coverage_cache
**/.coverage_contracts
**/artifacts
**/artifacts-zk
**/build
**/cache
**/cache-zk
**/coverage
**/dist
**/node_modules
Expand Down
58 changes: 58 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
## [2.3.0-dev.5](https://github.com/VenusProtocol/protocol-reserve/compare/v2.3.0-dev.4...v2.3.0-dev.5) (2024-09-10)


### Features

* bump dependencies with venus packages ([8f22d7f](https://github.com/VenusProtocol/protocol-reserve/commit/8f22d7f24f0146edbe074407e35ff7aee162f4c5))

## [2.3.0-dev.4](https://github.com/VenusProtocol/protocol-reserve/compare/v2.3.0-dev.3...v2.3.0-dev.4) (2024-09-10)


### Features

* add PSR deployments on zksync ([6fece9e](https://github.com/VenusProtocol/protocol-reserve/commit/6fece9ec81ec9c4fda12e3b1a511e8aa8666528e))
* redeploy PSR with updated zksolc version ([16945a3](https://github.com/VenusProtocol/protocol-reserve/commit/16945a31dbc33ed59cff8b6acc2d779683d643c4))
* updating deployment files ([bf31aba](https://github.com/VenusProtocol/protocol-reserve/commit/bf31aba8e6083f82a27c5788acb6cc115ba8f313))
* updating deployment files ([7e92b8e](https://github.com/VenusProtocol/protocol-reserve/commit/7e92b8ea9f075d68f3135addc6716c18f3458018))

## [2.3.0-dev.3](https://github.com/VenusProtocol/protocol-reserve/compare/v2.3.0-dev.2...v2.3.0-dev.3) (2024-09-05)


### Features

* add access controls and receiver to sweepTokenFromPool ([d34bf38](https://github.com/VenusProtocol/protocol-reserve/commit/d34bf3859b9eea8b06c29a568bcf19f705c93975))
* updating deployment files ([285b27e](https://github.com/VenusProtocol/protocol-reserve/commit/285b27ee2ba0bac2fb34b87a74852532376a7814))

## [2.3.0-dev.2](https://github.com/VenusProtocol/protocol-reserve/compare/v2.3.0-dev.1...v2.3.0-dev.2) (2024-08-14)


### Features

* PSR deployment on zksync sepolia ([88197ea](https://github.com/VenusProtocol/protocol-reserve/commit/88197ea1a2b37b538e0006e70a3d4d0fa0bacd50))
* updating deployment files ([5fd48dd](https://github.com/VenusProtocol/protocol-reserve/commit/5fd48dd1685f9f12d7df121df77ada7bcd27e822))


### Bug Fixes

* remove unnecessary comment ([ac7f495](https://github.com/VenusProtocol/protocol-reserve/commit/ac7f49592b2d1795e464806534693510f940af0b))
* remove unnecessary external dependency from hardhat config ([fddb63d](https://github.com/VenusProtocol/protocol-reserve/commit/fddb63d606dd11c7c59aae50808a74616541acb5))
* remove unused dependency ([1f44f5c](https://github.com/VenusProtocol/protocol-reserve/commit/1f44f5c495a7adf1d14ebd938a8aa83d348573f9))

## [2.3.0-dev.1](https://github.com/VenusProtocol/protocol-reserve/compare/v2.2.0...v2.3.0-dev.1) (2024-06-20)


### Features

* updating deployment files ([2331045](https://github.com/VenusProtocol/protocol-reserve/commit/233104539bc35d8ce99ed7d170c3a7b4f7f3b7fb))
* updating deployment files ([a2ff8de](https://github.com/VenusProtocol/protocol-reserve/commit/a2ff8de3b1d26b91d25c64f8dba3f0d75a3f010e))
* updating deployment files ([3df1a06](https://github.com/VenusProtocol/protocol-reserve/commit/3df1a063834266a75dac385b36600c097fb8eab6))
* updating deployment files ([6cee196](https://github.com/VenusProtocol/protocol-reserve/commit/6cee196a414ea691a621f34100bffaece85fc73a))
* updating deployment files ([8657319](https://github.com/VenusProtocol/protocol-reserve/commit/8657319650ba1bd6a7bacb9ce8ef565fd9538786))


### Bug Fixes

* deployment scripts ([c5aaf2b](https://github.com/VenusProtocol/protocol-reserve/commit/c5aaf2b0575d912ea22250e63913d2c286fa92ad))
* typo in file name ([5e00e66](https://github.com/VenusProtocol/protocol-reserve/commit/5e00e66f3a3a17d276c5eaf86de62ffa768cdb36))
* USDT Etherum approval ([5a04ca7](https://github.com/VenusProtocol/protocol-reserve/commit/5a04ca70ff4eac37bdc28013271274b5b88d8e5c))

## [2.2.0](https://github.com/VenusProtocol/protocol-reserve/compare/v2.1.0...v2.2.0) (2024-05-31)


Expand Down
Binary file added audits/117_riskFundUpgrade_certik_20240826.pdf
Binary file not shown.
25 changes: 17 additions & 8 deletions contracts/ProtocolReserve/RiskFundV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {
event SweepToken(address indexed token, address indexed to, uint256 amount);

/// @notice Event emitted when tokens are swept and transferred from pool
event SweepTokenFromPool(address indexed token, address indexed comptroller, uint256 amount);
event SweepTokenFromPool(
address indexed token,
address indexed comptroller,
address indexed receiver,
uint256 amount
);

/// @notice Error is thrown when updatePoolState is not called by riskFundConverter
error InvalidRiskFundConverter();
Expand Down Expand Up @@ -146,19 +151,23 @@ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {

/// @notice Function to sweep token from pool
/// @param tokenAddress Address of the asset(token)
/// @param comptroller Pool address to which assets will be transferred
/// @param comptroller Pool address that the assets belong to
/// @param receiver The receiver of the funds
/// @param amount Amount need to sweep from the pool
/// @custom:event Emits sweepTokenFromPool event on success
/// @custom:error ZeroAddressNotAllowed is thrown when tokenAddress/comptroller address is zero
/// @custom:event Emits SweepTokenFromPool event on success
/// @custom:error ZeroAddressNotAllowed is thrown when tokenAddress, comptroller, or receiver address is zero
/// @custom:error ZeroValueNotAllowed is thrown when amount is zero
/// @custom:access Only Governance
/// @custom:access Controlled by AccessControlManager
function sweepTokenFromPool(
address tokenAddress,
address comptroller,
address receiver,
uint256 amount
) external onlyOwner nonReentrant {
) external nonReentrant {
_checkAccessAllowed("sweepTokenFromPool(address,address,address,uint256)");
ensureNonzeroAddress(tokenAddress);
ensureNonzeroAddress(comptroller);
ensureNonzeroAddress(receiver);
ensureNonzeroValue(amount);

uint256 poolReserve = poolAssetsFunds[comptroller][tokenAddress];
Expand All @@ -171,9 +180,9 @@ contract RiskFundV2 is AccessControlledV8, RiskFundV2Storage, IRiskFund {
poolAssetsFunds[comptroller][tokenAddress] = poolReserve - amount;
}

IERC20Upgradeable(tokenAddress).safeTransfer(comptroller, amount);
IERC20Upgradeable(tokenAddress).safeTransfer(receiver, amount);

emit SweepTokenFromPool(tokenAddress, comptroller, amount);
emit SweepTokenFromPool(tokenAddress, comptroller, receiver, amount);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/TokenConverter/AbstractTokenConverter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo

uint256 balanceBefore = IERC20Upgradeable(tokenAddressIn).balanceOf(_destinationAddress);

IERC20Upgradeable(tokenAddressOut).approve(converterAddresses[i], amountIn);
IERC20Upgradeable(tokenAddressOut).forceApprove(converterAddresses[i], amountIn);
IAbstractTokenConverter(converterAddresses[i]).convertExactTokens(
amountIn,
0,
Expand Down
11 changes: 10 additions & 1 deletion deploy/001-psr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,27 @@ const func: DeployFunction = async ({
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const loopsLimit = 20;

const defaultProxyAdmin = await hre.artifacts.readArtifact(
"hardhat-deploy/solc_0.8/openzeppelin/proxy/transparent/ProxyAdmin.sol:ProxyAdmin",
);

await deploy("ProtocolShareReserve", {
from: deployer,
log: true,
deterministicDeployment: false,
args: [comptrollerAddress, WBNBAddress, vBNBAddress],
skipIfAlreadyDeployed: true,
proxy: {
owner: live ? timelockAddress : deployer,
proxyContract: "OpenZeppelinTransparentProxy",
proxyContract: "OptimizedTransparentUpgradeableProxy",
execute: {
methodName: "initialize",
args: [acmAddress, loopsLimit],
},
viaAdminContract: {
name: "DefaultProxyAdmin",
artifact: defaultProxyAdmin,
},
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const func = async ({ network: { live, name }, getNamedAccounts, deployments }:

const xvsAddress = (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_ONE;
const proxyOwnerAddress =
(await ethers.getContractOrNull("NormalTimelock"))?.address || ADDRESS_ONE || multisigs[name];
(await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name] || ADDRESS_ONE;
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const xvsVaultAddress = (await ethers.getContractOrNull("XVSVaultProxy"))?.address || ADDRESS_ONE;

Expand Down
62 changes: 51 additions & 11 deletions deploy/004-single-token-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,61 @@ import { DeployResult } from "hardhat-deploy/dist/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESS_ONE, ADDRESS_TWO } from "../helpers/utils";
import { ADDRESS_ONE, ADDRESS_TWO, multisigs } from "../helpers/utils";

interface BaseAssets {
[key: string]: string;
}

async function getBaseAssets(network: string): Promise<BaseAssets> {
const networkBaseAssets: { [key: string]: BaseAssets } = {
bsctestnet: {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
bscmainnet: {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
sepolia: {
USDTPrimeConverter: (await ethers.getContractOrNull("MockUSDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("MockUSDC"))?.address || ADDRESS_ONE,
WBTCPrimeConverter: (await ethers.getContractOrNull("MockWBTC"))?.address || ADDRESS_ONE,
WETHPrimeConverter: "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9", // WETH on Sepolia
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
ethereum: {
USDTPrimeConverter: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT on Ethereum
USDCPrimeConverter: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
WBTCPrimeConverter: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", // WBTC on Ethereum
WETHPrimeConverter: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH on Ethereum
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
// add more networks
};
return networkBaseAssets[network];
}

const MIN_AMOUNT_TO_CONVERT = parseUnits("10", 18).toString();

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deployments, getNamedAccounts, network } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const baseAssets: BaseAssets = {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
};
const networkName = network.name;
const baseAssets: BaseAssets = await getBaseAssets(networkName);

const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const oracleAddress = (await ethers.getContractOrNull("ResilientOracle"))?.address || ADDRESS_ONE;
const proxyOwnerAddress =
(await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[networkName] || ADDRESS_ONE;

const singleTokenConverterImp: DeployResult = await deploy("SingleTokenConverterImp", {
contract: "SingleTokenConverter",
Expand Down Expand Up @@ -57,16 +89,24 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const args: string[] = [acmAddress, oracleAddress, destinationAddress, baseAsset, MIN_AMOUNT_TO_CONVERT];

await deploy(singleTokenConverterName, {
const converterProxy: DeployResult = await deploy(singleTokenConverterName, {
from: deployer,
contract: "BeaconProxy",
args: [SingleTokenConverterBeacon.address, SingleTokenConverter.interface.encodeFunctionData("initialize", args)],
log: true,
autoMine: true,
});

if (network.live) {
const converter = await ethers.getContractAt("SingleTokenConverter", converterProxy.address);

const tx = await converter.transferOwnership(proxyOwnerAddress);
await tx.wait();
console.log(`Transferred ownership of ${singleTokenConverterName} to Timelock: ` + proxyOwnerAddress);
}
}
};

func.tags = ["SingleTokenConverter"];
func.tags = ["SingleTokenConverter", "Converters"];

export default func;
2 changes: 1 addition & 1 deletion deploy/005-converter-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ const func = async ({ network: { live, name }, getNamedAccounts, deployments }:
}
};

func.tags = ["ConverterNetwork"];
func.tags = ["ConverterNetwork", "Converters"];

export default func;
7 changes: 6 additions & 1 deletion deployments/bscmainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -7669,7 +7669,7 @@
]
},
"RiskFundV2_Implementation": {
"address": "0x2F377545Fd095fA59A56Cb1fD7456A2a0B781Cb6",
"address": "0x7Ef5ABbcC9A701e728BeB7Afd4fb5747fAB15A28",
"abi": [
{
"inputs": [],
Expand Down Expand Up @@ -8219,6 +8219,11 @@
"name": "comptroller",
"type": "address"
},
{
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
Expand Down
Loading

0 comments on commit c2a0228

Please sign in to comment.