Skip to content

Commit

Permalink
Updated the contract ABI fetching script to retrieve the implementati…
Browse files Browse the repository at this point in the history
…on (#35)
  • Loading branch information
volod-vana authored Oct 16, 2024
1 parent 06416fb commit e57e769
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions vana/contracts/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@
import os

import requests
from web3 import Web3

import vana
from vana.contracts import contracts


def fetch_and_save_contract_abi(network, contract_name, contract_hash):
try:
BASE_URL = f"https://api.{network}.vanascan.io/api/v2/smart-contracts"
base_url = f"https://api.{network}.vanascan.io/api/v2/smart-contracts"
rpc_url = f"https://rpc.{network}.vana.org"

# Get details about the proxy contract
proxy_response = requests.get(f"{BASE_URL}/{contract_hash}")
proxy_response.raise_for_status()
implementation_address = proxy_response.json()["decoded_constructor_args"][0][0]
# Connect to the network
w3 = Web3(Web3.HTTPProvider(rpc_url))

# ERC1967 implementation slot
implementation_slot = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'

# Get the implementation address
implementation_address = w3.eth.get_storage_at(contract_hash, implementation_slot)
# If address is 0x0000...0000, it means the contract is not a proxy, use its address as implementation address
implementation_address = '0x' + implementation_address.hex()[-40:] if implementation_address != b'\x00' * 32 else contract_hash

# Fetch ABI from the implementation
implementation_response = requests.get(f"{BASE_URL}/{implementation_address}")
implementation_response = requests.get(f"{base_url}/{implementation_address}")
implementation_response.raise_for_status()

# Extract the ABI from the response
Expand All @@ -39,7 +47,7 @@ def fetch_and_save_contract_abi(network, contract_name, contract_hash):


def update_contract_abis():
network = os.environ.get("CHAIN_NETWORK", "satori")
network = os.environ.get("CHAIN_NETWORK", "moksha")
if network not in contracts:
network = "satori"

Expand Down

0 comments on commit e57e769

Please sign in to comment.