This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: llama message broadcaster #96
Open
0xrajath
wants to merge
8
commits into
main
Choose a base branch
from
rajath/llama-broadcast
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1ba1c70
LlamaMessageBroadcaster
0xrajath 918bbda
duck testing
0xrajath 83aeb61
natspec
0xrajath 2f96fb6
updated deploy script
0xrajath ce9d6ce
working positive test
0xrajath f1b017a
revert test
0xrajath 56e4cae
integration test
0xrajath a568a03
fix
0xrajath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {ILlamaCore} from "src/interfaces/ILlamaCore.sol"; | ||
import {ILlamaExecutor} from "src/interfaces/ILlamaExecutor.sol"; | ||
|
||
/// @title LlamaMessageBroadcaster | ||
/// @author Llama (devsdosomething@llama.xyz) | ||
/// @notice This contract enables Llama instances to broadcast an offchain message. | ||
contract LlamaMessageBroadcaster { | ||
/// @dev Emitted when a message is broadcast by a Llama instance. | ||
event MessageBroadcasted(ILlamaExecutor indexed llamaExecutor, string message); | ||
|
||
/// @notice Broadcasts a message from a Llama instance. | ||
/// @param message Message to be broadcasted. | ||
function broadcastMessage(string calldata message) external { | ||
ILlamaExecutor llamaExecutor = ILlamaExecutor(msg.sender); | ||
// Duck testing to check if the caller is a Llama instance. | ||
ILlamaCore(llamaExecutor.LLAMA_CORE()).actionsCount(); | ||
emit MessageBroadcasted(llamaExecutor, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Test, console2} from "forge-std/Test.sol"; | ||
import {Vm} from "forge-std/Vm.sol"; | ||
|
||
import {LlamaPeripheryTestSetup} from "test/LlamaPeripheryTestSetup.sol"; | ||
|
||
import {DeployLlamaTokenVotingFactory} from "script/DeployLlamaTokenVotingFactory.s.sol"; | ||
|
||
import {ILlamaExecutor} from "src/interfaces/ILlamaExecutor.sol"; | ||
import {ILlamaPolicy} from "src/interfaces/ILlamaPolicy.sol"; | ||
import {ActionInfo} from "src/lib/Structs.sol"; | ||
import {LlamaMessageBroadcaster} from "src/message-broadcaster/LlamaMessageBroadcaster.sol"; | ||
|
||
contract LlamaMessageBroadcasterTest is LlamaPeripheryTestSetup, DeployLlamaTokenVotingFactory { | ||
event MessageBroadcasted(ILlamaExecutor indexed llamaExecutor, string message); | ||
|
||
function setUp() public virtual override { | ||
LlamaPeripheryTestSetup.setUp(); | ||
|
||
// Deploy the peripheral contracts | ||
DeployLlamaTokenVotingFactory.run(); | ||
} | ||
} | ||
|
||
contract BroadcastMessage is LlamaMessageBroadcasterTest { | ||
function test_BroadcastMessage() public { | ||
string memory message = "Hello World!"; | ||
vm.expectEmit(); | ||
emit MessageBroadcasted(EXECUTOR, message); | ||
vm.prank(address(EXECUTOR)); | ||
llamaMessageBroadcaster.broadcastMessage(message); | ||
} | ||
|
||
function test_BroadcastMessageFullActionLifecycle() public { | ||
string memory message = "Hello World!"; | ||
|
||
// Giving Action Creator permission to call `LlamaMessageBroadcaster.broadcastMessage`. | ||
vm.prank(address(EXECUTOR)); | ||
POLICY.setRolePermission( | ||
CORE_TEAM_ROLE, | ||
ILlamaPolicy.PermissionData( | ||
address(llamaMessageBroadcaster), LlamaMessageBroadcaster.broadcastMessage.selector, address(STRATEGY) | ||
), | ||
true | ||
); | ||
|
||
// Create Action to broadcast message. | ||
bytes memory data = abi.encodeCall(LlamaMessageBroadcaster.broadcastMessage, (message)); | ||
vm.prank(coreTeam1); | ||
uint256 actionId = CORE.createAction(CORE_TEAM_ROLE, STRATEGY, address(llamaMessageBroadcaster), 0, data, ""); | ||
ActionInfo memory actionInfo = | ||
ActionInfo(actionId, coreTeam1, CORE_TEAM_ROLE, STRATEGY, address(llamaMessageBroadcaster), 0, data); | ||
|
||
// Approval and auto-queue process. | ||
vm.prank(coreTeam2); | ||
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, ""); | ||
vm.prank(coreTeam3); | ||
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, ""); | ||
vm.prank(coreTeam4); | ||
CORE.castApproval(CORE_TEAM_ROLE, actionInfo, ""); | ||
|
||
// Execute Action. | ||
vm.expectEmit(); | ||
emit MessageBroadcasted(EXECUTOR, message); | ||
CORE.executeAction(actionInfo); | ||
} | ||
|
||
function test_RevertIf_CallerIsNotExecutor() public { | ||
string memory message = "Hello World!"; | ||
vm.expectRevert(); | ||
llamaMessageBroadcaster.broadcastMessage(message); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the duck test here to reduce possible spam since it's an open function.