-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allocationOpt: add gas cost and concurrent plans
- Loading branch information
Showing
7 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export calculate_gas_fee, sum_gas_fee, estimated_profit | ||
|
||
function calculate_gas_fee(allocs::Dict{String, Float64}, txGas) | ||
sum(map(x -> x > 0 ? txGas : 0, values(allocs))) | ||
end | ||
|
||
function sum_gas_fee(allocs::Dict{String, Float64}, txGas) | ||
# open + close + claim | ||
calculate_gas_fee(allocs, txGas) + calculate_gas_fee(allocs, txGas) + calculate_gas_fee(allocs, 0.3 * txGas) | ||
end | ||
|
||
function estimated_profit(repo::Repository, allocs::Dict{String, Float64}, txGas) | ||
repository = Repository(repo.indexers, filter(x -> x.id in keys(allocs) ,repo.subgraphs)) | ||
rewards(repository, allocs) - sum_gas_fee(allocs, txGas) | ||
end | ||
|
||
function rewards(repo::Repository, allocs::Dict{String, Float64}) | ||
total = 0 | ||
for (id, amount) in allocs | ||
total += signals(repo, id) * amount / (allocations(repo, id) + amount) | ||
end | ||
total | ||
end | ||
|
||
#TODO: add query to get real time gas rates for each tx -> this can be connected to indexer making gas estimations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@testset "AllocationOpt" begin | ||
|
||
gas_fee = 0.3 | ||
repository = Repository( | ||
[ | ||
Indexer( | ||
"0x000", 5.0, 0.0, [Allocation("0x010", 2.5), Allocation("0x011", 2.5)] | ||
), | ||
Indexer( | ||
"0x001", 10.0, 0.0, [Allocation("0x010", 2.0), Allocation("0x011", 8.0)] | ||
), | ||
], | ||
[Subgraph("0x011", 10.0), Subgraph("0x010", 5.0)], | ||
) | ||
|
||
allocations = allocation_optimization("0x000", repository, gas_fee) | ||
|
||
@test allocations["0x011"] ≈ 5.0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters