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

Method parameters_from_app_data

crates/simulator/src/simulation_builder.rs:221–260  ·  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

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