Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
d3ccf9f
bumped to web6
8ball030 Oct 9, 2023
3ef2a33
[feat] deps
Oct 10, 2023
4218170
bumped to web3v6
8ball030 Oct 10, 2023
0656963
small improvements
8ball030 Oct 11, 2023
f858316
reverted testing changes
8ball030 Oct 11, 2023
0bcefb4
added test for graph
8ball030 Oct 11, 2023
1cc7137
[chore] ensured pep8 compliance
8ball030 Oct 11, 2023
5498b3e
[chore] ensured pep8 compliance
8ball030 Oct 11, 2023
e55ab2f
[chore] ensured pep8 compliance
8ball030 Oct 11, 2023
61c6efd
[chore] added dev deps group
8ball030 Oct 11, 2023
98bf435
[chore] added docs
8ball030 Oct 11, 2023
521fb53
added test for graph
8ball030 Oct 11, 2023
ebb6ac9
[feat] ensured commit matches
8ball030 Nov 16, 2023
baedb62
Merge pull request #1 from 8ball030/feat/syncing-changes-2
8ball030 Nov 16, 2023
8c1b44f
feat: added base
8ball030 Mar 28, 2024
dc7d0d7
feat: added base
8ball030 Mar 28, 2024
f845b54
feat: add apiEndpoint to balpy class
8ball030 May 27, 2024
ba00442
feat: relaxed dependencies
8ball030 Aug 11, 2024
c64e790
Merge pull request #3 from 8ball030/feat/improvments
8ball030 Aug 11, 2024
b83aa67
Merge pull request #4 from 8ball030/feat/stable
8ball030 Aug 11, 2024
c715f93
feat: relaxed dependencies
8ball030 Aug 11, 2024
c73beed
feat: updated for v3 api
Oct 4, 2024
4f57f1e
chore: relaxed deps
Oct 13, 2024
8af73de
Merge branch 'main' into feat/updated-upstream
8ball030 Oct 13, 2024
f3ad8d2
chore: regenerated poetry lock
Oct 13, 2024
0b5e9a1
Merge pull request #5 from 8ball030/feat/updated-upstream
8ball030 Oct 13, 2024
d00c791
feat:fixed import
Oct 13, 2024
5462bd7
chore: linters and api3 integration
Oct 15, 2024
ef17927
fix: retry to account for blocking
Oct 16, 2024
419b598
Merge branch 'main' into feat/updates
8ball030 Oct 23, 2024
a804c81
Merge pull request #6 from 8ball030/feat/updates
8ball030 Oct 23, 2024
86ef737
chore: removed unused code
Oct 23, 2024
4269105
chore: improve-balpy api response handling to advoid rpc
Oct 25, 2024
9dff00a
chore: improve copy of query
Oct 28, 2024
ea5392d
chore:workflows-and-github
Oct 28, 2024
d2cd8b0
Merge pull request #7 from 8ball030/feat/preparing-fork
8ball030 Oct 28, 2024
136d305
feat/ensured-passes-ci
Oct 28, 2024
55052fd
feat:tbump
Oct 28, 2024
b70a2be
Bump to 0.0.2
Oct 28, 2024
54743a2
Bump to 0.0.3
Oct 28, 2024
87f4759
feat:bumping
Oct 28, 2024
5e27278
Bump to 0.0.4
Oct 28, 2024
f0f4998
feat:bumping
Oct 28, 2024
294c3a8
Bump to 0.0.5
Oct 28, 2024
e75a06d
feat:added-common-checks
Oct 28, 2024
b1b3961
Bump to 0.0.6
Oct 28, 2024
2f0add9
feat:aligning-relase-versions
Oct 28, 2024
cfb4364
Bump to 0.0.7
Oct 28, 2024
db3bc9d
feat:refactor
Dec 23, 2024
0ee7aee
Merge pull request #8 from 8ball030/feat/extra-endpoints
8ball030 Dec 23, 2024
061fa7f
Bump to 0.0.8
Dec 23, 2024
4f9391b
Bump to 0.0.9
Dec 23, 2024
aaab40e
feat:Add MODE support in balpy
gauravlochab Jan 16, 2025
5c4b104
chore:version update to 0.1.0 for release
gauravlochab Jan 16, 2025
f2083dd
feat: Add mode.json for various tasks
gauravlochab Jan 16, 2025
e34ffb4
fix: resolve ci issue for lockfile
gauravlochab Jan 16, 2025
0cf7daa
Merge pull request #9 from 8ball030/feat/add-mode
8ball030 Jan 17, 2025
8562d02
fix:added-deployments-docs-table
Jan 17, 2025
335a7bf
Bump to 0.1.1
Jan 17, 2025
073d739
Bump to 0.1.1
Jan 17, 2025
9ba7dc3
feat: return batch swap call data
xiuxiuxar Jul 25, 2025
fcbfb5e
set SOR to find v2 swaps only and return only bytes32 poolids
xiuxiuxar Jul 26, 2025
6bda2e7
revert to correct poolid logic, now that API returns v2 only
xiuxiuxar Jul 26, 2025
6163eca
define sender and recipient for safe address compatibility
xiuxiuxar Jul 30, 2025
476e400
remove unneeded code
xiuxiuxar Jul 30, 2025
75c03aa
fix ci, bump versions
xiuxiuxar Jul 30, 2025
5b3226d
bump ci poetry
xiuxiuxar Jul 30, 2025
4f0911f
update lockfile
xiuxiuxar Jul 30, 2025
1771c21
bump ci poetry
xiuxiuxar Jul 30, 2025
377be32
feat:fixed-ci-issues
Aug 19, 2025
f0e3a4a
feat:fixed-ci-issues
Aug 19, 2025
f428ae1
feat:fixed-ci-issues
Aug 19, 2025
7635168
fix:lock-issues
Aug 19, 2025
3236b71
Merge branch 'main' into test-fixes
8ball030 Aug 19, 2025
e18f75d
fix:lock-issues
Aug 19, 2025
563b5ac
fix:linter-issues
Aug 19, 2025
aa22a72
Merge pull request #13 from 8ball030/test-fixes
8ball030 Aug 19, 2025
1585a71
Merge pull request #10 from 8ball030/feat/generate-deployments-docs-t…
8ball030 Aug 19, 2025
3c98d31
Merge branch 'fix/swaps' into chore/fix-swap-data
8ball030 Aug 19, 2025
86e1dbd
Merge pull request #12 from xiuxiuxar/chore/fix-swap-data
8ball030 Aug 19, 2025
ceeceaa
fix:relock-poetry
Aug 19, 2025
9f3ff95
chore:linters
Aug 19, 2025
44ebe20
Merge pull request #14 from 8ball030/fix/swaps
8ball030 Aug 21, 2025
7b3770a
feat: add get ticker graph query
xiuxiuxar Aug 23, 2025
c2d9936
Merge pull request #15 from xiuxiuxar/feat/add-ticker-query
8ball030 Aug 23, 2025
62bce53
Bump to 0.1.2
Aug 28, 2025
a716de5
feat:example-and-improvements
Aug 31, 2025
6ff2553
chore:linters
Aug 31, 2025
bae2c69
Bump to 0.1.3
Aug 31, 2025
969baff
feat:fixed-query-to-pin-protocol
Aug 31, 2025
371855b
Bump to 0.1.4
Aug 31, 2025
ae7f670
bump multicaller -> v0.3.0
xiuxiuxar Sep 12, 2025
dfd92a8
Merge branch 'main' into chore/bump-multicaller
xiuxiuxar Sep 12, 2025
b72f9c2
Merge pull request #17 from xiuxiuxar/chore/bump-multicaller
8ball030 Sep 12, 2025
d2bdf77
Merge pull request #18 from 8ball030/bump-multicaller
8ball030 Sep 12, 2025
4d310da
Bump to 0.1.5
Sep 12, 2025
85d53bc
remove web3 middleware
xiuxiuxar Sep 13, 2025
1e99104
Merge pull request #19 from xiuxiuxar/chore/remove-web3-middleware
8ball030 Sep 13, 2025
a65aace
Bump to 0.1.6
Sep 13, 2025
4f52515
feat:fixing-deps
Dec 16, 2025
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
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ See release on PyPI: https://pypi.org/project/balpy/
```bash
# Install in virtual environment using poetry
git clone https://github.com/balancer-labs/balpy.git
# checkout submodules
git submodule update --init --recursive
Comment on lines +33 to +34
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the docs atm, might need to add the compile step too


cd balpy
poetry install # Install dependencies and package
# You can enter the virtual environment using
Expand Down Expand Up @@ -62,3 +65,32 @@ You also must set AT LEAST one of these environment variables to connect to the

## Samples
See README.md in samples/ for more information.

## DEV

# Formatting

```bash
make fmt
```

## Linting

```bash
make lint
```

Check all linters and formaters and tests.

## Tests

A small number of tests are included for functionaly demonstration.

```bash
make test
```



```bash
make all
3 changes: 0 additions & 3 deletions balpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .balancerErrors import handleException
from balpy import balpy

2 changes: 1 addition & 1 deletion balpy/balancer-deployments
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:
Comment on lines -100 to -101
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed tabs and whitespaces

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
22 changes: 12 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,27 @@ 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 +48,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)
13 changes: 6 additions & 7 deletions balpy/balancerv2cad/src/balancerv2cad/BalancerConstants.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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