-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
520b84d
commit 12c82f7
Showing
3 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import pytest | ||
import boa | ||
|
||
from tests.unitary.utils import GodModePool | ||
|
||
factory_deployer = boa.load_partial("contracts/main/TwocryptoFactory.vy") | ||
s_amm_deployer = boa.load_partial("contracts/stableswap_invariant/TwocryptoStableswap.vy") | ||
s_math_deployer = boa.load_partial("contracts/stableswap_invariant/TwocryptoStableswapMath.vy") | ||
|
||
|
||
@pytest.fixture | ||
def factory(): | ||
_deployer = boa.env.generate_address() | ||
_fee_receiver = boa.env.generate_address() | ||
_owner = boa.env.generate_address() | ||
|
||
# assume(_fee_receiver != _owner != _deployer) | ||
|
||
with boa.env.prank(_deployer): | ||
amm_implementation = s_amm_deployer.deploy_as_blueprint() | ||
# gauge_implementation = gauge_deployer.deploy_as_blueprint() | ||
|
||
# view_contract = view_deployer.deploy() | ||
math_contract = s_math_deployer.deploy() | ||
print(math_contract.address) | ||
|
||
_factory = factory_deployer.deploy() | ||
_factory.initialise_ownership(_fee_receiver, _owner) | ||
|
||
with boa.env.prank(_owner): | ||
_factory.set_pool_implementation(amm_implementation, 0) | ||
# _factory.set_gauge_implementation(gauge_implementation) | ||
# _factory.set_views_implementation(view_contract) | ||
_factory.set_math_implementation(math_contract) | ||
|
||
return _factory | ||
|
||
|
||
@pytest.fixture() | ||
def tokens(): | ||
tgen = boa.load_partial( | ||
"contracts/mocks/ERC20Mock.vy", | ||
) | ||
return [tgen("test", "test", 18), tgen("test", "test", 18)] | ||
|
||
|
||
@pytest.fixture | ||
def stable_pool( | ||
factory, | ||
params, | ||
tokens, | ||
): | ||
print(params) | ||
print(tokens) | ||
"""Creates a factory based pool with the following fuzzed parameters: | ||
Custom strategies can be passed as argument to override the default | ||
""" | ||
|
||
pool = factory.deploy_pool( | ||
"stateful simulation", | ||
"SIMULATION", | ||
tokens, | ||
0, | ||
params["A"], | ||
params["gamma"], | ||
params["mid_fee"], | ||
params["out_fee"], | ||
params["fee_gamma"], | ||
params["allowed_extra_profit"], | ||
params["adjustment_step"], | ||
params["ma_time"], | ||
params["initial_prices"][ | ||
1 | ||
], # TODO careful started on diff prices even tho stableswap invariant is used | ||
) | ||
|
||
pool = s_amm_deployer.at(pool) | ||
|
||
return GodModePool(pool, tokens) | ||
|
||
|
||
def test_simple(stable_pool): | ||
amounts = [10**18, 10**18] | ||
|
||
stable_pool.add_liquidity(amounts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import boa | ||
|
||
from tests.utils.tokens import mint_for_testing | ||
|
||
god = boa.env.generate_address() | ||
|
||
|
||
class GodModePool: | ||
def __init__(self, instance, coins): | ||
self.instance = instance | ||
self.coins = coins | ||
self.plotting = {} | ||
for c in self.coins: | ||
c.approve(self.instance, 2**256 - 1, sender=god) | ||
|
||
def __getattr__(self, name): | ||
return getattr(self.instance, name) | ||
|
||
def donate(self, amounts, update_ema=False): | ||
self.__premint_amounts(amounts) | ||
|
||
self.instance.donate(amounts, sender=god) | ||
|
||
if update_ema: | ||
self.__update_ema() | ||
|
||
def exchange(self, i, dx, update_ema=False): | ||
if i == 0: | ||
amounts = [dx, 0] | ||
else: | ||
amounts = [0, dx] | ||
self.__premint_amounts(amounts) | ||
|
||
self.instance.exchange(i, 1 - i, dx, 0, sender=god) | ||
|
||
if update_ema: | ||
self.__update_ema() | ||
|
||
def add_liquidity(self, amounts, update_ema=False): | ||
self.__premint_amounts(amounts) | ||
|
||
self.instance.add_liquidity(amounts, 0, sender=god) | ||
|
||
if update_ema: | ||
self.__update_ema() | ||
|
||
def __premint_amounts(self, amounts): | ||
for c, amount in zip(self.coins, amounts): | ||
mint_for_testing(c, god, amount) | ||
|
||
def __update_ema(self): | ||
boa.env.time_travel(seconds=86400 * 7) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters