@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

@@ -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
)