Skip to content

Notional trade module adjustments post audit #256

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
69b054b
Remove redundant _fromUnderlying parameter
Jun 19, 2022
53ab96d
Reset allowances
Jun 19, 2022
ff8fbe1
Add gas limit for getDecodedID call
Jun 19, 2022
bbb5368
Remove logs
Jun 19, 2022
758fcca
Add optional disabling of the automatic redemption
Jun 20, 2022
14e8b28
Fix failing tests
Jun 20, 2022
054667e
Gas optimization in getFCashPositions
Jun 20, 2022
2512dc2
Remove declation of max/minImpliedRate variables
Jun 20, 2022
10e787c
Use isEth return value instead of ETH_ADDRESS to determine if underly…
Jun 20, 2022
a49681b
More minor gas / qa changes
Jun 20, 2022
51590bd
Switch redeem function to use relative position instead of absolute a…
Jun 21, 2022
580ec79
Switch mint function to use relative position instead of total amounts
Jun 21, 2022
a449510
Fix integration tests
Jun 21, 2022
1a036e4
Use test utils to convert between notional and position values in uni…
Jun 21, 2022
848ffe6
Add endpoitn for fixed input mints
Jun 22, 2022
3e6152f
Integration test failing due to inaccurate fCash amount estimation
Jun 22, 2022
a567ac8
Fix tests
Jun 23, 2022
c0bd76c
Add redeemFCashForFixedToken method + integration tests
Jun 25, 2022
7654f77
Add NotionalV2Mock for unittests
Jun 25, 2022
ac6c052
Reenable all integration tests
Jun 25, 2022
9d45e09
Add integration test for fixed output fCash redemption
Jun 26, 2022
c06daa9
Add deployment helper for NotionalV2Mock
Jun 26, 2022
0df8d4a
Add max deviation of redeem amount as function parameter
Jun 26, 2022
445959f
Add fixedToken test cases to unittests
Jun 26, 2022
f676d4c
Remove code to manually deploy notional dependencies
Jun 26, 2022
9b4934e
Silence failing integration test in curveALM
Jun 26, 2022
edee2fc
Fix more curveALM integration tests
Jun 26, 2022
f101ff7
Adjust curveExchangeALM tests based on Richard suggestions
Jun 28, 2022
456913a
Add safe downcasting to uint88
Jun 28, 2022
3d776b4
Address further QA issues from audit
Jun 28, 2022
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
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;
}
}

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