feat(exchange): add cbBTC, BNB and USDT-on-BSC to Chainflip (#3840)
What changed, and why it matters
This commit adds support for three new cryptocurrencies (cbBTC, BNB, and USDT-on-BSC) to the Chainflip exchange provider in Cake Wallet. It also fixes a numeric conversion bug where very large token amounts could be calculated incorrectly or even overflow, which could have caused swap quotes or trades to use the wrong amount. There is no direct evidence in the commit of an active security vulnerability being exploited.
Review AmountConverter.toBaseUnits for correct rounding/truncation behavior and decimal validation; verify that new asset tickers match Chainflip API exactly; consider adding unit tests for large 18-decimal amount conversion and for all reverse currency mappings.
Security signals we found
Integer overflow/precision loss in amount conversion replaced with arbitrary-precision decimal conversion
Missing asset mapping (usdt.sol) restored, preventing null-currency handling
New asset support expands provider surface area
Evidence from the diff
The patch extends ChainflipExchangeProvider._supported and _toCurrency mappings for cbbtc.eth, bnb.bsc, and usdt.bsc, and restores the missing usdt.sol -> usdtSol mapping. The main functional change is replacing a double-to-int conversion (amount * 10^decimals).toInt() with AmountConverter.toBaseUnits operating on a decimal string. The old approach could lose precision for 18-decimal assets and, on Dart VM/int platforms where int is 64-bit, overflow at >2^63-1 (e.g., 10 USDT-BSC = 1e19). The commit also adds cbbtc to CryptoCurrency.all so it serializes/deserializes and appears in UI pickers.
Changed components
lib/exchange/provider/chainflip_exchange_provider.dartcw_core/lib/crypto_currency.dartInspect captured patch +20 / −4
### cw_core/lib/crypto_currency.dart
@@ -123,6 +123,7 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
CryptoCurrency.storj,
CryptoCurrency.tusd,
CryptoCurrency.wbtc,
+ CryptoCurrency.cbbtc,
CryptoCurrency.weth,
CryptoCurrency.zrx,
CryptoCurrency.dydx,
### lib/exchange/provider/chainflip_exchange_provider.dart
@@ -9,6 +9,7 @@ import 'package:cake_wallet/exchange/provider/exchange_provider.dart';
import 'package:cake_wallet/exchange/trade.dart';
import 'package:cake_wallet/exchange/trade_request.dart';
import 'package:cake_wallet/exchange/trade_state.dart';
+import 'package:cw_core/amount_converter.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_core/utils/proxy_wrapper.dart';
@@ -32,6 +33,9 @@ class ChainflipExchangeProvider extends ExchangeProvider {
CryptoCurrency.usdtArb,
CryptoCurrency.trx,
CryptoCurrency.usdttrc20,
+ CryptoCurrency.cbbtc,
+ CryptoCurrency.bnb,
+ CryptoCurrency.usdtbsc,
];
static const _baseURL = 'chainflip-broker.io';
@@ -112,7 +116,7 @@ class ChainflipExchangeProvider extends ExchangeProvider {
'apiKey': _affiliateKey,
'sourceAsset': _normalizeCurrency(from),
'destinationAsset': _normalizeCurrency(to),
- 'amount': _amountToNative(amount, from),
+ 'amount': _amountToNative(_amountString(amount, from), from),
'commissionBps': _affiliateBps
};
@@ -172,7 +176,7 @@ class ChainflipExchangeProvider extends ExchangeProvider {
'apiKey': _affiliateKey,
'sourceAsset': _normalizeCurrency(request.fromCurrency),
'destinationAsset': _normalizeCurrency(request.toCurrency),
- 'amount': _amountToNative(double.parse(request.fromAmount), request.fromCurrency),
+ 'amount': _amountToNative(request.fromAmount, request.fromCurrency),
'commissionBps': _affiliateBps
};
@@ -351,21 +355,32 @@ class ChainflipExchangeProvider extends ExchangeProvider {
'usdt.eth' => CryptoCurrency.usdterc20,
'flip.eth' => CryptoCurrency.flip,
'wbtc.eth' => CryptoCurrency.wbtc,
+ 'cbbtc.eth' => CryptoCurrency.cbbtc,
'sol.sol' => CryptoCurrency.sol,
'usdc.sol' => CryptoCurrency.usdcsol,
+ 'usdt.sol' => CryptoCurrency.usdtSol,
'eth.arb' => CryptoCurrency.arbEth,
'usdc.arb' => CryptoCurrency.usdcArb,
'usdt.arb' => CryptoCurrency.usdtArb,
'trx.tron' => CryptoCurrency.trx,
'usdt.tron' => CryptoCurrency.usdttrc20,
+ 'bnb.bsc' => CryptoCurrency.bnb,
+ 'usdt.bsc' => CryptoCurrency.usdtbsc,
_ => null
};
return currency;
}
- String _amountToNative(double amount, CryptoCurrency currency) =>
- (amount * pow(10, currency.decimals)).toInt().toString();
+ String _amountToNative(String amount, CryptoCurrency currency) =>
+ AmountConverter.toBaseUnits(amount, currency.decimals);
+
+ String _amountString(double amount, CryptoCurrency currency) {
+ final text = amount.toString();
+ return text.contains('e') || text.contains('E')
+ ? amount.toStringAsFixed(currency.decimals)
+ : text;
+ }
double _amountFromNative(String amount, CryptoCurrency currency) =>
double.parse(amount) / pow(10, currency.decimals);Why this scored 34/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.