* Move PrivateKeys.cs * Update gitignore * Update gitignore * updt * Extract GmxServiceTests.cs * Refact * update todo * Update code * Fix hashdata * Replace static token hashed datas * Set allowance * Add get orders * Add get orders tests * Add ignore * add close orders * revert * Add get gas limit * Start increasePosition. Todo: Finish GetExecutionFee and estimateGas * little refact * Update gitignore * Fix namespaces and clean repo * Add tests samples * Add execution fee * Add increase position * Handle backtest on the frontend * Add tests * Update increase * Test increase * fix increase * Fix size * Start get position * Update get positions * Fix get position * Update rpc and trade mappers * Finish close position * Fix leverage
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
using System.Numerics;
|
|
using Managing.Common;
|
|
using Managing.Infrastructure.Evm.Services.Gmx;
|
|
using Xunit;
|
|
|
|
namespace Managing.Infrastructure.Tests;
|
|
|
|
public class GmxHelpersTests
|
|
{
|
|
[Fact]
|
|
public void Should_return_correct_usd_formatting_for_sizeDelta()
|
|
{
|
|
// Arrange
|
|
var sizeDelta = BigInteger.Parse("19970983955394369245200000000000");
|
|
|
|
// Act
|
|
var result = GmxHelpers.FormatAmount(sizeDelta, 30, 2);
|
|
|
|
// Assert
|
|
Assert.Equal(19.97m, result);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("2200000000000000", Enums.Ticker.ETH, 2200)]
|
|
[InlineData("500000000000000000000000000", Enums.Ticker.BTC, 50000)]
|
|
[InlineData("759434500000000000000000000", Enums.Ticker.BTC, 75943.45)]
|
|
[InlineData("100000000000000000000000", Enums.Ticker.SOL, 100)]
|
|
public void Should_return_correct_usd_formatting_for_triggerPrice(string triggerPriceString, Enums.Ticker ticker,
|
|
decimal expected)
|
|
{
|
|
// Arrange
|
|
var triggerPrice = BigInteger.Parse(triggerPriceString);
|
|
var indexToken = TokenV2Service.TOKENS.First(t => t.Symbol == ticker.ToString());
|
|
|
|
// Act
|
|
var result = GmxV2Helpers.ParseContractPrice(triggerPrice, indexToken.Decimals, true);
|
|
|
|
// Assert
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(50200, "502000000000000000000000000")]
|
|
public void Should_correctly_parse_value_to_contract_price(decimal triggerPrice, string expected)
|
|
{
|
|
var indexToken = TokenV2Service.TOKENS.First(t => t.Symbol == Enums.Ticker.BTC.ToString());
|
|
var triggerPriceValue = GmxV2Helpers.ConvertToContractPrice(triggerPrice, indexToken.Decimals, true);
|
|
var expectedPrice = BigInteger.Parse(expected);
|
|
|
|
Assert.IsType<BigInteger>(triggerPriceValue);
|
|
Assert.Equal(expectedPrice, triggerPriceValue);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("10000000", 10)]
|
|
public void Should_return_correct_usd_formatting_for_collateralDeltaAmount(string priceString, decimal expected)
|
|
{
|
|
// Arrange
|
|
var price = BigInteger.Parse(priceString);
|
|
var shortToken = TokenV2Service.TOKENS.First(t => t.Symbol == "USDC");
|
|
|
|
// Act
|
|
var result = GmxV2Helpers.ParseContractPrice(price, shortToken.Decimals, false);
|
|
|
|
// Assert
|
|
Assert.Equal(expected, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void Helpers_Should_Validate_Exact_Same_Address()
|
|
{
|
|
var address = "0x47904963Fc8b2340414262125aF798B9655E58Cd";
|
|
var address2 = "0x47904963fc8b2340414262125aF798B9655E58Cd";
|
|
|
|
Assert.True(GmxV2Helpers.SameAddress(address, address2));
|
|
}
|
|
} |