Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: update web3py to v6, apply no-implicit-optional, misc fixes#320

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ErikBjare merged 13 commits intomasterfromdev/misc-fixes2
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
b4f0ad3
build(deps): updated dependencies
ErikBjareFeb 24, 2023
38b7870
fix: applied no-implicit-optional
ErikBjareFeb 24, 2023
00a97bd
fix: changed to using new names in updated web3py versions
ErikBjareFeb 24, 2023
c358849
fix: explicitly set gasPrice for tx's
ErikBjareMar 6, 2023
8625211
fix: misc fixes
ErikBjareMar 29, 2023
5fc8110
build(deps): updated dependencies
ErikBjareMar 29, 2023
356e940
fix: fixed bug caused previously in PR
ErikBjareMar 30, 2023
cb73004
build(deps): updated dependencies
ErikBjareMar 30, 2023
27ca688
ci: added `poetry config installer.modern-installation false` to work…
ErikBjareMar 30, 2023
8a96c07
fix: removed unused code
ErikBjareMar 30, 2023
702419e
ci: fix ci
ErikBjareMar 30, 2023
ece7f1e
build(deps): pinned pydata-sphinx-theme to work around bug
ErikBjareMar 30, 2023
1956fec
build(deps): changed version marker for web3
ErikBjareMar 30, 2023
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
1 change: 1 addition & 0 deletions.github/workflows/docs.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,6 +19,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
poetry config installer.modern-installation false
poetry install
- name: Docs
run: |
Expand Down
2 changes: 2 additions & 0 deletions.github/workflows/test.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,6 +54,7 @@ jobs:
run: |
python -m pip install --upgrade pip poetry
poetry config virtualenvs.in-project true
poetry config installer.modern-installation false

- name: Set up cache
uses: actions/cache@v2
Expand DownExpand Up@@ -107,6 +108,7 @@ jobs:
run: |
python -m pip install --upgrade pip poetry
poetry config virtualenvs.in-project true
poetry config installer.modern-installation false

- name: Set up cache
uses: actions/cache@v2
Expand Down
4 changes: 2 additions & 2 deletionsMakefile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
.PHONY: test typecheck lint precommit docs

test:
poetry run pytest -v --tb=line --maxfail=4 --cov=uniswap --cov-report html --cov-report term --cov-report xml
poetry run pytest -v --tb=auto --maxfail=20 --cov=uniswap --cov-report html --cov-report term --cov-report xml

typecheck:
poetry run mypy --pretty
Expand All@@ -21,4 +21,4 @@ precommit:
make test

docs:
cd docs/ && make html
cd docs/ && make html
2,906 changes: 1,539 additions & 1,367 deletionspoetry.lock
View file
Open in desktop

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletionpyproject.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ unipy = "uniswap:main"

[tool.poetry.dependencies]
python = "^3.7.2"
web3 = { version = ">5.23.0,<7.0", allow-prereleases = true }
web3 = { version = "^6.0", allow-prereleases = true }
click = "^8.0.3"
python-dotenv = "*"
typing-extensions = "*"
Expand All@@ -39,11 +39,15 @@ flake8 = "*"
Sphinx = "*"
sphinx-book-theme = "*"
sphinx-click = "*"
pydata-sphinx-theme = "0.13.1" # due to: https://github.com/executablebooks/sphinx-book-theme/issues/711

[tool.pytest.ini_options]
log_cli = false # to print logs during tests, set to true
#log_level = "NOTSET"

[tool.ruff]
ignore = ["E402", "E501"]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
43 changes: 22 additions & 21 deletionstests/test_uniswap.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,20 +9,17 @@
from time import sleep

from web3 import Web3
from web3.exceptions import NameNotFound

from uniswap import Uniswap, token
from uniswap.constants import ETH_ADDRESS, WETH9_ADDRESS
from uniswap import Uniswap
from uniswap.constants import ETH_ADDRESS
from uniswap.exceptions import InsufficientBalance
from uniswap.tokens import get_tokens
from uniswap.util import (
_str_to_addr,
default_tick_range,
_addr_to_str,
_load_contract_erc20,
)


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

Expand All@@ -35,6 +32,13 @@
RECEIPT_TIMEOUT = 5


ONE_ETH = 10**18
ONE_DAI = 10**18
ONE_USDC = 10**6

ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"


@dataclass
class GanacheInstance:
provider: str
Expand All@@ -53,7 +57,7 @@ def client(request, web3: Web3, ganache: GanacheInstance):
)


@pytest.fixture(scope="function", params=UNISWAP_VERSIONS)
@pytest.fixture(scope="function")
def tokens(client: Uniswap):
return get_tokens(client.netname)

Expand All@@ -65,14 +69,18 @@ def test_assets(client: Uniswap):
"""
tokens = get_tokens(client.netname)

for token_name, amount in [("DAI", 100 * 10 ** 18), ("USDC", 100 * 10 ** 6)]:
for token_name, amount in [
("DAI", 10_000 * ONE_DAI),
("USDC", 10_000 * ONE_USDC),
]:
token_addr = tokens[token_name]
price = client.get_price_output(_str_to_addr(ETH_ADDRESS), token_addr, amount)
logger.info(f"Cost of {amount} {token_name}: {price}")
logger.info("Buying...")

tx = client.make_trade_output(tokens["ETH"], token_addr, amount)
client.w3.eth.wait_for_transaction_receipt(tx, timeout=RECEIPT_TIMEOUT)
txid = client.make_trade_output(tokens["ETH"], token_addr, amount)
tx = client.w3.eth.wait_for_transaction_receipt(txid, timeout=RECEIPT_TIMEOUT)
assert tx["status"] == 1, f"Transaction failed: {tx}"


@pytest.fixture(scope="module")
Expand All@@ -96,7 +104,7 @@ def ganache() -> Generator[GanacheInstance, None, None]:
)

port = 10999
defaultGasPrice =1000_000_000_000 #1000 gwei
defaultGasPrice =100_000_000_000 #100 gwei
p = subprocess.Popen(
f"""ganache
--port {port}
Expand DownExpand Up@@ -125,16 +133,9 @@ def does_not_raise():
yield


ONE_ETH = 10 ** 18
ONE_USDC = 10 ** 6

ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"


# TODO: Change pytest.param(..., mark=pytest.mark.xfail) to the expectation/raises method
@pytest.mark.usefixtures("client", "web3")
class TestUniswap(object):

# ------ Exchange ------------------------------------------------------------------
def test_get_fee_maker(self, client: Uniswap):
if client.version not in [1, 2]:
Expand DownExpand Up@@ -343,7 +344,7 @@ def test_v3_deploy_pool_with_liquidity(
amount1,
tick_lower=min_tick,
tick_upper=max_tick,
deadline=2 **64,
deadline=2**64,
)
assert r["status"]

Expand All@@ -357,7 +358,7 @@ def test_v3_deploy_pool_with_liquidity(

@pytest.mark.parametrize(
"deadline",
[(2 **64)],
[(2**64)],
)
def test_close_position(self, client: Uniswap, deadline):
if client.version != 3:
Expand DownExpand Up@@ -445,7 +446,7 @@ def test_make_trade(

txid = client.make_trade(input_token, output_token, qty, recipient)
tx = web3.eth.wait_for_transaction_receipt(txid, timeout=RECEIPT_TIMEOUT)
assert tx["status"]
assert tx["status"], f"Transaction failed with status {tx['status']}: {tx}"

# TODO: Checks for ETH, taking gas into account
bal_in_after = client.get_token_balance(input_token)
Expand All@@ -460,7 +461,7 @@ def test_make_trade(
# Token -> Token
("DAI", "USDC", ONE_USDC, None, does_not_raise),
# Token -> ETH
("DAI", "ETH",100 * ONE_USDC, None, does_not_raise),
("DAI", "ETH",ONE_ETH // 10, None, does_not_raise),
# FIXME: These should probably be uncommented eventually
# ("ETH", "UNI", int(0.000001 * ONE_ETH), ZERO_ADDRESS),
# ("UNI", "ETH", int(0.000001 * ONE_ETH), ZERO_ADDRESS),
Expand Down
6 changes: 3 additions & 3 deletionsuniswap/cli.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,10 +28,10 @@ def _coerce_to_checksum(addr: str) -> str:
raise ValueError(
"token was not an address, and a shorthand was not found in the token db"
)
if Web3.isChecksumAddress(addr):
if Web3.is_checksum_address(addr):
return addr
else:
return Web3.toChecksumAddress(addr)
return Web3.to_checksum_address(addr)


@click.group()
Expand DownExpand Up@@ -71,7 +71,7 @@ def price(
token_in: AddressLike,
token_out: AddressLike,
raw: bool,
quantity: int = None,
quantity:Optional[int] = None,
) -> None:
"""Returns the price of ``quantity`` tokens of ``token_in`` quoted in ``token_out``."""
uni: Uniswap = ctx.obj["UNISWAP"]
Expand Down
6 changes: 3 additions & 3 deletionsuniswap/tokens.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@


tokens_mainnet: Dict[str, ChecksumAddress] = {
k: Web3.toChecksumAddress(v)
k: Web3.to_checksum_address(v)
for k, v in {
"ETH": "0x0000000000000000000000000000000000000000",
"WETH": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
Expand All@@ -18,7 +18,7 @@
}

tokens_rinkeby: Dict[str, ChecksumAddress] = {
k: Web3.toChecksumAddress(v)
k: Web3.to_checksum_address(v)
for k, v in {
"ETH": "0x0000000000000000000000000000000000000000",
"DAI": "0x2448eE2641d78CC42D7AD76498917359D961A783",
Expand All@@ -27,7 +27,7 @@
}

tokens_arbitrum: Dict[str, ChecksumAddress] = {
k: Web3.toChecksumAddress(v)
k: Web3.to_checksum_address(v)
for k, v in {
"ETH": "0x0000000000000000000000000000000000000000",
"WETH": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp