forked from KomodoPlatform/komodo-defi-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//? RPC implementation for swaps with liquidity routing (LR) | ||
|
||
use mm2_err_handle::mm_error::{MmResult, MmError}; | ||
use mm2_core::mm_ctx::MmArc; | ||
use types::{LrFindBestSwapPathRequest, LrFindBestSwapPathResponse, LrFillOrderRequest, LrFillOrderResponse}; | ||
use errors::LrSwapRpcError; | ||
|
||
pub mod errors; | ||
pub mod types; | ||
|
||
/// Find best swap path with liquidity routing over evm tokens. | ||
/// For the provided list of orderbook entries this RPC searches for the most price effective swap with LR | ||
pub async fn lr_find_best_swap_path_rpc( | ||
ctx: MmArc, | ||
req: LrFindBestSwapPathRequest, | ||
) -> MmResult<LrFindBestSwapPathResponse, LrSwapRpcError> { | ||
MmError::err(LrSwapRpcError::SomeError) | ||
} | ||
|
||
/// Run a swap with LR part | ||
pub async fn lr_fill_order_rpc( | ||
ctx: MmArc, | ||
req: LrFillOrderRequest, | ||
) -> MmResult<LrFillOrderResponse, LrSwapRpcError> { | ||
MmError::err(LrSwapRpcError::SomeError) | ||
} | ||
|
||
// TODO: Do we need to extend trade_preimage_rpc to include LR-part fee? | ||
// In fact, lr_find_best_swap_path_rpc has same behaviour: returns trade fee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//? Errors for LR swaps rpc | ||
|
||
use common::{HttpStatusCode, StatusCode}; | ||
use enum_derives::EnumFromStringify; | ||
use ser_error_derive::SerializeErrorType; | ||
use serde::Serialize; | ||
|
||
#[derive(Debug, Display, Serialize, SerializeErrorType)] | ||
#[serde(tag = "error_type", content = "error_data")] | ||
pub enum LrSwapRpcError { | ||
#[display(fmt = "LR swap error")] | ||
SomeError, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//? Types for LR swaps rpc | ||
use mm2_number::MmNumber; | ||
use mm2_number::BigDecimal; | ||
|
||
use crate::lp_ordermatch::AggregatedOrderbookEntryV2; | ||
use crate::rpc::lp_commands::one_inch::types::ClassicSwapDetails; | ||
use crate::lp_swap::TradePreimageResponse; | ||
use mm2_rpc::data::legacy::{SellBuyRequest, SellBuyResponse}; | ||
//use trading_api::one_inch_api::types::ClassicSwapData; | ||
//use coins::TradeFee; | ||
|
||
/// Request to find best swap path with LR rpc. | ||
#[derive(Debug, Deserialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct LrFindBestSwapPathRequest { | ||
/// Base (source) coin ticker | ||
pub base: String, | ||
/// Rel (target) coin ticker | ||
pub rel: String, | ||
/// Swap amount in base coins to sell (with fraction) | ||
pub amount: MmNumber, | ||
/// List of maker orders which is searched for best path with LR | ||
pub orderbook_entries: Vec<AggregatedOrderbookEntryV2>, | ||
/// List of tokens allowed to route through with LR | ||
pub route_tokens: Vec<String>, | ||
} | ||
|
||
/// Response for find best swap path with LR rpc | ||
#[derive(Serialize)] | ||
pub struct LrFindBestSwapPathResponse { | ||
/// Swap tx data (from 1inch quote) | ||
pub lr_swap_details: ClassicSwapDetails, | ||
/// found best order which can be filled with LR swap | ||
pub best_order: AggregatedOrderbookEntryV2, | ||
/// base/rel price including the price of the LR swap part | ||
pub total_price: BigDecimal, | ||
/// Same retuned | ||
pub trade_fee: TradePreimageResponse, | ||
} | ||
|
||
/// Request to sell or buy with LR | ||
#[derive(Debug, Deserialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct LrFillOrderRequest { | ||
/// Original sell or buy request (but only MatchBy::Orders could be used to fill the maker swap found in ) | ||
#[serde(flatten)] | ||
pub fill_req: SellBuyRequest, | ||
|
||
/// Tx data to create one inch swap (from 1inch quote) | ||
/// TODO: make this a enum to allow other LR providers | ||
pub lr_swap_details: ClassicSwapDetails, | ||
} | ||
|
||
/// Request to sell or buy with LR | ||
#[derive(Debug, Deserialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct LrFillOrderResponse { | ||
/// Original sell or buy response | ||
#[serde(flatten)] | ||
pub fill_response: SellBuyResponse, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters