Cw 537 integrate thor chain swaps (#1280)

* thorChain btc to eth swap

* eth to btc swap

* update the UI

* update localization

* Update thorchain_exchange.provider.dart

* minor fixes

* minor fix

* fix min amount bug

* revert amount_converter changes

* fetching thorChain traid info

* resolve evm related merge conflicts

* minor fix

* Fix eth transaction hash for Thorchain Integration

* add new status endpoint and refund address for eth

* Adjust affiliate fee

* Fix conflicts with main

* review comments + transaction filter item

* taproot addresses check

* added 10 outputs check

* Update thorchain_exchange.provider.dart

* minor fixes

* update thorchain title

* fix fetching rate for thorchain

* Revert "fix fetching rate for thorchain"

This reverts commit 3aa1386ecf.

* fix thorchain exchange rate

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Serhii 2024-03-28 14:41:11 +02:00 committed by GitHub
parent b9e803f3bd
commit cdf081edfd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
55 changed files with 534 additions and 102 deletions

View file

@ -14,6 +14,7 @@ import 'package:flutter/services.dart';
import 'package:http/http.dart';
import 'package:erc20/erc20.dart';
import 'package:web3dart/web3dart.dart';
import 'package:hex/hex.dart' as hex;
abstract class EVMChainClient {
final httpClient = Client();
@ -85,6 +86,7 @@ abstract class EVMChainClient {
required CryptoCurrency currency,
required int exponent,
String? contractAddress,
String? data,
}) async {
assert(currency == CryptoCurrency.eth ||
currency == CryptoCurrency.maticpoly ||
@ -100,6 +102,7 @@ abstract class EVMChainClient {
to: EthereumAddress.fromHex(toAddress),
maxPriorityFeePerGas: EtherAmount.fromInt(EtherUnit.gwei, priority.tip),
amount: isEVMCompatibleChain ? EtherAmount.inWei(BigInt.parse(amount)) : EtherAmount.zero(),
data: data != null ? hexToBytes(data) : null,
);
final signedTransaction =
@ -140,12 +143,14 @@ abstract class EVMChainClient {
required EthereumAddress to,
required EtherAmount amount,
EtherAmount? maxPriorityFeePerGas,
Uint8List? data,
}) {
return Transaction(
from: from,
to: to,
maxPriorityFeePerGas: maxPriorityFeePerGas,
value: amount,
data: data,
);
}
@ -222,6 +227,10 @@ abstract class EVMChainClient {
}
}
Uint8List hexToBytes(String hexString) {
return Uint8List.fromList(hex.HEX.decode(hexString.startsWith('0x') ? hexString.substring(2) : hexString));
}
void stop() {
_client?.dispose();
}

View file

@ -224,6 +224,13 @@ abstract class EVMChainWalletBase
final outputs = _credentials.outputs;
final hasMultiDestination = outputs.length > 1;
final String? opReturnMemo = outputs.first.memo;
String? hexOpReturnMemo;
if (opReturnMemo != null) {
hexOpReturnMemo = '0x${opReturnMemo.codeUnits.map((char) => char.toRadixString(16).padLeft(2, '0')).join()}';
}
final CryptoCurrency transactionCurrency =
balance.keys.firstWhere((element) => element.title == _credentials.currency.title);
@ -279,6 +286,7 @@ abstract class EVMChainWalletBase
exponent: exponent,
contractAddress:
transactionCurrency is Erc20Token ? transactionCurrency.contractAddress : null,
data: hexOpReturnMemo,
);
return pendingEVMChainTransaction;

View file

@ -3,6 +3,7 @@ import 'dart:typed_data';
import 'package:cw_core/pending_transaction.dart';
import 'package:web3dart/crypto.dart';
import 'package:hex/hex.dart' as Hex;
class PendingEVMChainTransaction with PendingTransaction {
final Function sendTransaction;
@ -38,5 +39,12 @@ class PendingEVMChainTransaction with PendingTransaction {
String get hex => bytesToHex(signedTransaction, include0x: true);
@override
String get id => '';
String get id {
final String eip1559Hex = '0x02${hex.substring(2)}';
final Uint8List bytes = Uint8List.fromList(Hex.HEX.decode(eip1559Hex.substring(2)));
var txid = keccak256(bytes);
return '0x${Hex.HEX.encode(txid)}';
}
}