Skip to content
Merged
Changes from 1 commit
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
Next Next commit
feat: added util functions for fee calculations
  • Loading branch information
Voyz committed Mar 18, 2023
commit a1b1083f64605ff3815dc9a991da99c37018eb50
17 changes: 17 additions & 0 deletions uniswap/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,20 @@ def nearest_tick(tick: int, fee: int) -> int:
def chunks(arr: Sequence[Any], n: int) -> Generator:
for i in range(0, len(arr), n):
yield arr[i : i + n]

def fee_to_fraction(fee:int):
return fee / 1000000

def fraction_to_fee(fraction:float):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unused

return fraction * 1000000

def realised_fee_percentage(fee:int, amount_in:int) -> float:
"""
Calculate realised fee expressed as a percentage of the amount_in.
The realised fee is rounded up as fractional units cannot be used -
this correlates to how the fees are rounded by Uniswap.
"""

fee_percentage = fee_to_fraction(fee)
fee_realised = math.ceil(amount_in * fee_percentage)
return fee_realised / amount_in