Skip to content

Commit

Permalink
Merge pull request #9 from VenusProtocol/feat/passive-swap
Browse files Browse the repository at this point in the history
[VEN-1462]: Risk Fund and XVS Converter
  • Loading branch information
Debugger022 authored Jan 24, 2024
2 parents 6b07e7a + e5b95c4 commit bdf14b6
Show file tree
Hide file tree
Showing 97 changed files with 50,976 additions and 2,734 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ Deployed contract abis and addresses are exported in the `deployments` directory
```
$ yarn hardhat export --network <network-name> --export ./deployments/<network-name>.json
```

### Discussion

For any concerns with the protocol, open an issue or visit us on [Telegram](https://t.me/venusprotocol) to discuss.

For security concerns, please contact the administrators of our telegram chat.
Binary file not shown.
Binary file added audits/067_tokenConverter_fairyproof_20230828.pdf
Binary file not shown.
Binary file not shown.
Binary file added audits/074_tokenConverter_certik_20231107.pdf
Binary file not shown.
Binary file added audits/081_privateConversions_certik_20231127.pdf
Binary file not shown.
Binary file not shown.
6 changes: 0 additions & 6 deletions contracts/Interfaces/ComptrollerInterface.sol

This file was deleted.

10 changes: 10 additions & 0 deletions contracts/Interfaces/IComptroller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

interface IComptroller {
function isComptroller() external view returns (bool);

function markets(address) external view returns (bool);

function getAllMarkets() external view returns (address[] memory);
}
46 changes: 46 additions & 0 deletions contracts/Interfaces/IConverterNetwork.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

import { IAbstractTokenConverter } from "../TokenConverter/IAbstractTokenConverter.sol";

/**
* @title IConverterNetwork
* @author Venus
* @notice Interface implemented by `ConverterNetwork`.
*/
interface IConverterNetwork {
/// @notice Adds new converter to the array
/// @param _tokenConverter Address of the token converter
function addTokenConverter(IAbstractTokenConverter _tokenConverter) external;

/// @notice Removes converter from the array
/// @param _tokenConverter Address of the token converter
function removeTokenConverter(IAbstractTokenConverter _tokenConverter) external;

/// @notice Used to get the array of converters supporting conversions, arranged in descending order based on token balances
/// @param _tokenAddressIn Address of tokenIn
/// @param _tokenAddressOut Address of tokenOut
/// @return converters Array of the conveters on the basis of the tokens pair
/// @return convertersBalance Array of balances with respect to token out
function findTokenConverters(address _tokenAddressIn, address _tokenAddressOut)
external
returns (address[] memory converters, uint256[] memory convertersBalance);

/// @notice Used to get the array of converters supporting conversions, arranged in descending order based on token balances
/// @param _tokenAddressIn Address of tokenIn
/// @param _tokenAddressOut Address of tokenOut
/// @return converters Array of the conveters on the basis of the tokens pair
/// @return convertersBalance Array of balances with respect to token out
function findTokenConvertersForConverters(address _tokenAddressIn, address _tokenAddressOut)
external
returns (address[] memory converters, uint256[] memory convertersBalance);

/// @notice This function returns the array containing all the converters addresses
/// @return Array containing all the converters addresses
function getAllConverters() external view returns (IAbstractTokenConverter[] memory);

/// @notice This function checks for given address is converter or not
/// @param _tokenConverter Address of the token converter
/// @return boolean true if given address is converter otherwise false
function isTokenConverter(address _tokenConverter) external view returns (bool);
}
10 changes: 10 additions & 0 deletions contracts/Interfaces/IPoolRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

interface IPoolRegistry {
/// @notice Get VToken in the Pool for an Asset
function getVTokenForAsset(address comptroller, address asset) external view returns (address);

/// @notice Get the addresss of the Pools supported that include a market for the provided asset
function getPoolsSupportedByAsset(address asset) external view returns (address[] memory);
}
28 changes: 28 additions & 0 deletions contracts/Interfaces/IRiskFund.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

Check warning on line 2 in contracts/Interfaces/IRiskFund.sol

View workflow job for this annotation

GitHub Actions / Lint

Found more than One contract per file. 2 contracts found!

/**
* @title IRiskFund
* @author Venus
* @notice Interface implemented by `RiskFund`.
*/
interface IRiskFund {
function transferReserveForAuction(address comptroller, uint256 amount) external returns (uint256);

function updatePoolState(
address comptroller,
address asset,
uint256 amount
) external;

function getPoolsBaseAssetReserves(address comptroller) external view returns (uint256);
}

/**
* @title IRiskFundGetters
* @author Venus
* @notice Interface implemented by `RiskFund` for getter methods.
*/
interface IRiskFundGetters {
function convertibleBaseAsset() external view returns (address);
}
8 changes: 8 additions & 0 deletions contracts/Interfaces/IRiskFundConverter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

interface IRiskFundConverter {
function updateAssetsState(address comptroller, address asset) external;

function getPools(address asset) external view returns (address[] memory);
}
11 changes: 11 additions & 0 deletions contracts/Interfaces/IShortfall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

/**
* @title IShortfall
* @author Venus
* @notice Interface implemented by `Shortfall`.
*/
interface IShortfall {
function convertibleBaseAsset() external returns (address);
}
9 changes: 9 additions & 0 deletions contracts/Interfaces/IXVSVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

/// @title IXVSVaultProxy
/// @author Venus
/// @notice Interface implemented by `XVSVault`.
interface IXVSVault {
function xvsStore() external view returns (address);
}
7 changes: 0 additions & 7 deletions contracts/Interfaces/PoolRegistryInterface.sol

This file was deleted.

27 changes: 15 additions & 12 deletions contracts/ProtocolReserve/ProtocolShareReserve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { SafeERC20Upgradeable, IERC20Upgradeable } from "@openzeppelin/contracts
import { AccessControlledV8 } from "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { MaxLoopsLimitHelper } from "@venusprotocol/solidity-utilities/contracts/MaxLoopsLimitHelper.sol";
import { ensureNonzeroAddress } from "@venusprotocol/solidity-utilities/contracts/validators.sol";

import { IProtocolShareReserve } from "../Interfaces/IProtocolShareReserve.sol";
import { ComptrollerInterface } from "../Interfaces/ComptrollerInterface.sol";
import { PoolRegistryInterface } from "../Interfaces/PoolRegistryInterface.sol";
import { IComptroller } from "../Interfaces/IComptroller.sol";
import { IPoolRegistry } from "../Interfaces/IPoolRegistry.sol";
import { IVToken } from "../Interfaces/IVToken.sol";
import { IIncomeDestination } from "../Interfaces/IIncomeDestination.sol";

Expand Down Expand Up @@ -69,7 +70,7 @@ contract ProtocolShareReserve is
/// @notice Emitted when pool registry address is updated
event PoolRegistryUpdated(address indexed oldPoolRegistry, address indexed newPoolRegistry);

/// @notice Event emitted after the updation of the assets reserves.
/// @notice Event emitted after updating of the assets reserves.
event AssetsReservesUpdated(
address indexed comptroller,
address indexed asset,
Expand Down Expand Up @@ -122,9 +123,9 @@ contract ProtocolShareReserve is
address _wbnb,
address _vbnb
) {
if (_corePoolComptroller == address(0)) revert InvalidAddress();
if (_wbnb == address(0)) revert InvalidAddress();
if (_vbnb == address(0)) revert InvalidAddress();
ensureNonzeroAddress(_corePoolComptroller);
ensureNonzeroAddress(_wbnb);
ensureNonzeroAddress(_vbnb);

CORE_POOL_COMPTROLLER = _corePoolComptroller;
WBNB = _wbnb;
Expand All @@ -149,9 +150,10 @@ contract ProtocolShareReserve is
/**
* @dev Pool registry setter.
* @param _poolRegistry Address of the pool registry
* @custom:error ZeroAddressNotAllowed is thrown when pool registry address is zero
*/
function setPoolRegistry(address _poolRegistry) external onlyOwner {
if (_poolRegistry == address(0)) revert InvalidAddress();
ensureNonzeroAddress(_poolRegistry);
emit PoolRegistryUpdated(poolRegistry, _poolRegistry);
poolRegistry = _poolRegistry;
}
Expand All @@ -165,7 +167,7 @@ contract ProtocolShareReserve is

for (uint256 i = 0; i < configs.length; ) {
DistributionConfig memory _config = configs[i];
if (_config.destination == address(0)) revert InvalidAddress();
ensureNonzeroAddress(_config.destination);

bool updated = false;
uint256 distributionTargetsLength = distributionTargets.length;
Expand Down Expand Up @@ -313,7 +315,7 @@ contract ProtocolShareReserve is

/**
* @dev Update the reserve of the asset for the specific pool after transferring to the protocol share reserve.
* @param comptroller Comptroller address(pool)
* @param comptroller Comptroller address (pool)
* @param asset Asset address.
* @param incomeType type of income
*/
Expand All @@ -322,11 +324,12 @@ contract ProtocolShareReserve is
address asset,
IncomeType incomeType
) public override(IProtocolShareReserve) nonReentrant {
if (!ComptrollerInterface(comptroller).isComptroller()) revert InvalidAddress();
if (asset == address(0)) revert InvalidAddress();
if (!IComptroller(comptroller).isComptroller()) revert InvalidAddress();
ensureNonzeroAddress(asset);

if (
comptroller != CORE_POOL_COMPTROLLER &&
PoolRegistryInterface(poolRegistry).getVTokenForAsset(comptroller, asset) == address(0)
IPoolRegistry(poolRegistry).getVTokenForAsset(comptroller, asset) == address(0)
) revert InvalidAddress();

Schema schema = _getSchema(incomeType);
Expand Down
67 changes: 67 additions & 0 deletions contracts/ProtocolReserve/RiskFundStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;

Check warning on line 2 in contracts/ProtocolReserve/RiskFundStorage.sol

View workflow job for this annotation

GitHub Actions / Lint

Found more than One contract per file. 4 contracts found!

import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

/// @title ReserveHelpersStorage
/// @author Venus
/// @dev Reserve helpers storage
/// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
contract ReserveHelpersStorage is Ownable2StepUpgradeable {
/// @notice Deprecated slot for assetReserves mapping
bytes32 private __deprecatedSlot1;

/// @notice Available asset's fund per pool in RiskFund
/// Comptroller(pool) -> Asset -> amount
mapping(address => mapping(address => uint256)) public poolAssetsFunds;

/// @notice Deprecated slot for poolRegistry address
bytes32 private __deprecatedSlot2;
/// @notice Deprecated slot for status variable
bytes32 private __deprecatedSlot3;

/// @dev This empty reserved space is put in place to allow future versions to add new
/// variables without shifting down storage in the inheritance chain.
uint256[46] private __gap;
}

/// @title MaxLoopsLimitHelpersStorage
/// @author Venus
/// @dev Max loop limit helpers storage
/// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
contract MaxLoopsLimitHelpersStorage {
/// @notice Limit for the loops to avoid the DOS
/// @notice This state is deprecated, using it to prevent storage collision
uint256 public maxLoopsLimit;

/// @dev This empty reserved space is put in place to allow future versions to add new
/// variables without shifting down storage in the inheritance chain.
/// See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[49] private __gap;
}

/// @title RiskFundV1Storage
/// @author Venus
/// @dev Risk fund V1 storage
/// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
contract RiskFundV1Storage is ReserveHelpersStorage, MaxLoopsLimitHelpersStorage {
/// @notice Address of base asset
address public convertibleBaseAsset;
/// @notice Address of shortfall contract
address public shortfall;

/// @notice This state is deprecated, using it to prevent storage collision
address private pancakeSwapRouter;
/// @notice This state is deprecated, using it to prevent storage collision
uint256 private minAmountToConvert;
}

/// @title RiskFundV2Storage
/// @author Venus
/// @dev Risk fund V2 storage
/// @custom:security-contact https://github.com/VenusProtocol/protocol-reserve#discussion
contract RiskFundV2Storage is RiskFundV1Storage, ReentrancyGuardUpgradeable {
/// @notice Risk fund converter address
address public riskFundConverter;
}
Loading

0 comments on commit bdf14b6

Please sign in to comment.