Skip to content

Commit 8599556

Browse files
committed
Add ether_rounding to evm_utils
1 parent a401698 commit 8599556

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/aleph/sdk/evm_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from decimal import Decimal
1+
from decimal import ROUND_CEILING, Decimal
22
from enum import Enum
33
from typing import List, Optional, Union
44

@@ -37,6 +37,11 @@ def to_wei_token(amount: Decimal) -> Decimal:
3737
return amount * Decimal(10) ** Decimal(settings.TOKEN_DECIMALS)
3838

3939

40+
def ether_rounding(amount: Decimal) -> Decimal:
41+
"""Rounds the given value to 18 decimals."""
42+
return amount.quantize(Decimal(1) / 10**18, rounding=ROUND_CEILING)
43+
44+
4045
def get_chain_id(chain: Union[Chain, str, None]) -> Optional[int]:
4146
"""Returns the CHAIN_ID of a given EVM blockchain"""
4247
if chain:

0 commit comments

Comments
 (0)