55
66from eth_utils import to_normalized_address
77from superfluid import CFA_V1 , Operation , Web3FlowInfo
8+ from web3 .exceptions import ContractCustomError
89
910from aleph .sdk .evm_utils import (
1011 FlowUpdate ,
@@ -52,7 +53,15 @@ def _simulate_create_tx_flow(self, flow: Decimal, block=True) -> bool:
5253 self .account .rpc , self .account ._account .key
5354 )
5455 return self .account .can_transact (tx = populated_transaction , block = block )
55- except Exception :
56+ except ContractCustomError as e :
57+ if getattr (e , "data" , None ) == "0xea76c9b3" :
58+ balance = self .account .get_super_token_balance ()
59+ MIN_FLOW_4H = to_wei_token (flow ) * Decimal (self .MIN_4_HOURS )
60+ raise InsufficientFundsError (
61+ token_type = TokenType .ALEPH ,
62+ required_funds = float (from_wei_token (MIN_FLOW_4H )),
63+ available_funds = float (from_wei_token (balance )),
64+ )
5665 return False
5766
5867 async def _execute_operation_with_account (self , operation : Operation ) -> str :
@@ -70,18 +79,8 @@ async def _execute_operation_with_account(self, operation: Operation) -> str:
7079
7180 def can_start_flow (self , flow : Decimal , block = True ) -> bool :
7281 """Check if the account has enough funds to start a Superfluid flow of the given size."""
73- valid = False
74- if self ._simulate_create_tx_flow (flow = flow , block = block ):
75- balance = self .account .get_super_token_balance ()
76- MIN_FLOW_4H = to_wei_token (flow ) * Decimal (self .MIN_4_HOURS )
77- valid = balance > MIN_FLOW_4H
78- if not valid and block :
79- raise InsufficientFundsError (
80- token_type = TokenType .ALEPH ,
81- required_funds = float (from_wei_token (MIN_FLOW_4H )),
82- available_funds = float (from_wei_token (balance )),
83- )
84- return valid
82+ return self ._simulate_create_tx_flow (flow = flow , block = block )
83+
8584
8685 async def create_flow (self , receiver : str , flow : Decimal ) -> str :
8786 """Create a Superfluid flow between two addresses."""
0 commit comments