Skip to content

Commit

Permalink
feat: Network accessors
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 14, 2023
1 parent e416bfe commit ca38e6a
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
111 changes: 111 additions & 0 deletions src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,117 @@ julia> AllocationOpt.togrt("1")
"""
togrt(x::AbstractString) = parse(Float64, x) / ethtogrt


"""
totalsupply(::Val{:network}, x)
The total GRT supply.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"epochLength" => 28,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
)
])
julia> AllocationOpt.totalsupply(Val(:network), n)
"""
totalsupply(::Val{:network}, x) = x.totalSupply |> only

"""
blockissuance(::Val{:network}, x)
The tokens issued per block.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"epochLength" => 28,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
)
])
julia> AllocationOpt.blockissuance(Val(:network), n)
"""
blockissuance(::Val{:network}, x) = x.networkGRTIssuance |> only

"""
blocksperepoch(::Val{:network}, x)
The number of blocks in each epoch.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"epochLength" => 28,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
)
])
julia> AllocationOpt.blocksperepoch(Val(:network), n)
"""
blocksperepoch(::Val{:network}, x) = x.epochLength |> only

"""
totalsignal(::Val{:network}, x)
The total signal in the network
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"epochLength" => 28,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
)
])
julia> AllocationOpt.totalsignal(Val(:network), n)
"""
totalsignal(::Val{:network}, x) = x.totalTokensSignalled |> only

"""
currentepoch(::Val{:network}, x)
The current epoch.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"epochLength" => 28,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
)
])
julia> AllocationOpt.currentepoch.(Val(:network), n)
"""
currentepoch(::Val{:network}, x) = x.currentEpoch |> only

"""
ipfshash(::Val{:allocation}, x)
Expand Down
18 changes: 18 additions & 0 deletions test/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@

@testset "accessors" begin

@testset "network" begin
n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"epochLength" => 28,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
)
])
@test AllocationOpt.totalsupply(Val(:network), n) == 1
@test AllocationOpt.blockissuance(Val(:network), n) == 1
@test AllocationOpt.blocksperepoch(Val(:network), n) == 28
@test AllocationOpt.totalsignal(Val(:network), n) == 2
@test AllocationOpt.currentepoch(Val(:network), n) == 1
end

@testset "allocation" begin
x = flextable([
Dict("allocatedTokens" => 1, "subgraphDeployment.ipfsHash" => "Qma")
Expand Down

0 comments on commit ca38e6a

Please sign in to comment.