diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b3f3976..423dc86 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,12 +27,14 @@ jobs: - name: Check out source repository uses: actions/checkout@v2 - name: Setup Kustomize - uses: imranismail/setup-kustomize@v1 + uses: imranismail/setup-kustomize@v2.1.0-rc with: kustomize-version: "4.5.4" + - name: Update secret properties with injected secrets + run: touch $GITHUB_WORKSPACE/k8s/secret.properties - name: Kustomize run: kustomize build k8s > /tmp/kustomized.yaml - - uses: azure/k8s-lint@v1 + - uses: azure/k8s-lint@v2.0 with: manifests: | /tmp/kustomized.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index f676352..ed8cc30 100755 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -75,11 +75,13 @@ jobs: # k8s Deployment - name: Setup Kustomize - uses: imranismail/setup-kustomize@v1 + uses: imranismail/setup-kustomize@v2.1.0-rc with: kustomize-version: "4.5.4" - name: Update deployment file with image run: sed -i 's||'${DOCKER_IMAGE}'|' $GITHUB_WORKSPACE/k8s/base/deployment.yaml + - name: Update secret properties with injected secrets + run: envsubst < $GITHUB_WORKSPACE/k8s/secret.properties.template > $GITHUB_WORKSPACE/k8s/secret.properties - name: Save DigitalOcean kubeconfig with short-lived credentials run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 ${{ secrets.DIGITALOCEAN_CLUSTER_NAME }} - name: Deploy to DigitalOcean Kubernetes diff --git a/Dockerfile b/Dockerfile index 70f7fdf..126b950 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* # CVE-2022-1292 openssl fix -RUN apt-get update && apt-get --only-upgrade install openssl libssl1.1 -y && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get --only-upgrade install openssl libssl-dev -y && rm -rf /var/lib/apt/lists/* RUN mkdir -p /opt diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml index 7a15aa5..0831060 100644 --- a/k8s/kustomization.yaml +++ b/k8s/kustomization.yaml @@ -28,4 +28,5 @@ namespace: discord-bots secretGenerator: - name: discord-bots-secret - env: secret.properties + envs: + - secret.properties diff --git a/k8s/secret.properties b/k8s/secret.properties deleted file mode 100644 index 9bb4d71..0000000 --- a/k8s/secret.properties +++ /dev/null @@ -1,27 +0,0 @@ -AIRTABLE_API_KEY - -DISCORD_BOT_TOKEN_BCT_PRICE -DISCORD_BOT_TOKEN_KLIMA_BOND_ALERTS -DISCORD_BOT_TOKEN_C3_PRICE -DISCORD_BOT_TOKEN_KLIMA_PRICE -DISCORD_BOT_TOKEN_MCO2_PRICE -DISCORD_BOT_TOKEN_MOSS_PRICE -DISCORD_BOT_TOKEN_NBO_PRICE -DISCORD_BOT_TOKEN_NCT_PRICE -DISCORD_BOT_TOKEN_REBASE -DISCORD_BOT_TOKEN_STAKING_REWARDS -DISCORD_BOT_TOKEN_SUPPLY_CC -DISCORD_BOT_TOKEN_INDEX -DISCORD_BOT_TOKEN_TREASURY_CARBON -DISCORD_BOT_TOKEN_TREASURY_MARKET -DISCORD_BOT_TOKEN_UBO_PRICE -DISCORD_BOT_TOKEN_RUNWAY -DISCORD_BOT_TOKEN_RETIREMENT_FEE_INFO -DISCORD_BOT_TOKEN_DAO_FEE -DISCORD_BOT_TOKEN_DAO_BALANCE -DISCORD_BOT_WEBHOOK_REBASE -DISCORD_WEBHOOK_BROKEN_BOND_ALERT - -POLYGONSCAN_API_KEY -WEB3_PROVIDER_ETH_URL -WEB3_PROVIDER_POLYGON_URL diff --git a/k8s/secret.properties.template b/k8s/secret.properties.template new file mode 100644 index 0000000..48bd166 --- /dev/null +++ b/k8s/secret.properties.template @@ -0,0 +1,27 @@ +AIRTABLE_API_KEY=${AIRTABLE_API_KEY} + +DISCORD_BOT_TOKEN_BCT_PRICE=${DISCORD_BOT_TOKEN_BCT_PRICE} +DISCORD_BOT_TOKEN_KLIMA_BOND_ALERTS=${DISCORD_BOT_TOKEN_KLIMA_BOND_ALERTS} +DISCORD_BOT_TOKEN_C3_PRICE=${DISCORD_BOT_TOKEN_C3_PRICE} +DISCORD_BOT_TOKEN_KLIMA_PRICE=${DISCORD_BOT_TOKEN_KLIMA_PRICE} +DISCORD_BOT_TOKEN_MCO2_PRICE=${DISCORD_BOT_TOKEN_MCO2_PRICE} +DISCORD_BOT_TOKEN_MOSS_PRICE=${DISCORD_BOT_TOKEN_MOSS_PRICE} +DISCORD_BOT_TOKEN_NBO_PRICE=${DISCORD_BOT_TOKEN_NBO_PRICE} +DISCORD_BOT_TOKEN_NCT_PRICE=${DISCORD_BOT_TOKEN_NCT_PRICE} +DISCORD_BOT_TOKEN_REBASE=${DISCORD_BOT_TOKEN_REBASE} +DISCORD_BOT_TOKEN_STAKING_REWARDS=${DISCORD_BOT_TOKEN_STAKING_REWARDS} +DISCORD_BOT_TOKEN_SUPPLY_CC=${DISCORD_BOT_TOKEN_SUPPLY_CC} +DISCORD_BOT_TOKEN_INDEX=${DISCORD_BOT_TOKEN_INDEX} +DISCORD_BOT_TOKEN_TREASURY_CARBON=${DISCORD_BOT_TOKEN_TREASURY_CARBON} +DISCORD_BOT_TOKEN_TREASURY_MARKET=${DISCORD_BOT_TOKEN_TREASURY_MARKET} +DISCORD_BOT_TOKEN_UBO_PRICE=${DISCORD_BOT_TOKEN_UBO_PRICE} +DISCORD_BOT_TOKEN_RUNWAY=${DISCORD_BOT_TOKEN_RUNWAY} +DISCORD_BOT_TOKEN_RETIREMENT_FEE_INFO=${DISCORD_BOT_TOKEN_RETIREMENT_FEE_INFO} +DISCORD_BOT_TOKEN_DAO_FEE=${DISCORD_BOT_TOKEN_DAO_FEE} +DISCORD_BOT_TOKEN_DAO_BALANCE=${DISCORD_BOT_TOKEN_DAO_BALANCE} +DISCORD_BOT_WEBHOOK_REBASE=${DISCORD_BOT_WEBHOOK_REBASE} +DISCORD_WEBHOOK_BROKEN_BOND_ALERT=${DISCORD_WEBHOOK_BROKEN_BOND_ALERT} + +POLYGONSCAN_API_KEY=${POLYGONSCAN_API_KEY} +WEB3_PROVIDER_ETH_URL=${WEB3_PROVIDER_ETH_URL} +WEB3_PROVIDER_POLYGON_URL=${WEB3_PROVIDER_POLYGON_URL} diff --git a/src/runway/main.py b/src/runway/main.py index b8db2ed..7650b29 100644 --- a/src/runway/main.py +++ b/src/runway/main.py @@ -3,7 +3,7 @@ from subgrounds.subgrounds import Subgrounds -from ..constants import MCO2_ADDRESS, MCO2_DECIMALS,\ +from ..constants import MCO2_ADDRESS, MCO2_DECIMALS, \ BCT_ADDRESS, BCT_DECIMALS, \ NCT_ADDRESS, NCT_DECIMALS, NBO_ADDRESS, \ NBO_DECIMALS, UBO_ADDRESS, UBO_DECIMALS diff --git a/src/staking_rewards/main.py b/src/staking_rewards/main.py index 4fe6e0e..ea82e01 100755 --- a/src/staking_rewards/main.py +++ b/src/staking_rewards/main.py @@ -1,15 +1,16 @@ import os -import json import math import traceback -import requests from web3.middleware import geth_poa_middleware from discord.ext import tasks from ..constants import DISTRIBUTOR_ADDRESS, SKLIMA_ADDRESS from ..utils import get_discord_client, get_polygon_web3, load_abi, update_nickname, update_presence +# Hard-coded since Polygon block times have stabilized +AVG_BLOCK_SECS = 2.21 + BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"] SCAN_API_KEY = os.environ['POLYGONSCAN_API_KEY'] @@ -62,11 +63,8 @@ def get_rebases_per_day(blocks_per_rebase): Calculates the average number of rebases per day based on the average block production time for the previous 1 million blocks ''' - avg_block_secs = float(json.loads( - requests.get('https://klimadao.finance/api/block-rate').content)['blockRate30Day'] - ) - secs_per_rebase = blocks_per_rebase * avg_block_secs + secs_per_rebase = blocks_per_rebase * AVG_BLOCK_SECS return 24 / (secs_per_rebase / 60 / 60) @@ -98,7 +96,7 @@ async def update_info(): else: return - yield_text = f'{five_day_rewards*100:,.2f}% 5 Day Rewards' + yield_text = f'{five_day_rewards*100:,.3f}% 5 Day Rewards' print(yield_text) success = await update_nickname(client, yield_text)