-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArbitrumRelayer.vy
79 lines (53 loc) · 1.92 KB
/
ArbitrumRelayer.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
# pragma version 0.3.10
"""
@title Arbitrum 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]
interface IAgent:
def execute(_messages: DynArray[Message, MAX_MESSAGES]): nonpayable
interface IArbSys:
def wasMyCallersAddressAliased() -> bool: view
def myCallersAddressWithoutAliasing() -> address: view
enum Agent:
OWNERSHIP
PARAMETER
EMERGENCY
struct Message:
target: address
data: Bytes[MAX_BYTES]
MAX_BYTES: constant(uint256) = 1024
MAX_MESSAGES: constant(uint256) = 8
CODE_OFFSET: constant(uint256) = 3
BROADCASTER: public(immutable(address))
ARBSYS: public(immutable(address))
OWNERSHIP_AGENT: public(immutable(address))
PARAMETER_AGENT: public(immutable(address))
EMERGENCY_AGENT: public(immutable(address))
agent: HashMap[Agent, address]
@external
def __init__(broadcaster: address, _agent_blueprint: address, _arbsys: address):
BROADCASTER = broadcaster
ARBSYS = _arbsys
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 IArbSys(ARBSYS).wasMyCallersAddressAliased()
assert IArbSys(ARBSYS).myCallersAddressWithoutAliasing() == BROADCASTER
IAgent(self.agent[_agent]).execute(_messages)
log Relay(_agent, _messages)