Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlando committed Aug 28, 2023
1 parent b63ed4d commit 082c97c
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 200 deletions.
10 changes: 5 additions & 5 deletions ethereum/src/deps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.19;

import '@gnosis.pm/safe-contracts/contracts/GnosisSafeL2.sol';
import '@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxyFactory.sol';
import '@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol';
import '@gnosis.pm/zodiac/contracts/guard/Guardable.sol';
import '@gnosis.pm/zodiac/contracts/core/Module.sol';
import "@gnosis.pm/safe-contracts/contracts/GnosisSafeL2.sol";
import "@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxyFactory.sol";
import "@gnosis.pm/zodiac/contracts/factory/ModuleProxyFactory.sol";
import "@gnosis.pm/zodiac/contracts/guard/Guardable.sol";
import "@gnosis.pm/zodiac/contracts/core/Module.sol";
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy {
uint256[] memory _starknetSpaces,
uint256 _quorum
) {
bytes memory initParams = abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum);
bytes memory initParams =
abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum);
setUp(initParams);
}

Expand All @@ -70,7 +71,7 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy {
address _starknetCore,
uint256 _executionRelayer,
uint256[] memory _starknetSpaces,
uint256 _quorum
uint256 _quorum
) = abi.decode(initParams, (address, address, address, uint256, uint256[], uint256));
__Ownable_init();
transferOwnership(_owner);
Expand Down Expand Up @@ -146,7 +147,7 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy {
payload[6] = proposal.executionStrategy;
payload[7] = proposal.authorAddressType;
payload[8] = proposal.author;
payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1);
payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1);
payload[10] = proposal.activeVotingStrategies >> 128;

payload[11] = votesFor & (2 ** 128 - 1);
Expand Down Expand Up @@ -180,4 +181,4 @@ contract L1AvatarExecutionStrategy is SimpleQuorumExecutionStrategy {
function getStrategyType() external pure override returns (string memory) {
return "SimpleQuorumL1Avatar";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {StarknetSpaceManager} from "./StarknetSpaceManager.sol";
/// @title Simple Quorum Base Execution Strategy
abstract contract SimpleQuorumExecutionStrategy is IExecutionStrategy, StarknetSpaceManager {
event QuorumUpdated(uint256 newQuorum);

/// @notice The quorum required to execute a proposal using this strategy.
uint256 public quorum;

Expand Down
4 changes: 2 additions & 2 deletions ethereum/src/execution-strategies/StarknetSpaceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.19;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { TRUE, FALSE } from "../types.sol";
import {TRUE, FALSE} from "../types.sol";

/// @title Space Manager
/// @notice Manages a whitelist of Spaces that are authorized to execute transactions via this contract.
Expand Down Expand Up @@ -32,7 +32,7 @@ contract StarknetSpaceManager is OwnableUpgradeable {
/// @notice Enable a space.
/// @param space Address of the space.
function enableSpace(uint256 space) public onlyOwner {
if (space == 0 || (spaces[space] != FALSE)) revert InvalidSpace();
if (space == 0 || (spaces[space] != FALSE)) revert InvalidSpace();
spaces[space] = TRUE;
emit SpaceEnabled(space);
}
Expand Down
62 changes: 28 additions & 34 deletions ethereum/src/mocks/IStarknetMessaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@ import "./IStarknetMessagingEvents.sol";

interface IStarknetMessaging is IStarknetMessagingEvents {
/**
Sends a message to an L2 contract.
This function is payable, the payed amount is the message fee.
Returns the hash of the message and the nonce of the message.
*/
function sendMessageToL2(
uint256 toAddress,
uint256 selector,
uint256[] calldata payload
) external payable returns (bytes32, uint256);

/**
Consumes a message that was sent from an L2 contract.
Returns the hash of the message.
*/
function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload)
* Sends a message to an L2 contract.
* This function is payable, the payed amount is the message fee.
*
* Returns the hash of the message and the nonce of the message.
*/
function sendMessageToL2(uint256 toAddress, uint256 selector, uint256[] calldata payload)
external
returns (bytes32);
payable
returns (bytes32, uint256);

/**
Starts the cancellation of an L1 to L2 message.
A message can be canceled messageCancellationDelay() seconds after this function is called.
* Consumes a message that was sent from an L2 contract.
*
* Returns the hash of the message.
*/
function consumeMessageFromL2(uint256 fromAddress, uint256[] calldata payload) external returns (bytes32);

Note: This function may only be called for a message that is currently pending and the caller
must be the sender of the that message.
*/
/**
* Starts the cancellation of an L1 to L2 message.
* A message can be canceled messageCancellationDelay() seconds after this function is called.
*
* Note: This function may only be called for a message that is currently pending and the caller
* must be the sender of the that message.
*/
function startL1ToL2MessageCancellation(
uint256 toAddress,
uint256 selector,
Expand All @@ -40,15 +37,12 @@ interface IStarknetMessaging is IStarknetMessagingEvents {
) external returns (bytes32);

/**
Cancels an L1 to L2 message, this function should be called messageCancellationDelay() seconds
after the call to startL1ToL2MessageCancellation().
Note that the message fee is not refunded.
*/
function cancelL1ToL2Message(
uint256 toAddress,
uint256 selector,
uint256[] calldata payload,
uint256 nonce
) external returns (bytes32);
* Cancels an L1 to L2 message, this function should be called messageCancellationDelay() seconds
* after the call to startL1ToL2MessageCancellation().
*
* Note that the message fee is not refunded.
*/
function cancelL1ToL2Message(uint256 toAddress, uint256 selector, uint256[] calldata payload, uint256 nonce)
external
returns (bytes32);
}
8 changes: 2 additions & 6 deletions ethereum/src/mocks/IStarknetMessagingEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ interface IStarknetMessagingEvents {
);

// An event that is raised when a message from L2 to L1 is consumed.
event ConsumedMessageToL1(
uint256 indexed fromAddress,
address indexed toAddress,
uint256[] payload
);
event ConsumedMessageToL1(uint256 indexed fromAddress, address indexed toAddress, uint256[] payload);

// An event that is raised when a message from L1 to L2 is consumed.
event ConsumedMessageToL2(
Expand Down Expand Up @@ -48,4 +44,4 @@ interface IStarknetMessagingEvents {
uint256[] payload,
uint256 nonce
);
}
}
7 changes: 4 additions & 3 deletions ethereum/src/mocks/L1AvatarExecutionStrategyMockMessaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy
uint256[] memory _starknetSpaces,
uint256 _quorum
) {
bytes memory initParams = abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum);
bytes memory initParams =
abi.encode(_owner, _target, _starknetCore, _executionRelayer, _starknetSpaces, _quorum);
setUp(initParams);
}

Expand All @@ -70,7 +71,7 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy
address _starknetCore,
uint256 _executionRelayer,
uint256[] memory _starknetSpaces,
uint256 _quorum
uint256 _quorum
) = abi.decode(initParams, (address, address, address, uint256, uint256[], uint256));
__Ownable_init();
transferOwnership(_owner);
Expand Down Expand Up @@ -146,7 +147,7 @@ contract L1AvatarExecutionStrategyMockMessaging is SimpleQuorumExecutionStrategy
payload[6] = proposal.executionStrategy;
payload[7] = proposal.authorAddressType;
payload[8] = proposal.author;
payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1);
payload[9] = proposal.activeVotingStrategies & (2 ** 128 - 1);
payload[10] = proposal.activeVotingStrategies >> 128;

payload[11] = votesFor & (2 ** 128 - 1);
Expand Down
22 changes: 7 additions & 15 deletions ethereum/src/mocks/MockStarknetMessaging.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,24 @@ contract MockStarknetMessaging is StarknetMessaging {
}

/**
Mocks a message from L2 to L1.
*/
function mockSendMessageFromL2(
uint256 fromAddress,
uint256 toAddress,
uint256[] calldata payload
) external {
bytes32 msgHash = keccak256(
abi.encodePacked(fromAddress, toAddress, payload.length, payload)
);
* Mocks a message from L2 to L1.
*/
function mockSendMessageFromL2(uint256 fromAddress, uint256 toAddress, uint256[] calldata payload) external {
bytes32 msgHash = keccak256(abi.encodePacked(fromAddress, toAddress, payload.length, payload));
l2ToL1Messages()[msgHash] += 1;
}

/**
Mocks consumption of a message from L1 to L2.
*/
* Mocks consumption of a message from L1 to L2.
*/
function mockConsumeMessageToL2(
uint256 fromAddress,
uint256 toAddress,
uint256 selector,
uint256[] calldata payload,
uint256 nonce
) external {
bytes32 msgHash = keccak256(
abi.encodePacked(fromAddress, toAddress, nonce, selector, payload.length, payload)
);
bytes32 msgHash = keccak256(abi.encodePacked(fromAddress, toAddress, nonce, selector, payload.length, payload));

require(l1ToL2Messages()[msgHash] > 0, "INVALID_MESSAGE_TO_CONSUME");
l1ToL2Messages()[msgHash] = 0;
Expand Down
132 changes: 66 additions & 66 deletions ethereum/src/mocks/NamedStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,88 @@ pragma solidity ^0.8.19;
New types of storage variables should be added here upon need.
*/
library NamedStorage {
function bytes32ToUint256Mapping(string memory tag_)
internal
pure
returns (mapping(bytes32 => uint256) storage randomVariable)
{
bytes32 location = keccak256(abi.encodePacked(tag_));
assembly {
randomVariable.slot := location
function bytes32ToUint256Mapping(string memory tag_)
internal
pure
returns (mapping(bytes32 => uint256) storage randomVariable)
{
bytes32 location = keccak256(abi.encodePacked(tag_));
assembly {
randomVariable.slot := location
}
}
}

function bytes32ToAddressMapping(string memory tag_)
internal
pure
returns (mapping(bytes32 => address) storage randomVariable)
{
bytes32 location = keccak256(abi.encodePacked(tag_));
assembly {
randomVariable.slot := location
function bytes32ToAddressMapping(string memory tag_)
internal
pure
returns (mapping(bytes32 => address) storage randomVariable)
{
bytes32 location = keccak256(abi.encodePacked(tag_));
assembly {
randomVariable.slot := location
}
}
}

function addressToBoolMapping(string memory tag_)
internal
pure
returns (mapping(address => bool) storage randomVariable)
{
bytes32 location = keccak256(abi.encodePacked(tag_));
assembly {
randomVariable.slot := location
function addressToBoolMapping(string memory tag_)
internal
pure
returns (mapping(address => bool) storage randomVariable)
{
bytes32 location = keccak256(abi.encodePacked(tag_));
assembly {
randomVariable.slot := location
}
}
}

function getUintValue(string memory tag_) internal view returns (uint256 retVal) {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
retVal := sload(slot)
function getUintValue(string memory tag_) internal view returns (uint256 retVal) {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
retVal := sload(slot)
}
}
}

function setUintValue(string memory tag_, uint256 value) internal {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
sstore(slot, value)
function setUintValue(string memory tag_, uint256 value) internal {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
sstore(slot, value)
}
}
}

function setUintValueOnce(string memory tag_, uint256 value) internal {
require(getUintValue(tag_) == 0, 'ALREADY_SET');
setUintValue(tag_, value);
}
function setUintValueOnce(string memory tag_, uint256 value) internal {
require(getUintValue(tag_) == 0, "ALREADY_SET");
setUintValue(tag_, value);
}

function getAddressValue(string memory tag_) internal view returns (address retVal) {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
retVal := sload(slot)
function getAddressValue(string memory tag_) internal view returns (address retVal) {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
retVal := sload(slot)
}
}
}

function setAddressValue(string memory tag_, address value) internal {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
sstore(slot, value)
function setAddressValue(string memory tag_, address value) internal {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
sstore(slot, value)
}
}
}

function setAddressValueOnce(string memory tag_, address value) internal {
require(getAddressValue(tag_) == address(0x0), 'ALREADY_SET');
setAddressValue(tag_, value);
}
function setAddressValueOnce(string memory tag_, address value) internal {
require(getAddressValue(tag_) == address(0x0), "ALREADY_SET");
setAddressValue(tag_, value);
}

function getBoolValue(string memory tag_) internal view returns (bool retVal) {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
retVal := sload(slot)
function getBoolValue(string memory tag_) internal view returns (bool retVal) {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
retVal := sload(slot)
}
}
}

function setBoolValue(string memory tag_, bool value) internal {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
sstore(slot, value)
function setBoolValue(string memory tag_, bool value) internal {
bytes32 slot = keccak256(abi.encodePacked(tag_));
assembly {
sstore(slot, value)
}
}
}
}
}
Loading

0 comments on commit 082c97c

Please sign in to comment.