-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPolygonzkEVMRelayer.vy
92 lines (63 loc) · 2.26 KB
/
PolygonzkEVMRelayer.vy
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# pragma version 0.3.10
"""
@title Polygon zkEVM Relayer
@author CurveFi
@license MIT
@custom:version 1.0.1
"""
version: public(constant(String[8])) = "1.0.1"
event Relay:
agent: Agent
messages: DynArray[Message, MAX_MESSAGES]
event SetMessenger:
messenger: address
event SetOriginNetwork:
origin_network: uint32
interface IAgent:
def execute(_messages: DynArray[Message, MAX_MESSAGES]): nonpayable
enum Agent:
OWNERSHIP
PARAMETER
EMERGENCY
struct Message:
target: address
data: Bytes[MAX_BYTES]
MAX_BYTES: constant(uint256) = 1024
MAX_MESSAGES: constant(uint256) = 8
MAX_MESSAGE_RECEIVED: constant(uint256) = 9400
CODE_OFFSET: constant(uint256) = 3
OWNERSHIP_AGENT: public(immutable(address))
PARAMETER_AGENT: public(immutable(address))
EMERGENCY_AGENT: public(immutable(address))
agent: HashMap[Agent, address]
BROADCASTER: public(immutable(address))
MESSENGER: public(immutable(address))
ORIGIN_NETWORK: public(immutable(uint32))
@external
def __init__(_broadcaster: address, _agent_blueprint: address, _messenger: address, _origin_network: uint32):
BROADCASTER = _broadcaster
MESSENGER = _messenger
log SetMessenger(_messenger)
ORIGIN_NETWORK = _origin_network
OWNERSHIP_AGENT = create_from_blueprint(_agent_blueprint, code_offset=CODE_OFFSET)
PARAMETER_AGENT = create_from_blueprint(_agent_blueprint, code_offset=CODE_OFFSET)
EMERGENCY_AGENT = create_from_blueprint(_agent_blueprint, code_offset=CODE_OFFSET)
self.agent[Agent.OWNERSHIP] = OWNERSHIP_AGENT
self.agent[Agent.PARAMETER] = PARAMETER_AGENT
self.agent[Agent.EMERGENCY] = EMERGENCY_AGENT
@external
def relay(_agent: Agent, _messages: DynArray[Message, MAX_MESSAGES]):
"""
@notice Receive messages for an agent and relay them.
@param _agent The agent to relay messages to.
@param _messages The sequence of messages to relay.
"""
assert msg.sender == self
IAgent(self.agent[_agent]).execute(_messages)
log Relay(_agent, _messages)
@external
def onMessageReceived(_origin_address: address, _origin_network: uint32, _data: Bytes[MAX_MESSAGE_RECEIVED]):
assert msg.sender == MESSENGER
assert _origin_address == BROADCASTER
assert _origin_network == ORIGIN_NETWORK
raw_call(self, _data) # .relay()