-
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 e97a242
Showing
10 changed files
with
174 additions
and
40 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,90 @@ | ||
import os | ||
import math | ||
|
||
from discord.ext import tasks | ||
from subgrounds.subgrounds import Subgrounds | ||
from web3.middleware import geth_poa_middleware | ||
|
||
from ..utils import ( | ||
get_discord_client, | ||
get_polygon_web3, | ||
update_nickname, | ||
update_presence, | ||
get_last_metric, | ||
get_last_carbon, | ||
prettify_number, | ||
get_rebases_per_day, | ||
get_staking_params | ||
) | ||
|
||
BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"] | ||
|
||
# Initialized Discord client | ||
client = get_discord_client() | ||
|
||
sg = Subgrounds() | ||
|
||
# Initialize web3 | ||
web3 = get_polygon_web3() | ||
web3.middleware_onion.inject(geth_poa_middleware, layer=0) | ||
|
||
|
||
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(): | ||
staking_reward, epoch_length = get_staking_params(web3) | ||
rebases_per_day = get_rebases_per_day(epoch_length) | ||
|
||
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
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