-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiquidationExecutor.cs
More file actions
45 lines (38 loc) · 1.62 KB
/
Copy pathLiquidationExecutor.cs
File metadata and controls
45 lines (38 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Nethereum.Web3;
using Nethereum.Web3.Accounts;
using Nethereum.Hex.HexTypes;
public class LiquidationExecutor(Web3 web3, string privateKey, string liquidationContract)
{
private static readonly string Abi = @"[
{
'inputs': [
{ 'internalType': 'address','name': 'borrower','type': 'address' },
{ 'internalType': 'address','name': 'debtAsset','type': 'address' },
{ 'internalType': 'address','name': 'collateralAsset','type': 'address' },
{ 'internalType': 'uint256','name': 'debtToCover','type': 'uint256' }
],
'name': 'executeLiquidation',
'outputs': [],
'stateMutability': 'nonpayable',
'type': 'function'
}
]";
public Account Account { get; set; } = new(privateKey);
public async Task TriggerLiquidationAsync(string borrower, string debtAsset, string collateralAsset, decimal debtToCoverHuman, int debtDecimals)
{
var contract = web3.Eth.GetContract(Abi, liquidationContract);
var function = contract.GetFunction("executeLiquidation");
var debtToCoverWei = Web3.Convert.ToWei(debtToCoverHuman, debtDecimals);
var gasEstimate = await function.EstimateGasAsync(
Account, null, null,
borrower, debtAsset, collateralAsset, debtToCoverWei
);
var txHash = await function.SendTransactionAsync(
Account.Address,
new HexBigInteger(gasEstimate),
null, // auto gas price
borrower, debtAsset, collateralAsset, debtToCoverWei
);
Console.WriteLine($"Liquidation Transaction Sent: {txHash}");
}
}