Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping: Add linter, CI #40

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Lint

on: [push, pull_request]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
version: "~= 22.0"
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
exclude: \.py-tpl$
1 change: 0 additions & 1 deletion balpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .balancerErrors import handleException
from balpy import balpy

209 changes: 106 additions & 103 deletions balpy/balancerErrors.py
Original file line number Diff line number Diff line change
@@ -1,107 +1,110 @@
codes = {0:"ADD_OVERFLOW",
1:"SUB_OVERFLOW",
2:"SUB_UNDERFLOW",
3:"MUL_OVERFLOW",
4:"ZERO_DIVISION",
5:"DIV_INTERNAL",
6:"X_OUT_OF_BOUNDS",
7:"Y_OUT_OF_BOUNDS",
8:"PRODUCT_OUT_OF_BOUNDS",
9:"INVALID_EXPONENT",
100:"OUT_OF_BOUNDS",
101:"UNSORTED_ARRAY",
102:"UNSORTED_TOKENS",
103:"INPUT_LENGTH_MISMATCH",
104:"ZERO_TOKEN",
200:"MIN_TOKENS",
201:"MAX_TOKENS",
202:"MAX_SWAP_FEE_PERCENTAGE",
203:"MIN_SWAP_FEE_PERCENTAGE",
204:"MINIMUM_BPT",
205:"CALLER_NOT_VAULT",
206:"UNINITIALIZED",
207:"BPT_IN_MAX_AMOUNT",
208:"BPT_OUT_MIN_AMOUNT",
209:"EXPIRED_PERMIT",
300:"MIN_AMP",
301:"MAX_AMP",
302:"MIN_WEIGHT",
303:"MAX_STABLE_TOKENS",
304:"MAX_IN_RATIO",
305:"MAX_OUT_RATIO",
306:"MIN_BPT_IN_FOR_TOKEN_OUT",
307:"MAX_OUT_BPT_FOR_TOKEN_IN",
308:"NORMALIZED_WEIGHT_INVARIANT",
309:"INVALID_TOKEN",
310:"UNHANDLED_JOIN_KIND",
311:"ZERO_INVARIANT",
400:"REENTRANCY",
401:"SENDER_NOT_ALLOWED",
402:"PAUSED",
403:"PAUSE_WINDOW_EXPIRED",
404:"MAX_PAUSE_WINDOW_DURATION",
405:"MAX_BUFFER_PERIOD_DURATION",
406:"INSUFFICIENT_BALANCE",
407:"INSUFFICIENT_ALLOWANCE",
408:"ERC20_TRANSFER_FROM_ZERO_ADDRESS",
409:"ERC20_TRANSFER_TO_ZERO_ADDRESS",
410:"ERC20_MINT_TO_ZERO_ADDRESS",
411:"ERC20_BURN_FROM_ZERO_ADDRESS",
412:"ERC20_APPROVE_FROM_ZERO_ADDRESS",
413:"ERC20_APPROVE_TO_ZERO_ADDRESS",
414:"ERC20_TRANSFER_EXCEEDS_ALLOWANCE",
415:"ERC20_DECREASED_ALLOWANCE_BELOW_ZERO",
416:"ERC20_TRANSFER_EXCEEDS_BALANCE",
417:"ERC20_BURN_EXCEEDS_ALLOWANCE",
418:"SAFE_ERC20_CALL_FAILED",
419:"ADDRESS_INSUFFICIENT_BALANCE",
420:"ADDRESS_CANNOT_SEND_VALUE",
421:"SAFE_CAST_VALUE_CANT_FIT_INT256",
422:"GRANT_SENDER_NOT_ADMIN",
423:"REVOKE_SENDER_NOT_ADMIN",
424:"RENOUNCE_SENDER_NOT_ALLOWED",
425:"BUFFER_PERIOD_EXPIRED",
500:"INVALID_POOL_ID",
501:"CALLER_NOT_POOL",
502:"SENDER_NOT_ASSET_MANAGER",
503:"USER_DOESNT_ALLOW_RELAYER",
504:"INVALID_SIGNATURE",
505:"EXIT_BELOW_MIN",
506:"JOIN_ABOVE_MAX",
507:"SWAP_LIMIT",
508:"SWAP_DEADLINE",
509:"CANNOT_SWAP_SAME_TOKEN",
510:"UNKNOWN_AMOUNT_IN_FIRST_SWAP",
511:"MALCONSTRUCTED_MULTIHOP_SWAP",
512:"INTERNAL_BALANCE_OVERFLOW",
513:"INSUFFICIENT_INTERNAL_BALANCE",
514:"INVALID_ETH_INTERNAL_BALANCE",
515:"INVALID_POST_LOAN_BALANCE",
516:"INSUFFICIENT_ETH",
517:"UNALLOCATED_ETH",
518:"ETH_TRANSFER",
519:"CANNOT_USE_ETH_SENTINEL",
520:"TOKENS_MISMATCH",
521:"TOKEN_NOT_REGISTERED",
522:"TOKEN_ALREADY_REGISTERED",
523:"TOKENS_ALREADY_SET",
524:"TOKENS_LENGTH_MUST_BE_2",
525:"NONZERO_TOKEN_BALANCE",
526:"BALANCE_TOTAL_OVERFLOW",
600:"SWAP_FEE_PERCENTAGE_TOO_HIGH",
601:"FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH",
602:"INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT"
};
codes = {
0: "ADD_OVERFLOW",
1: "SUB_OVERFLOW",
2: "SUB_UNDERFLOW",
3: "MUL_OVERFLOW",
4: "ZERO_DIVISION",
5: "DIV_INTERNAL",
6: "X_OUT_OF_BOUNDS",
7: "Y_OUT_OF_BOUNDS",
8: "PRODUCT_OUT_OF_BOUNDS",
9: "INVALID_EXPONENT",
100: "OUT_OF_BOUNDS",
101: "UNSORTED_ARRAY",
102: "UNSORTED_TOKENS",
103: "INPUT_LENGTH_MISMATCH",
104: "ZERO_TOKEN",
200: "MIN_TOKENS",
201: "MAX_TOKENS",
202: "MAX_SWAP_FEE_PERCENTAGE",
203: "MIN_SWAP_FEE_PERCENTAGE",
204: "MINIMUM_BPT",
205: "CALLER_NOT_VAULT",
206: "UNINITIALIZED",
207: "BPT_IN_MAX_AMOUNT",
208: "BPT_OUT_MIN_AMOUNT",
209: "EXPIRED_PERMIT",
300: "MIN_AMP",
301: "MAX_AMP",
302: "MIN_WEIGHT",
303: "MAX_STABLE_TOKENS",
304: "MAX_IN_RATIO",
305: "MAX_OUT_RATIO",
306: "MIN_BPT_IN_FOR_TOKEN_OUT",
307: "MAX_OUT_BPT_FOR_TOKEN_IN",
308: "NORMALIZED_WEIGHT_INVARIANT",
309: "INVALID_TOKEN",
310: "UNHANDLED_JOIN_KIND",
311: "ZERO_INVARIANT",
400: "REENTRANCY",
401: "SENDER_NOT_ALLOWED",
402: "PAUSED",
403: "PAUSE_WINDOW_EXPIRED",
404: "MAX_PAUSE_WINDOW_DURATION",
405: "MAX_BUFFER_PERIOD_DURATION",
406: "INSUFFICIENT_BALANCE",
407: "INSUFFICIENT_ALLOWANCE",
408: "ERC20_TRANSFER_FROM_ZERO_ADDRESS",
409: "ERC20_TRANSFER_TO_ZERO_ADDRESS",
410: "ERC20_MINT_TO_ZERO_ADDRESS",
411: "ERC20_BURN_FROM_ZERO_ADDRESS",
412: "ERC20_APPROVE_FROM_ZERO_ADDRESS",
413: "ERC20_APPROVE_TO_ZERO_ADDRESS",
414: "ERC20_TRANSFER_EXCEEDS_ALLOWANCE",
415: "ERC20_DECREASED_ALLOWANCE_BELOW_ZERO",
416: "ERC20_TRANSFER_EXCEEDS_BALANCE",
417: "ERC20_BURN_EXCEEDS_ALLOWANCE",
418: "SAFE_ERC20_CALL_FAILED",
419: "ADDRESS_INSUFFICIENT_BALANCE",
420: "ADDRESS_CANNOT_SEND_VALUE",
421: "SAFE_CAST_VALUE_CANT_FIT_INT256",
422: "GRANT_SENDER_NOT_ADMIN",
423: "REVOKE_SENDER_NOT_ADMIN",
424: "RENOUNCE_SENDER_NOT_ALLOWED",
425: "BUFFER_PERIOD_EXPIRED",
500: "INVALID_POOL_ID",
501: "CALLER_NOT_POOL",
502: "SENDER_NOT_ASSET_MANAGER",
503: "USER_DOESNT_ALLOW_RELAYER",
504: "INVALID_SIGNATURE",
505: "EXIT_BELOW_MIN",
506: "JOIN_ABOVE_MAX",
507: "SWAP_LIMIT",
508: "SWAP_DEADLINE",
509: "CANNOT_SWAP_SAME_TOKEN",
510: "UNKNOWN_AMOUNT_IN_FIRST_SWAP",
511: "MALCONSTRUCTED_MULTIHOP_SWAP",
512: "INTERNAL_BALANCE_OVERFLOW",
513: "INSUFFICIENT_INTERNAL_BALANCE",
514: "INVALID_ETH_INTERNAL_BALANCE",
515: "INVALID_POST_LOAN_BALANCE",
516: "INSUFFICIENT_ETH",
517: "UNALLOCATED_ETH",
518: "ETH_TRANSFER",
519: "CANNOT_USE_ETH_SENTINEL",
520: "TOKENS_MISMATCH",
521: "TOKEN_NOT_REGISTERED",
522: "TOKEN_ALREADY_REGISTERED",
523: "TOKENS_ALREADY_SET",
524: "TOKENS_LENGTH_MUST_BE_2",
525: "NONZERO_TOKEN_BALANCE",
526: "BALANCE_TOTAL_OVERFLOW",
600: "SWAP_FEE_PERCENTAGE_TOO_HIGH",
601: "FLASH_LOAN_FEE_PERCENTAGE_TOO_HIGH",
602: "INSUFFICIENT_FLASH_LOAN_FEE_AMOUNT",
}


def translateError(code):
return(codes[code])
return codes[code]


def handleException(error):
stringError = str('{}'.format(error));
if "BAL#" in stringError:
code = int(stringError.split("BAL#")[1])
balError = translateError(code);
descriptiveError = "Balancer Smart Contract threw error: " + balError;
return(descriptiveError);
else:
return(stringError);
stringError = str("{}".format(error))
if "BAL#" in stringError:
code = int(stringError.split("BAL#")[1])
balError = translateError(code)
descriptiveError = "Balancer Smart Contract threw error: " + balError
return descriptiveError
else:
return stringError
19 changes: 9 additions & 10 deletions balpy/balancerv2cad/scripts/project_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys

import balancerv2cad as ks

# from balancerv2cad import PKG_NAME, BASE_DIR


Expand All @@ -15,26 +16,24 @@ def stub_gen() -> None:
for the package
"""
out_file = f"src/{ks.__package__}-stubs"
path = str(ks.BASE_DIR / 'src' / f'{ks.__package__}')
path = str(ks.BASE_DIR / "src" / f"{ks.__package__}")
try:
sp.run(f'stubgen -p {ks.__package__} -o {out_file}',
check=True,
shell=True)
sp.run(f'mypy {path}', check=True, shell=True)
sp.run(f"stubgen -p {ks.__package__} -o {out_file}", check=True, shell=True)
sp.run(f"mypy {path}", check=True, shell=True)
except sp.CalledProcessError as error:
print(f'{error}')
print(f"{error}")
sys.exit(1)


def run_analyzer() -> None:
"""
Run the mypy static type checking analyzer
"""
path = str(ks.BASE_DIR / 'src' / f'{ks.__package__}')
path = str(ks.BASE_DIR / "src" / f"{ks.__package__}")
try:
sp.run(f'mypy {path}', check=True, shell=True)
sp.run(f"mypy {path}", check=True, shell=True)
except sp.CalledProcessError as error:
print(f'{error}')
print(f"{error}")
sys.exit(1)


Expand All @@ -46,7 +45,7 @@ def run_tests():
These functions can be as complicated or as simple as you like
"""
try:
sp.run('pytest --capture=tee-sys', check=True, shell=True)
sp.run("pytest --capture=tee-sys", check=True, shell=True)
except sp.CalledProcessError as error:
print(f"{error}")
sys.exit(1)
12 changes: 6 additions & 6 deletions balpy/balancerv2cad/src/balancerv2cad/BalancerConstants.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from decimal import Decimal


BONE = Decimal('1')
MIN_FEE = Decimal('0.000001')
MAX_FEE = Decimal('0.1')
INIT_POOL_SUPPLY = BONE * Decimal('100')
BONE = Decimal("1")
MIN_FEE = Decimal("0.000001")
MAX_FEE = Decimal("0.1")
INIT_POOL_SUPPLY = BONE * Decimal("100")
MIN_BOUND_TOKENS = 2
MAX_BOUND_TOKENS = 8
AMPLIFICATION_PARAMETER = Decimal('200')
AMPLIFICATION_PARAMETER = Decimal("200")
MIN_WEIGHT = 0.01
_MAX_WEIGHTED_TOKENS = 100
_MAX_IN_RATIO = 0.3
_MAX_OUT_RATIO = 0.3
_MAX_INVARIANT_RATIO = 3
_MIN_INVARIANT_RATIO = 0.7
_MIN_INVARIANT_RATIO = 0.7
Loading