2023-10-20 08:14:56 +00:00
|
|
|
|
using CodexContractsPlugin;
|
|
|
|
|
using Core;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using GethPlugin;
|
|
|
|
|
|
2023-10-22 08:38:46 +00:00
|
|
|
|
namespace BiblioTech.Commands
|
2023-10-20 08:14:56 +00:00
|
|
|
|
{
|
|
|
|
|
public class MintCommand : BaseNetCommand
|
|
|
|
|
{
|
|
|
|
|
private readonly string nl = Environment.NewLine;
|
|
|
|
|
private readonly Ether defaultEthToSend = 10.Eth();
|
|
|
|
|
private readonly TestToken defaultTestTokensToMint = 1024.TestTokens();
|
2023-10-22 08:10:52 +00:00
|
|
|
|
private readonly UserOption optionalUser = new UserOption(
|
|
|
|
|
description: "If set, mint tokens for this user. (Optional, admin-only)",
|
|
|
|
|
isRequired: true);
|
2023-10-20 08:14:56 +00:00
|
|
|
|
|
|
|
|
|
public MintCommand(DeploymentsFilesMonitor monitor, CoreInterface ci)
|
|
|
|
|
: base(monitor, ci)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name => "mint";
|
2023-10-20 09:20:38 +00:00
|
|
|
|
public override string StartingMessage => "Minting some tokens...";
|
2023-10-22 08:10:52 +00:00
|
|
|
|
public override string Description => "Mint some TestTokens and send some Eth to the user if their balance is low.";
|
|
|
|
|
public override CommandOption[] Options => new[] { optionalUser };
|
2023-10-20 08:14:56 +00:00
|
|
|
|
|
|
|
|
|
protected override async Task Execute(SocketSlashCommand command, IGethNode gethNode, ICodexContracts contracts)
|
|
|
|
|
{
|
2023-10-22 08:10:52 +00:00
|
|
|
|
var userId = GetUserId(optionalUser, command);
|
|
|
|
|
var addr = Program.UserRepo.GetCurrentAddressForUser(userId);
|
2023-10-20 08:14:56 +00:00
|
|
|
|
if (addr == null) return;
|
|
|
|
|
|
2023-10-20 09:20:38 +00:00
|
|
|
|
var report =
|
2023-10-20 08:14:56 +00:00
|
|
|
|
ProcessEth(gethNode, addr) +
|
|
|
|
|
ProcessTestTokens(gethNode, contracts, addr);
|
|
|
|
|
|
2023-10-20 09:20:38 +00:00
|
|
|
|
await command.FollowupAsync(report);
|
2023-10-20 08:14:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string ProcessTestTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr)
|
|
|
|
|
{
|
|
|
|
|
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
|
|
|
|
|
if (testTokens.Amount < 64m)
|
|
|
|
|
{
|
|
|
|
|
contracts.MintTestTokens(gethNode, addr, defaultTestTokensToMint);
|
|
|
|
|
return $"Minted {defaultTestTokensToMint}." + nl;
|
|
|
|
|
}
|
|
|
|
|
return "TestToken balance over threshold." + nl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string ProcessEth(IGethNode gethNode, EthAddress addr)
|
|
|
|
|
{
|
|
|
|
|
var eth = gethNode.GetEthBalance(addr);
|
|
|
|
|
if (eth.Eth < 1.0m)
|
|
|
|
|
{
|
|
|
|
|
gethNode.SendEth(addr, defaultEthToSend);
|
|
|
|
|
return $"Sent {defaultEthToSend}." + nl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "Eth balance over threshold." + nl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|