Swap tokens
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Managing.Infrastructure.Evm.Models.Proxy;
|
||||
|
||||
/// <summary>
|
||||
/// Response model for GMX swap operations
|
||||
/// </summary>
|
||||
public class GmxSwapResponse : Web3ProxyBaseResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Transaction hash if successful
|
||||
/// </summary>
|
||||
[JsonProperty("hash")]
|
||||
[JsonPropertyName("hash")]
|
||||
public string Hash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Success message
|
||||
/// </summary>
|
||||
[JsonProperty("message")]
|
||||
[JsonPropertyName("message")]
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Error type if failed
|
||||
/// </summary>
|
||||
[JsonProperty("errorType")]
|
||||
[JsonPropertyName("errorType")]
|
||||
public string ErrorType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Suggestion for error resolution
|
||||
/// </summary>
|
||||
[JsonProperty("suggestion")]
|
||||
[JsonPropertyName("suggestion")]
|
||||
public string Suggestion { get; set; }
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user