mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
code refactor
This commit is contained in:
parent
7b002f9704
commit
a715112abc
|
|
@ -52,5 +52,30 @@ contract DSMath {
|
|||
function toRad(uint wad) internal pure returns (uint rad) {
|
||||
rad = mul(wad, 10 ** 27);
|
||||
}
|
||||
|
||||
function toUint96(uint256 value) internal pure returns (uint96) {
|
||||
require(value <= type(uint96).max, "uint96 value overflow");
|
||||
return uint96(value);
|
||||
}
|
||||
|
||||
function toUint88(uint256 value) internal pure returns (uint88) {
|
||||
require(value <= type(uint88).max, "uint88-overflow");
|
||||
return uint88(value);
|
||||
}
|
||||
|
||||
function toUint32(uint256 value) internal pure returns (uint32) {
|
||||
require(value <= type(uint32).max, "uint32-overflow");
|
||||
return uint32(value);
|
||||
}
|
||||
|
||||
function toUint16(uint256 value) internal pure returns (uint16) {
|
||||
require(value <= type(uint16).max, "uint16-overflow");
|
||||
return uint16(value);
|
||||
}
|
||||
|
||||
function toUint8(uint256 value) internal pure returns (uint8) {
|
||||
require(value <= type(uint8).max, "uint8-overflow");
|
||||
return uint8(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,16 +71,6 @@ abstract contract Helpers is DSMath, Basic {
|
|||
}
|
||||
}
|
||||
|
||||
function toUint96(uint256 value) internal pure returns (uint96) {
|
||||
require(value <= type(uint96).max, "uint96 value overflow");
|
||||
return uint96(value);
|
||||
}
|
||||
|
||||
function toUint88(uint256 value) internal pure returns (uint88) {
|
||||
require(value <= type(uint88).max, "uint88 value overflow");
|
||||
return uint88(value);
|
||||
}
|
||||
|
||||
function getMsgValue(
|
||||
uint16 currencyId,
|
||||
bool useUnderlying,
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@
|
|||
pragma solidity ^0.7.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
// import { Helpers } from "./helpers.sol";
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import { Token, NotionalInterface, BalanceAction, BalanceActionWithTrades, DepositActionType, AaveV2LendingPoolProviderInterface, AaveV2DataProviderInterface, AaveV2Interface, AaveV3PoolProviderInterface, AaveV3Interface, AaveV3DataProviderInterface } from "./interface.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract Helpers is Basic {
|
||||
contract Helpers is DSMath, Basic {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
enum Protocol {
|
||||
AaveV2,
|
||||
AaveV3,
|
||||
Compound,
|
||||
Notional
|
||||
AAVEV2,
|
||||
AAVEV3,
|
||||
COMPOUND,
|
||||
NOTIONAL
|
||||
}
|
||||
|
||||
uint256 internal constant LEND_TRADE = 0;
|
||||
|
|
@ -116,26 +116,6 @@ contract Helpers is Basic {
|
|||
underlying ? underlyingToken.tokenAddress : assetToken.tokenAddress;
|
||||
}
|
||||
|
||||
function toUint88(uint256 value) internal pure returns (uint88) {
|
||||
require(value <= type(uint88).max, "uint88 value overflow");
|
||||
return uint88(value);
|
||||
}
|
||||
|
||||
function toUint32(uint256 value) internal pure returns (uint32) {
|
||||
require(value <= type(uint32).max, "uint32 value overflow");
|
||||
return uint32(value);
|
||||
}
|
||||
|
||||
function toUint16(uint256 value) internal pure returns (uint16) {
|
||||
require(value <= type(uint16).max, "uint16 value overflow");
|
||||
return uint16(value);
|
||||
}
|
||||
|
||||
function toUint8(uint256 value) internal pure returns (uint8) {
|
||||
require(value <= type(uint8).max, "uint8 value overflow");
|
||||
return uint8(value);
|
||||
}
|
||||
|
||||
function getAaveV2PaybackAmt(uint256 rateMode, address token)
|
||||
internal
|
||||
returns (uint256 bal)
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ pragma solidity ^0.7.6;
|
|||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { Helpers } from "../helpers.sol";
|
||||
|
||||
import { AaveV3DataProviderInterface, AaveV3PoolProviderInterface, AaveV3Interface } from "../interface.sol";
|
||||
import { TokenInterface } from "../../../common/interfaces.sol";
|
||||
import "../interface.sol";
|
||||
|
||||
contract AaveV3Helpers is Helpers {
|
||||
// payback token to Aave V2, amts sent already checked for MAX
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ pragma solidity ^0.7.6;
|
|||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { Helpers } from "../helpers.sol";
|
||||
import { Token, NotionalInterface, BalanceAction, BalanceActionWithTrades, DepositActionType, AaveV2DataProviderInterface } from "../interface.sol";
|
||||
import "../interface.sol";
|
||||
|
||||
contract NotionalHelpers is Helpers {
|
||||
function _notionalBorrowOne(
|
||||
|
|
@ -52,12 +52,12 @@ contract NotionalHelpers is Helpers {
|
|||
|
||||
//calculating payback amounts for Aave v2
|
||||
if (_amt == uint256(-1)) {
|
||||
if (data.source == Protocol.AaveV2)
|
||||
if (data.source == Protocol.AAVEV2)
|
||||
_amt = getAaveV2PaybackAmt(
|
||||
data.rateModes[i],
|
||||
data.tokens[i]
|
||||
);
|
||||
else if(data.source == Protocol.AaveV3)
|
||||
else if (data.source == Protocol.AAVEV3)
|
||||
_amt = getAaveV3PaybackAmt(
|
||||
data.rateModes[i],
|
||||
data.tokens[i]
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ pragma experimental ABIEncoderV2;
|
|||
* @title Refinance.
|
||||
* @dev Refinancing among Notional, Aave v2, Aave v3.
|
||||
*/
|
||||
import { AaveV2Interface, AaveV2DataProviderInterface, AaveV2LendingPoolProviderInterface, AaveV3Interface, AaveV3DataProviderInterface, AaveV3PoolProviderInterface } from "./interface.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import { AaveV2Helpers } from "./helpers/aaveV2.sol";
|
||||
import { AaveV3Helpers } from "./helpers/aaveV3.sol";
|
||||
import { NotionalHelpers } from "./helpers/notional.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
contract RefinanceResolver is AaveV2Helpers, AaveV3Helpers, NotionalHelpers {
|
||||
struct RefinanceData {
|
||||
|
|
@ -79,7 +79,7 @@ contract RefinanceResolver is AaveV2Helpers, AaveV3Helpers, NotionalHelpers {
|
|||
|
||||
// Aave v2 to Notional
|
||||
if (
|
||||
data.source == Protocol.AaveV2 && data.target == Protocol.Notional
|
||||
data.source == Protocol.AAVEV2 && data.target == Protocol.NOTIONAL
|
||||
) {
|
||||
NotionalBorrowData memory _notionalBorrowData;
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ contract RefinanceResolver is AaveV2Helpers, AaveV3Helpers, NotionalHelpers {
|
|||
}
|
||||
// Aave v3 to Notional
|
||||
else if (
|
||||
data.source == Protocol.AaveV3 && data.target == Protocol.Notional
|
||||
data.source == Protocol.AAVEV3 && data.target == Protocol.NOTIONAL
|
||||
) {
|
||||
NotionalBorrowData memory _notionalBorrowData;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user