Swap tokens

This commit is contained in:
2025-07-06 14:00:44 +07:00
parent 8096db495a
commit c7dec76809
21 changed files with 1124 additions and 173 deletions

View File

@@ -6,6 +6,7 @@ using Managing.Application.Abstractions.Services;
using Managing.Domain.Accounts;
using Managing.Infrastructure.Evm.Models.Proxy;
using Microsoft.Extensions.Options;
using static Managing.Common.Enums;
namespace Managing.Infrastructure.Evm.Services
{
@@ -180,6 +181,38 @@ namespace Managing.Infrastructure.Evm.Services
};
}
public async Task<SwapInfos> SwapGmxTokensAsync(string account, Ticker fromTicker, Ticker toTicker, double amount, string orderType = "market", double? triggerRatio = null, double allowedSlippage = 0.5)
{
var payload = new
{
account,
fromTicker = fromTicker.ToString(),
toTicker = toTicker.ToString(),
amount,
orderType,
triggerRatio,
allowedSlippage
};
var response = await CallGmxServiceAsync<GmxSwapResponse>("/swap-tokens", payload);
if (response == null)
{
throw new Web3ProxyException("GMX swap response is null");
}
// Map from infrastructure model to domain model
return new SwapInfos
{
Success = response.Success,
Hash = response.Hash,
Message = response.Message,
Error = null, // GmxSwapResponse doesn't have Error property
ErrorType = response.ErrorType,
Suggestion = response.Suggestion
};
}
private async Task HandleErrorResponse(HttpResponseMessage response)
{
var statusCode = (int)response.StatusCode;