Skip to content

Commit

Permalink
feat: Set defaults values for config
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 8, 2023
1 parent 4c863a3 commit 4f39de3
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/AllocationOpt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2022-, The Graph Foundation
# SPDX-License-Identifier: MIT

module AllocationOpt

using TheGraphData

include("configuration.jl")

end
71 changes: 71 additions & 0 deletions src/configuration.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2022-, The Graph Foundation
# SPDX-License-Identifier: MIT

"""
configuredefaults!(config::AbstractDict)
Set default values for the config dictionary if the value was not specified in the config file.
# Config Specification
- `network_subgraph_endpoint::String`: The network subgraph endpoint to query.
By default, `"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet"`
- `writedir::String`: The directory to which to write the results of optimisation.
If don't specify `readdir`, `writedir` also specifies the path to which to save
the input data tables. By default, `"."`
- `readdir::Union{String, Nothing}`: The directory from which to read saved data tables.
This speeds up the process as we won't have to query the network subgraph for the
relevant data. If you don't specify `readdir`, we will query your specified
`network_subgraph_endpoint` for the data and write it to CSV files in `writedir`.
This way, you can use your previous `writedir` as your `readdir` in future runs.
By default, `nothing`
- `whitelist::Vector{String}`: A list of subgraph IPFS hashes that you want to consider
as candidates to which to allocate. If you leave this empty, we'll assume all subgraphs
are in the whitelist. By default, `String[]`
- `blacklist::Vector{String}`: A list of subgraph IPFS hashes that you do not want to
consider allocating to. For example, this list could include broken subgraphs or
subgraphs that you don't want to index. By default, `String[]`
- `frozenlist::Vector{String}`: If you have open allocations that you don't want to change,
add the corresponding subgraph IPFS hashes to this list. By default, `String[]`
- `pinnedlist::Vector{String}`: If you have subgraphs that you absolutely want to be
allocated to, even if only with a negligible amount of GRT, add it to this list.
By default, `String[]`
- `allocation_lifetime::Integer`: The number of epochs for which you expect the allocations
the optimiser finds to be open. By default, `28`
- `gas::Real`: The estimated gas cost in GRT to open/close allocations. By default, `100`
- `min_signal::Real`: The minimum amount of signal in GRT that must be on a subgraph
in order for you to consider allocating to it. By default, `1000`
- `max_allocations::Integer`: The maximum number of new allocations you'd like the optimiser
to consider opening. By default, `10`
- `verbose::Bool`: If true, the optimiser will print details about what it is doing to
stdout. By default, `false`
```julia
julia> using AllocationOpt
julia> config = Dict()
julia> config = AllocationOpt.configuredefaults!(config)
[...]
julia> isnothing(config["readdir"])
true
julia> config["writedir"] == "."
true
```
"""
function configuredefaults!(config::AbstractDict)
setdefault!(
config,
"network_subgraph_endpoint",
"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet",
)
setdefault!(config, "writedir", ".")
setdefault!(config, "readdir", nothing)
setdefault!(config, "whitelist", String[])
setdefault!(config, "blacklist", String[])
setdefault!(config, "frozenlist", String[])
setdefault!(config, "pinnedlist", String[])
setdefault!(config, "allocation_lifetime", 28)
setdefault!(config, "gas", 100)
setdefault!(config, "min_signal", 1000)
setdefault!(config, "max_allocations", 10)
setdefault!(config, "verbose", false)
return config
end
247 changes: 247 additions & 0 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.8.1"
manifest_format = "2.0"
project_hash = "58b323ba7d88e4a3b72f98d6c2c0494ae28bcbe1"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[deps.Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "78bee250c6826e1cf805a88b7f1e86025275d208"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.46.0"

[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "0.5.2+0"

[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[deps.DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"

[[deps.ExprTools]]
git-tree-sha1 = "56559bbef6ca5ea0c0818fa5c90320398a6fbf8d"
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
version = "0.1.8"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[deps.GraphQLClient]]
deps = ["GraphQLParser", "HTTP", "JSON3", "StructTypes"]
git-tree-sha1 = "3a25c0c4c5a83fac16cbf54638edf6addfef5678"
uuid = "09d831e3-9c21-47a9-bfd8-076871817219"
version = "0.7.5"

[[deps.GraphQLParser]]
deps = ["Parsers"]
git-tree-sha1 = "a1504d77493399c34b9debdc188040001d7a51df"
uuid = "0ae10fbf-af58-4883-b66b-ff0ac82d20dd"
version = "0.1.2"

[[deps.HTTP]]
deps = ["Base64", "Dates", "IniFile", "Logging", "MbedTLS", "NetworkOptions", "Sockets", "URIs"]
git-tree-sha1 = "0fa77022fe4b511826b39c894c90daf5fce3334a"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "0.9.17"

[[deps.IniFile]]
git-tree-sha1 = "f550e6e32074c939295eb5ea6de31849ac2c9625"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.1"

[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[deps.JSON3]]
deps = ["Dates", "Mmap", "Parsers", "StructTypes", "UUIDs"]
git-tree-sha1 = "f1572de22c866dc92aea032bc89c2b137cbddd6a"
uuid = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
version = "1.10.0"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.3"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "7.84.0+0"

[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
version = "1.10.2+0"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[deps.LinearAlgebra]]
deps = ["Libdl", "libblastrampoline_jll"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[deps.Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[deps.MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "Random", "Sockets"]
git-tree-sha1 = "ae6676d5f576ccd21b6789c2cbe2ba24fcc8075d"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.1.5"

[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.0+0"

[[deps.Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[deps.Mocking]]
deps = ["Compat", "ExprTools"]
git-tree-sha1 = "29714d0a7a8083bba8427a4fbfb00a540c681ce7"
uuid = "78c3b35d-d492-501b-9361-3d52fe80e533"
version = "0.7.3"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2022.2.1"

[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"

[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.20+0"

[[deps.Parsers]]
deps = ["Dates"]
git-tree-sha1 = "3d5bf43e3e8b412656404ed9466f1dcbf7c50269"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "2.4.0"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.8.0"

[[deps.Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[deps.Random]]
deps = ["SHA", "Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[deps.SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[deps.Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[deps.SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[deps.Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[deps.StructTypes]]
deps = ["Dates", "UUIDs"]
git-tree-sha1 = "ca4bccb03acf9faaf4137a9abc1881ed1841aa70"
uuid = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
version = "1.10.0"

[[deps.TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.0"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.0"

[[deps.Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[deps.URIs]]
git-tree-sha1 = "e59ecc5a41b000fa94423a578d29290c7266fc10"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.4.0"

[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[deps.Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.12+3"

[[deps.libblastrampoline_jll]]
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
version = "5.1.1+0"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.48.0+0"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
version = "17.4.0+0"
4 changes: 4 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
GraphQLClient = "09d831e3-9c21-47a9-bfd8-076871817219"
Mocking = "78c3b35d-d492-501b-9361-3d52fe80e533"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
27 changes: 27 additions & 0 deletions test/configuration.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022-, The Graph Foundation
# SPDX-License-Identifier: MIT

@testset "configuration" begin
@testset "configuredefaults!" begin
config = Dict()
config = AllocationOpt.configuredefaults!(config)
@test isnothing(config["readdir"])
@test config["writedir"] == "."
@test config["network_subgraph_endpoint"] ==
"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-mainnet"
@test config["whitelist"] == String[]
@test config["blacklist"] == String[]
@test config["frozenlist"] == String[]
@test config["pinnedlist"] == String[]
@test config["allocation_lifetime"] == 28
@test config["gas"] == 100
@test config["min_signal"] == 1000
@test config["max_allocations"] == 10
@test !config["verbose"]

config = Dict{String,Any}("gas" => 0)
config = AllocationOpt.configuredefaults!(config)
@test config["gas"] == 0
@test !config["verbose"]
end
end
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2022-, The Graph Foundation
# SPDX-License-Identifier: MIT

using AllocationOpt
using Test

for f in readlines(joinpath(@__DIR__, "testgroups"))
include(f * ".jl")
end
1 change: 1 addition & 0 deletions test/testgroups
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
configuration

0 comments on commit 4f39de3

Please sign in to comment.