Skip to content

Commit 87d41a8

Browse files
committed
fix: SAO updates from old repo
1 parent 15f9d5e commit 87d41a8

File tree

11 files changed

+454
-452
lines changed

11 files changed

+454
-452
lines changed

Cargo.lock

Lines changed: 303 additions & 408 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
## Subgraph Oracle
2-
3-
The Subgraph Oracle verifies the availability of the subgraph files and does other validity checks, if a subgraph is found to be invalid it will be denied rewards in the RewardsManager contract.
2+
The Subgraph Oracle verifies the availability of the subgraph files and does other validity checks, if a subgraph is found to be invalid it will be denied rewards in the rewards manager contract. Usage:
43

54
```
65
USAGE:
@@ -13,7 +12,7 @@ FLAGS:
1312
1413
OPTIONS:
1514
-c, --contracts <contracts>
16-
One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, or `ganache/mainnet`. See
15+
One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, `ganache/mainnet`, `sepolia` or `arbitrum-sepolia`. See
1716
`common/src/contracts/config.rs` for the respective configurations [env: ORACLE_CONTRACTS=]
1817
--grace-period <grace-period>
1918
Grace period, in seconds from subgraph creation, for which subgraphs will not be checked [env:

availability-oracle/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "availability-oracle"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["Leonardo Yvens <[email protected]>"]
55
edition = "2018"
66

@@ -10,7 +10,7 @@ edition = "2018"
1010
common = { path = "../common" }
1111
async-trait = "0.1.50"
1212
tokio = { version = "1.10", features = ["macros", "sync", "time"] }
13-
serde_yaml = "0.8.13"
13+
serde_yaml = "0.9"
1414
reqwest = { version = "0.11.4", features = ["json"] }
1515
serde_derive = "1.0.116"
1616
serde = "1.0.116"

availability-oracle/src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ struct Config {
8787
long,
8888
env = "ORACLE_CONTRACTS",
8989
required_unless("dry-run"),
90-
help = "One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, or `ganache/mainnet`. \
90+
help = "One of: `mainnet`, `goerli`, `arbitrum-one`, `arbitrum-goerli`, `ganache/mainnet` \
91+
`sepolia` or `arbitrum-sepolia`. \
9192
See `common/src/contracts/config.rs` for the respective \
9293
configurations"
9394
)]
@@ -132,7 +133,7 @@ struct Config {
132133
// Note: `ethereum/contract` is a valid alias for `ethereum`
133134
#[structopt(
134135
long,
135-
default_value = "ethereum,ethereum/contract,file/ipfs",
136+
default_value = "ethereum,ethereum/contract,file/ipfs,substreams",
136137
value_delimiter = ",",
137138
env = "SUPPORTED_DATA_SOURCE_KINDS",
138139
help = "a comma separated list of the supported data source kinds"
@@ -434,18 +435,20 @@ async fn check(
434435
// Check that:
435436
// - The subgraph has the same network in all data sources.
436437
// - That network is listed in the `supported_networks` list
437-
match network {
438-
None => {
438+
match (network, ds_network) {
439+
(None, Some(ds_network)) => {
439440
if !supported_network_ids.contains(ds_network) {
440441
return Err(Invalid::UnsupportedNetwork(ds_network.clone()).into());
441442
}
442443
network = Some(ds_network)
443444
}
444-
Some(network) => {
445+
(Some(network), Some(ds_network)) => {
445446
if network != ds_network {
446447
return Err(Invalid::ManifestParseError(anyhow!("mismatching networks")).into());
447448
}
448449
}
450+
// Data sources such as file data sources don't have a network
451+
(_, None) => (),
449452
}
450453

451454
// Check that ABIs are valid.
@@ -455,11 +458,13 @@ async fn check(
455458
}
456459

457460
// Check mappings.
458-
let wasm = ipfs.cat(check_link(file)?).await?;
459-
if let Some(host_fn) =
460-
calls_any_host_fn(&wasm, FORBIDDEN_HOST_FN_PREFIX).map_err(Invalid::WasmParseError)?
461-
{
462-
return Err(Invalid::ForbiddenApi(host_fn.to_string()).into());
461+
if let Some(file) = file {
462+
let wasm = ipfs.cat(check_link(file)?).await?;
463+
if let Some(host_fn) = calls_any_host_fn(&wasm, FORBIDDEN_HOST_FN_PREFIX)
464+
.map_err(Invalid::WasmParseError)?
465+
{
466+
return Err(Invalid::ForbiddenApi(host_fn.to_string()).into());
467+
}
463468
}
464469
}
465470

availability-oracle/src/manifest.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ pub(crate) struct Abi {
1818

1919
#[derive(Clone, Debug, Deserialize)]
2020
pub(crate) struct Mapping {
21-
pub(crate) file: Link,
21+
pub(crate) file: Option<Link>,
22+
#[serde(default)]
2223
pub(crate) abis: Vec<Abi>,
2324
}
2425

2526
#[derive(Clone, Debug, Deserialize)]
2627
pub(crate) struct DataSource {
2728
pub(crate) kind: String,
28-
pub(crate) network: String,
29+
pub(crate) network: Option<String>,
2930
pub(crate) mapping: Mapping,
3031
}
3132

availability-oracle/src/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async fn test_reconcile() {
5656
"ethereum".into(),
5757
"ethereum/contract".into(),
5858
"file/ipfs".into(),
59+
"substreams".into(),
5960
],
6061
)
6162
.await
@@ -142,13 +143,13 @@ impl contract::RewardsManager for MockRewardsManager {
142143
})
143144
.collect::<Vec<_>>();
144145

146+
assert!(denied_status.len() == 6);
145147
assert_eq!(denied_status[0], (TWO.to_string(), true));
146148
assert_eq!(denied_status[1], (THREE.to_string(), true));
147149
assert_eq!(denied_status[2], (FOUR.to_string(), false));
148150
assert_eq!(denied_status[3], (FIVE.to_string(), true));
149151
assert_eq!(denied_status[4], (SIX.to_string(), true));
150152
assert_eq!(denied_status[5], (SEVEN.to_string(), true));
151-
assert_eq!(denied_status[6], (SUBSTREAM.to_string(), true));
152153

153154
Ok(())
154155
}

availability-oracle/src/test_files/file_ds.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ dataSources:
2424
handler: handleTrigger
2525
file:
2626
/: QmWt3wasmzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
27+
templates:
28+
- kind: file/ipfs
29+
mapping:
30+
abis:
31+
- file:
32+
/: /ipfs/QmWt3abizzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
33+
name: Contract
34+
apiVersion: 0.0.7
35+
entities:
36+
- ERC721TokenMetadata
37+
file:
38+
/: /ipfs/QmWt3wasmzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
39+
handler: handler
40+
language: wasm/assemblyscript
41+
name: fileDsTemplate
Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
specVersion: 0.0.2
2-
schema:
3-
file:
4-
/: QmWt3schemazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
51
dataSources:
62
- kind: substreams
7-
name: Contract
3+
mapping:
4+
apiVersion: 0.0.5
5+
kind: substreams/graph-entities
6+
name: my_substreams
87
network: mainnet
98
source:
10-
address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601"
11-
abi: Contract
12-
mapping:
13-
kind: ethereum/events
14-
apiVersion: 0.0.4
15-
language: wasm/assemblyscript
16-
abis:
17-
- name: Contract
18-
file:
19-
/: QmWt3abizzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
20-
entities:
21-
- Call
22-
eventHandlers:
23-
- event: Trigger(uint16)
24-
handler: handleTrigger
25-
file:
26-
/: QmWt3wasmzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
9+
package:
10+
file:
11+
/: /ipfs/whatever
12+
moduleName: graph_out
13+
schema:
14+
file:
15+
/: /ipfs/QmWt3schemazzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
16+
specVersion: 0.0.6

common/src/chain_id.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use eip_712_derive::U256;
2+
3+
pub const MAIN_NET: U256 = U256([
4+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
5+
]);
6+
7+
pub const GOERLI: U256 = U256([
8+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
9+
]);
10+
11+
// 421613 = 0x66EED is the chain ID for Arbitrum Goerli
12+
pub const ARBITRUM_GOERLI: U256 = U256([
13+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 110,
14+
237,
15+
]);
16+
17+
// 42161 = 0xA4B1 is the chain ID for Arbitrum One
18+
pub const ARBITRUM_ONE: U256 = U256([
19+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 164,
20+
177,
21+
]);
22+
23+
// 111551111 = 0xAA36A7 is the chain ID for Sepolia
24+
pub const SEPOLIA: U256 = U256([
25+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 54,
26+
167,
27+
]);
28+
29+
// 421614 = 0x66EEE is the chain ID for Arbitrum Sepolia
30+
pub const ARBITRUM_SEPOLIA: U256 = U256([
31+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 110,
32+
238,
33+
]);

common/src/contracts/config.rs

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use super::ContractConfig;
2+
use crate::chain_id::{ARBITRUM_GOERLI, ARBITRUM_ONE, ARBITRUM_SEPOLIA, GOERLI, MAIN_NET, SEPOLIA};
23
use crate::prelude::*;
34
use anyhow::anyhow;
4-
use eip_712_derive::{
5-
chain_id::{ARBITRUM_GOERLI, ARBITRUM_ONE, GOERLI, MAIN_NET},
6-
U256,
7-
};
5+
use eip_712_derive::U256;
86
use serde::{Deserialize, Deserializer};
97
use serde_json;
108
use std::{collections::BTreeMap, fs::File, path::Path, str::FromStr};
@@ -113,6 +111,68 @@ impl ContractConfig {
113111
chain_id: ARBITRUM_ONE,
114112
}
115113
}
114+
115+
pub fn sepolia(url: &str) -> Self {
116+
Self {
117+
url: url.into(),
118+
graph_token: "0xCA59cCeb39bE1808d7aA607153f4A5062daF3a83"
119+
.parse()
120+
.unwrap(),
121+
epoch_manager: "0x3C39036a76104D7c6D3eF13a21477C0fE23A3Aa2"
122+
.parse()
123+
.unwrap(),
124+
dispute_manager: "0x1Da0DF3435cde4199650D35690E3B0885dfc38B1"
125+
.parse()
126+
.unwrap(),
127+
staking: "0x14e9B07Dc56A0B03ac8A58453B5cCCB289d6ec90"
128+
.parse()
129+
.unwrap(),
130+
curation: "0x77A6e5F2f13218B33A97Aec56d591dB18D60FFb1"
131+
.parse()
132+
.unwrap(),
133+
rewards_manager: "0x175f483AfAB4Fc52A6E07F9e9d46C90eB95941b5"
134+
.parse()
135+
.unwrap(),
136+
service_registry: "0x0Ee47634c94E6606f67301b3A868319073CB0FC2"
137+
.parse()
138+
.unwrap(),
139+
gns: "0x5461D48556B94e7fdD8ED5A8f865Ba4F1A3b5454"
140+
.parse()
141+
.unwrap(),
142+
chain_id: SEPOLIA,
143+
}
144+
}
145+
146+
pub fn arbitrum_sepolia(url: &str) -> Self {
147+
Self {
148+
url: url.into(),
149+
graph_token: "0xf8c05dCF59E8B28BFD5eed176C562bEbcfc7Ac04"
150+
.parse()
151+
.unwrap(),
152+
epoch_manager: "0x88b3C7f37253bAA1A9b95feAd69bD5320585826D"
153+
.parse()
154+
.unwrap(),
155+
dispute_manager: "0x7C9B82717f9433932507dF6EdA93A9678b258698"
156+
.parse()
157+
.unwrap(),
158+
staking: "0x865365C425f3A593Ffe698D9c4E6707D14d51e08"
159+
.parse()
160+
.unwrap(),
161+
curation: "0xDe761f075200E75485F4358978FB4d1dC8644FD5"
162+
.parse()
163+
.unwrap(),
164+
rewards_manager: "0x1F49caE7669086c8ba53CC35d1E9f80176d67E79"
165+
.parse()
166+
.unwrap(),
167+
service_registry: "0x888541878CbDDEd880Cd58c728f1Af5C47343F86"
168+
.parse()
169+
.unwrap(),
170+
gns: "0x3133948342F35b8699d8F94aeE064AbB76eDe965"
171+
.parse()
172+
.unwrap(),
173+
chain_id: ARBITRUM_SEPOLIA,
174+
}
175+
}
116176
}
117177

118178
// The idea behind having this .parse() compatible API is to be able to easily
@@ -126,8 +186,10 @@ impl FromStr for ContractConfig {
126186
["mainnet", url] => ContractConfig::mainnet(url),
127187
["ganache/mainnet"] => ContractConfig::ganache(MAIN_NET),
128188
["goerli", url] => ContractConfig::goerli(url),
189+
["sepolia", url] => ContractConfig::sepolia(url),
129190
["arbitrum-goerli", url] => ContractConfig::arbitrum_goerli(url),
130191
["arbitrum-one", url] => ContractConfig::arbitrum_one(url),
192+
["arbitrum-sepolia", url] => ContractConfig::arbitrum_sepolia(url),
131193
_ => {
132194
return Err(anyhow!("Unrecognized format. Expecting: network:url (or just network for \"ganache/mainnet\"). Got: {}", s));
133195
}

0 commit comments

Comments
 (0)