Skip to content
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

Pool command #7

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ DISCORD_TOKEN_PRICING=
DISCORD_TOKEN_TVL=
DISCORD_TOKEN_FEES=
DISCORD_TOKEN_REWARDS=
DISCORD_TOKEN_COMMANDER=
WEB3_PROVIDER_URI=https://mainnet.optimism.io
PROTOCOL_NAME=Velodrome
APP_BASE_URL=https://velodrome.finance
LP_SUGAR_ADDRESS=0xa1F09427fa89b92e9B4e4c7003508C8614F19791
PRICE_ORACLE_ADDRESS=0x07F544813E9Fb63D57a92f28FbD3FF0f7136F5cE
PRICE_BATCH_SIZE=40
Expand All @@ -16,5 +18,7 @@ STABLE_TOKEN_ADDRESS=0x7F5c764cBc14f9669B88837ca1490cCa17c31607
BOT_TICKER_INTERVAL_MINUTES=1
# caching for Sugar tokens
SUGAR_TOKENS_CACHE_MINUTES=10
# caching for Sugar LPs
SUGAR_LPS_CACHE_MINUTES=10
# caching for oracle pricing
ORACLE_PRICES_CACHE_MINUTES=10
9 changes: 8 additions & 1 deletion bots/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
DISCORD_TOKEN_TVL,
DISCORD_TOKEN_FEES,
DISCORD_TOKEN_REWARDS,
DISCORD_TOKEN_COMMANDER,
TOKEN_ADDRESS,
STABLE_TOKEN_ADDRESS,
PROTOCOL_NAME,
)
from .data import Token
from .helpers import LOGGING_HANDLER, LOGGING_LEVEL
from .helpers import (
LOGGING_HANDLER,
LOGGING_LEVEL,
)
from .price import PriceBot
from .tvl import TVLBot
from .fees import FeesBot
from .rewards import RewardsBot
from .commander import CommanderBot


async def main():
Expand All @@ -33,12 +38,14 @@ async def main():
tvl_bot = TVLBot(protocol_name=PROTOCOL_NAME)
fees_bot = FeesBot(protocol_name=PROTOCOL_NAME)
rewards_bot = RewardsBot(protocol_name=PROTOCOL_NAME)
commander_bot = CommanderBot()

await asyncio.gather(
price_bot.start(DISCORD_TOKEN_PRICING),
fees_bot.start(DISCORD_TOKEN_FEES),
tvl_bot.start(DISCORD_TOKEN_TVL),
rewards_bot.start(DISCORD_TOKEN_REWARDS),
commander_bot.start(DISCORD_TOKEN_COMMANDER),
)


Expand Down
63 changes: 63 additions & 0 deletions bots/commander.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from .data import LiquidityPool
from .helpers import is_address
from .ui import PoolsDropdown, PoolStats

import discord
from discord.ext import commands


class _CommanderBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(command_prefix="/", intents=intents)

async def on_ready(self):
print(f"Logged in as {self.user} (ID: {self.user.id})")
print("------")
await bot.tree.sync()


bot = _CommanderBot()


def CommanderBot() -> commands.Bot:
return bot


async def on_select_pool(
response: discord.InteractionResponse,
address_or_pool: str | LiquidityPool,
):
pool = (
await LiquidityPool.by_address(address_or_pool)
if isinstance(address_or_pool, str)
else address_or_pool
)
tvl = await LiquidityPool.tvl([pool])
await response.send_message(
await PoolStats().render(pool, tvl), suppress_embeds=True
)


@bot.tree.command(name="pool", description="Get data for specific pool")
@discord.app_commands.describe(
address_or_query="Pool address or search query",
)
async def pool(interaction: discord.Interaction, address_or_query: str):
if is_address(address_or_query):
pool = await LiquidityPool.by_address(address_or_query)

if pool is not None:
await on_select_pool(interaction.response, pool)
else:
await interaction.response.send_message(
f"No pool found with this address: {address_or_query}"
)
return

pools = await LiquidityPool.search(address_or_query)

await interaction.response.send_message(
"Choose a pool:", view=PoolsDropdown(pools=pools, callback=on_select_pool)
)
Loading