Enable Eth/Erc20 auto send in exchange (#1024)

* Generate missing secrets file for ethereum

* Enable Sending ERC-20 and Ethereum automatically from an Exchange
This commit is contained in:
Omar Hatem 2023-08-08 04:02:09 +03:00 committed by GitHub
parent d1684f5be8
commit 8185b88b4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 12 deletions

View file

@ -156,15 +156,19 @@ abstract class EthereumWalletBase
final _credentials = credentials as EthereumTransactionCredentials;
final outputs = _credentials.outputs;
final hasMultiDestination = outputs.length > 1;
final _erc20Balance = balance[_credentials.currency]!;
final CryptoCurrency transactionCurrency =
balance.keys.firstWhere((element) => element.title == _credentials.currency.title);
final _erc20Balance = balance[transactionCurrency]!;
BigInt totalAmount = BigInt.zero;
int exponent =
_credentials.currency is Erc20Token ? (_credentials.currency as Erc20Token).decimal : 18;
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
num amountToEthereumMultiplier = pow(10, exponent);
// so far this can not be made with Ethereum as Ethereum does not support multiple recipients
if (hasMultiDestination) {
if (outputs.any((item) => item.sendAll || (item.formattedCryptoAmount ?? 0) <= 0)) {
throw EthereumTransactionCreationException(_credentials.currency);
throw EthereumTransactionCreationException(transactionCurrency);
}
final totalOriginalAmount = EthereumFormatter.parseEthereumAmountToDouble(
@ -172,7 +176,7 @@ abstract class EthereumWalletBase
totalAmount = BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
if (_erc20Balance.balance < totalAmount) {
throw EthereumTransactionCreationException(_credentials.currency);
throw EthereumTransactionCreationException(transactionCurrency);
}
} else {
final output = outputs.first;
@ -185,7 +189,7 @@ abstract class EthereumWalletBase
: BigInt.from(totalOriginalAmount * amountToEthereumMultiplier);
if (_erc20Balance.balance < totalAmount) {
throw EthereumTransactionCreationException(_credentials.currency);
throw EthereumTransactionCreationException(transactionCurrency);
}
}
@ -195,11 +199,10 @@ abstract class EthereumWalletBase
amount: totalAmount.toString(),
gas: _estimatedGas!,
priority: _credentials.priority!,
currency: _credentials.currency,
currency: transactionCurrency,
exponent: exponent,
contractAddress: _credentials.currency is Erc20Token
? (_credentials.currency as Erc20Token).contractAddress
: null,
contractAddress:
transactionCurrency is Erc20Token ? transactionCurrency.contractAddress : null,
);
return pendingEthereumTransaction;