Skip to content

Commit

Permalink
chore: cleaning simulator
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed Apr 22, 2024
1 parent a69abb6 commit 53d5e17
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tests/unitary/math/test_newton_D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/math/test_newton_D_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/pool/stateful/test_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 13 additions & 18 deletions tests/utils/simulation_int_many.py → tests/utils/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 53d5e17

Please sign in to comment.