Skip to content

Commit

Permalink
fix: try using api
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Feb 22, 2024
1 parent f9618ff commit e3f594a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions ape_safe/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ def create_client(self, key: str) -> BaseSafeClient:
return safe.client

elif key in self.addresses:
return self[cast(AddressType, key)].client
account = cast(SafeAccount, self[cast(AddressType, key)])
return account.client

elif key in self.aliases:
return self.load_account(key).client

else:
address = self.conversion_manager.convert(key, AddressType)
if address in self.addresses:
return self[cast(AddressType, key)].client
account = cast(SafeAccount, self[cast(AddressType, key)])
return account.client

# Is not locally managed.
return SafeClient(address=address, chain_id=self.chain_manager.provider.chain_id)
Expand Down Expand Up @@ -457,13 +459,15 @@ def load_submitter(

def prepare_transaction(self, txn: TransactionAPI) -> TransactionAPI:
# NOTE: Need to override `AccountAPI` behavior for balance checks
txn.gas_limit = 1
txn.gas_limit = self.estimate_gas_cost(txn=txn)
return self.provider.prepare_transaction(txn)

def estimate_gas_cost(self, **kwargs) -> int:
operation = kwargs.pop("operation", 0)
txn = self.as_transaction(**kwargs)
self.client.estimate_gas_cost(txn.receiver, txn.value, txn.data, operation=operation)
txn = kwargs.pop("txn", self.as_transaction(**kwargs))
return self.client.estimate_gas_cost(
txn.receiver or ZERO_ADDRESS, txn.value, txn.data, operation=operation
)

def _preapproved_signature(
self, signer: Union[AddressType, BaseAddress, str]
Expand Down
4 changes: 2 additions & 2 deletions ape_safe/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def estimate_gas_cost(
self, receiver: AddressType, value: int, data: bytes, operation: int = 0
) -> int:
url = f"safes/{self.address}/multsig-transactions/estimations"
data = {
request: Dict = {
"to": receiver,
"value": value,
"data": HexBytes(data).hex(),
"operation": operation,
}
result = self._post(url, json=data).json()
result = self._post(url, json=request).json()
gas = result.get("safeTxGas")
return int(HexBytes(gas).hex(), 16)

Expand Down

0 comments on commit e3f594a

Please sign in to comment.