-
Notifications
You must be signed in to change notification settings - Fork 1
/
XYZRelayer.vy
77 lines (52 loc) · 1.79 KB
/
XYZRelayer.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
# @version 0.3.10
"""
@title XYZ Relayer
@author CurveFi
"""
event SetMessenger:
messenger: address
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
CODE_OFFSET: constant(uint256) = 3
OWNERSHIP_AGENT: public(immutable(address))
PARAMETER_AGENT: public(immutable(address))
EMERGENCY_AGENT: public(immutable(address))
agent: HashMap[Agent, address]
messenger: public(address)
@external
def __init__(_agent_blueprint: address, _messenger: address):
self.messenger = _messenger
log SetMessenger(_messenger)
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.messenger
IAgent(self.agent[_agent]).execute(_messages)
@external
def set_messenger(_messenger: address):
"""
@notice Set the messenger which verifies messages and is permitted to call `relay`.
@dev Only callable by the OWNERSHIP_AGENT.
"""
assert msg.sender == OWNERSHIP_AGENT
self.messenger = _messenger
log SetMessenger(_messenger)