Skip to content

Commit

Permalink
fix: Refactor fetch and process contract events
Browse files Browse the repository at this point in the history
  • Loading branch information
eugypalu committed Sep 16, 2024
1 parent 875d8a0 commit 9074c78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class NetworkType(Enum):
"check_interval": 1,
"max_wait": 60,
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
"voyager_api_url": "https://api.voyager.online/beta",
},
"sepolia": {
"name": "starknet-sepolia",
Expand All @@ -52,6 +53,7 @@ class NetworkType(Enum):
"check_interval": 1,
"max_wait": 10,
"class_hash": 0x061DAC032F228ABEF9C6626F995015233097AE253A7F72D68552DB02F2971B8F,
"voyager_api_url": "https://sepolia-api.voyager.online/beta",
},
"starknet-devnet": {
"name": "starknet-devnet",
Expand Down
28 changes: 21 additions & 7 deletions kakarot_scripts/withdraw_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import requests

from kakarot_scripts.constants import ETH_TOKEN_ADDRESS, NETWORK, RPC_CLIENT
from kakarot_scripts.utils.starknet import get_balance, get_declarations, invoke
from kakarot_scripts.utils.starknet import (
get_balance,
get_declarations,
get_deployments,
invoke,
)

logging.basicConfig()
logger = logging.getLogger(__name__)
Expand All @@ -15,20 +20,29 @@

# %% Fetch contract events
def get_contracts():
url = f"{os.getenv('VOYAGER_API_URL')}/events?ps=10&p=1&contract={os.getenv('KAKAROT_SEPOLIA_ACCOUNT_ADDRESS')}"
contract_address = hex(get_deployments()["kakarot"]["address"])
logger.info(f"ℹ️ Fetching contracts from {contract_address}")
url = f"{NETWORK['voyager_api_url']}/events?ps=10&p=1&contract={contract_address}"
headers = {
"accept": "application/json",
"x-api-key": os.getenv("VOYAGER_API_KEY"),
}
response = requests.get(url, headers=headers)
return [
{
"evm_address": "0x" + raw[2:22].hex(),
"starknet_address": "0x" + raw[23:].hex(),
"evm_address": next(
item["value"]
for item in event["dataDecoded"]
if item["name"] == "evm_contract_address"
),
"starknet_address": next(
item["value"]
for item in event["dataDecoded"]
if item["name"] == "starknet_contract_address"
),
}
for raw in (
bytes(contract["data"]["data"]) for contract in response.json()["items"]
)
for event in response.json()["items"]
if "name" in event and event["name"] == "evm_contract_deployed"
]


Expand Down

0 comments on commit 9074c78

Please sign in to comment.