GMX v2 - Trading (#7)

* 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
This commit is contained in:
Oda
2025-01-30 23:06:22 +07:00
committed by GitHub
parent ecaa89c67b
commit 65bdb8e34f
156 changed files with 11253 additions and 4073 deletions

View File

@@ -0,0 +1,54 @@
using System.Numerics;
using Managing.Core;
using Nethereum.Contracts.Standards.ERC20;
using Nethereum.Contracts.Standards.ERC20.ContractDefinition;
using Nethereum.Hex.HexTypes;
using Nethereum.Util;
using Nethereum.Web3;
namespace Managing.Infrastructure.Evm;
public static class EvmBase
{
public static async Task<bool> ApproveToken(Web3 web3, string publicAddress, string contractAddress, string spender,
BigInteger amount = default)
{
var input = new ApproveFunction
{
Spender = spender,
Value = UnitConversion.Convert.ToWei(amount),
FromAddress = publicAddress
};
var txHandler = web3.Eth
.GetContractTransactionHandler<ApproveFunction>();
var result = await txHandler.SendRequestAndWaitForReceiptAsync(contractAddress, input);
return result.Status == new HexBigInteger(1);
}
public static async Task<BigInteger> GetAllowance(Web3 web3, string publicAddress, string contractAddress)
{
var input = new AllowanceFunction
{
Owner = publicAddress,
Spender = contractAddress
};
var contract = new ERC20ContractService(web3.Eth, contractAddress);
var allowance = await contract.AllowanceQueryAsync(input);
return allowance;
}
public static async Task<DateTime> GetBlockDate(Web3 web3, HexBigInteger blockNumber)
{
var block = await web3.Eth.Blocks.GetBlockWithTransactionsByNumber.SendRequestAsync(blockNumber);
var date = DateHelpers.GetFromUnixTimestamp((int)block.Timestamp.Value);
return date;
}
public static async Task<BigInteger> GetGasPrice(Web3 web3)
{
var gasPrice = await web3.Eth.GasPrice.SendRequestAsync();
return gasPrice.Value;
}
}