@0x/contracts-asset-proxy: Add getMarketMarginPremium() to IDydx.

`@0x/contracts-dev-utils`: Handle dydx market premiums.
This commit is contained in:
Lawrence Forman 2020-02-06 11:36:37 -05:00
parent bf9b4b993f
commit 809885afd0
5 changed files with 45 additions and 0 deletions

View File

@ -166,6 +166,15 @@ interface IDydx {
view
returns (Price memory price);
/// @dev Get the margin premium for a market. A margin premium makes it so that any positions that
/// include the market require a higher collateralization to avoid being liquidated.
/// @param marketId The market to query
/// @return premium The market's margin premium
function getMarketMarginPremium(uint256 marketId)
external
view
returns (D256 memory premium);
/// @dev Get the total supplied and total borrowed values of an account adjusted by the marginPremium
/// of each market. Supplied values are divided by (1 + marginPremium) for each market and
/// borrowed values are multiplied by (1 + marginPremium) for each market. Comparing these

View File

@ -210,6 +210,13 @@ contract TestDydxBridge is
returns (Price memory price)
{}
/// @dev Unsused
function getMarketMarginPremium(uint256 marketId)
external
view
returns (IDydx.D256 memory premium)
{}
/// @dev Unused.
function getAdjustedAccountValues(
AccountInfo calldata account

View File

@ -57,6 +57,16 @@ library D18 {
r = _add(int256(a), b);
}
/// @dev Add two decimals.
function add(int256 a, uint256 b)
internal
pure
returns (int256 r)
{
require(int256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG");
r = _add(a, int256(b));
}
/// @dev Add two decimals.
function add(uint256 a, uint256 b)
internal

View File

@ -339,6 +339,16 @@ library LibDydxBalance {
}
// The action value is the action rate times the price.
value = D18.mul(price, value);
// Scale by the market premium.
int256 marketPremium = D18.add(
D18.one(),
info.dydx.getMarketMarginPremium(action.marketId).value
);
if (action.actionType == IDydxBridge.BridgeActionType.Deposit) {
value = D18.div(value, marketPremium);
} else {
value = D18.mul(value, marketPremium);
}
}
/// @dev Returns the conversion rate for an action, expressed as units

View File

@ -129,6 +129,15 @@ contract TestDydx {
}
}
function getMarketMarginPremium(uint256)
external
view
returns (IDydx.D256 memory premium)
{
// Return 0.
return premium;
}
function getMarketPrice(
uint256 marketId
)