Skip to content

Commit 67fd967

Browse files
committed
chore: add DataEdge contracts
1 parent 59154f7 commit 67fd967

33 files changed

+13105
-0
lines changed

packages/data-edge/.env.sample

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
MNEMONIC=
2+
INFURA_KEY=
3+
ETHERSCAN_API_KEY=
4+
ARBISCAN_API_KEY=

packages/data-edge/.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
cache/
3+
dist/
4+
node_modules/
5+
reports/

packages/data-edge/.eslintrc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"parserOptions": {
4+
"ecmaVersion": 2020,
5+
"sourceType": "module"
6+
},
7+
"extends": ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
8+
"rules": {
9+
"prefer-const": "warn",
10+
"no-extra-semi": "off",
11+
"@typescript-eslint/no-extra-semi": "warn",
12+
"@typescript-eslint/no-inferrable-types": "warn",
13+
"@typescript-eslint/no-empty-function": "warn"
14+
}
15+
}

packages/data-edge/.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.sol linguist-language=Solidity

packages/data-edge/.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
cd packages/contracts
3+
4+
npx --no-install commitlint --edit ""

packages/data-edge/.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
cd packages/contracts
3+
4+
yarn lint

packages/data-edge/.prettierignore

Whitespace-only changes.

packages/data-edge/.prettierrc.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"printWidth": 120,
3+
"useTabs": false,
4+
"bracketSpacing": true,
5+
"overrides": [
6+
{
7+
"files": "*.js",
8+
"options": {
9+
"semi": false,
10+
"trailingComma": "all",
11+
"tabWidth": 2,
12+
"singleQuote": true,
13+
"explicitTypes": "always"
14+
}
15+
},
16+
{
17+
"files": "*.ts",
18+
"options": {
19+
"semi": false,
20+
"trailingComma": "all",
21+
"tabWidth": 2,
22+
"singleQuote": true,
23+
"explicitTypes": "always"
24+
}
25+
},
26+
{
27+
"files": "*.sol",
28+
"options": {
29+
"tabWidth": 4,
30+
"singleQuote": false,
31+
"explicitTypes": "always"
32+
}
33+
}
34+
]
35+
}

packages/data-edge/.solcover.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const skipFiles = ['']
2+
3+
module.exports = {
4+
providerOptions: {
5+
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
6+
network_id: 1337,
7+
},
8+
skipFiles,
9+
istanbulFolder: './reports/coverage',
10+
}

packages/data-edge/.solhint.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "solhint:recommended",
3+
"plugins": ["prettier"],
4+
"rules": {
5+
"prettier/prettier": "error",
6+
"func-visibility": ["warn", { "ignoreConstructors": true }],
7+
"compiler-version": ["off"],
8+
"constructor-syntax": "warn",
9+
"quotes": ["error", "double"],
10+
"reason-string": ["off"],
11+
"not-rely-on-time": "off",
12+
"no-empty-blocks": "off"
13+
}
14+
}
15+

packages/data-edge/.solhintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

packages/data-edge/LICENSE

+342
Large diffs are not rendered by default.

packages/data-edge/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Data Edge
2+
3+
A DataEdge contract is used to store arbitrary data on-chain on any EVM compatible blockchain. A subgraph can then read all the calldata sent to a particular contract, decode it and update the subgraph state accordingly.
4+
5+
The DataEdge accepts any function call by using a fallback function that will not revert. It is up to the implementor to define the calldata format as well as how to decode it.
6+
7+
### Additional Considerations
8+
9+
- Fallback is not payable to avoid anyone sending ETH by mistake as the main purpose is to store calldata.
10+
11+
# Deploying
12+
13+
Setup a `.env` file with the keys you want to use for deployments. You can use `.env.sample` as a guide.
14+
Deploy a `DataEdge` contract by running `yarn deploy -- --network <network-name>`
15+
16+
# Copyright
17+
18+
Copyright &copy; 2022 The Graph Foundation
19+
20+
Licensed under [GPL license](LICENSE).

packages/data-edge/addresses.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"421614": {
3+
"DataEdge": "0x17f1fcD16E2A9fF2a55c63C97a778D96Fa473548",
4+
"EventfulDataEdge": "0x9b9402939133F27c6eba81a321dfBFa1feE6714E"
5+
},
6+
"11155111": {
7+
"DataEdge": "0x00C602A72363917Bc30a793593731F93352eB85d",
8+
"EventfulDataEdge": "0xEFC8D47673777b899f2FB597C6FC0E87ecce98Cb"
9+
}
10+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] }
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
pragma solidity ^0.8.12;
4+
5+
/// @title Data Edge contract is only used to store on-chain data, it does not
6+
/// perform execution. On-chain client services can read the data
7+
/// and decode the payload for different purposes.
8+
contract DataEdge {
9+
/// @dev Fallback function, accepts any payload
10+
fallback() external payable {
11+
// no-op
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
pragma solidity ^0.8.12;
4+
5+
/// @title Data Edge contract is only used to store on-chain data, it does not
6+
/// perform execution. On-chain client services can read the data
7+
/// and decode the payload for different purposes.
8+
/// NOTE: This version emits an event with the calldata.
9+
contract EventfulDataEdge {
10+
event Log(bytes data);
11+
12+
/// @dev Fallback function, accepts any payload
13+
fallback() external payable {
14+
emit Log(msg.data);
15+
}
16+
}

packages/data-edge/hardhat.config.ts

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import * as dotenv from 'dotenv'
2+
dotenv.config()
3+
4+
import { HardhatUserConfig } from 'hardhat/types'
5+
import { task } from 'hardhat/config'
6+
7+
// Plugins
8+
9+
import '@nomiclabs/hardhat-ethers'
10+
import '@nomiclabs/hardhat-etherscan'
11+
import '@nomiclabs/hardhat-waffle'
12+
import 'hardhat-abi-exporter'
13+
import 'hardhat-gas-reporter'
14+
import 'hardhat-contract-sizer'
15+
import '@tenderly/hardhat-tenderly'
16+
import '@openzeppelin/hardhat-upgrades'
17+
import '@typechain/hardhat'
18+
19+
// Tasks
20+
21+
import './tasks/craft-calldata'
22+
import './tasks/post-calldata'
23+
24+
// Networks
25+
26+
interface NetworkConfig {
27+
network: string
28+
chainId: number
29+
gas?: number | 'auto'
30+
gasPrice?: number | 'auto'
31+
url?: string
32+
}
33+
34+
const networkConfigs: NetworkConfig[] = [
35+
{ network: 'mainnet', chainId: 1 },
36+
{ network: 'ropsten', chainId: 3 },
37+
{ network: 'rinkeby', chainId: 4 },
38+
{ network: 'kovan', chainId: 42 },
39+
{ network: 'sepolia', chainId: 11155111 },
40+
{
41+
network: 'arbitrum-one',
42+
chainId: 42161,
43+
url: 'https://arb1.arbitrum.io/rpc',
44+
},
45+
{
46+
network: 'arbitrum-goerli',
47+
chainId: 421613,
48+
url: 'https://goerli-rollup.arbitrum.io/rpc',
49+
},
50+
{
51+
network: 'arbitrum-sepolia',
52+
chainId: 421614,
53+
url: 'https://sepolia-rollup.arbitrum.io/rpcblock',
54+
},
55+
]
56+
57+
function getAccountMnemonic() {
58+
return process.env.MNEMONIC || ''
59+
}
60+
61+
function getDefaultProviderURL(network: string) {
62+
return `https://${network}.infura.io/v3/${process.env.INFURA_KEY}`
63+
}
64+
65+
function setupDefaultNetworkProviders(buidlerConfig) {
66+
for (const netConfig of networkConfigs) {
67+
buidlerConfig.networks[netConfig.network] = {
68+
chainId: netConfig.chainId,
69+
url: netConfig.url ? netConfig.url : getDefaultProviderURL(netConfig.network),
70+
gas: netConfig.gasPrice || 'auto',
71+
gasPrice: netConfig.gasPrice || 'auto',
72+
accounts: {
73+
mnemonic: getAccountMnemonic(),
74+
},
75+
}
76+
}
77+
}
78+
79+
// Tasks
80+
81+
task('accounts', 'Prints the list of accounts', async (taskArgs, bre) => {
82+
const accounts = await bre.ethers.getSigners()
83+
for (const account of accounts) {
84+
console.log(await account.getAddress())
85+
}
86+
})
87+
88+
// Config
89+
const config: HardhatUserConfig = {
90+
paths: {
91+
sources: './contracts',
92+
tests: './test',
93+
artifacts: './build/contracts',
94+
},
95+
solidity: {
96+
compilers: [
97+
{
98+
version: '0.8.12',
99+
settings: {
100+
optimizer: {
101+
enabled: true,
102+
runs: 200,
103+
},
104+
outputSelection: {
105+
'*': {
106+
'*': ['storageLayout'],
107+
},
108+
},
109+
},
110+
},
111+
],
112+
},
113+
defaultNetwork: 'hardhat',
114+
networks: {
115+
hardhat: {
116+
chainId: 1337,
117+
loggingEnabled: false,
118+
gas: 1200000,
119+
gasPrice: 'auto',
120+
blockGasLimit: 12000000,
121+
accounts: {
122+
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
123+
},
124+
mining: {
125+
auto: true,
126+
interval: 0,
127+
},
128+
},
129+
ganache: {
130+
chainId: 1337,
131+
url: 'http://localhost:8545',
132+
},
133+
},
134+
etherscan: {
135+
apiKey: {
136+
mainnet: process.env.ETHERSCAN_API_KEY,
137+
goerli: process.env.ETHERSCAN_API_KEY,
138+
sepolia: process.env.ETHERSCAN_API_KEY,
139+
arbitrumOne: process.env.ARBISCAN_API_KEY,
140+
arbitrumGoerli: process.env.ARBISCAN_API_KEY,
141+
arbitrumSepolia: process.env.ARBISCAN_API_KEY,
142+
},
143+
customChains: [
144+
{
145+
network: 'arbitrumSepolia',
146+
chainId: 421614,
147+
urls: {
148+
apiURL: 'https://api-sepolia.arbiscan.io/api',
149+
browserURL: 'https://sepolia.arbiscan.io',
150+
},
151+
},
152+
],
153+
},
154+
gasReporter: {
155+
enabled: process.env.REPORT_GAS ? true : false,
156+
showTimeSpent: true,
157+
currency: 'USD',
158+
outputFile: 'reports/gas-report.log',
159+
},
160+
typechain: {
161+
outDir: 'build/types',
162+
target: 'ethers-v5',
163+
},
164+
abiExporter: {
165+
path: './build/abis',
166+
clear: false,
167+
flat: true,
168+
},
169+
tenderly: {
170+
project: process.env.TENDERLY_PROJECT,
171+
username: process.env.TENDERLY_USERNAME,
172+
},
173+
contractSizer: {
174+
alphaSort: true,
175+
runOnCompile: false,
176+
disambiguatePaths: true,
177+
},
178+
}
179+
180+
setupDefaultNetworkProviders(config)
181+
182+
export default config

0 commit comments

Comments
 (0)