Skip to content

Commit

Permalink
feat: Compute frozen stake
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 13, 2023
1 parent 0914ceb commit 01ed4a2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/AllocationOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,40 @@ using TOML
using TypedTables
using TheGraphData

import SplitApplyCombine as SAC

include("configuration.jl")
include("data.jl")
include("domain.jl")

function julia_main()::Cint
try
main(ARGS)
catch
Base.invokelatest(Base.display_error, Base.catch_stack())
return 1
end
return 0 # if things finished successfully
end

main(args::Vector{String}) = main(first(args))

function main(path::AbstractString)
# Read config and set defaults
config = path |> readconfig |> configuredefaults!
return main(config)
end

function main(config::Dict)
# Read data
i, a, s, n = AllocationOpt.read(config)

# Queried data has not yet been converted to GRT, so
# if this isn't data that we've queried, correct the
# types and write the data out to CSVs
isnothing(config["readdir"]) && write(i, a, s, n, config)

return nothing
end

end
21 changes: 21 additions & 0 deletions src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,24 @@ julia> AllocationOpt.locked(Val(:indexer), x)
```
"""
locked(::Val{:indexer}, x) = x.lockedTokens |> only

"""
frozen(a::FlexTable, config::AbstractDict)
The frozen stake of the indexer with allocations `a`.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "allocatedTokens" => 5),
Dict("subgraphDeployment.ipfsHash" => "Qmb", "allocatedTokens" => 10),
])
julia> config = Dict("frozenlist" => ["Qma", "Qmb"])
julia> AllocationOpt.frozen(a, config)
```
"""
function frozen(a::FlexTable, config::AbstractDict)
frozenallocs = SAC.filterview(r -> ipfshash(Val(:allocation), r) config["frozenlist"], a)
return stake(Val(:allocation), frozenallocs) |> sum
end
11 changes: 11 additions & 0 deletions test/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@

end

@testset "frozen" begin
a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "allocatedTokens" => 5),
Dict("subgraphDeployment.ipfsHash" => "Qmb", "allocatedTokens" => 10),
])
config = Dict("frozenlist" => ["Qma", "Qmb"])
@test AllocationOpt.frozen(a, config) == 15
config = Dict("frozenlist" => ["Qmb"])
@test AllocationOpt.frozen(a, config) == 10
end

end

0 comments on commit 01ed4a2

Please sign in to comment.