Skip to content

Commit

Permalink
Merge branch 'develop' into VEN-1831
Browse files Browse the repository at this point in the history
  • Loading branch information
Debugger022 committed Apr 23, 2024
2 parents 967dbbf + 425e718 commit d40f440
Show file tree
Hide file tree
Showing 202 changed files with 70,761 additions and 6,579 deletions.
362 changes: 362 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
SHELL ["/bin/bash", "-c"]
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash
RUN apt -y install nodejs
RUN wget https://github.com/ethereum/solidity/releases/download/v0.8.13/solc-static-linux -O /usr/bin/solc && chmod +x /usr/bin/solc
RUN wget https://github.com/ethereum/solidity/releases/download/v0.8.25/solc-static-linux -O /usr/bin/solc && chmod +x /usr/bin/solc

RUN mkdir -p /usr/app
WORKDIR /usr/app
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The `Comptroller` also includes two functions `liquidateAccount()` and `healAcco
## Prerequisites

- NodeJS - 12.x
- Solc - v0.8.13 (https://github.com/ethereum/solidity/releases/tag/v0.8.13)
- Solc - v0.8.25 (https://github.com/ethereum/solidity/releases/tag/v0.8.25)

## Installing

Expand Down
Binary file added audits/092_nativeTokenGateway_certik_20240226.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/BaseJumpRateModelV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { IAccessControlManagerV8 } from "@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol";

Expand Down
34 changes: 32 additions & 2 deletions contracts/Comptroller.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { Ownable2StepUpgradeable } from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import { ResilientOracleInterface } from "@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol";
import { AccessControlledV8 } from "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
import { IPrime } from "@venusprotocol/venus-protocol/contracts/Tokens/Prime/Interfaces/IPrime.sol";

import { ComptrollerInterface } from "./ComptrollerInterface.sol";
import { ComptrollerInterface, Action } from "./ComptrollerInterface.sol";
import { ComptrollerStorage } from "./ComptrollerStorage.sol";
import { ExponentialNoError } from "./ExponentialNoError.sol";
import { VToken } from "./VToken.sol";
Expand Down Expand Up @@ -98,6 +98,9 @@ contract Comptroller is
/// @notice Emitted when forced liquidation is enabled or disabled for a market
event IsForcedLiquidationEnabledUpdated(address indexed vToken, bool enable);

/// @notice Emitted when the borrowing or redeeming delegate rights are updated for an account
event DelegateUpdated(address indexed approver, address indexed delegate, bool approved);

/// @notice Thrown when collateral factor exceeds the upper bound
error InvalidCollateralFactor();

Expand Down Expand Up @@ -155,6 +158,9 @@ contract Comptroller is
/// @notice Thrown if the borrow cap is exceeded
error BorrowCapExceeded(address market, uint256 cap);

/// @notice Thrown if delegate approval status is already set to the requested value
error DelegationStatusUnchanged();

/// @param poolRegistry_ Pool registry address
/// @custom:oz-upgrades-unsafe-allow constructor
/// @custom:error ZeroAddressNotAllowed is thrown when pool registry address is zero
Expand Down Expand Up @@ -199,6 +205,30 @@ contract Comptroller is
return results;
}

/**
* @notice Grants or revokes the borrowing or redeeming delegate rights to / from an account
* If allowed, the delegate will be able to borrow funds on behalf of the sender
* Upon a delegated borrow, the delegate will receive the funds, and the borrower
* will see the debt on their account
* Upon a delegated redeem, the delegate will receive the redeemed amount and the approver
* will see a deduction in his vToken balance
* @param delegate The address to update the rights for
* @param approved Whether to grant (true) or revoke (false) the borrowing or redeeming rights
* @custom:event DelegateUpdated emits on success
* @custom:error ZeroAddressNotAllowed is thrown when delegate address is zero
* @custom:error DelegationStatusUnchanged is thrown if approval status is already set to the requested value
* @custom:access Not restricted
*/
function updateDelegate(address delegate, bool approved) external {
ensureNonzeroAddress(delegate);
if (approvedDelegates[msg.sender][delegate] == approved) {
revert DelegationStatusUnchanged();
}

approvedDelegates[msg.sender][delegate] = approved;
emit DelegateUpdated(msg.sender, delegate, approved);
}

/**
* @notice Removes asset from sender's account liquidity calculation; disabling them as collateral
* @dev Sender must not have an outstanding borrow balance in the asset,
Expand Down
18 changes: 17 additions & 1 deletion contracts/ComptrollerInterface.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity ^0.8.25;

import { ResilientOracleInterface } from "@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol";

import { VToken } from "./VToken.sol";
import { RewardsDistributor } from "./Rewards/RewardsDistributor.sol";

enum Action {
MINT,
REDEEM,
BORROW,
REPAY,
SEIZE,
LIQUIDATE,
TRANSFER,
ENTER_MARKET,
EXIT_MARKET
}

/**
* @title ComptrollerInterface
* @author Venus
Expand Down Expand Up @@ -89,6 +101,8 @@ interface ComptrollerInterface {
) external view returns (uint256, uint256);

function getAllMarkets() external view returns (VToken[] memory);

function actionPaused(address market, Action action) external view returns (bool);
}

/**
Expand Down Expand Up @@ -116,4 +130,6 @@ interface ComptrollerViewInterface {
function borrowCaps(address) external view returns (uint256);

function supplyCaps(address) external view returns (uint256);

function approvedDelegates(address user, address delegate) external view returns (bool);
}
21 changes: 7 additions & 14 deletions contracts/ComptrollerStorage.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { ResilientOracleInterface } from "@venusprotocol/oracle/contracts/interfaces/OracleInterface.sol";

import { VToken } from "./VToken.sol";
import { RewardsDistributor } from "./Rewards/RewardsDistributor.sol";
import { IPrime } from "@venusprotocol/venus-protocol/contracts/Tokens/Prime/Interfaces/IPrime.sol";
import { Action } from "./ComptrollerInterface.sol";

/**
* @title ComptrollerStorage
Expand Down Expand Up @@ -49,18 +50,6 @@ contract ComptrollerStorage {
mapping(address => bool) accountMembership;
}

enum Action {
MINT,
REDEEM,
BORROW,
REPAY,
SEIZE,
LIQUIDATE,
TRANSFER,
ENTER_MARKET,
EXIT_MARKET
}

/**
* @notice Oracle which gives the price of any given asset
*/
Expand Down Expand Up @@ -125,10 +114,14 @@ contract ComptrollerStorage {
/// Prime token address
IPrime public prime;

/// @notice Whether the delegate is allowed to borrow or redeem on behalf of the user
//mapping(address user => mapping (address delegate => bool approved)) public approvedDelegates;
mapping(address => mapping(address => bool)) public approvedDelegates;

/**
* @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[48] private __gap;
uint256[47] private __gap;
}
3 changes: 2 additions & 1 deletion contracts/ErrorReporter.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

/**
* @title TokenErrorReporter
Expand All @@ -18,6 +18,7 @@ contract TokenErrorReporter {

error BorrowFreshnessCheck();
error BorrowCashNotAvailable();
error DelegateNotApproved();

error RepayBorrowFreshnessCheck();

Expand Down
2 changes: 1 addition & 1 deletion contracts/ExponentialNoError.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.13;
pragma solidity 0.8.25;

import { EXP_SCALE as EXP_SCALE_, MANTISSA_ONE as MANTISSA_ONE_ } from "./lib/constants.sol";

Expand Down
95 changes: 95 additions & 0 deletions contracts/Gateway/INativeTokenGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.25;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
* @title INativeTokenGateway
* @author Venus
* @notice Interface for NativeTokenGateway contract
*/
interface INativeTokenGateway {
/**
* @dev Emitted when native currency is supplied
*/
event TokensWrappedAndSupplied(address indexed sender, address indexed vToken, uint256 amount);

/**
* @dev Emitted when tokens are redeemed and then unwrapped to be sent to user
*/
event TokensRedeemedAndUnwrapped(address indexed sender, address indexed vToken, uint256 amount);

/**
* @dev Emitted when native tokens are borrowed and unwrapped
*/
event TokensBorrowedAndUnwrapped(address indexed sender, address indexed vToken, uint256 amount);

/**
* @dev Emitted when native currency is wrapped and repaid
*/
event TokensWrappedAndRepaid(address indexed sender, address indexed vToken, uint256 amount);

/**
* @dev Emitted when token is swept from the contract
*/
event SweepToken(address indexed token, address indexed receiver, uint256 amount);

/**
* @dev Emitted when native asset is swept from the contract
*/
event SweepNative(address indexed receiver, uint256 amount);

/**
* @notice Thrown if transfer of native token fails
*/
error NativeTokenTransferFailed();

/**
* @notice Thrown if the supplied address is a zero address where it is not allowed
*/
error ZeroAddressNotAllowed();

/**
* @notice Thrown if the supplied value is 0 where it is not allowed
*/
error ZeroValueNotAllowed();

/**
* @dev Wrap Native Token, get wNativeToken, mint vWNativeTokens, and supply to the market
* @param minter The address on behalf of whom the supply is performed
*/
function wrapAndSupply(address minter) external payable;

/**
* @dev Redeem vWNativeTokens, unwrap to Native Token, and send to the user
* @param redeemAmount The amount of underlying tokens to redeem
*/
function redeemUnderlyingAndUnwrap(uint256 redeemAmount) external;

/**
* @dev Redeem vWNativeTokens, unwrap to Native Token, and send to the user
* @param redeemTokens The amount of vWNative tokens to redeem
*/
function redeemAndUnwrap(uint256 redeemTokens) external;

/**
* @dev Borrow wNativeToken, unwrap to Native Token, and send to the user
* @param amount The amount of underlying tokens to borrow
*/
function borrowAndUnwrap(uint256 amount) external;

/**
* @dev Wrap Native Token, repay borrow in the market, and send remaining Native Token to the user
*/
function wrapAndRepay() external payable;

/**
* @dev Sweeps input token address tokens from the contract and sends them to the owner
*/
function sweepToken(IERC20 token) external;

/**
* @dev Sweeps native assets (Native Token) from the contract and sends them to the owner
*/
function sweepNative() external;
}
24 changes: 24 additions & 0 deletions contracts/Gateway/Interfaces/IVToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.25;

interface IVToken {
function mintBehalf(address receiver, uint256 mintAmount) external returns (uint256);

function redeemUnderlyingBehalf(address redeemer, uint256 redeemAmount) external returns (uint256);

function redeemBehalf(address redeemer, uint256 redeemTokens) external returns (uint256);

function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns (uint256);

function borrowBehalf(address borrower, uint256 borrowAmount) external returns (uint256);

function borrowBalanceCurrent(address account) external returns (uint256);

function underlying() external returns (address);

function exchangeRateCurrent() external returns (uint256);

function transferFrom(address from, address to, uint256 amount) external returns (bool);

function redeem(uint256 redeemTokens) external returns (uint256);
}
16 changes: 16 additions & 0 deletions contracts/Gateway/Interfaces/IWrappedNative.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.25;

interface IWrappedNative {
function deposit() external payable;

function withdraw(uint256) external;

function approve(address guy, uint256 wad) external returns (bool);

function transferFrom(address src, address dst, uint256 wad) external returns (bool);

function transfer(address dst, uint256 wad) external returns (bool);

function balanceOf(address account) external view returns (uint256);
}
Loading

0 comments on commit d40f440

Please sign in to comment.