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

Adds Lint and Build workflow #14

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
66 changes: 66 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Lint and Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Print forge version
run: forge --version

- name: Build
working-directory: .
run: forge build
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

- name: Print forge version
run: forge --version

- name: Run tests
working-directory: .
run: forge test -vvv

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Print forge version
run: forge --version

- name: Check formatting src
working-directory: src
run: forge fmt --check

- name: Check formatting test
working-directory: test
run: forge fmt --check


3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ artifacts
out
cache

*.DS_Store
*.DS_Store
.idea/
18 changes: 9 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
[submodule "lib/eigenlayer-contracts"]
path = lib/eigenlayer-contracts
url = https://github.com/Layr-Labs/eigenlayer-contracts
[submodule "lib/eigenlayer-middleware"]
path = lib/eigenlayer-middleware
url = https://github.com/Layr-Labs/eigenlayer-middleware
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/transmissions11/solmate
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-foundry-upgrades"]
path = lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
21 changes: 0 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
MIT License

Copyright (c) 2024 Predicate

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 5 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[profile.default]
src = "src"
out = "out"
ffi = true
build_info = true
ast = true
extra_output = ["storageLayout", "abi", "metadata", "devdoc", "userdoc"]
libs = ["lib"]
gas_reports = ["*"]
# Override the Solidity version (this overrides `auto_detect_solc`)
solc_version = '0.8.12'
solc_version = '0.8.28'

[fmt]
bracket_spacing = false
Expand All @@ -15,5 +18,4 @@ number_underscore = "thousands"
quote_style = "double"
tab_width = 4


# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
12 changes: 5 additions & 7 deletions src/ServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
pragma solidity ^0.8.12;

import {OwnableUpgradeable} from "openzeppelin-upgradeable/access/OwnableUpgradeable.sol";
import {Initializable} from "openzeppelin-upgradeable/proxy/utils/Initializable.sol";

import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISignatureUtils.sol";
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
import {ECDSA} from "openzeppelin/utils/cryptography/ECDSA.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import {IStakeRegistry} from "./interfaces/IStakeRegistry.sol";
import {IPredicateManager, Task, SignatureWithSaltAndExpiry} from "./interfaces/IPredicateManager.sol";

contract ServiceManager is IPredicateManager, OwnableUpgradeable {
contract ServiceManager is IPredicateManager, Initializable, OwnableUpgradeable {
error ServiceManager__Unauthorized();
error ServiceManager__InvalidOperator();
error ServiceManager__InvalidStrategy();
Expand Down Expand Up @@ -90,10 +91,6 @@ contract ServiceManager is IPredicateManager, OwnableUpgradeable {
_;
}

constructor() {
_disableInitializers();
}

function initialize(
address _owner,
address _aggregator,
Expand Down Expand Up @@ -233,7 +230,7 @@ contract ServiceManager is IPredicateManager, OwnableUpgradeable {
function registerOperatorToAVS(
address _operatorSigningKey,
SignatureWithSaltAndExpiry memory _operatorSignature
) external onlyPermissionedOperator {
) external {
require(
signingKeyToOperator[_operatorSigningKey] == address(0),
"ServiceManager.registerOperatorToAVS: operator already registered"
Expand Down Expand Up @@ -277,6 +274,7 @@ contract ServiceManager is IPredicateManager, OwnableUpgradeable {
* @notice Deploys a policy for which clients can use
* @param _policyID is a unique identifier
* @param _policy is set of formatted rules
* @param _quorumThreshold is the number of signatures required to validate a task
*/
function deployPolicy(
string memory _policyID,
Expand Down
59 changes: 15 additions & 44 deletions src/examples/MetaCoin.sol
Original file line number Diff line number Diff line change
@@ -1,64 +1,35 @@
// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.12;

import {Ownable} from "openzeppelin/access/Ownable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {PredicateClient} from "../mixins/PredicateClient.sol";
import {PredicateMessage} from "../interfaces/IPredicateClient.sol";
import {IPredicateManager} from "../interfaces/IPredicateManager.sol";

// This is just a simple example of a coin-like contract.
// It is not ERC20 compatible and cannot be expected to talk to other
// coin/token contracts.

contract MetaCoin is PredicateClient, Ownable {
contract MetaCoin is Ownable {
mapping(address => uint256) public balances;

event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor(address _owner, address _serviceManager, string memory _policyID) {
constructor(
address _owner
) Ownable() {
balances[_owner] = 10_000_000_000_000;
_initPredicateClient(_serviceManager, _policyID);
_transferOwnership(_owner);
}

function sendCoin(address receiver, uint256 amount, PredicateMessage calldata predicateMessage) public payable {
bytes memory encodedSigAndArgs = abi.encodeWithSignature("_sendCoin(address,uint256)", receiver, amount);
require(
_authorizeTransaction(predicateMessage, encodedSigAndArgs, msg.sender, msg.value),
"MetaCoin: unauthorized transaction"
);

// business logic function that is protected
_sendCoin(receiver, amount);
}

// @inheritdoc IPredicateClient
function setPolicy(
string memory _policyID
) external onlyOwner {
_setPolicy(_policyID);
transferOwnership(_owner);
}

// @inheritdoc IPredicateClient
function setPredicateManager(
address _predicateManager
) public onlyOwner {
_setPredicateManager(_predicateManager);
function sendCoin(address _receiver, uint256 _amount) external payable {
_sendCoin(_receiver, _amount);
}

// business logic function that is protected
function _sendCoin(address receiver, uint256 amount) internal {
require(balances[msg.sender] >= amount, "MetaCoin: insufficient balance");
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
function _sendCoin(address _receiver, uint256 _amount) internal {
require(balances[msg.sender] >= _amount, "MetaCoin: insufficient balance");
balances[msg.sender] -= _amount;
balances[_receiver] += _amount;
emit Transfer(msg.sender, _receiver, _amount);
}

function getBalance(
address addr
address _addr
) public view returns (uint256) {
return balances[addr];
return balances[_addr];
}
}
57 changes: 57 additions & 0 deletions src/examples/inheritance/MetaCoin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.12;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {PredicateClient} from "../../mixins/PredicateClient.sol";
import {PredicateMessage} from "../../interfaces/IPredicateClient.sol";
import {IPredicateManager} from "../../interfaces/IPredicateManager.sol";

contract MetaCoin is PredicateClient, Ownable {
mapping(address => uint256) public balances;

event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor(address _owner, address _serviceManager, string memory _policyID) Ownable() {
balances[_owner] = 10_000_000_000_000;
_initPredicateClient(_serviceManager, _policyID);
transferOwnership(_owner);
}

function sendCoin(address _receiver, uint256 _amount, PredicateMessage calldata _message) external payable {
bytes memory encodedSigAndArgs = abi.encodeWithSignature("_sendCoin(address,uint256)", _receiver, _amount);
require(
_authorizeTransaction(_message, encodedSigAndArgs, msg.sender, msg.value),
"MetaCoin: unauthorized transaction"
);

// business logic function that is protected
_sendCoin(_receiver, _amount);
}

function setPolicy(
string memory _policyID
) external onlyOwner {
_setPolicy(_policyID);
}

function setPredicateManager(
address _predicateManager
) public onlyOwner {
_setPredicateManager(_predicateManager);
}

function _sendCoin(address _receiver, uint256 _amount) internal {
require(balances[msg.sender] >= _amount, "MetaCoin: insufficient balance");
balances[msg.sender] -= _amount;
balances[_receiver] += _amount;
emit Transfer(msg.sender, _receiver, _amount);
}

function getBalance(
address _addr
) public view returns (uint256) {
return balances[_addr];
}
}
12 changes: 12 additions & 0 deletions src/examples/proxy/IPredicateProtected.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.12;

interface IPredicateProtected {
function getPredicateProxy() external view returns (address);
function setPredicateProxy(
address _predicateProxyAddress
) external;
function enablePredicateProxy() external;
function disablePredicateProxy() external;
}
49 changes: 49 additions & 0 deletions src/examples/proxy/MetaCoin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.12;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {PredicateProtected} from "./PredicateProtected.sol";

contract MetaCoin is Ownable, PredicateProtected {
mapping(address => uint256) public balances;

event Transfer(address indexed _from, address indexed _to, uint256 _value);

constructor(address _owner, address _predicateProxyAddress) Ownable() {
balances[_owner] = 10_000_000_000_000;
_setPredicateProxy(_predicateProxyAddress);
transferOwnership(_owner);
}

function sendCoin(address _sender, address _receiver, uint256 _amount) external payable onlyPredicateProxy {
_sendCoin(_sender, _receiver, _amount);
}

function _sendCoin(address _sender, address _receiver, uint256 _amount) internal {
require(balances[_sender] >= _amount, "MetaCoin: insufficient balance");
balances[_sender] -= _amount;
balances[_receiver] += _amount;
emit Transfer(_sender, _receiver, _amount);
}

function getBalance(
address _addr
) public view returns (uint256) {
return balances[_addr];
}

function setPredicateProxy(
address _predicateProxyAddress
) external onlyOwner {
_setPredicateProxy(_predicateProxyAddress);
}

function enablePredicateProxy() external onlyOwner {
_enablePredicateProxy();
}

function disablePredicateProxy() external onlyOwner {
_disablePredicateProxy();
}
}
Loading
Loading