Price reminder and init approval

* Start price reminder grain

* Add config and init grain at startup

* Save init wallet when already init
This commit is contained in:
Oda
2025-09-13 02:29:14 +07:00
committed by GitHub
parent da50b30344
commit 56b4f14eb3
69 changed files with 2373 additions and 701 deletions

View File

@@ -23,6 +23,7 @@ public class TradingService : ITradingService
private readonly ITradingRepository _tradingRepository;
private readonly IExchangeService _exchangeService;
private readonly IAccountService _accountService;
private readonly IAccountRepository _accountRepository;
private readonly ICacheService _cacheService;
private readonly IMessengerService _messengerService;
private readonly IStatisticRepository _statisticRepository;
@@ -35,6 +36,7 @@ public class TradingService : ITradingService
IExchangeService exchangeService,
ILogger<TradingService> logger,
IAccountService accountService,
IAccountRepository accountRepository,
ICacheService cacheService,
IMessengerService messengerService,
IStatisticRepository statisticRepository,
@@ -45,6 +47,7 @@ public class TradingService : ITradingService
_exchangeService = exchangeService;
_logger = logger;
_accountService = accountService;
_accountRepository = accountRepository;
_cacheService = cacheService;
_messengerService = messengerService;
_statisticRepository = statisticRepository;
@@ -319,7 +322,7 @@ public class TradingService : ITradingService
$"[{shortAddress}][{ticker}] No change - Quantity still {newTrade.Quantity}");
}
}
catch (Exception ex)
catch (Exception)
{
_logger.LogError($"[{shortAddress}][{ticker}] Impossible to fetch trader");
}
@@ -357,7 +360,7 @@ public class TradingService : ITradingService
public List<string> PositionIdentifiers { get; set; }
}
public async Task<PrivyInitAddressResponse> InitPrivyWallet(string publicAddress)
public async Task<PrivyInitAddressResponse> InitPrivyWallet(string publicAddress, TradingExchanges tradingExchange)
{
try
{
@@ -368,7 +371,39 @@ public class TradingService : ITradingService
{ Success = false, Error = "Public address cannot be null or empty" };
}
return await _evmManager.InitAddress(publicAddress);
// Check if the account is already initialized
var account = await _accountRepository.GetAccountByKeyAsync(publicAddress);
if (account != null && account.IsGmxInitialized)
{
_logger.LogInformation("Account with address {PublicAddress} is already initialized for GMX", publicAddress);
return new PrivyInitAddressResponse
{
Success = true,
Address = publicAddress,
IsAlreadyInitialized = true
};
}
PrivyInitAddressResponse initResult;
switch (tradingExchange)
{
case TradingExchanges.GmxV2:
initResult = await _evmManager.InitAddressForGMX(publicAddress);
break;
default:
initResult = await _evmManager.InitAddressForGMX(publicAddress);
break;
}
// If initialization was successful, update the account's initialization status
if (initResult.Success && account != null)
{
account.IsGmxInitialized = true;
await _accountRepository.UpdateAccountAsync(account);
_logger.LogInformation("Updated account {AccountName} GMX initialization status to true", account.Name);
}
return initResult;
}
catch (Exception ex)
{