MCPcopy Create free account
hub / github.com/cowprotocol/services / parameters_from_app_data

Method parameters_from_app_data

crates/simulator/src/simulation_builder.rs:209–248  ·  view source on GitHub ↗

Parses the app data JSON and configures the builder accordingly: - Pre/post hooks are encoded as interactions via the [`HooksTrampoline`] - Flashloan/wrapper fields set the [`WrapperConfig`].

(mut self, app_data: &str)

Source from the content-addressed store, hash-verified

207 /// - Pre/post hooks are encoded as interactions via the [`HooksTrampoline`]
208 /// - Flashloan/wrapper fields set the [`WrapperConfig`].
209 pub fn parameters_from_app_data(mut self, app_data: &str) -> Result<Self, BuildError> {
210 let protocol = app_data::parse(app_data.as_bytes()).map_err(BuildError::AppDataParse)?;
211
212 self.pre_interactions
213 .extend(self.encode_hooks(&protocol.hooks.pre));
214 self.post_interactions
215 .extend(self.encode_hooks(&protocol.hooks.post));
216
217 match (protocol.wrappers.is_empty(), protocol.flashloan) {
218 (false, Some(_)) => return Err(BuildError::FlashloanWrappersIncompatible),
219 (false, None) => {
220 let mut wrapper_calls = Vec::with_capacity(protocol.wrappers.len());
221 for w in protocol.wrappers {
222 // TODO: REMOVE THIS HACK!
223 // Unconditionally add state override for euler compatibility.
224 // If this state override gets added to calls that don't need it
225 // it will not interfere with the simulation.
226 self.account_override_requests
227 .extend(compute_euler_override(&w));
228
229 wrapper_calls.push(WrapperCall {
230 address: w.address,
231 data: w.data.into(),
232 });
233 }
234 self.wrapper = WrapperConfig::Custom(wrapper_calls);
235 }
236 (true, Some(flashloan)) => {
237 self.wrapper = WrapperConfig::Flashloan(vec![FlashloanRequest {
238 amount: flashloan.amount,
239 borrower: flashloan.protocol_adapter,
240 lender: flashloan.liquidity_provider,
241 token: flashloan.token,
242 }]);
243 }
244 (true, None) => {}
245 }
246
247 Ok(self)
248 }
249
250 /// Generates 1 interaction executing the given hooks via the trampoline
251 /// contract since executing hooks directly from the settlement contract

Callers 6

build_settle_callMethod · 0.80
prepare_simulationMethod · 0.80
simulate_orderMethod · 0.80
simulate_custom_orderMethod · 0.80
build_replay_simulationFunction · 0.80

Calls 10

parseFunction · 0.85
compute_euler_overrideFunction · 0.85
CustomClass · 0.85
as_bytesMethod · 0.80
extendMethod · 0.80
encode_hooksMethod · 0.80
lenMethod · 0.80
FlashloanClass · 0.50
is_emptyMethod · 0.45
intoMethod · 0.45

Tested by 2

build_replay_simulationFunction · 0.64