Skip to content

Commit 2585495

Browse files
tmigonepcarranzav
authored andcommitted
chore(horizon): add horizon package boilerplate
Signed-off-by: Tomás Migone <[email protected]>
1 parent 0e8895b commit 2585495

28 files changed

+1057
-51
lines changed

.github/actions/setup/action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ runs:
44
using: composite
55

66
steps:
7+
- name: Install Foundry
8+
uses: foundry-rs/foundry-toolchain@v1
79
- name: Enable corepack for modern yarn
810
shell: bash
911
run: corepack enable

.github/workflows/build.yml

+2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v4
19+
with:
20+
submodules: recursive
1921
- name: Set up environment
2022
uses: ./.github/actions/setup

.github/workflows/ci-contracts.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
2325
- name: Set up environment
2426
uses: ./.github/actions/setup
2527
- name: Run tests

.github/workflows/ci-horizon.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI - packages/horizon
2+
3+
env:
4+
CI: true
5+
6+
on:
7+
push:
8+
branches: "*"
9+
paths:
10+
- packages/horizon/**
11+
pull_request:
12+
branches: "*"
13+
paths:
14+
- packages/horizon/**
15+
workflow_dispatch:
16+
17+
jobs:
18+
test-ci:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
25+
- name: Set up environment
26+
uses: ./.github/actions/setup
27+
- name: Run tests
28+
run: |
29+
pushd packages/horizon
30+
yarn test

.github/workflows/ci-token-dist.yml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout
2222
uses: actions/checkout@v4
23+
with:
24+
submodules: recursive
2325
- name: Set up environment
2426
uses: ./.github/actions/setup
2527
- name: Run tests

.github/workflows/e2e-contracts.yml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
steps:
3131
- name: Checkout
3232
uses: actions/checkout@v4
33+
with:
34+
submodules: recursive
3335
- name: Set up environment
3436
uses: ./.github/actions/setup
3537
- name: Run e2e tests

.github/workflows/publish.yml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v4
26+
with:
27+
submodules: recursive
2628
- name: Set up environment
2729
uses: ./.github/actions/setup
2830
- name: Publish 🚀

.github/workflows/verifydeployed.yml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
steps:
2626
- name: Checkout
2727
uses: actions/checkout@v3
28+
with:
29+
submodules: recursive
2830
- name: Set up environment
2931
uses: ./.github/actions/setup
3032

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ cached/
2121
# Build artifacts
2222
dist/
2323
build/
24+
typechain/
25+
typechain-types/
2426
deployments/hardhat/
2527

2628
# Ignore solc bin output
@@ -45,8 +47,10 @@ addresses-fork.json
4547
# Keys
4648
.keystore
4749

50+
# Forge artifacts
51+
cache_forge
4852
# Graph client
4953
.graphclient
5054

5155
tx-builder-*.json
52-
!tx-builder-template.json
56+
!tx-builder-template.json

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "packages/horizon/lib/forge-std"]
2+
path = packages/horizon/lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std

.husky/pre-commit

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ popd
99
# data-edge
1010
pushd packages/data-edge
1111
npx --no-install lint-staged
12-
popd
12+
popd
13+
14+
# graph horizon
15+
pushd packages/horizon
16+
npx --no-install lint-staged
17+
popd

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ This repository is a Yarn workspaces monorepo containing the following packages:
3838
| --- | --- | --- |
3939
| [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. |
4040
| [eslint-graph-config](./packages/eslint-graph-config) | [![npm version]()]() | Shared linting and formatting rules for TypeScript projects. |
41-
| [token-distribution](./packages/token-distribution) | - | Contracts managing token locks for network participants |
41+
| [horizon](./packages/horizon) | [![npm version]()]() | Contracts for Graph Horizon, the next iteration of The Graph protocol. |
4242
| [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 |
4343
| [solhint-graph-config](./packages/eslint-graph-config) | [![npm version]()]() | Shared linting and formatting rules for Solidity projects. |
44+
| [token-distribution](./packages/token-distribution) | - | Contracts managing token locks for network participants |
4445

4546

4647
## Development

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"packages/contracts",
1111
"packages/data-edge",
1212
"packages/eslint-graph-config",
13+
"packages/horizon",
1314
"packages/sdk",
1415
"packages/solhint-graph-config",
1516
"packages/token-distribution"

packages/contracts/contracts/staking/IHorizonStaking.sol

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

3-
pragma solidity 0.7.6;
3+
pragma solidity >=0.7.6 <0.9.0;
44
pragma abicoder v2;
55

6+
interface Test {
7+
function test() external returns (uint256);
8+
}
9+
610
interface IHorizonStaking {
711
struct Provision {
812
// Service provider that created the provision
@@ -93,12 +97,7 @@ interface IHorizonStaking {
9397
function stake(uint256 tokens) external;
9498

9599
// create a provision
96-
function provision(
97-
uint256 tokens,
98-
address verifier,
99-
uint256 maxVerifierCut,
100-
uint256 thawingPeriod
101-
) external;
100+
function provision(uint256 tokens, address verifier, uint256 maxVerifierCut, uint256 thawingPeriod) external;
102101

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

125124
// slash a service provider
126-
function slash(
127-
bytes32 provisionId,
128-
uint256 tokens,
129-
uint256 verifierAmount
130-
) external;
125+
function slash(bytes32 provisionId, uint256 tokens, uint256 verifierAmount) external;
131126

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

151-
function getServiceProvider(address serviceProvider)
152-
external
153-
view
154-
returns (ServiceProvider memory);
146+
function getServiceProvider(address serviceProvider) external view returns (ServiceProvider memory);
155147

156148
function getProvision(bytes32 provision) external view returns (Provision memory);
157149
}

packages/horizon/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Sample Hardhat Project
2+
3+
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.
4+
5+
Try running some of the following tasks:
6+
7+
```shell
8+
npx hardhat help
9+
npx hardhat test
10+
REPORT_GAS=true npx hardhat test
11+
npx hardhat node
12+
npx hardhat run scripts/deploy.ts
13+
```
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
pragma solidity >=0.4.0 <0.9.0;
3+
4+
import { Test } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol";
5+
6+
contract SimpleTest is Test {
7+
function test() external pure returns (uint256) {
8+
return 42;
9+
}
10+
}

packages/horizon/eslint.config.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @ts-check
2+
/* eslint-disable no-undef */
3+
/* eslint-disable @typescript-eslint/no-var-requires */
4+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
5+
6+
const eslintGraphConfig = require('eslint-graph-config')
7+
module.exports = [
8+
...eslintGraphConfig.default,
9+
{
10+
rules: {
11+
'@typescript-eslint/no-unsafe-assignment': 'off',
12+
'@typescript-eslint/no-var-requires': 'off',
13+
'@typescript-eslint/no-unsafe-call': 'off',
14+
'@typescript-eslint/no-unsafe-member-access': 'off',
15+
'@typescript-eslint/no-unsafe-argument': 'off',
16+
},
17+
},
18+
{
19+
ignores: ['typechain-types/*'],
20+
},
21+
]

packages/horizon/foundry.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile.default]
2+
src = 'contracts'
3+
out = 'build'
4+
libs = ['node_modules', 'lib']
5+
test = 'test'
6+
cache_path = 'cache_forge'

packages/horizon/hardhat.config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// import '@nomicfoundation/hardhat-foundry'
2+
import '@nomicfoundation/hardhat-toolbox'
3+
import { HardhatUserConfig } from 'hardhat/config'
4+
5+
const config: HardhatUserConfig = {
6+
solidity: '0.8.24',
7+
paths: {
8+
artifacts: './build/contracts',
9+
sources: './contracts',
10+
},
11+
}
12+
13+
export default config

packages/horizon/lib/forge-std

Submodule forge-std added at bb4ceea

packages/horizon/package.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "@graphprotocol/horizon",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "The Graph Team",
6+
"license": "GPL-2.0-or-later",
7+
"scripts": {
8+
"lint:ts": "eslint '**/*.{js,ts}' --fix",
9+
"lint:sol": "prettier --write contracts/**/*.sol && solhint --noPrompt --fix contracts/**/*.sol --config node_modules/solhint-graph-config/index.js",
10+
"lint": "yarn lint:ts && yarn lint:sol",
11+
"clean": "rm -rf build cache typechain-types",
12+
"build": "forge build && hardhat compile",
13+
"test": "forge test && hardhat test"
14+
},
15+
"devDependencies": {
16+
"@graphprotocol/contracts": "workspace:^7.0.0",
17+
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
18+
"@nomicfoundation/hardhat-ethers": "^3.0.0",
19+
"@nomicfoundation/hardhat-foundry": "^1.1.1",
20+
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
21+
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
22+
"@nomicfoundation/hardhat-verify": "^2.0.0",
23+
"@typechain/ethers-v6": "^0.5.0",
24+
"@typechain/hardhat": "^9.0.0",
25+
"@types/chai": "^4.2.0",
26+
"@types/mocha": ">=9.1.0",
27+
"@types/node": ">=16.0.0",
28+
"chai": "^4.2.0",
29+
"eslint": "^8.56.0",
30+
"eslint-graph-config": "workspace:^0.0.1",
31+
"ethers": "^6.4.0",
32+
"hardhat": "^2.20.1",
33+
"hardhat-gas-reporter": "^1.0.8",
34+
"lint-staged": "^15.2.2",
35+
"prettier": "^3.2.5",
36+
"prettier-plugin-solidity": "^1.3.1",
37+
"solhint": "^4.5.2",
38+
"solhint-graph-config": "workspace:^0.0.1",
39+
"solidity-coverage": "^0.8.0",
40+
"ts-node": ">=8.0.0",
41+
"typechain": "^8.3.0",
42+
"typescript": "^5.3.3"
43+
},
44+
"lint-staged": {
45+
"contracts/**/*.sol": [
46+
"yarn lint:sol"
47+
],
48+
"**/*.ts": [
49+
"yarn lint:ts"
50+
],
51+
"**/*.js": [
52+
"yarn lint:ts"
53+
],
54+
"**/*.json": [
55+
"yarn lint:ts"
56+
]
57+
}
58+
}

packages/horizon/prettier.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const prettierGraphConfig = require('solhint-graph-config/prettier')
2+
module.exports = prettierGraphConfig

packages/horizon/remappings.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@graphprotocol/contracts/=node_modules/@graphprotocol/contracts/
2+
forge-std/=lib/forge-std/src/
3+
ds-test/=lib/forge-std/lib/ds-test/src/
4+
eth-gas-reporter/=node_modules/eth-gas-reporter/
5+
hardhat/=node_modules/hardhat/

packages/horizon/scripts/deploy.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ethers } from 'hardhat'
2+
3+
async function main() {
4+
const currentTimestampInSeconds = Math.round(Date.now() / 1000)
5+
const unlockTime = currentTimestampInSeconds + 60
6+
7+
const lockedAmount = ethers.parseEther('0.001')
8+
const a = 1
9+
console.log(a)
10+
const lock = await ethers.deployContract('Lock', [unlockTime], {
11+
value: lockedAmount,
12+
})
13+
14+
await lock.waitForDeployment()
15+
16+
console.log(
17+
`Lock with ${ethers.formatEther(
18+
lockedAmount,
19+
)}ETH and unlock timestamp ${unlockTime} deployed to ${typeof lock.target == 'string' ? lock.target : ''}`,
20+
)
21+
}
22+
23+
// We recommend this pattern to be able to use async/await everywhere
24+
// and properly handle errors.
25+
main().catch((error) => {
26+
console.error(error)
27+
process.exitCode = 1
28+
})
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: GPL-3.0
2+
pragma solidity 0.8.10;
3+
4+
import "forge-std/Test.sol";
5+
import { SimpleTest } from "../contracts/SimpleTest.sol";
6+
7+
contract ContractTest is Test {
8+
SimpleTest simpleTest;
9+
10+
function setUp() public {
11+
simpleTest = new SimpleTest();
12+
}
13+
14+
function test_NumberIs42() public {
15+
assertEq(simpleTest.test(), 42);
16+
}
17+
}

0 commit comments

Comments
 (0)