This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmulticall.py
72 lines (56 loc) · 2.25 KB
/
multicall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
import json
import asyncio
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)) + "/../tutorial")
from console import blue_strong, blue, red
from utils import compile_deploy, invoke_tx_hash, print_n_wait, fund_account, get_evaluator, get_client, get_account
from starkware.starknet.public.abi import get_selector_from_name
from starkware.crypto.signature.signature import private_to_stark_key, sign
from starknet_py.net.models import InvokeFunction
with open(os.path.abspath(os.path.dirname(__file__)) + "/../config.json", "r") as f:
data = json.load(f)
async def main():
blue_strong.print("Your mission:")
blue.print("\t 1) implement account execution similar to OpenZeppelin w/ AccountCallArray")
blue.print("\t 2) deploy account contract")
blue.print("\t 3) format and sign invocations and calldata")
blue.print("\t 4) invoke multiple contracts in the same block\n")
private_key = data['PRIVATE_KEY']
stark_key = private_to_stark_key(private_key)
client = get_account(get_client())
multicall, multicall_addr = await compile_deploy(client=client, contract=data['MULTICALL'], args=[stark_key], account=True)
reward_account = await fund_account(multicall_addr)
if reward_account == "":
red.print("Account must have ETH to cover transaction fees")
return
_, evaluator_address = await get_evaluator(client)
#
# Format calldata
#
selector = get_selector_from_name("validate_multicall")
nonce = await client.get_contract_nonce(multicall_addr)
#
# Format the 'CalldataArray'
#
inner_calldata = [reward_account, reward_account, reward_account]
calldata = [
3,
evaluator_address, selector, 0, 1,
evaluator_address, selector, 1, 1,
evaluator_address, selector, 2, 1,
len(inner_calldata), *inner_calldata
]
hash = invoke_tx_hash(multicall_addr, calldata, nonce)
signature = sign(hash, private_key)
invoke = InvokeFunction(
calldata=calldata,
signature=[*signature],
max_fee=data['MAX_FEE'],
version=1,
nonce=nonce,
contract_address=multicall_addr,
)
resp = await multicall.send_transaction(invoke)
await print_n_wait(client, resp)
asyncio.run(main())