mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
added read files
This commit is contained in:
parent
68fd33ea6d
commit
b4f184bafd
56
contracts/Read/InstaBalRead.sol
Normal file
56
contracts/Read/InstaBalRead.sol
Normal file
|
@ -0,0 +1,56 @@
|
|||
pragma solidity ^0.5.8;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface TokenInterface {
|
||||
function balanceOf(address) external view returns (uint);
|
||||
}
|
||||
|
||||
|
||||
contract DSMath {
|
||||
|
||||
function add(uint x, uint y) internal pure returns (uint z) {
|
||||
require((z = x + y) >= x, "math-not-safe");
|
||||
}
|
||||
|
||||
function mul(uint x, uint y) internal pure returns (uint z) {
|
||||
require(y == 0 || (z = x * y) / y == x, "math-not-safe");
|
||||
}
|
||||
|
||||
uint constant WAD = 10 ** 18;
|
||||
|
||||
function wmul(uint x, uint y) internal pure returns (uint z) {
|
||||
z = add(mul(x, y), WAD / 2) / WAD;
|
||||
}
|
||||
|
||||
function wdiv(uint x, uint y) internal pure returns (uint z) {
|
||||
z = add(mul(x, WAD), y / 2) / y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract Helpers is DSMath {
|
||||
|
||||
/**
|
||||
* @dev get ethereum address
|
||||
*/
|
||||
function getAddressETH() public pure returns (address eth) {
|
||||
eth = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract InstaBalRead is Helpers {
|
||||
function getTokensBalData(address owner, address[] memory tknAddress) public view returns (uint[] memory) {
|
||||
uint[] memory tokensBal = new uint[](tknAddress.length);
|
||||
for (uint i = 0; i < tknAddress.length; i++) {
|
||||
if (tknAddress[i] == getAddressETH()) {
|
||||
tokensBal[i] = owner.balance;
|
||||
} else {
|
||||
TokenInterface token = TokenInterface(tknAddress[i]);
|
||||
tokensBal[i] = token.balanceOf(owner);
|
||||
}
|
||||
}
|
||||
return tokensBal;
|
||||
}
|
||||
}
|
|
@ -56,19 +56,17 @@ contract Helpers is DSMath {
|
|||
*/
|
||||
function getComptrollerAddress() public pure returns (address troller) {
|
||||
troller = 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B;
|
||||
// troller = 0x2EAa9D77AE4D8f9cdD9FAAcd44016E746485bddb; // Rinkeby
|
||||
// troller = 0x3CA5a0E85aD80305c2d2c4982B2f2756f1e747a5; // Kovan
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get Compound Orcale Address
|
||||
*/
|
||||
function getOracleAddress() public pure returns (address oracle) {
|
||||
oracle = 0xe7664229833AE4Abf4E269b8F23a86B657E2338D;
|
||||
oracle = 0x1D8aEdc9E924730DD3f9641CDb4D1B92B848b4bd;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get Compound Comptroller Address
|
||||
* @dev get InstaDapp Registry Address
|
||||
*/
|
||||
function getInstaRegistry() public pure returns (address addr) {
|
||||
addr = 0x498b3BfaBE9F73db90D252bCD4Fa9548Cd0Fd981;
|
||||
|
|
105
contracts/Read/InstaDydxRead.sol
Normal file
105
contracts/Read/InstaDydxRead.sol
Normal file
|
@ -0,0 +1,105 @@
|
|||
pragma solidity ^0.5.8;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface ERC20Interface {
|
||||
function allowance(address, address) external view returns (uint);
|
||||
function balanceOf(address) external view returns (uint);
|
||||
function approve(address, uint) external;
|
||||
function transfer(address, uint) external returns (bool);
|
||||
function transferFrom(address, address, uint) external returns (bool);
|
||||
function deposit() external payable;
|
||||
function withdraw(uint) external;
|
||||
}
|
||||
|
||||
|
||||
contract SoloMarginContract {
|
||||
|
||||
struct Info {
|
||||
address owner; // The address that owns the account
|
||||
uint256 number; // A nonce that allows a single address to control many accounts
|
||||
}
|
||||
|
||||
|
||||
struct Wei {
|
||||
bool sign; // true if positive
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
struct Price {
|
||||
uint256 value;
|
||||
}
|
||||
|
||||
struct TotalPar {
|
||||
uint128 borrow;
|
||||
uint128 supply;
|
||||
}
|
||||
|
||||
struct Index {
|
||||
uint96 borrow;
|
||||
uint96 supply;
|
||||
uint32 lastUpdate;
|
||||
}
|
||||
|
||||
function getMarketPrice(uint256 marketId) public view returns (Price memory);
|
||||
function getAccountWei(Info memory account, uint256 marketId) public view returns (Wei memory);
|
||||
function getMarketTotalPar(uint256 marketId) public view returns (TotalPar memory);
|
||||
function getMarketCurrentIndex(uint256 marketId) public view returns (Index memory);
|
||||
}
|
||||
|
||||
interface RegistryInterface {
|
||||
function proxies(address owner) external view returns (address);
|
||||
}
|
||||
|
||||
|
||||
contract Helpers {
|
||||
|
||||
/**
|
||||
* @dev get Dydx Solo Address
|
||||
*/
|
||||
function getSoloAddress() public pure returns (address addr) {
|
||||
addr = 0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e;
|
||||
}
|
||||
|
||||
function getInstaRegistry() public pure returns (address addr) {
|
||||
addr = 0x498b3BfaBE9F73db90D252bCD4Fa9548Cd0Fd981;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev getting acccount arg
|
||||
*/
|
||||
function getAccountArgs(address owner) internal pure returns (SoloMarginContract.Info[] memory) {
|
||||
SoloMarginContract.Info[] memory accounts = new SoloMarginContract.Info[](1);
|
||||
accounts[0] = (SoloMarginContract.Info(owner, 0));
|
||||
return accounts;
|
||||
}
|
||||
|
||||
struct DydxData {
|
||||
SoloMarginContract.Price tokenPrice;
|
||||
SoloMarginContract.Wei balanceOfUser;
|
||||
SoloMarginContract.Wei balanceOfWallet;
|
||||
SoloMarginContract.TotalPar marketTotalPar;
|
||||
SoloMarginContract.Index marketCurrentIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract InstaDydxRead is Helpers {
|
||||
function getDydxUserData(address owner, uint[] memory marketId) public view returns(DydxData[] memory) {
|
||||
SoloMarginContract solo = SoloMarginContract(getSoloAddress());
|
||||
address userWallet = RegistryInterface(getInstaRegistry()).proxies(owner);
|
||||
DydxData[] memory tokensData = new DydxData[](marketId.length);
|
||||
for (uint i = 0; i < marketId.length; i++) {
|
||||
uint id = marketId[i];
|
||||
tokensData[i] = DydxData(
|
||||
solo.getMarketPrice(id),
|
||||
solo.getAccountWei(getAccountArgs(owner)[0], id),
|
||||
solo.getAccountWei(getAccountArgs(userWallet)[0], id),
|
||||
solo.getMarketTotalPar(id),
|
||||
solo.getMarketCurrentIndex(id)
|
||||
);
|
||||
}
|
||||
return tokensData;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user