-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
10 changed files
with
2,354 additions
and
220 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,10 @@ | ||
import { Bot } from 'grammy'; | ||
import strategies from '../config'; | ||
|
||
export const viewStrategiesCallback = (bot: Bot) => { | ||
bot.callbackQuery('view_strategies', async (ctx) => { | ||
const strategyList = strategies.strategies.map(s => `${s.id}. ${s.name}`).join('\n'); | ||
await ctx.reply(`Available strategies:\n${strategyList}\n\nTo invest, use /invest <strategy_id> <amount>`); | ||
await ctx.answerCallbackQuery(); | ||
}); | ||
}; |
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,19 @@ | ||
import { fetchNeko } from '@/helpers/utils'; | ||
import { ethers } from 'ethers'; | ||
import { Bot } from 'grammy'; | ||
|
||
export const viewStrategiesCallback = (bot: Bot) => { | ||
bot.callbackQuery('generate_wallet', async (ctx) => { | ||
await ctx.reply("You already have a connected wallet."); | ||
|
||
// Generate a new wallet | ||
const wallet = ethers.Wallet.createRandom(); | ||
|
||
const imageUrl = await fetchNeko(); | ||
|
||
await ctx.reply(imageUrl) | ||
await ctx.reply(`New wallet generated for you!\nAddress: ${wallet.address}\n\nIMPORTANT: Please store this recovery phrase safely and never share it:\n${wallet.mnemonic?.phrase}`); | ||
await ctx.reply("Your wallet is now connected and ready to use."); | ||
await ctx.answerCallbackQuery(); | ||
}); | ||
}; |
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,10 @@ | ||
import { Bot } from 'grammy'; | ||
import strategies from '../config'; | ||
|
||
export const viewStrategiesCallback = (bot: Bot) => { | ||
bot.callbackQuery('view_strategies', async (ctx) => { | ||
const strategyList = strategies.strategies.map(s => `${s.id}. ${s.name}`).join('\n'); | ||
await ctx.reply(`Available strategies:\n${strategyList}\n\nTo invest, use /invest <strategy_id> <amount>`); | ||
await ctx.answerCallbackQuery(); | ||
}); | ||
}; |
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 @@ | ||
import { Bot } from 'grammy'; | ||
|
||
export const helpCommand = (bot: Bot) => { | ||
bot.command('help', (ctx) => { | ||
ctx.reply(` | ||
Available commands: | ||
/menu - Show main menu | ||
/help - Show this help message | ||
Use the menu buttons to: | ||
- Connect your wallet | ||
- Check your balance | ||
- View available strategies | ||
- Check your investment performance | ||
`); | ||
}); | ||
}; |
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,44 @@ | ||
import { Bot } from 'grammy'; | ||
import { ethers } from 'ethers'; | ||
import strategies from '../config'; | ||
|
||
|
||
export const investCommand = (bot: Bot) => { | ||
bot.command('invest', async (ctx) => { | ||
if (!ctx.message || !ctx.message.text) { | ||
return ctx.reply("Invalid command format."); | ||
} | ||
|
||
const parts = ctx.message.text.split(' '); | ||
if (parts.length !== 3) { | ||
return ctx.reply("Invalid format. Use: /invest <strategy_id> <amount>"); | ||
} | ||
|
||
const strategyId = Number(parts[1]); | ||
const amount = Number(parts[2]); | ||
|
||
if (isNaN(strategyId) || isNaN(amount)) { | ||
return ctx.reply("Invalid strategy ID or amount."); | ||
} | ||
|
||
const strategy = strategies.strategies.find((s: { id: number; }) => s.id === strategyId); | ||
if (!strategy) { | ||
return ctx.reply("Invalid strategy ID."); | ||
} | ||
|
||
ctx.reply(`Simulating investment of ${amount} USDC in strategy: ${strategy.name}`); | ||
const provider = new ethers.JsonRpcProvider(process.env.ETHEREUM_RPC_URL); | ||
const wallet = new ethers.Wallet("ctx.session.walletPrivateKey", provider); | ||
|
||
try { | ||
const tx = await wallet.sendTransaction({ | ||
to: "strategyAddress", | ||
value: ethers.parseUnits(amount.toString(), 'usdc'), // Assuming amount is in USDC | ||
}); | ||
await ctx.reply(`Investment successful! Transaction hash: ${tx.hash}`); | ||
} catch (error) { | ||
console.error('Investment error:', error); | ||
await ctx.reply('An error occurred while processing your investment.'); | ||
} | ||
}); | ||
}; |
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,18 @@ | ||
import { Bot, InlineKeyboard } from "grammy"; | ||
|
||
export const menuCommand = (bot: Bot) => { | ||
bot.command('menu', (ctx) => { | ||
const mainMenu = new InlineKeyboard() | ||
.text('Connect Wallet', 'connect_wallet') | ||
.row() | ||
.text('Check Balance', 'check_balance') | ||
.row() | ||
.text('View Strategies', 'view_strategies') | ||
.row() | ||
.text('Performance', 'performance'); | ||
|
||
ctx.reply('Welcome! Please choose an option:', { | ||
reply_markup: mainMenu | ||
}); | ||
}); | ||
}; |
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.