Skip to content

Commit

Permalink
chore(horizon): add horizon package boilerplate
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone authored and pcarranzav committed Apr 9, 2024
1 parent 0e8895b commit 2585495
Show file tree
Hide file tree
Showing 28 changed files with 1,057 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ runs:
using: composite

steps:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Enable corepack for modern yarn
shell: bash
run: corepack enable
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup
2 changes: 2 additions & 0 deletions .github/workflows/ci-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup
- name: Run tests
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/ci-horizon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI - packages/horizon

env:
CI: true

on:
push:
branches: "*"
paths:
- packages/horizon/**
pull_request:
branches: "*"
paths:
- packages/horizon/**
workflow_dispatch:

jobs:
test-ci:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup
- name: Run tests
run: |
pushd packages/horizon
yarn test
2 changes: 2 additions & 0 deletions .github/workflows/ci-token-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/e2e-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup
- name: Run e2e tests
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup
- name: Publish 🚀
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/verifydeployed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set up environment
uses: ./.github/actions/setup

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ cached/
# Build artifacts
dist/
build/
typechain/
typechain-types/
deployments/hardhat/

# Ignore solc bin output
Expand All @@ -45,8 +47,10 @@ addresses-fork.json
# Keys
.keystore

# Forge artifacts
cache_forge
# Graph client
.graphclient

tx-builder-*.json
!tx-builder-template.json
!tx-builder-template.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "packages/horizon/lib/forge-std"]
path = packages/horizon/lib/forge-std
url = https://github.com/foundry-rs/forge-std
7 changes: 6 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ popd
# data-edge
pushd packages/data-edge
npx --no-install lint-staged
popd
popd

# graph horizon
pushd packages/horizon
npx --no-install lint-staged
popd
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ This repository is a Yarn workspaces monorepo containing the following packages:
| --- | --- | --- |
| [contracts](./packages/contracts) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fcontracts.svg)](https://badge.fury.io/js/@graphprotocol%2Fcontracts) | Contracts enabling the open and permissionless decentralized network known as The Graph protocol. |
| [eslint-graph-config](./packages/eslint-graph-config) | [![npm version]()]() | Shared linting and formatting rules for TypeScript projects. |
| [token-distribution](./packages/token-distribution) | - | Contracts managing token locks for network participants |
| [horizon](./packages/horizon) | [![npm version]()]() | Contracts for Graph Horizon, the next iteration of The Graph protocol. |
| [sdk](./packages/sdk) | [![npm version](https://badge.fury.io/js/@graphprotocol%2Fsdk.svg)](https://badge.fury.io/js/@graphprotocol%2Fsdk) | TypeScript based SDK to interact with the protocol contracts |
| [solhint-graph-config](./packages/eslint-graph-config) | [![npm version]()]() | Shared linting and formatting rules for Solidity projects. |
| [token-distribution](./packages/token-distribution) | - | Contracts managing token locks for network participants |


## Development
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"packages/contracts",
"packages/data-edge",
"packages/eslint-graph-config",
"packages/horizon",
"packages/sdk",
"packages/solhint-graph-config",
"packages/token-distribution"
Expand Down
24 changes: 8 additions & 16 deletions packages/contracts/contracts/staking/IHorizonStaking.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity 0.7.6;
pragma solidity >=0.7.6 <0.9.0;
pragma abicoder v2;

interface Test {
function test() external returns (uint256);
}

interface IHorizonStaking {
struct Provision {
// Service provider that created the provision
Expand Down Expand Up @@ -93,12 +97,7 @@ interface IHorizonStaking {
function stake(uint256 tokens) external;

// create a provision
function provision(
uint256 tokens,
address verifier,
uint256 maxVerifierCut,
uint256 thawingPeriod
) external;
function provision(uint256 tokens, address verifier, uint256 maxVerifierCut, uint256 thawingPeriod) external;

// initiate a thawing to remove tokens from a provision
function thaw(bytes32 provisionId, uint256 tokens) external returns (bytes32 thawRequestId);
Expand All @@ -123,11 +122,7 @@ interface IHorizonStaking {
) external returns (bytes32 thawRequestId);

// slash a service provider
function slash(
bytes32 provisionId,
uint256 tokens,
uint256 verifierAmount
) external;
function slash(bytes32 provisionId, uint256 tokens, uint256 verifierAmount) external;

// set the Service Provider's preferred provisions to be force thawed
function setForceThawProvisions(bytes32[] calldata provisions) external;
Expand All @@ -148,10 +143,7 @@ interface IHorizonStaking {
// `Provision.tokens - Provision.tokensThawing`
function getTokensAvailable(bytes32 provision) external view returns (uint256 tokens);

function getServiceProvider(address serviceProvider)
external
view
returns (ServiceProvider memory);
function getServiceProvider(address serviceProvider) external view returns (ServiceProvider memory);

function getProvision(bytes32 provision) external view returns (Provision memory);
}
13 changes: 13 additions & 0 deletions packages/horizon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Sample Hardhat Project

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract.

Try running some of the following tasks:

```shell
npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test
npx hardhat node
npx hardhat run scripts/deploy.ts
```
10 changes: 10 additions & 0 deletions packages/horizon/contracts/SimpleTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.0 <0.9.0;

import { Test } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol";

contract SimpleTest is Test {
function test() external pure returns (uint256) {
return 42;
}
}
21 changes: 21 additions & 0 deletions packages/horizon/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

const eslintGraphConfig = require('eslint-graph-config')
module.exports = [
...eslintGraphConfig.default,
{
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
},
},
{
ignores: ['typechain-types/*'],
},
]
6 changes: 6 additions & 0 deletions packages/horizon/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.default]
src = 'contracts'
out = 'build'
libs = ['node_modules', 'lib']
test = 'test'
cache_path = 'cache_forge'
13 changes: 13 additions & 0 deletions packages/horizon/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// import '@nomicfoundation/hardhat-foundry'
import '@nomicfoundation/hardhat-toolbox'
import { HardhatUserConfig } from 'hardhat/config'

const config: HardhatUserConfig = {
solidity: '0.8.24',
paths: {
artifacts: './build/contracts',
sources: './contracts',
},
}

export default config
1 change: 1 addition & 0 deletions packages/horizon/lib/forge-std
Submodule forge-std added at bb4cee
58 changes: 58 additions & 0 deletions packages/horizon/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@graphprotocol/horizon",
"version": "0.0.1",
"description": "",
"author": "The Graph Team",
"license": "GPL-2.0-or-later",
"scripts": {
"lint:ts": "eslint '**/*.{js,ts}' --fix",
"lint:sol": "prettier --write contracts/**/*.sol && solhint --noPrompt --fix contracts/**/*.sol --config node_modules/solhint-graph-config/index.js",
"lint": "yarn lint:ts && yarn lint:sol",
"clean": "rm -rf build cache typechain-types",
"build": "forge build && hardhat compile",
"test": "forge test && hardhat test"
},
"devDependencies": {
"@graphprotocol/contracts": "workspace:^7.0.0",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.2.0",
"@types/mocha": ">=9.1.0",
"@types/node": ">=16.0.0",
"chai": "^4.2.0",
"eslint": "^8.56.0",
"eslint-graph-config": "workspace:^0.0.1",
"ethers": "^6.4.0",
"hardhat": "^2.20.1",
"hardhat-gas-reporter": "^1.0.8",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.3.1",
"solhint": "^4.5.2",
"solhint-graph-config": "workspace:^0.0.1",
"solidity-coverage": "^0.8.0",
"ts-node": ">=8.0.0",
"typechain": "^8.3.0",
"typescript": "^5.3.3"
},
"lint-staged": {
"contracts/**/*.sol": [
"yarn lint:sol"
],
"**/*.ts": [
"yarn lint:ts"
],
"**/*.js": [
"yarn lint:ts"
],
"**/*.json": [
"yarn lint:ts"
]
}
}
2 changes: 2 additions & 0 deletions packages/horizon/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const prettierGraphConfig = require('solhint-graph-config/prettier')
module.exports = prettierGraphConfig
5 changes: 5 additions & 0 deletions packages/horizon/remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@graphprotocol/contracts/=node_modules/@graphprotocol/contracts/
forge-std/=lib/forge-std/src/
ds-test/=lib/forge-std/lib/ds-test/src/
eth-gas-reporter/=node_modules/eth-gas-reporter/
hardhat/=node_modules/hardhat/
28 changes: 28 additions & 0 deletions packages/horizon/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ethers } from 'hardhat'

async function main() {
const currentTimestampInSeconds = Math.round(Date.now() / 1000)
const unlockTime = currentTimestampInSeconds + 60

const lockedAmount = ethers.parseEther('0.001')
const a = 1
console.log(a)
const lock = await ethers.deployContract('Lock', [unlockTime], {
value: lockedAmount,
})

await lock.waitForDeployment()

console.log(
`Lock with ${ethers.formatEther(
lockedAmount,
)}ETH and unlock timestamp ${unlockTime} deployed to ${typeof lock.target == 'string' ? lock.target : ''}`,
)
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error)
process.exitCode = 1
})
17 changes: 17 additions & 0 deletions packages/horizon/test/SimpleTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.10;

import "forge-std/Test.sol";
import { SimpleTest } from "../contracts/SimpleTest.sol";

contract ContractTest is Test {
SimpleTest simpleTest;

function setUp() public {
simpleTest = new SimpleTest();
}

function test_NumberIs42() public {
assertEq(simpleTest.test(), 42);
}
}
Loading

0 comments on commit 2585495

Please sign in to comment.