-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CCO2 price feed bot based on KLIMA/CCO2 pool #72
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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:,.3f} 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we can't always assume that there's a decimals function to call on an ERC20, but in this case it should be fine since the tokens we are tracking all have the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's why I made it optional
Either we can specify it manually, or if not specified manually we try calling from the
decimals
function