-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86139dc
commit ea063bf
Showing
9 changed files
with
143 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: bot | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: bot | ||
args: ["src.dcm_supply.main"] | ||
env: | ||
- name: DISCORD_BOT_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: discord-bots-secret | ||
key: DISCORD_BOT_TOKEN_DCM_SUPPLY |
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,13 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
|
||
resources: | ||
- ../base | ||
|
||
namePrefix: dcm-supply- | ||
|
||
commonLabels: | ||
bot: dcm-supply | ||
|
||
patchesStrategicMerge: | ||
- deployment_set_bot.yaml |
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
Empty file.
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,99 @@ | ||
import os | ||
import json | ||
import math | ||
|
||
import requests | ||
from discord.ext import tasks | ||
from subgrounds.subgrounds import Subgrounds | ||
|
||
from ..utils import ( | ||
get_discord_client, | ||
update_nickname, | ||
update_presence, | ||
get_last_metric, | ||
get_last_carbon, | ||
prettify_number | ||
) | ||
|
||
BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"] | ||
|
||
# Initialized Discord client | ||
client = get_discord_client() | ||
|
||
sg = Subgrounds() | ||
|
||
|
||
def get_rebases_per_day(): | ||
""" | ||
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 = 11520 * avg_block_secs | ||
|
||
return 24 / (secs_per_rebase / 60 / 60) | ||
|
||
|
||
def get_info(): | ||
last_metric = get_last_metric(sg) | ||
total_carbon = sg.query([last_metric.treasuryCarbon]) | ||
|
||
last_carbon = get_last_carbon(sg) | ||
current_sma, credit_supply = sg.query( | ||
[last_carbon.creditSMA, last_carbon.creditSupply] | ||
) | ||
return total_carbon, current_sma, credit_supply | ||
|
||
|
||
@client.event | ||
async def on_ready(): | ||
print("Logged in as {0.user}".format(client)) | ||
if not update_info.is_running(): | ||
update_info.start() | ||
|
||
|
||
@tasks.loop(seconds=300) | ||
async def update_info(): | ||
rebases_per_day = get_rebases_per_day() | ||
|
||
treasury_carbon, carbon_sma, credit_supply = get_info() | ||
|
||
carbon_sma = carbon_sma / 1e18 | ||
credit_supply = credit_supply / 1e18 | ||
|
||
print(treasury_carbon) | ||
print(carbon_sma) | ||
if ( | ||
treasury_carbon is not None | ||
and carbon_sma is not None | ||
and rebases_per_day is not None | ||
): | ||
sma_percent = carbon_sma / credit_supply | ||
# ie, annualized reward % | ||
supply_change_annual = math.pow(1 + sma_percent, 365 * rebases_per_day) - 1 | ||
else: | ||
return | ||
|
||
yield_text = f"{supply_change_annual*100:,.2f}% Δ DCM Supply" | ||
print(yield_text) | ||
|
||
success = await update_nickname(client, yield_text) | ||
if not success: | ||
return | ||
|
||
presence_txt = f'Total DCM Supply: {prettify_number(credit_supply)}t' | ||
success = await update_presence( | ||
client, | ||
presence_txt, | ||
type='playing' | ||
) | ||
if not success: | ||
return | ||
|
||
|
||
client.run(BOT_TOKEN) |
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