renegade_sdk/external_match_client/
options.rs1use url::form_urlencoded;
3
4use crate::{
5 api_types::{
6 ASSEMBLE_EXTERNAL_MATCH_ROUTE, REQUEST_EXTERNAL_MATCH_ROUTE, REQUEST_EXTERNAL_QUOTE_ROUTE,
7 },
8 types::ExternalOrder,
9 GAS_REFUND_NATIVE_ETH_QUERY_PARAM,
10};
11
12use super::{GAS_REFUND_ADDRESS_QUERY_PARAM, GAS_SPONSORSHIP_QUERY_PARAM};
13
14#[derive(Clone, Default)]
16pub struct RequestQuoteOptions {
17 pub disable_gas_sponsorship: bool,
19 pub gas_refund_address: Option<String>,
21 pub refund_native_eth: bool,
23}
24
25impl RequestQuoteOptions {
26 pub fn new() -> Self {
28 Default::default()
29 }
30
31 pub fn disable_gas_sponsorship(mut self) -> Self {
33 self.disable_gas_sponsorship = true;
34 self
35 }
36
37 pub fn with_gas_refund_address(mut self, gas_refund_address: String) -> Self {
39 self.gas_refund_address = Some(gas_refund_address);
40 self
41 }
42
43 pub fn with_refund_native_eth(mut self) -> Self {
45 self.refund_native_eth = true;
46 self
47 }
48
49 pub(crate) fn build_request_path(&self) -> String {
51 let mut query = form_urlencoded::Serializer::new(String::new());
52 query.append_pair(GAS_SPONSORSHIP_QUERY_PARAM, &self.disable_gas_sponsorship.to_string());
53 query.append_pair(GAS_REFUND_NATIVE_ETH_QUERY_PARAM, &self.refund_native_eth.to_string());
54
55 if let Some(addr) = &self.gas_refund_address {
56 query.append_pair(GAS_REFUND_ADDRESS_QUERY_PARAM, addr);
57 }
58
59 format!("{}?{}", REQUEST_EXTERNAL_QUOTE_ROUTE, query.finish())
60 }
61}
62
63#[deprecated(
65 since = "0.1.0",
66 note = "This endpoint will soon be removed, use `request_quote` and `assemble_quote` instead"
67)]
68#[derive(Clone, Default)]
69pub struct ExternalMatchOptions {
70 pub do_gas_estimation: bool,
72 pub sponsor_gas: bool,
78 pub gas_refund_address: Option<String>,
80 pub receiver_address: Option<String>,
84}
85
86#[allow(deprecated)]
87impl ExternalMatchOptions {
88 pub fn new() -> Self {
90 Default::default()
91 }
92
93 pub fn with_gas_estimation(mut self, do_gas_estimation: bool) -> Self {
95 self.do_gas_estimation = do_gas_estimation;
96 self
97 }
98
99 pub fn with_receiver_address(mut self, receiver_address: String) -> Self {
101 self.receiver_address = Some(receiver_address);
102 self
103 }
104
105 pub fn request_gas_sponsorship(mut self) -> Self {
107 self.sponsor_gas = true;
108 self
109 }
110
111 pub fn with_gas_refund_address(mut self, gas_refund_address: String) -> Self {
113 self.gas_refund_address = Some(gas_refund_address);
114 self
115 }
116
117 pub(crate) fn build_request_path(&self) -> String {
119 let mut query = form_urlencoded::Serializer::new(String::new());
120
121 query.append_pair(GAS_SPONSORSHIP_QUERY_PARAM, &(!self.sponsor_gas).to_string());
123 if let Some(addr) = &self.gas_refund_address {
124 query.append_pair(GAS_REFUND_ADDRESS_QUERY_PARAM, addr);
125 }
126
127 format!("{}?{}", REQUEST_EXTERNAL_MATCH_ROUTE, query.finish())
128 }
129}
130
131#[derive(Clone, Default)]
133pub struct AssembleQuoteOptions {
134 pub do_gas_estimation: bool,
136 pub allow_shared: bool,
141 #[deprecated(
147 since = "0.1.0",
148 note = "This option will soon be removed, request gas sponsorship when requesting a quote instead"
149 )]
150 pub sponsor_gas: bool,
151 #[deprecated(
153 since = "0.1.0",
154 note = "This option will soon be removed, request gas sponsorship when requesting a quote instead"
155 )]
156 pub gas_refund_address: Option<String>,
157 pub receiver_address: Option<String>,
161 pub updated_order: Option<ExternalOrder>,
166}
167
168impl AssembleQuoteOptions {
169 pub fn new() -> Self {
171 Default::default()
172 }
173
174 pub fn with_gas_estimation(mut self, do_gas_estimation: bool) -> Self {
176 self.do_gas_estimation = do_gas_estimation;
177 self
178 }
179
180 pub fn with_allow_shared(mut self, allow_shared: bool) -> Self {
182 self.allow_shared = allow_shared;
183 self
184 }
185
186 #[deprecated(
188 since = "0.1.0",
189 note = "This option will soon be removed, request gas sponsorship when requesting a quote instead"
190 )]
191 #[allow(deprecated)]
192 pub fn request_gas_sponsorship(mut self) -> Self {
193 self.sponsor_gas = true;
194 self
195 }
196
197 #[deprecated(
199 since = "0.1.0",
200 note = "This option will soon be removed, request gas sponsorship when requesting a quote instead"
201 )]
202 #[allow(deprecated)]
203 pub fn with_gas_refund_address(mut self, gas_refund_address: String) -> Self {
204 self.gas_refund_address = Some(gas_refund_address);
205 self
206 }
207
208 pub fn with_receiver_address(mut self, receiver_address: String) -> Self {
210 self.receiver_address = Some(receiver_address);
211 self
212 }
213
214 pub fn with_updated_order(mut self, updated_order: ExternalOrder) -> Self {
216 self.updated_order = Some(updated_order);
217 self
218 }
219
220 #[allow(deprecated)]
222 pub(crate) fn build_request_path(&self) -> String {
223 let mut query = form_urlencoded::Serializer::new(String::new());
224 if self.sponsor_gas {
225 query.append_pair(GAS_SPONSORSHIP_QUERY_PARAM, &(!self.sponsor_gas).to_string());
230 }
231
232 if let Some(addr) = &self.gas_refund_address {
233 query.append_pair(GAS_REFUND_ADDRESS_QUERY_PARAM, addr);
234 }
235
236 let query_str = query.finish();
237 if query_str.is_empty() {
238 return ASSEMBLE_EXTERNAL_MATCH_ROUTE.to_string();
239 }
240
241 format!("{ASSEMBLE_EXTERNAL_MATCH_ROUTE}?{query_str}")
242 }
243}