Struct nash_protocol::types::exchange::OrderRate [−][src]
pub struct OrderRate { /* fields omitted */ }
Expand description
Order rates impose limits on what trades the smart contract is allowed to execute. For example, the smart contract will reject a payload that requests a less favorable amount of asset_to than is imposed by the minimum order rate. For Sell orders, an order rate represented by currency B an in A/B market. For Buy orders, an order rate is represented in the protocol by currency A. Note that OrderRates are always created w.r.t. currency B, then potentially inverted during payload creation. This is because, unlike the smart contract, the ME always wants order prices expressed in currency B. In either case, these rates are encoded as 64 bit integers which take the initial price ratio, multiply by 10^8, and then drop all precision after the decimal.
Implementations
Serialize the OrderRate to bytes for payload creation. We always use a precision of 8 and multiplication factor of 10^8
Create new OrderRate from bigdecimal
Invert the price to units of the other market pair. For example, if price is in terms of ETH in an ETH/USDC market, this will convert it to terms of USDC
Return a new BigDecimal
based on OrderRate
Subtract fee from user by adjusting the order rate downwards. This will keep track of as much precision as BigDecimal is capable of. However, this method is exclusively used by the smart contract and will be reduced to an integer in scale of 10^8 before encoding
Trait Implementations
Enum wrappers are kind of annoying. This allows us to use .into()
on a value to generate a wrapped value. For example:
OrderRate::new("1").unwrap().into() => Rate::OrderRate(...)
Auto Trait Implementations
impl RefUnwindSafe for OrderRate
impl UnwindSafe for OrderRate
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more