Skip to content

Commit

Permalink
fix: linear indexing reward for network token issuance
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Aug 24, 2023
1 parent cc3d75a commit 85d5ac7
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 75 deletions.
2 changes: 1 addition & 1 deletion src/AllocationOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 8 additions & 12 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -95,8 +95,7 @@ function nquery()
a = Dict("id" => 1)
f = [
"id",
"totalSupply",
"networkGRTIssuance",
"networkGRTIssuancePerBlock",
"epochLength",
"totalTokensSignalled",
"currentEpoch",
Expand Down Expand Up @@ -336,24 +335,22 @@ julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => "1",
"networkGRTIssuance" => "1",
"networkGRTIssuancePerBlock" => "1",
"epochLength" => 28,
"totalTokensSignalled" => "2",
"currentEpoch" => 1,
)
])
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

Expand Down Expand Up @@ -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,
Expand Down
45 changes: 8 additions & 37 deletions src/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -467,16 +440,15 @@ 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
julia> using TheGraphData
julia> n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 2,
"networkGRTIssuancePerBlock" => 2,
"epochLength" => 1,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
Expand All @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/opt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 5 additions & 10 deletions test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
@test v == "graphNetwork"
@test f == [
"id",
"totalSupply",
"networkGRTIssuance",
"networkGRTIssuancePerBlock",
"epochLength",
"totalTokensSignalled",
"currentEpoch",
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -153,9 +150,8 @@
Dict(
"totalTokensSignalled" => "100",
"currentEpoch" => 1,
"totalSupply" => "100",
"id" => "1",
"networkGRTIssuance" => "100",
"networkGRTIssuancePerBlock" => "100",
"epochLength" => 1,
),
])
Expand All @@ -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
Expand Down
16 changes: 5 additions & 11 deletions test/domain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -201,8 +199,7 @@
n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"networkGRTIssuancePerBlock" => 1,
"epochLength" => 1,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
Expand All @@ -214,8 +211,7 @@
n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 1,
"networkGRTIssuancePerBlock" => 1,
"epochLength" => 0,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
Expand All @@ -227,8 +223,7 @@
n = flextable([
Dict(
"id" => 1,
"totalSupply" => 0,
"networkGRTIssuance" => 1,
"networkGRTIssuancePerBlock" => 0,
"epochLength" => 1,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
Expand All @@ -240,8 +235,7 @@
n = flextable([
Dict(
"id" => 1,
"totalSupply" => 1,
"networkGRTIssuance" => 2,
"networkGRTIssuancePerBlock" => 1,
"epochLength" => 1,
"totalTokensSignalled" => 2,
"currentEpoch" => 1,
Expand Down
3 changes: 1 addition & 2 deletions test/patch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
]
Expand Down

0 comments on commit 85d5ac7

Please sign in to comment.