Skip to content

Commit

Permalink
Add cryptoswap D_to_balances
Browse files Browse the repository at this point in the history
  • Loading branch information
nagakingg committed Jul 10, 2023
1 parent aa3e4cd commit abe030c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions curvesim/iterators/param_samplers/pool_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CurvePoolMixin:
"""

@property
def attribute_setters(self):
def setters(self):
return {"D": stableswap_D_to_balances}


Expand All @@ -16,7 +16,7 @@ class CurveMetaPoolMixin:
"""

@property
def attribute_setters(self):
def setters(self):
return {"D": stableswap_D_to_balances}


Expand All @@ -27,11 +27,27 @@ class CurveCryptoPoolMixin:
"""

@property
def attribute_setters(self):
return {}
def setters(self):
return {"D": cryptoswap_D_to_balances}


def stableswap_D_to_balances(pool, D):
rates = pool.rates[:]
rates = pool.rates
n = pool.n
pool.balances = [D // n * 10**18 // p for p in rates]
pool.balances = [D // n * 10**18 // r for r in rates]


def cryptoswap_D_to_balances(pool, D):
n = pool.n
price_scale = pool.price_scale
precisions = pool.precisions

if n==2:
price_scale = [price_scale]

balances = [D // n // precisions[0]]
divisors = zip(price_scale, precisions[1:])
balances += [D * 10**18 // (n * price) // prec for price, prec in divisors]

pool.balances = balances

0 comments on commit abe030c

Please sign in to comment.