mirror of
https://github.com/Instadapp/dsa-resolvers-deprecated.git
synced 2024-07-29 22:38:16 +00:00
Updated dydx resolver
This commit is contained in:
parent
a79713ed49
commit
813137d741
|
@ -3,6 +3,7 @@ pragma experimental ABIEncoderV2;
|
|||
|
||||
interface ERC20Interface {
|
||||
function allowance(address, address) external view returns (uint);
|
||||
function decimals() external view returns (uint);
|
||||
function balanceOf(address) external view returns (uint);
|
||||
function approve(address, uint) external;
|
||||
function transfer(address, uint) external returns (bool);
|
||||
|
@ -44,6 +45,7 @@ interface SoloMarginContract {
|
|||
function getAccountWei(Info calldata account, uint256 marketId) external view returns (Wei memory);
|
||||
function getMarketTotalPar(uint256 marketId) external view returns (TotalPar memory);
|
||||
function getMarketCurrentIndex(uint256 marketId) external view returns (Index memory);
|
||||
function getMarketTokenAddress(uint256 marketId) external view returns (address);
|
||||
}
|
||||
|
||||
contract DSMath {
|
||||
|
@ -100,10 +102,31 @@ contract Helpers is DSMath{
|
|||
}
|
||||
|
||||
struct DydxData {
|
||||
uint tokenPrice;
|
||||
uint tokenPriceInEth;
|
||||
uint tokenPriceInUsd;
|
||||
uint supplyBalance;
|
||||
uint borrowBalance;
|
||||
uint availableLiquidity;
|
||||
uint tokenUtil;
|
||||
// uint collateralFactor;
|
||||
}
|
||||
|
||||
struct TokenData {
|
||||
uint tokenPriceInEth;
|
||||
uint tokenPriceInUsd;
|
||||
uint balance;
|
||||
}
|
||||
|
||||
function getTokenPrice(SoloMarginContract solo, uint[] memory marketId) internal view returns(TokenData[] memory tokenData) {
|
||||
uint ethPrice = solo.getMarketPrice(0).value;
|
||||
tokenData = new TokenData[](marketId.length);
|
||||
for (uint i = 0; i < marketId.length; i++) {
|
||||
uint decimals = marketId[i] == 0 ? 18 : ERC20Interface(solo.getMarketTokenAddress(marketId[i])).decimals();
|
||||
tokenData[i].balance = marketId[i] == 0 ? address(solo).balance : ERC20Interface(solo.getMarketTokenAddress(marketId[i])).balanceOf(address(solo));
|
||||
uint price = marketId[i] == 1 ? 10 ** 18 : solo.getMarketPrice(marketId[i]).value;
|
||||
tokenData[i].tokenPriceInUsd = price / 10 ** (18 - decimals);
|
||||
tokenData[i].tokenPriceInEth = wdiv(tokenData[i].tokenPriceInUsd, ethPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,6 +135,7 @@ contract Resolver is Helpers {
|
|||
function getPosition(address user, uint[] memory marketId) public view returns(DydxData[] memory) {
|
||||
SoloMarginContract solo = SoloMarginContract(getSoloAddress());
|
||||
DydxData[] memory tokensData = new DydxData[](marketId.length);
|
||||
TokenData[] memory tokenData = getTokenPrice(solo, marketId);
|
||||
for (uint i = 0; i < marketId.length; i++) {
|
||||
uint id = marketId[i];
|
||||
SoloMarginContract.Wei memory tokenBal = solo.getAccountWei(getAccountArgs(user), id);
|
||||
|
@ -119,9 +143,11 @@ contract Resolver is Helpers {
|
|||
SoloMarginContract.Index memory rateIndex = solo.getMarketCurrentIndex(id);
|
||||
|
||||
tokensData[i] = DydxData(
|
||||
solo.getMarketPrice(id).value,
|
||||
tokenData[i].tokenPriceInUsd,
|
||||
tokenData[i].tokenPriceInEth,
|
||||
tokenBal.sign ? tokenBal.value : 0,
|
||||
!tokenBal.sign ? tokenBal.value : 0,
|
||||
tokenData[i].balance,
|
||||
wdiv(wmul(totalPar.borrow, rateIndex.borrow), wmul(totalPar.supply, rateIndex.supply))
|
||||
);
|
||||
}
|
||||
|
@ -130,5 +156,5 @@ contract Resolver is Helpers {
|
|||
}
|
||||
|
||||
contract InstaDydxResolver is Resolver {
|
||||
string public constant name = "Dydx-Resolver-v1";
|
||||
string public constant name = "Dydx-Resolver-v1.1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user