From 85d5ac7c50e66b98192c69e5e5e2a195cdc6a7af Mon Sep 17 00:00:00 2001 From: hopeyen Date: Thu, 24 Aug 2023 12:36:48 -0500 Subject: [PATCH] fix: linear indexing reward for network token issuance --- src/AllocationOpt.jl | 2 +- src/data.jl | 20 ++++++++------------ src/domain.jl | 45 ++++++++------------------------------------ src/opt.jl | 2 -- test/data.jl | 15 +++++---------- test/domain.jl | 16 +++++----------- test/patch.jl | 3 +-- 7 files changed, 28 insertions(+), 75 deletions(-) diff --git a/src/AllocationOpt.jl b/src/AllocationOpt.jl index 7abf4f9..8fbb389 100644 --- a/src/AllocationOpt.jl +++ b/src/AllocationOpt.jl @@ -88,7 +88,7 @@ function main(config::Dict) # Ensure that the indexer stake is not exceeded σmax = σ + σpinned for x in sum(xs; dims=1) - x ≤ σmax || error("Tried to allocate more stake than is available") + x ≤ σmax || error("Tried to allocate more stake than is available by $(x - σmax)") end # Write the result values diff --git a/src/data.jl b/src/data.jl index e6ebdd8..390682d 100644 --- a/src/data.jl +++ b/src/data.jl @@ -84,7 +84,7 @@ For use with the TheGraphData.jl package. ```julia julia> using AllocationOpt julia> value, args, fields = AllocationOpt.nquery() -("graphNetwork", Dict("id" => 1), ["id", "totalSupply", "networkGRTIssuance", "epochLength", "totalTokensSignalled", "currentEpoch"]) +("graphNetwork", Dict("id" => 1), ["id", "networkGRTIssuance", "epochLength", "totalTokensSignalled", "currentEpoch"]) ``` # Extended Help @@ -95,8 +95,7 @@ function nquery() a = Dict("id" => 1) f = [ "id", - "totalSupply", - "networkGRTIssuance", + "networkGRTIssuancePerBlock", "epochLength", "totalTokensSignalled", "currentEpoch", @@ -336,8 +335,7 @@ julia> using TheGraphData julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => "1", - "networkGRTIssuance" => "1", + "networkGRTIssuancePerBlock" => "1", "epochLength" => 28, "totalTokensSignalled" => "2", "currentEpoch" => 1, @@ -345,15 +343,14 @@ julia> n = flextable([ ]) julia> AllocationOpt.correcttypes!(Val(:network), n) FlexTable with 6 columns and 1 row: - totalTokensSignalled currentEpoch totalSupply id networkGRTIssuance epochLength - ┌───────────────────────────────────────────────────────────────────────────────────── - 1 │ 2.0e-18 1 1.0e-18 1 1.0e-18 28 + totalTokensSignalled currentEpoch id networkGRTIssuancePerBlock epochLength +┌──────────────────────────────────────────────────────────────────────────────── +1 │ 2.0e-18 1 1 1.0e-18 28 ``` """ function correcttypes!(::Val{:network}, n::FlexTable) - n.totalSupply = n.totalSupply .|> togrt n.totalTokensSignalled = n.totalTokensSignalled .|> togrt - n.networkGRTIssuance = n.networkGRTIssuance .|> togrt + n.networkGRTIssuancePerBlock = n.networkGRTIssuancePerBlock .|> togrt return n end @@ -389,8 +386,7 @@ julia> a = flextable([ julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => "1", - "networkGRTIssuance" => "1", + "networkGRTIssuancePerBlock" => "1", "epochLength" => 28, "totalTokensSignalled" => "2", "currentEpoch" => 1, diff --git a/src/domain.jl b/src/domain.jl index ed878db..7b923c8 100644 --- a/src/domain.jl +++ b/src/domain.jl @@ -20,29 +20,6 @@ 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) -1 -""" -totalsupply(::Val{:network}, x) = x.totalSupply |> only - """ blockissuance(::Val{:network}, x) @@ -54,8 +31,7 @@ julia> using TheGraphData julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 28, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -64,7 +40,7 @@ julia> n = flextable([ julia> AllocationOpt.blockissuance(Val(:network), n) 1 """ -blockissuance(::Val{:network}, x) = x.networkGRTIssuance |> only +blockissuance(::Val{:network}, x) = x.networkGRTIssuancePerBlock |> only """ blocksperepoch(::Val{:network}, x) @@ -77,8 +53,7 @@ julia> using TheGraphData julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 28, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -100,8 +75,7 @@ julia> using TheGraphData julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 28, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -123,8 +97,7 @@ julia> using TheGraphData julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 28, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -467,7 +440,7 @@ end """ newtokenissuance(n::FlexTable, config::Dict) -How many new tokens are issued over the allocation lifetime given network parameters `n`. +How many new tokens are issued over the allocation lifetime given network parameters `n`. Calcualted by networkGRTIssuancePerBlock * epochLength * allocation_lifetime ```julia julia> using AllocationOpt @@ -475,8 +448,7 @@ julia> using TheGraphData julia> n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 2, + "networkGRTIssuancePerBlock" => 2, "epochLength" => 1, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -488,11 +460,10 @@ julia> AllocationOpt.newtokenissuance(n, config) ``` """ function newtokenissuance(n::FlexTable, config::Dict) - p = totalsupply(Val(:network), n) r = blockissuance(Val(:network), n) t = blocksperepoch(Val(:network), n) * config["allocation_lifetime"] - newtokens = p * (r^t - 1.0) + newtokens = r * t return newtokens end diff --git a/src/opt.jl b/src/opt.jl index 7095852..cd2ca9e 100644 --- a/src/opt.jl +++ b/src/opt.jl @@ -288,8 +288,6 @@ julia> xs, nonzeros, profits = AllocationOpt.optimize( ``` """ function optimize(val::Val{:optimal}, Ω, ψ, σ, K, Φ, Ψ, g, rixs) - @warn "This uses the pairwise greedy algorithm, which is currently experimental." - # Helper function to compute profit f = x -> profit.(indexingreward.(x, Ω, ψ, Φ, Ψ), g) diff --git a/test/data.jl b/test/data.jl index d1c8e5b..99ea953 100644 --- a/test/data.jl +++ b/test/data.jl @@ -32,8 +32,7 @@ @test v == "graphNetwork" @test f == [ "id", - "totalSupply", - "networkGRTIssuance", + "networkGRTIssuancePerBlock", "epochLength", "totalTokensSignalled", "currentEpoch", @@ -108,18 +107,16 @@ Dict( "totalTokensSignalled" => "100", "currentEpoch" => 1, - "totalSupply" => "100", "id" => "1", - "networkGRTIssuance" => "100", + "networkGRTIssuancePerBlock" => "100", "epochLength" => 1, ), ]) AllocationOpt.correcttypes!(Val(:network), n) @test n.totalTokensSignalled == [1e-16] @test n.currentEpoch == [1] - @test n.totalSupply == [1e-16] @test n.id == ["1"] - @test n.networkGRTIssuance == [1e-16] + @test n.networkGRTIssuancePerBlock == [1e-16] @test n.epochLength == [1] end @@ -153,9 +150,8 @@ Dict( "totalTokensSignalled" => "100", "currentEpoch" => 1, - "totalSupply" => "100", "id" => "1", - "networkGRTIssuance" => "100", + "networkGRTIssuancePerBlock" => "100", "epochLength" => 1, ), ]) @@ -172,9 +168,8 @@ ["Qma", "Qmb", "Qmc"] @test n.totalTokensSignalled == [1e-16] @test n.currentEpoch == [1] - @test n.totalSupply == [1e-16] @test n.id == ["1"] - @test n.networkGRTIssuance == [1e-16] + @test n.networkGRTIssuancePerBlock == [1e-16] @test n.epochLength == [1] end end diff --git a/test/domain.jl b/test/domain.jl index 7b2dfc0..ca73940 100644 --- a/test/domain.jl +++ b/test/domain.jl @@ -11,14 +11,12 @@ n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 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.signal(Val(:network), n) == 2 @@ -201,8 +199,7 @@ n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 1, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -214,8 +211,7 @@ n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 0, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -227,8 +223,7 @@ n = flextable([ Dict( "id" => 1, - "totalSupply" => 0, - "networkGRTIssuance" => 1, + "networkGRTIssuancePerBlock" => 0, "epochLength" => 1, "totalTokensSignalled" => 2, "currentEpoch" => 1, @@ -240,8 +235,7 @@ n = flextable([ Dict( "id" => 1, - "totalSupply" => 1, - "networkGRTIssuance" => 2, + "networkGRTIssuancePerBlock" => 1, "epochLength" => 1, "totalTokensSignalled" => 2, "currentEpoch" => 1, diff --git a/test/patch.jl b/test/patch.jl index 5f5752b..44d49fb 100644 --- a/test/patch.jl +++ b/test/patch.jl @@ -41,9 +41,8 @@ query_success_patch = @patch function query(v, a, f) Dict( "totalTokensSignalled" => "100", "currentEpoch" => 1, - "totalSupply" => "100", "id" => "1", - "networkGRTIssuance" => "100", + "networkGRTIssuancePerBlock" => "100", "epochLength" => 1, ), ]