Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VEN-1214][VEN-1150]: integrate ACM and automatic reduce reserves in VToken #262

Merged
merged 47 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9be81a5
feat: VEN-1214 integrate ACM in vToken
GitGuru7 May 10, 2023
2bb5610
feat: refactor storage and interface
GitGuru7 May 15, 2023
2499c08
resolve merge conflicts
GitGuru7 May 15, 2023
6ca872d
feat: add VToken version two
GitGuru7 May 16, 2023
491dc1f
Merge branch 'feature/VEN-1214' of https://github.com/VenusProtocol/v…
GitGuru7 May 16, 2023
fd99dfc
refactor: revert VToken V2
GitGuru7 May 16, 2023
93a9381
chore: fix comments
GitGuru7 May 18, 2023
18dcf7d
Merge VEN-1150 and resolve conflicts
GitGuru7 Jun 8, 2023
72a9119
chore: delete old VToken contract
GitGuru7 Jun 8, 2023
64f9caa
WIP
GitGuru7 Jun 8, 2023
ac50e14
test: simulate old and new mint operations
GitGuru7 Jun 8, 2023
c0c45d0
test: add tests for user operations in all markets
GitGuru7 Jun 9, 2023
928b75e
refactor: use function instead of modifier
GitGuru7 Jun 12, 2023
ea216cd
Revert "refactor: use function instead of modifier"
GitGuru7 Jul 3, 2023
aa64f64
feat: remove v2 dependency for VToken
GitGuru7 Jul 3, 2023
351ce56
chore: fix comments and config
GitGuru7 Jul 3, 2023
b83ff22
refactor: variable names
GitGuru7 Jul 4, 2023
42ae2af
fix: contract size and tests
GitGuru7 Jul 5, 2023
e8714c8
fix: 1.1 VTokenInterfaces.sol
GitGuru7 Jul 24, 2023
6e5176c
fix: 1.2 VToken.sol
GitGuru7 Jul 24, 2023
3f2862e
Merge branch 'develop' into feature/VEN-1214
GitGuru7 Jul 24, 2023
476dafc
refactor: update event name
GitGuru7 Jul 26, 2023
79c8c65
Merge branch 'develop' into feature/VEN-1214
GitGuru7 Aug 2, 2023
cc3231a
fix: FairyProof 2.1
GitGuru7 Aug 2, 2023
f1b4dce
Merge pull request #310 from VenusProtocol/fix/VEN-1794
GitGuru7 Aug 3, 2023
a575a70
fix: PVE001
GitGuru7 Aug 7, 2023
0ea2384
Merge pull request #313 from VenusProtocol/fix/Peckshield-fixes
chechu Aug 9, 2023
df0c07b
fix: certik VPB-05
GitGuru7 Aug 21, 2023
e699b13
fix: certik VPI-01 MISSING ZERO ADDRESS VALIDATION
GitGuru7 Aug 21, 2023
e8fdf1b
fix: certik VPB-03 Typos and Inconsistencies
GitGuru7 Aug 21, 2023
0695114
fix: certik: VTV-02 Optimization
GitGuru7 Aug 21, 2023
ca4d1da
fix: resolve comments
GitGuru7 Aug 25, 2023
2e0f5f6
Merge pull request #316 from VenusProtocol/fix/VEN-1845
GitGuru7 Aug 25, 2023
fc1178a
docs: VPI-02 fix the access control related comment
chechu Aug 29, 2023
dec5e9d
refactor: redce VToken size
GitGuru7 Sep 7, 2023
1bfe5d3
refactor: error type and tests
GitGuru7 Sep 7, 2023
3629618
fix: require statement
GitGuru7 Sep 7, 2023
8f3a15e
refactor: use functions to revert
GitGuru7 Sep 12, 2023
397e272
Merge pull request #334 from VenusProtocol/reduce-vtoken-size
GitGuru7 Sep 12, 2023
7f303f5
fix: 4. [Low] Input Validation
GitGuru7 Sep 15, 2023
51bf6fd
fix: 12. [Info] Safe Math Function Not Used For Block Delta Calculation
GitGuru7 Sep 15, 2023
4cd97d0
fix: BP12
GitGuru7 Sep 15, 2023
8ba19a1
Merge pull request #354 from VenusProtocol/fix/quantstamp-audit
GitGuru7 Sep 20, 2023
5312427
fix: fix natspec comment
GitGuru7 Oct 23, 2023
2538f33
Merge branch 'develop' into feature/VEN-1214
GitGuru7 Oct 23, 2023
e6ea28b
fix: fixed vBNBAdmin tests
web3rover Oct 23, 2023
d24f9f6
fix: tests
GitGuru7 Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions contracts/Tokens/VTokens/VBep20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ contract VBep20 is VToken, VBep20Interface {
* See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
function doTransferIn(address from, uint amount) internal returns (uint) {
EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);
uint balanceBefore = EIP20Interface(underlying).balanceOf(address(this));
token.transferFrom(from, address(this), amount);
EIP20NonStandardInterface(underlying).transferFrom(from, address(this), amount);

bool success;
assembly {
Expand Down Expand Up @@ -218,8 +217,7 @@ contract VBep20 is VToken, VBep20Interface {
* See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
*/
function doTransferOut(address payable to, uint amount) internal {
EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);
token.transfer(to, amount);
EIP20NonStandardInterface(underlying).transfer(to, amount);

bool success;
assembly {
Expand Down Expand Up @@ -247,7 +245,6 @@ contract VBep20 is VToken, VBep20Interface {
* @return The quantity of underlying tokens owned by this contract
*/
function getCashPrior() internal view returns (uint) {
EIP20Interface token = EIP20Interface(underlying);
return token.balanceOf(address(this));
return EIP20Interface(underlying).balanceOf(address(this));
}
}
152 changes: 98 additions & 54 deletions contracts/Tokens/VTokens/VToken.sol

Large diffs are not rendered by default.

84 changes: 66 additions & 18 deletions contracts/Tokens/VTokens/VTokenInterfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ pragma solidity ^0.5.16;
import "../../Comptroller/ComptrollerInterface.sol";
import "../../InterestRateModels/InterestRateModel.sol";

contract VTokenStorage {
interface IProtocolShareReserve {
chechu marked this conversation as resolved.
Show resolved Hide resolved
enum IncomeType {
SPREAD,
LIQUIDATION
}

function updateAssetsState(address comptroller, address asset, IncomeType kind) external;
}

contract VTokenStorageBase {
/**
* @notice Container for borrow balance information
* @member principal Total balance (with accrued interest), after applying the most recent balance-changing action
Expand Down Expand Up @@ -114,6 +123,46 @@ contract VTokenStorage {
* @notice Mapping of account addresses to outstanding borrow balances
*/
mapping(address => BorrowSnapshot) internal accountBorrows;

/**
* @notice Underlying asset for this VToken
*/
address public underlying;

/**
* @notice Implementation address for this contract
*/
address public implementation;

/**
* @notice delta block after which reserves will be reduced
*/
uint public reduceReservesBlockDelta;
0xlucian marked this conversation as resolved.
Show resolved Hide resolved

/**
* @notice last block number at which reserves were reduced
*/
uint public reduceReservesBlockNumber;

/**
* @notice address of protocol share reserve contract
*/
address payable public protocolShareReserve;

/**
* @notice address of accessControlManager
*/

address public accessControlManager;
}

contract VTokenStorage is VTokenStorageBase {
/**
* @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[50] private __gap;
}

contract VTokenInterface is VTokenStorage {
Expand Down Expand Up @@ -217,11 +266,24 @@ contract VTokenInterface is VTokenStorage {
*/
event Approval(address indexed owner, address indexed spender, uint amount);

/**
* @notice Event emitted when block delta for reduce reserves get updated
*/
event NewReduceReservesBlockDelta(uint256 oldReduceReservesBlockDelta, uint256 newReduceReservesBlockDelta);

/**
* @notice Event emitted when address of ProtocolShareReserve contract get updated
*/
event NewProtocolShareReserve(address indexed oldProtocolShareReserve, address indexed newProtocolShareReserve);

/**
* @notice Failure event
*/
event Failure(uint error, uint info, uint detail);

/// @notice Emitted when access control address is changed by admin
event NewAccessControlManager(address oldAccessControlAddress, address newAccessControlAddress);

/*** User Interface ***/

function transfer(address dst, uint amount) external returns (bool);
Expand Down Expand Up @@ -277,14 +339,7 @@ contract VTokenInterface is VTokenStorage {
function exchangeRateStored() public view returns (uint);
}

contract VBep20Storage {
/**
* @notice Underlying asset for this VToken
*/
address public underlying;
}

contract VBep20Interface is VBep20Storage {
contract VBep20Interface {
/*** User Interface ***/

function mint(uint mintAmount) external returns (uint);
Expand Down Expand Up @@ -312,14 +367,7 @@ contract VBep20Interface is VBep20Storage {
function _addReserves(uint addAmount) external returns (uint);
}

contract VDelegationStorage {
/**
* @notice Implementation address for this contract
*/
address public implementation;
}

contract VDelegatorInterface is VDelegationStorage {
contract VDelegatorInterface {
/**
* @notice Emitted when implementation is changed
*/
Expand All @@ -338,7 +386,7 @@ contract VDelegatorInterface is VDelegationStorage {
) public;
}

contract VDelegateInterface is VDelegationStorage {
contract VDelegateInterface {
/**
* @notice Called by the delegator on a delegate to initialize it for duty
* @dev Should revert if any issues arise which make it unfit for delegation
Expand Down
3 changes: 3 additions & 0 deletions contracts/Utils/ErrorReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ contract TokenErrorReporter {
SET_COLLATERAL_FACTOR_OWNER_CHECK,
SET_COLLATERAL_FACTOR_VALIDATION,
SET_COMPTROLLER_OWNER_CHECK,
SET_ACCESS_CONTROL_OWNER_CHECK,
SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED,
SET_INTEREST_RATE_MODEL_FRESH_CHECK,
SET_INTEREST_RATE_MODEL_OWNER_CHECK,
Expand All @@ -178,6 +179,8 @@ contract TokenErrorReporter {
SET_RESERVE_FACTOR_ADMIN_CHECK,
SET_RESERVE_FACTOR_FRESH_CHECK,
SET_RESERVE_FACTOR_BOUNDS_CHECK,
SET_REDUCE_RESERVES_BLOCK_DELTA_OWNER_CHECK,
SET_PROTOCOL_SHARE_RESERVES_OWNER_CHECK,
TRANSFER_COMPTROLLER_REJECTION,
TRANSFER_NOT_ALLOWED,
TRANSFER_NOT_ENOUGH,
Expand Down
9 changes: 8 additions & 1 deletion tests/hardhat/EvilXToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chai from "chai";
import { ethers } from "hardhat";

import { convertToUnit } from "../../helpers/utils";
import { ComptrollerHarness__factory, IAccessControlManager } from "../../typechain";
import { ComptrollerHarness__factory, IAccessControlManager, IProtocolShareReserve } from "../../typechain";

const { expect } = chai;

Expand Down Expand Up @@ -168,8 +168,15 @@ describe("Evil Token test", async () => {
await unitroller.connect(user).enterMarkets([vToken1.address, vToken2.address, vToken3.address]);
await underlying1.harnessSetBalance(user.address, convertToUnit(1, 8));
await underlying1.connect(user).approve(vToken1.address, convertToUnit(1, 10));
await vToken1.setReduceReservesBlockDelta(10000);
await vToken1.connect(user).mint(convertToUnit(1, 4));
await underlying3.harnessSetBalance(vToken3.address, convertToUnit(1, 8));

const protocolShareReserve = await smock.fake<IProtocolShareReserve>("IProtocolShareReserve");
protocolShareReserve.updateAssetsState.returns(true);
await vToken1.setProtcolShareReserve(protocolShareReserve.address);
await vToken2.setProtcolShareReserve(protocolShareReserve.address);
await vToken3.setProtcolShareReserve(protocolShareReserve.address);
});

it("Check the updated vToken states after transfer out", async () => {
Expand Down
Loading