Skip to content

Commit

Permalink
pre-commit runs
Browse files Browse the repository at this point in the history
  • Loading branch information
heswithme committed Sep 25, 2024
1 parent 8beaf4b commit 9be0ba4
Show file tree
Hide file tree
Showing 42 changed files with 137 additions and 554 deletions.
5 changes: 1 addition & 4 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[flake8]
max-line-length =100
# codestyles - numpy, google, pep8
# formatter - black
# instead of flake and black use ruff - same written in rust
max-line-length = 120
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repos:
hooks:
- id: black
args:
- --line-length=120
- --skip-magic-trailing-comma
- --target-version=py310
- repo: https://github.com/PyCQA/flake8
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exclude = '''
)/
)
'''
line-length = 100
line-length = 120
target_version = ['py310']

[tool.isort]
Expand Down
20 changes: 5 additions & 15 deletions scripts/deploy_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ def set_contract_pragma(contract_file, network) -> boa.contracts.vyper.vyper_con

if is_shanghai_chain and "# pragma evm-version paris" in source:
logger.log("Replacing EVM version to Shanghai ...")
new_source = source.replace(
"# pragma evm-version paris\n", "# pragma evm-version shanghai\n"
)
new_source = source.replace("# pragma evm-version paris\n", "# pragma evm-version shanghai\n")
elif not is_shanghai_chain and "# pragma evm-version shanghai" in source:
logger.log("Replacing EVM version to Paris ...")
new_source = source.replace(
"# pragma evm-version shanghai\n", "# pragma evm-version paris\n"
)
new_source = source.replace("# pragma evm-version shanghai\n", "# pragma evm-version paris\n")
else: # all looks good ...
new_source = source

Expand Down Expand Up @@ -65,9 +61,7 @@ def check_and_deploy(contract_obj, contract_designation, network, blueprint: boo
contract = contract_obj.deploy(*args)
if args:
constructor_args = encode(["address", "address"], args)
logger.log(
f"Constructor arguments for {contract_designation}: {constructor_args.hex()}"
)
logger.log(f"Constructor arguments for {contract_designation}: {constructor_args.hex()}")
else:
if "zksync:mainnet" in network:
if "CurveStableSwapNG.vy" == contract_name:
Expand Down Expand Up @@ -114,9 +108,7 @@ def check_and_deploy(contract_obj, contract_designation, network, blueprint: boo

logger.log(f"Deployed! At: {contract.address}.")
else:
logger.log(
f"Deployed {contract_designation} contract exists. Using {deployed_contract} ..."
)
logger.log(f"Deployed {contract_designation} contract exists. Using {deployed_contract} ...")
contract = contract_obj.at(deployed_contract)

return contract
Expand Down Expand Up @@ -170,9 +162,7 @@ def deploy_infra(network, url, account, fork=False):
meta_blueprint = check_and_deploy(meta_contract_obj, "meta_amm", network, blueprint=True)

# Factory:
factory_contract_obj = set_contract_pragma(
"./contracts/main/CurveStableSwapFactoryNG.vy", network
)
factory_contract_obj = set_contract_pragma("./contracts/main/CurveStableSwapFactoryNG.vy", network)
args = [fee_receiver, deploy_utils.FIDDYDEPLOYER]
factory = check_and_deploy(factory_contract_obj, "factory", network, False, args)

Expand Down
8 changes: 2 additions & 6 deletions scripts/deploy_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,8 @@ def deploy_pool_and_gauge(network, url, account, pool_type, fork):

def main():
fork = False
deploy_pool_and_gauge(
"ethereum:mainnet", os.environ["RPC_ETHEREUM"], "FIDDYDEPLOYER", "plain", fork
)
deploy_pool_and_gauge(
"ethereum:mainnet", "http://localhost:9090/", "FIDDYDEPLOYER", "meta", fork
)
deploy_pool_and_gauge("ethereum:mainnet", os.environ["RPC_ETHEREUM"], "FIDDYDEPLOYER", "plain", fork)
deploy_pool_and_gauge("ethereum:mainnet", "http://localhost:9090/", "FIDDYDEPLOYER", "meta", fork)


if __name__ == "__main__":
Expand Down
19 changes: 4 additions & 15 deletions scripts/set_up_base_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,14 @@ class BasePoolSettings:
BasePoolSettings( # 2pool
pool="0x7f90122BF0700F9E7e1F688fe926940E8839F353",
lp_token="0x7f90122BF0700F9E7e1F688fe926940E8839F353",
coins=[
"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
"0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
],
coins=["0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"],
asset_types=[0, 0],
n_coins=2,
),
BasePoolSettings( # fraxbp
pool="0xC9B8a3FDECB9D5b218d02555a8Baf332E5B740d5",
lp_token="0xC9B8a3FDECB9D5b218d02555a8Baf332E5B740d5",
coins=[
"0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F",
"0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
],
coins=["0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F", "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"],
asset_types=[0, 0],
n_coins=2,
),
Expand All @@ -108,10 +102,7 @@ class BasePoolSettings:
BasePoolSettings( # fraxbp
pool="0x29A3d66B30Bc4AD674A4FDAF27578B64f6afbFe7",
lp_token="0x29A3d66B30Bc4AD674A4FDAF27578B64f6afbFe7",
coins=[
"0x2E3D870790dC77A83DD1d18184Acc7439A53f475",
"0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
],
coins=["0x2E3D870790dC77A83DD1d18184Acc7439A53f475", "0x7F5c764cBc14f9669B88837ca1490cCa17c31607"],
asset_types=[0, 0],
n_coins=2,
),
Expand Down Expand Up @@ -156,9 +147,7 @@ def set_up_base_pools(network, url, account, fork: bool = False):
factory.add_base_pool(data.pool, data.lp_token, data.asset_types, data.n_coins)
logger.log(f"Added {data.pool} to factory {factory_address} on {network}.")
else:
logger.log(
f"{data.pool} is already configured as a base pool in factory {factory_address}."
)
logger.log(f"{data.pool} is already configured as a base pool in factory {factory_address}.")

assert factory.base_pool_data(data.pool)[0] == data.lp_token

Expand Down
4 changes: 1 addition & 3 deletions scripts/vote_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def prepare_evm_script(target: Dict, actions: List[Tuple]) -> str:
contract = ape.Contract(address)
fn = getattr(contract, fn_name)
calldata = fn.as_transaction(*args, sender=agent.address, gas_price=0).data
agent_calldata = agent.execute.as_transaction(
address, 0, calldata, sender=voting, gas_price=0
).data
agent_calldata = agent.execute.as_transaction(address, 0, calldata, sender=voting, gas_price=0).data
length = hex(len(agent_calldata.hex()) // 2)[2:].zfill(8)
evm_script = f"{evm_script}{agent.address[2:]}{length}{agent_calldata.hex()}"

Expand Down
11 changes: 1 addition & 10 deletions test_suite/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,7 @@ def generate_report():
summary = extract_summary(line)

if summary:
(
failed,
passed,
skipped,
deselected,
xfailed,
warnings,
errors,
time_taken,
) = summary
(failed, passed, skipped, deselected, xfailed, warnings, errors, time_taken) = summary
total = int(sum(summary) - time_taken)
# Extract folder, subfolder, filename, and timestamp
relative_path = os.path.relpath(root, start=reports_base_dir)
Expand Down
12 changes: 3 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,12 @@ def pytest_generate_tests(metafunc):
combined_ids.append(f"(PoolType={pool_name})")

# Parametrize both pool_type and metapool_token_type together
metafunc.parametrize(
("pool_type", "metapool_token_type"), combined_params, ids=combined_ids
)
metafunc.parametrize(("pool_type", "metapool_token_type"), combined_params, ids=combined_ids)
elif "pool_type" in metafunc.fixturenames:
# or parametrize pool_type only
pool_type_items = get_pool_types(metafunc)
metafunc.parametrize(
"pool_type",
[v for k, v in pool_type_items],
ids=[f"(PoolType={k})" for k, v in pool_type_items],
"pool_type", [v for k, v in pool_type_items], ids=[f"(PoolType={k})" for k, v in pool_type_items]
)
elif "metapool_token_type" in metafunc.fixturenames:
# or parametrize metapool_token_type only
Expand All @@ -89,9 +85,7 @@ def pytest_generate_tests(metafunc):

# Parametrize initial_decimals
if "initial_decimals" in metafunc.fixturenames:
metafunc.parametrize(
"initial_decimals", DECIMAL_PAIRS, ids=[f"(Decimals={i},{j})" for i, j in DECIMAL_PAIRS]
)
metafunc.parametrize("initial_decimals", DECIMAL_PAIRS, ids=[f"(Decimals={i},{j})" for i, j in DECIMAL_PAIRS])


def get_pool_token_pairs(metafunc):
Expand Down
12 changes: 3 additions & 9 deletions tests/factory/test_factory_add_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def empty_factory_with_implementations(
return empty_factory


def test_add_base_pool_already_exists(
owner, factory, add_base_pool, base_pool, base_pool_lp_token, base_pool_tokens
):
def test_add_base_pool_already_exists(owner, factory, add_base_pool, base_pool, base_pool_lp_token, base_pool_tokens):
with boa.reverts():
factory.add_base_pool(
base_pool.address,
Expand All @@ -54,9 +52,7 @@ def test_add_base_pool_only_admin(factory, bob, base_pool, base_pool_lp_token, b
)


def test_deploy_plain_pool(
empty_factory_with_implementations, amm_deployer, plain_tokens, pool_size, zero_address
):
def test_deploy_plain_pool(empty_factory_with_implementations, amm_deployer, plain_tokens, pool_size, zero_address):
swap_address = empty_factory_with_implementations.deploy_plain_pool(
"test",
"test",
Expand All @@ -81,9 +77,7 @@ def test_deploy_plain_pool(

assert empty_factory_with_implementations.pool_count() == 1
assert empty_factory_with_implementations.pool_list(0) == swap.address
assert empty_factory_with_implementations.get_decimals(swap) == [
t.decimals() for t in (plain_tokens)
]
assert empty_factory_with_implementations.get_decimals(swap) == [t.decimals() for t in (plain_tokens)]


def test_pool_count(
Expand Down
7 changes: 2 additions & 5 deletions tests/factory/test_factory_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
@pytest.mark.parametrize("sending,receiving", [(0, 1), (1, 0)])
def test_find_pool_for_coins(factory, basic_swap, pool_tokens, sending, receiving):
assert (
factory.find_pool_for_coins(pool_tokens[sending].address, pool_tokens[receiving].address)
== basic_swap.address
factory.find_pool_for_coins(pool_tokens[sending].address, pool_tokens[receiving].address) == basic_swap.address
)


Expand All @@ -23,9 +22,7 @@ def test_get_decimals(factory, basic_swap, decimals):


def test_get_balances(factory, basic_swap, pool_size):
assert factory.get_balances(basic_swap.address) == [
basic_swap.balances(i) for i in range(pool_size)
]
assert factory.get_balances(basic_swap.address) == [basic_swap.balances(i) for i in range(pool_size)]


def test_get_underlying_balances(factory, basic_swap):
Expand Down
41 changes: 9 additions & 32 deletions tests/factory/test_factory_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@
@pytest.mark.parametrize("sending,receiving", [(0, 1), (1, 0)])
def test_find_pool_for_coins(factory, meta_swap, underlying_tokens, sending, receiving):
assert (
factory.find_pool_for_coins(
underlying_tokens[sending].address, underlying_tokens[receiving].address
)
factory.find_pool_for_coins(underlying_tokens[sending].address, underlying_tokens[receiving].address)
== meta_swap.address
)


@pytest.mark.parametrize("idx", range(1, 4))
def test_find_pool_for_coins_underlying(factory, meta_swap, underlying_tokens, idx):
assert (
factory.find_pool_for_coins(underlying_tokens[0], underlying_tokens[idx])
== meta_swap.address
)
assert (
factory.find_pool_for_coins(underlying_tokens[idx], underlying_tokens[0])
== meta_swap.address
)
assert factory.find_pool_for_coins(underlying_tokens[0], underlying_tokens[idx]) == meta_swap.address
assert factory.find_pool_for_coins(underlying_tokens[idx], underlying_tokens[0]) == meta_swap.address


def test_get_meta_n_coins(factory, meta_swap):
Expand All @@ -42,34 +34,21 @@ def test_get_underlying_decimals(factory, meta_swap, base_pool_decimals):


def test_get_metapool_rates(meta_setup, factory, meta_swap, base_pool, base_pool_lp_token):
assert factory.get_metapool_rates(meta_swap.address) == [
10**18,
base_pool.get_virtual_price(),
]
assert factory.get_metapool_rates(meta_swap.address) == [10**18, base_pool.get_virtual_price()]


def test_get_underlying_balances(meta_setup, factory, meta_swap, base_pool):
assert factory.get_metapool_rates(meta_swap.address) == [
10**18,
base_pool.get_virtual_price(),
]
assert factory.get_metapool_rates(meta_swap.address) == [10**18, base_pool.get_virtual_price()]


@pytest.mark.parametrize("sending,receiving", itertools.permutations(range(1, 4), 2))
def test_find_pool_underlying_base_pool_only(
factory, underlying_tokens, sending, receiving, zero_address
):
assert (
factory.find_pool_for_coins(underlying_tokens[sending], underlying_tokens[receiving])
== zero_address
)
def test_find_pool_underlying_base_pool_only(factory, underlying_tokens, sending, receiving, zero_address):
assert factory.find_pool_for_coins(underlying_tokens[sending], underlying_tokens[receiving]) == zero_address


@pytest.mark.parametrize("sending,receiving", itertools.permutations(range(2, 5), 2))
def test_get_coin_indices_underlying(factory, meta_swap, sending, receiving, underlying_tokens):
i, j, is_underlying = factory.get_coin_indices(
meta_swap, underlying_tokens[sending], underlying_tokens[receiving]
)
i, j, is_underlying = factory.get_coin_indices(meta_swap, underlying_tokens[sending], underlying_tokens[receiving])
assert i == sending - 1
assert j == receiving - 1
assert is_underlying is True
Expand All @@ -78,9 +57,7 @@ def test_get_coin_indices_underlying(factory, meta_swap, sending, receiving, und
@pytest.mark.parametrize("idx", range(1, 4))
def test_get_coin_indices_reverts(factory, meta_swap, base_pool_lp_token, underlying_tokens, idx):
with boa.reverts():
factory.get_coin_indices(
meta_swap.address, base_pool_lp_token.address, underlying_tokens[idx]
)
factory.get_coin_indices(meta_swap.address, base_pool_lp_token.address, underlying_tokens[idx])


def test_get_implementation_address(factory, meta_swap, amm_implementation_meta):
Expand Down
14 changes: 3 additions & 11 deletions tests/fixtures/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def add_initial_liquidity_owner_meta(
with boa.env.prank(owner):
base_pool_lp_token.approve(meta_swap.address, 2**256 - 1)
lp_token_bal = base_pool_lp_token.balanceOf(owner)
to_mint_token0 = (
lp_token_bal * 10 ** metapool_token.decimals() // 10 ** base_pool_lp_token.decimals()
)
to_mint_token0 = lp_token_bal * 10 ** metapool_token.decimals() // 10 ** base_pool_lp_token.decimals()

mint_for_testing(owner, to_mint_token0, metapool_token, False)
metapool_token.approve(meta_swap.address, 2**256 - 1)
Expand Down Expand Up @@ -211,11 +209,7 @@ def meta_setup(
alice_mp_balance_norm = metapool_token.balanceOf(alice) / 10 ** metapool_token.decimals()

if alice_mp_balance_norm < alice_bp_balance_norm:
mint_for_testing(
alice,
int(math.ceil(alice_bp_balance_norm) * 10 ** metapool_token.decimals()),
metapool_token,
)
mint_for_testing(alice, int(math.ceil(alice_bp_balance_norm) * 10 ** metapool_token.decimals()), metapool_token)

with boa.env.prank(alice):
metapool_token.approve(meta_swap.address, 2**256 - 1)
Expand Down Expand Up @@ -243,8 +237,6 @@ def initial_setup(pool_type, request, metapool_token_type, pool_token_types, ini
# For basic pools, we don't care about metapool_token_type
metapool_token_type = None
# Continue with the general logic
assert all(
fixture is not None for fixture in (initial_decimals, pool_token_types)
), "Fixtures required downstream"
assert all(fixture is not None for fixture in (initial_decimals, pool_token_types)), "Fixtures required downstream"
fixture_name = {POOL_TYPES["basic"]: "basic_setup", POOL_TYPES["meta"]: "meta_setup"}[pool_type]
return request.getfixturevalue(fixture_name)
13 changes: 2 additions & 11 deletions tests/fixtures/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ def math_implementation(deployer, math_deployer):

@pytest.fixture()
def factory(
deployer,
fee_receiver,
owner,
gauge_implementation,
views_implementation,
math_implementation,
factory_deployer,
deployer, fee_receiver, owner, gauge_implementation, views_implementation, math_implementation, factory_deployer
):
with boa.env.prank(deployer):
factory = factory_deployer.deploy(fee_receiver, owner)
Expand Down Expand Up @@ -70,10 +64,7 @@ def set_metapool_implementations(owner, factory, amm_implementation_meta):
def add_base_pool(owner, factory, base_pool, base_pool_lp_token, base_pool_tokens):
with boa.env.prank(owner):
factory.add_base_pool(
base_pool.address,
base_pool_lp_token.address,
[0] * len(base_pool_tokens),
len(base_pool_tokens),
base_pool.address, base_pool_lp_token.address, [0] * len(base_pool_tokens), len(base_pool_tokens)
)


Expand Down
Loading

0 comments on commit 9be0ba4

Please sign in to comment.