From 209450cb25ac872416923e42cddc1844c5c30ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sehyun=20Chung=20=E2=9C=8C=EF=B8=8E?= <41171808+sehyunc@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:37:41 -0800 Subject: [PATCH] external-api: add `get_quote_amount` helper --- external-api/src/http/external_match.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/external-api/src/http/external_match.rs b/external-api/src/http/external_match.rs index 75c02501..62152ed5 100644 --- a/external-api/src/http/external_match.rs +++ b/external-api/src/http/external_match.rs @@ -161,7 +161,7 @@ impl ExternalOrder { /// /// The price here is expected to be decimal corrected; i.e. multiplied by /// the decimal diff for the two tokens - fn get_base_amount(&self, price: FixedPoint) -> Amount { + pub fn get_base_amount(&self, price: FixedPoint) -> Amount { if self.base_amount != 0 { return self.base_amount; } @@ -170,6 +170,20 @@ impl ExternalOrder { scalar_to_u128(&implied_base_amount) } + /// Get the quote amount of the order implied by the external order + /// + /// The price here is expected to be decimal corrected; i.e. multiplied by + /// the decimal diff for the two tokens + pub fn get_quote_amount(&self, price: FixedPoint) -> Amount { + if self.quote_amount != 0 { + return self.quote_amount; + } + + let base_amount_scalar = Scalar::from(self.base_amount); + let implied_quote_amount = price * base_amount_scalar; + scalar_to_u128(&implied_quote_amount.floor()) + } + /// Get the min fill size in units of the base token /// /// If the order size is specified in the `base_amount` field, this is