Gmx v2 - Funding rates (#6)
* Setup GMX v2 * Add get markets * Map token with service * Add get market info data * Add get markets * Add get market token prices * Get markets infos multicall * Try call datastore * Add some tests to figure out why datastore call dont work * Update funding rates * clean
This commit is contained in:
121
src/Managing.Infrastructure.Tests/GmxServiceV2Tests.cs
Normal file
121
src/Managing.Infrastructure.Tests/GmxServiceV2Tests.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using Managing.Common;
|
||||
using Managing.Infrastructure.Evm.Models.Gmx.v2;
|
||||
using Managing.Infrastructure.Evm.Services;
|
||||
using Managing.Infrastructure.Evm.Services.Gmx;
|
||||
using Nethereum.Web3;
|
||||
using Xunit;
|
||||
|
||||
namespace Managing.Infrastructure.Tests;
|
||||
|
||||
public class GmxV2ServiceTests
|
||||
{
|
||||
private readonly GmxV2Service _service;
|
||||
private readonly Web3 _web3;
|
||||
|
||||
public GmxV2ServiceTests()
|
||||
{
|
||||
var defaultChain = ChainService.GetArbitrum();
|
||||
_web3 = new Web3(defaultChain.RpcUrl);
|
||||
_service = new GmxV2Service();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Multiple_Markets_With_MultiCall()
|
||||
{
|
||||
// Act
|
||||
var result = await _service.GetMarketsAsync(_web3);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotEmpty(result);
|
||||
Assert.All(result, r =>
|
||||
{
|
||||
Assert.NotNull(r.MarketToken);
|
||||
Assert.NotNull(r.IndexToken);
|
||||
Assert.NotNull(r.LongToken);
|
||||
Assert.NotNull(r.ShortToken);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Multiple_Markets()
|
||||
{
|
||||
var result = await _service.GetMarkets(_web3);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Multiple_MarketsInfos_With_Multicall()
|
||||
{
|
||||
// Act
|
||||
var result = await _service.GetMarketInfosAsync(_web3);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
Assert.NotEmpty(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Single_MarketInfos()
|
||||
{
|
||||
var result = await _service.GetMarketInfo(_web3);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Single_FundingRate()
|
||||
{
|
||||
var result = await _service.GetFundingRate(_web3);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Market_Token_Price()
|
||||
{
|
||||
var result = await _service.GetMarketTokenPrice(_web3);
|
||||
var resultMaximized = await _service.GetMarketTokenPrice(_web3, false);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.NotNull(resultMaximized);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_IsMarket_Disabled()
|
||||
{
|
||||
var result = await _service.GetIsMarketDisabled(_web3);
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_Long_Interest_Amount()
|
||||
{
|
||||
var result = await _service.GetLongInterestAmount(_web3);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Get_FundigRates()
|
||||
{
|
||||
var result = await _service.GetFundingRates(_web3);
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Helpers_Should_Validate_Exact_Same_Address()
|
||||
{
|
||||
var address = "0x47904963Fc8b2340414262125aF798B9655E58Cd";
|
||||
var address2 = "0x47904963fc8b2340414262125aF798B9655E58Cd";
|
||||
|
||||
Assert.True(GmxV2Helpers.SameAddress(address, address2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Return_Correct_Long_Key()
|
||||
{
|
||||
var expectedKey = "0xaaf79028722fd65633cdf994a4a10b0bd349761062506c4bb6a0489956ba5d3f";
|
||||
var keys = GmxKeysService.GetMarketKeys(Constants.GMX.Markets.BTCUSDC);
|
||||
|
||||
Assert.NotNull(keys);
|
||||
Assert.Equal(expectedKey, keys.LongInterestUsingLongToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user