-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArbitrumBroadcaster.vy
178 lines (135 loc) · 4.93 KB
/
ArbitrumBroadcaster.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# pragma version 0.3.10
"""
@title Arbitrum Broadcaster
@author CurveFi
@license MIT
@custom:version 1.0.1
"""
version: public(constant(String[8])) = "1.0.1"
interface IArbInbox:
def calculateRetryableSubmissionFee(_data_length: uint256, _base_fee: uint256) -> uint256: view
event Broadcast:
chain_id: indexed(uint256)
agent: indexed(Agent)
messages: DynArray[Message, MAX_MESSAGES]
event SetDestinationData:
chain_id: indexed(uint256)
data: DestinationData
event ApplyAdmins:
admins: AdminSet
event CommitAdmins:
future_admins: AdminSet
enum Agent:
OWNERSHIP
PARAMETER
EMERGENCY
struct AdminSet:
ownership: address
parameter: address
emergency: address
struct Message:
target: address
data: Bytes[MAX_BYTES]
struct DestinationData:
arb_inbox: IArbInbox
arb_refund: address # DAO owned Vault or FeeCollector
relayer: address
MAX_BYTES: constant(uint256) = 1024
MAX_MESSAGES: constant(uint256) = 8
MAXSIZE: constant(uint256) = 16384
admins: public(AdminSet)
future_admins: public(AdminSet)
destination_data: public(HashMap[uint256, DestinationData])
agent: HashMap[address, Agent]
@payable
@external
def __init__(_admins: AdminSet):
assert _admins.ownership != _admins.parameter # a != b
assert _admins.ownership != _admins.emergency # a != c
assert _admins.parameter != _admins.emergency # b != c
self.admins = _admins
self.agent[_admins.ownership] = Agent.OWNERSHIP
self.agent[_admins.parameter] = Agent.PARAMETER
self.agent[_admins.emergency] = Agent.EMERGENCY
log ApplyAdmins(_admins)
@external
def broadcast(_chain_id: uint256, _messages: DynArray[Message, MAX_MESSAGES], _gas_limit: uint256, _max_fee_per_gas: uint256, _destination_data: DestinationData=empty(DestinationData)):
"""
@notice Broadcast a sequence of messages.
@param _chain_id Chain ID of L2
@param _messages The sequence of messages to broadcast.
@param _gas_limit The gas limit for the execution on L2.
@param _max_fee_per_gas The maximum gas price bid for the execution on L2.
@param _destination_data Specific DestinationData (self.destination_data by default)
"""
agent: Agent = self.agent[msg.sender]
assert agent != empty(Agent)
destination: DestinationData = _destination_data
if destination.relayer == empty(address):
destination = self.destination_data[_chain_id]
assert destination.relayer != empty(address)
# define all variables here before expanding memory enormously
submission_cost: uint256 = 0
data: Bytes[MAXSIZE] = _abi_encode(
agent,
_messages,
method_id=method_id("relay(uint256,(address,bytes)[])"),
)
submission_cost = destination.arb_inbox.calculateRetryableSubmissionFee(len(data), block.basefee)
# NOTE: using `unsafeCreateRetryableTicket` so that refund address is not aliased
raw_call(
destination.arb_inbox.address,
_abi_encode(
destination.relayer, # to
empty(uint256), # l2CallValue
submission_cost, # maxSubmissionCost
destination.arb_refund, # excessFeeRefundAddress
destination.arb_refund, # callValueRefundAddress
_gas_limit,
_max_fee_per_gas,
data,
method_id=method_id("unsafeCreateRetryableTicket(address,uint256,uint256,address,address,uint256,uint256,bytes)"),
),
value=submission_cost + _gas_limit * _max_fee_per_gas,
)
@external
def set_destination_data(_chain_id: uint256, _destination_data: DestinationData):
"""
@notice Set destination data for child chain.
"""
assert msg.sender == self.admins.ownership
self.destination_data[_chain_id] = _destination_data
log SetDestinationData(_chain_id, _destination_data)
@external
def commit_admins(_future_admins: AdminSet):
"""
@notice Commit an admin set to use in the future.
"""
assert msg.sender == self.admins.ownership
assert _future_admins.ownership != _future_admins.parameter # a != b
assert _future_admins.ownership != _future_admins.emergency # a != c
assert _future_admins.parameter != _future_admins.emergency # b != c
self.future_admins = _future_admins
log CommitAdmins(_future_admins)
@external
def apply_admins():
"""
@notice Apply the future admin set.
"""
admins: AdminSet = self.admins
assert msg.sender == admins.ownership
# reset old admins
self.agent[admins.ownership] = empty(Agent)
self.agent[admins.parameter] = empty(Agent)
self.agent[admins.emergency] = empty(Agent)
# set new admins
future_admins: AdminSet = self.future_admins
self.agent[future_admins.ownership] = Agent.OWNERSHIP
self.agent[future_admins.parameter] = Agent.PARAMETER
self.agent[future_admins.emergency] = Agent.EMERGENCY
self.admins = future_admins
log ApplyAdmins(future_admins)
@payable
@external
def __default__():
assert len(msg.data) == 0