@0x/contracts-asset-proxy: Add getMarketMarginPremium() to IDydx.
`@0x/contracts-dev-utils`: Handle dydx market premiums.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -129,6 +129,15 @@ contract TestDydx {
|
||||
}
|
||||
}
|
||||
|
||||
function getMarketMarginPremium(uint256)
|
||||
external
|
||||
view
|
||||
returns (IDydx.D256 memory premium)
|
||||
{
|
||||
// Return 0.
|
||||
return premium;
|
||||
}
|
||||
|
||||
function getMarketPrice(
|
||||
uint256 marketId
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user