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