-
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.
Add CCO2 price feed bot based on KLIMA/CCO2 pool
- Loading branch information
1 parent
5c8a2dc
commit 9d9252d
Showing
8 changed files
with
94 additions
and
2 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
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.cco2_price.main"] | ||
env: | ||
- name: DISCORD_BOT_TOKEN | ||
valueFrom: | ||
secretKeyRef: | ||
name: discord-bots-secret | ||
key: DISCORD_BOT_TOKEN_CCO2_PRICE |
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: cco2-price- | ||
|
||
commonLabels: | ||
bot: cco2-price | ||
|
||
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
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,56 @@ | ||
import os | ||
from discord.ext import tasks | ||
|
||
from ..constants import CCO2_ADDRESS, KLIMA_CCO2_POOL, KLIMA_DECIMALS | ||
from ..contract_info import uni_v2_pool_price, token_supply, klima_usdc_price | ||
from ..utils import get_polygon_web3, \ | ||
get_discord_client, load_abi, prettify_number, \ | ||
update_nickname, update_presence | ||
|
||
BOT_TOKEN = os.environ["DISCORD_BOT_TOKEN"] | ||
|
||
# Initialized Discord client | ||
client = get_discord_client() | ||
|
||
# Initialize web3 | ||
web3 = get_polygon_web3() | ||
|
||
# Load ABIs | ||
cco2_abi = load_abi('carbon_pool.json') | ||
|
||
|
||
@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(): | ||
klima_price = klima_usdc_price(web3) | ||
token_price = uni_v2_pool_price( | ||
web3, KLIMA_CCO2_POOL, | ||
KLIMA_DECIMALS | ||
) | ||
supply = token_supply(web3, CCO2_ADDRESS, cco2_abi) | ||
|
||
if klima_price is not None and token_price is not None and supply is not None: | ||
price = klima_price * token_price | ||
price_text = f'${price:,.2f} CCO2' | ||
|
||
print(price_text) | ||
|
||
success = await update_nickname(client, price_text) | ||
if not success: | ||
return | ||
|
||
supply_text = f'Supply: {prettify_number(supply)}' | ||
success = await update_presence( | ||
client, | ||
supply_text | ||
) | ||
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