odos_sdk/
limit_order_v2.rs1use std::{fmt::Debug, marker::PhantomData};
2
3use OdosLimitOrderRouter::TokenInfo;
4use OdosLimitOrderV2::OdosLimitOrderV2Instance;
5use alloy_contract::CallBuilder;
6use alloy_network::Ethereum;
7use alloy_primitives::{Address, U256};
8use alloy_provider::Provider;
9use alloy_rpc_types::TransactionRequest;
10use alloy_sol_types::sol;
11
12use crate::SwapInputs;
13
14#[derive(Debug, Clone)]
16pub struct LimitOrderV2<P: Provider<Ethereum>> {
17 instance: OdosLimitOrderV2Instance<P>,
18}
19
20impl<P: Provider<Ethereum>> LimitOrderV2<P> {
21 pub fn new(address: Address, provider: P) -> Self {
22 Self {
23 instance: OdosLimitOrderV2Instance::new(address, provider),
24 }
25 }
26
27 pub async fn liquidator_address(&self) -> Result<Address, alloy_contract::Error> {
28 self.instance.liquidatorAddress().call().await
29 }
30
31 pub async fn owner(&self) -> Result<Address, alloy_contract::Error> {
32 self.instance.owner().call().await
33 }
34
35 pub fn build_swap_router_funds_call(
36 &self,
37 from: Address,
38 to: Address,
39 inputs: &SwapInputs,
40 ) -> CallBuilder<&P, PhantomData<OdosLimitOrderV2::swapRouterFundsCall>> {
41 self.instance
42 .swapRouterFunds(
43 vec![TokenInfo::from((
44 inputs.token_address(),
45 inputs.amount_in(),
46 ))],
47 vec![inputs.receiver()],
48 TokenInfo::from((inputs.output_token_address(), inputs.value_out_min())),
49 to,
50 inputs.path_definition().clone(),
51 inputs.executor(),
52 )
53 .from(from)
54 }
55
56 pub fn transfer_router_funds_request(
57 &self,
58 from: Address,
59 token: Address,
60 amount: U256,
61 output_recipient: Address,
62 ) -> TransactionRequest {
63 self.transfer_router_funds(from, token, amount, output_recipient)
64 .into_transaction_request()
65 }
66
67 pub fn transfer_router_funds(
68 &self,
69 from: Address,
70 token: Address,
71 amount: U256,
72 output_recipient: Address,
73 ) -> CallBuilder<&P, PhantomData<OdosLimitOrderV2::transferRouterFundsCall>> {
74 self.instance
75 .transferRouterFunds(vec![token], vec![amount], output_recipient)
76 .from(from)
77 }
78
79 pub fn transfer_router_funds_calldata(
80 &self,
81 from: Address,
82 token: Address,
83 amount: U256,
84 output_recipient: Address,
85 ) -> Vec<u8> {
86 self.transfer_router_funds(from, token, amount, output_recipient)
87 .calldata()
88 .to_vec()
89 }
90}
91
92impl Debug for OdosLimitOrderV2::swapRouterFundsReturn {
93 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94 write!(f, "amountOut: {}", self.amountOut)
95 }
96}
97
98impl Debug for OdosLimitOrderRouter::TokenInfo {
99 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
100 f.debug_struct("TokenInfo")
101 .field("input_token", &self.tokenAddress)
102 .field("input_amount", &self.tokenAmount)
103 .finish()
104 }
105}
106
107sol!(
109 #[allow(missing_docs)]
110 #[sol(rpc)]
111 OdosLimitOrderV2,
112 "abis/odos_limit_order_v2.json"
113);