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

Commit6ff4539

Browse files
authored
fix: update web3py to v6, apply no-implicit-optional, misc fixes (#320)
1 parentda8c7dd commit6ff4539

File tree

10 files changed

+1630
-1439
lines changed

10 files changed

+1630
-1439
lines changed

‎.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
-name:Install dependencies
2020
run:|
2121
python -m pip install --upgrade pip poetry
22+
poetry config installer.modern-installationfalse
2223
poetry install
2324
-name:Docs
2425
run:|

‎.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
run:|
5555
python -m pip install --upgrade pip poetry
5656
poetry config virtualenvs.in-projecttrue
57+
poetry config installer.modern-installationfalse
5758
5859
-name:Set up cache
5960
uses:actions/cache@v2
@@ -107,6 +108,7 @@ jobs:
107108
run:|
108109
python -m pip install --upgrade pip poetry
109110
poetry config virtualenvs.in-projecttrue
111+
poetry config installer.modern-installationfalse
110112
111113
-name:Set up cache
112114
uses:actions/cache@v2

‎Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: test typecheck lint precommit docs
22

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

66
typecheck:
77
poetry run mypy --pretty
@@ -21,4 +21,4 @@ precommit:
2121
maketest
2222

2323
docs:
24-
cd docs/&& make html
24+
cd docs/&& make html

‎poetry.lock

Lines changed: 1539 additions & 1367 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ unipy = "uniswap:main"
2424

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

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

48+
[tool.ruff]
49+
ignore = ["E402","E501"]
50+
4751
[build-system]
4852
requires = ["poetry>=0.12"]
4953
build-backend ="poetry.masonry.api"

‎tests/test_uniswap.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,17 @@
99
fromtimeimportsleep
1010

1111
fromweb3importWeb3
12-
fromweb3.exceptionsimportNameNotFound
1312

14-
fromuniswapimportUniswap,token
15-
fromuniswap.constantsimportETH_ADDRESS,WETH9_ADDRESS
13+
fromuniswapimportUniswap
14+
fromuniswap.constantsimportETH_ADDRESS
1615
fromuniswap.exceptionsimportInsufficientBalance
1716
fromuniswap.tokensimportget_tokens
1817
fromuniswap.utilimport (
1918
_str_to_addr,
2019
default_tick_range,
2120
_addr_to_str,
22-
_load_contract_erc20,
2321
)
2422

25-
2623
logger=logging.getLogger(__name__)
2724
logging.basicConfig(level=logging.INFO)
2825

@@ -35,6 +32,13 @@
3532
RECEIPT_TIMEOUT=5
3633

3734

35+
ONE_ETH=10**18
36+
ONE_DAI=10**18
37+
ONE_USDC=10**6
38+
39+
ZERO_ADDRESS="0x0000000000000000000000000000000000000000"
40+
41+
3842
@dataclass
3943
classGanacheInstance:
4044
provider:str
@@ -53,7 +57,7 @@ def client(request, web3: Web3, ganache: GanacheInstance):
5357
)
5458

5559

56-
@pytest.fixture(scope="function",params=UNISWAP_VERSIONS)
60+
@pytest.fixture(scope="function")
5761
deftokens(client:Uniswap):
5862
returnget_tokens(client.netname)
5963

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

68-
fortoken_name,amountin [("DAI",100*10**18), ("USDC",100*10**6)]:
72+
fortoken_name,amountin [
73+
("DAI",10_000*ONE_DAI),
74+
("USDC",10_000*ONE_USDC),
75+
]:
6976
token_addr=tokens[token_name]
7077
price=client.get_price_output(_str_to_addr(ETH_ADDRESS),token_addr,amount)
7178
logger.info(f"Cost of{amount}{token_name}:{price}")
7279
logger.info("Buying...")
7380

74-
tx=client.make_trade_output(tokens["ETH"],token_addr,amount)
75-
client.w3.eth.wait_for_transaction_receipt(tx,timeout=RECEIPT_TIMEOUT)
81+
txid=client.make_trade_output(tokens["ETH"],token_addr,amount)
82+
tx=client.w3.eth.wait_for_transaction_receipt(txid,timeout=RECEIPT_TIMEOUT)
83+
asserttx["status"]==1,f"Transaction failed:{tx}"
7684

7785

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

98106
port=10999
99-
defaultGasPrice=1000_000_000_000#1000 gwei
107+
defaultGasPrice=100_000_000_000#100 gwei
100108
p=subprocess.Popen(
101109
f"""ganache
102110
--port{port}
@@ -125,16 +133,9 @@ def does_not_raise():
125133
yield
126134

127135

128-
ONE_ETH=10**18
129-
ONE_USDC=10**6
130-
131-
ZERO_ADDRESS="0x0000000000000000000000000000000000000000"
132-
133-
134136
# TODO: Change pytest.param(..., mark=pytest.mark.xfail) to the expectation/raises method
135137
@pytest.mark.usefixtures("client","web3")
136138
classTestUniswap(object):
137-
138139
# ------ Exchange ------------------------------------------------------------------
139140
deftest_get_fee_maker(self,client:Uniswap):
140141
ifclient.versionnotin [1,2]:
@@ -343,7 +344,7 @@ def test_v3_deploy_pool_with_liquidity(
343344
amount1,
344345
tick_lower=min_tick,
345346
tick_upper=max_tick,
346-
deadline=2**64,
347+
deadline=2**64,
347348
)
348349
assertr["status"]
349350

@@ -357,7 +358,7 @@ def test_v3_deploy_pool_with_liquidity(
357358

358359
@pytest.mark.parametrize(
359360
"deadline",
360-
[(2**64)],
361+
[(2**64)],
361362
)
362363
deftest_close_position(self,client:Uniswap,deadline):
363364
ifclient.version!=3:
@@ -445,7 +446,7 @@ def test_make_trade(
445446

446447
txid=client.make_trade(input_token,output_token,qty,recipient)
447448
tx=web3.eth.wait_for_transaction_receipt(txid,timeout=RECEIPT_TIMEOUT)
448-
asserttx["status"]
449+
asserttx["status"],f"Transaction failed with status{tx['status']}:{tx}"
449450

450451
# TODO: Checks for ETH, taking gas into account
451452
bal_in_after=client.get_token_balance(input_token)
@@ -460,7 +461,7 @@ def test_make_trade(
460461
# Token -> Token
461462
("DAI","USDC",ONE_USDC,None,does_not_raise),
462463
# Token -> ETH
463-
("DAI","ETH",100*ONE_USDC,None,does_not_raise),
464+
("DAI","ETH",ONE_ETH//10,None,does_not_raise),
464465
# FIXME: These should probably be uncommented eventually
465466
# ("ETH", "UNI", int(0.000001 * ONE_ETH), ZERO_ADDRESS),
466467
# ("UNI", "ETH", int(0.000001 * ONE_ETH), ZERO_ADDRESS),

‎uniswap/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def _coerce_to_checksum(addr: str) -> str:
2828
raiseValueError(
2929
"token was not an address, and a shorthand was not found in the token db"
3030
)
31-
ifWeb3.isChecksumAddress(addr):
31+
ifWeb3.is_checksum_address(addr):
3232
returnaddr
3333
else:
34-
returnWeb3.toChecksumAddress(addr)
34+
returnWeb3.to_checksum_address(addr)
3535

3636

3737
@click.group()
@@ -71,7 +71,7 @@ def price(
7171
token_in:AddressLike,
7272
token_out:AddressLike,
7373
raw:bool,
74-
quantity:int=None,
74+
quantity:Optional[int]=None,
7575
)->None:
7676
"""Returns the price of ``quantity`` tokens of ``token_in`` quoted in ``token_out``."""
7777
uni:Uniswap=ctx.obj["UNISWAP"]

‎uniswap/tokens.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
tokens_mainnet:Dict[str,ChecksumAddress]= {
8-
k:Web3.toChecksumAddress(v)
8+
k:Web3.to_checksum_address(v)
99
fork,vin {
1010
"ETH":"0x0000000000000000000000000000000000000000",
1111
"WETH":"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
@@ -18,7 +18,7 @@
1818
}
1919

2020
tokens_rinkeby:Dict[str,ChecksumAddress]= {
21-
k:Web3.toChecksumAddress(v)
21+
k:Web3.to_checksum_address(v)
2222
fork,vin {
2323
"ETH":"0x0000000000000000000000000000000000000000",
2424
"DAI":"0x2448eE2641d78CC42D7AD76498917359D961A783",
@@ -27,7 +27,7 @@
2727
}
2828

2929
tokens_arbitrum:Dict[str,ChecksumAddress]= {
30-
k:Web3.toChecksumAddress(v)
30+
k:Web3.to_checksum_address(v)
3131
fork,vin {
3232
"ETH":"0x0000000000000000000000000000000000000000",
3333
"WETH":"0x82af49447d8a07e3bd95bd0d56f35241523fbab1",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp