Skip to content

Commit

Permalink
Merge pull request #80 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
chechu authored Apr 2, 2024
2 parents 9ea612f + 113ce12 commit 0f2d903
Show file tree
Hide file tree
Showing 52 changed files with 18,935 additions and 1,142 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:

- name: Export deployments
run: |
for NETWORK in bsctestnet bscmainnet ethereum sepolia; do
for NETWORK in bsctestnet bscmainnet ethereum sepolia opbnbmainnet opbnbtestnet; 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
Expand Down
88 changes: 88 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,83 @@
## [1.5.0-dev.8](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.7...v1.5.0-dev.8) (2024-03-20)

## [1.5.0-dev.7](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.6...v1.5.0-dev.7) (2024-03-20)


### Features

* updating deployment files ([4e1f600](https://github.com/VenusProtocol/protocol-reserve/commit/4e1f600cc023c263332a02c211ad11fafc9a9990))


### Bug Fixes

* local deployment of RiskFund ([aa98e23](https://github.com/VenusProtocol/protocol-reserve/commit/aa98e235feb46a951265ab2af7e5ef9769e2866b))

## [1.5.0-dev.6](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.5...v1.5.0-dev.6) (2024-03-14)


### Features

* updating deployment files ([84d13e4](https://github.com/VenusProtocol/protocol-reserve/commit/84d13e4b709451d22948748c02c95d977d69b68c))
* upgrade dependencies and export opbnbmainnet addresses ([eab12a8](https://github.com/VenusProtocol/protocol-reserve/commit/eab12a84929160b7bf7994347f81b68bfa078d96))


### Bug Fixes

* CI ([7f355dd](https://github.com/VenusProtocol/protocol-reserve/commit/7f355ddff366c22cbe166139843eb55c60d29867))
* remove unneeded dependency ([4969d8e](https://github.com/VenusProtocol/protocol-reserve/commit/4969d8e8673ac26a1802a3a2ba5fe17dbd4fbae1))

## [1.5.0-dev.5](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.4...v1.5.0-dev.5) (2024-03-05)


### Features

* psr deployments on ethereum ([9591482](https://github.com/VenusProtocol/protocol-reserve/commit/9591482b639fc6be0b61cfc19877cefb4da376e4))
* updating deployment files ([9068f88](https://github.com/VenusProtocol/protocol-reserve/commit/9068f8846b583885136bf7ce251261219b12e13f))

## [1.5.0-dev.4](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.3...v1.5.0-dev.4) (2024-03-05)


### Features

* update converter implementation deployment files ([9590f0a](https://github.com/VenusProtocol/protocol-reserve/commit/9590f0a51d61b9a33d59e7350667662950922fed))
* update converters deployment files for bscmainnet ([8dc80e9](https://github.com/VenusProtocol/protocol-reserve/commit/8dc80e99923419147b85021a19733820e16e5ddb))
* update converters deployment files for bsctestnet ([65da556](https://github.com/VenusProtocol/protocol-reserve/commit/65da55607d26bd43689e4fa5467f6fa7d7904ea1))
* updating deployment files ([eed49a2](https://github.com/VenusProtocol/protocol-reserve/commit/eed49a2bb43964ad431dd296dabbcf83aa348a6a))
* updating deployment files ([dced648](https://github.com/VenusProtocol/protocol-reserve/commit/dced648d3085d324b5f27012a1de4f3cfc9630c2))
* updating deployment files ([987a287](https://github.com/VenusProtocol/protocol-reserve/commit/987a2874e487076318e0f4f8d5e173ab9111e2a4))


### Bug Fixes

* _getAmountOut normalisation ([20d9df9](https://github.com/VenusProtocol/protocol-reserve/commit/20d9df919005adf5de618edd7377cebf271d58af))
* amountOutMantissa in _getAmountOut() ([6c74d7b](https://github.com/VenusProtocol/protocol-reserve/commit/6c74d7b4bd63c69bc931a238e2f46ed4a6e797ef))
* lint ([09885c0](https://github.com/VenusProtocol/protocol-reserve/commit/09885c04d73f4d858f23a68962cdcc72e899d260))
* round up for _getAmountIn ([498441f](https://github.com/VenusProtocol/protocol-reserve/commit/498441f21f92d38cb68bb76f3269cb38758e5ce1))
* round-up condition suggested by certik ([5486b99](https://github.com/VenusProtocol/protocol-reserve/commit/5486b9909b5d1a2257b8ac7287509e4cd697cd2b))
* spelling ([a3bd0b8](https://github.com/VenusProtocol/protocol-reserve/commit/a3bd0b8e5073410adbc426034cd6cf42a6043e5e))

## [1.5.0-dev.3](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.2...v1.5.0-dev.3) (2024-02-27)


### Bug Fixes

* compile before deploy ([c345ad5](https://github.com/VenusProtocol/protocol-reserve/commit/c345ad536b84787bee3528b396cb0fdf7ef3e96d))

## [1.5.0-dev.2](https://github.com/VenusProtocol/protocol-reserve/compare/v1.5.0-dev.1...v1.5.0-dev.2) (2024-02-26)


### Bug Fixes

* compile typechain for distribution ([f029174](https://github.com/VenusProtocol/protocol-reserve/commit/f029174bc59d71fab87d22bc429287e2aaba738b))

## [1.5.0-dev.1](https://github.com/VenusProtocol/protocol-reserve/compare/v1.4.0...v1.5.0-dev.1) (2024-01-26)


### Features

* deployment files for riskFundV2 ([9aa4058](https://github.com/VenusProtocol/protocol-reserve/commit/9aa4058f4e369c86d8b2aa232ab97d4c2e67297b))
* updating deployment files ([6d6ef46](https://github.com/VenusProtocol/protocol-reserve/commit/6d6ef46924918558534c5c09aded1184cbda6bae))

## [1.4.0](https://github.com/VenusProtocol/protocol-reserve/compare/v1.3.0...v1.4.0) (2024-01-24)


Expand Down Expand Up @@ -130,6 +210,14 @@
* VPB-13 ([b8e3e7b](https://github.com/VenusProtocol/protocol-reserve/commit/b8e3e7b5069103c005a7215598cd0ec04f306a51))
* VPB-14 ([e991342](https://github.com/VenusProtocol/protocol-reserve/commit/e99134211022180b0ca7c2f4b317ddb03d159487))

## [1.4.0-dev.3](https://github.com/VenusProtocol/protocol-reserve/compare/v1.4.0-dev.2...v1.4.0-dev.3) (2024-01-25)


### Features

* deployment files for riskFundV2 ([9aa4058](https://github.com/VenusProtocol/protocol-reserve/commit/9aa4058f4e369c86d8b2aa232ab97d4c2e67297b))
* updating deployment files ([6d6ef46](https://github.com/VenusProtocol/protocol-reserve/commit/6d6ef46924918558534c5c09aded1184cbda6bae))

## [1.4.0-dev.2](https://github.com/VenusProtocol/protocol-reserve/compare/v1.4.0-dev.1...v1.4.0-dev.2) (2024-01-24)


Expand Down
Binary file added audits/081_privateConversions_certik_20240215.pdf
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions contracts/Test/imports.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pragma solidity 0.8.13;

import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";

Check warning on line 10 in contracts/Test/imports.sol

View workflow job for this annotation

GitHub Actions / Lint

imported name UpgradeableBeacon is not used

Check warning on line 10 in contracts/Test/imports.sol

View workflow job for this annotation

GitHub Actions / Lint

imported name UpgradeableBeacon is not used
import { BeaconProxy } from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol";

Check warning on line 11 in contracts/Test/imports.sol

View workflow job for this annotation

GitHub Actions / Lint

imported name BeaconProxy is not used

Check warning on line 11 in contracts/Test/imports.sol

View workflow job for this annotation

GitHub Actions / Lint

imported name BeaconProxy is not used
import { ProxyAdmin } from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

Check warning on line 12 in contracts/Test/imports.sol

View workflow job for this annotation

GitHub Actions / Lint

imported name ProxyAdmin is not used

Check warning on line 12 in contracts/Test/imports.sol

View workflow job for this annotation

GitHub Actions / Lint

imported name ProxyAdmin is not used
42 changes: 31 additions & 11 deletions contracts/TokenConverter/AbstractTokenConverter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo

/// @notice To get the amount of tokenAddressOut tokens sender could receive on providing amountInMantissa tokens of tokenAddressIn.
/// This function does not account for potential token transfer fees(in case of deflationary tokens)
/// @notice The amountInMantissa might be adjusted if amountOutMantissa is greater than the balance of the contract for tokenAddressOut
/// @dev This function retrieves values without altering token prices
/// @param amountInMantissa Amount of tokenAddressIn
/// @param tokenAddressIn Address of the token to convert
Expand Down Expand Up @@ -574,9 +575,7 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo

/// If contract has less liquidity for tokenAddressOut than amountOutMantissa
if (maxTokenOutReserve < amountOutMantissa) {
amountConvertedMantissa =
((maxTokenOutReserve * EXP_SCALE) + tokenInToOutConversion - 1) /
tokenInToOutConversion; //round-up
amountConvertedMantissa = _divRoundingUp(maxTokenOutReserve * EXP_SCALE, tokenInToOutConversion);
amountOutMantissa = maxTokenOutReserve;
}
}
Expand Down Expand Up @@ -808,6 +807,7 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo

/// @dev Converts tokens for tokenAddressIn for the amount of tokenAddressOut used for deflationary tokens
/// it is called by convertForExactTokensSupportingFeeOnTransferTokens function
/// @notice Advising users to input a smaller amountOutMantissa to avoid potential transaction revert
/// @param amountInMaxMantissa Max amount of tokenAddressIn
/// @param amountOutMantissa Amount of tokenAddressOut required as output
/// @param tokenAddressIn Address of the token to convert
Expand Down Expand Up @@ -1089,17 +1089,16 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo
/// conversion rate after considering incentive(conversionWithIncentive)
uint256 conversionWithIncentive = MANTISSA_ONE + incentive;

tokenInToOutConversion = (tokenInUnderlyingPrice * conversionWithIncentive) / tokenOutUnderlyingPrice;
/// amount of tokenAddressOut after including incentive as amountOutMantissa will be greater than actual as it gets
/// multiplied by conversionWithIncentive which will be >= 1
amountOutMantissa =
(amountInMantissa * tokenInUnderlyingPrice * conversionWithIncentive) /
(tokenOutUnderlyingPrice * EXP_SCALE);

tokenInToOutConversion = (tokenInUnderlyingPrice * conversionWithIncentive) / tokenOutUnderlyingPrice;
amountOutMantissa = (amountInMantissa * tokenInToOutConversion) / (EXP_SCALE);
}

/// @dev To get the amount of tokenAddressIn tokens sender would send on receiving amountOutMantissa tokens of tokenAddressOut
/// @dev This function retrieves values without altering token prices.
/// @dev For user conversions, the function returns an amountInMantissa that is rounded up, ensuring that the equivalent amountInMantissa
/// is obtained from users for corresponding amountOutMantissa, preventing any losses to the protocol. However, no rounding up is required for private conversions
/// @param amountOutMantissa Amount of tokenAddressOut user wants to receive
/// @param tokenAddressIn Address of the token to convert
/// @param tokenAddressOut Address of the token to get after conversion
Expand All @@ -1126,16 +1125,29 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo
uint256 tokenOutUnderlyingPrice = priceOracle.getPrice(tokenAddressOut);

uint256 incentive = configuration.incentive;
if ((address(converterNetwork) != address(0)) && (converterNetwork.isTokenConverter(msg.sender))) {

bool isPrivateConversion = address(converterNetwork) != address(0) &&
converterNetwork.isTokenConverter(msg.sender);
if (isPrivateConversion) {
incentive = 0;
}

/// conversion rate after considering incentive(conversionWithIncentive)
uint256 conversionWithIncentive = MANTISSA_ONE + incentive;
tokenInToOutConversion = (tokenInUnderlyingPrice * conversionWithIncentive) / tokenOutUnderlyingPrice;

/// amount of tokenAddressIn after considering incentive(i.e. amountInMantissa will be less than actual amountInMantissa if incentive > 0)
amountInMantissa = ((amountOutMantissa * EXP_SCALE) + tokenInToOutConversion - 1) / tokenInToOutConversion; //round-up
if (isPrivateConversion) {
amountInMantissa =
(amountOutMantissa * tokenOutUnderlyingPrice * EXP_SCALE) /
(tokenInUnderlyingPrice * conversionWithIncentive);
} else {
amountInMantissa = _divRoundingUp(
amountOutMantissa * tokenOutUnderlyingPrice * EXP_SCALE,
tokenInUnderlyingPrice * conversionWithIncentive
);
}

tokenInToOutConversion = (tokenInUnderlyingPrice * conversionWithIncentive) / tokenOutUnderlyingPrice;
}

/// @dev Check if msg.sender is allowed to convert as per onlyForPrivateConversions flag
Expand Down Expand Up @@ -1164,4 +1176,12 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo
/// @dev Get base asset address of the destination contract
/// @return Address of the base asset
function _getDestinationBaseAsset() internal view virtual returns (address) {}

/// @dev Performs division where the result is rounded up
/// @param numerator The numerator of the division operation
/// @param denominator The denominator of the division operation. Must be non-zero
/// @return The result of the division, rounded up
function _divRoundingUp(uint256 numerator, uint256 denominator) internal pure returns (uint256) {
return (numerator + denominator - 1) / denominator;
}
}
44 changes: 44 additions & 0 deletions deploy/006-risk-fund-v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { multisigs } from "../helpers/utils";

const func: DeployFunction = async ({
network: { name, live },
getNamedAccounts,
deployments,
}: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const proxyAdmin = await ethers.getContract("DefaultProxyAdmin");
const owner = await proxyAdmin.owner();

await deploy("RiskFundV2", {
from: deployer,
contract: "RiskFundV2",
proxy: {
owner: owner,
proxyContract: "OpenZeppelinTransparentProxy",
upgradeIndex: 0,
},
autoMine: true,
log: true,
});

if (live) {
const targetOwner = (await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name];

const contract = await ethers.getContract("RiskFundV2");
if ((await contract.owner()) !== targetOwner && (await contract.pendingOwner()) !== targetOwner) {
console.log(`Transferring ownership of RiskFundV2 to ${targetOwner}`);
const tx = await contract.transferOwnership(targetOwner);
await tx.wait();
}
}
};

func.tags = ["RiskFundV2"];

export default func;
Loading

0 comments on commit 0f2d903

Please sign in to comment.