From c1d4578175dd399fdcc6702cc3a0827d2683ff55 Mon Sep 17 00:00:00 2001 From: "Anirudh A. Patel" Date: Wed, 23 Mar 2022 14:26:44 -0700 Subject: [PATCH] chore: initial commit --- .github/workflows/CI.yml | 57 ++++++++++++++++ .github/workflows/CompatHelper.yml | 16 +++++ .github/workflows/Release.yml | 36 +++++++++++ .releaserc | 40 ++++++++++++ CHANGELOG.md | 0 LICENSE | 21 ++++++ Manifest.toml | 2 + Project.toml | 13 ++++ README.md | 6 ++ docs/Manifest.toml | 100 +++++++++++++++++++++++++++++ docs/Project.toml | 3 + docs/make.jl | 23 +++++++ docs/src/index.md | 14 ++++ src/AllocationOpt.jl | 5 ++ src/optimize.jl | 8 +++ test/optimize-test.jl | 53 +++++++++++++++ test/runtests.jl | 6 ++ 17 files changed, 403 insertions(+) create mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/CompatHelper.yml create mode 100644 .github/workflows/Release.yml create mode 100644 .releaserc create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 Manifest.toml create mode 100644 Project.toml create mode 100644 README.md create mode 100644 docs/Manifest.toml create mode 100644 docs/Project.toml create mode 100644 docs/make.jl create mode 100644 docs/src/index.md create mode 100644 src/AllocationOpt.jl create mode 100644 src/optimize.jl create mode 100644 test/optimize-test.jl create mode 100644 test/runtests.jl diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..ec0864f --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,57 @@ +name: CI +on: + push: + branches: + tags: '*' + pull_request: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.7' + - 'nightly' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v1 + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v2 + with: + files: lcov.info + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: '1' + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-docdeploy@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} + - run: | + julia --project=docs -e ' + using Documenter: DocMeta, doctest + using AllocationOpt + DocMeta.setdocmeta!(AllocationOpt, :DocTestSetup, :(using AllocationOpt); recursive=true) + doctest(AllocationOpt)' diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml new file mode 100644 index 0000000..cba9134 --- /dev/null +++ b/.github/workflows/CompatHelper.yml @@ -0,0 +1,16 @@ +name: CompatHelper +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: +jobs: + CompatHelper: + runs-on: ubuntu-latest + steps: + - name: Pkg.add("CompatHelper") + run: julia -e 'using Pkg; Pkg.add("CompatHelper")' + - name: CompatHelper.main() + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} + run: julia -e 'using CompatHelper; CompatHelper.main()' diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml new file mode 100644 index 0000000..1207485 --- /dev/null +++ b/.github/workflows/Release.yml @@ -0,0 +1,36 @@ +name: Release + +on: + workflow_run: + workflows: ["CI"] + types: [completed] + +jobs: + release: + name: Release + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v2 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + semantic_version: 18.0.1 + extra_plugins: | + @semantic-release/changelog + @semantic-release/git + @google/semantic-release-replace-plugin + + no-release: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + steps: + - run: | + echo "Release skipped as previous stage failed." + curl \ + -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/octocat/hello-world/actions/runs/42/cancel diff --git a/.releaserc b/.releaserc new file mode 100644 index 0000000..98d6628 --- /dev/null +++ b/.releaserc @@ -0,0 +1,40 @@ +{ + "branches": ["main"], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@google/semantic-release-replace-plugin", { + "replacements": [ + { + "files": ["Project.toml"], + "from": "version = \".*\"", + "to": "version = \"${nextRelease.version}\"", + "results": [ + { + "file": "Project.toml", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + } + ], + "countMatches": true + } + ] + } + ], + [ + "@semantic-release/changelog", { + "changelogTitle": "# Changelog" + } + ], + [ + "@semantic-release/git", { + "assets": ["CHANGELOG.md", "Project.toml"], + "message": "chore: release v${nextRelease.version}\n\n${nextRelease.notes}" + } + ], + "@semantic-release/github" + ], + "repositoryUrl": "git@github.com:graphprotocol/AllocationOpt.jl.git" +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..23dc21e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 The Graph Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 0000000..f45eecf --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..71789be --- /dev/null +++ b/Project.toml @@ -0,0 +1,13 @@ +name = "AllocationOpt" +uuid = "c8d4fa36-652a-4cad-a59b-8b946e6f88a6" +authors = ["The Graph Foundation"] +version = "0.1.0" + +[compat] +julia = "1.7" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ceecc5e --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# AllocationOpt + +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://anirudh2.github.io/AllocationOpt.jl/stable) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://anirudh2.github.io/AllocationOpt.jl/dev) +[![Build Status](https://github.com/anirudh2/AllocationOpt.jl/actions/workflows/CI.yml/badge.svg?branch=)](https://github.com/anirudh2/AllocationOpt.jl/actions/workflows/CI.yml?query=branch%3A) +[![Coverage](https://codecov.io/gh/anirudh2/AllocationOpt.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/anirudh2/AllocationOpt.jl) diff --git a/docs/Manifest.toml b/docs/Manifest.toml new file mode 100644 index 0000000..f471996 --- /dev/null +++ b/docs/Manifest.toml @@ -0,0 +1,100 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.7.2" +manifest_format = "2.0" + +[[deps.ANSIColoredPrinters]] +git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c" +uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9" +version = "0.0.1" + +[[deps.AllocationOpt]] +path = ".." +uuid = "c8d4fa36-652a-4cad-a59b-8b946e6f88a6" +version = "0.1.0" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.DocStringExtensions]] +deps = ["LibGit2"] +git-tree-sha1 = "b19534d1895d702889b219c382a6e18010797f0b" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.6" + +[[deps.Documenter]] +deps = ["ANSIColoredPrinters", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "7d9a46421aef53cbd6b8ecc40c3dcbacbceaf40e" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.27.15" + +[[deps.IOCapture]] +deps = ["Logging", "Random"] +git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a" +uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +version = "0.2.2" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "3c837543ddb02250ef42f4738347454f95079d4e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.3" + +[[deps.LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" + +[[deps.Parsers]] +deps = ["Dates"] +git-tree-sha1 = "85b5da0fa43588c75bb1ff986493443f821c70b7" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.2.3" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/docs/Project.toml b/docs/Project.toml new file mode 100644 index 0000000..57daaa9 --- /dev/null +++ b/docs/Project.toml @@ -0,0 +1,3 @@ +[deps] +AllocationOpt = "c8d4fa36-652a-4cad-a59b-8b946e6f88a6" +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 0000000..2979f24 --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,23 @@ +using AllocationOpt +using Documenter + +DocMeta.setdocmeta!(AllocationOpt, :DocTestSetup, :(using AllocationOpt); recursive=true) + +makedocs(; + modules=[AllocationOpt], + authors="The Graph Foundation", + repo="https://github.com/anirudh2/AllocationOpt.jl/blob/{commit}{path}#{line}", + sitename="AllocationOpt.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://anirudh2.github.io/AllocationOpt.jl", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) + +deploydocs(; + repo="github.com/anirudh2/AllocationOpt.jl", +) diff --git a/docs/src/index.md b/docs/src/index.md new file mode 100644 index 0000000..2823587 --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1,14 @@ +```@meta +CurrentModule = AllocationOpt +``` + +# AllocationOpt + +Documentation for [AllocationOpt](https://github.com/anirudh2/AllocationOpt.jl). + +```@index +``` + +```@autodocs +Modules = [AllocationOpt] +``` diff --git a/src/AllocationOpt.jl b/src/AllocationOpt.jl new file mode 100644 index 0000000..e5abe54 --- /dev/null +++ b/src/AllocationOpt.jl @@ -0,0 +1,5 @@ +module AllocationOpt + +include("optimize.jl") + +end diff --git a/src/optimize.jl b/src/optimize.jl new file mode 100644 index 0000000..ab2495b --- /dev/null +++ b/src/optimize.jl @@ -0,0 +1,8 @@ +export optimize + +function optimize(optimize_id, repository, whitelist, blacklist) + if !isnothing(whitelist) && !isnothing(blacklist) + throw(ArgumentError("whitelist and blacklist cannot both be specified")) + end + +end diff --git a/test/optimize-test.jl b/test/optimize-test.jl new file mode 100644 index 0000000..0cc20db --- /dev/null +++ b/test/optimize-test.jl @@ -0,0 +1,53 @@ +@testset "optimize.jl" begin + + struct FakeAllocation + id::String + amount::Float64 + end + struct FakeIndexer + id::String + stake::Float64 + allocation::NTuple{2, FakeAllocation} + end + struct FakeSubgraph + id::String + signal::Float64 + end + struct FakeRepository + indexers::NTuple{2, FakeIndexer} + subgraphs::NTuple{2, FakeSubgraph} + end + + fake_repository = FakeRepository( + ( + FakeIndexer("0x000", 5.0, (FakeAllocation("0x010", 2.5), FakeAllocation("0x011", 2.5))), + FakeIndexer("0x001", 10.0, (FakeAllocation("0x010", 2.0), FakeAllocation("0x011", 8.0))) + ), + (FakeSubgraph("0x010", 10.0), FakeSubgraph("0x011", 5.0)) + ) + @test_throws ArgumentError optimize("0x000", fake_repository, ("0x010",), ("0x010",)) + + allocations = optimize(optimize_id="0x000", repository=fake_repository, blacklist=nothing, whitelist=nothing) + @test allocations["0x010"] ≈ 4.2 + @test allocations["0x011"] ≈ 0.8 + + # allocations = optimize(optimize_id="0x000", repository=fake_repository, blacklist=("0x010",), whitelist=nothing) + # @test allocations["0x010"] ≈ 0.0 + # @test allocations["0x011"] ≈ 5.0 + + # allocations = optimize(optimize_id="0x000", repository=fake_repository, blacklist=nothing, whitelist=("0x010",)) + # @test allocations["0x010"] ≈ 5.0 + # @test allocations["0x011"] ≈ 0.0 + + # fake_repository = FakeRepository( + # ( + # FakeIndexer("0x000", 2.0, (FakeAllocation("0x010", 2.0), FakeAllocation("0x011", 0.0))), + # FakeIndexer("0x001", 10.0, (FakeAllocation("0x010", 10.0), FakeAllocation("0x011", 4.0))) + # ), + # (FakeSubgraph("0x010", 1.0), FakeSubgraph("0x011", 5.0)) + # ) + # allocations = optimize(optimize_id="0x000", repository=fake_repository, blacklist=nothing, whitelist=nothing) + # @test allocations["0x010"] ≈ 0.0 + # @test allocations["0x011"] ≈ 2.0 + @test true +end diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..2126237 --- /dev/null +++ b/test/runtests.jl @@ -0,0 +1,6 @@ +using AllocationOpt +using Test + +@testset "AllocationOpt.jl" begin + include("optimize-test.jl") +end