Skip to content

Commit

Permalink
feat: integration web3-google-hsm module to sign txs using gcp HSM key (
Browse files Browse the repository at this point in the history
#271)

- Add: Google Cloud HSM hardware wallet support in `eth_defi.gcloud_hsm_wallet`
  • Loading branch information
Aviksaikat authored Jan 16, 2025
1 parent cf109a2 commit 0ca0156
Show file tree
Hide file tree
Showing 11 changed files with 1,664 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@ jobs:
JSON_RPC_ETHEREUM: ${{ secrets.JSON_RPC_ETHEREUM }}
JSON_RPC_BASE: ${{ secrets.JSON_RPC_BASE }}
ETHEREUM_JSON_RPC: ${{ secrets.JSON_RPC_ETHEREUM }}
GOOGLE_CLOUD_PROJECT: ${{ secrets.GOOGLE_CLOUD_PROJECT }}
GOOGLE_CLOUD_REGION: ${{ secrets.GOOGLE_CLOUD_REGION }}
KEY_RING: ${{ secrets.KEY_RING }}
KEY_NAME: ${{ secrets.KEY_NAME }}
GCP_ADC_CREDENTIALS_STRING: ${{ secrets.GCP_ADC_CREDENTIALS_STRING }}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Current

- Mainly needed for Lagoon vaults, but can work for others: vanilla Safe, DAOs
- Add: Google Cloud HSM hardware wallet support in `eth_defi.gcloud_hsm_wallet`
- Add Multicall3 support in `multicall_batcher` module
- Add `SwapRouter02` support on Base for doing Uniswap v3 swaps
- Add Uniswap V3 quoter for the valuation
Expand Down
1 change: 1 addition & 0 deletions docs/source/api/core/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ The core API is built on the top of Web3.py library.
eth_defi.timestamp
eth_defi.trade
eth_defi.utils
eth_defi.hsm_hotwallet
59 changes: 59 additions & 0 deletions eth_defi/basewallet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from abc import ABC, abstractmethod
from decimal import Decimal
from typing import Optional

from eth_typing import HexAddress
from web3 import Web3
from web3.contract.contract import ContractFunction

from eth_defi.hotwallet import SignedTransactionWithNonce


class BaseWallet(ABC):
"""Abstract base class for Ethereum wallets.
This interface defines the common contract that both HotWallet and HSM-based
wallets must implement.
"""

@property
@abstractmethod
def address(self) -> HexAddress:
"""Get the wallet's Ethereum address."""
pass

@abstractmethod
def get_main_address(self) -> HexAddress:
"""Get the main Ethereum address for this wallet."""
pass

@abstractmethod
def sync_nonce(self, web3: Web3) -> None:
"""Synchronize the nonce with the blockchain."""
pass

@abstractmethod
def allocate_nonce(self) -> int:
"""Get the next available nonce."""
pass

@abstractmethod
def sign_transaction_with_new_nonce(self, tx: dict) -> SignedTransactionWithNonce:
"""Sign a transaction with a new nonce."""
pass

@abstractmethod
def sign_bound_call_with_new_nonce(self, func: ContractFunction, tx_params: Optional[dict] = None) -> SignedTransactionWithNonce:
"""Sign a contract function call with a new nonce."""
pass

@abstractmethod
def get_native_currency_balance(self, web3: Web3) -> Decimal:
"""Get the wallet's native currency balance."""
pass

@staticmethod
@abstractmethod
def fill_in_gas_price(web3: Web3, tx: dict) -> dict:
"""Fill in gas price details for a transaction."""
pass
2 changes: 1 addition & 1 deletion eth_defi/confirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def wait_and_broadcast_multiple_nodes_mev_blocker(
max_timeout=datetime.timedelta(minutes=10),
poll_delay=datetime.timedelta(seconds=10),
broadcast_and_read_delay=datetime.timedelta(seconds=6),
try_other_provider_delay=datetime.timedelta(seconds=40),
try_other_provider_delay=datetime.timedelta(seconds=45),
) -> Dict[HexBytes, dict]:
"""Broadcast transactions through a MEV blocker enabled endpoint.
Expand Down
Loading

0 comments on commit 0ca0156

Please sign in to comment.