Skip to content

Commit

Permalink
fix(NotionalTradeModule): audit adjustments
Browse files Browse the repository at this point in the history
fix(NotionalTradeModule): audit adjustments
  • Loading branch information
ckoopmann authored Oct 3, 2022
2 parents ca55b0e + bf8bf35 commit de39ee1
Show file tree
Hide file tree
Showing 27 changed files with 2,363 additions and 1,624 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center">
<a href="https://circleci.com/gh/SetProtocol/set-protocol-v2/tree/master">
<img src="https://img.shields.io/circleci/project/github/SetProtocol/set-protocol-v2/master.svg" />
<a href="https://circleci.com/gh/IndexCoop/index-protocol/tree/master">
<img src="https://img.shields.io/circleci/project/github/IndexCoop/index-protocol/master.svg" />
</a>
<a href='https://coveralls.io/github/SetProtocol/set-protocol-v2?branch=master'><img src='https://coveralls.io/repos/github/SetProtocol/set-protocol-v2/badge.svg?branch=master&amp;t=4pzROZ' alt='Coverage Status' /></a>
<a href='https://coveralls.io/github/IndexCoop/index-protocol?branch=master'><img src='https://coveralls.io/repos/github/IndexCoop/index-protocol/badge.svg?branch=master' alt='Coverage Status' /></a>
</p>

# Set Protocol V2 Contract Repository
Expand Down
13 changes: 13 additions & 0 deletions contracts/interfaces/IERC20Metadata.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.10;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);

function symbol() external view returns (string memory);

function decimals() external view returns (uint8);
}

7 changes: 5 additions & 2 deletions contracts/interfaces/IWrappedFCash.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./IERC20Metadata.sol";

/// @notice Different types of internal tokens
/// - UnderlyingToken: underlying asset for a cToken (except for Ether)
Expand Down Expand Up @@ -65,4 +65,7 @@ interface IWrappedfCash {
}


interface IWrappedfCashComplete is IWrappedfCash, IERC20 {}
interface IWrappedfCashComplete is IWrappedfCash, IERC20Metadata {
/// @notice Returns the maturity of the underlying fCash instance
function getMaturity() external view returns (uint40);
}
5 changes: 0 additions & 5 deletions contracts/interfaces/external/INotionalProxy.sol

This file was deleted.

66 changes: 66 additions & 0 deletions contracts/interfaces/external/INotionalV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

/// @dev Market object as represented in memory
struct MarketParameters {
bytes32 storageSlot;
uint256 maturity;
// Total amount of fCash available for purchase in the market.
int256 totalfCash;
// Total amount of cash available for purchase in the market.
int256 totalAssetCash;
// Total amount of liquidity tokens (representing a claim on liquidity) in the market.
int256 totalLiquidity;
// This is the previous annualized interest rate in RATE_PRECISION that the market traded
// at. This is used to calculate the rate anchor to smooth interest rates over time.
uint256 lastImpliedRate;
// Time lagged version of lastImpliedRate, used to value fCash assets at market rates while
// remaining resistent to flash loan attacks.
uint256 oracleRate;
// This is the timestamp of the previous trade
uint256 previousTradeTime;
}


interface INotionalV2 {
function getfCashLendFromDeposit(
uint16 currencyId,
uint256 depositAmountExternal,
uint256 maturity,
uint32 minLendRate,
uint256 blockTime,
bool useUnderlying
) external view returns (
uint88 fCashAmount,
uint8 marketIndex,
bytes32 encodedTrade
);

function getfCashBorrowFromPrincipal(
uint16 currencyId,
uint256 borrowedAmountExternal,
uint256 maturity,
uint32 maxBorrowRate,
uint256 blockTime,
bool useUnderlying
) external view returns (
uint88 fCashDebt,
uint8 marketIndex,
bytes32 encodedTrade
);

}

interface INotionalV2Complete is INotionalV2 {
function getCurrencyId(address tokenAddress) external view returns (uint16 currencyId);

function getActiveMarkets(uint16 currencyId) external view returns (MarketParameters[] memory);

function updateAssetRate(uint16 currencyId, address rateOracle) external;

function upgradeTo(address newAddress) external;

function owner() external view returns(address);
}

45 changes: 45 additions & 0 deletions contracts/mocks/NotionalV2Mock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

import { INotionalV2 } from "../interfaces/external/INotionalV2.sol";


contract NotionalV2Mock is INotionalV2 {
uint88 fCashEstimation;

function setFCashEstimation(uint88 _fCashEstimation) public {
fCashEstimation = _fCashEstimation;
}

function getfCashLendFromDeposit(
uint16 currencyId,
uint256 depositAmountExternal,
uint256 maturity,
uint32 minLendRate,
uint256 blockTime,
bool useUnderlying
) external view override returns (
uint88 fCashAmount,
uint8 marketIndex,
bytes32 encodedTrade
) {
fCashAmount = fCashEstimation;
}

function getfCashBorrowFromPrincipal(
uint16 currencyId,
uint256 borrowedAmountExternal,
uint256 maturity,
uint32 maxBorrowRate,
uint256 blockTime,
bool useUnderlying
) external view override returns (
uint88 fCashDebt,
uint8 marketIndex,
bytes32 encodedTrade
) {
fCashDebt = fCashEstimation;
}
}

8 changes: 5 additions & 3 deletions contracts/mocks/WrappedfCashMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ contract WrappedfCashMock is ERC20, IWrappedfCash {
IERC20 private assetToken;
int256 private assetPrecision;
TokenType private tokenType;
bool private isEth;

IERC20 private weth;

Expand All @@ -46,10 +47,11 @@ contract WrappedfCashMock is ERC20, IWrappedfCash {

address internal constant ETH_ADDRESS = address(0);

constructor (IERC20 _assetToken, IERC20 _underlyingToken, IERC20 _weth) public ERC20("FCashMock", "FCM") {
constructor (IERC20 _assetToken, IERC20 _underlyingToken, IERC20 _weth, bool _isEth) public ERC20("FCashMock", "FCM") {
assetToken = _assetToken;
underlyingToken = _underlyingToken;
weth = _weth;
isEth = _isEth;
}

function initialize(uint16 _currencyId, uint40 _maturity) external override {
Expand Down Expand Up @@ -162,13 +164,13 @@ contract WrappedfCashMock is ERC20, IWrappedfCash {
revertDecodedID = _revertDecodedID;
}

function getToken(bool useUnderlying) public view override returns (IERC20 token, bool isETH) {
function getToken(bool useUnderlying) public view override returns (IERC20 token, bool _isEth) {
if (useUnderlying) {
(token, /* */) = getUnderlyingToken();
_isEth = isEth;
} else {
(token, /* */, /* */) = getAssetToken();
}
isETH = address(token) == ETH_ADDRESS;
}


Expand Down
10 changes: 0 additions & 10 deletions contracts/protocol/integration/wrap/notional/WrappedfCash.sol

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions contracts/protocol/integration/wrap/notional/nBeaconProxy.sol

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/protocol/modules/v1/DebtIssuanceModuleV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ contract DebtIssuanceModuleV2 is DebtIssuanceModule {

return (components, equityUnits, debtUnits);
}
}
}
Loading

0 comments on commit de39ee1

Please sign in to comment.