From 0b048fbcc1ae72b485654a92ab6df2ab9e594785 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Wed, 26 May 2021 20:17:15 +0530 Subject: [PATCH] Pushed common folder --- contracts/aggregate/aaveV2.sol | 2 +- contracts/aggregate/compound.sol | 2 +- contracts/aggregate/maker.sol | 2 +- contracts/common/interfaces.sol | 33 +++++++++++++++++++ contracts/common/math.sol | 50 +++++++++++++++++++++++++++++ contracts/common/stores-polygon.sol | 37 +++++++++++++++++++++ contracts/common/stores.sol | 42 ++++++++++++++++++++++++ 7 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 contracts/common/interfaces.sol create mode 100644 contracts/common/math.sol create mode 100644 contracts/common/stores-polygon.sol create mode 100644 contracts/common/stores.sol diff --git a/contracts/aggregate/aaveV2.sol b/contracts/aggregate/aaveV2.sol index 475b93e..00d4486 100644 --- a/contracts/aggregate/aaveV2.sol +++ b/contracts/aggregate/aaveV2.sol @@ -1,7 +1,7 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; -import { DSMath } from "../../../common/math.sol"; +import { DSMath } from "../../common/math.sol"; interface AaveProtocolDataProvider { function getUserAccountData(address user) external view returns ( diff --git a/contracts/aggregate/compound.sol b/contracts/aggregate/compound.sol index a2fb676..8449379 100644 --- a/contracts/aggregate/compound.sol +++ b/contracts/aggregate/compound.sol @@ -1,7 +1,7 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; -import { DSMath } from "../../../common/math.sol"; +import { DSMath } from "../../common/math.sol"; interface CTokenInterface { function exchangeRateCurrent() external returns (uint); diff --git a/contracts/aggregate/maker.sol b/contracts/aggregate/maker.sol index 5e746dc..c42c8ca 100644 --- a/contracts/aggregate/maker.sol +++ b/contracts/aggregate/maker.sol @@ -1,7 +1,7 @@ pragma solidity ^0.7.0; pragma experimental ABIEncoderV2; -import { DSMath } from "../../../common/math.sol"; +import { DSMath } from "../../common/math.sol"; interface ManagerLike { function ilks(uint) external view returns (bytes32); function owns(uint) external view returns (address); diff --git a/contracts/common/interfaces.sol b/contracts/common/interfaces.sol new file mode 100644 index 0000000..b0ff099 --- /dev/null +++ b/contracts/common/interfaces.sol @@ -0,0 +1,33 @@ +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +interface TokenInterface { + function approve(address, uint256) external; + function transfer(address, uint) external; + function transferFrom(address, address, uint) external; + function deposit() external payable; + function withdraw(uint) external; + function balanceOf(address) external view returns (uint); + function decimals() external view returns (uint); +} + +interface MemoryInterface { + function getUint(uint id) external returns (uint num); + function setUint(uint id, uint val) external; +} + +interface InstaMapping { + function cTokenMapping(address) external view returns (address); + function gemJoinMapping(bytes32) external view returns (address); +} + +interface AccountInterface { + function enable(address) external; + function disable(address) external; + function isAuth(address) external view returns (bool); + function cast( + string[] calldata _targets, + bytes[] calldata _datas, + address _origin + ) external payable returns (bytes32); +} diff --git a/contracts/common/math.sol b/contracts/common/math.sol new file mode 100644 index 0000000..f6e2e6c --- /dev/null +++ b/contracts/common/math.sol @@ -0,0 +1,50 @@ +pragma solidity ^0.7.0; + +import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; + +contract DSMath { + uint constant WAD = 10 ** 18; + uint constant RAY = 10 ** 27; + + function add(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(x, y); + } + + function sub(uint x, uint y) internal virtual pure returns (uint z) { + z = SafeMath.sub(x, y); + } + + function mul(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.mul(x, y); + } + + function div(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.div(x, y); + } + + function wmul(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD; + } + + function wdiv(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y; + } + + function rdiv(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y; + } + + function rmul(uint x, uint y) internal pure returns (uint z) { + z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY; + } + + function toInt(uint x) internal pure returns (int y) { + y = int(x); + require(y >= 0, "int-overflow"); + } + + function toRad(uint wad) internal pure returns (uint rad) { + rad = mul(wad, 10 ** 27); + } + +} diff --git a/contracts/common/stores-polygon.sol b/contracts/common/stores-polygon.sol new file mode 100644 index 0000000..2726b47 --- /dev/null +++ b/contracts/common/stores-polygon.sol @@ -0,0 +1,37 @@ +pragma solidity ^0.7.0; + +import { MemoryInterface } from "./interfaces.sol"; + + +abstract contract Stores { + + /** + * @dev Return matic address + */ + address constant internal maticAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + + /** + * @dev Return Wrapped MATIC address + */ + address constant internal wmaticAddr = 0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270; + + /** + * @dev Return memory variable address + */ + MemoryInterface constant internal instaMemory = MemoryInterface(0x6C7256cf7C003dD85683339F75DdE9971f98f2FD); + + /** + * @dev Get Uint value from InstaMemory Contract. + */ + function getUint(uint getId, uint val) internal returns (uint returnVal) { + returnVal = getId == 0 ? val : instaMemory.getUint(getId); + } + + /** + * @dev Set Uint value in InstaMemory Contract. + */ + function setUint(uint setId, uint val) virtual internal { + if (setId != 0) instaMemory.setUint(setId, val); + } + +} diff --git a/contracts/common/stores.sol b/contracts/common/stores.sol new file mode 100644 index 0000000..19687ea --- /dev/null +++ b/contracts/common/stores.sol @@ -0,0 +1,42 @@ +pragma solidity ^0.7.0; + +import { MemoryInterface, InstaMapping } from "./interfaces.sol"; + + +abstract contract Stores { + + /** + * @dev Return ethereum address + */ + address constant internal ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; + + /** + * @dev Return Wrapped ETH address + */ + address constant internal wethAddr = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; + + /** + * @dev Return memory variable address + */ + MemoryInterface constant internal instaMemory = MemoryInterface(0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F); + + /** + * @dev Return InstaDApp Mapping Addresses + */ + InstaMapping constant internal instaMapping = InstaMapping(0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88); + + /** + * @dev Get Uint value from InstaMemory Contract. + */ + function getUint(uint getId, uint val) internal returns (uint returnVal) { + returnVal = getId == 0 ? val : instaMemory.getUint(getId); + } + + /** + * @dev Set Uint value in InstaMemory Contract. + */ + function setUint(uint setId, uint val) virtual internal { + if (setId != 0) instaMemory.setUint(setId, val); + } + +}