renegade_sdk/external_match_client/
options.rs1use url::form_urlencoded;
3
4use crate::{
5 GAS_REFUND_NATIVE_ETH_QUERY_PARAM,
6 api_types::{ASSEMBLE_MATCH_BUNDLE_ROUTE, ExternalOrderV2, GET_QUOTE_ROUTE, v1_types},
7};
8
9use super::{GAS_REFUND_ADDRESS_QUERY_PARAM, GAS_SPONSORSHIP_QUERY_PARAM};
10
11#[derive(Clone, Default)]
13pub struct RequestQuoteOptions {
14 pub disable_gas_sponsorship: bool,
16 pub gas_refund_address: Option<String>,
18 pub refund_native_eth: bool,
20}
21
22impl RequestQuoteOptions {
23 pub fn new() -> Self {
25 Default::default()
26 }
27
28 pub fn disable_gas_sponsorship(mut self) -> Self {
30 self.disable_gas_sponsorship = true;
31 self
32 }
33
34 pub fn with_gas_refund_address(mut self, gas_refund_address: String) -> Self {
36 self.gas_refund_address = Some(gas_refund_address);
37 self
38 }
39
40 pub fn with_refund_native_eth(mut self) -> Self {
42 self.refund_native_eth = true;
43 self
44 }
45
46 pub(crate) fn build_request_path(&self) -> String {
48 let mut query = form_urlencoded::Serializer::new(String::new());
49 query.append_pair(GAS_SPONSORSHIP_QUERY_PARAM, &self.disable_gas_sponsorship.to_string());
50 query.append_pair(GAS_REFUND_NATIVE_ETH_QUERY_PARAM, &self.refund_native_eth.to_string());
51
52 if let Some(addr) = &self.gas_refund_address {
53 query.append_pair(GAS_REFUND_ADDRESS_QUERY_PARAM, addr);
54 }
55
56 format!("{}?{}", GET_QUOTE_ROUTE, query.finish())
57 }
58}
59
60#[derive(Clone)]
62pub struct ExternalMatchOptions {
63 pub do_gas_estimation: bool,
65 pub sponsor_gas: bool,
71 pub gas_refund_address: Option<String>,
73 pub receiver_address: Option<String>,
77}
78
79impl Default for ExternalMatchOptions {
80 fn default() -> Self {
81 Self {
82 do_gas_estimation: false,
83 sponsor_gas: true,
84 gas_refund_address: None,
85 receiver_address: None,
86 }
87 }
88}
89
90#[allow(deprecated)]
91impl ExternalMatchOptions {
92 pub fn new() -> Self {
94 Default::default()
95 }
96
97 pub fn with_gas_estimation(mut self, do_gas_estimation: bool) -> Self {
99 self.do_gas_estimation = do_gas_estimation;
100 self
101 }
102
103 pub fn with_receiver_address(mut self, receiver_address: String) -> Self {
105 self.receiver_address = Some(receiver_address);
106 self
107 }
108
109 pub fn request_gas_sponsorship(mut self) -> Self {
111 self.sponsor_gas = true;
112 self
113 }
114
115 pub fn with_gas_refund_address(mut self, gas_refund_address: String) -> Self {
117 self.gas_refund_address = Some(gas_refund_address);
118 self
119 }
120
121 pub(crate) fn build_request_path(&self) -> String {
123 let mut query = form_urlencoded::Serializer::new(String::new());
124
125 query.append_pair(GAS_SPONSORSHIP_QUERY_PARAM, &(!self.sponsor_gas).to_string());
127 if let Some(addr) = &self.gas_refund_address {
128 query.append_pair(GAS_REFUND_ADDRESS_QUERY_PARAM, addr);
129 }
130
131 format!("{}?{}", ASSEMBLE_MATCH_BUNDLE_ROUTE, query.finish())
132 }
133}
134
135#[derive(Clone, Default)]
137pub struct AssembleQuoteOptionsV2 {
138 pub do_gas_estimation: bool,
140 pub receiver_address: Option<String>,
144 pub updated_order: Option<ExternalOrderV2>,
149}
150
151impl AssembleQuoteOptionsV2 {
152 pub fn new() -> Self {
154 Default::default()
155 }
156
157 pub fn with_gas_estimation(mut self, do_gas_estimation: bool) -> Self {
159 self.do_gas_estimation = do_gas_estimation;
160 self
161 }
162
163 pub fn with_receiver_address(mut self, receiver_address: String) -> Self {
165 self.receiver_address = Some(receiver_address);
166 self
167 }
168
169 pub fn with_updated_order(mut self, updated_order: ExternalOrderV2) -> Self {
171 self.updated_order = Some(updated_order);
172 self
173 }
174}
175
176#[derive(Clone, Default)]
182pub struct AssembleQuoteOptions {
183 pub do_gas_estimation: bool,
185 pub allow_shared: bool,
187 pub receiver_address: Option<String>,
191 pub updated_order: Option<v1_types::ExternalOrder>,
196}
197
198impl AssembleQuoteOptions {
199 pub fn new() -> Self {
201 Default::default()
202 }
203
204 pub fn with_gas_estimation(mut self, do_gas_estimation: bool) -> Self {
206 self.do_gas_estimation = do_gas_estimation;
207 self
208 }
209
210 pub fn with_allow_shared(mut self, allow_shared: bool) -> Self {
212 self.allow_shared = allow_shared;
213 self
214 }
215
216 pub fn with_receiver_address(mut self, receiver_address: String) -> Self {
218 self.receiver_address = Some(receiver_address);
219 self
220 }
221
222 pub fn with_updated_order(mut self, updated_order: v1_types::ExternalOrder) -> Self {
224 self.updated_order = Some(updated_order);
225 self
226 }
227}