Skip to content

Commit

Permalink
fix: stake amount include lockedTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
hopey1118@gmail.com committed Aug 9, 2022
1 parent b89ea03 commit a74db38
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ We recommend making queries to the network subgraph served by your own indexer s
Alternatively, you can supply an API url to `indexer_service_network_url` from the decentralized gateway or hosted service.
To provide the network subgraph to the optimiser, set the indexer-service flag `--serve-network-subgraph` to `true`.

Populate your preferred lists (whitelist, blacklist, pinnedlist, frozenlist) into a CSV and remember its file path
Populate your preferred lists (whitelist, blacklist, pinnedlist, frozenlist) into a CSV and take note of its file path. If you choose to supply specific deployment preferences through this list, please read list definitions in detail and keep the file updated to your expectations as it changes the problem statement for the optimiser.

!!! note
You can access the help for the optimiser by running the script with the `--help` flag.
Expand Down
3 changes: 2 additions & 1 deletion scripts/allocationopt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Optimise an indexer's allocations and generates indexer rules to change allocati
pinnedlist = cols[3]

# Pull network state from indexer service network endpoint
println("Reading network state.") repo, indexer, network = network_state(id, parse(Int, network_id), cols..., indexer_service_network_url)
println("Reading network state.")
repo, indexer, network = network_state(id, parse(Int, network_id), cols..., indexer_service_network_url)

# Pull full network state from indexer service network endpoint
fullrepo, _, _ = network_state(id, parse(Int, network_id), String[], String[], String[], String[], indexer_service_network_url)
Expand Down
2 changes: 1 addition & 1 deletion src/AllocationOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function optimize_indexer(
throw(ArgumentError("τ must be between 0 and 1."))
end
if maximum_new_allocations > length(repo.subgraphs)
@warn "Maximum new allocations is more than the number of available subgraph deployments; setting it to the number of subgraphs"
@warn "Maximum new allocations is more than the number of available subgraph deployments; setting it to the number of subgraphs: $(length(repo.subgraphs))"
maximum_new_allocations = length(repo.subgraphs)
end

Expand Down
10 changes: 8 additions & 2 deletions src/domainmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ struct Indexer <: GraphEntity
stake::Real
allocations::AbstractVector{Allocation}

function Indexer(id, delegation::AbstractString, stake::AbstractString, allocation)
function Indexer(
id,
delegation::AbstractString,
stake::AbstractString,
locked_tokens::AbstractString,
allocation,
)
return new(
id,
togrt(stake) + togrt(delegation),
togrt(stake) + togrt(delegation) - togrt(locked_tokens),
map(
x -> Allocation(
x["subgraphDeployment"]["ipfsHash"],
Expand Down
9 changes: 8 additions & 1 deletion src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ function query_indexers(client::Client, subgraphs::AbstractVector{SubgraphDeploy
"id",
"delegatedTokens",
"stakedTokens",
"lockedTokens",
"allocations($allocations_query){allocatedTokens,createdAtEpoch,subgraphDeployment{ipfsHash}}",
],
)
indexers_data = query(client, "indexers"; query_args=indexer_query.args, output_fields=indexer_query.fields).data["indexers"]
indexers = map(
x -> Indexer(x["id"], x["delegatedTokens"], x["stakedTokens"], x["allocations"]),
x -> Indexer(
x["id"],
x["delegatedTokens"],
x["stakedTokens"],
x["lockedTokens"],
x["allocations"],
),
indexers_data,
)
return indexers
Expand Down
2 changes: 1 addition & 1 deletion src/service.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end
function optimize(
Ω::AbstractVector{T},
ψ::AbstractVector{T},
σ::Real,
σ::T,
max_allocations::Int,
filter_fn::Function,
) where {T<:Real}
Expand Down
5 changes: 2 additions & 3 deletions test/example.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
whitelist,blacklist,pinnedlist,frozenlist
QmXvEzRJXby7KFuTr7NJsM47hGefM5VckEXZrQyZzL9eJd,,,
QmWxteQps5mtjAx14XD1uycg6kJkFN8EPW7561iZE3dJz8,,,

QmXvEzRJXby7KFuTr7NJsM47hGefM5VckEXZrQyZzL9eJd,,,
QmWxteQps5mtjAx14XD1uycg6kJkFN8EPW7561iZE3dJz8,,,
10 changes: 7 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ using GraphQLClient

# Indexer stake should be equal to the sum of allocations
# query indexer's stake
indexer = query(client, "indexers"; query_args=Dict("where" => Dict("id" => id)), output_fields=["delegatedTokens", "stakedTokens"]).data["indexers"][1]
stake = togrt(indexer["delegatedTokens"]) + togrt(indexer["stakedTokens"])
indexer = query(client, "indexers"; query_args=Dict("where" => Dict("id" => id)), output_fields=["delegatedTokens", "stakedTokens", "lockedTokens"]).data["indexers"][1]
stake =
togrt(indexer["delegatedTokens"]) + togrt(indexer["stakedTokens"]) -
togrt(indexer["lockedTokens"])

# run optimize_indexer
repo, optindexer, network = network_state(
id, network_id, String[ipfshash], String[], String[], String[], gateway_url
)
# Check stake
@test isapprox(stake, optindexer.stake; atol=1e-6)
allocs = optimize_indexer(optindexer, repo, repo, 2, τ, filter_fn, String[])
# Sum allocation amounts
ω = sum(values(allocs))
Expand Down Expand Up @@ -94,7 +98,7 @@ using GraphQLClient
ω = sum(values(pinned_allocs))
@test isapprox(ω, stake; atol=1e-6)

# run optimize_indexer with pinnedlist when allocation is optimal
# run optimize_indexer with pinnedlist when pinned subgraph is optimal
pinnedlist = String[ipfshash]
repo, optindexer, network = network_state(
id,
Expand Down
3 changes: 0 additions & 3 deletions test/semiotic.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
whitelist,blacklist,pinnedlist,frozenlist
QmVqMeQUwvQ3XjzCYiMhRvQjRiQLGpVt8C3oHgvDi3agJ2,,,
QmbvTyvmxqHLahZwS7fZtVWGM85VCpCiKHiagPxQJp5ktS,,,
QmXYZnggrnRpQe5ZGK2VzdhNyTgFqAP4AziQgxEZFk7fJm,,,

0 comments on commit a74db38

Please sign in to comment.