Skip to content

Commit

Permalink
Merge pull request #69 from 0xAurelius/avoid-api-call
Browse files Browse the repository at this point in the history
Switch to hard-coded block secs
  • Loading branch information
0xAurelius committed Nov 9, 2023
2 parents 1e642d3 + 1caf08f commit 5c8a2dc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 40 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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|<IMAGE>|'${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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion k8s/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ namespace: discord-bots

secretGenerator:
- name: discord-bots-secret
env: secret.properties
envs:
- secret.properties
27 changes: 0 additions & 27 deletions k8s/secret.properties

This file was deleted.

27 changes: 27 additions & 0 deletions k8s/secret.properties.template
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 1 addition & 1 deletion src/runway/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions src/staking_rewards/main.py
Original file line number Diff line number Diff line change
@@ -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']

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5c8a2dc

Please sign in to comment.