Migrate to new Chainflip endpoints (#2386)
* feat: migrate to new chainflip endpoints * chore: remove debug comments
David Cumps committed
Jul 16, 2025 at 05:49 UTC
28eb83cc8fd310df19287c83c730a672e0d1060b
1 file changed
+29
-6
lib/exchange/provider/chainflip_exchange_provider.dart
+29
-6
@@ -37,7 +37,7 @@ class ChainflipExchangeProvider extends ExchangeProvider {
37
38
static const _baseURL = 'chainflip-broker.io';
39
static const _assetsPath = '/assets';
40
- static const _quotePath = '/quote-native';
40
+ static const _quotePath = '/quotes-native';
41
static const _swapPath = '/swap';
42
static const _txInfoPath = '/status-by-deposit-channel';
43
static const _affiliateBps = secrets.chainflipAffiliateFee;
@@ -145,6 +145,13 @@ class ChainflipExchangeProvider extends ExchangeProvider {
145
'retryDurationInBlocks': '150'
146
};
147
148
+ if (quoteResponse.containsKey('numberOfChunks') && quoteResponse.containsKey('chunkIntervalBlocks')) {
149
+ swapParams.addAll({
150
+ 'numberOfChunks': quoteResponse['numberOfChunks'].toString(),
151
+ 'chunkIntervalBlocks': quoteResponse['chunkIntervalBlocks'].toString(),
152
+ });
153
+ }
154
+
155
final swapResponse = await _openDepositChannel(swapParams);
156
157
final id = '${swapResponse['issuedBlock']}-${swapResponse['network'].toString().toUpperCase()}-${swapResponse['channelId']}';
@@ -266,9 +273,6 @@ class ChainflipExchangeProvider extends ExchangeProvider {
273
Future<Map<String, dynamic>> _getAssets() async =>
274
_getRequest(_assetsPath, {});
275
269
- Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async =>
270
- _getRequest(_quotePath, params);
271
-
276
Future<Map<String, dynamic>> _openDepositChannel(Map<String, String> params) async =>
277
_getRequest(_swapPath, params);
278
@@ -276,7 +280,6 @@ class ChainflipExchangeProvider extends ExchangeProvider {
280
final uri = Uri.https(_baseURL, path, params);
281
282
final response = await ProxyWrapper().get(clearnetUri: uri);
279
-
283
284
if ((response.statusCode != 200) || (response.body.contains('error'))) {
285
throw Exception('Unexpected response: ${response.statusCode} / ${uri.toString()} / ${response.body}');
@@ -285,11 +288,31 @@ class ChainflipExchangeProvider extends ExchangeProvider {
288
return json.decode(response.body) as Map<String, dynamic>;
289
}
290
291
+ Future<Map<String, dynamic>> _getSwapQuote(Map<String, String> params) async {
292
+ final uri = Uri.https(_baseURL, _quotePath, params);
293
+
294
+ final response = await ProxyWrapper().get(clearnetUri: uri);
295
+
296
+ if ((response.statusCode != 200) || (response.body.contains('error'))) {
297
+ throw Exception('Unexpected response: ${response.statusCode} / ${uri.toString()} / ${response.body}');
298
+ }
299
+
300
+ final quotes = json.decode(response.body) as List<dynamic>;
301
+
302
+ Map<String, dynamic> highestQuote = quotes.reduce((current, next) {
303
+ double currentAmount = current['egressAmount'];
304
+ double nextAmount = next['egressAmount'];
305
+
306
+ return currentAmount > nextAmount ? current : next;
307
+ });
308
+
309
+ return highestQuote;
310
+ }
311
+
312
Future<Map<String, dynamic>?> _getStatus(Map<String, String> params) async {
313
final uri = Uri.https(_baseURL, _txInfoPath, params);
314
315
final response = await ProxyWrapper().get(clearnetUri: uri);
292
-
316
317
if (response.statusCode == 404) return null;
318