diff --git a/.github/workflows/pr_test_build_android.yml b/.github/workflows/pr_test_build_android.yml
index 3cc67e53a..e9665e179 100644
--- a/.github/workflows/pr_test_build_android.yml
+++ b/.github/workflows/pr_test_build_android.yml
@@ -187,6 +187,8 @@ jobs:
echo "const nanoNowNodesApiKey = '${{ secrets.NANO_NOW_NODES_API_KEY }}';" >> cw_nano/lib/.secrets.g.dart
echo "const tronGridApiKey = '${{ secrets.TRON_GRID_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart
echo "const tronNowNodesApiKey = '${{ secrets.TRON_NOW_NODES_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart
+ echo "const letsExchangeBearerToken = '${{ secrets.LETS_EXCHANGE_TOKEN }}';" >> lib/.secrets.g.dart
+ echo "const letsExchangeAffiliateId = '${{ secrets.LETS_EXCHANGE_AFFILIATE_ID }}';" >> lib/.secrets.g.dart
echo "const stealthExBearerToken = '${{ secrets.STEALTH_EX_BEARER_TOKEN }}';" >> lib/.secrets.g.dart
echo "const stealthExAdditionalFeePercent = '${{ secrets.STEALTH_EX_ADDITIONAL_FEE_PERCENT }}';" >> lib/.secrets.g.dart
diff --git a/.github/workflows/pr_test_build_linux.yml b/.github/workflows/pr_test_build_linux.yml
index f00584345..9632786a5 100644
--- a/.github/workflows/pr_test_build_linux.yml
+++ b/.github/workflows/pr_test_build_linux.yml
@@ -173,6 +173,8 @@ jobs:
echo "const nanoNowNodesApiKey = '${{ secrets.NANO_NOW_NODES_API_KEY }}';" >> cw_nano/lib/.secrets.g.dart
echo "const tronGridApiKey = '${{ secrets.TRON_GRID_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart
echo "const tronNowNodesApiKey = '${{ secrets.TRON_NOW_NODES_API_KEY }}';" >> cw_tron/lib/.secrets.g.dart
+ echo "const letsExchangeBearerToken = '${{ secrets.LETS_EXCHANGE_TOKEN }}';" >> lib/.secrets.g.dart
+ echo "const letsExchangeAffiliateId = '${{ secrets.LETS_EXCHANGE_AFFILIATE_ID }}';" >> lib/.secrets.g.dart
echo "const stealthExBearerToken = '${{ secrets.STEALTH_EX_BEARER_TOKEN }}';" >> lib/.secrets.g.dart
echo "const stealthExAdditionalFeePercent = '${{ secrets.STEALTH_EX_ADDITIONAL_FEE_PERCENT }}';" >> lib/.secrets.g.dart
diff --git a/assets/images/letsexchange_icon.svg b/assets/images/letsexchange_icon.svg
new file mode 100644
index 000000000..104b43a6b
--- /dev/null
+++ b/assets/images/letsexchange_icon.svg
@@ -0,0 +1,5 @@
+
\ No newline at end of file
diff --git a/lib/exchange/exchange_provider_description.dart b/lib/exchange/exchange_provider_description.dart
index a91288024..9f3723356 100644
--- a/lib/exchange/exchange_provider_description.dart
+++ b/lib/exchange/exchange_provider_description.dart
@@ -27,8 +27,10 @@ class ExchangeProviderDescription extends EnumerableItem with Serializable<
ExchangeProviderDescription(title: 'ThorChain', raw: 8, image: 'assets/images/thorchain.png');
static const quantex =
ExchangeProviderDescription(title: 'Quantex', raw: 9, image: 'assets/images/quantex.png');
+ static const letsExchange =
+ ExchangeProviderDescription(title: 'LetsExchange', raw: 10, image: 'assets/images/letsexchange_icon.svg');
static const stealthEx =
- ExchangeProviderDescription(title: 'StealthEx', raw: 10, image: 'assets/images/stealthex.png');
+ ExchangeProviderDescription(title: 'StealthEx', raw: 11, image: 'assets/images/stealthex.png');
static ExchangeProviderDescription deserialize({required int raw}) {
switch (raw) {
@@ -53,6 +55,8 @@ class ExchangeProviderDescription extends EnumerableItem with Serializable<
case 9:
return quantex;
case 10:
+ return letsExchange;
+ case 11:
return stealthEx;
default:
throw Exception('Unexpected token: $raw for ExchangeProviderDescription deserialize');
diff --git a/lib/exchange/provider/letsexchange_exchange_provider.dart b/lib/exchange/provider/letsexchange_exchange_provider.dart
new file mode 100644
index 000000000..a11e69796
--- /dev/null
+++ b/lib/exchange/provider/letsexchange_exchange_provider.dart
@@ -0,0 +1,292 @@
+import 'dart:convert';
+import 'dart:developer';
+
+import 'package:cake_wallet/.secrets.g.dart' as secrets;
+import 'package:cake_wallet/exchange/provider/exchange_provider.dart';
+import 'package:cake_wallet/exchange/exchange_provider_description.dart';
+import 'package:cake_wallet/exchange/limits.dart';
+import 'package:cake_wallet/exchange/trade.dart';
+import 'package:cake_wallet/exchange/trade_not_created_exception.dart';
+import 'package:cake_wallet/exchange/trade_request.dart';
+import 'package:cake_wallet/exchange/trade_state.dart';
+import 'package:cake_wallet/exchange/utils/currency_pairs_utils.dart';
+import 'package:cw_core/crypto_currency.dart';
+import 'package:http/http.dart' as http;
+
+class LetsExchangeExchangeProvider extends ExchangeProvider {
+ LetsExchangeExchangeProvider() : super(pairList: supportedPairs(_notSupported));
+
+ static const List _notSupported = [];
+
+ static const apiKey = secrets.letsExchangeBearerToken;
+ static const _baseUrl = 'api.letsexchange.io';
+ static const _infoPath = '/api/v1/info';
+ static const _infoRevertPath = '/api/v1/info-revert';
+ static const _createTransactionPath = '/api/v1/transaction';
+ static const _createTransactionRevertPath = '/api/v1/transaction-revert';
+ static const _getTransactionPath = '/api/v1/transaction';
+
+ static const _affiliateId = secrets.letsExchangeAffiliateId;
+
+ @override
+ String get title => 'LetsExchange';
+
+ @override
+ bool get isAvailable => true;
+
+ @override
+ bool get isEnabled => true;
+
+ @override
+ bool get supportsFixedRate => true;
+
+ @override
+ ExchangeProviderDescription get description => ExchangeProviderDescription.letsExchange;
+
+ @override
+ Future checkIsAvailable() async => true;
+
+ @override
+ Future fetchLimits(
+ {required CryptoCurrency from,
+ required CryptoCurrency to,
+ required bool isFixedRateMode}) async {
+ final networkFrom = _getNetworkType(from);
+ final networkTo = _getNetworkType(to);
+
+ try {
+ final params = {
+ 'from': from.title,
+ 'to': to.title,
+ if (networkFrom != null) 'network_from': networkFrom,
+ if (networkTo != null) 'network_to': networkTo,
+ 'amount': '1',
+ 'affiliate_id': _affiliateId
+ };
+
+ final responseJSON = await _getInfo(params, isFixedRateMode);
+ final min = double.tryParse(responseJSON['min_amount'] as String);
+ final max = double.tryParse(responseJSON['max_amount'] as String);
+ return Limits(min: min, max: max);
+ } catch (e) {
+ log(e.toString());
+ throw Exception('Failed to fetch limits');
+ }
+ }
+
+ @override
+ Future fetchRate(
+ {required CryptoCurrency from,
+ required CryptoCurrency to,
+ required double amount,
+ required bool isFixedRateMode,
+ required bool isReceiveAmount}) async {
+ final networkFrom = _getNetworkType(from);
+ final networkTo = _getNetworkType(to);
+ try {
+ final params = {
+ 'from': from.title,
+ 'to': to.title,
+ if (networkFrom != null) 'network_from': networkFrom,
+ if (networkTo != null) 'network_to': networkTo,
+ 'amount': amount.toString(),
+ 'affiliate_id': _affiliateId
+ };
+
+ final responseJSON = await _getInfo(params, isFixedRateMode);
+
+ final amountToGet = double.tryParse(responseJSON['amount'] as String) ?? 0.0;
+
+ return isFixedRateMode ? amount / amountToGet : amountToGet / amount;
+ } catch (e) {
+ log(e.toString());
+ return 0.0;
+ }
+ }
+
+ @override
+ Future createTrade(
+ {required TradeRequest request,
+ required bool isFixedRateMode,
+ required bool isSendAll}) async {
+ final networkFrom = _getNetworkType(request.fromCurrency);
+ final networkTo = _getNetworkType(request.toCurrency);
+ try {
+ final params = {
+ 'from': request.fromCurrency.title,
+ 'to': request.toCurrency.title,
+ if (networkFrom != null) 'network_from': networkFrom,
+ if (networkTo != null) 'network_to': networkTo,
+ 'amount': isFixedRateMode ? request.toAmount.toString() : request.fromAmount.toString(),
+ 'affiliate_id': _affiliateId
+ };
+
+ final responseInfoJSON = await _getInfo(params, isFixedRateMode);
+ final rateId = responseInfoJSON['rate_id'] as String;
+
+ final withdrawalAddress = _normalizeBchAddress(request.toAddress);
+ final returnAddress = _normalizeBchAddress(request.refundAddress);
+
+ final tradeParams = {
+ 'coin_from': request.fromCurrency.title,
+ 'coin_to': request.toCurrency.title,
+ if (!isFixedRateMode) 'deposit_amount': request.fromAmount.toString(),
+ 'withdrawal': withdrawalAddress,
+ if (isFixedRateMode) 'withdrawal_amount': request.toAmount.toString(),
+ 'withdrawal_extra_id': '',
+ 'return': returnAddress,
+ 'rate_id': rateId,
+ if (networkFrom != null) 'network_from': networkFrom,
+ if (networkTo != null) 'network_to': networkTo,
+ 'affiliate_id': _affiliateId
+ };
+
+ final headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ 'Authorization': apiKey
+ };
+
+ final uri = Uri.https(_baseUrl,
+ isFixedRateMode ? _createTransactionRevertPath : _createTransactionPath, tradeParams);
+ final response = await http.post(uri, headers: headers);
+
+ if (response.statusCode != 200) {
+ throw Exception('LetsExchange create trade failed: ${response.body}');
+ }
+ final responseJSON = json.decode(response.body) as Map;
+ final id = responseJSON['transaction_id'] as String;
+ final from = responseJSON['coin_from'] as String;
+ final to = responseJSON['coin_to'] as String;
+ final payoutAddress = responseJSON['withdrawal'] as String;
+ final depositAddress = responseJSON['deposit'] as String;
+ final refundAddress = responseJSON['return'] as String;
+ final depositAmount = responseJSON['deposit_amount'] as String;
+ final receiveAmount = responseJSON['withdrawal_amount'] as String;
+ final status = responseJSON['status'] as String;
+ final createdAtString = responseJSON['created_at'] as String;
+ final expiredAtTimestamp = responseJSON['expired_at'] as int;
+
+ final createdAt = DateTime.parse(createdAtString);
+ final expiredAt = DateTime.fromMillisecondsSinceEpoch(expiredAtTimestamp * 1000);
+
+ CryptoCurrency fromCurrency;
+ if (request.fromCurrency.tag != null && request.fromCurrency.title == from) {
+ fromCurrency = request.fromCurrency;
+ } else {
+ fromCurrency = CryptoCurrency.fromString(from);
+ }
+
+ CryptoCurrency toCurrency;
+ if (request.toCurrency.tag != null && request.toCurrency.title == to) {
+ toCurrency = request.toCurrency;
+ } else {
+ toCurrency = CryptoCurrency.fromString(to);
+ }
+
+ return Trade(
+ id: id,
+ from: fromCurrency,
+ to: toCurrency,
+ provider: description,
+ inputAddress: depositAddress,
+ payoutAddress: payoutAddress,
+ refundAddress: refundAddress,
+ amount: depositAmount,
+ receiveAmount: receiveAmount,
+ state: TradeState.deserialize(raw: status),
+ createdAt: createdAt,
+ expiredAt: expiredAt,
+ );
+ } catch (e) {
+ log(e.toString());
+ throw TradeNotCreatedException(description);
+ }
+ }
+
+ @override
+ Future findTradeById({required String id}) async {
+ final headers = {
+ 'Content-Type': 'application/json',
+ 'Accept': 'application/json',
+ 'Authorization': apiKey
+ };
+
+ final url = Uri.https(_baseUrl, '$_getTransactionPath/$id');
+ final response = await http.get(url, headers: headers);
+
+ if (response.statusCode != 200) {
+ throw Exception('LetsExchange fetch trade failed: ${response.body}');
+ }
+ final responseJSON = json.decode(response.body) as Map;
+ final from = responseJSON['coin_from'] as String;
+ final to = responseJSON['coin_to'] as String;
+ final payoutAddress = responseJSON['withdrawal'] as String;
+ final depositAddress = responseJSON['deposit'] as String;
+ final refundAddress = responseJSON['return'] as String;
+ final depositAmount = responseJSON['deposit_amount'] as String;
+ final receiveAmount = responseJSON['withdrawal_amount'] as String;
+ final status = responseJSON['status'] as String;
+ final createdAtString = responseJSON['created_at'] as String;
+ final expiredAtTimestamp = responseJSON['expired_at'] as int;
+
+ final createdAt = DateTime.parse(createdAtString);
+ final expiredAt = DateTime.fromMillisecondsSinceEpoch(expiredAtTimestamp * 1000);
+
+ return Trade(
+ id: id,
+ from: CryptoCurrency.fromString(from),
+ to: CryptoCurrency.fromString(to),
+ provider: description,
+ inputAddress: depositAddress,
+ payoutAddress: payoutAddress,
+ refundAddress: refundAddress,
+ amount: depositAmount,
+ receiveAmount: receiveAmount,
+ state: TradeState.deserialize(raw: status),
+ createdAt: createdAt,
+ expiredAt: expiredAt,
+ isRefund: status == 'refund',
+ );
+ }
+
+ Future