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

Commitac9545c

Browse files
authored
Merge pull request#388 from uniswap-python/master
1
2 parents0d2cb41 +4f15d2e commitac9545c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

‎uniswap/uniswap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ def approve(self, token: AddressLike, max_approval: Optional[int] = None) -> Non
14031403
tx=self._build_and_send_tx(function)
14041404
self.w3.eth.wait_for_transaction_receipt(tx,timeout=6000)
14051405

1406-
# Add extra sleep to let txpropogate correctly
1406+
# Add extra sleep to let txpropagate correctly
14071407
time.sleep(1)
14081408

14091409
def_is_approved(self,token:AddressLike)->bool:
@@ -1413,6 +1413,8 @@ def _is_approved(self, token: AddressLike) -> bool:
14131413
contract_addr=self._exchange_address_from_token(token)
14141414
elifself.versionin [2,3]:
14151415
contract_addr=self.router_address
1416+
else:
1417+
raiseValueError
14161418
amount= (
14171419
_load_contract_erc20(self.w3,token)
14181420
.functions.allowance(self.address,contract_addr)

‎uniswap/util.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,39 @@ def encode_sqrt_ratioX96(amount_0: int, amount_1: int) -> int:
103103
returnint(math.sqrt(ratioX192))
104104

105105

106+
defdecode_sqrt_ratioX96(sqrtPriceX96:int)->float:
107+
Q96=2**96
108+
ratio=sqrtPriceX96/Q96
109+
price=ratio**2
110+
returnprice
111+
112+
113+
defget_tick_at_sqrt(sqrtPriceX96:int)->int:
114+
sqrtPriceX96=int(sqrtPriceX96)
115+
116+
# Define constants
117+
Q96=2**96
118+
119+
# Calculate the price from the sqrt ratio
120+
ratio=sqrtPriceX96/Q96
121+
price=ratio**2
122+
123+
# Calculate the natural logarithm of the price
124+
logPrice=math.log(price)
125+
126+
# Calculate the log base 1.0001 of the price
127+
logBase=math.log(1.0001)
128+
tick=logPrice/logBase
129+
130+
# Round tick to nearest integer
131+
tick=int(round(tick))
132+
133+
# Ensure the tick is within the valid range
134+
asserttick>=MIN_TICKandtick<=MAX_TICK
135+
136+
returntick
137+
138+
106139
# Adapted from: https://github.com/tradingstrategy-ai/web3-ethereum-defi/blob/c3c68bc723d55dda0cc8252a0dadb534c4fdb2c5/eth_defi/uniswap_v3/utils.py#L77
107140
defget_min_tick(fee:int)->int:
108141
min_tick_spacing:int=_tick_spacing[fee]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp