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

Method parameters_from_app_data

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

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