Skip to content

Commit

Permalink
feat: execute mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Mar 20, 2023
1 parent 53378d5 commit 7b8342d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/AllocationOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function main(config::Dict)
g = config["gas"]

# Get optimal values
# TODO: Handle pinned stake
xs, nonzeros, profitmatrix = optimize(Ω, ψ, σ, K, Φ, Ψ, g)

# Write the result values
Expand All @@ -88,13 +89,17 @@ function main(config::Dict)
nreport = min(config["num_reported_options"], length(popts))

# Create JSON string
strategies = strategydict.(popts, Ref(xs), Ref(nonzeros), Ref(fs), Ref(profitmatrix))
strategies = strategydict.(
popts[1:nreport], Ref(xs), Ref(nonzeros), Ref(fs), Ref(profitmatrix)
)
reportdata = JSON.json(Dict("strategies" => strategies))

# Write JSON string to file
writejson(reportdata, config)

# Use config to see if actionqueue or rules with the top profit batch
# Use config for using actionqueue or rules with the top profit batch
ix = first(popts)[:index]
execute(a, ix, fs, xs, ps, config)

return nothing
end
Expand Down
57 changes: 56 additions & 1 deletion src/reporting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ function reallocate(
t::FlexTable,
config::AbstractDict,
)
ti = SAC.innerjoin(getproperty(:ipfshash), getproperty(Symbol("subgraphDeployment.ipfsHash")), t, a)
ti = SAC.innerjoin(
getproperty(:ipfshash), getproperty(Symbol("subgraphDeployment.ipfsHash")), t, a
)

actions::Vector{Dict{String, Any}} = map(
r -> Dict(
Expand Down Expand Up @@ -500,3 +502,56 @@ function allocate(

return actions
end

"""
execute(
a::FlexTable,
ix::Integer,
s::FlexTable,
xs::AbstractMatrix{T},
ps::AbstractMatrix{T},
config::AbstractDict
) where {T<:Real}
Execute the actions picked by the optimiser.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
julia> xs = [[2.5 5.0]; [2.5 0.0]]
julia> ps = [[3.0 5.0]; [3.0 0.0]]
julia> s = flextable([
Dict("stakedTokens" => "1", "signalledTokens" => "0", "ipfsHash" => "Qma"),
Dict("stakedTokens" => "2", "signalledTokens" => "0", "ipfsHash" => "Qmb"),
])
julia> config = Dict("execution_mode" => "none")
julia> ix = 1
julia> AllocationOpt.execute(a, ix, s, xs, ps, config)
```
"""
function execute(
a::FlexTable,
ix::Integer,
s::FlexTable,
xs::AbstractMatrix{T},
ps::AbstractMatrix{T},
config::AbstractDict
) where {T<:Real}
# Construct t
t = reportingtable(s, xs, ps, ix)

mode = Val(Symbol(config["execution_mode"]))

indexerurlclient(mode, config)
_ = unallocate(mode, a, t, config)
_ = reallocate(mode, a, t, config)
_ = allocate(mode, a, t, config)

return nothing
end

indexerurlclient(::Val{:actionqueue}, config::AbstractDict) = client!(config["indexer_url"])
indexerurlclient(::Any, config::AbstractDict) = nothing

0 comments on commit 7b8342d

Please sign in to comment.