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)
|
||||||
{
|
{
|
||||||
@@ -172,20 +179,20 @@ namespace Managing.Application.ManageBot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ValidateKudaiStakingRequirements(User user)
|
private async Task ValidateKudaiStakingRequirements(User user)
|
||||||
{
|
|
||||||
// Use the user's wallet address directly
|
|
||||||
if (string.IsNullOrEmpty(user.OwnerWalletAddress))
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
// Use the user's wallet address directly
|
||||||
"To copy trade the Kudai strategy, you must have a wallet address configured in your profile.");
|
if (string.IsNullOrEmpty(user.OwnerWalletAddress))
|
||||||
}
|
{
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"To copy trade the Kudai strategy, you must have a wallet address configured in your profile.");
|
||||||
|
}
|
||||||
|
|
||||||
// Check KUDAI staked balance
|
// Check KUDAI staked balance
|
||||||
var kudaiStakedBalance = await _evmManager.GetKudaiStakedBalance(user.OwnerWalletAddress);
|
var kudaiStakedBalance = await _evmManager.GetKudaiStakedBalance(user.OwnerWalletAddress);
|
||||||
|
|
||||||
// Check GBC staked NFT count
|
// Check GBC staked NFT count
|
||||||
var gbcStakedCount = await _evmManager.GetGbcStakedCount(user.OwnerWalletAddress);
|
var gbcStakedCount = await _evmManager.GetGbcStakedCount(user.OwnerWalletAddress);
|
||||||
|
|
||||||
// Requirements: 100 million KUDAI OR 10 GBC NFTs
|
// Requirements: 100 million KUDAI OR 10 GBC NFTs
|
||||||
const decimal requiredKudaiAmount = 100_000_000m; // 100 million
|
const decimal requiredKudaiAmount = 100_000_000m; // 100 million
|
||||||
|
|||||||
Reference in New Issue
Block a user