Skip to content

Commit

Permalink
feat: support syncing_network filter in subgraph selection
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 27, 2023
1 parent bba8173 commit 09a3b38
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ min_signal = 100
verbose = true
num_reported_options = 2
execution_mode = "none"
opt_mode = "fast"
opt_mode = "optimal"
network_subgraph_endpoint = "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet"
protocol_network = "mainnet"
syncing_networks = ["mainnet", "gnosis"]
5 changes: 5 additions & 0 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ num_reported_options = 2
execution_mode = "none"
opt_mode = "fast"
protocol_network = "mainnet"
syncing_networks = ["mainnet"]
```


Expand Down Expand Up @@ -83,6 +84,9 @@ protocol_network = "mainnet"
- `protocol_network::String`: Defines the protocol network that allocation transactions
should be sent to. The current protocol network options are "mainnet", "goerli",
"arbitrum", and "arbitrum-goerli". By default, `"mainnet"`
- `syncing_networks::Vector{String}`: The list of syncing networks to support when selecting
the set of possible subgraphs. This list should match the networks available to your
graph-node. By default, the list is a singleton of your protocol network

### Example Configurations

Expand All @@ -107,6 +111,7 @@ num_reported_options = 2
execution_mode = "actionqueue"
indexer_url = "https://localhost:8000"
protocol_network = "arbitrum"
syncing_network = ["mainnet"]
```

#### Indexer Rules
Expand Down
6 changes: 6 additions & 0 deletions src/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Set default values for the config dictionary if the value was not specified in t
- `protocol_network::String`: Defines the protocol network that allocation transactions
should be sent to. The current protocol network options are "mainnet", "goerli",
"arbitrum", and "arbitrum-goerli". By default, `"mainnet"`
- `syncing_networks::Vector{String}`: The list of syncing networks to support when selecting
the set of possible subgraphs. This list should match the networks available to your
graph-node. By default, the list is a singleton of your protocol network
```julia
julia> using AllocationOpt
Expand All @@ -80,6 +83,7 @@ Dict{String, Any} with 16 entries:
"network_subgraph_endpoint" => "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet"
"whitelist" => String[]
"protocol_network" => "mainnet"
"syncing_networks" => String["mainnet"]
```
"""
function configuredefaults!(config::AbstractDict)
Expand All @@ -105,6 +109,7 @@ function configuredefaults!(config::AbstractDict)
setdefault!(config, "verbose", false)
setdefault!(config, "opt_mode", "optimal")
setdefault!(config, "protocol_network", "mainnet")
setdefault!(config, "syncing_networks", String[config["protocol_network"]])
return config
end

Expand Down Expand Up @@ -152,6 +157,7 @@ Dict{String, Any} with 13 entries:
"max_allocations" => 5
"frozenlist" => Union{}[]
"protocol_network" => "mainnet"
"syncing_networks" => String["mainnet", "gnosis"]
```
"""
readconfig(p::AbstractString) = p |> TOML.parsefile
13 changes: 8 additions & 5 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
# SPDX-Licen se-Identifier: MIT

"""
squery()
squery(config::AbstractDict)
Return the components of a GraphQL query for subgraphs.
For use with the TheGraphData.jl package.
```julia
julia> using AllocationOpt
julia> value, args, fields = AllocationOpt.squery()
julia> config = Dict("syncing_networking" => ["mainnet"])
julia> value, args, fields = AllocationOpt.squery(config)
("subgraphDeployments", Dict{String, Union{Dict{String, String}, String}}(), ["ipfsHash", "signalledTokens", "stakedTokens"])
```
# Extended Help
You can find TheGraphData.jl at https://github.com/semiotic-ai/TheGraphData.jl
"""
function squery()
function squery(config::AbstractDict)
v = "subgraphDeployments"
a = Dict{String,Union{Dict{String,String},String}}()
a = Dict{String,Any}(
"where" => Dict{String,Any}("network_in" => config["syncing_networks"])
)
f = ["ipfsHash", "signalledTokens", "stakedTokens", "deniedAt"]
return v, a, f
end
Expand Down Expand Up @@ -180,7 +183,7 @@ function read(::Nothing, config::AbstractDict{String,Any})
flextable(d)
end

s = flextable(@mock(paginated_query(squery()...)))
s = flextable(@mock(paginated_query(squery(config)...)))
n = flextable(@mock(query(nquery()...)))

# Convert string types to GRT
Expand Down
1 change: 1 addition & 0 deletions test/configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@test !config["verbose"]
@test config["opt_mode"] == "optimal"
@test config["protocol_network"] == "mainnet"
@test config["syncing_networks"] == ["mainnet"]

config = Dict{String,Any}("id" => "a", "gas" => 0)
config = AllocationOpt.configuredefaults!(config)
Expand Down
8 changes: 6 additions & 2 deletions test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

@testset "data" begin
@testset "squery" begin
v, a, f = AllocationOpt.squery()
config = Dict("syncing_networks" => ["mainnet"])
v, a, f = AllocationOpt.squery(config)
@test v == "subgraphDeployments"
@test f == ["ipfsHash", "signalledTokens", "stakedTokens", "deniedAt"]
@test a == Dict{String,Union{Dict{String,String},String}}()
@test a == Dict{String,Union{Dict{String,Vector{String}},String}}(
"where" => Dict("network_in" => ["mainnet"])
)
end

@testset "iquery" begin
Expand Down Expand Up @@ -224,6 +227,7 @@
"verbose" => false,
"network_subgraph_endpoint" => "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet",
"readdir" => nothing,
"syncing_networks" => ["mainnet"],
)
apply(paginated_query_success_patch) do
apply(query_success_patch) do
Expand Down

0 comments on commit 09a3b38

Please sign in to comment.