diff --git a/.github/workflows/prod-deploy.yaml b/.github/workflows/prod-deploy.yaml new file mode 100644 index 00000000..d31c530e --- /dev/null +++ b/.github/workflows/prod-deploy.yaml @@ -0,0 +1,60 @@ +# deploys a new instance of rain solver +name: Deploy A New Rain Solver Worker + +on: + workflow_dispatch: + inputs: + deployment: + description: "Choose From Available Deployments" + required: true + type: choice + options: + - flare + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - run: | + deployment=${{ inputs.deployment }} + echo "rpc=PROD_${deployment^^}_RPC" >> $GITHUB_ENV + + - name: Checkout Repo + id: checkout + uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.PUBLISHER_SSH_KEY }} + submodules: recursive + fetch-depth: 0 + + - name: Install Nix 1/2 + uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - name: Install Nix 2/2 + uses: DeterminateSystems/flakehub-cache-action@main + + - name: Deploy New ${{ inputs.deployment }} Worker + env: + HYPERDX_API_KEY: ${{ secrets.HYPERDX_API_KEY }} + PROD_WALLET_KEY: ${{ secrets.PROD_WALLET_KEY }} + RPC_URL: ${{ secrets[env.rpc] }} + run: | + # Use envsubst to replace secrets in spec.yaml + nix develop -c envsubst -i deployments/${{ inputs.deployment }}/specs.yaml -o spec.yaml + + # Deploy + nix develop -c doctl apps create -t ${{ secrets.DOCTL_API_KEY }} --project-id ${{ secrets.DOCTL_PROJECT_ID }} --spec spec.yaml -o json > result.json + echo "APP_ID=$(jq -r '.[0].id' result.json)" >> $GITHUB_ENV + echo "${{ env.APP_ID }}" > deployments/${{ inputs.deployment }}/id.txt + + # rm temp files + rm -f result.json spec.yaml + + - name: Commit Changes + run: | + git add "deployments/${{ inputs.deployment }}/id.txt" + git commit -m "New Deployment ${{ inputs.deployment }} [skip ci]" + + - name: Push Changes To Remote + run: git push origin diff --git a/.github/workflows/prod-rebuild.yaml b/.github/workflows/prod-rebuild.yaml new file mode 100644 index 00000000..bf2f9666 --- /dev/null +++ b/.github/workflows/prod-rebuild.yaml @@ -0,0 +1,34 @@ +# Forces a rebuild of rain solver worker source +name: Rebuild A Rain Solver Worker + +on: + workflow_dispatch: + inputs: + deployment: + description: "Choose From Available Deployments" + required: true + type: choice + options: + - flare + +jobs: + rebuild: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + id: checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install Nix 1/2 + uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - name: Install Nix 2/2 + uses: DeterminateSystems/flakehub-cache-action@main + + - name: Rebuild ${{ inputs.deployment }} Worker + run: nix develop -c doctl apps create-deployment $(cat deployments/${{ inputs.deployment }}/id.txt) -t ${{ secrets.DOCTL_API_KEY }} --force-rebuild + diff --git a/.github/workflows/prod-restart.yaml b/.github/workflows/prod-restart.yaml new file mode 100644 index 00000000..ecb98cd7 --- /dev/null +++ b/.github/workflows/prod-restart.yaml @@ -0,0 +1,34 @@ +# soft restart the rain solver worker +name: Restart A Rain Solver Worker + +on: + workflow_dispatch: + inputs: + deployment: + description: "Choose From Available Deployments" + required: true + type: choice + options: + - flare + +jobs: + restart: + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + id: checkout + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install Nix 1/2 + uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - name: Install Nix 2/2 + uses: DeterminateSystems/flakehub-cache-action@main + + - name: Restart ${{ inputs.deployment }} Worker + run: nix develop -c doctl apps restart $(cat deployments/${{ inputs.deployment }}/id.txt) -t ${{ secrets.DOCTL_API_KEY }} + diff --git a/.github/workflows/prod-update.yaml b/.github/workflows/prod-update.yaml new file mode 100644 index 00000000..deadb0cb --- /dev/null +++ b/.github/workflows/prod-update.yaml @@ -0,0 +1,48 @@ +# updates the rain solver configuration only, i.e. without updating the source +name: Update A Rain Solver Worker Configurations + +on: + workflow_dispatch: + inputs: + deployment: + description: "Choose From Available Deployments" + required: true + type: choice + options: + - flare + +jobs: + update: + runs-on: ubuntu-latest + steps: + - run: | + deployment=${{ inputs.deployment }} + echo "rpc=PROD_${deployment^^}_RPC" >> $GITHUB_ENV + + - name: Checkout Repo + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install Nix 1/2 + uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - name: Install Nix 2/2 + uses: DeterminateSystems/flakehub-cache-action@main + + - name: Update ${{ inputs.deployment }} Worker + env: + HYPERDX_API_KEY: ${{ secrets.HYPERDX_API_KEY }} + PROD_WALLET_KEY: ${{ secrets.PROD_WALLET_KEY }} + RPC_URL: ${{ secrets[env.rpc] }} + run: | + # Use envsubst to replace secrets in spec.yaml + nix develop -c envsubst -i deployments/${{ inputs.deployment }}/specs.yaml -o spec.yaml + + # Deploy + nix develop -c doctl apps update $(cat deployments/${{ inputs.deployment }}/id.txt) -t ${{ secrets.DOCTL_API_KEY }} --spec spec.yaml + + # rm temp files + rm -f spec.yaml diff --git a/.github/workflows/prod-upgrade.yaml b/.github/workflows/prod-upgrade.yaml new file mode 100644 index 00000000..61b09f13 --- /dev/null +++ b/.github/workflows/prod-upgrade.yaml @@ -0,0 +1,47 @@ +# updates all rain solver workers to latest upstream changes +name: Upgrade Rain Solver Workers With Latest Production Changes + +on: + push: + branches: + - main + +jobs: + upgrade: + runs-on: ubuntu-latest + strategy: + matrix: + deployment: [flare] + fail-fast: false + steps: + - run: | + deployment=${{ matrix.deployment }} + echo "rpc=PROD_${deployment^^}_RPC" >> $GITHUB_ENV + + - name: Checkout Repo + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Install Nix 1/2 + uses: DeterminateSystems/nix-installer-action@main + with: + determinate: true + - name: Install Nix 2/2 + uses: DeterminateSystems/flakehub-cache-action@main + + - name: Upgrade ${{ matrix.deployment }} Worker + env: + HYPERDX_API_KEY: ${{ secrets.HYPERDX_API_KEY }} + PROD_WALLET_KEY: ${{ secrets.PROD_WALLET_KEY }} + RPC_URL: ${{ secrets[env.rpc] }} + run: | + # Use envsubst to replace secrets in spec.yaml + nix develop -c envsubst -i deployments/${{ matrix.deployment }}/specs.yaml -o spec.yaml + + # Upgrade to latest upstream source + nix develop -c doctl apps update $(cat deployments/${{ matrix.deployment }}/id.txt) -t ${{ secrets.DOCTL_API_KEY }} --spec spec.yaml --update-sources + + # rm temp files + rm -f spec.yaml diff --git a/deployments/flare/config.yaml b/deployments/flare/config.yaml new file mode 100644 index 00000000..117ceb76 --- /dev/null +++ b/deployments/flare/config.yaml @@ -0,0 +1,16 @@ +key: $BOT_WALLET_PRIVATEKEY +rpc: $RPC_URL +subgraph: + - https://api.goldsky.com/api/public/project_clv14x04y9kzi01saerx7bxpg/subgraphs/ob4-flare/2024-12-13-9dc7/gn +arbAddress: "0x5376Ffa8fbE804f3D9292bc6b319b0e59Ce42311" +dispair: "0xE3989Ea7486c0F418C764e6c511e86f6E8830FAb" +sleep: 10 +poolUpdateInterval: 60 +txGas: 110% +botMinBalance: 1 +gasPriceMultiplier: 115 +maxRatio: true +rpOnly: true +sgFilter: + includeOwners: + - "0x7177b9d00bB5dbcaaF069CC63190902763783b09" diff --git a/deployments/flare/specs.yaml b/deployments/flare/specs.yaml new file mode 100644 index 00000000..c1b70190 --- /dev/null +++ b/deployments/flare/specs.yaml @@ -0,0 +1,44 @@ +alerts: +- rule: DEPLOYMENT_FAILED +- rule: DOMAIN_FAILED + +features: +- buildpack-stack=ubuntu-22 + +ingress: {} +name: flare-bot-test-poc +region: nyc + +workers: +- image: + registry: rainprotocol + registry_type: DOCKER_HUB + repository: arb-bot + tag: master + instance_count: 1 + instance_size_slug: apps-s-1vcpu-0.5gb + name: flare-bot-test-poc + +envs: +- key: BOT_WALLET_PRIVATEKEY + scope: RUN_AND_BUILD_TIME + type: SECRET + value: $PROD_WALLET_KEY + +- key: RPC_URL + scope: RUN_AND_BUILD_TIME + type: SECRET + value: $RPC_URL + +- key: HYPERDX_API_KEY + scope: RUN_AND_BUILD_TIME + type: SECRET + value: $HYPERDX_API_KEY + +- key: TRACER_SERVICE_NAME + scope: RUN_AND_BUILD_TIME + value: flare-bot-test-poc + +- key: CONFIG + scope: RUN_AND_BUILD_TIME + value: deployments/flare/config.yaml diff --git a/flake.lock b/flake.lock index b2b3b97c..2ef008ae 100644 --- a/flake.lock +++ b/flake.lock @@ -228,7 +228,7 @@ "foundry": { "inputs": { "flake-utils": "flake-utils_3", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1709457044, @@ -248,7 +248,7 @@ "foundry_2": { "inputs": { "flake-utils": "flake-utils_6", - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { "lastModified": 1705216422, @@ -268,7 +268,7 @@ "foundry_3": { "inputs": { "flake-utils": "flake-utils_9", - "nixpkgs": "nixpkgs_5" + "nixpkgs": "nixpkgs_6" }, "locked": { "lastModified": 1705216422, @@ -287,7 +287,7 @@ }, "naersk": { "inputs": { - "nixpkgs": "nixpkgs_7" + "nixpkgs": "nixpkgs_8" }, "locked": { "lastModified": 1686572087, @@ -305,19 +305,36 @@ }, "nixpkgs": { "locked": { - "lastModified": 1666753130, - "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", - "owner": "NixOS", + "lastModified": 1746665457, + "narHash": "sha256-T6XRB5wFV9sfD7Qm0Jp4YFTrYqYgI9H2mEm2O8w3KoM=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "f540aeda6f677354f1e7144ab04352f61aaa0118", + "rev": "b12bed980c5f2467ca81278f80ad7826188c0c55", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" } }, "nixpkgs_10": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_11": { "locked": { "lastModified": 1706487304, "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", @@ -333,7 +350,7 @@ "type": "github" } }, - "nixpkgs_11": { + "nixpkgs_12": { "locked": { "lastModified": 1706487304, "narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=", @@ -350,6 +367,20 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1666753130, + "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f540aeda6f677354f1e7144ab04352f61aaa0118", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1711909583, "narHash": "sha256-pzOaVA9C4Ragp7m5Uzp0JpanE+MOYdY0IJb6wpvtlD4=", @@ -364,7 +395,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1666753130, "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", @@ -378,7 +409,7 @@ "type": "indirect" } }, - "nixpkgs_4": { + "nixpkgs_5": { "locked": { "lastModified": 1706634492, "narHash": "sha256-9wg1OQET7oCzzMsktGufJmfr2ylecL8T8YYqQo+qNSc=", @@ -394,7 +425,7 @@ "type": "github" } }, - "nixpkgs_5": { + "nixpkgs_6": { "locked": { "lastModified": 1666753130, "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", @@ -408,7 +439,7 @@ "type": "indirect" } }, - "nixpkgs_6": { + "nixpkgs_7": { "locked": { "lastModified": 1706634492, "narHash": "sha256-9wg1OQET7oCzzMsktGufJmfr2ylecL8T8YYqQo+qNSc=", @@ -424,7 +455,7 @@ "type": "github" } }, - "nixpkgs_7": { + "nixpkgs_8": { "locked": { "lastModified": 1687518131, "narHash": "sha256-KirltRIc4SFfk8bTNudIqgKAALH5oqpW3PefmkfWK5M=", @@ -438,7 +469,7 @@ "type": "indirect" } }, - "nixpkgs_8": { + "nixpkgs_9": { "locked": { "lastModified": 1687518131, "narHash": "sha256-KirltRIc4SFfk8bTNudIqgKAALH5oqpW3PefmkfWK5M=", @@ -454,22 +485,6 @@ "type": "github" } }, - "nixpkgs_9": { - "locked": { - "lastModified": 1681358109, - "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "rain": { "inputs": { "flake-utils": "flake-utils_4", @@ -512,7 +527,7 @@ "inputs": { "flake-utils": "flake-utils_10", "naersk": "naersk", - "nixpkgs": "nixpkgs_8" + "nixpkgs": "nixpkgs_9" }, "locked": { "lastModified": 1700476138, @@ -532,7 +547,7 @@ "inputs": { "flake-utils": "flake-utils_2", "foundry": "foundry", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs_3", "rain": "rain", "rust-overlay": "rust-overlay_3" }, @@ -554,7 +569,7 @@ "inputs": { "flake-utils": "flake-utils_5", "foundry": "foundry_2", - "nixpkgs": "nixpkgs_4", + "nixpkgs": "nixpkgs_5", "rain": "rain_2", "rust-overlay": "rust-overlay_2" }, @@ -576,7 +591,7 @@ "inputs": { "flake-utils": "flake-utils_8", "foundry": "foundry_3", - "nixpkgs": "nixpkgs_6", + "nixpkgs": "nixpkgs_7", "rain": "rain_3", "rust-overlay": "rust-overlay" }, @@ -597,13 +612,14 @@ "root": { "inputs": { "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", "rainix": "rainix" } }, "rust-overlay": { "inputs": { "flake-utils": "flake-utils_11", - "nixpkgs": "nixpkgs_9" + "nixpkgs": "nixpkgs_10" }, "locked": { "lastModified": 1706580650, @@ -622,7 +638,7 @@ "rust-overlay_2": { "inputs": { "flake-utils": "flake-utils_12", - "nixpkgs": "nixpkgs_10" + "nixpkgs": "nixpkgs_11" }, "locked": { "lastModified": 1706634984, @@ -641,7 +657,7 @@ "rust-overlay_3": { "inputs": { "flake-utils": "flake-utils_13", - "nixpkgs": "nixpkgs_11" + "nixpkgs": "nixpkgs_12" }, "locked": { "lastModified": 1711851236, diff --git a/flake.nix b/flake.nix index 6e4f2cde..a39ea30c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,20 +2,23 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; rainix.url = "github:rainprotocol/rainix"; + nixpkgs.url = "github:nixos/nixpkgs"; }; - outputs = { self, flake-utils, rainix }: + outputs = { self, flake-utils, rainix, nixpkgs }: flake-utils.lib.eachDefaultSystem (system: let pkgs = rainix.pkgs.${system}; + pkgsnix = import nixpkgs { inherit system; }; in rec { # For `nix develop`: devShells.default = pkgs.mkShell { nativeBuildInputs = [ rainix.node-build-inputs.${system} rainix.sol-build-inputs.${system} - pkgs.doctl + pkgsnix.doctl + pkgsnix.envsubst ]; }; }