From 425b40133822accfd5820253be9db6a8b3967577 Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 9 Dec 2024 13:05:44 +0400 Subject: [PATCH 01/28] Add test testClear2ZeroRatioBug - show no changes to Alice's or Bob's balances due to zero ratio --- test/concrete/ob/OrderBook.clear.mock.t.sol | 95 +++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index e7cee4a81..fcf518d76 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -139,6 +139,101 @@ contract OrderBookClearTest is OrderBookExternalMockTest { assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), bobBountyVaultId), 0.00495e18); } + function testClear2ZeroRatioBug( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId + ) public { + // Different accounts + vm.assume(alice != bob); + vm.assume(alice != bountyBot); + vm.assume(bob != bountyBot); + vm.assume(aliceBountyVaultId != bobBountyVaultId); + vm.assume(aliceConfig.validInputs.length > 0); + vm.assume(aliceConfig.validOutputs.length > 0); + vm.assume(bobConfig.validInputs.length > 0); + vm.assume(bobConfig.validOutputs.length > 0); + + aliceConfig.evaluable.interpreter = iInterpreter; + aliceConfig.evaluable.store = iStore; + + bobConfig.evaluable.interpreter = iInterpreter; + bobConfig.evaluable.store = iStore; + + aliceConfig.validInputs[0].token = address(iToken0); + aliceConfig.validOutputs[0].token = address(iToken1); + + bobConfig.validInputs[0].token = address(iToken1); + bobConfig.validOutputs[0].token = address(iToken0); + + aliceConfig.validInputs[0].decimals = 18; + aliceConfig.validOutputs[0].decimals = 18; + bobConfig.validInputs[0].decimals = 18; + bobConfig.validOutputs[0].decimals = 18; + + aliceConfig.meta = ""; + bobConfig.meta = ""; + + uint256 amount = 2e18; + + _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, amount); + _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, amount); + { + (OrderV3 memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, aliceConfig, expression); + (OrderV3 memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, bobConfig, expression); + + ClearConfig memory configClear = ClearConfig({ + aliceInputIOIndex: 0, + aliceOutputIOIndex: 0, + bobInputIOIndex: 0, + bobOutputIOIndex: 0, + aliceBountyVaultId: aliceBountyVaultId, + bobBountyVaultId: bobBountyVaultId + }); + + { + // Mock the interpreter.eval for Alice and Bob orders with zero ratio + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 0; // Zero orderIORatio + orderStackAlice[1] = 5e17; // orderOutputMax + vm.mockCall( + address(iInterpreter), + abi.encodeWithSelector(IInterpreterV3.eval3.selector), + abi.encode(orderStackAlice, new uint256[](0)) + ); + uint256[] memory orderStackBob = new uint256[](2); + + orderStackBob[0] = 0; // Zero orderIORatio + orderStackBob[1] = 5e17; // orderOutputMax + vm.mockCall( + address(iInterpreter), + abi.encodeWithSelector(IInterpreterV3.eval3.selector), + abi.encode(orderStackBob, new uint256[](0)) + ); + } + + vm.prank(bountyBot); + iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); + } + // No changes to Alice's or Bob's balances due to zero ratio + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + ); + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), + amount + ); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); + assertEq( + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), amount + ); + } + /// Make a deposit to the OB mocking the internal transferFrom call. function _depositInternal(address depositor, address token, uint256 vaultId, uint256 amount) internal { vm.prank(depositor); From 61bd381cced2dedd25b809abc0cab03ba3ec8abf Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 9 Dec 2024 13:42:03 +0400 Subject: [PATCH 02/28] Add test testClear2ZeroRatioBug - show no vault balance changes and no bounties --- test/concrete/ob/OrderBook.clear.mock.t.sol | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index fcf518d76..8b25617c2 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -220,18 +220,14 @@ contract OrderBookClearTest is OrderBookExternalMockTest { vm.prank(bountyBot); iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } - // No changes to Alice's or Bob's balances due to zero ratio - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 - ); - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - amount - ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); + + //Check that the entire output vault balances have been transferred to the bounty bot assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), amount + iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), 0 ); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), amount); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), amount); } /// Make a deposit to the OB mocking the internal transferFrom call. From 0eaf103f8d6ec1c65d00e1e59187137ac0527654 Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 16 Dec 2024 17:36:50 +0400 Subject: [PATCH 03/28] Move InputToken.svelte to ui-components --- .../lib/components/input/InputToken.svelte | 60 +++++++++++++++++++ packages/ui-components/src/lib/index.ts | 1 + .../src/lib/components/InputToken.svelte | 60 ------------------- .../ModalVaultDepositGeneric.svelte | 2 +- 4 files changed, 62 insertions(+), 61 deletions(-) create mode 100644 packages/ui-components/src/lib/components/input/InputToken.svelte delete mode 100644 tauri-app/src/lib/components/InputToken.svelte diff --git a/packages/ui-components/src/lib/components/input/InputToken.svelte b/packages/ui-components/src/lib/components/input/InputToken.svelte new file mode 100644 index 000000000..fe16865e4 --- /dev/null +++ b/packages/ui-components/src/lib/components/input/InputToken.svelte @@ -0,0 +1,60 @@ + + +
+
+
+ +
+ + {#if !isAddressValid && address.length > 0} + Invalid Address + {/if} + + Token Address +
+
+ + Decimals +
+
diff --git a/packages/ui-components/src/lib/index.ts b/packages/ui-components/src/lib/index.ts index 170227373..9a30ff6c7 100644 --- a/packages/ui-components/src/lib/index.ts +++ b/packages/ui-components/src/lib/index.ts @@ -42,6 +42,7 @@ export { default as IconSuccess } from './components/IconSuccess.svelte'; export { default as IconTelegram } from './components/IconTelegram.svelte'; export { default as IconWalletConnect } from './components/IconWalletConnect.svelte'; export { default as IconWarning } from './components/IconWarning.svelte'; +export { default as InputToken } from './components/input/InputToken.svelte'; //Types export type { AppStoresInterface } from './types/appStores.ts'; diff --git a/tauri-app/src/lib/components/InputToken.svelte b/tauri-app/src/lib/components/InputToken.svelte deleted file mode 100644 index b5d4f2934..000000000 --- a/tauri-app/src/lib/components/InputToken.svelte +++ /dev/null @@ -1,60 +0,0 @@ - - -
-
-
- -
- - {#if !isAddressValid && address.length > 0} - Invalid Address - {/if} - - Token Address -
-
- - Decimals -
-
diff --git a/tauri-app/src/lib/components/ModalVaultDepositGeneric.svelte b/tauri-app/src/lib/components/ModalVaultDepositGeneric.svelte index 277fa44ae..5c83e956f 100644 --- a/tauri-app/src/lib/components/ModalVaultDepositGeneric.svelte +++ b/tauri-app/src/lib/components/ModalVaultDepositGeneric.svelte @@ -6,7 +6,7 @@ vaultDepositApproveCalldata, vaultDepositCalldata, } from '$lib/services/vault'; - import InputToken from '$lib/components/InputToken.svelte'; + import { InputToken } from '@rainlanguage/ui-components'; import InputVaultId from '$lib/components/InputVaultId.svelte'; import { orderbookAddress } from '$lib/stores/settings'; import { checkAllowance, ethersExecute } from '$lib/services/ethersTx'; From 986adbe6f14f311959bd9d2fb62172c5990643cc Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 16 Dec 2024 18:30:19 +0400 Subject: [PATCH 04/28] Add additional typings in ui-components --- packages/ui-components/src/additional-svelte-typings.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/ui-components/src/additional-svelte-typings.d.ts diff --git a/packages/ui-components/src/additional-svelte-typings.d.ts b/packages/ui-components/src/additional-svelte-typings.d.ts new file mode 100644 index 000000000..d742690da --- /dev/null +++ b/packages/ui-components/src/additional-svelte-typings.d.ts @@ -0,0 +1,7 @@ +declare namespace svelteHTML { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface HTMLAttributes { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + 'on:complete'?: (event: any) => any; + } +} From 193b3dbe120295917f6bf14421c9fd4a7f698ea7 Mon Sep 17 00:00:00 2001 From: nino Date: Mon, 16 Dec 2024 18:55:25 +0400 Subject: [PATCH 05/28] Format --- .../ui-components/src/additional-svelte-typings.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ui-components/src/additional-svelte-typings.d.ts b/packages/ui-components/src/additional-svelte-typings.d.ts index d742690da..cc18f8751 100644 --- a/packages/ui-components/src/additional-svelte-typings.d.ts +++ b/packages/ui-components/src/additional-svelte-typings.d.ts @@ -1,7 +1,7 @@ declare namespace svelteHTML { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - interface HTMLAttributes { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - 'on:complete'?: (event: any) => any; - } + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface HTMLAttributes { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + 'on:complete'?: (event: any) => any; + } } From de40ff204fbbca02b0f6c590dedd9fa04ee2ee3f Mon Sep 17 00:00:00 2001 From: findolor Date: Wed, 18 Dec 2024 19:53:38 +0300 Subject: [PATCH 06/28] add order field to dotrain yaml --- crates/settings/src/order.rs | 295 +++++++++++++++++++++++++++- crates/settings/src/yaml/dotrain.rs | 74 ++++++- crates/settings/src/yaml/mod.rs | 9 +- 3 files changed, 372 insertions(+), 6 deletions(-) diff --git a/crates/settings/src/order.rs b/crates/settings/src/order.rs index a7db0f5f8..7a72a07c4 100644 --- a/crates/settings/src/order.rs +++ b/crates/settings/src/order.rs @@ -1,9 +1,17 @@ use crate::*; use alloy::primitives::U256; use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, sync::Arc}; +use std::{ + collections::HashMap, + str::FromStr, + sync::{Arc, RwLock}, +}; +use strict_yaml_rust::StrictYaml; use thiserror::Error; use typeshare::typeshare; +use yaml::{ + optional_string, require_hash, require_string, require_vec, YamlError, YamlParsableHash, +}; #[cfg(target_family = "wasm")] use rain_orderbook_bindings::{impl_all_wasm_traits, wasm_traits::prelude::*}; @@ -27,10 +35,14 @@ pub struct OrderIO { impl_all_wasm_traits!(OrderIO); #[typeshare] -#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(target_family = "wasm", derive(Tsify))] #[serde(rename_all = "kebab-case")] +#[serde(default)] pub struct Order { + #[serde(skip)] + pub document: Arc>, + pub key: String, #[typeshare(typescript(type = "OrderIO[]"))] #[cfg_attr(target_family = "wasm", tsify(type = "Vault[]"))] pub inputs: Vec, @@ -47,6 +59,189 @@ pub struct Order { #[cfg(target_family = "wasm")] impl_all_wasm_traits!(Order); +impl Order { + pub fn validate_vault_id(value: &str) -> Result { + U256::from_str(value).map_err(ParseOrderConfigSourceError::VaultParseError) + } +} + +impl YamlParsableHash for Order { + fn parse_all_from_yaml( + document: Arc>, + ) -> Result, YamlError> { + let document_read = document.read().map_err(|_| YamlError::ReadLockError)?; + let orders_hash = require_hash( + &document_read, + Some("orders"), + Some("missing field: orders".to_string()), + )?; + + orders_hash + .into_iter() + .map(|(key_yaml, order_yaml)| { + let order_key = key_yaml.as_str().unwrap_or_default().to_string(); + + let mut network: Option> = None; + + let deployer = match optional_string(order_yaml, "deployer") { + Some(deployer_name) => { + let deployer = + Arc::new(Deployer::parse_from_yaml(document.clone(), &deployer_name)?); + if let Some(n) = &network { + if deployer.network != *n { + return Err(YamlError::ParseOrderConfigSourceError( + ParseOrderConfigSourceError::NetworkNotMatch, + )); + } + } else { + network = Some(deployer.network.clone()); + } + Some(deployer) + } + None => None, + }; + + let orderbook = match optional_string(order_yaml, "orderbook") { + Some(orderbook_name) => { + let orderbook = Arc::new(Orderbook::parse_from_yaml( + document.clone(), + &orderbook_name, + )?); + if let Some(n) = &network { + if orderbook.network != *n { + return Err(YamlError::ParseOrderConfigSourceError( + ParseOrderConfigSourceError::NetworkNotMatch, + )); + } + } else { + network = Some(orderbook.network.clone()); + } + Some(orderbook) + } + None => None, + }; + + let inputs = require_vec( + order_yaml, + "inputs", + Some(format!("inputs list missing in order: {order_key}")), + )? + .iter() + .enumerate() + .map(|(i, input)| { + let token_name = require_string( + input, + Some("token"), + Some(format!( + "token string missing in input index: {i} in order: {order_key}" + )), + )?; + let token = Token::parse_from_yaml(document.clone(), &token_name)?; + + if let Some(n) = &network { + if token.network != *n { + return Err(YamlError::ParseOrderConfigSourceError( + ParseOrderConfigSourceError::NetworkNotMatch, + )); + } + } else { + network = Some(token.network.clone()); + } + + let vault_id = match optional_string(input, "vault-id") { + Some(id) => Some(Order::validate_vault_id(&id)?), + None => None, + }; + + Ok(OrderIO { + token: Arc::new(token), + vault_id, + }) + }) + .collect::, YamlError>>()?; + + let outputs = require_vec( + order_yaml, + "outputs", + Some(format!("outputs list missing in order: {order_key}")), + )? + .iter() + .enumerate() + .map(|(i, output)| { + let token_name = require_string( + output, + Some("token"), + Some(format!( + "token string missing in output index: {i} in order: {order_key}" + )), + )?; + let token = Token::parse_from_yaml(document.clone(), &token_name)?; + + if let Some(n) = &network { + if token.network != *n { + return Err(YamlError::ParseOrderConfigSourceError( + ParseOrderConfigSourceError::NetworkNotMatch, + )); + } + } else { + network = Some(token.network.clone()); + } + + let vault_id = match optional_string(output, "vault-id") { + Some(id) => Some(Order::validate_vault_id(&id)?), + None => None, + }; + + Ok(OrderIO { + token: Arc::new(token), + vault_id, + }) + }) + .collect::, YamlError>>()?; + + let order = Order { + document: document.clone(), + key: order_key.clone(), + inputs, + outputs, + network: network.ok_or(ParseOrderConfigSourceError::NetworkNotFoundError( + String::new(), + ))?, + deployer, + orderbook, + }; + + Ok((order_key, order)) + }) + .collect() + } +} + +impl Default for Order { + fn default() -> Self { + Self { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: String::new(), + inputs: vec![], + outputs: vec![], + network: Arc::new(Network::default()), + deployer: None, + orderbook: None, + } + } +} + +impl PartialEq for Order { + fn eq(&self, other: &Self) -> bool { + self.key == other.key + && self.inputs == other.inputs + && self.outputs == other.outputs + && self.network == other.network + && self.deployer == other.deployer + && self.orderbook == other.orderbook + } +} + #[derive(Error, Debug, PartialEq)] pub enum ParseOrderConfigSourceError { #[error("Failed to parse deployer")] @@ -181,6 +376,8 @@ impl OrderConfigSource { .collect::, _>>()?; Ok(Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: String::new(), inputs, outputs, network: network.ok_or(ParseOrderConfigSourceError::NetworkNotFoundError( @@ -194,6 +391,8 @@ impl OrderConfigSource { #[cfg(test)] mod tests { + use yaml::tests::get_document; + use super::*; use crate::test::*; @@ -327,4 +526,96 @@ mod tests { Err(ParseOrderConfigSourceError::TokenParseError(_)) )); } + + #[test] + fn test_parse_orders_from_yaml() { + let yaml = r#" +test: test +"#; + let error = Order::parse_all_from_yaml(get_document(yaml)).unwrap_err(); + assert_eq!( + error, + YamlError::ParseError("missing field: orders".to_string()) + ); + + let yaml = r#" +orders: + order1: +"#; + let error = Order::parse_all_from_yaml(get_document(yaml)).unwrap_err(); + assert_eq!( + error, + YamlError::ParseError("inputs list missing in order: order1".to_string()) + ); + + let yaml = r#" +orders: + order1: + inputs: + - test: test +"#; + let error = Order::parse_all_from_yaml(get_document(yaml)).unwrap_err(); + assert_eq!( + error, + YamlError::ParseError( + "token string missing in input index: 0 in order: order1".to_string() + ) + ); + + let yaml = r#" +orders: + order1: + inputs: + - token: eth +"#; + let error = Order::parse_all_from_yaml(get_document(yaml)).unwrap_err(); + assert_eq!( + error, + YamlError::ParseError("missing field: tokens".to_string()) + ); + + let yaml = r#" +networks: + mainnet: + rpc: "https://mainnet.infura.io" + chain-id: "1" +tokens: + eth: + network: mainnet + address: 0x1234567890123456789012345678901234567890 +orders: + order1: + inputs: + - token: eth +"#; + let error = Order::parse_all_from_yaml(get_document(yaml)).unwrap_err(); + assert_eq!( + error, + YamlError::ParseError("outputs list missing in order: order1".to_string()) + ); + + let yaml = r#" +networks: + mainnet: + rpc: "https://mainnet.infura.io" + chain-id: "1" +tokens: + eth: + network: mainnet + address: 0x1234567890123456789012345678901234567890 +orders: + order1: + inputs: + - token: eth + outputs: + - test: test +"#; + let error = Order::parse_all_from_yaml(get_document(yaml)).unwrap_err(); + assert_eq!( + error, + YamlError::ParseError( + "token string missing in output index: 0 in order: order1".to_string() + ) + ); + } } diff --git a/crates/settings/src/yaml/dotrain.rs b/crates/settings/src/yaml/dotrain.rs index 8e14e37f2..8129b057f 100644 --- a/crates/settings/src/yaml/dotrain.rs +++ b/crates/settings/src/yaml/dotrain.rs @@ -1,4 +1,5 @@ use super::*; +use crate::Order; use std::sync::{Arc, RwLock}; #[derive(Debug, Clone)] @@ -15,10 +16,79 @@ impl YamlParsable for DotrainYaml { let doc = docs[0].clone(); let document = Arc::new(RwLock::new(doc)); - if validate {} + if validate { + Order::parse_all_from_yaml(document.clone())?; + } Ok(DotrainYaml { document }) } } -impl DotrainYaml {} +impl DotrainYaml { + pub fn get_order_keys(&self) -> Result, YamlError> { + let orders = Order::parse_all_from_yaml(self.document.clone())?; + Ok(orders.keys().cloned().collect()) + } + pub fn get_order(&self, key: &str) -> Result { + Order::parse_from_yaml(self.document.clone(), key) + } +} + +#[cfg(test)] +mod tests { + use alloy::primitives::U256; + use orderbook::OrderbookYaml; + + use super::*; + + const FULL_YAML: &str = r#" + networks: + mainnet: + rpc: https://mainnet.infura.io + chain-id: 1 + tokens: + token1: + network: mainnet + address: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 + decimals: 18 + label: Wrapped Ether + symbol: WETH + token2: + network: mainnet + address: 0x0000000000000000000000000000000000000002 + decimals: 6 + label: USD Coin + symbol: USDC + orders: + order1: + inputs: + - token: token1 + vault-id: 1 + outputs: + - token: token2 + vault-id: 2 + "#; + + #[test] + fn test_full_yaml() { + let ob_yaml = OrderbookYaml::new(FULL_YAML.to_string(), false).unwrap(); + let dotrain_yaml = DotrainYaml::new(FULL_YAML.to_string(), false).unwrap(); + + assert_eq!(dotrain_yaml.get_order_keys().unwrap().len(), 1); + let order = dotrain_yaml.get_order("order1").unwrap(); + assert_eq!(order.inputs.len(), 1); + let input = order.inputs.first().unwrap(); + assert_eq!( + *input.token.clone().as_ref(), + ob_yaml.get_token("token1").unwrap() + ); + assert_eq!(input.vault_id, Some(U256::from(1))); + let output = order.outputs.first().unwrap(); + assert_eq!(*output.token.as_ref(), ob_yaml.get_token("token2").unwrap()); + assert_eq!(output.vault_id, Some(U256::from(2))); + assert_eq!( + *order.network.as_ref(), + ob_yaml.get_network("mainnet").unwrap() + ); + } +} diff --git a/crates/settings/src/yaml/mod.rs b/crates/settings/src/yaml/mod.rs index 144a06a70..cd6cca81b 100644 --- a/crates/settings/src/yaml/mod.rs +++ b/crates/settings/src/yaml/mod.rs @@ -2,9 +2,10 @@ pub mod dotrain; pub mod orderbook; use crate::{ - ParseDeployerConfigSourceError, ParseNetworkConfigSourceError, ParseOrderbookConfigSourceError, - ParseTokenConfigSourceError, + ParseDeployerConfigSourceError, ParseNetworkConfigSourceError, ParseOrderConfigSourceError, + ParseOrderbookConfigSourceError, ParseTokenConfigSourceError, }; +use alloy::primitives::ruint::ParseError as RuintParseError; use std::collections::HashMap; use std::sync::{Arc, RwLock}; use std::sync::{PoisonError, RwLockReadGuard, RwLockWriteGuard}; @@ -65,6 +66,8 @@ pub enum YamlError { RwLockWriteGuardError(#[from] PoisonError>), #[error(transparent)] UrlParseError(#[from] UrlParseError), + #[error(transparent)] + RuintParseError(#[from] RuintParseError), #[error("Yaml file is empty")] EmptyFile, #[error("Yaml parse error: {0}")] @@ -89,6 +92,8 @@ pub enum YamlError { ParseOrderbookConfigSourceError(#[from] ParseOrderbookConfigSourceError), #[error(transparent)] ParseDeployerConfigSourceError(#[from] ParseDeployerConfigSourceError), + #[error(transparent)] + ParseOrderConfigSourceError(#[from] ParseOrderConfigSourceError), } impl PartialEq for YamlError { fn eq(&self, other: &Self) -> bool { From 00bc84a1d15311a4e4a59747c0b2be48291eb6a4 Mon Sep 17 00:00:00 2001 From: findolor Date: Wed, 18 Dec 2024 19:53:42 +0300 Subject: [PATCH 07/28] udpate tests --- crates/common/src/add_order.rs | 6 ++++++ crates/settings/src/deployment.rs | 6 ++++++ crates/settings/src/gui.rs | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/crates/common/src/add_order.rs b/crates/common/src/add_order.rs index 633542213..318104e33 100644 --- a/crates/common/src/add_order.rs +++ b/crates/common/src/add_order.rs @@ -485,6 +485,8 @@ price: 2e18; let token3_arc = Arc::new(token3); let known_vault_id = U256::from(1); let order = Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: "".to_string(), inputs: vec![ OrderIO { token: token1_arc.clone(), @@ -591,6 +593,8 @@ _ _: 0 0; let token2_arc = Arc::new(token2); let token3_arc = Arc::new(token3); let order = Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: "".to_string(), inputs: vec![ OrderIO { token: token1_arc.clone(), @@ -733,6 +737,8 @@ _ _: 0 0; let token3_arc = Arc::new(token3); let known_vault_id = U256::from(1); let order = Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: "".to_string(), inputs: vec![ OrderIO { token: token1_arc.clone(), diff --git a/crates/settings/src/deployment.rs b/crates/settings/src/deployment.rs index 794b79fc9..ce3f6af01 100644 --- a/crates/settings/src/deployment.rs +++ b/crates/settings/src/deployment.rs @@ -65,6 +65,8 @@ impl DeploymentConfigSource { mod tests { use super::*; use crate::test::*; + use std::sync::RwLock; + use strict_yaml_rust::StrictYaml; #[test] fn test_try_into_deployment_success() { @@ -78,6 +80,8 @@ mod tests { blocks: None, }; let order = Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: String::new(), inputs: vec![], outputs: vec![], network: mock_network(), @@ -107,6 +111,8 @@ mod tests { blocks: None, }; let order = Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: String::new(), inputs: vec![], outputs: vec![], network: mock_network(), diff --git a/crates/settings/src/gui.rs b/crates/settings/src/gui.rs index 1b1a0a1dd..219d7ff66 100644 --- a/crates/settings/src/gui.rs +++ b/crates/settings/src/gui.rs @@ -226,12 +226,15 @@ impl_all_wasm_traits!(Gui); #[cfg(test)] mod tests { + use std::sync::RwLock; + use super::*; use crate::{ test::{mock_deployer, mock_network, mock_token}, Order, Scenario, }; use alloy::primitives::Address; + use strict_yaml_rust::StrictYaml; #[test] fn test_gui_creation_success() { @@ -308,6 +311,8 @@ mod tests { blocks: None, }; let order = Order { + document: Arc::new(RwLock::new(StrictYaml::String("".to_string()))), + key: String::new(), inputs: vec![], outputs: vec![], network: mock_network(), From c3af6ea3da1335a53379ec128f91647164328ce1 Mon Sep 17 00:00:00 2001 From: findolor Date: Wed, 18 Dec 2024 20:01:17 +0300 Subject: [PATCH 08/28] update tests --- packages/orderbook/test/js_api/gui.test.ts | 2 +- packages/webapp/src/routes/deployment/+page.svelte | 3 ++- tauri-app/src/tests/pickConfig.test.ts | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/orderbook/test/js_api/gui.test.ts b/packages/orderbook/test/js_api/gui.test.ts index b4e4ea876..967bca540 100644 --- a/packages/orderbook/test/js_api/gui.test.ts +++ b/packages/orderbook/test/js_api/gui.test.ts @@ -592,7 +592,7 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Gui', async function () describe('state management tests', async () => { let serializedState = - 'H4sIAAAAAAAA_3WNTQoCMQyFZ1REb-FaUNLUdNqdR_AKSZvKIIygs_D4LkxdCL7Nl5_He-fuo4FDyJ6ZXNIEKLlWDigpRR-rehWUisKQyZNXikhZQ4m1FOAMLi0sZ2uUcSrjdD243g7Qb2y6PPSp887t2-fl0J8oDDEBSy5a_-2_4dg1LY0OoBWujfP9ppP7OldGgmN4A9ok8gT9AAAA'; + 'H4sIAAAAAAAA_3WNTQoCMQxGZ1REb-FaUJpMk7Y7j-AV0jaVQRhBZ-HxXdi6EObbvPzxcum-iUxoKQSJUbyFlEjFSPFZQrQumewZUYvmJMihOKABnLNUUJnVyap69s03Tnmcbifo68D0u1pdn_rS-QDHtnkDDpbY-WAkpqxlqf-XY9eyrgRj2sNt5fy46wS_y00lmTN_AHYyHjD9AAAA'; let gui: DotrainOrderGui; beforeAll(async () => { mockServer diff --git a/packages/webapp/src/routes/deployment/+page.svelte b/packages/webapp/src/routes/deployment/+page.svelte index c7457a600..ac0a3e33b 100644 --- a/packages/webapp/src/routes/deployment/+page.svelte +++ b/packages/webapp/src/routes/deployment/+page.svelte @@ -7,6 +7,7 @@ type DepositAndAddOrderCalldataResult, type GuiDeposit, type GuiFieldDefinition, + type Network, type SelectTokens, type TokenInfos } from '@rainlanguage/orderbook/js_api'; @@ -132,7 +133,7 @@ await window.ethereum?.request({ method: 'eth_requestAccounts' }); const walletClient = createWalletClient({ chain: getChainById( - gui.getCurrentDeployment().deployment.order.network['chain-id'] as number + (gui.getCurrentDeployment().deployment.order.network as Network)['chain-id'] as number ), // @ts-expect-error window.ethereum is not typed transport: custom(window.ethereum!) diff --git a/tauri-app/src/tests/pickConfig.test.ts b/tauri-app/src/tests/pickConfig.test.ts index 2e4b36044..96532bf24 100644 --- a/tauri-app/src/tests/pickConfig.test.ts +++ b/tauri-app/src/tests/pickConfig.test.ts @@ -48,6 +48,7 @@ export const config: Config = { tokens: {}, orders: { buy: { + key: 'buy', inputs: [], outputs: [], network: { @@ -57,6 +58,7 @@ export const config: Config = { }, }, sell: { + key: 'sell', inputs: [], outputs: [], network: { @@ -124,6 +126,7 @@ export const config: Config = { }, }, order: { + key: 'sell', inputs: [], outputs: [], network: { @@ -148,6 +151,7 @@ export const config: Config = { }, }, order: { + key: 'buy', inputs: [], outputs: [], network: { From ff282e595c6ff6ac65aa495ce87c7ed50fcb7313 Mon Sep 17 00:00:00 2001 From: findolor Date: Thu, 19 Dec 2024 09:13:36 +0300 Subject: [PATCH 09/28] fix order typescript interface --- crates/settings/src/order.rs | 6 +++--- crates/settings/src/yaml/mod.rs | 4 ++++ packages/orderbook/test/js_api/gui.test.ts | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/settings/src/order.rs b/crates/settings/src/order.rs index 7a72a07c4..c72a32d9f 100644 --- a/crates/settings/src/order.rs +++ b/crates/settings/src/order.rs @@ -10,7 +10,8 @@ use strict_yaml_rust::StrictYaml; use thiserror::Error; use typeshare::typeshare; use yaml::{ - optional_string, require_hash, require_string, require_vec, YamlError, YamlParsableHash, + default_document, optional_string, require_hash, require_string, require_vec, YamlError, + YamlParsableHash, }; #[cfg(target_family = "wasm")] @@ -38,9 +39,8 @@ impl_all_wasm_traits!(OrderIO); #[derive(Debug, Serialize, Deserialize, Clone)] #[cfg_attr(target_family = "wasm", derive(Tsify))] #[serde(rename_all = "kebab-case")] -#[serde(default)] pub struct Order { - #[serde(skip)] + #[serde(skip, default = "default_document")] pub document: Arc>, pub key: String, #[typeshare(typescript(type = "OrderIO[]"))] diff --git a/crates/settings/src/yaml/mod.rs b/crates/settings/src/yaml/mod.rs index cd6cca81b..c7d788618 100644 --- a/crates/settings/src/yaml/mod.rs +++ b/crates/settings/src/yaml/mod.rs @@ -190,6 +190,10 @@ pub fn optional_vec<'a>(value: &'a StrictYaml, field: &str) -> Option<&'a Array> value[field].as_vec() } +pub fn default_document() -> Arc> { + Arc::new(RwLock::new(StrictYaml::String("".to_string()))) +} + #[cfg(test)] pub mod tests { use super::*; diff --git a/packages/orderbook/test/js_api/gui.test.ts b/packages/orderbook/test/js_api/gui.test.ts index 967bca540..b93f496f9 100644 --- a/packages/orderbook/test/js_api/gui.test.ts +++ b/packages/orderbook/test/js_api/gui.test.ts @@ -592,7 +592,7 @@ describe('Rain Orderbook JS API Package Bindgen Tests - Gui', async function () describe('state management tests', async () => { let serializedState = - 'H4sIAAAAAAAA_3WNTQoCMQxGZ1REb-FaUJpMk7Y7j-AV0jaVQRhBZ-HxXdi6EObbvPzxcum-iUxoKQSJUbyFlEjFSPFZQrQumewZUYvmJMihOKABnLNUUJnVyap69s03Tnmcbifo68D0u1pdn_rS-QDHtnkDDpbY-WAkpqxlqf-XY9eyrgRj2sNt5fy46wS_y00lmTN_AHYyHjD9AAAA'; + 'H4sIAAAAAAAA_3WPTQoCMQyFZ1REb-FaUJq26TQ7j-AV0k4qg1BBZ-HxFUxdCL7Nlz_eI6fuI7DekQOkDHnIgdlxZBY_SikpcLFiLQsigCOIPpkEBYjIx1FCxLxQn60yTXWc6uUAvQ5Mv9HqfJeHzDvYt80TrPMYhkiGU34n_ut_zW3XtGxvGNMC18r5dpUK38uVEs0xvAARbQwj_QAAAA=='; let gui: DotrainOrderGui; beforeAll(async () => { mockServer From a6c8a4774bbb5d4e3388433940c294729b024092 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Sat, 21 Dec 2024 17:07:10 +0400 Subject: [PATCH 10/28] wip on clear bug --- src/concrete/ob/OrderBook.sol | 8 +- test/concrete/ob/OrderBook.clear.mock.t.sol | 191 ++++++++++++++------ 2 files changed, 142 insertions(+), 57 deletions(-) diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index a8c7ef6d9..ff58b8c75 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -28,6 +28,7 @@ import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; import {LibMeta} from "rain.metadata/lib/LibMeta.sol"; import {IMetaV1_2} from "rain.metadata/interface/unstable/IMetaV1_2.sol"; import {LibOrderBook} from "../../lib/LibOrderBook.sol"; +import {console2} from "forge-std/Test.sol"; import { IOrderBookV4, @@ -681,6 +682,11 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order ClearStateChange memory clearStateChange = calculateClearStateChange(aliceOrderIOCalculation, bobOrderIOCalculation); + console2.log("clearStateChange.aliceOutput", clearStateChange.aliceOutput); + console2.log("clearStateChange.bobInput", clearStateChange.bobInput); + console2.log("clearStateChange.bobOutput", clearStateChange.bobOutput); + console2.log("clearStateChange.aliceInput", clearStateChange.aliceInput); + recordVaultIO(clearStateChange.aliceInput, clearStateChange.aliceOutput, aliceOrderIOCalculation); recordVaultIO(clearStateChange.bobInput, clearStateChange.bobOutput, bobOrderIOCalculation); @@ -963,7 +969,7 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order ) ); Output18Amount aliceOutputMax18 = aliceOrderIOCalculation.outputMax; - // Alice's doesn't need to provide more output than bob's max input. + // Alice doesn't need to provide more output than bob's max input. if (Output18Amount.unwrap(aliceOutputMax18) > Input18Amount.unwrap(bobInputMax18)) { aliceOutputMax18 = Output18Amount.wrap(Input18Amount.unwrap(bobInputMax18)); } diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 8b25617c2..0d416aefe 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -18,26 +18,26 @@ import { } from "rain.orderbook.interface/interface/IOrderBookV4.sol"; import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {NotOrderOwner} from "src/concrete/ob/OrderBook.sol"; +import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; +import {StateNamespace} from "rain.interpreter.interface/interface/IInterpreterV3.sol"; /// @title OrderBookClearTest /// Tests clearing an order. contract OrderBookClearTest is OrderBookExternalMockTest { - /// forge-config: default.fuzz.runs = 100 - function testClearSimple( - address alice, - OrderConfigV3 memory aliceConfig, - address bob, - OrderConfigV3 memory bobConfig, - bytes memory expression, - address bountyBot, - uint256 aliceBountyVaultId, - uint256 bobBountyVaultId - ) public { - // Different accounts - vm.assume(alice != bob); - vm.assume(alice != bountyBot); - vm.assume(bob != bountyBot); - vm.assume(aliceBountyVaultId != bobBountyVaultId); + /// Make a deposit to the OB mocking the internal transferFrom call. + function _depositInternal(address depositor, address token, uint256 vaultId, uint256 amount) internal { + vm.prank(depositor); + vm.mockCall( + token, + abi.encodeWithSelector(IERC20.transferFrom.selector, depositor, address(iOrderbook), amount), + abi.encode(true) + ); + iOrderbook.deposit2(address(token), vaultId, amount, new TaskV1[](0)); + + assertEq(iOrderbook.vaultBalance(depositor, token, vaultId), amount); + } + + function conformBasicConfig(OrderConfigV3 memory aliceConfig, OrderConfigV3 memory bobConfig) internal view { vm.assume(aliceConfig.validInputs.length > 0); vm.assume(aliceConfig.validOutputs.length > 0); vm.assume(bobConfig.validInputs.length > 0); @@ -62,7 +62,25 @@ contract OrderBookClearTest is OrderBookExternalMockTest { aliceConfig.meta = ""; bobConfig.meta = ""; + } + /// forge-config: default.fuzz.runs = 100 + function testClearSimple( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId + ) external { + // Different accounts + vm.assume(alice != bob); + vm.assume(alice != bountyBot); + vm.assume(bob != bountyBot); + vm.assume(aliceBountyVaultId != bobBountyVaultId); + conformBasicConfig(aliceConfig, bobConfig); uint256 amount = 2e18; _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, amount); @@ -139,7 +157,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), bobBountyVaultId), 0.00495e18); } - function testClear2ZeroRatioBug( + /// forge-config: default.fuzz.runs = 100 + function testClear2ZeroRatioAlice( address alice, OrderConfigV3 memory aliceConfig, address bob, @@ -148,41 +167,110 @@ contract OrderBookClearTest is OrderBookExternalMockTest { address bountyBot, uint256 aliceBountyVaultId, uint256 bobBountyVaultId - ) public { + ) external { // Different accounts vm.assume(alice != bob); vm.assume(alice != bountyBot); vm.assume(bob != bountyBot); vm.assume(aliceBountyVaultId != bobBountyVaultId); - vm.assume(aliceConfig.validInputs.length > 0); - vm.assume(aliceConfig.validOutputs.length > 0); - vm.assume(bobConfig.validInputs.length > 0); - vm.assume(bobConfig.validOutputs.length > 0); - aliceConfig.evaluable.interpreter = iInterpreter; - aliceConfig.evaluable.store = iStore; + conformBasicConfig(aliceConfig, bobConfig); + vm.assume(keccak256(aliceConfig.evaluable.bytecode) != keccak256(bobConfig.evaluable.bytecode)); - bobConfig.evaluable.interpreter = iInterpreter; - bobConfig.evaluable.store = iStore; + uint256 aliceAmount = 2e18; + uint256 bobAmount = 3e18; - aliceConfig.validInputs[0].token = address(iToken0); - aliceConfig.validOutputs[0].token = address(iToken1); + _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, aliceAmount); + _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, bobAmount); + { + { + bytes memory call = abi.encodeWithSelector( + IInterpreterV3.eval3.selector, + aliceConfig.evaluable.store, + LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(alice))), address(iOrderbook)) + ); - bobConfig.validInputs[0].token = address(iToken1); - bobConfig.validOutputs[0].token = address(iToken0); + // Mock the interpreter.eval for Alice with zero ratio + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 0; // Zero orderIORatio + orderStackAlice[1] = 5e17; // orderOutputMax + vm.mockCall(address(iInterpreter), call, abi.encode(orderStackAlice, new uint256[](0))); - aliceConfig.validInputs[0].decimals = 18; - aliceConfig.validOutputs[0].decimals = 18; - bobConfig.validInputs[0].decimals = 18; - bobConfig.validOutputs[0].decimals = 18; + uint256[] memory orderStackBob = new uint256[](2); + orderStackBob[0] = 1e18; // Nonzero orderIORatio + orderStackBob[1] = 5e17; // orderOutputMax - aliceConfig.meta = ""; - bobConfig.meta = ""; + call = abi.encodeWithSelector( + IInterpreterV3.eval3.selector, + bobConfig.evaluable.store, + LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(bob))), address(iOrderbook)) + ); - uint256 amount = 2e18; + vm.mockCall(address(iInterpreter), call, abi.encode(orderStackBob, new uint256[](0))); + } - _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, amount); - _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, amount); + OrderV3 memory aliceOrder; + OrderV3 memory bobOrder; + { + (aliceOrder,) = addOrderWithChecks(alice, aliceConfig, expression); + (bobOrder,) = addOrderWithChecks(bob, bobConfig, expression); + } + + ClearConfig memory configClear = ClearConfig({ + aliceInputIOIndex: 0, + aliceOutputIOIndex: 0, + bobInputIOIndex: 0, + bobOutputIOIndex: 0, + aliceBountyVaultId: aliceBountyVaultId, + bobBountyVaultId: bobBountyVaultId + }); + + vm.prank(bountyBot); + iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); + } + + // As both ratios are 0, there should be no token movements as no party + // is requesting anything from the other. + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), + aliceAmount - 0.5e18 + ); + assertEq( + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), + bobAmount - 0.5e18 + ); + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + ); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); + } + + /// forge-config: default.fuzz.runs = 100 + function testClear2ZeroRatioAliceAndBob( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId + ) external { + // Different accounts + vm.assume(alice != bob); + vm.assume(alice != bountyBot); + vm.assume(bob != bountyBot); + vm.assume(aliceBountyVaultId != bobBountyVaultId); + + conformBasicConfig(aliceConfig, bobConfig); + + uint256 aliceAmount = 2e18; + uint256 bobAmount = 3e18; + + _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, aliceAmount); + _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, bobAmount); { (OrderV3 memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, aliceConfig, expression); (OrderV3 memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, bobConfig, expression); @@ -221,25 +309,16 @@ contract OrderBookClearTest is OrderBookExternalMockTest { iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } - //Check that the entire output vault balances have been transferred to the bounty bot + // As both ratios are 0, there should be no token movements as no party + // is requesting anything from the other. assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), 0 + iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), + aliceAmount ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), amount); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), amount); - } - - /// Make a deposit to the OB mocking the internal transferFrom call. - function _depositInternal(address depositor, address token, uint256 vaultId, uint256 amount) internal { - vm.prank(depositor); - vm.mockCall( - token, - abi.encodeWithSelector(IERC20.transferFrom.selector, depositor, address(iOrderbook), amount), - abi.encode(true) + assertEq( + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), bobAmount ); - iOrderbook.deposit2(address(token), vaultId, amount, new TaskV1[](0)); - - assertEq(iOrderbook.vaultBalance(depositor, token, vaultId), amount); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); } } From 9b71e26ae4d54a551901c29d9d7f5d594d40097a Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Sun, 22 Dec 2024 21:35:31 +0400 Subject: [PATCH 11/28] show zero order ratio behaviour in clear --- test/concrete/ob/OrderBook.clear.mock.t.sol | 99 +++++++++++++++++++-- 1 file changed, 92 insertions(+), 7 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 0d416aefe..dbd3639a3 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -158,7 +158,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { } /// forge-config: default.fuzz.runs = 100 - function testClear2ZeroRatioAlice( + function testClear2ZeroRatioAliceOnly( address alice, OrderConfigV3 memory aliceConfig, address bob, @@ -193,12 +193,12 @@ contract OrderBookClearTest is OrderBookExternalMockTest { // Mock the interpreter.eval for Alice with zero ratio uint256[] memory orderStackAlice = new uint256[](2); orderStackAlice[0] = 0; // Zero orderIORatio - orderStackAlice[1] = 5e17; // orderOutputMax + orderStackAlice[1] = 0.5e18; // orderOutputMax vm.mockCall(address(iInterpreter), call, abi.encode(orderStackAlice, new uint256[](0))); uint256[] memory orderStackBob = new uint256[](2); orderStackBob[0] = 1e18; // Nonzero orderIORatio - orderStackBob[1] = 5e17; // orderOutputMax + orderStackBob[1] = 0.5e18; // orderOutputMax call = abi.encodeWithSelector( IInterpreterV3.eval3.selector, @@ -229,12 +229,97 @@ contract OrderBookClearTest is OrderBookExternalMockTest { iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } - // As both ratios are 0, there should be no token movements as no party - // is requesting anything from the other. assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), aliceAmount - 0.5e18 ); + assertEq( + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), bobAmount + ); + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + ); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); + } + + /// forge-config: default.fuzz.runs = 100 + function testClear2ZeroRatioBobOnly( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId + ) external { + // Different accounts + vm.assume(alice != bob); + vm.assume(alice != bountyBot); + vm.assume(bob != bountyBot); + vm.assume(aliceBountyVaultId != bobBountyVaultId); + + conformBasicConfig(aliceConfig, bobConfig); + vm.assume(keccak256(aliceConfig.evaluable.bytecode) != keccak256(bobConfig.evaluable.bytecode)); + + uint256 aliceAmount = 2e18; + uint256 bobAmount = 3e18; + + _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, aliceAmount); + _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, bobAmount); + { + { + bytes memory call = abi.encodeWithSelector( + IInterpreterV3.eval3.selector, + aliceConfig.evaluable.store, + LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(alice))), address(iOrderbook)) + ); + + // Mock the interpreter.eval for Alice with zero ratio + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 1e18; // Zero orderIORatio + orderStackAlice[1] = 0.5e18; // orderOutputMax + vm.mockCall(address(iInterpreter), call, abi.encode(orderStackAlice, new uint256[](0))); + + uint256[] memory orderStackBob = new uint256[](2); + orderStackBob[0] = 0; // Nonzero orderIORatio + orderStackBob[1] = 0.5e18; // orderOutputMax + + call = abi.encodeWithSelector( + IInterpreterV3.eval3.selector, + bobConfig.evaluable.store, + LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(bob))), address(iOrderbook)) + ); + + vm.mockCall(address(iInterpreter), call, abi.encode(orderStackBob, new uint256[](0))); + } + + OrderV3 memory aliceOrder; + OrderV3 memory bobOrder; + { + (aliceOrder,) = addOrderWithChecks(alice, aliceConfig, expression); + (bobOrder,) = addOrderWithChecks(bob, bobConfig, expression); + } + + ClearConfig memory configClear = ClearConfig({ + aliceInputIOIndex: 0, + aliceOutputIOIndex: 0, + bobInputIOIndex: 0, + bobOutputIOIndex: 0, + aliceBountyVaultId: aliceBountyVaultId, + bobBountyVaultId: bobBountyVaultId + }); + + vm.prank(bountyBot); + iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); + } + + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), + aliceAmount + ); assertEq( iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), bobAmount - 0.5e18 @@ -242,9 +327,9 @@ contract OrderBookClearTest is OrderBookExternalMockTest { assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0.5e18); } /// forge-config: default.fuzz.runs = 100 From 2ad7564938c0b8f54df1d556ea9bcb4a842c69f6 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Mon, 23 Dec 2024 19:43:32 +0400 Subject: [PATCH 12/28] update clear alice calcs --- src/concrete/ob/OrderBook.sol | 33 ++++++++------ test/concrete/ob/OrderBook.clear.mock.t.sol | 50 +++++++++++---------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index ff58b8c75..650e3c746 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -960,36 +960,41 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order OrderIOCalculationV2 memory aliceOrderIOCalculation, OrderIOCalculationV2 memory bobOrderIOCalculation ) internal pure returns (uint256 aliceInput, uint256 aliceOutput) { + // Alice's input is her output * her IO ratio. // Always round IO calculations up so that the counterparty pays more. - // This is the max input that bob can afford, given his own IO ratio - // and maximum spend/output. - Input18Amount bobInputMax18 = Input18Amount.wrap( - Output18Amount.unwrap(bobOrderIOCalculation.outputMax).fixedPointMul( - bobOrderIOCalculation.IORatio, Math.Rounding.Up + Input18Amount aliceInputMax18 = Input18Amount.wrap( + Output18Amount.unwrap(aliceOrderIOCalculation.outputMax).fixedPointMul( + aliceOrderIOCalculation.IORatio, Math.Rounding.Up ) ); Output18Amount aliceOutputMax18 = aliceOrderIOCalculation.outputMax; - // Alice doesn't need to provide more output than bob's max input. - if (Output18Amount.unwrap(aliceOutputMax18) > Input18Amount.unwrap(bobInputMax18)) { - aliceOutputMax18 = Output18Amount.wrap(Input18Amount.unwrap(bobInputMax18)); + + // If Alice's input is greater than Bob's max output, Alice's input is + // capped at Bob's max output. + if (Input18Amount.unwrap(aliceInputMax18) > Output18Amount.unwrap(bobOrderIOCalculation.outputMax)) { + aliceInputMax18 = Input18Amount.wrap(Output18Amount.unwrap(bobOrderIOCalculation.outputMax)); + + // Alice's output is capped at her input / her IO ratio. + // Round down to benefit Alice. + aliceOutputMax18 = Output18Amount.wrap( + Input18Amount.unwrap(aliceInputMax18).fixedPointDiv(aliceOrderIOCalculation.IORatio, Math.Rounding.Down) + ); } + // Alice's final output is the scaled version of the 18 decimal output, // rounded down to benefit Alice. aliceOutput = Output18Amount.unwrap(aliceOutputMax18).scaleN( aliceOrderIOCalculation.order.validOutputs[aliceOrderIOCalculation.outputIOIndex].decimals, 0 ); - // Alice's input is her bob-capped output * her IO ratio, rounded up. - Input18Amount aliceInput18 = Input18Amount.wrap( - Output18Amount.unwrap(aliceOutputMax18).fixedPointMul(aliceOrderIOCalculation.IORatio, Math.Rounding.Up) - ); - aliceInput = + // Alice's final input is the scaled version of the 18 decimal input, + // rounded up to benefit Alice. // Use bob's output decimals as alice's input decimals. // // This is only safe if we have previously checked that the decimals // match for alice and bob per token, otherwise bob could manipulate // alice's intent. - Input18Amount.unwrap(aliceInput18).scaleN( + aliceInput = Input18Amount.unwrap(aliceInputMax18).scaleN( bobOrderIOCalculation.order.validOutputs[bobOrderIOCalculation.outputIOIndex].decimals, FLAG_ROUND_UP ); } diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index dbd3639a3..02661648e 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -122,8 +122,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { // Mock the interpreter.eval that is used inside clear().calculateOrderIO() // Produce the stack output for OB uint256[] memory orderStackBob = new uint256[](2); - orderStackBob[0] = 99e16; // orderIORatio - orderStackBob[1] = 5e17; // orderOutputMax + orderStackBob[0] = 0.99e18; // orderIORatio + orderStackBob[1] = 0.5e18; // orderOutputMax vm.mockCall( address(iInterpreter), abi.encodeWithSelector(IInterpreterV3.eval3.selector), @@ -137,24 +137,24 @@ contract OrderBookClearTest is OrderBookExternalMockTest { assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), - 0.49005e18 + 0.495e18 ); assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - 1.505e18 + 1.5e18 ); assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.49005e18 + iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.495e18 ); assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), 1.505e18 + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), 1.5e18 ); assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken1), aliceBountyVaultId), 0.00495e18); + assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken1), aliceBountyVaultId), 0.005e18); assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken1), bobBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), bobBountyVaultId), 0.00495e18); + assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), bobBountyVaultId), 0.005e18); } /// forge-config: default.fuzz.runs = 100 @@ -234,14 +234,15 @@ contract OrderBookClearTest is OrderBookExternalMockTest { aliceAmount - 0.5e18 ); assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), bobAmount + iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 ); assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), + bobAmount - 0.5e18 ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0.5e18); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0.5e18); } /// forge-config: default.fuzz.runs = 100 @@ -318,18 +319,18 @@ contract OrderBookClearTest is OrderBookExternalMockTest { assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - aliceAmount + aliceAmount - 0.5e18 ); assertEq( iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), bobAmount - 0.5e18 ); assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0.5e18 ); assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); } /// forge-config: default.fuzz.runs = 100 @@ -394,16 +395,19 @@ contract OrderBookClearTest is OrderBookExternalMockTest { iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } - // As both ratios are 0, there should be no token movements as no party - // is requesting anything from the other. assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - aliceAmount + aliceAmount - 0.5e18 ); assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), bobAmount + iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), + bobAmount - 0.5e18 ); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); + assertEq( + iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + ); + assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); + assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0.5e18); + assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0.5e18); } } From a9f5786184be3221cb4ed45032e58adcdf4f38e9 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 15:16:52 +0400 Subject: [PATCH 13/28] wip on refactor clear check --- test/concrete/ob/OrderBook.clear.mock.t.sol | 400 ++++++++++---------- 1 file changed, 192 insertions(+), 208 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 02661648e..66b8a156b 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -64,76 +64,147 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bobConfig.meta = ""; } - /// forge-config: default.fuzz.runs = 100 - function testClearSimple( - address alice, - OrderConfigV3 memory aliceConfig, - address bob, - OrderConfigV3 memory bobConfig, - bytes memory expression, - address bountyBot, - uint256 aliceBountyVaultId, - uint256 bobBountyVaultId - ) external { - // Different accounts - vm.assume(alice != bob); - vm.assume(alice != bountyBot); - vm.assume(bob != bountyBot); - vm.assume(aliceBountyVaultId != bobBountyVaultId); - conformBasicConfig(aliceConfig, bobConfig); - uint256 amount = 2e18; + struct DoClear { + address alice; + OrderConfigV3 aliceConfig; + address bob; + OrderConfigV3 bobConfig; + address bountyBot; + uint256 aliceBountyVaultId; + uint256 bobBountyVaultId; + uint256 aliceAmount; + uint256 bobAmount; + bytes expression; + uint256[] orderStackAlice; + uint256[] orderStackBob; + } - _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, amount); - _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, amount); + function doClear(DoClear memory clear) internal { + vm.assume(clear.alice != clear.bob); + vm.assume(clear.alice != clear.bountyBot); + vm.assume(clear.bob != clear.bountyBot); + vm.assume(clear.aliceBountyVaultId != clear.bobBountyVaultId); + + conformBasicConfig(clear.aliceConfig, clear.bobConfig); + vm.assume(keccak256(clear.aliceConfig.evaluable.bytecode) != keccak256(clear.bobConfig.evaluable.bytecode)); + + _depositInternal( + clear.alice, + clear.aliceConfig.validOutputs[0].token, + clear.aliceConfig.validOutputs[0].vaultId, + clear.aliceAmount + ); + _depositInternal( + clear.bob, clear.bobConfig.validOutputs[0].token, clear.bobConfig.validOutputs[0].vaultId, clear.bobAmount + ); assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 + iOrderbook.vaultBalance( + clear.alice, clear.aliceConfig.validInputs[0].token, clear.aliceConfig.validInputs[0].vaultId + ), + 0 ); assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - amount + iOrderbook.vaultBalance( + clear.alice, clear.aliceConfig.validOutputs[0].token, clear.aliceConfig.validOutputs[0].vaultId + ), + clear.aliceAmount ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), amount + iOrderbook.vaultBalance( + clear.bob, clear.bobConfig.validInputs[0].token, clear.bobConfig.validInputs[0].vaultId + ), + 0 + ); + assertEq( + iOrderbook.vaultBalance( + clear.bob, clear.bobConfig.validOutputs[0].token, clear.bobConfig.validOutputs[0].vaultId + ), + clear.bobAmount ); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken1), bobBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(clear.bountyBot, address(iToken0), clear.aliceBountyVaultId), 0); + assertEq(iOrderbook.vaultBalance(clear.bountyBot, address(iToken1), clear.bobBountyVaultId), 0); { - (OrderV3 memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, aliceConfig, expression); - assertTrue(iOrderbook.orderExists(aliceOrderHash)); + { + bytes memory call = abi.encodeWithSelector( + IInterpreterV3.eval3.selector, + clear.aliceConfig.evaluable.store, + LibNamespace.qualifyNamespace( + StateNamespace.wrap(uint256(uint160(clear.alice))), address(iOrderbook) + ) + ); - (OrderV3 memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, bobConfig, expression); - assertTrue(iOrderbook.orderExists(bobOrderHash)); + vm.mockCall(address(iInterpreter), call, abi.encode(clear.orderStackAlice, new uint256[](0))); + + call = abi.encodeWithSelector( + IInterpreterV3.eval3.selector, + clear.bobConfig.evaluable.store, + LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(clear.bob))), address(iOrderbook)) + ); + + vm.mockCall(address(iInterpreter), call, abi.encode(clear.orderStackBob, new uint256[](0))); + } + + OrderV3 memory aliceOrder; + OrderV3 memory bobOrder; + { + (aliceOrder,) = addOrderWithChecks(clear.alice, clear.aliceConfig, clear.expression); + (bobOrder,) = addOrderWithChecks(clear.bob, clear.bobConfig, clear.expression); + } ClearConfig memory configClear = ClearConfig({ aliceInputIOIndex: 0, aliceOutputIOIndex: 0, bobInputIOIndex: 0, bobOutputIOIndex: 0, - aliceBountyVaultId: aliceBountyVaultId, - bobBountyVaultId: bobBountyVaultId + aliceBountyVaultId: clear.aliceBountyVaultId, + bobBountyVaultId: clear.bobBountyVaultId }); - { - // Mock the interpreter.eval that is used inside clear().calculateOrderIO() - // Produce the stack output for OB - uint256[] memory orderStackBob = new uint256[](2); - orderStackBob[0] = 0.99e18; // orderIORatio - orderStackBob[1] = 0.5e18; // orderOutputMax - vm.mockCall( - address(iInterpreter), - abi.encodeWithSelector(IInterpreterV3.eval3.selector), - abi.encode(orderStackBob, new uint256[](0)) - ); - } - - vm.prank(bountyBot); + vm.prank(clear.bountyBot); iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } + } + + /// forge-config: default.fuzz.runs = 100 + function testClearSimple( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId + ) external { + uint256 aliceAmount = 2e18; + uint256 bobAmount = 2e18; + + // Mock the interpreter.eval that is used inside clear().calculateOrderIO() + // Produce the stack output for OB + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 0.99e18; // orderIORatio + orderStackAlice[1] = 0.5e18; // orderOutputMax + + doClear( + DoClear( + alice, + aliceConfig, + bob, + bobConfig, + bountyBot, + aliceBountyVaultId, + bobBountyVaultId, + aliceAmount, + bobAmount, + expression, + orderStackAlice, + orderStackAlice + ) + ); assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), @@ -168,66 +239,33 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 aliceBountyVaultId, uint256 bobBountyVaultId ) external { - // Different accounts - vm.assume(alice != bob); - vm.assume(alice != bountyBot); - vm.assume(bob != bountyBot); - vm.assume(aliceBountyVaultId != bobBountyVaultId); - - conformBasicConfig(aliceConfig, bobConfig); - vm.assume(keccak256(aliceConfig.evaluable.bytecode) != keccak256(bobConfig.evaluable.bytecode)); - uint256 aliceAmount = 2e18; uint256 bobAmount = 3e18; - _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, aliceAmount); - _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, bobAmount); - { - { - bytes memory call = abi.encodeWithSelector( - IInterpreterV3.eval3.selector, - aliceConfig.evaluable.store, - LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(alice))), address(iOrderbook)) - ); - - // Mock the interpreter.eval for Alice with zero ratio - uint256[] memory orderStackAlice = new uint256[](2); - orderStackAlice[0] = 0; // Zero orderIORatio - orderStackAlice[1] = 0.5e18; // orderOutputMax - vm.mockCall(address(iInterpreter), call, abi.encode(orderStackAlice, new uint256[](0))); - - uint256[] memory orderStackBob = new uint256[](2); - orderStackBob[0] = 1e18; // Nonzero orderIORatio - orderStackBob[1] = 0.5e18; // orderOutputMax - - call = abi.encodeWithSelector( - IInterpreterV3.eval3.selector, - bobConfig.evaluable.store, - LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(bob))), address(iOrderbook)) - ); - - vm.mockCall(address(iInterpreter), call, abi.encode(orderStackBob, new uint256[](0))); - } - - OrderV3 memory aliceOrder; - OrderV3 memory bobOrder; - { - (aliceOrder,) = addOrderWithChecks(alice, aliceConfig, expression); - (bobOrder,) = addOrderWithChecks(bob, bobConfig, expression); - } - - ClearConfig memory configClear = ClearConfig({ - aliceInputIOIndex: 0, - aliceOutputIOIndex: 0, - bobInputIOIndex: 0, - bobOutputIOIndex: 0, - aliceBountyVaultId: aliceBountyVaultId, - bobBountyVaultId: bobBountyVaultId - }); - - vm.prank(bountyBot); - iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); - } + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 0; // Zero orderIORatio + orderStackAlice[1] = 0.5e18; // orderOutputMax + + uint256[] memory orderStackBob = new uint256[](2); + orderStackBob[0] = 1e18; // Nonzero orderIORatio + orderStackBob[1] = 0.5e18; // orderOutputMax + + doClear( + DoClear( + alice, + aliceConfig, + bob, + bobConfig, + bountyBot, + aliceBountyVaultId, + bobBountyVaultId, + aliceAmount, + bobAmount, + expression, + orderStackAlice, + orderStackBob + ) + ); assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), @@ -256,66 +294,33 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 aliceBountyVaultId, uint256 bobBountyVaultId ) external { - // Different accounts - vm.assume(alice != bob); - vm.assume(alice != bountyBot); - vm.assume(bob != bountyBot); - vm.assume(aliceBountyVaultId != bobBountyVaultId); - - conformBasicConfig(aliceConfig, bobConfig); - vm.assume(keccak256(aliceConfig.evaluable.bytecode) != keccak256(bobConfig.evaluable.bytecode)); - uint256 aliceAmount = 2e18; uint256 bobAmount = 3e18; - _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, aliceAmount); - _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, bobAmount); - { - { - bytes memory call = abi.encodeWithSelector( - IInterpreterV3.eval3.selector, - aliceConfig.evaluable.store, - LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(alice))), address(iOrderbook)) - ); - - // Mock the interpreter.eval for Alice with zero ratio - uint256[] memory orderStackAlice = new uint256[](2); - orderStackAlice[0] = 1e18; // Zero orderIORatio - orderStackAlice[1] = 0.5e18; // orderOutputMax - vm.mockCall(address(iInterpreter), call, abi.encode(orderStackAlice, new uint256[](0))); - - uint256[] memory orderStackBob = new uint256[](2); - orderStackBob[0] = 0; // Nonzero orderIORatio - orderStackBob[1] = 0.5e18; // orderOutputMax - - call = abi.encodeWithSelector( - IInterpreterV3.eval3.selector, - bobConfig.evaluable.store, - LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(bob))), address(iOrderbook)) - ); - - vm.mockCall(address(iInterpreter), call, abi.encode(orderStackBob, new uint256[](0))); - } - - OrderV3 memory aliceOrder; - OrderV3 memory bobOrder; - { - (aliceOrder,) = addOrderWithChecks(alice, aliceConfig, expression); - (bobOrder,) = addOrderWithChecks(bob, bobConfig, expression); - } - - ClearConfig memory configClear = ClearConfig({ - aliceInputIOIndex: 0, - aliceOutputIOIndex: 0, - bobInputIOIndex: 0, - bobOutputIOIndex: 0, - aliceBountyVaultId: aliceBountyVaultId, - bobBountyVaultId: bobBountyVaultId - }); - - vm.prank(bountyBot); - iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); - } + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 1e18; // Zero orderIORatio + orderStackAlice[1] = 0.5e18; // orderOutputMax + + uint256[] memory orderStackBob = new uint256[](2); + orderStackBob[0] = 0; // Nonzero orderIORatio + orderStackBob[1] = 0.5e18; // orderOutputMax + + doClear( + DoClear( + alice, + aliceConfig, + bob, + bobConfig, + bountyBot, + aliceBountyVaultId, + bobBountyVaultId, + aliceAmount, + bobAmount, + expression, + orderStackAlice, + orderStackBob + ) + ); assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), @@ -344,56 +349,35 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 aliceBountyVaultId, uint256 bobBountyVaultId ) external { - // Different accounts - vm.assume(alice != bob); - vm.assume(alice != bountyBot); - vm.assume(bob != bountyBot); - vm.assume(aliceBountyVaultId != bobBountyVaultId); - - conformBasicConfig(aliceConfig, bobConfig); - uint256 aliceAmount = 2e18; uint256 bobAmount = 3e18; - _depositInternal(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId, aliceAmount); - _depositInternal(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId, bobAmount); - { - (OrderV3 memory aliceOrder, bytes32 aliceOrderHash) = addOrderWithChecks(alice, aliceConfig, expression); - (OrderV3 memory bobOrder, bytes32 bobOrderHash) = addOrderWithChecks(bob, bobConfig, expression); - - ClearConfig memory configClear = ClearConfig({ - aliceInputIOIndex: 0, - aliceOutputIOIndex: 0, - bobInputIOIndex: 0, - bobOutputIOIndex: 0, - aliceBountyVaultId: aliceBountyVaultId, - bobBountyVaultId: bobBountyVaultId - }); - - { - // Mock the interpreter.eval for Alice and Bob orders with zero ratio - uint256[] memory orderStackAlice = new uint256[](2); - orderStackAlice[0] = 0; // Zero orderIORatio - orderStackAlice[1] = 5e17; // orderOutputMax - vm.mockCall( - address(iInterpreter), - abi.encodeWithSelector(IInterpreterV3.eval3.selector), - abi.encode(orderStackAlice, new uint256[](0)) - ); - uint256[] memory orderStackBob = new uint256[](2); - - orderStackBob[0] = 0; // Zero orderIORatio - orderStackBob[1] = 5e17; // orderOutputMax - vm.mockCall( - address(iInterpreter), - abi.encodeWithSelector(IInterpreterV3.eval3.selector), - abi.encode(orderStackBob, new uint256[](0)) - ); - } - - vm.prank(bountyBot); - iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); - } + // Mock the interpreter.eval for Alice and Bob orders with zero ratio + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = 0; // Zero orderIORatio + orderStackAlice[1] = 5e17; // orderOutputMax + + uint256[] memory orderStackBob = new uint256[](2); + + orderStackBob[0] = 0; // Zero orderIORatio + orderStackBob[1] = 5e17; // orderOutputMax + + doClear( + DoClear( + alice, + aliceConfig, + bob, + bobConfig, + bountyBot, + aliceBountyVaultId, + bobBountyVaultId, + aliceAmount, + bobAmount, + expression, + orderStackAlice, + orderStackBob + ) + ); assertEq( iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), From eea95664d824654a1c60b6dbd3de28a4f19106b8 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 15:24:45 +0400 Subject: [PATCH 14/28] refactor tests --- test/concrete/ob/OrderBook.clear.mock.t.sol | 139 ++++++++++---------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 66b8a156b..e171e232b 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -77,6 +77,12 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bytes expression; uint256[] orderStackAlice; uint256[] orderStackBob; + uint256 expectedAliceOutput; + uint256 expectedBobOutput; + uint256 expectedAliceInput; + uint256 expectedBobInput; + uint256 expectedAliceBounty; + uint256 expectedBobBounty; } function doClear(DoClear memory clear) internal { @@ -167,6 +173,41 @@ contract OrderBookClearTest is OrderBookExternalMockTest { vm.prank(clear.bountyBot); iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } + + assertEq( + iOrderbook.vaultBalance( + clear.alice, clear.aliceConfig.validOutputs[0].token, clear.aliceConfig.validOutputs[0].vaultId + ), + clear.aliceAmount - clear.expectedAliceOutput + ); + assertEq( + iOrderbook.vaultBalance( + clear.alice, clear.aliceConfig.validInputs[0].token, clear.aliceConfig.validInputs[0].vaultId + ), + clear.expectedAliceInput + ); + + assertEq( + iOrderbook.vaultBalance( + clear.bob, clear.bobConfig.validOutputs[0].token, clear.bobConfig.validOutputs[0].vaultId + ), + clear.bobAmount - clear.expectedBobOutput + ); + assertEq( + iOrderbook.vaultBalance( + clear.bob, clear.bobConfig.validInputs[0].token, clear.bobConfig.validInputs[0].vaultId + ), + clear.expectedBobInput + ); + + assertEq( + iOrderbook.vaultBalance(clear.bountyBot, clear.aliceConfig.validOutputs[0].token, clear.aliceBountyVaultId), + clear.expectedAliceBounty + ); + assertEq( + iOrderbook.vaultBalance(clear.bountyBot, clear.bobConfig.validOutputs[0].token, clear.bobBountyVaultId), + clear.expectedBobBounty + ); } /// forge-config: default.fuzz.runs = 100 @@ -202,30 +243,15 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bobAmount, expression, orderStackAlice, - orderStackAlice + orderStackAlice, + 0.5e18, + 0.5e18, + 0.495e18, + 0.495e18, + 0.005e18, + 0.005e18 ) ); - - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), - 0.495e18 - ); - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - 1.5e18 - ); - - assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.495e18 - ); - assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), 1.5e18 - ); - - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken1), aliceBountyVaultId), 0.005e18); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken1), bobBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, address(iToken0), bobBountyVaultId), 0.005e18); } /// forge-config: default.fuzz.runs = 100 @@ -263,24 +289,15 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bobAmount, expression, orderStackAlice, - orderStackBob + orderStackBob, + 0.5e18, + 0.5e18, + 0, + 0.5e18, + 0, + 0.5e18 ) ); - - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - aliceAmount - 0.5e18 - ); - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 - ); - assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), - bobAmount - 0.5e18 - ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0.5e18); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0.5e18); } /// forge-config: default.fuzz.runs = 100 @@ -318,24 +335,15 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bobAmount, expression, orderStackAlice, - orderStackBob + orderStackBob, + 0.5e18, + 0.5e18, + 0.5e18, + 0, + 0.5e18, + 0 ) ); - - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - aliceAmount - 0.5e18 - ); - assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), - bobAmount - 0.5e18 - ); - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0.5e18 - ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0.5e18); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0); } /// forge-config: default.fuzz.runs = 100 @@ -375,23 +383,14 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bobAmount, expression, orderStackAlice, - orderStackBob + orderStackBob, + 0.5e18, + 0.5e18, + 0, + 0, + 0.5e18, + 0.5e18 ) ); - - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validOutputs[0].token, aliceConfig.validOutputs[0].vaultId), - aliceAmount - 0.5e18 - ); - assertEq( - iOrderbook.vaultBalance(bob, bobConfig.validOutputs[0].token, bobConfig.validOutputs[0].vaultId), - bobAmount - 0.5e18 - ); - assertEq( - iOrderbook.vaultBalance(alice, aliceConfig.validInputs[0].token, aliceConfig.validInputs[0].vaultId), 0 - ); - assertEq(iOrderbook.vaultBalance(bob, bobConfig.validInputs[0].token, bobConfig.validInputs[0].vaultId), 0); - assertEq(iOrderbook.vaultBalance(bountyBot, aliceConfig.validOutputs[0].token, aliceBountyVaultId), 0.5e18); - assertEq(iOrderbook.vaultBalance(bountyBot, bobConfig.validOutputs[0].token, bobBountyVaultId), 0.5e18); } } From 56495e45abdd24757034cb47af1db56728d75b6b Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 15:25:55 +0400 Subject: [PATCH 15/28] lint --- src/concrete/ob/OrderBook.sol | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index 650e3c746..af713aba8 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -28,7 +28,6 @@ import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; import {LibMeta} from "rain.metadata/lib/LibMeta.sol"; import {IMetaV1_2} from "rain.metadata/interface/unstable/IMetaV1_2.sol"; import {LibOrderBook} from "../../lib/LibOrderBook.sol"; -import {console2} from "forge-std/Test.sol"; import { IOrderBookV4, @@ -682,11 +681,6 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order ClearStateChange memory clearStateChange = calculateClearStateChange(aliceOrderIOCalculation, bobOrderIOCalculation); - console2.log("clearStateChange.aliceOutput", clearStateChange.aliceOutput); - console2.log("clearStateChange.bobInput", clearStateChange.bobInput); - console2.log("clearStateChange.bobOutput", clearStateChange.bobOutput); - console2.log("clearStateChange.aliceInput", clearStateChange.aliceInput); - recordVaultIO(clearStateChange.aliceInput, clearStateChange.aliceOutput, aliceOrderIOCalculation); recordVaultIO(clearStateChange.bobInput, clearStateChange.bobOutput, bobOrderIOCalculation); From df8df90c8837083c7cf0c9af48db34a7c4ebab5f Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 16:20:00 +0400 Subject: [PATCH 16/28] wip on fuzz --- test/concrete/ob/OrderBook.clear.mock.t.sol | 92 +++++++++++++++++++-- 1 file changed, 86 insertions(+), 6 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index e171e232b..aa10a3bf8 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -20,10 +20,16 @@ import {LibTestAddOrder} from "test/util/lib/LibTestAddOrder.sol"; import {NotOrderOwner} from "src/concrete/ob/OrderBook.sol"; import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; import {StateNamespace} from "rain.interpreter.interface/interface/IInterpreterV3.sol"; +import {LibFixedPointDecimalArithmeticOpenZeppelin} from + "rain.math.fixedpoint/lib/LibFixedPointDecimalArithmeticOpenZeppelin.sol"; + import {Math} from "openzeppelin-contracts/contracts/utils/math/Math.sol"; /// @title OrderBookClearTest /// Tests clearing an order. contract OrderBookClearTest is OrderBookExternalMockTest { + using LibFixedPointDecimalArithmeticOpenZeppelin for uint256; + using Math for uint256; + /// Make a deposit to the OB mocking the internal transferFrom call. function _depositInternal(address depositor, address token, uint256 vaultId, uint256 amount) internal { vm.prank(depositor); @@ -178,35 +184,52 @@ contract OrderBookClearTest is OrderBookExternalMockTest { iOrderbook.vaultBalance( clear.alice, clear.aliceConfig.validOutputs[0].token, clear.aliceConfig.validOutputs[0].vaultId ), - clear.aliceAmount - clear.expectedAliceOutput + clear.aliceAmount - clear.expectedAliceOutput, + "Alice output vault" ); assertEq( iOrderbook.vaultBalance( clear.alice, clear.aliceConfig.validInputs[0].token, clear.aliceConfig.validInputs[0].vaultId ), - clear.expectedAliceInput + clear.expectedAliceOutput.fixedPointMul(clear.orderStackAlice[0], Math.Rounding.Up), + "Alice input vault" ); assertEq( iOrderbook.vaultBalance( clear.bob, clear.bobConfig.validOutputs[0].token, clear.bobConfig.validOutputs[0].vaultId ), - clear.bobAmount - clear.expectedBobOutput + clear.bobAmount - clear.expectedBobOutput, + "Bob output vault" ); assertEq( iOrderbook.vaultBalance( clear.bob, clear.bobConfig.validInputs[0].token, clear.bobConfig.validInputs[0].vaultId ), - clear.expectedBobInput + clear.expectedAliceOutput, + // clear.expectedBobOutput.fixedPointMul(clear.orderStackBob[0], Math.Rounding.Up), + "Bob input vault" ); assertEq( iOrderbook.vaultBalance(clear.bountyBot, clear.aliceConfig.validOutputs[0].token, clear.aliceBountyVaultId), - clear.expectedAliceBounty + 0, + "Alice bounty" + ); + assertEq( + iOrderbook.vaultBalance(clear.bountyBot, clear.aliceConfig.validInputs[0].token, clear.aliceBountyVaultId), + 0, + "Alice bounty input" ); assertEq( iOrderbook.vaultBalance(clear.bountyBot, clear.bobConfig.validOutputs[0].token, clear.bobBountyVaultId), - clear.expectedBobBounty + clear.expectedBobOutput - clear.expectedAliceOutput.fixedPointMul(clear.orderStackAlice[0], Math.Rounding.Up), + "Bob bounty" + ); + assertEq( + iOrderbook.vaultBalance(clear.bountyBot, clear.bobConfig.validInputs[0].token, clear.bobBountyVaultId), + 0, + "Bob bounty input" ); } @@ -254,6 +277,63 @@ contract OrderBookClearTest is OrderBookExternalMockTest { ); } + /// forge-config: default.fuzz.runs = 100 + function testClearFuzzIoRatio( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId, + uint256 aliceIORatio, + uint256 bobIORatio + ) external { + // uint256 aliceAmount = 1e18; + // uint256 bobAmount = 1e18; + + aliceIORatio = bound(aliceIORatio, 0.1e18, 1e18); + bobIORatio = bound(bobIORatio, 1e18, uint256(1e18).fixedPointDiv(aliceIORatio, Math.Rounding.Up)); + // vm.assume(aliceIORatio.fixedPointMul(bobIORatio, Math.Rounding.Up) <= 1e18); + + // Mock the interpreter.eval that is used inside clear().calculateOrderIO() + // Produce the stack output for OB + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = aliceIORatio; // orderIORatio + orderStackAlice[1] = 1e18; // orderOutputMax + + uint256[] memory orderStackBob = new uint256[](2); + orderStackBob[0] = bobIORatio; // orderIORatio + orderStackBob[1] = 1e18; // orderOutputMax + + doClear( + DoClear( + alice, + aliceConfig, + bob, + bobConfig, + bountyBot, + aliceBountyVaultId, + bobBountyVaultId, + 1e18, + 1e18, + expression, + orderStackAlice, + orderStackBob, + 1e18, + // Alice is outputting 1 so bob will output enough to match this + // according to his own IO ratio. + uint256(1e18).fixedPointDiv(bobIORatio, Math.Rounding.Down).min(1e18), + uint256(1e18).fixedPointMul(aliceIORatio, Math.Rounding.Up), + uint256(1e18).fixedPointMul(bobIORatio, Math.Rounding.Up), + 5e17, + 4e17 + ) + ); + } + + /// forge-config: default.fuzz.runs = 100 function testClear2ZeroRatioAliceOnly( address alice, From 3833fb95b6ec871dce569fc5ed56169e9702ba31 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 17:01:53 +0400 Subject: [PATCH 17/28] wip on fuzz --- src/concrete/ob/OrderBook.sol | 6 ++++++ test/concrete/ob/OrderBook.clear.mock.t.sol | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index af713aba8..650e3c746 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -28,6 +28,7 @@ import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; import {LibMeta} from "rain.metadata/lib/LibMeta.sol"; import {IMetaV1_2} from "rain.metadata/interface/unstable/IMetaV1_2.sol"; import {LibOrderBook} from "../../lib/LibOrderBook.sol"; +import {console2} from "forge-std/Test.sol"; import { IOrderBookV4, @@ -681,6 +682,11 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order ClearStateChange memory clearStateChange = calculateClearStateChange(aliceOrderIOCalculation, bobOrderIOCalculation); + console2.log("clearStateChange.aliceOutput", clearStateChange.aliceOutput); + console2.log("clearStateChange.bobInput", clearStateChange.bobInput); + console2.log("clearStateChange.bobOutput", clearStateChange.bobOutput); + console2.log("clearStateChange.aliceInput", clearStateChange.aliceInput); + recordVaultIO(clearStateChange.aliceInput, clearStateChange.aliceOutput, aliceOrderIOCalculation); recordVaultIO(clearStateChange.bobInput, clearStateChange.bobOutput, bobOrderIOCalculation); diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index aa10a3bf8..6f7bac78f 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -191,7 +191,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { iOrderbook.vaultBalance( clear.alice, clear.aliceConfig.validInputs[0].token, clear.aliceConfig.validInputs[0].vaultId ), - clear.expectedAliceOutput.fixedPointMul(clear.orderStackAlice[0], Math.Rounding.Up), + clear.expectedAliceInput, "Alice input vault" ); @@ -293,8 +293,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { // uint256 aliceAmount = 1e18; // uint256 bobAmount = 1e18; - aliceIORatio = bound(aliceIORatio, 0.1e18, 1e18); - bobIORatio = bound(bobIORatio, 1e18, uint256(1e18).fixedPointDiv(aliceIORatio, Math.Rounding.Up)); + aliceIORatio = bound(aliceIORatio, 0.99e18, 1e18); + bobIORatio = bound(bobIORatio, 1e18, uint256(1e18).fixedPointDiv(aliceIORatio, Math.Rounding.Down)); // vm.assume(aliceIORatio.fixedPointMul(bobIORatio, Math.Rounding.Up) <= 1e18); // Mock the interpreter.eval that is used inside clear().calculateOrderIO() From df68c21010562d4bf4456f5f7cf95bdc318d25c6 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 17:19:43 +0400 Subject: [PATCH 18/28] refactor tests --- test/concrete/ob/OrderBook.clear.mock.t.sol | 31 ++++++++------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 6f7bac78f..8ea6074cd 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -22,7 +22,7 @@ import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; import {StateNamespace} from "rain.interpreter.interface/interface/IInterpreterV3.sol"; import {LibFixedPointDecimalArithmeticOpenZeppelin} from "rain.math.fixedpoint/lib/LibFixedPointDecimalArithmeticOpenZeppelin.sol"; - import {Math} from "openzeppelin-contracts/contracts/utils/math/Math.sol"; +import {Math} from "openzeppelin-contracts/contracts/utils/math/Math.sol"; /// @title OrderBookClearTest /// Tests clearing an order. @@ -87,8 +87,6 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 expectedBobOutput; uint256 expectedAliceInput; uint256 expectedBobInput; - uint256 expectedAliceBounty; - uint256 expectedBobBounty; } function doClear(DoClear memory clear) internal { @@ -206,14 +204,14 @@ contract OrderBookClearTest is OrderBookExternalMockTest { iOrderbook.vaultBalance( clear.bob, clear.bobConfig.validInputs[0].token, clear.bobConfig.validInputs[0].vaultId ), - clear.expectedAliceOutput, + clear.expectedBobInput, // clear.expectedBobOutput.fixedPointMul(clear.orderStackBob[0], Math.Rounding.Up), "Bob input vault" ); assertEq( iOrderbook.vaultBalance(clear.bountyBot, clear.aliceConfig.validOutputs[0].token, clear.aliceBountyVaultId), - 0, + clear.expectedAliceOutput - clear.expectedBobInput, "Alice bounty" ); assertEq( @@ -223,7 +221,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { ); assertEq( iOrderbook.vaultBalance(clear.bountyBot, clear.bobConfig.validOutputs[0].token, clear.bobBountyVaultId), - clear.expectedBobOutput - clear.expectedAliceOutput.fixedPointMul(clear.orderStackAlice[0], Math.Rounding.Up), + clear.expectedBobOutput - clear.expectedAliceInput, "Bob bounty" ); assertEq( @@ -270,9 +268,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0.495e18, - 0.495e18, - 0.005e18, - 0.005e18 + 0.495e18 ) ); } @@ -325,15 +321,16 @@ contract OrderBookClearTest is OrderBookExternalMockTest { // Alice is outputting 1 so bob will output enough to match this // according to his own IO ratio. uint256(1e18).fixedPointDiv(bobIORatio, Math.Rounding.Down).min(1e18), + // Expected input for Alice is aliceOutput * aliceIORatio uint256(1e18).fixedPointMul(aliceIORatio, Math.Rounding.Up), - uint256(1e18).fixedPointMul(bobIORatio, Math.Rounding.Up), - 5e17, - 4e17 + // Expected output for Bob is bob's output * bobIORatio + uint256(1e18).fixedPointDiv(bobIORatio, Math.Rounding.Down).min(1e18).fixedPointMul( + bobIORatio, Math.Rounding.Up + ) ) ); } - /// forge-config: default.fuzz.runs = 100 function testClear2ZeroRatioAliceOnly( address alice, @@ -373,8 +370,6 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0, - 0.5e18, - 0, 0.5e18 ) ); @@ -419,8 +414,6 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0.5e18, - 0, - 0.5e18, 0 ) ); @@ -467,9 +460,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0, - 0, - 0.5e18, - 0.5e18 + 0 ) ); } From 54d69212b412a4aaa43c0324dea96fe88fe4682c Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 17:20:49 +0400 Subject: [PATCH 19/28] refactor test --- test/concrete/ob/OrderBook.clear.mock.t.sol | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 8ea6074cd..1a78ee010 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -286,12 +286,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 aliceIORatio, uint256 bobIORatio ) external { - // uint256 aliceAmount = 1e18; - // uint256 bobAmount = 1e18; - aliceIORatio = bound(aliceIORatio, 0.99e18, 1e18); bobIORatio = bound(bobIORatio, 1e18, uint256(1e18).fixedPointDiv(aliceIORatio, Math.Rounding.Down)); - // vm.assume(aliceIORatio.fixedPointMul(bobIORatio, Math.Rounding.Up) <= 1e18); // Mock the interpreter.eval that is used inside clear().calculateOrderIO() // Produce the stack output for OB From f747e3d15ad75b2a77a7d38ebb632ea27e2cd457 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 17:55:12 +0400 Subject: [PATCH 20/28] fix fuzz --- .gas-snapshot | 316 ++++++++++---------- src/concrete/ob/OrderBook.sol | 6 - test/concrete/ob/OrderBook.clear.mock.t.sol | 12 +- 3 files changed, 167 insertions(+), 167 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index f906d5dc2..891a425a0 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,107 +1,111 @@ -GenericPoolOrderBookV4ArbOrderTakerExpressionTest:testGenericPoolTakeOrdersExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256[],uint256[]) (runs: 30, μ: 431441, ~: 426614) -GenericPoolOrderBookV4ArbOrderTakerExpressionTest:testGenericPoolTakeOrdersWrongExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,address,bytes)) (runs: 30, μ: 170093, ~: 168794) -GenericPoolOrderBookV4ArbOrderTakerSenderTest:testGenericPoolTakeOrdersSender((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 30, μ: 273592, ~: 271336) -GenericPoolOrderBookV4FlashBorrowerTest:testGenericPoolOrderBookV4FlashBorrowerTakeOrdersSender((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 30, μ: 522441, ~: 517262) -LibOrderTest:testHashEqual((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 120, μ: 196758, ~: 185247) -LibOrderTest:testHashNotEqual((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 120, μ: 303709, ~: 288071) -OrderBookAddOrderEnactTest:testAddLiveOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 943074, ~: 889022) -OrderBookAddOrderEnactTest:testAddLiveOrderRevertNoAdd(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 737740, ~: 696173) -OrderBookAddOrderEnactTest:testAddOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 1045640, ~: 1001791) -OrderBookAddOrderEnactTest:testAddOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 659270, ~: 620393) -OrderBookAddOrderEnactTest:testAddOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 720030, ~: 681137) -OrderBookAddOrderEnactTest:testAddOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 705378, ~: 666485) -OrderBookAddOrderEnactTest:testAddOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 3273330, ~: 3280060) -OrderBookAddOrderEnactTest:testAddOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 953859, ~: 914910) -OrderBookAddOrderEnactTest:testAddOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 1362298, ~: 1291950) -OrderBookAddOrderMockTest:testAddOrderSameAccountWithDifferentConfig(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 120, μ: 2768347, ~: 2720274) -OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithDifferentConfig(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 120, μ: 2616512, ~: 2642029) -OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithSameConfig(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 2435598, ~: 2461148) -OrderBookAddOrderMockTest:testAddOrderWithCalculationsInputsAndOutputsSucceeds(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 1285282, ~: 1179797) -OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaEmitsMetaV1(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 1294905, ~: 1189304) -OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 690182, ~: 636539) -OrderBookAddOrderMockTest:testAddOrderWithoutCalculationsDeploys(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 706725, ~: 665020) -OrderBookAddOrderMockTest:testAddOrderWithoutInputsReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 169387, ~: 165247) -OrderBookAddOrderMockTest:testAddOrderWithoutOutputsReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 166523, ~: 162469) -OrderBookAddOrderNonceTest:testAddOrderNonceDifferentNonceStateChange(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes32) (runs: 120, μ: 1271608, ~: 1282006) -OrderBookAddOrderNonceTest:testAddOrderNonceSameNonceDifferentOrderStateChange(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1435409, ~: 1406287) -OrderBookAddOrderNonceTest:testAddOrderNonceSameOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1015185, ~: 953426) -OrderBookAddOrderOwnerTest:testAddOrderOwnerDifferentOwnerStateChange(((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,address) (runs: 120, μ: 1149077, ~: 1201727) -OrderBookAddOrderOwnerTest:testAddOrderOwnerSameOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1015281, ~: 953522) -OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts1(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 687910, ~: 648848) -OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts2(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 689693, ~: 650631) -OrderBookAddOrderTest:testAddOrderRealCalculateInputsRevertsPreference(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 689256, ~: 650194) -OrderBookAddOrderTest:testAddOrderRealNoHandleIODeploys(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 679992, ~: 640930) -OrderBookAddOrderTest:testAddOrderRealNoSourcesDeploys(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 657650, ~: 618598) -OrderBookAddOrderTest:testAddOrderRealOneStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 692220, ~: 653158) -OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 704822, ~: 665760) -OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 698464, ~: 659402) -OrderBookAddOrderTest:testAddOrderRealZeroStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 686630, ~: 647568) -OrderBookClearHandleIORevertTest:testClearOrderAliceNoHandleIORevert() (gas: 521011) -OrderBookClearHandleIORevertTest:testClearOrderBobNoHandleIORevert() (gas: 521012) -OrderBookClearHandleIORevertTest:testClearOrderBothNoHandleIORevert() (gas: 500338) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 561233) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 553176) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 553384) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO3() (gas: 561277) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO4() (gas: 569142) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO5() (gas: 526740) -OrderBookClearOrderBadStackTest:testClearOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2374769, ~: 2424878) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2461435, ~: 2503676) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2469182, ~: 2511420) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOtherOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2395937, ~: 2446051) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2389510, ~: 2439624) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOtherEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2388262, ~: 2438367) -OrderBookClearOrderContextTest:testContextEmptyStack(address,address,uint256,uint256,uint256,uint256) (runs: 30, μ: 2163795, ~: 2166500) -OrderBookClearSameTokenTest:testClearSameToken(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 1586753, ~: 1610409) -OrderBookClearTest:testClearSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256,bytes,address,uint256,uint256) (runs: 120, μ: 528352, ~: 525266) -OrderBookClearTest:testFlashLoanToNonReceiver(uint256,bytes,bytes32,bytes) (runs: 5116, μ: 28247, ~: 28145) -OrderBookDepositEnactTest:testDepositRevertInAction(address,uint256,uint256) (runs: 30, μ: 97295, ~: 97295) -OrderBookDepositEnactTest:testOrderBookDepositEnactEmptyNoop(address,uint256,uint256) (runs: 30, μ: 41751, ~: 41751) -OrderBookDepositEnactTest:testOrderBookDepositEnactOneReadState(address,uint256,uint256) (runs: 30, μ: 104020, ~: 104020) -OrderBookDepositEnactTest:testOrderBookDepositEnactOneStateless(address,uint256,uint256) (runs: 30, μ: 89382, ~: 89382) -OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256) (runs: 30, μ: 959679, ~: 959588) -OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSequential(address,uint256,uint256) (runs: 30, μ: 594204, ~: 594113) -OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSingle(address,uint256,uint256) (runs: 30, μ: 212811, ~: 212720) -OrderBookDepositEnactTest:testOrderDepositContext(address,uint256,uint256,uint256) (runs: 30, μ: 638475, ~: 631576) -OrderBookDepositTest:testDepositEvent(address,uint256,uint256) (runs: 120, μ: 39527, ~: 39527) -OrderBookDepositTest:testDepositFail(address,uint256,uint256) (runs: 120, μ: 1040441656, ~: 1040441612) +GenericPoolOrderBookV4ArbOrderTakerExpressionTest:testGenericPoolTakeOrdersExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256[],uint256[]) (runs: 34, μ: 428801, ~: 424733) +GenericPoolOrderBookV4ArbOrderTakerExpressionTest:testGenericPoolTakeOrdersWrongExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,address,bytes)) (runs: 34, μ: 170749, ~: 160600) +GenericPoolOrderBookV4ArbOrderTakerSenderTest:testGenericPoolTakeOrdersSender((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 34, μ: 274813, ~: 261494) +GenericPoolOrderBookV4FlashBorrowerTest:testGenericPoolOrderBookV4FlashBorrowerTakeOrdersSender((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 34, μ: 524833, ~: 497497) +LibOrderTest:testHashEqual((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 124, μ: 197448, ~: 186039) +LibOrderTest:testHashNotEqual((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 124, μ: 302512, ~: 286228) +OrderBookAddOrderEnactTest:testAddLiveOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 949267, ~: 900199) +OrderBookAddOrderEnactTest:testAddLiveOrderRevertNoAdd(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 742523, ~: 704793) +OrderBookAddOrderEnactTest:testAddOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1050395, ~: 1010656) +OrderBookAddOrderEnactTest:testAddOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 663683, ~: 628394) +OrderBookAddOrderEnactTest:testAddOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 724444, ~: 689141) +OrderBookAddOrderEnactTest:testAddOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 709792, ~: 674489) +OrderBookAddOrderEnactTest:testAddOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 3220991, ~: 3209629) +OrderBookAddOrderEnactTest:testAddOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 958281, ~: 922929) +OrderBookAddOrderEnactTest:testAddOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1370425, ~: 1306555) +OrderBookAddOrderMockTest:testAddOrderSameAccountWithDifferentConfig(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 124, μ: 2779086, ~: 2737709) +OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithDifferentConfig(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 124, μ: 2608876, ~: 2614417) +OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithSameConfig(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 2424811, ~: 2432732) +OrderBookAddOrderMockTest:testAddOrderWithCalculationsInputsAndOutputsSucceeds(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 1287450, ~: 1193623) +OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaEmitsMetaV1(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 1297086, ~: 1203601) +OrderBookAddOrderMockTest:testAddOrderWithNonEmptyMetaReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 691347, ~: 644037) +OrderBookAddOrderMockTest:testAddOrderWithoutCalculationsDeploys(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 707113, ~: 661336) +OrderBookAddOrderMockTest:testAddOrderWithoutInputsReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 169722, ~: 165526) +OrderBookAddOrderMockTest:testAddOrderWithoutOutputsReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 166365, ~: 161072) +OrderBookAddOrderNonceTest:testAddOrderNonceDifferentNonceStateChange(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes32) (runs: 124, μ: 1273547, ~: 1273546) +OrderBookAddOrderNonceTest:testAddOrderNonceSameNonceDifferentOrderStateChange(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1442764, ~: 1411510) +OrderBookAddOrderNonceTest:testAddOrderNonceSameOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1015735, ~: 948036) +OrderBookAddOrderOwnerTest:testAddOrderOwnerDifferentOwnerStateChange(((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,address) (runs: 124, μ: 1139373, ~: 1185421) +OrderBookAddOrderOwnerTest:testAddOrderOwnerSameOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1015831, ~: 948132) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts1(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 688267, ~: 645417) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsReverts2(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 690050, ~: 647200) +OrderBookAddOrderTest:testAddOrderRealCalculateInputsRevertsPreference(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 689613, ~: 646763) +OrderBookAddOrderTest:testAddOrderRealNoHandleIODeploys(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 680349, ~: 637499) +OrderBookAddOrderTest:testAddOrderRealNoSourcesDeploys(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 658007, ~: 615168) +OrderBookAddOrderTest:testAddOrderRealOneStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 692577, ~: 649727) +OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 705179, ~: 662329) +OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 698821, ~: 655971) +OrderBookAddOrderTest:testAddOrderRealZeroStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 686987, ~: 644137) +OrderBookClearHandleIORevertTest:testClearOrderAliceNoHandleIORevert() (gas: 518091) +OrderBookClearHandleIORevertTest:testClearOrderBobNoHandleIORevert() (gas: 518092) +OrderBookClearHandleIORevertTest:testClearOrderBothNoHandleIORevert() (gas: 497418) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 558313) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 550256) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 550464) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO3() (gas: 558357) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO4() (gas: 566810) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO5() (gas: 524408) +OrderBookClearOrderBadStackTest:testClearOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2367717, ~: 2393487) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2454362, ~: 2470602) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2462109, ~: 2478343) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOtherOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2388885, ~: 2414657) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2382458, ~: 2408230) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOtherEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2381210, ~: 2406973) +OrderBookClearOrderContextTest:testContextEmptyStack(address,address,uint256,uint256,uint256,uint256) (runs: 34, μ: 2160140, ~: 2150067) +OrderBookClearSameTokenTest:testClearSameToken(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1570894, ~: 1571631) +OrderBookClearTest:testClear2ZeroRatioAliceAndBob(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920271, ~: 4040826) +OrderBookClearTest:testClear2ZeroRatioAliceOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920387, ~: 4040942) +OrderBookClearTest:testClear2ZeroRatioBobOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920393, ~: 4040948) +OrderBookClearTest:testClearFuzzIoRatio(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3866568, ~: 3863723) +OrderBookClearTest:testClearSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3961226, ~: 4081777) +OrderBookClearTest:testFlashLoanToNonReceiver(uint256,bytes,bytes32,bytes) (runs: 5120, μ: 28247, ~: 28145) +OrderBookDepositEnactTest:testDepositRevertInAction(address,uint256,uint256) (runs: 34, μ: 97295, ~: 97295) +OrderBookDepositEnactTest:testOrderBookDepositEnactEmptyNoop(address,uint256,uint256) (runs: 34, μ: 41751, ~: 41751) +OrderBookDepositEnactTest:testOrderBookDepositEnactOneReadState(address,uint256,uint256) (runs: 34, μ: 104020, ~: 104020) +OrderBookDepositEnactTest:testOrderBookDepositEnactOneStateless(address,uint256,uint256) (runs: 34, μ: 89382, ~: 89382) +OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256) (runs: 34, μ: 959717, ~: 959588) +OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSequential(address,uint256,uint256) (runs: 34, μ: 594234, ~: 594113) +OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSingle(address,uint256,uint256) (runs: 34, μ: 212841, ~: 212720) +OrderBookDepositEnactTest:testOrderDepositContext(address,uint256,uint256,uint256) (runs: 34, μ: 640956, ~: 632645) +OrderBookDepositTest:testDepositEvent(address,uint256,uint256) (runs: 124, μ: 39527, ~: 39527) +OrderBookDepositTest:testDepositFail(address,uint256,uint256) (runs: 124, μ: 1040441653, ~: 1040441629) OrderBookDepositTest:testDepositGas00() (gas: 8940) OrderBookDepositTest:testDepositGas01() (gas: 35406) -OrderBookDepositTest:testDepositMany((address,address,uint256,uint248)[]) (runs: 104, μ: 2341676, ~: 1527003) -OrderBookDepositTest:testDepositOverflow(address,uint256,uint256,uint256) (runs: 119, μ: 53340, ~: 53654) -OrderBookDepositTest:testDepositReentrancy(address,uint256,uint256,address,uint256,uint256) (runs: 120, μ: 623779, ~: 624277) -OrderBookDepositTest:testDepositSimple(address,uint256,uint256) (runs: 120, μ: 38760, ~: 38760) -OrderBookDepositTest:testDepositZero(address,uint256) (runs: 120, μ: 13201, ~: 13201) -OrderBookDepositTest:testVaultBalanceNoDeposits(address,uint256) (runs: 5116, μ: 8947, ~: 8947) -OrderBookEnactTest:testOrderBookEvalEmptyNoop(address) (runs: 120, μ: 14051, ~: 14051) -OrderBookEnactTest:testOrderBookEvalOneReadState(address) (runs: 120, μ: 73408, ~: 73408) -OrderBookEnactTest:testOrderBookEvalOneStateless(address) (runs: 120, μ: 58746, ~: 58746) -OrderBookEnactTest:testOrderBookEvalWriteStateDifferentOwnersNamespaced(address,address) (runs: 120, μ: 867107, ~: 867107) +OrderBookDepositTest:testDepositMany((address,address,uint256,uint248)[]) (runs: 107, μ: 2307629, ~: 1479224) +OrderBookDepositTest:testDepositOverflow(address,uint256,uint256,uint256) (runs: 123, μ: 53308, ~: 53654) +OrderBookDepositTest:testDepositReentrancy(address,uint256,uint256,address,uint256,uint256) (runs: 124, μ: 623795, ~: 624277) +OrderBookDepositTest:testDepositSimple(address,uint256,uint256) (runs: 124, μ: 38760, ~: 38760) +OrderBookDepositTest:testDepositZero(address,uint256) (runs: 124, μ: 13201, ~: 13201) +OrderBookDepositTest:testVaultBalanceNoDeposits(address,uint256) (runs: 5120, μ: 8947, ~: 8947) +OrderBookEnactTest:testOrderBookEvalEmptyNoop(address) (runs: 124, μ: 14051, ~: 14051) +OrderBookEnactTest:testOrderBookEvalOneReadState(address) (runs: 124, μ: 73408, ~: 73408) +OrderBookEnactTest:testOrderBookEvalOneStateless(address) (runs: 124, μ: 58746, ~: 58746) +OrderBookEnactTest:testOrderBookEvalWriteStateDifferentOwnersNamespaced(address,address) (runs: 124, μ: 867107, ~: 867107) OrderBookEnactTest:testOrderBookEvalWriteStateSequential() (gas: 543024) -OrderBookEnactTest:testOrderBookEvalWriteStateSingle(address) (runs: 120, μ: 170894, ~: 170894) -OrderBookQuoteSameTokenTest:testQuoteSameToken(((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)[])) (runs: 30, μ: 7875634, ~: 7965690) -OrderBookQuoteTest:testQuoteContextSender(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 120, μ: 10904292, ~: 11063023) -OrderBookQuoteTest:testQuoteDeadOrder(((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)[])) (runs: 120, μ: 6619696, ~: 5534272) -OrderBookQuoteTest:testQuoteMaxOutput(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 120, μ: 1188835, ~: 1207423) -OrderBookQuoteTest:testQuoteSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 120, μ: 1182167, ~: 1200421) -OrderBookRemoveOrderEnactTest:testRemoveOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 687363, ~: 661455) -OrderBookRemoveOrderEnactTest:testRemoveOrderDeadOrder(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 380772, ~: 359784) -OrderBookRemoveOrderEnactTest:testRemoveOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1162539, ~: 1091632) -OrderBookRemoveOrderEnactTest:testRemoveOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1223651, ~: 1152727) -OrderBookRemoveOrderEnactTest:testRemoveOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1209007, ~: 1138083) -OrderBookRemoveOrderEnactTest:testRemoveOrderRevertInAction(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1355858, ~: 1277355) -OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 4998149, ~: 4996303) -OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 1458888, ~: 1387903) -OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 2365186, ~: 2230637) -OrderBookRemoveOrderMockTest:testRemoveOrderAddRemoveMulti(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 7378289, ~: 6693347) -OrderBookRemoveOrderMockTest:testRemoveOrderDifferent(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 4964653, ~: 4909064) -OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwners(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 4820881, ~: 4857836) -OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwnersDifferent(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 10602665, ~: 10658666) -OrderBookRemoveOrderMockTest:testRemoveOrderDoesNotExist(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 388030, ~: 355582) -OrderBookRemoveOrderMockTest:testRemoveOrderOnlyOwner(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 120, μ: 2581550, ~: 2606274) -OrderBookRemoveOrderOwnerTest:testRemoveOrderOwnerDifferentOwnerStateChange(((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,address) (runs: 120, μ: 5571616, ~: 5772034) -OrderBookRemoveOrderOwnerTest:testRemoveOrderOwnerSameOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 3664516, ~: 3421522) -OrderBookRemoveOrderOwnerTest:testRemoveOrderWrongOwner(((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,address) (runs: 120, μ: 718199, ~: 750627) +OrderBookEnactTest:testOrderBookEvalWriteStateSingle(address) (runs: 124, μ: 170894, ~: 170894) +OrderBookQuoteSameTokenTest:testQuoteSameToken(((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)[])) (runs: 34, μ: 7316072, ~: 7067047) +OrderBookQuoteTest:testQuoteContextSender(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 10907376, ~: 10885914) +OrderBookQuoteTest:testQuoteDeadOrder(((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)[])) (runs: 124, μ: 6489058, ~: 5413815) +OrderBookQuoteTest:testQuoteMaxOutput(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 1189229, ~: 1188117) +OrderBookQuoteTest:testQuoteSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 1182510, ~: 1181115) +OrderBookRemoveOrderEnactTest:testRemoveOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 687553, ~: 659404) +OrderBookRemoveOrderEnactTest:testRemoveOrderDeadOrder(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 380949, ~: 357984) +OrderBookRemoveOrderEnactTest:testRemoveOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1163199, ~: 1085367) +OrderBookRemoveOrderEnactTest:testRemoveOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1224311, ~: 1146461) +OrderBookRemoveOrderEnactTest:testRemoveOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1209667, ~: 1131817) +OrderBookRemoveOrderEnactTest:testRemoveOrderRevertInAction(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1356568, ~: 1270473) +OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 4976864, ~: 4872948) +OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1459549, ~: 1381630) +OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2366456, ~: 2218703) +OrderBookRemoveOrderMockTest:testRemoveOrderAddRemoveMulti(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 7390386, ~: 6778974) +OrderBookRemoveOrderMockTest:testRemoveOrderDifferent(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 4963217, ~: 4909064) +OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwners(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 4798479, ~: 4800278) +OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwnersDifferent(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 10532784, ~: 10582773) +OrderBookRemoveOrderMockTest:testRemoveOrderDoesNotExist(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 388673, ~: 359875) +OrderBookRemoveOrderMockTest:testRemoveOrderOnlyOwner(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 2569832, ~: 2575893) +OrderBookRemoveOrderOwnerTest:testRemoveOrderOwnerDifferentOwnerStateChange(((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,address) (runs: 124, μ: 5520750, ~: 5685104) +OrderBookRemoveOrderOwnerTest:testRemoveOrderOwnerSameOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 3666333, ~: 3401225) +OrderBookRemoveOrderOwnerTest:testRemoveOrderWrongOwner(((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,address) (runs: 124, μ: 712164, ~: 740525) OrderBookSubParserContextCalculatedIORatioTest:testSubParserContextHappy() (gas: 2102274) OrderBookSubParserContextCalculatedIORatioTest:testSubParserContextUnhappyDisallowedInputs() (gas: 2080218) OrderBookSubParserContextCalculatedIORatioTest:testSubParserContextUnhappyDisallowedOperand() (gas: 2065830) @@ -154,7 +158,7 @@ OrderBookSubParserContextVaultBalanceBeforeTest:testSubParserContextHappy() (gas OrderBookSubParserContextVaultBalanceBeforeTest:testSubParserContextUnhappyDisallowedInputs() (gas: 2080056) OrderBookSubParserContextVaultBalanceBeforeTest:testSubParserContextUnhappyDisallowedOperand() (gas: 2065668) OrderBookSubParserDescribedByMetaV1Test:testOrderBookSubParserDescribedByMetaV1Happy() (gas: 2018322) -OrderBookSubParserIERC165Test:testOrderBookSubParserIERC165(bytes4) (runs: 5116, μ: 2018691, ~: 2018691) +OrderBookSubParserIERC165Test:testOrderBookSubParserIERC165(bytes4) (runs: 5120, μ: 2018691, ~: 2018691) OrderBookSubParserPointersTest:testSubParserFunctionPointers() (gas: 2029308) OrderBookSubParserPointersTest:testSubParserOperandParsers() (gas: 2029308) OrderBookSubParserPointersTest:testSubParserParseMeta() (gas: 172448) @@ -171,70 +175,70 @@ OrderBookSubParserSignersTest:testSubParserContextSignerHappy1() (gas: 2103255) OrderBookSubParserSignersTest:testSubParserContextSignerUnhappyInput() (gas: 2081027) OrderBookSubParserSignersTest:testSubParserContextSignerUnhappyNoOperand() (gas: 2060334) OrderBookSubParserSignersTest:testSubParserContextSignerUnhappyTooManyOperands() (gas: 2066585) -OrderBookTakeOrderBadStackTest:testTakeOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 971414, ~: 969392) -OrderBookTakeOrderBadStackTest:testTakeOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 978731, ~: 976709) +OrderBookTakeOrderBadStackTest:testTakeOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 966841, ~: 943156) +OrderBookTakeOrderBadStackTest:testTakeOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 974157, ~: 950469) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO0() (gas: 241092) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO1() (gas: 405265) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO10(uint256) (runs: 120, μ: 644132, ~: 608769) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO10(uint256) (runs: 124, μ: 644122, ~: 608769) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO2() (gas: 418991) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO3() (gas: 563700) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO4() (gas: 583211) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO5() (gas: 583210) OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO6() (gas: 569415) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO7(uint256) (runs: 120, μ: 828013, ~: 828324) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO8(uint256) (runs: 120, μ: 986808, ~: 987119) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO9(uint256) (runs: 120, μ: 727911, ~: 663874) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO7(uint256) (runs: 124, μ: 828023, ~: 828324) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO8(uint256) (runs: 124, μ: 986818, ~: 987119) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO9(uint256) (runs: 124, μ: 725368, ~: 663874) OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert0() (gas: 233005) OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert1() (gas: 391201) OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert2() (gas: 377476) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrders(uint256,uint256) (runs: 120, μ: 414435, ~: 425042) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrdersMultipleOwners(uint256,uint256,uint256) (runs: 120, μ: 472150, ~: 483089) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleAnyDeposit(uint256,uint256) (runs: 120, μ: 261126, ~: 261943) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumInput(uint256,uint256) (runs: 120, μ: 242333, ~: 243577) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumOutput(uint256) (runs: 120, μ: 241942, ~: 241905) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderUnlimitedMax(uint256) (runs: 120, μ: 238883, ~: 238709) -OrderBookTakeOrderMaximumInputTest:testTakeOrderNoopZeroMaxTakerInput((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,uint256[],bytes)) (runs: 120, μ: 178517, ~: 174756) -OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderOne((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)) (runs: 120, μ: 433111, ~: 412866) -OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderTwo((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256,(address,uint256[],bytes),(address,uint256[],bytes)) (runs: 120, μ: 849949, ~: 841638) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrders(uint256,uint256) (runs: 124, μ: 412695, ~: 425042) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrdersMultipleOwners(uint256,uint256,uint256) (runs: 124, μ: 471460, ~: 483089) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleAnyDeposit(uint256,uint256) (runs: 124, μ: 261154, ~: 261943) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumInput(uint256,uint256) (runs: 124, μ: 242385, ~: 243577) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumOutput(uint256) (runs: 124, μ: 241941, ~: 241905) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderUnlimitedMax(uint256) (runs: 124, μ: 238888, ~: 238709) +OrderBookTakeOrderMaximumInputTest:testTakeOrderNoopZeroMaxTakerInput((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,uint256[],bytes)) (runs: 124, μ: 179434, ~: 177315) +OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderOne((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)) (runs: 124, μ: 433736, ~: 412791) +OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderTwo((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256,(address,uint256[],bytes),(address,uint256[],bytes)) (runs: 124, μ: 846774, ~: 827948) OrderBookTakeOrderNoopTest:testTakeOrderNoopZeroOrders() (gas: 12427) OrderBookTakeOrderPrecisionTest:testTakeOrderPrecisionKnownBad01() (gas: 2224106) -OrderBookTakeOrderSameTokenTest:testTakeOrderSameToken(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 30, μ: 798509, ~: 750217) -OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenDecimalsMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 29, μ: 653020, ~: 650740) -OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 30, μ: 665302, ~: 656765) -OrderBookTakeOrderTokenMismatchTest:testTokenDecimalMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 30, μ: 666703, ~: 680544) -OrderBookTakeOrderTokenMismatchTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 30, μ: 665449, ~: 679290) +OrderBookTakeOrderSameTokenTest:testTakeOrderSameToken(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 804111, ~: 760276) +OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenDecimalsMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 33, μ: 677650, ~: 686132) +OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 33, μ: 667067, ~: 664356) +OrderBookTakeOrderTokenMismatchTest:testTokenDecimalMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 34, μ: 669331, ~: 694240) +OrderBookTakeOrderTokenMismatchTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 34, μ: 668077, ~: 692986) OrderBookV4ArbOrderTakerContextTest:testOrderBookV4ArbOrderTakerContext() (gas: 2602528) -OrderBookV4ArbOrderTakerIERC165Test:testOrderBookV4ArbOrderTakerIERC165(bytes4) (runs: 5115, μ: 2374572, ~: 2374572) -OrderBookV4FlashBorrowerIERC165Test:testOrderBookV4FlashBorrowerIERC165(bytes4) (runs: 5116, μ: 2786827, ~: 2786827) -OrderBookV4FlashLenderFeeTest:testFlashFee(address,uint256) (runs: 5116, μ: 6536, ~: 6536) -OrderBookV4FlashLenderIERC165Test:testOrderBookV4FlashLenderIERC165(bytes4) (runs: 5116, μ: 580452, ~: 580452) -OrderBookV4FlashLenderMaxFlashLoanTest:testFlashMaxLoan(uint256) (runs: 5116, μ: 7981, ~: 7981) -OrderBookV4FlashLenderMockSuccessTest:testFlashLoanToReceiver(uint256,bytes) (runs: 5116, μ: 14786, ~: 14732) -OrderBookV4FlashLenderReentrant:testReenterAddOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 18194767, ~: 18185165) -OrderBookV4FlashLenderReentrant:testReenterCheckOrderExists(bytes32,uint256) (runs: 120, μ: 553734, ~: 553900) -OrderBookV4FlashLenderReentrant:testReenterClear(uint256,address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 38278399, ~: 37480533) -OrderBookV4FlashLenderReentrant:testReenterDeposit(uint256,uint256,uint256) (runs: 120, μ: 654935, ~: 655599) -OrderBookV4FlashLenderReentrant:testReenterReadVaultBalances(uint256,uint256) (runs: 120, μ: 598689, ~: 599187) -OrderBookV4FlashLenderReentrant:testReenterRemoveOrder(uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 120, μ: 18206981, ~: 17683197) -OrderBookV4FlashLenderReentrant:testReenterTakeOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 120, μ: 18812960, ~: 18743878) -OrderBookV4FlashLenderReentrant:testReenterWithdraw(uint256,uint256,uint256) (runs: 120, μ: 631402, ~: 632066) -OrderBookV4FlashLenderTransferTest:testFlashLoanTransferFail(uint256,uint256,bool) (runs: 120, μ: 1345648, ~: 1347531) -OrderBookV4FlashLenderTransferTest:testFlashLoanTransferSuccess(uint256,bool) (runs: 120, μ: 1291806, ~: 1297531) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalEmptyNoop(address,uint256,uint256,uint256) (runs: 120, μ: 53343, ~: 54109) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneReadState(address,uint256,uint256,uint256) (runs: 120, μ: 115301, ~: 116671) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneStateless(address,uint256,uint256,uint256) (runs: 120, μ: 100684, ~: 102054) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256,uint256) (runs: 120, μ: 993643, ~: 994386) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSequential(address,uint256,uint256,uint256) (runs: 120, μ: 611291, ~: 612659) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSingle(address,uint256,uint256,uint256) (runs: 120, μ: 229045, ~: 230413) -OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalRevertInAction(address,uint256,uint256,uint256) (runs: 120, μ: 108288, ~: 109658) -OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalZeroAmountEvalNoop(address,uint256,uint256) (runs: 120, μ: 60976, ~: 60768) -OrderBookWithdrawEvalTest:testOrderWithdrawContext(address,uint256,uint256,uint256) (runs: 120, μ: 722770, ~: 721530) -OrderBookWithdrawTest:testWithdrawEmptyVault(address,address,uint256,uint256) (runs: 120, μ: 17802, ~: 17802) -OrderBookWithdrawTest:testWithdrawFailure(address,uint256,uint256,uint256) (runs: 120, μ: 1040419101, ~: 1040437714) -OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (runs: 110, μ: 40855, ~: 40836) -OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) (runs: 120, μ: 3252472, ~: 3353023) -OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 110, μ: 51385, ~: 51385) -OrderBookWithdrawTest:testWithdrawZero(address,address,uint256) (runs: 120, μ: 13382, ~: 13382) -RouteProcessorOrderBookV4ArbOrderTakerExpressionTest:testRouteProcessorTakeOrdersExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256[],uint256[]) (runs: 120, μ: 366932, ~: 361105) -RouteProcessorOrderBookV4ArbOrderTakerExpressionTest:testRouteProcessorTakeOrdersWrongExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,address,bytes)) (runs: 120, μ: 167491, ~: 155298) -RouteProcessorOrderBookV4ArbOrderTakerSenderTest:testRouteProcessorTakeOrdersSender((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 120, μ: 264572, ~: 263505) \ No newline at end of file +OrderBookV4ArbOrderTakerIERC165Test:testOrderBookV4ArbOrderTakerIERC165(bytes4) (runs: 5119, μ: 2374572, ~: 2374572) +OrderBookV4FlashBorrowerIERC165Test:testOrderBookV4FlashBorrowerIERC165(bytes4) (runs: 5120, μ: 2786827, ~: 2786827) +OrderBookV4FlashLenderFeeTest:testFlashFee(address,uint256) (runs: 5120, μ: 6536, ~: 6536) +OrderBookV4FlashLenderIERC165Test:testOrderBookV4FlashLenderIERC165(bytes4) (runs: 5120, μ: 580452, ~: 580452) +OrderBookV4FlashLenderMaxFlashLoanTest:testFlashMaxLoan(uint256) (runs: 5120, μ: 7981, ~: 7981) +OrderBookV4FlashLenderMockSuccessTest:testFlashLoanToReceiver(uint256,bytes) (runs: 5120, μ: 14786, ~: 14732) +OrderBookV4FlashLenderReentrant:testReenterAddOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 18438356, ~: 18737951) +OrderBookV4FlashLenderReentrant:testReenterCheckOrderExists(bytes32,uint256) (runs: 124, μ: 553900, ~: 553900) +OrderBookV4FlashLenderReentrant:testReenterClear(uint256,address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 37927832, ~: 37278193) +OrderBookV4FlashLenderReentrant:testReenterDeposit(uint256,uint256,uint256) (runs: 124, μ: 655278, ~: 655599) +OrderBookV4FlashLenderReentrant:testReenterReadVaultBalances(uint256,uint256) (runs: 124, μ: 598866, ~: 599187) +OrderBookV4FlashLenderReentrant:testReenterRemoveOrder(uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 124, μ: 18140249, ~: 17634324) +OrderBookV4FlashLenderReentrant:testReenterTakeOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 19061600, ~: 19326380) +OrderBookV4FlashLenderReentrant:testReenterWithdraw(uint256,uint256,uint256) (runs: 124, μ: 631745, ~: 632066) +OrderBookV4FlashLenderTransferTest:testFlashLoanTransferFail(uint256,uint256,bool) (runs: 124, μ: 1345626, ~: 1347531) +OrderBookV4FlashLenderTransferTest:testFlashLoanTransferSuccess(uint256,bool) (runs: 124, μ: 1291779, ~: 1297531) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalEmptyNoop(address,uint256,uint256,uint256) (runs: 124, μ: 53297, ~: 54109) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneReadState(address,uint256,uint256,uint256) (runs: 124, μ: 115200, ~: 116671) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneStateless(address,uint256,uint256,uint256) (runs: 124, μ: 100583, ~: 102054) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256,uint256) (runs: 124, μ: 993387, ~: 994386) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSequential(address,uint256,uint256,uint256) (runs: 124, μ: 611190, ~: 612659) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSingle(address,uint256,uint256,uint256) (runs: 124, μ: 228944, ~: 230413) +OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalRevertInAction(address,uint256,uint256,uint256) (runs: 124, μ: 108187, ~: 109658) +OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalZeroAmountEvalNoop(address,uint256,uint256) (runs: 124, μ: 60969, ~: 60768) +OrderBookWithdrawEvalTest:testOrderWithdrawContext(address,uint256,uint256,uint256) (runs: 124, μ: 723413, ~: 721505) +OrderBookWithdrawTest:testWithdrawEmptyVault(address,address,uint256,uint256) (runs: 123, μ: 17802, ~: 17802) +OrderBookWithdrawTest:testWithdrawFailure(address,uint256,uint256,uint256) (runs: 124, μ: 1040418749, ~: 1040437709) +OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (runs: 115, μ: 40852, ~: 40831) +OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) (runs: 124, μ: 3260899, ~: 3383353) +OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 109, μ: 51385, ~: 51385) +OrderBookWithdrawTest:testWithdrawZero(address,address,uint256) (runs: 124, μ: 13382, ~: 13382) +RouteProcessorOrderBookV4ArbOrderTakerExpressionTest:testRouteProcessorTakeOrdersExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256[],uint256[]) (runs: 124, μ: 366920, ~: 361105) +RouteProcessorOrderBookV4ArbOrderTakerExpressionTest:testRouteProcessorTakeOrdersWrongExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,address,bytes)) (runs: 124, μ: 167756, ~: 157267) +RouteProcessorOrderBookV4ArbOrderTakerSenderTest:testRouteProcessorTakeOrdersSender((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 124, μ: 265201, ~: 262673) \ No newline at end of file diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index 650e3c746..af713aba8 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -28,7 +28,6 @@ import {LibNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol"; import {LibMeta} from "rain.metadata/lib/LibMeta.sol"; import {IMetaV1_2} from "rain.metadata/interface/unstable/IMetaV1_2.sol"; import {LibOrderBook} from "../../lib/LibOrderBook.sol"; -import {console2} from "forge-std/Test.sol"; import { IOrderBookV4, @@ -682,11 +681,6 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order ClearStateChange memory clearStateChange = calculateClearStateChange(aliceOrderIOCalculation, bobOrderIOCalculation); - console2.log("clearStateChange.aliceOutput", clearStateChange.aliceOutput); - console2.log("clearStateChange.bobInput", clearStateChange.bobInput); - console2.log("clearStateChange.bobOutput", clearStateChange.bobOutput); - console2.log("clearStateChange.aliceInput", clearStateChange.aliceInput); - recordVaultIO(clearStateChange.aliceInput, clearStateChange.aliceOutput, aliceOrderIOCalculation); recordVaultIO(clearStateChange.bobInput, clearStateChange.bobOutput, bobOrderIOCalculation); diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 1a78ee010..025c39d6d 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -286,7 +286,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 aliceIORatio, uint256 bobIORatio ) external { - aliceIORatio = bound(aliceIORatio, 0.99e18, 1e18); + aliceIORatio = bound(aliceIORatio, 0.9e18, 1e18); bobIORatio = bound(bobIORatio, 1e18, uint256(1e18).fixedPointDiv(aliceIORatio, Math.Rounding.Down)); // Mock the interpreter.eval that is used inside clear().calculateOrderIO() @@ -319,10 +319,12 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256(1e18).fixedPointDiv(bobIORatio, Math.Rounding.Down).min(1e18), // Expected input for Alice is aliceOutput * aliceIORatio uint256(1e18).fixedPointMul(aliceIORatio, Math.Rounding.Up), - // Expected output for Bob is bob's output * bobIORatio - uint256(1e18).fixedPointDiv(bobIORatio, Math.Rounding.Down).min(1e18).fixedPointMul( - bobIORatio, Math.Rounding.Up - ) + // Expected input for Bob is Alice's output in entirety, because + // alice IO * bob IO <= 1 and Bob is the larger ratio. + // As Bob's ratio is >= 1 he will have his input shrunk to match + // Alice's output. This means in this case Bob's input will be + // 1 always, as it either = 1 anyway or matches Alice's 1. + uint256(1e18) ) ); } From a534b78d88c8156a6ca92d22481169153ca9296d Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Tue, 24 Dec 2024 18:10:50 +0400 Subject: [PATCH 21/28] fuzz for ratio more than 1 --- test/concrete/ob/OrderBook.clear.mock.t.sol | 70 +++++++++++++++++++-- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index 025c39d6d..bed215109 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -2,7 +2,7 @@ // SPDX-FileCopyrightText: Copyright (c) 2020 thedavidmeister pragma solidity =0.8.25; -import {Test} from "forge-std/Test.sol"; +import {Test, stdError} from "forge-std/Test.sol"; import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {OrderBookExternalMockTest} from "test/util/abstract/OrderBookExternalMockTest.sol"; @@ -87,6 +87,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 expectedBobOutput; uint256 expectedAliceInput; uint256 expectedBobInput; + bytes expectedError; } function doClear(DoClear memory clear) internal { @@ -175,6 +176,9 @@ contract OrderBookClearTest is OrderBookExternalMockTest { }); vm.prank(clear.bountyBot); + if (clear.expectedError.length > 0) { + vm.expectRevert(clear.expectedError); + } iOrderbook.clear2(aliceOrder, bobOrder, configClear, new SignedContextV1[](0), new SignedContextV1[](0)); } @@ -268,7 +272,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0.495e18, - 0.495e18 + 0.495e18, + "" ) ); } @@ -324,7 +329,57 @@ contract OrderBookClearTest is OrderBookExternalMockTest { // As Bob's ratio is >= 1 he will have his input shrunk to match // Alice's output. This means in this case Bob's input will be // 1 always, as it either = 1 anyway or matches Alice's 1. - uint256(1e18) + uint256(1e18), + "" + ) + ); + } + + /// forge-config: default.fuzz.runs = 100 + function testClearFuzzIoRatioError( + address alice, + OrderConfigV3 memory aliceConfig, + address bob, + OrderConfigV3 memory bobConfig, + bytes memory expression, + address bountyBot, + uint256 aliceBountyVaultId, + uint256 bobBountyVaultId, + uint256 aliceIORatio, + uint256 bobIORatio + ) external { + aliceIORatio = bound(aliceIORatio, 1e18 + 1, 1.1e18); + bobIORatio = bound(bobIORatio, 1e18 + 1, 1.1e18); + + // Mock the interpreter.eval that is used inside clear().calculateOrderIO() + // Produce the stack output for OB + uint256[] memory orderStackAlice = new uint256[](2); + orderStackAlice[0] = aliceIORatio; // orderIORatio + orderStackAlice[1] = 1e18; // orderOutputMax + + uint256[] memory orderStackBob = new uint256[](2); + orderStackBob[0] = bobIORatio; // orderIORatio + orderStackBob[1] = 1e18; // orderOutputMax + + doClear( + DoClear( + alice, + aliceConfig, + bob, + bobConfig, + bountyBot, + aliceBountyVaultId, + bobBountyVaultId, + 1e18, + 1e18, + expression, + orderStackAlice, + orderStackBob, + 0, + 0, + 0, + 0, + stdError.arithmeticError ) ); } @@ -368,7 +423,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0, - 0.5e18 + 0.5e18, + "" ) ); } @@ -412,7 +468,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0.5e18, - 0 + 0, + "" ) ); } @@ -458,7 +515,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { 0.5e18, 0.5e18, 0, - 0 + 0, + "" ) ); } From fefcbfdb3411cbbfdeb6e991832c22f15342c02d Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Thu, 26 Dec 2024 19:34:20 +0400 Subject: [PATCH 22/28] lint --- .gas-snapshot | 11 ++++---- test/concrete/ob/OrderBook.clear.mock.t.sol | 31 +++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 891a425a0..f1dd85ccd 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -53,11 +53,12 @@ OrderBookClearOrderBadStackTest:testClearOrderBadStackOneStack(address,address,( OrderBookClearOrderBadStackTest:testClearOrderBadStackOtherEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2381210, ~: 2406973) OrderBookClearOrderContextTest:testContextEmptyStack(address,address,uint256,uint256,uint256,uint256) (runs: 34, μ: 2160140, ~: 2150067) OrderBookClearSameTokenTest:testClearSameToken(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1570894, ~: 1571631) -OrderBookClearTest:testClear2ZeroRatioAliceAndBob(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920271, ~: 4040826) -OrderBookClearTest:testClear2ZeroRatioAliceOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920387, ~: 4040942) -OrderBookClearTest:testClear2ZeroRatioBobOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920393, ~: 4040948) -OrderBookClearTest:testClearFuzzIoRatio(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3866568, ~: 3863723) -OrderBookClearTest:testClearSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3961226, ~: 4081777) +OrderBookClearTest:testClear2ZeroRatioAliceAndBob(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920430, ~: 4040987) +OrderBookClearTest:testClear2ZeroRatioAliceOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920546, ~: 4041103) +OrderBookClearTest:testClear2ZeroRatioBobOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920530, ~: 4041087) +OrderBookClearTest:testClearFuzzIoRatio(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3858509, ~: 3863881) +OrderBookClearTest:testClearFuzzIoRatioError(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3856937, ~: 3853167) +OrderBookClearTest:testClearSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3961384, ~: 4081938) OrderBookClearTest:testFlashLoanToNonReceiver(uint256,bytes,bytes32,bytes) (runs: 5120, μ: 28247, ~: 28145) OrderBookDepositEnactTest:testDepositRevertInAction(address,uint256,uint256) (runs: 34, μ: 97295, ~: 97295) OrderBookDepositEnactTest:testOrderBookDepositEnactEmptyNoop(address,uint256,uint256) (runs: 34, μ: 41751, ~: 41751) diff --git a/test/concrete/ob/OrderBook.clear.mock.t.sol b/test/concrete/ob/OrderBook.clear.mock.t.sol index bed215109..be2e982b8 100644 --- a/test/concrete/ob/OrderBook.clear.mock.t.sol +++ b/test/concrete/ob/OrderBook.clear.mock.t.sol @@ -70,7 +70,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bobConfig.meta = ""; } - struct DoClear { + struct CheckClear { address alice; OrderConfigV3 aliceConfig; address bob; @@ -90,7 +90,7 @@ contract OrderBookClearTest is OrderBookExternalMockTest { bytes expectedError; } - function doClear(DoClear memory clear) internal { + function checkClear(CheckClear memory clear) internal { vm.assume(clear.alice != clear.bob); vm.assume(clear.alice != clear.bountyBot); vm.assume(clear.bob != clear.bountyBot); @@ -255,8 +255,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStackAlice[0] = 0.99e18; // orderIORatio orderStackAlice[1] = 0.5e18; // orderOutputMax - doClear( - DoClear( + checkClear( + CheckClear( alice, aliceConfig, bob, @@ -291,7 +291,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { uint256 aliceIORatio, uint256 bobIORatio ) external { - aliceIORatio = bound(aliceIORatio, 0.9e18, 1e18); + // 0 tested separately. + aliceIORatio = bound(aliceIORatio, 1, 1e18); bobIORatio = bound(bobIORatio, 1e18, uint256(1e18).fixedPointDiv(aliceIORatio, Math.Rounding.Down)); // Mock the interpreter.eval that is used inside clear().calculateOrderIO() @@ -304,8 +305,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStackBob[0] = bobIORatio; // orderIORatio orderStackBob[1] = 1e18; // orderOutputMax - doClear( - DoClear( + checkClear( + CheckClear( alice, aliceConfig, bob, @@ -361,8 +362,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStackBob[0] = bobIORatio; // orderIORatio orderStackBob[1] = 1e18; // orderOutputMax - doClear( - DoClear( + checkClear( + CheckClear( alice, aliceConfig, bob, @@ -406,8 +407,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStackBob[0] = 1e18; // Nonzero orderIORatio orderStackBob[1] = 0.5e18; // orderOutputMax - doClear( - DoClear( + checkClear( + CheckClear( alice, aliceConfig, bob, @@ -451,8 +452,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStackBob[0] = 0; // Nonzero orderIORatio orderStackBob[1] = 0.5e18; // orderOutputMax - doClear( - DoClear( + checkClear( + CheckClear( alice, aliceConfig, bob, @@ -498,8 +499,8 @@ contract OrderBookClearTest is OrderBookExternalMockTest { orderStackBob[0] = 0; // Zero orderIORatio orderStackBob[1] = 5e17; // orderOutputMax - doClear( - DoClear( + checkClear( + CheckClear( alice, aliceConfig, bob, From dd826af6c517b6f2a3fe55283b84cb563dcd9b01 Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Thu, 26 Dec 2024 19:42:28 +0400 Subject: [PATCH 23/28] fix compile size --- .gas-snapshot | 188 +++++++++++++++++----------------- src/concrete/ob/OrderBook.sol | 12 ++- 2 files changed, 102 insertions(+), 98 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index f1dd85ccd..018e5946d 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -6,14 +6,14 @@ LibOrderTest:testHashEqual((address,(address,address,bytes),(address,uint8,uint2 LibOrderTest:testHashNotEqual((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 124, μ: 302512, ~: 286228) OrderBookAddOrderEnactTest:testAddLiveOrderNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 949267, ~: 900199) OrderBookAddOrderEnactTest:testAddLiveOrderRevertNoAdd(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 742523, ~: 704793) -OrderBookAddOrderEnactTest:testAddOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1050395, ~: 1010656) +OrderBookAddOrderEnactTest:testAddOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1050387, ~: 1010578) OrderBookAddOrderEnactTest:testAddOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 663683, ~: 628394) OrderBookAddOrderEnactTest:testAddOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 724444, ~: 689141) OrderBookAddOrderEnactTest:testAddOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 709792, ~: 674489) -OrderBookAddOrderEnactTest:testAddOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 3220991, ~: 3209629) +OrderBookAddOrderEnactTest:testAddOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 3220985, ~: 3209629) OrderBookAddOrderEnactTest:testAddOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 958281, ~: 922929) OrderBookAddOrderEnactTest:testAddOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1370425, ~: 1306555) -OrderBookAddOrderMockTest:testAddOrderSameAccountWithDifferentConfig(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 124, μ: 2779086, ~: 2737709) +OrderBookAddOrderMockTest:testAddOrderSameAccountWithDifferentConfig(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 124, μ: 2779085, ~: 2737709) OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithDifferentConfig(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,bytes) (runs: 124, μ: 2608876, ~: 2614417) OrderBookAddOrderMockTest:testAddOrderTwoAccountsWithSameConfig(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 2424811, ~: 2432732) OrderBookAddOrderMockTest:testAddOrderWithCalculationsInputsAndOutputsSucceeds(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 1287450, ~: 1193623) @@ -36,45 +36,45 @@ OrderBookAddOrderTest:testAddOrderRealOneStackCalculateReverts(address,((address OrderBookAddOrderTest:testAddOrderRealThreeStackCalculate(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 705179, ~: 662329) OrderBookAddOrderTest:testAddOrderRealTwoStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 698821, ~: 655971) OrderBookAddOrderTest:testAddOrderRealZeroStackCalculateReverts(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 686987, ~: 644137) -OrderBookClearHandleIORevertTest:testClearOrderAliceNoHandleIORevert() (gas: 518091) -OrderBookClearHandleIORevertTest:testClearOrderBobNoHandleIORevert() (gas: 518092) -OrderBookClearHandleIORevertTest:testClearOrderBothNoHandleIORevert() (gas: 497418) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 558313) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 550256) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 550464) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO3() (gas: 558357) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO4() (gas: 566810) -OrderBookClearHandleIORevertTest:testClearOrderHandleIO5() (gas: 524408) -OrderBookClearOrderBadStackTest:testClearOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2367717, ~: 2393487) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2454362, ~: 2470602) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2462109, ~: 2478343) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOtherOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2388885, ~: 2414657) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2382458, ~: 2408230) -OrderBookClearOrderBadStackTest:testClearOrderBadStackOtherEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2381210, ~: 2406973) -OrderBookClearOrderContextTest:testContextEmptyStack(address,address,uint256,uint256,uint256,uint256) (runs: 34, μ: 2160140, ~: 2150067) +OrderBookClearHandleIORevertTest:testClearOrderAliceNoHandleIORevert() (gas: 517719) +OrderBookClearHandleIORevertTest:testClearOrderBobNoHandleIORevert() (gas: 517720) +OrderBookClearHandleIORevertTest:testClearOrderBothNoHandleIORevert() (gas: 497046) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO0() (gas: 557941) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO1() (gas: 549884) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO2() (gas: 550092) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO3() (gas: 557985) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO4() (gas: 566438) +OrderBookClearHandleIORevertTest:testClearOrderHandleIO5() (gas: 524036) +OrderBookClearOrderBadStackTest:testClearOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2367720, ~: 2393602) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2454275, ~: 2470804) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2462022, ~: 2478546) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneOtherOne(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2388888, ~: 2414772) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2382461, ~: 2408345) +OrderBookClearOrderBadStackTest:testClearOrderBadStackOtherEmpty(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2381213, ~: 2407088) +OrderBookClearOrderContextTest:testContextEmptyStack(address,address,uint256,uint256,uint256,uint256) (runs: 34, μ: 2162782, ~: 2164743) OrderBookClearSameTokenTest:testClearSameToken(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 1570894, ~: 1571631) -OrderBookClearTest:testClear2ZeroRatioAliceAndBob(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920430, ~: 4040987) -OrderBookClearTest:testClear2ZeroRatioAliceOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920546, ~: 4041103) -OrderBookClearTest:testClear2ZeroRatioBobOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920530, ~: 4041087) -OrderBookClearTest:testClearFuzzIoRatio(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3858509, ~: 3863881) -OrderBookClearTest:testClearFuzzIoRatioError(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3856937, ~: 3853167) -OrderBookClearTest:testClearSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3961384, ~: 4081938) +OrderBookClearTest:testClear2ZeroRatioAliceAndBob(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920244, ~: 4040801) +OrderBookClearTest:testClear2ZeroRatioAliceOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920360, ~: 4040917) +OrderBookClearTest:testClear2ZeroRatioBobOnly(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3920344, ~: 4040901) +OrderBookClearTest:testClearFuzzIoRatio(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3858134, ~: 3863695) +OrderBookClearTest:testClearFuzzIoRatioError(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256,uint256,uint256) (runs: 123, μ: 3856745, ~: 3852981) +OrderBookClearTest:testClearSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,address,uint256,uint256) (runs: 123, μ: 3961198, ~: 4081752) OrderBookClearTest:testFlashLoanToNonReceiver(uint256,bytes,bytes32,bytes) (runs: 5120, μ: 28247, ~: 28145) OrderBookDepositEnactTest:testDepositRevertInAction(address,uint256,uint256) (runs: 34, μ: 97295, ~: 97295) OrderBookDepositEnactTest:testOrderBookDepositEnactEmptyNoop(address,uint256,uint256) (runs: 34, μ: 41751, ~: 41751) OrderBookDepositEnactTest:testOrderBookDepositEnactOneReadState(address,uint256,uint256) (runs: 34, μ: 104020, ~: 104020) OrderBookDepositEnactTest:testOrderBookDepositEnactOneStateless(address,uint256,uint256) (runs: 34, μ: 89382, ~: 89382) -OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256) (runs: 34, μ: 959717, ~: 959588) -OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSequential(address,uint256,uint256) (runs: 34, μ: 594234, ~: 594113) -OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSingle(address,uint256,uint256) (runs: 34, μ: 212841, ~: 212720) -OrderBookDepositEnactTest:testOrderDepositContext(address,uint256,uint256,uint256) (runs: 34, μ: 640956, ~: 632645) +OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256) (runs: 34, μ: 959677, ~: 959588) +OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSequential(address,uint256,uint256) (runs: 34, μ: 594214, ~: 594113) +OrderBookDepositEnactTest:testOrderBookDepositEvalWriteStateSingle(address,uint256,uint256) (runs: 34, μ: 212821, ~: 212720) +OrderBookDepositEnactTest:testOrderDepositContext(address,uint256,uint256,uint256) (runs: 34, μ: 639026, ~: 630019) OrderBookDepositTest:testDepositEvent(address,uint256,uint256) (runs: 124, μ: 39527, ~: 39527) -OrderBookDepositTest:testDepositFail(address,uint256,uint256) (runs: 124, μ: 1040441653, ~: 1040441629) +OrderBookDepositTest:testDepositFail(address,uint256,uint256) (runs: 124, μ: 1040441656, ~: 1040441629) OrderBookDepositTest:testDepositGas00() (gas: 8940) OrderBookDepositTest:testDepositGas01() (gas: 35406) -OrderBookDepositTest:testDepositMany((address,address,uint256,uint248)[]) (runs: 107, μ: 2307629, ~: 1479224) -OrderBookDepositTest:testDepositOverflow(address,uint256,uint256,uint256) (runs: 123, μ: 53308, ~: 53654) -OrderBookDepositTest:testDepositReentrancy(address,uint256,uint256,address,uint256,uint256) (runs: 124, μ: 623795, ~: 624277) +OrderBookDepositTest:testDepositMany((address,address,uint256,uint248)[]) (runs: 105, μ: 2295057, ~: 1431474) +OrderBookDepositTest:testDepositOverflow(address,uint256,uint256,uint256) (runs: 123, μ: 53324, ~: 53654) +OrderBookDepositTest:testDepositReentrancy(address,uint256,uint256,address,uint256,uint256) (runs: 124, μ: 623635, ~: 624277) OrderBookDepositTest:testDepositSimple(address,uint256,uint256) (runs: 124, μ: 38760, ~: 38760) OrderBookDepositTest:testDepositZero(address,uint256) (runs: 124, μ: 13201, ~: 13201) OrderBookDepositTest:testVaultBalanceNoDeposits(address,uint256) (runs: 5120, μ: 8947, ~: 8947) @@ -85,19 +85,19 @@ OrderBookEnactTest:testOrderBookEvalWriteStateDifferentOwnersNamespaced(address, OrderBookEnactTest:testOrderBookEvalWriteStateSequential() (gas: 543024) OrderBookEnactTest:testOrderBookEvalWriteStateSingle(address) (runs: 124, μ: 170894, ~: 170894) OrderBookQuoteSameTokenTest:testQuoteSameToken(((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)[])) (runs: 34, μ: 7316072, ~: 7067047) -OrderBookQuoteTest:testQuoteContextSender(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 10907376, ~: 10885914) +OrderBookQuoteTest:testQuoteContextSender(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 10906401, ~: 10884984) OrderBookQuoteTest:testQuoteDeadOrder(((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)[])) (runs: 124, μ: 6489058, ~: 5413815) -OrderBookQuoteTest:testQuoteMaxOutput(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 1189229, ~: 1188117) -OrderBookQuoteTest:testQuoteSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 1182510, ~: 1181115) -OrderBookRemoveOrderEnactTest:testRemoveOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 687553, ~: 659404) -OrderBookRemoveOrderEnactTest:testRemoveOrderDeadOrder(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 380949, ~: 357984) -OrderBookRemoveOrderEnactTest:testRemoveOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1163199, ~: 1085367) -OrderBookRemoveOrderEnactTest:testRemoveOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1224311, ~: 1146461) -OrderBookRemoveOrderEnactTest:testRemoveOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1209667, ~: 1131817) -OrderBookRemoveOrderEnactTest:testRemoveOrderRevertInAction(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1356568, ~: 1270473) +OrderBookQuoteTest:testQuoteMaxOutput(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 1189125, ~: 1188024) +OrderBookQuoteTest:testQuoteSimple(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),uint256) (runs: 124, μ: 1182417, ~: 1181022) +OrderBookRemoveOrderEnactTest:testRemoveOrderContext(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 687566, ~: 659378) +OrderBookRemoveOrderEnactTest:testRemoveOrderDeadOrder(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 380947, ~: 357984) +OrderBookRemoveOrderEnactTest:testRemoveOrderEmptyNoop(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1163197, ~: 1085367) +OrderBookRemoveOrderEnactTest:testRemoveOrderOneReadState(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1224309, ~: 1146461) +OrderBookRemoveOrderEnactTest:testRemoveOrderOneStateless(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1209665, ~: 1131817) +OrderBookRemoveOrderEnactTest:testRemoveOrderRevertInAction(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1356567, ~: 1270473) OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateDifferentOwnersNamespaced(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 4976864, ~: 4872948) -OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1459549, ~: 1381630) -OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2366456, ~: 2218703) +OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSequential(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 1459547, ~: 1381630) +OrderBookRemoveOrderEnactTest:testRemoveOrderWriteStateSingle(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 2366455, ~: 2218703) OrderBookRemoveOrderMockTest:testRemoveOrderAddRemoveMulti(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 7390386, ~: 6778974) OrderBookRemoveOrderMockTest:testRemoveOrderDifferent(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 4963217, ~: 4909064) OrderBookRemoveOrderMockTest:testRemoveOrderDifferentOwners(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),bytes) (runs: 124, μ: 4798479, ~: 4800278) @@ -176,38 +176,38 @@ OrderBookSubParserSignersTest:testSubParserContextSignerHappy1() (gas: 2103255) OrderBookSubParserSignersTest:testSubParserContextSignerUnhappyInput() (gas: 2081027) OrderBookSubParserSignersTest:testSubParserContextSignerUnhappyNoOperand() (gas: 2060334) OrderBookSubParserSignersTest:testSubParserContextSignerUnhappyTooManyOperands() (gas: 2066585) -OrderBookTakeOrderBadStackTest:testTakeOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 966841, ~: 943156) -OrderBookTakeOrderBadStackTest:testTakeOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 974157, ~: 950469) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO0() (gas: 241092) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO1() (gas: 405265) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO10(uint256) (runs: 124, μ: 644122, ~: 608769) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO2() (gas: 418991) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO3() (gas: 563700) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO4() (gas: 583211) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO5() (gas: 583210) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO6() (gas: 569415) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO7(uint256) (runs: 124, μ: 828023, ~: 828324) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO8(uint256) (runs: 124, μ: 986818, ~: 987119) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO9(uint256) (runs: 124, μ: 725368, ~: 663874) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert0() (gas: 233005) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert1() (gas: 391201) -OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert2() (gas: 377476) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrders(uint256,uint256) (runs: 124, μ: 412695, ~: 425042) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrdersMultipleOwners(uint256,uint256,uint256) (runs: 124, μ: 471460, ~: 483089) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleAnyDeposit(uint256,uint256) (runs: 124, μ: 261154, ~: 261943) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumInput(uint256,uint256) (runs: 124, μ: 242385, ~: 243577) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumOutput(uint256) (runs: 124, μ: 241941, ~: 241905) -OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderUnlimitedMax(uint256) (runs: 124, μ: 238888, ~: 238709) +OrderBookTakeOrderBadStackTest:testTakeOrderBadStackEmptyStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 966848, ~: 943156) +OrderBookTakeOrderBadStackTest:testTakeOrderBadStackOneStack(address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 974164, ~: 950469) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO0() (gas: 240999) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO1() (gas: 405079) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO10(uint256) (runs: 124, μ: 644196, ~: 608676) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO2() (gas: 418805) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO3() (gas: 563421) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO4() (gas: 582932) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO5() (gas: 582931) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO6() (gas: 569136) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO7(uint256) (runs: 124, μ: 827618, ~: 827754) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO8(uint256) (runs: 124, μ: 986320, ~: 986456) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderHandleIO9(uint256) (runs: 124, μ: 733459, ~: 663781) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert0() (gas: 232912) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert1() (gas: 391015) +OrderBookTakeOrderHandleIORevertTest:testTakeOrderNoHandleIORevert2() (gas: 377290) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrders(uint256,uint256) (runs: 124, μ: 412947, ~: 424856) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputMultipleOrdersMultipleOwners(uint256,uint256,uint256) (runs: 124, μ: 470231, ~: 482903) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleAnyDeposit(uint256,uint256) (runs: 124, μ: 261061, ~: 261850) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumInput(uint256,uint256) (runs: 124, μ: 243504, ~: 243484) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderLessThanMaximumOutput(uint256) (runs: 124, μ: 241854, ~: 241812) +OrderBookTakeOrderMaximumInputTest:testTakeOrderMaximumInputSingleOrderUnlimitedMax(uint256) (runs: 124, μ: 238801, ~: 238616) OrderBookTakeOrderMaximumInputTest:testTakeOrderNoopZeroMaxTakerInput((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,uint256[],bytes)) (runs: 124, μ: 179434, ~: 177315) -OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderOne((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)) (runs: 124, μ: 433736, ~: 412791) -OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderTwo((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256,(address,uint256[],bytes),(address,uint256[],bytes)) (runs: 124, μ: 846774, ~: 827948) +OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderOne((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,uint256[],bytes)) (runs: 124, μ: 433730, ~: 412866) +OrderBookTakeOrderNoopTest:testTakeOrderNoopNonLiveOrderTwo((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256,(address,uint256[],bytes),(address,uint256[],bytes)) (runs: 124, μ: 847102, ~: 827948) OrderBookTakeOrderNoopTest:testTakeOrderNoopZeroOrders() (gas: 12427) -OrderBookTakeOrderPrecisionTest:testTakeOrderPrecisionKnownBad01() (gas: 2224106) +OrderBookTakeOrderPrecisionTest:testTakeOrderPrecisionKnownBad01() (gas: 2223083) OrderBookTakeOrderSameTokenTest:testTakeOrderSameToken(address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 34, μ: 804111, ~: 760276) -OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenDecimalsMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 33, μ: 677650, ~: 686132) -OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 33, μ: 667067, ~: 664356) -OrderBookTakeOrderTokenMismatchTest:testTokenDecimalMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 34, μ: 669331, ~: 694240) -OrderBookTakeOrderTokenMismatchTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 34, μ: 668077, ~: 692986) +OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenDecimalsMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 34, μ: 669456, ~: 675872) +OrderBookTakeOrderTokenMismatchDecimalsTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256) (runs: 33, μ: 669323, ~: 684876) +OrderBookTakeOrderTokenMismatchTest:testTokenDecimalMismatchOutputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 34, μ: 658715, ~: 694240) +OrderBookTakeOrderTokenMismatchTest:testTokenMismatchInputs((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256,uint256) (runs: 34, μ: 668073, ~: 692986) OrderBookV4ArbOrderTakerContextTest:testOrderBookV4ArbOrderTakerContext() (gas: 2602528) OrderBookV4ArbOrderTakerIERC165Test:testOrderBookV4ArbOrderTakerIERC165(bytes4) (runs: 5119, μ: 2374572, ~: 2374572) OrderBookV4FlashBorrowerIERC165Test:testOrderBookV4FlashBorrowerIERC165(bytes4) (runs: 5120, μ: 2786827, ~: 2786827) @@ -215,30 +215,30 @@ OrderBookV4FlashLenderFeeTest:testFlashFee(address,uint256) (runs: 5120, μ: 653 OrderBookV4FlashLenderIERC165Test:testOrderBookV4FlashLenderIERC165(bytes4) (runs: 5120, μ: 580452, ~: 580452) OrderBookV4FlashLenderMaxFlashLoanTest:testFlashMaxLoan(uint256) (runs: 5120, μ: 7981, ~: 7981) OrderBookV4FlashLenderMockSuccessTest:testFlashLoanToReceiver(uint256,bytes) (runs: 5120, μ: 14786, ~: 14732) -OrderBookV4FlashLenderReentrant:testReenterAddOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 18438356, ~: 18737951) +OrderBookV4FlashLenderReentrant:testReenterAddOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 18429209, ~: 18737951) OrderBookV4FlashLenderReentrant:testReenterCheckOrderExists(bytes32,uint256) (runs: 124, μ: 553900, ~: 553900) -OrderBookV4FlashLenderReentrant:testReenterClear(uint256,address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 37927832, ~: 37278193) -OrderBookV4FlashLenderReentrant:testReenterDeposit(uint256,uint256,uint256) (runs: 124, μ: 655278, ~: 655599) -OrderBookV4FlashLenderReentrant:testReenterReadVaultBalances(uint256,uint256) (runs: 124, μ: 598866, ~: 599187) -OrderBookV4FlashLenderReentrant:testReenterRemoveOrder(uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 124, μ: 18140249, ~: 17634324) -OrderBookV4FlashLenderReentrant:testReenterTakeOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 19061600, ~: 19326380) -OrderBookV4FlashLenderReentrant:testReenterWithdraw(uint256,uint256,uint256) (runs: 124, μ: 631745, ~: 632066) -OrderBookV4FlashLenderTransferTest:testFlashLoanTransferFail(uint256,uint256,bool) (runs: 124, μ: 1345626, ~: 1347531) +OrderBookV4FlashLenderReentrant:testReenterClear(uint256,address,address,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes),((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 37910299, ~: 37217229) +OrderBookV4FlashLenderReentrant:testReenterDeposit(uint256,uint256,uint256) (runs: 124, μ: 654475, ~: 655599) +OrderBookV4FlashLenderReentrant:testReenterReadVaultBalances(uint256,uint256) (runs: 124, μ: 599026, ~: 599187) +OrderBookV4FlashLenderReentrant:testReenterRemoveOrder(uint256,(address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32)) (runs: 124, μ: 18132064, ~: 17587711) +OrderBookV4FlashLenderReentrant:testReenterTakeOrder(uint256,((address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32,bytes32,bytes)) (runs: 124, μ: 19052515, ~: 19326287) +OrderBookV4FlashLenderReentrant:testReenterWithdraw(uint256,uint256,uint256) (runs: 124, μ: 630942, ~: 632066) +OrderBookV4FlashLenderTransferTest:testFlashLoanTransferFail(uint256,uint256,bool) (runs: 124, μ: 1345637, ~: 1347531) OrderBookV4FlashLenderTransferTest:testFlashLoanTransferSuccess(uint256,bool) (runs: 124, μ: 1291779, ~: 1297531) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalEmptyNoop(address,uint256,uint256,uint256) (runs: 124, μ: 53297, ~: 54109) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneReadState(address,uint256,uint256,uint256) (runs: 124, μ: 115200, ~: 116671) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneStateless(address,uint256,uint256,uint256) (runs: 124, μ: 100583, ~: 102054) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256,uint256) (runs: 124, μ: 993387, ~: 994386) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSequential(address,uint256,uint256,uint256) (runs: 124, μ: 611190, ~: 612659) -OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSingle(address,uint256,uint256,uint256) (runs: 124, μ: 228944, ~: 230413) -OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalRevertInAction(address,uint256,uint256,uint256) (runs: 124, μ: 108187, ~: 109658) -OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalZeroAmountEvalNoop(address,uint256,uint256) (runs: 124, μ: 60969, ~: 60768) -OrderBookWithdrawEvalTest:testOrderWithdrawContext(address,uint256,uint256,uint256) (runs: 124, μ: 723413, ~: 721505) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalEmptyNoop(address,uint256,uint256,uint256) (runs: 124, μ: 53303, ~: 54109) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneReadState(address,uint256,uint256,uint256) (runs: 124, μ: 115206, ~: 116671) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalOneStateless(address,uint256,uint256,uint256) (runs: 124, μ: 100589, ~: 102054) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateDifferentOwnersNamespaced(address,address,uint256,uint256,uint256) (runs: 124, μ: 993337, ~: 994386) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSequential(address,uint256,uint256,uint256) (runs: 124, μ: 611196, ~: 612659) +OrderBookWithdrawEvalTest:testOrderBookWithdrawEvalWriteStateSingle(address,uint256,uint256,uint256) (runs: 124, μ: 228950, ~: 230413) +OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalRevertInAction(address,uint256,uint256,uint256) (runs: 124, μ: 108192, ~: 109658) +OrderBookWithdrawEvalTest:testOrderBookWithdrawalEvalZeroAmountEvalNoop(address,uint256,uint256) (runs: 124, μ: 60997, ~: 60768) +OrderBookWithdrawEvalTest:testOrderWithdrawContext(address,uint256,uint256,uint256) (runs: 124, μ: 722980, ~: 721418) OrderBookWithdrawTest:testWithdrawEmptyVault(address,address,uint256,uint256) (runs: 123, μ: 17802, ~: 17802) -OrderBookWithdrawTest:testWithdrawFailure(address,uint256,uint256,uint256) (runs: 124, μ: 1040418749, ~: 1040437709) -OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (runs: 115, μ: 40852, ~: 40831) -OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) (runs: 124, μ: 3260899, ~: 3383353) -OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 109, μ: 51385, ~: 51385) +OrderBookWithdrawTest:testWithdrawFailure(address,uint256,uint256,uint256) (runs: 124, μ: 1040419072, ~: 1040437714) +OrderBookWithdrawTest:testWithdrawFullVault(address,uint256,uint256,uint256) (runs: 112, μ: 40849, ~: 40829) +OrderBookWithdrawTest:testWithdrawMany((bool,address,address,uint256,uint248)[]) (runs: 124, μ: 3260897, ~: 3383353) +OrderBookWithdrawTest:testWithdrawPartialVault(address,uint256,uint256,uint256) (runs: 112, μ: 51385, ~: 51385) OrderBookWithdrawTest:testWithdrawZero(address,address,uint256) (runs: 124, μ: 13382, ~: 13382) RouteProcessorOrderBookV4ArbOrderTakerExpressionTest:testRouteProcessorTakeOrdersExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,uint256[],uint256[]) (runs: 124, μ: 366920, ~: 361105) RouteProcessorOrderBookV4ArbOrderTakerExpressionTest:testRouteProcessorTakeOrdersWrongExpression((address,(address,address,bytes),(address,uint8,uint256)[],(address,uint8,uint256)[],bytes32),uint256,uint256,(address,address,bytes)) (runs: 124, μ: 167756, ~: 157267) diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index af713aba8..337c93503 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -786,14 +786,18 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order new uint256[](0) ); - // This is redundant with the array index checks implied by solidity - // but it's a much clearer error message. + // This is a much error message and overall more efficient than + // solidity generic index out of bounds errors. if (calculateOrderStack.length < CALCULATE_ORDER_MIN_OUTPUTS) { revert UnsupportedCalculateOutputs(calculateOrderStack.length); } - Output18Amount orderOutputMax18 = Output18Amount.wrap(calculateOrderStack[1]); - uint256 orderIORatio = calculateOrderStack[0]; + uint256 orderIORatio; + Output18Amount orderOutputMax18; + assembly ("memory-safe") { + orderIORatio := mload(add(calculateOrderStack, 0x20)) + orderOutputMax18 := mload(add(calculateOrderStack, 0x40)) + } { // The order owner can't send more than the smaller of their vault From bbd057f5eb0356f6c8a4de738971eefb26c74743 Mon Sep 17 00:00:00 2001 From: nino Date: Fri, 27 Dec 2024 11:18:14 +0400 Subject: [PATCH 24/28] Add test for imputToken to check it renders with correct initial value --- .../src/__tests__/InputToken.test.ts | 16 ++++++++++++++++ .../src/lib/components/input/InputToken.svelte | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 packages/ui-components/src/__tests__/InputToken.test.ts diff --git a/packages/ui-components/src/__tests__/InputToken.test.ts b/packages/ui-components/src/__tests__/InputToken.test.ts new file mode 100644 index 000000000..2840a4064 --- /dev/null +++ b/packages/ui-components/src/__tests__/InputToken.test.ts @@ -0,0 +1,16 @@ +import { render } from '@testing-library/svelte'; +import InputToken from '../lib/components/input/InputToken.svelte'; + + +describe('InputToken', () => { + it('renders with initial values', () => { + const address = '0xc0D477556c25C9d67E1f57245C7453DA776B51cf'; + const decimals = 10; + const { getByTestId } = render(InputToken, { props: { address, decimals } }); + + const input = getByTestId('token-address-input').querySelector('input'); + expect(input?.value).toBe('0xc0D477556c25C9d67E1f57245C7453DA776B51cf'); + const decimalsInput = getByTestId('token-decimals-input').querySelector('input'); + expect(decimalsInput?.value).toBe('10'); + }); +}); diff --git a/packages/ui-components/src/lib/components/input/InputToken.svelte b/packages/ui-components/src/lib/components/input/InputToken.svelte index fe16865e4..c661b3db8 100644 --- a/packages/ui-components/src/lib/components/input/InputToken.svelte +++ b/packages/ui-components/src/lib/components/input/InputToken.svelte @@ -37,7 +37,7 @@
-
+
@@ -47,7 +47,7 @@ Token Address
-
+
Date: Fri, 27 Dec 2024 11:46:33 +0400 Subject: [PATCH 25/28] Add test for imputToken to check invalid address --- .../src/__tests__/InputToken.test.ts | 15 +++++++++++++-- .../src/lib/components/input/InputToken.svelte | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/ui-components/src/__tests__/InputToken.test.ts b/packages/ui-components/src/__tests__/InputToken.test.ts index 2840a4064..5c1eaf500 100644 --- a/packages/ui-components/src/__tests__/InputToken.test.ts +++ b/packages/ui-components/src/__tests__/InputToken.test.ts @@ -1,4 +1,4 @@ -import { render } from '@testing-library/svelte'; +import { render, fireEvent } from '@testing-library/svelte'; import InputToken from '../lib/components/input/InputToken.svelte'; @@ -8,9 +8,20 @@ describe('InputToken', () => { const decimals = 10; const { getByTestId } = render(InputToken, { props: { address, decimals } }); - const input = getByTestId('token-address-input').querySelector('input'); + const input = getByTestId('token-address').querySelector('input'); expect(input?.value).toBe('0xc0D477556c25C9d67E1f57245C7453DA776B51cf'); const decimalsInput = getByTestId('token-decimals-input').querySelector('input'); expect(decimalsInput?.value).toBe('10'); }); + + it('shows error for invalid address', async () => { + const address = 'abc'; + const decimals = 0; + const { getByTestId, getByText } = render(InputToken, { props: { address, decimals } }); + + const addressInput = getByTestId('token-address').querySelector('input') as HTMLInputElement; + await fireEvent.input(addressInput, { target: { value: 'invalidAddress' } }); + + expect(getByText('Invalid Address')).toBeInTheDocument(); + }); }); diff --git a/packages/ui-components/src/lib/components/input/InputToken.svelte b/packages/ui-components/src/lib/components/input/InputToken.svelte index c661b3db8..935674c55 100644 --- a/packages/ui-components/src/lib/components/input/InputToken.svelte +++ b/packages/ui-components/src/lib/components/input/InputToken.svelte @@ -36,8 +36,8 @@
-
-
+
+
From 56b032071ba748af573ba5d1526d1799269636e8 Mon Sep 17 00:00:00 2001 From: nino Date: Fri, 27 Dec 2024 11:48:38 +0400 Subject: [PATCH 26/28] Add test for imputToken to check does not show error for valid address --- .../ui-components/src/__tests__/InputToken.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/ui-components/src/__tests__/InputToken.test.ts b/packages/ui-components/src/__tests__/InputToken.test.ts index 5c1eaf500..1371eaa87 100644 --- a/packages/ui-components/src/__tests__/InputToken.test.ts +++ b/packages/ui-components/src/__tests__/InputToken.test.ts @@ -24,4 +24,15 @@ describe('InputToken', () => { expect(getByText('Invalid Address')).toBeInTheDocument(); }); + + it('does not show error for valid address', async () => { + const address = ''; + const decimals = 0; + const { getByTestId, queryByText } = render(InputToken, { props: { address, decimals } }); + + const addressInput = getByTestId('token-address').querySelector('input') as HTMLInputElement; + await fireEvent.input(addressInput, { target: { value: '0xc0D477556c25C9d67E1f57245C7453DA776B51cf' } }); + + expect(queryByText('Invalid Address')).toBeNull(); + }); }); From 24d7a5a8f2844a0bd12964103a40fb828daad7b6 Mon Sep 17 00:00:00 2001 From: nino Date: Fri, 27 Dec 2024 12:45:35 +0400 Subject: [PATCH 27/28] Format --- packages/ui-components/src/__tests__/InputToken.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/ui-components/src/__tests__/InputToken.test.ts b/packages/ui-components/src/__tests__/InputToken.test.ts index 1371eaa87..c1e808027 100644 --- a/packages/ui-components/src/__tests__/InputToken.test.ts +++ b/packages/ui-components/src/__tests__/InputToken.test.ts @@ -1,7 +1,6 @@ import { render, fireEvent } from '@testing-library/svelte'; import InputToken from '../lib/components/input/InputToken.svelte'; - describe('InputToken', () => { it('renders with initial values', () => { const address = '0xc0D477556c25C9d67E1f57245C7453DA776B51cf'; @@ -31,7 +30,9 @@ describe('InputToken', () => { const { getByTestId, queryByText } = render(InputToken, { props: { address, decimals } }); const addressInput = getByTestId('token-address').querySelector('input') as HTMLInputElement; - await fireEvent.input(addressInput, { target: { value: '0xc0D477556c25C9d67E1f57245C7453DA776B51cf' } }); + await fireEvent.input(addressInput, { + target: { value: '0xc0D477556c25C9d67E1f57245C7453DA776B51cf' } + }); expect(queryByText('Invalid Address')).toBeNull(); }); From 565f3b9d59dfbced0598374d3e0efc520f7ed41d Mon Sep 17 00:00:00 2001 From: thedavidmeister Date: Sat, 28 Dec 2024 16:21:47 +0400 Subject: [PATCH 28/28] lint --- src/concrete/ob/OrderBook.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/concrete/ob/OrderBook.sol b/src/concrete/ob/OrderBook.sol index 337c93503..44baa77a1 100644 --- a/src/concrete/ob/OrderBook.sol +++ b/src/concrete/ob/OrderBook.sol @@ -786,8 +786,8 @@ contract OrderBook is IOrderBookV4, IMetaV1_2, ReentrancyGuard, Multicall, Order new uint256[](0) ); - // This is a much error message and overall more efficient than - // solidity generic index out of bounds errors. + // This is a much clearer error message and overall is more efficient + // than solidity generic index out of bounds errors. if (calculateOrderStack.length < CALCULATE_ORDER_MIN_OUTPUTS) { revert UnsupportedCalculateOutputs(calculateOrderStack.length); }