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

1#388

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
liquid-8 merged 3 commits intodev/v4frommaster
Jun 5, 2024
Merged

1#388

Show file tree
Hide file tree
Changes fromall 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
4 changes: 3 additions & 1 deletionuniswap/uniswap.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1403,7 +1403,7 @@ def approve(self, token: AddressLike, max_approval: Optional[int] = None) -> Non
tx = self._build_and_send_tx(function)
self.w3.eth.wait_for_transaction_receipt(tx, timeout=6000)

# Add extra sleep to let txpropogate correctly
# Add extra sleep to let txpropagate correctly
time.sleep(1)

def _is_approved(self, token: AddressLike) -> bool:
Expand All@@ -1413,6 +1413,8 @@ def _is_approved(self, token: AddressLike) -> bool:
contract_addr = self._exchange_address_from_token(token)
elif self.version in [2, 3]:
contract_addr = self.router_address
else:
raise ValueError
amount = (
_load_contract_erc20(self.w3, token)
.functions.allowance(self.address, contract_addr)
Expand Down
33 changes: 33 additions & 0 deletionsuniswap/util.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -99,6 +99,39 @@ def encode_sqrt_ratioX96(amount_0: int, amount_1: int) -> int:
return int(math.sqrt(ratioX192))


def decode_sqrt_ratioX96(sqrtPriceX96: int) -> float:
Q96 = 2**96
ratio = sqrtPriceX96 / Q96
price = ratio**2
return price


def get_tick_at_sqrt(sqrtPriceX96: int) -> int:
sqrtPriceX96 = int(sqrtPriceX96)

# Define constants
Q96 = 2**96

# Calculate the price from the sqrt ratio
ratio = sqrtPriceX96 / Q96
price = ratio**2

# Calculate the natural logarithm of the price
logPrice = math.log(price)

# Calculate the log base 1.0001 of the price
logBase = math.log(1.0001)
tick = logPrice / logBase

# Round tick to nearest integer
tick = int(round(tick))

# Ensure the tick is within the valid range
assert tick >= MIN_TICK and tick <= MAX_TICK

return tick


# Adapted from: https://github.com/tradingstrategy-ai/web3-ethereum-defi/blob/c3c68bc723d55dda0cc8252a0dadb534c4fdb2c5/eth_defi/uniswap_v3/utils.py#L77
def get_min_tick(fee: int) -> int:
min_tick_spacing: int = _tick_spacing[fee]
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp