Skip to content

Commit

Permalink
Merge pull request #1 from lwYeo/WebAPI
Browse files Browse the repository at this point in the history
Web API
  • Loading branch information
lwYeo authored Aug 9, 2021
2 parents 21d0002 + ca03dd0 commit 9874bb0
Show file tree
Hide file tree
Showing 30 changed files with 1,373 additions and 599 deletions.
23 changes: 19 additions & 4 deletions Crypto LP Compounder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,35 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crypto LP Compounder", "Crypto LP Compounder\Crypto LP Compounder.csproj", "{70E1FCDF-C7E8-4A0C-8A91-A280EBACEC1E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crypto LP Compounder", "Crypto LP Compounder\Crypto LP Compounder.csproj", "{70E1FCDF-C7E8-4A0C-8A91-A280EBACEC1E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csproj", "{E8B14AE5-1F59-4E9D-A581-E3589DF30C58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{741A5661-803C-4AAE-AFBD-CC07021D1CD9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{70E1FCDF-C7E8-4A0C-8A91-A280EBACEC1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{70E1FCDF-C7E8-4A0C-8A91-A280EBACEC1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70E1FCDF-C7E8-4A0C-8A91-A280EBACEC1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70E1FCDF-C7E8-4A0C-8A91-A280EBACEC1E}.Release|Any CPU.Build.0 = Release|Any CPU
{E8B14AE5-1F59-4E9D-A581-E3589DF30C58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E8B14AE5-1F59-4E9D-A581-E3589DF30C58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E8B14AE5-1F59-4E9D-A581-E3589DF30C58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E8B14AE5-1F59-4E9D-A581-E3589DF30C58}.Release|Any CPU.Build.0 = Release|Any CPU
{741A5661-803C-4AAE-AFBD-CC07021D1CD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{741A5661-803C-4AAE-AFBD-CC07021D1CD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{741A5661-803C-4AAE-AFBD-CC07021D1CD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{741A5661-803C-4AAE-AFBD-CC07021D1CD9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F7DF41FD-8D6A-4EA2-B436-F6A33B0DEF5B}
EndGlobalSection
EndGlobal
363 changes: 233 additions & 130 deletions Crypto LP Compounder/Compounder.cs

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions Crypto LP Compounder/Contract/ERC20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ namespace Crypto_LP_Compounder.Contract
{
internal class ERC20
{
private readonly Settings _Settings;
private readonly Log _Log;
private readonly Settings.CompounderSettings _Settings;
private readonly Web3 _Web3;
private readonly ContractHandler _ContractHandler;

public string Address { get; }

public ERC20(Settings settings, Web3 web3, string tokenAddress)
public ERC20(Log log, Settings.CompounderSettings settings, Web3 web3, string tokenAddress)
{
_Log = log;
Address = tokenAddress;
_Settings = settings;
_Web3 = web3;
Expand Down Expand Up @@ -109,10 +111,10 @@ public bool HandleApproveSpend(string contract, uint decimals, BigInteger amount
{
approveAmt = amount * 5; // Minimize future unnecessary approvals

Program.WriteLineLog("Approving spend of {0:n10} to {1}...",
(decimal)(UnitConversion.Convert.FromWeiToBigDecimal(approveAmt, UnitConversion.EthUnit.Wei) /
BigDecimal.Pow(10, decimals)),
contract);
_Log.WriteLine(
$"Approving spend of" +
$" {(decimal)(UnitConversion.Convert.FromWeiToBigDecimal(approveAmt, UnitConversion.EthUnit.Wei) / BigDecimal.Pow(10, decimals)):n10}" +
$" to {contract}...");

BigInteger gasPrice = _Settings.GetGasPrice(_Web3);

Expand All @@ -127,30 +129,30 @@ public bool HandleApproveSpend(string contract, uint decimals, BigInteger amount

if (approveResult.Succeeded())
{
Program.WriteLineLog("Success: Approve spend (gas: {0:n10} {1}, txn ID: {2})",
UnitConversion.Convert.FromWei(approveResult.GasUsed * gasPrice, UnitConversion.EthUnit.Ether),
_Settings.GasSymbol,
approveResult.TransactionHash);
_Log.WriteLine(
$"Success: Approve spend" +
$" (gas: {UnitConversion.Convert.FromWei(approveResult.GasUsed * gasPrice, UnitConversion.EthUnit.Ether):n10}" +
$" {_Settings.GasSymbol}, txn ID: {approveResult.TransactionHash})");

return true;
}
else
{
Program.WriteLineLog("Failed: Approve spend, gas: {0:n10} {1}, txn ID: {2}",
UnitConversion.Convert.FromWei(approveResult.GasUsed * gasPrice, UnitConversion.EthUnit.Ether),
_Settings.GasSymbol,
approveResult.TransactionHash);
_Log.WriteLine(
$"Failed: Approve spend," +
$" gas: {UnitConversion.Convert.FromWei(approveResult.GasUsed * gasPrice, UnitConversion.EthUnit.Ether):n10}" +
$" {_Settings.GasSymbol}, txn ID: {approveResult.TransactionHash}");

if (approveResult.HasLogs())
Program.WriteLineLog(approveResult.Logs.ToString());
_Log.WriteLine(approveResult.Logs.ToString());

return false;
}
}
catch (Exception ex)
{
Program.WriteLineLog("Failed: Approve spend rewards");
Program.WriteLineLog(ex.ToString());
_Log.WriteLine("Failed: Approve spend rewards");
_Log.WriteLine(ex.ToString());

return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Crypto LP Compounder/Contract/Farm/MOMA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace Crypto_LP_Compounder.Contract.Farm
{
internal class MOMA : MasterChef
{
public MOMA(Settings settings, Web3 web3, UniswapV2.Router router, ERC20 rewardToken) :
base(settings, web3, router, rewardToken)
public MOMA(Log log, Settings.CompounderSettings settings, Web3 web3, UniswapV2.Router router, ERC20 rewardToken) :
base(log, settings, web3, router, rewardToken)
{
}

Expand Down
Loading

0 comments on commit 9874bb0

Please sign in to comment.