Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scripts/utils/chain_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def has_evm_addresses(self):
def get_asset_by_symbol(self, symbol: str) -> ChainAsset:
return next((a for a in self.assets if a.symbol == symbol))

def get_asset_by_symbol_or_null(self, symbol: str) -> ChainAsset | None:
return next((a for a in self.assets if a.symbol == symbol), None)

def get_asset_by_id(self, id: int) -> ChainAsset:
return next((a for a in self.assets if a.id == id))

Expand Down Expand Up @@ -160,8 +163,12 @@ def __init__(self, data: dict, chain: Chain, chain_cache: dict):
def __getitem__(self, item):
return self._data[item]

@staticmethod
def unify_symbol(symbol: str) -> str:
return symbol.removeprefix("xc")

def unified_symbol(self) -> str:
return self.symbol.removeprefix("xc")
return self.unify_symbol(self.symbol)

def planks(self, amount: int | float) -> int:
return int(amount * 10 ** self.precision)
Expand Down
2 changes: 2 additions & 0 deletions scripts/xcm_transfers/config_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_xcm_config_files() -> XCMConfigFiles:
xcm_stable_legacy_config=f"xcm/v6/transfers.json",
xcm_additional_data="scripts/xcm_transfers/xcm_registry_additional_data.json",
xcm_dynamic_config=f"xcm/{XCM_VERSION}/transfers_dynamic.json",
general_config=f"../../xcm/{XCM_VERSION}/xcm_general_config.json",
)
else:
print("Running in development mode")
Expand All @@ -25,4 +26,5 @@ def get_xcm_config_files() -> XCMConfigFiles:
xcm_stable_legacy_config=f"xcm/v6/transfers_dev.json",
xcm_additional_data="scripts/xcm_transfers/xcm_registry_additional_data.json",
xcm_dynamic_config=f"xcm/{XCM_VERSION}/transfers_dynamic_dev.json",
general_config=f"../../xcm/{XCM_VERSION}/xcm_general_config_dev.json",
)
45 changes: 45 additions & 0 deletions scripts/xcm_transfers/one_time/add_global_consensus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json

from eth_typing import ChainId

from scripts.utils.chain_model import Chain
from scripts.utils.work_with_data import get_data_from_file, write_data_to_file
from scripts.xcm_transfers.config_setup import get_xcm_config_files

config_files = get_xcm_config_files()
general_config = get_data_from_file(config_files.general_config)

chains_file = get_data_from_file(config_files.chains)
chains = [Chain(it) for it in chains_file]

def find_chain(chainId: ChainId) -> Chain:
return next((chain for chain in chains if chain.chainId == chainId))

def get_consensus_root(chainId: ChainId) -> Chain:
chain = find_chain(chainId)
if chain.parentId is None:
return chain

parent = find_chain(chain.parentId)
return parent

def construct_global_consensus_arg(consensus_root: Chain):
match consensus_root.chainId:
case "91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3":
return "Polkadot"
case "b0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe":
return "Kusama"
case _:
return { "ByGenesis": consensus_root.chainId }

for location in general_config["assets"]["assetsLocation"].values():
chain_id = location["chainId"]

consensus_root = get_consensus_root(chain_id)
consensus_arg = construct_global_consensus_arg(consensus_root)

location_items = list(location["multiLocation"].items())
location_items.insert(0, ("globalConsensus", consensus_arg))
location["multiLocation"] = dict(location_items)

write_data_to_file(config_files.general_config, json.dumps(general_config, indent=2))
29 changes: 20 additions & 9 deletions scripts/xcm_transfers/sync_xcm_preliminary_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

data = {}

general_xcm_config = get_data_from_file(config_files.general_config)
general_xcm_config_data = {}

def get_runtime_prefix(substrate: SubstrateInterface) -> str | None:
registry = substrate.get_type_registry(substrate.block_hash)

Expand Down Expand Up @@ -85,11 +88,28 @@ def construct_v1_dry_run_method_data(substrate: SubstrateInterface, runtime_pref
method_data = origin_caller + call
return method_data.to_hex()

def write_general_xcm_config():
general_xcm_config["chains"]["parachainIds"] = general_xcm_config_data
write_data_to_file(config_files.general_config, json.dumps(general_xcm_config, indent=2))

def process_chain(idx, chain, len):
print(f"\n{idx + 1}/{len}. Starting fetching data for {chain.name}")

chain.create_connection()

parachainId = None

if chain.parentId is not None:
try:
parachainId = chain.substrate.query("ParachainInfo", "ParachainId").value
except Exception as e:
print(f"Failed to fetch ParachainId for {chain.name} due to {e}, skipping")
return

if parachainId is not None:
general_xcm_config_data[chain.chainId] = parachainId
write_general_xcm_config()

try:
runtime_prefix = get_runtime_prefix(chain.substrate)
if runtime_prefix is None:
Expand All @@ -116,15 +136,6 @@ def process_chain(idx, chain, len):
xcm_payment_api_presence = determine_xcm_payment_api_presence(chain.substrate)
print(f"{chain.name} xcm payment api presence: {xcm_payment_api_presence}")

parachainId = None

if chain.parentId is not None:
try:
parachainId = chain.substrate.query("ParachainInfo", "ParachainId").value
except Exception as e:
print(f"Failed to fetch ParachainId for {chain.name} due to {e}, skipping")
return

parachain_info = {
"parachainId": parachainId,
"runtimePrefix": runtime_prefix,
Expand Down
2 changes: 2 additions & 0 deletions scripts/xcm_transfers/utils/xcm_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ class XCMConfigFiles(object):
xcm_dynamic_config: str

xcm_additional_data: str

general_config: str
Loading
Loading