diff --git a/Manifest.toml b/Manifest.toml index 91eedc2..8312601 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -606,7 +606,7 @@ uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[deps.TheGraphData]] deps = ["CSV", "GraphQLClient", "Mocking", "TensorCast", "TypedTables"] -git-tree-sha1 = "a8e55dcab58a88fdd27c315e3f09ba48891a908e" +git-tree-sha1 = "65b0fe4819e206fcabc133a8eb3a039d7eefb144" repo-rev = "main" repo-url = "https://github.com/semiotic-ai/TheGraphData.jl.git" uuid = "871720c8-5dfb-4fa2-998e-3fe6ebd08819" diff --git a/config.toml b/config.toml index fc746cf..528cc41 100644 --- a/config.toml +++ b/config.toml @@ -10,3 +10,6 @@ gas = 100 min_signal = 1000 verbose = true num_reported_options = 2 +execution_mode = "none" +indexer_url = "http://localhost:18000" +network_subgraph_endpoint = "https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-goerli" diff --git a/src/AllocationOpt.jl b/src/AllocationOpt.jl index bc1a13c..c3f39dd 100644 --- a/src/AllocationOpt.jl +++ b/src/AllocationOpt.jl @@ -99,7 +99,7 @@ function main(config::Dict) # Use config for using actionqueue or rules with the top profit batch ix = first(popts)[:index] - execute(a, ix, fs, xs, ps, config) + execute(a, ix, fs, xs, profitmatrix, config) return nothing end diff --git a/src/reporting.jl b/src/reporting.jl index 30e1b52..b877e23 100644 --- a/src/reporting.jl +++ b/src/reporting.jl @@ -171,7 +171,7 @@ function writejson(results::AbstractString, config::AbstractDict) end """ - unallocate(::Val{:none}, a, t, config) + unallocate_action(::Val{:none}, a, t, config) Do nothing. @@ -184,14 +184,14 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.unallocate(Val{:none}, a, t, Dict()) +julia> AllocationOpt.unallocate_action(Val{:none}, a, t, Dict()) ``` """ -unallocate(::Val{:none}, a, t, config) = nothing +unallocate_action(::Val{:none}, a, t, config) = nothing """ - reallocate(::Val{:none}, a, t, config) + reallocate_action(::Val{:none}, a, t, config) Do nothing. @@ -205,12 +205,12 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.reallocate(Val{:none}, a, t, Dict()) +julia> AllocationOpt.reallocate_action(Val{:none}, a, t, Dict()) """ -reallocate(::Val{:none}, a, t, config) = nothing +reallocate_action(::Val{:none}, a, t, config) = nothing """ - allocate(::Val{:none}, a, t, config) + allocate_action(::Val{:none}, a, t, config) Do nothing. @@ -224,13 +224,13 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.allocate(Val{:none}, a, t, Dict()) +julia> AllocationOpt.allocate_action(Val{:none}, a, t, Dict()) ``` """ -allocate(::Val{:none}, a, t, config) = nothing +allocate_action(::Val{:none}, a, t, config) = nothing """ - unallocate(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) + unallocate_action(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) Print a rule that stops old allocations that the optimiser has not chosen and that aren't frozen. @@ -243,10 +243,10 @@ julia > a = flextable([ julia> t = flextable([ Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.unallocate(Val{:rules}, a, t, Dict("frozenlist" => [])) +julia> AllocationOpt.unallocate_action(Val{:rules}, a, t, Dict("frozenlist" => [])) ``` """ -function unallocate(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) +function unallocate_action(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) frozenlist = config["frozenlist"] existingipfs = ipfshash(Val(:allocation), a) proposedipfs = t.ipfshash @@ -257,7 +257,7 @@ function unallocate(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractD end """ - reallocate(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) + reallocate_action(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) Print a rule that reallocates the old allocation with a new allocation amount @@ -271,10 +271,10 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.reallocate(Val(:rules), a, t, Dict()) +julia> AllocationOpt.reallocate_action(Val(:rules), a, t, Dict()) ``` """ -function reallocate( +function reallocate_action( ::Val{:rules}, a::FlexTable, t::FlexTable, @@ -292,12 +292,12 @@ function reallocate( ipfses, amounts ) - println(actions) + println.(actions) return actions end """ - allocate(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) + allocate_action(::Val{:rules}, a::FlexTable, t::FlexTable, config::AbstractDict) Print the rules that allocates to new subgraphs. @@ -311,9 +311,9 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.allocate(Val{:rules}, a, t, Dict()) +julia> AllocationOpt.allocate_action(Val{:rules}, a, t, Dict()) """ -function allocate( +function allocate_action( ::Val{:rules}, a::FlexTable, t::FlexTable, @@ -331,7 +331,7 @@ function allocate( ipfses, amounts ) - println(actions) + println.(actions) return actions end @@ -360,14 +360,14 @@ end end @enum ActionType begin - allocateaction - unallocateaction - reallocateaction - collectaction + allocate + unallocate + reallocate + collect end """ - unallocate(::Val{:actionqueue}, a::FlexTable, t::FlexTable, config::AbstractDict) + unallocate_action(::Val{:actionqueue}, a::FlexTable, t::FlexTable, config::AbstractDict) Create and push the unallocate actions to the action queue. @@ -379,9 +379,9 @@ julia > a = flextable([ julia> t = flextable([ Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.unallocate(Val{:rules}, a, t, Dict("frozenlist" => [])) +julia> AllocationOpt.unallocate_action(Val{:rules}, a, t, Dict("frozenlist" => [])) """ -function unallocate( +function unallocate_action( ::Val{:actionqueue}, a::FlexTable, t::FlexTable, @@ -393,23 +393,24 @@ function unallocate( actions::Vector{Dict{String, Any}} = map( r -> Dict( "status" => queued, - "type" => unallocateaction, - "allocation" => id(Val(:allocation), r), - "ipfshash" => ipfshash(Val(:allocation), r), - "user" => "AllocationOpt", + "type" => unallocate, + "allocationID" => id(Val(:allocation), r), + "deploymentID" => ipfshash(Val(:allocation), r), + "source" => "AllocationOpt", "reason" => "AllocationOpt", "priority" => 0, ), ft ) + # Send graphql mutation to action queue - _ = @mock(mutate("queueActions", Dict("actions" => actions))) + @mock(mutate("queueActions", Dict("actions" => actions); direct_write=true)) return actions end """ - reallocate(::Val{:actionqueue}, a::FlexTable, t::FlexTable, config::AbstractDict) + reallocate_action(::Val{:actionqueue}, a::FlexTable, t::FlexTable, config::AbstractDict) Create and push reallocate actions to the action queue. @@ -423,10 +424,10 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.reallocate(Val(:actionqueue), a, t, Dict()) +julia> AllocationOpt.reallocate_action(Val(:actionqueue), a, t, Dict()) ``` """ -function reallocate( +function reallocate_action( ::Val{:actionqueue}, a::FlexTable, t::FlexTable, @@ -439,11 +440,11 @@ function reallocate( actions::Vector{Dict{String, Any}} = map( r -> Dict( "status" => queued, - "type" => reallocateaction, - "allocation" => id(Val(:allocation), r), - "ipfshash" => ipfshash(Val(:allocation), r), + "type" => reallocate, + "allocationID" => id(Val(:allocation), r), + "deploymentID" => ipfshash(Val(:allocation), r), "amount" => format(r.amount), - "user" => "AllocationOpt", + "source" => "AllocationOpt", "reason" => "Expected profit: $(format(r.profit))", "priority" => 0, ), @@ -451,13 +452,13 @@ function reallocate( ) # Send graphql mutation to action queue - _ = @mock(mutate("queueActions", Dict("actions" => actions))) + @mock(mutate("queueActions", Dict("actions" => actions); direct_write=true)) return actions end """ - allocate(::Val{:actionqueue}, a::FlexTable, t::FlexTable, config::AbstractDict) + allocate_action(::Val{:actionqueue}, a::FlexTable, t::FlexTable, config::AbstractDict) Create and push allocate actions to the action queue. @@ -471,10 +472,10 @@ julia> t = flextable([ Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"), Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"), ]) -julia> AllocationOpt.allocate(Val(:actionqueue), a, t, Dict()) +julia> AllocationOpt.allocate_action(Val(:actionqueue), a, t, Dict()) ``` """ -function allocate( +function allocate_action( ::Val{:actionqueue}, a::FlexTable, t::FlexTable, @@ -487,10 +488,10 @@ function allocate( actions::Vector{Dict{String, Any}} = map( r -> Dict( "status" => queued, - "type" => allocateaction, - "ipfshash" => r.ipfshash, + "type" => allocate, + "deploymentID" => r.ipfshash, "amount" => format(r.amount), - "user" => "AllocationOpt", + "source" => "AllocationOpt", "reason" => "Expected profit: $(format(r.profit))", "priority" => 0, ), @@ -498,7 +499,7 @@ function allocate( ) # Send graphql mutation to action queue - _ = @mock(mutate("queueActions", Dict("actions" => actions))) + @mock(mutate("queueActions", Dict("actions" => actions); direct_write=true)) return actions end @@ -546,9 +547,9 @@ function execute( mode = Val(Symbol(config["execution_mode"])) indexerurlclient(mode, config) - _ = unallocate(mode, a, t, config) - _ = reallocate(mode, a, t, config) - _ = allocate(mode, a, t, config) + _ = unallocate_action(mode, a, t, config) + _ = reallocate_action(mode, a, t, config) + _ = allocate_action(mode, a, t, config) return nothing end diff --git a/test/patch.jl b/test/patch.jl index eb4115b..9279890 100644 --- a/test/patch.jl +++ b/test/patch.jl @@ -55,7 +55,7 @@ writejson_success_patch = @patch function JSON.print(io, s) return s end -mutate_success_patch = @patch function mutate(v, a) +mutate_success_patch = @patch function mutate(v, a; kwargs...) println("mutate stub ==> simulating queueActions") return [Dict(v => a["actions"])] end diff --git a/test/reporting.jl b/test/reporting.jl index c9fcb2f..de6eaef 100644 --- a/test/reporting.jl +++ b/test/reporting.jl @@ -109,32 +109,32 @@ cfg = Dict("frozenlist" => ["Qma"]) @testset "none" begin - @inferred AllocationOpt.unallocate(Val(:none), a, t, config) + @inferred AllocationOpt.unallocate_action(Val(:none), a, t, config) end @testset "rules" begin - @inferred AllocationOpt.unallocate(Val(:rules), a, t, config) - out = AllocationOpt.unallocate(Val(:rules), a, t, config) + @inferred AllocationOpt.unallocate_action(Val(:rules), a, t, config) + out = AllocationOpt.unallocate_action(Val(:rules), a, t, config) @test out == ["\e[0mgraph indexer rules stop Qma"] - out = AllocationOpt.unallocate(Val(:rules), a, t, cfg) + out = AllocationOpt.unallocate_action(Val(:rules), a, t, cfg) @test isempty(out) end @testset "actionqueue" begin apply(mutate_success_patch) do - @inferred AllocationOpt.unallocate(Val(:actionqueue), a, t, config) + @inferred AllocationOpt.unallocate_action(Val(:actionqueue), a, t, config) end apply(mutate_success_patch) do - out = AllocationOpt.unallocate(Val(:actionqueue), a, t, config) + out = AllocationOpt.unallocate_action(Val(:actionqueue), a, t, config) @test out == [ Dict( "status" => AllocationOpt.queued, - "type" => AllocationOpt.unallocateaction, - "allocation" => "0xa", - "ipfshash" => "Qma", - "user" => "AllocationOpt", + "type" => AllocationOpt.unallocate, + "allocationID" => "0xa", + "deploymentID" => "Qma", + "source" => "AllocationOpt", "reason" => "AllocationOpt", "priority" => 0, ) @@ -142,7 +142,7 @@ end apply(mutate_success_patch) do - out = AllocationOpt.unallocate(Val(:actionqueue), a, t, cfg) + out = AllocationOpt.unallocate_action(Val(:actionqueue), a, t, cfg) @test isempty(out) end end @@ -159,30 +159,30 @@ config = Dict() @testset "none" begin - @inferred AllocationOpt.reallocate(Val(:none), a, t, config) + @inferred AllocationOpt.reallocate_action(Val(:none), a, t, config) end @testset "rules" begin - @inferred AllocationOpt.reallocate(Val(:rules), a, t, config) - out = AllocationOpt.reallocate(Val(:rules), a, t, config) + @inferred AllocationOpt.reallocate_action(Val(:rules), a, t, config) + out = AllocationOpt.reallocate_action(Val(:rules), a, t, config) @test out == ["\e[0mgraph indexer rules stop Qma\n\e[1m\e[38;2;255;0;0;249mCheck allocation status being closed before submitting: \e[0mgraph indexer rules set Qma decisionBasis always allocationAmount 1"] end @testset "actionqueue" begin apply(mutate_success_patch) do - @inferred AllocationOpt.reallocate(Val(:actionqueue), a, t, config) + @inferred AllocationOpt.reallocate_action(Val(:actionqueue), a, t, config) end apply(mutate_success_patch) do - out = AllocationOpt.reallocate(Val(:actionqueue), a, t, config) + out = AllocationOpt.reallocate_action(Val(:actionqueue), a, t, config) @test out == [ Dict( "status" => AllocationOpt.queued, - "type" => AllocationOpt.reallocateaction, - "allocation" => "0xa", - "ipfshash" => "Qma", + "type" => AllocationOpt.reallocate, + "allocationID" => "0xa", + "deploymentID" => "Qma", "amount" => "1", - "user" => "AllocationOpt", + "source" => "AllocationOpt", "reason" => "Expected profit: 0", "priority" => 0, ) @@ -202,29 +202,29 @@ config = Dict() @testset "none" begin - @inferred AllocationOpt.allocate(Val(:none), a, t, config) + @inferred AllocationOpt.allocate_action(Val(:none), a, t, config) end @testset "rules" begin - @inferred AllocationOpt.allocate(Val(:rules), a, t, config) - out = AllocationOpt.allocate(Val(:rules), a, t, config) + @inferred AllocationOpt.allocate_action(Val(:rules), a, t, config) + out = AllocationOpt.allocate_action(Val(:rules), a, t, config) @test out == ["\e[0mgraph indexer rules set Qmb decisionBasis always allocationAmount 2"] end @testset "actionqueue" begin apply(mutate_success_patch) do - @inferred AllocationOpt.allocate(Val(:actionqueue), a, t, config) + @inferred AllocationOpt.allocate_action(Val(:actionqueue), a, t, config) end apply(mutate_success_patch) do - out = AllocationOpt.allocate(Val(:actionqueue), a, t, config) + out = AllocationOpt.allocate_action(Val(:actionqueue), a, t, config) @test out == [ Dict( "status" => AllocationOpt.queued, - "type" => AllocationOpt.allocateaction, - "ipfshash" => "Qmb", + "type" => AllocationOpt.allocate, + "deploymentID" => "Qmb", "amount" => "2", - "user" => "AllocationOpt", + "source" => "AllocationOpt", "reason" => "Expected profit: 0", "priority" => 0, )