5
5
6
6
from eth_utils import to_normalized_address
7
7
from superfluid import CFA_V1 , Operation , Web3FlowInfo
8
+ from web3 .exceptions import ContractCustomError
8
9
9
10
from aleph .sdk .evm_utils import (
10
11
FlowUpdate ,
@@ -52,7 +53,15 @@ def _simulate_create_tx_flow(self, flow: Decimal, block=True) -> bool:
52
53
self .account .rpc , self .account ._account .key
53
54
)
54
55
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
+ )
56
65
return False
57
66
58
67
async def _execute_operation_with_account (self , operation : Operation ) -> str :
@@ -70,18 +79,8 @@ async def _execute_operation_with_account(self, operation: Operation) -> str:
70
79
71
80
def can_start_flow (self , flow : Decimal , block = True ) -> bool :
72
81
"""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
+
85
84
86
85
async def create_flow (self , receiver : str , flow : Decimal ) -> str :
87
86
"""Create a Superfluid flow between two addresses."""
0 commit comments