Fix key conditions
This commit is contained in:
@@ -21,7 +21,8 @@ namespace Managing.Application.ManageBot
|
|||||||
private readonly IEvmManager _evmManager;
|
private readonly IEvmManager _evmManager;
|
||||||
|
|
||||||
public StartCopyTradingCommandHandler(
|
public StartCopyTradingCommandHandler(
|
||||||
IAccountService accountService, IGrainFactory grainFactory, IBotService botService, IKaigenService kaigenService, IEvmManager evmManager)
|
IAccountService accountService, IGrainFactory grainFactory, IBotService botService,
|
||||||
|
IKaigenService kaigenService, IEvmManager evmManager)
|
||||||
{
|
{
|
||||||
_accountService = accountService;
|
_accountService = accountService;
|
||||||
_grainFactory = grainFactory;
|
_grainFactory = grainFactory;
|
||||||
@@ -50,11 +51,13 @@ namespace Managing.Application.ManageBot
|
|||||||
if (string.Equals(request.MasterBotIdentifier.ToString(), "Kudai", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(request.MasterBotIdentifier.ToString(), "Kudai", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
await ValidateKudaiStakingRequirements(request.User);
|
await ValidateKudaiStakingRequirements(request.User);
|
||||||
}else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// Verify the user owns the keys of the master strategy
|
// Verify the user owns the keys of the master strategy
|
||||||
var ownedKeys = await _kaigenService.GetOwnedKeysAsync(request.User);
|
var ownedKeys = await _kaigenService.GetOwnedKeysAsync(request.User);
|
||||||
var hasMasterStrategyKey = ownedKeys.Items.Any(key =>
|
var hasMasterStrategyKey = ownedKeys.Items.Any(key =>
|
||||||
string.Equals(key.AgentName, request.MasterBotIdentifier.ToString(), StringComparison.OrdinalIgnoreCase) &&
|
string.Equals(key.AgentName, masterBot.User.AgentName, StringComparison.OrdinalIgnoreCase) &&
|
||||||
key.Owned >= 1);
|
key.Owned >= 1);
|
||||||
|
|
||||||
if (!hasMasterStrategyKey)
|
if (!hasMasterStrategyKey)
|
||||||
@@ -69,11 +72,13 @@ namespace Managing.Application.ManageBot
|
|||||||
var masterConfig = await _botService.GetBotConfig(request.MasterBotIdentifier);
|
var masterConfig = await _botService.GetBotConfig(request.MasterBotIdentifier);
|
||||||
if (masterConfig == null)
|
if (masterConfig == null)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Could not retrieve configuration for master bot {request.MasterBotIdentifier}");
|
throw new InvalidOperationException(
|
||||||
|
$"Could not retrieve configuration for master bot {request.MasterBotIdentifier}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user already has a bot on this ticker (same as master bot)
|
// Check if user already has a bot on this ticker (same as master bot)
|
||||||
var hasExistingBotOnTicker = await _botService.HasUserBotOnTickerAsync(request.User.Id, masterConfig.Ticker);
|
var hasExistingBotOnTicker =
|
||||||
|
await _botService.HasUserBotOnTickerAsync(request.User.Id, masterConfig.Ticker);
|
||||||
if (hasExistingBotOnTicker)
|
if (hasExistingBotOnTicker)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
@@ -88,6 +93,7 @@ namespace Managing.Application.ManageBot
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException($"User '{request.User.Name}' has no accounts configured.");
|
throw new InvalidOperationException($"User '{request.User.Name}' has no accounts configured.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Account account = firstAccount;
|
Account account = firstAccount;
|
||||||
|
|
||||||
// Check balances for EVM/GMX V2 accounts before starting
|
// Check balances for EVM/GMX V2 accounts before starting
|
||||||
@@ -164,7 +170,8 @@ namespace Managing.Application.ManageBot
|
|||||||
// Start the copy trading bot immediately
|
// Start the copy trading bot immediately
|
||||||
await botGrain.StartAsync();
|
await botGrain.StartAsync();
|
||||||
|
|
||||||
return $"Copy trading bot started successfully, following master bot '{masterConfig.Name}' with {request.BotTradingBalance:F2} USDC balance";
|
return
|
||||||
|
$"Copy trading bot started successfully, following master bot '{masterConfig.Name}' with {request.BotTradingBalance:F2} USDC balance";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user