Skip to content

Commit cde1e2f

Browse files
committed
Feature: Implemented new EVM chains.
1 parent d54e9ac commit cde1e2f

File tree

6 files changed

+131
-10
lines changed

6 files changed

+131
-10
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ dynamic = [ "version" ]
3030
dependencies = [
3131
"aiohttp>=3.8.3",
3232
"aioresponses>=0.7.6",
33-
"aleph-message>=0.4.9",
33+
"aleph-message @ git+https://github.com/aleph-im/aleph-message.git@andres-feature-add_new_evm_chains",
3434
"aleph-superfluid>=0.2.1",
35-
"base58==2.1.1", # Needed now as default with _load_account changement
35+
"base58==2.1.1", # Needed now as default with _load_account changement
3636
"coincurve; python_version<'3.11'",
3737
"coincurve>=19; python_version>='3.11'",
3838
"eth-abi>=4; python_version>='3.11'",
3939
"eth-typing==4.3.1",
4040
"jwcrypto==1.5.6",
41-
"pynacl==1.5", # Needed now as default with _load_account changement
41+
"pynacl==1.5", # Needed now as default with _load_account changement
4242
"python-magic",
4343
"typing-extensions",
4444
"web3==6.3",

src/aleph/sdk/account.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77

88
from aleph.sdk.chains.common import get_fallback_private_key
99
from aleph.sdk.chains.ethereum import ETHAccount
10+
from aleph.sdk.chains.evm import EVMAccount
1011
from aleph.sdk.chains.remote import RemoteAccount
1112
from aleph.sdk.chains.solana import SOLAccount
13+
from aleph.sdk.chains.substrate import DOTAccount
1214
from aleph.sdk.conf import load_main_configuration, settings
1315
from aleph.sdk.evm_utils import get_chains_with_super_token
1416
from aleph.sdk.types import AccountFromPrivateKey
@@ -18,10 +20,24 @@
1820
T = TypeVar("T", bound=AccountFromPrivateKey)
1921

2022
chain_account_map: Dict[Chain, Type[T]] = { # type: ignore
21-
Chain.ETH: ETHAccount,
23+
Chain.ARBITRUM: EVMAccount,
2224
Chain.AVAX: ETHAccount,
2325
Chain.BASE: ETHAccount,
26+
Chain.BLAST: EVMAccount,
27+
Chain.BOB: EVMAccount,
28+
Chain.CYBER: EVMAccount,
29+
Chain.DOT: DOTAccount,
30+
Chain.ETH: ETHAccount,
31+
Chain.FRAXTAL: EVMAccount,
32+
Chain.LINEA: EVMAccount,
33+
Chain.LISK: EVMAccount,
34+
Chain.METIS: EVMAccount,
35+
Chain.MODE: EVMAccount,
36+
Chain.OPTIMISM: EVMAccount,
37+
Chain.POL: EVMAccount,
2438
Chain.SOL: SOLAccount,
39+
Chain.WORLDCHAIN: EVMAccount,
40+
Chain.ZORA: EVMAccount,
2541
}
2642

2743

src/aleph/sdk/chains/evm.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from decimal import Decimal
2+
from pathlib import Path
3+
from typing import Awaitable, Optional
4+
5+
from aleph_message.models import Chain
6+
from eth_account import Account # type: ignore
7+
8+
from .common import get_fallback_private_key
9+
from .ethereum import ETHAccount
10+
11+
12+
class EVMAccount(ETHAccount):
13+
def __init__(self, private_key: bytes, chain: Optional[Chain] = None):
14+
super().__init__(private_key, chain)
15+
if chain:
16+
self.CHAIN = chain.value
17+
18+
@staticmethod
19+
def from_mnemonic(mnemonic: str, chain: Optional[Chain] = None) -> "EVMAccount":
20+
Account.enable_unaudited_hdwallet_features()
21+
return EVMAccount(
22+
private_key=Account.from_mnemonic(mnemonic=mnemonic).key, chain=chain
23+
)
24+
25+
def get_token_balance(self) -> Decimal:
26+
raise ValueError(f"Token not implemented for this chain {self.CHAIN}")
27+
28+
def get_super_token_balance(self) -> Decimal:
29+
raise ValueError(f"Super token not implemented for this chain {self.CHAIN}")
30+
31+
def create_flow(self, receiver: str, flow: Decimal) -> Awaitable[str]:
32+
raise ValueError(f"Flow creation not implemented for this chain {self.CHAIN}")
33+
34+
def get_flow(self, receiver: str):
35+
raise ValueError(f"Get flow not implemented for this chain {self.CHAIN}")
36+
37+
def update_flow(self, receiver: str, flow: Decimal) -> Awaitable[str]:
38+
raise ValueError(f"Flow update not implemented for this chain {self.CHAIN}")
39+
40+
def delete_flow(self, receiver: str) -> Awaitable[str]:
41+
raise ValueError(f"Flow deletion not implemented for this chain {self.CHAIN}")
42+
43+
44+
def get_fallback_account(
45+
path: Optional[Path] = None, chain: Optional[Chain] = None
46+
) -> ETHAccount:
47+
return ETHAccount(private_key=get_fallback_private_key(path=path), chain=chain)

src/aleph/sdk/conf.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ class Settings(BaseSettings):
9999
active=False,
100100
),
101101
# MAINNETS
102-
Chain.ETH: ChainInfo(
103-
chain_id=1,
104-
rpc="https://eth-mainnet.public.blastapi.io",
105-
token="0x27702a26126e0B3702af63Ee09aC4d1A084EF628",
102+
Chain.ARBITRUM: ChainInfo(
103+
chain_id=42161,
104+
rpc="https://arbitrum-one.publicnode.com",
106105
),
107106
Chain.AVAX: ChainInfo(
108107
chain_id=43114,
@@ -116,12 +115,65 @@ class Settings(BaseSettings):
116115
token="0xc0Fbc4967259786C743361a5885ef49380473dCF",
117116
super_token="0xc0Fbc4967259786C743361a5885ef49380473dCF",
118117
),
118+
Chain.BLAST: ChainInfo(
119+
chain_id=81457,
120+
rpc="https://blastl2-mainnet.public.blastapi.io",
121+
),
122+
Chain.BOB: ChainInfo(
123+
chain_id=60808,
124+
rpc="https://bob-mainnet.public.blastapi.io",
125+
),
119126
Chain.BSC: ChainInfo(
120127
chain_id=56,
121128
rpc="https://binance.llamarpc.com",
122129
token="0x82D2f8E02Afb160Dd5A480a617692e62de9038C4",
123130
active=False,
124131
),
132+
Chain.CYBER: ChainInfo(
133+
chain_id=7560,
134+
rpc="https://rpc.cyber.co",
135+
),
136+
Chain.ETH: ChainInfo(
137+
chain_id=1,
138+
rpc="https://eth-mainnet.public.blastapi.io",
139+
token="0x27702a26126e0B3702af63Ee09aC4d1A084EF628",
140+
),
141+
Chain.FRAXTAL: ChainInfo(
142+
chain_id=252,
143+
rpc="https://rpc.frax.com",
144+
),
145+
Chain.LINEA: ChainInfo(
146+
chain_id=59144,
147+
rpc="https://linea-rpc.publicnode.com",
148+
),
149+
Chain.LISK: ChainInfo(
150+
chain_id=1135,
151+
rpc="https://rpc.api.lisk.com",
152+
),
153+
Chain.METIS: ChainInfo(
154+
chain_id=1088,
155+
rpc="https://metis.drpc.org",
156+
),
157+
Chain.MODE: ChainInfo(
158+
chain_id=34443,
159+
rpc="https://mode.drpc.org",
160+
),
161+
Chain.OPTIMISM: ChainInfo(
162+
chain_id=10,
163+
rpc="https://optimism-rpc.publicnode.com",
164+
),
165+
Chain.POL: ChainInfo(
166+
chain_id=137,
167+
rpc="https://polygon.gateway.tenderly.co",
168+
),
169+
Chain.WORLDCHAIN: ChainInfo(
170+
chain_id=480,
171+
rpc="https://worldchain-mainnet.gateway.tenderly.co",
172+
),
173+
Chain.ZORA: ChainInfo(
174+
chain_id=7777777,
175+
rpc="https://rpc.zora.energy/",
176+
),
125177
}
126178
# Add all placeholders to allow easy dynamic setup of CHAINS
127179
CHAINS_SEPOLIA_ACTIVE: Optional[bool]

src/aleph/sdk/evm_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ def get_super_token_address(
7979
return None
8080

8181

82-
def get_chains_with_holding() -> List[Union[Chain, str]]:
82+
def get_compatible_chains() -> List[Union[Chain, str]]:
8383
return [chain for chain, info in settings.CHAINS.items() if info.active]
8484

8585

86+
def get_chains_with_holding() -> List[Union[Chain, str]]:
87+
return [
88+
chain for chain, info in settings.CHAINS.items() if info.active and info.token
89+
]
90+
91+
8692
def get_chains_with_super_token() -> List[Union[Chain, str]]:
8793
return [
8894
chain

src/aleph/sdk/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ class ChainInfo(BaseModel):
7777

7878
chain_id: int
7979
rpc: str
80-
token: str
80+
token: Optional[str] = None
8181
super_token: Optional[str] = None
8282
active: bool = True

0 commit comments

Comments
 (0)