From 378c1c27866d7a0f1b28acb58bee8626c5e2d685 Mon Sep 17 00:00:00 2001 From: kayibal Date: Wed, 23 Oct 2024 12:50:44 +0100 Subject: [PATCH 1/2] feat(testing): Test multiple amounts. --- testing/src/runner/runner.py | 54 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/testing/src/runner/runner.py b/testing/src/runner/runner.py index 12a15cf..adadf22 100644 --- a/testing/src/runner/runner.py +++ b/testing/src/runner/runner.py @@ -148,7 +148,8 @@ class TestRunner: comp_id = expected_component.id.lower() if comp_id not in components_by_id: return TestResult.Failed( - f"'{comp_id}' not found in protocol components." + f"'{comp_id}' not found in protocol components. " + f"Available components: {set(components_by_id.keys())}" ) diff = ProtocolComponentExpectation( @@ -265,32 +266,33 @@ class TestRunner: if not pool_state.balances: raise ValueError(f"Missing balances for pool {pool_id}") for sell_token, buy_token in itertools.permutations(pool_state.tokens, 2): - # Try to sell 0.1% of the protocol balance - sell_amount = Decimal("0.001") * pool_state.balances[sell_token.address] - try: - amount_out, gas_used, _ = pool_state.get_amount_out( - sell_token, sell_amount, buy_token - ) - print( - f"Amount out for {pool_id}: {sell_amount} {sell_token} -> {amount_out} {buy_token} - " - f"Gas used: {gas_used}" - ) - except Exception as e: - print( - f"Error simulating get_amount_out for {pool_id}: {sell_token} -> {buy_token}. " - f"Error: {e}" - ) - if pool_id not in failed_simulations: - failed_simulations[pool_id] = [] - failed_simulations[pool_id].append( - SimulationFailure( - pool_id=pool_id, - sell_token=str(sell_token), - buy_token=str(buy_token), - error=str(e), + for prctg in ["0.001", "0.01", "0.1"]: + # Try to sell 0.1% of the protocol balance + sell_amount = Decimal(prctg) * pool_state.balances[sell_token.address] + try: + amount_out, gas_used, _ = pool_state.get_amount_out( + sell_token, sell_amount, buy_token ) - ) - continue + print( + f"Amount out for {pool_id}: {sell_amount} {sell_token} -> {amount_out} {buy_token} - " + f"Gas used: {gas_used}" + ) + except Exception as e: + print( + f"Error simulating get_amount_out for {pool_id}: {sell_token} -> {buy_token} at block {block_number}. " + f"Error: {e}" + ) + if pool_id not in failed_simulations: + failed_simulations[pool_id] = [] + failed_simulations[pool_id].append( + SimulationFailure( + pool_id=pool_id, + sell_token=str(sell_token), + buy_token=str(buy_token), + error=str(e), + ) + ) + continue return failed_simulations @staticmethod From 3a93a55a46b0da9a9b9e161de22c599a5f87af3d Mon Sep 17 00:00:00 2001 From: kayibal Date: Wed, 23 Oct 2024 13:00:31 +0100 Subject: [PATCH 2/2] doc: fix formatting --- evm/src/interfaces/ISwapAdapter.sol | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/evm/src/interfaces/ISwapAdapter.sol b/evm/src/interfaces/ISwapAdapter.sol index a8fa405..5e1211c 100644 --- a/evm/src/interfaces/ISwapAdapter.sol +++ b/evm/src/interfaces/ISwapAdapter.sol @@ -74,9 +74,12 @@ interface ISwapAdapter is ISwapAdapterTypes { /// @param poolId The ID of the trading pool. /// @param sellToken The token being sold. /// @param buyToken The token being bought. - /// @return limits An array of size two indicating the limit amount for the sell - /// token (maximum the pool is willing to buy in sell token) as well as the limit - /// amount of the buy token (maximum the pool is willing to sell in buy token). + /// @return limits An array of size two indicating the limit amount for the + /// sell + /// token (maximum the pool is willing to buy in sell token) as well as + /// the limit + /// amount of the buy token (maximum the pool is willing to sell in buy + /// token). function getLimits(bytes32 poolId, address sellToken, address buyToken) external returns (uint256[] memory limits);