Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix XYZ(xdao) message passing #9

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions contracts/xyz/XYZBroadcaster.vy
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
"""
@title XYZ Broadcaster
@author CurveFi
@license MIT
@custom:version 0.0.2
@custom:security [email protected]
"""

version: public(constant(String[8])) = "0.0.2"

event Broadcast:
agent: Agent
chain_id: uint256
agent: indexed(Agent)
chain_id: indexed(uint256)
nonce: uint256
digest: bytes32
deadline: uint256

event ApplyAdmins:
admins: AdminSet
Expand Down Expand Up @@ -37,6 +42,8 @@ struct Message:
MAX_BYTES: constant(uint256) = 1024
MAX_MESSAGES: constant(uint256) = 8

DAY: constant(uint256) = 86400
WEEK: constant(uint256) = 7 * DAY

admins: public(AdminSet)
future_admins: public(AdminSet)
Expand All @@ -45,6 +52,7 @@ agent: HashMap[address, Agent]

nonce: public(HashMap[Agent, HashMap[uint256, uint256]]) # agent -> chainId -> nonce
digest: public(HashMap[Agent, HashMap[uint256, HashMap[uint256, bytes32]]]) # agent -> chainId -> nonce -> messageDigest
deadline: public(HashMap[Agent, HashMap[uint256, HashMap[uint256, uint256]]]) # agent -> chainId -> nonce -> deadline


@external
Expand All @@ -62,23 +70,41 @@ def __init__(_admins: AdminSet):
log ApplyAdmins(_admins)


@internal
@pure
def _get_ttl(agent: Agent, ttl: uint256) -> uint256:
if agent == Agent.EMERGENCY:
# Emergency votes should be brisk
if ttl == 0:
ttl = DAY # default
assert ttl <= WEEK
else:
if ttl == 0:
ttl = WEEK # default
assert DAY <= ttl and ttl <= 3 * WEEK
return ttl


@external
def broadcast(_chain_id: uint256, _messages: DynArray[Message, MAX_MESSAGES]):
def broadcast(_chain_id: uint256, _messages: DynArray[Message, MAX_MESSAGES], _ttl: uint256=0):
"""
@notice Broadcast a sequence of messeages.
@notice Broadcast a sequence of messages.
@param _chain_id The chain id to have messages executed on.
@param _messages The sequence of messages to broadcast.
@param _ttl Time-to-leave for message if it's not executed. 0 will use default values.
"""
agent: Agent = self.agent[msg.sender]
assert agent != empty(Agent)
assert agent != empty(Agent) and len(_messages) > 0
ttl: uint256 = self._get_ttl(agent, _ttl)

digest: bytes32 = keccak256(_abi_encode(_messages))
nonce: uint256 = self.nonce[agent][_chain_id]

self.digest[agent][_chain_id][nonce] = digest
self.nonce[agent][_chain_id] = nonce + 1
self.deadline[agent][_chain_id][nonce] = block.timestamp + ttl

log Broadcast(agent, _chain_id, nonce, digest)
log Broadcast(agent, _chain_id, nonce, digest, block.timestamp + ttl)


@external
Expand Down
Loading