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)
| 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 |