Skip to content

Commit

Permalink
Wait for multisig txs (#1485)
Browse files Browse the repository at this point in the history
- **Add wait_for_tx for multisig**
- **Add env var for relayers**
- **Deploy WETH and Coinbase only if required**

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1485)
<!-- Reviewable:end -->
  • Loading branch information
ClementWalter authored Oct 9, 2024
1 parent fe599c6 commit 4ee7e44
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ SHARINGAN_RPC_URL="https://sharingan.madara.zone"
STARKNET_DEVNET_ACCOUNT_ADDRESS=0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691
STARKNET_DEVNET_PRIVATE_KEY=0x71d7bb07b9a64f6f78ac4c816aff4da9

STARKNET_SEPOLIA_RELAYER_ACCOUNT_ADDRESS=
STARKNET_SEPOLIA_RELAYER_PRIVATE_KEY=
STARKNET_SEPOLIA_ACCOUNT_ADDRESS=
STARKNET_SEPOLIA_PRIVATE_KEY=

KATANA_ACCOUNT_ADDRESS=0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca
KATANA_PRIVATE_KEY=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a

Expand Down
37 changes: 21 additions & 16 deletions kakarot_scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,27 @@ def __next__(self) -> Account:
return relayer


NETWORK["relayers"] = RelayerPool(
NETWORK.get(
"relayers",
(
[
{
"address": int(NETWORK["account_address"], 16),
"private_key": int(NETWORK["private_key"], 16),
}
]
if NETWORK["account_address"] is not None
and NETWORK["private_key"] is not None
else []
),
)
)
if (
os.getenv(f"{prefix}_RELAYER_ACCOUNT_ADDRESS") is not None
and os.getenv(f"{prefix}_RELAYER_PRIVATE_KEY") is not None
):
default_relayer = {
"address": int(os.environ[f"{prefix}_RELAYER_ACCOUNT_ADDRESS"], 16),
"private_key": int(os.environ[f"{prefix}_RELAYER_PRIVATE_KEY"], 16),
}
elif NETWORK["account_address"] is not None and NETWORK["private_key"] is not None:
default_relayer = {
"address": int(NETWORK["account_address"], 16),
"private_key": int(NETWORK["private_key"], 16),
}
else:
default_relayer = None

if default_relayer is None and NETWORK.get("relayers") is None:
raise ValueError("No account nor relayers defined for this network")

NETWORK["relayers"] = RelayerPool(NETWORK.get("relayers", [default_relayer]))


logger.info(
f"ℹ️ Connected to Starknet chain id {bytes.fromhex(f'{ChainId.starknet_chain_id.value:x}')} "
Expand Down
41 changes: 27 additions & 14 deletions kakarot_scripts/deploy_kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,40 @@ async def main():
EVM_ADDRESS, amount=100 if NETWORK["type"] is NetworkType.DEV else 0.01
)

bridge = await deploy_evm("CairoPrecompiles", "EthStarknetBridge")
evm_deployments["Bridge"] = {
"address": int(bridge.address, 16),
"starknet_address": bridge.starknet_address,
}
await invoke(
"kakarot", "set_authorized_cairo_precompile_caller", int(bridge.address, 16), 1
)
await invoke("kakarot", "set_coinbase", int(bridge.address, 16))
coinbase = (await call("kakarot", "get_coinbase")).coinbase
if evm_deployments.get("Bridge", {}).get("address") != coinbase:
bridge = await deploy_evm("CairoPrecompiles", "EthStarknetBridge")
evm_deployments["Bridge"] = {
"address": int(bridge.address, 16),
"starknet_address": bridge.starknet_address,
}
await invoke(
"kakarot",
"set_authorized_cairo_precompile_caller",
int(bridge.address, 16),
1,
)
await invoke("kakarot", "set_coinbase", int(bridge.address, 16))

coinbase = (await call("kakarot", "get_coinbase")).coinbase
if coinbase == 0:
logger.error("❌ Coinbase is set to 0, all transaction fees will be lost")
else:
logger.info(f"✅ Coinbase set to: 0x{coinbase:040x}")

weth = await deploy_evm("WETH", "WETH9")
evm_deployments["WETH"] = {
"address": int(weth.address, 16),
"starknet_address": weth.starknet_address,
}
weth_starknet_address = (
await call(
"kakarot",
"get_starknet_address",
evm_deployments.get("WETH", {}).get("address", 0),
)
).starknet_address
if evm_deployments.get("WETH", {}).get("starknet_address") != weth_starknet_address:
weth = await deploy_evm("WETH", "WETH9")
evm_deployments["WETH"] = {
"address": int(weth.address, 16),
"starknet_address": weth.starknet_address,
}

dump_evm_deployments(evm_deployments)
balance_after = await get_balance(account.address)
Expand Down
22 changes: 11 additions & 11 deletions kakarot_scripts/utils/kakarot.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,6 @@ async def send_pre_eip155_transaction(
await _invoke_starknet(
"kakarot", "set_authorized_pre_eip155_tx", int(evm_address, 16), msg_hash
)
nonce = (
await _call_starknet("account_contract", "get_nonce", address=starknet_address)
).nonce
if nonce != 0:
logger.info(
f"ℹ️ Nonce for {evm_address} is not 0 ({nonce}), skipping transaction"
)
return

if WEB3.is_connected():
tx_hash = WEB3.eth.send_raw_transaction(signed_tx)
Expand Down Expand Up @@ -754,12 +746,20 @@ async def deploy_with_presigned_tx(
deployer_starknet_address = await deploy_and_fund_evm_address(
deployer_evm_address, amount
)
nonce = (
await _call_starknet(
"account_contract", "get_nonce", address=deployer_starknet_address
)
).nonce
if nonce != 0:
logger.info(
f"ℹ️ Nonce for {deployer_evm_address} is not 0 ({nonce}), skipping transaction"
)
return

response = await send_pre_eip155_transaction(
deployer_evm_address, deployer_starknet_address, signed_tx, max_fee
)
if response is None:
logger.info("ℹ️ Transaction already executed")
return

receipt, response, success, gas_used = response
deployed_address = response[1]
Expand Down
23 changes: 20 additions & 3 deletions kakarot_scripts/utils/starknet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import functools
import json
import logging
Expand Down Expand Up @@ -147,7 +148,6 @@ async def get_starknet_account(
f"Public key of account 0x{address:064x} is not consistent with provided private key"
)
if len(public_keys) > 1:
register_lazy_account(address)
register_multisig_account(address)
logger.info("ℹ️ Account is a multisig")
else:
Expand Down Expand Up @@ -611,9 +611,26 @@ async def execute_v1(account, calls):
f"{NETWORK['argent_multisig_api']}/0x{account.address:064x}/request",
json=data,
)
content = response.json()["content"]
transaction_id = content["id"]
status = content["state"]
while status not in {"TX_ACCEPTED_L2", "REVERTED"}:
response = requests.get(
f"{NETWORK['argent_multisig_api']}/0x{account.address:064x}/request"
)
contents = [
content
for content in response.json()["content"]
if content["id"] == transaction_id
]
if len(contents) == 0:
raise Exception("Transaction not found")
content = contents[0]
status = content["state"]
await asyncio.sleep(5)
return {
"transaction_hash": response.json()["content"]["transactionHash"],
"status": response.json()["content"]["state"],
"transaction_hash": content["transactionHash"],
"status": content["state"],
}

params = _create_broadcasted_txn(transaction=transaction)
Expand Down

0 comments on commit 4ee7e44

Please sign in to comment.