From 53d5e17bb44698752d065b61ce3f101c562d81e8 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 22 Apr 2024 13:38:59 +0200 Subject: [PATCH] chore: cleaning simulator --- tests/unitary/math/test_newton_D.py | 2 +- tests/unitary/math/test_newton_D_ref.py | 2 +- tests/unitary/pool/stateful/test_simulate.py | 2 +- .../{simulation_int_many.py => simulator.py} | 31 ++++++++----------- 4 files changed, 16 insertions(+), 21 deletions(-) rename tests/utils/{simulation_int_many.py => simulator.py} (94%) diff --git a/tests/unitary/math/test_newton_D.py b/tests/unitary/math/test_newton_D.py index bea276b1..f01f80e8 100644 --- a/tests/unitary/math/test_newton_D.py +++ b/tests/unitary/math/test_newton_D.py @@ -7,7 +7,7 @@ from hypothesis import given, settings from hypothesis import strategies as st -import tests.utils.simulation_int_many as sim +import tests.utils.simulator as sim # Uncomment to be able to print when parallelized # sys.stdout = sys.stderr diff --git a/tests/unitary/math/test_newton_D_ref.py b/tests/unitary/math/test_newton_D_ref.py index 5a5fb55f..c9b1e765 100644 --- a/tests/unitary/math/test_newton_D_ref.py +++ b/tests/unitary/math/test_newton_D_ref.py @@ -7,7 +7,7 @@ from hypothesis import given, settings from hypothesis import strategies as st -import tests.utils.simulation_int_many as sim +import tests.utils.simulator as sim # sys.stdout = sys.stderr diff --git a/tests/unitary/pool/stateful/test_simulate.py b/tests/unitary/pool/stateful/test_simulate.py index a2021657..fca41746 100644 --- a/tests/unitary/pool/stateful/test_simulate.py +++ b/tests/unitary/pool/stateful/test_simulate.py @@ -4,7 +4,7 @@ from tests.unitary.pool.stateful.stateful_base import StatefulBase from tests.utils import approx -from tests.utils import simulation_int_many as sim +from tests.utils import simulator as sim from tests.utils.tokens import mint_for_testing MAX_SAMPLES = 20 diff --git a/tests/utils/simulation_int_many.py b/tests/utils/simulator.py similarity index 94% rename from tests/utils/simulation_int_many.py rename to tests/utils/simulator.py index 36141857..98cd8cd5 100644 --- a/tests/utils/simulation_int_many.py +++ b/tests/utils/simulator.py @@ -181,6 +181,13 @@ def newton_y(A, gamma, x, D, i): def solve_x(A, gamma, x, D, i): + """ + Solving for x or y in the AMM equation. + + Even though we have an analytical solution we consider + the newton method to be a ground truth. The analytical + solution does not always work. + """ return newton_y(A, gamma, x, D, i) @@ -241,38 +248,26 @@ def __init__( A, gamma, D, - n, p0, mid_fee=1e-3, out_fee=3e-3, - allowed_extra_profit=2 * 10**13, fee_gamma=None, adjustment_step=0.003, ma_time=866, - log=True, ): - # allowed_extra_profit is actually not used - self.p0 = p0[:] - self.price_oracle = self.p0[:] - self.last_price = self.p0[:] + self.price_oracle = p0[:] + self.last_price = p0[:] self.curve = Curve(A, gamma, D, p=p0[:]) - self.dx = int(D * 1e-8) self.mid_fee = int(mid_fee * 1e10) self.out_fee = int(out_fee * 1e10) - self.D0 = self.curve.D() - self.xcp_0 = self.get_xcp() self.xcp_profit = 10**18 self.xcp_profit_real = 10**18 - self.xcp = self.xcp_0 - self.allowed_extra_profit = allowed_extra_profit + self.xcp = self.get_xcp() self.adjustment_step = int(10**18 * adjustment_step) - self.log = log - self.fee_gamma = fee_gamma or gamma - self.total_vol = 0.0 + self.fee_gamma = ( + fee_gamma or gamma + ) # why can gamma be used as fee_gamma? self.ma_time = ma_time - self.ext_fee = 0 # 0.03e-2 - self.slippage = 0 - self.slippage_count = 0 def fee(self): f = reduction_coefficient(self.curve.xp(), self.fee_gamma)