LCOV - code coverage report
Current view: top level - crypto/evm/entities/abi/erc - erc20_contract.dart (source / functions) Coverage Total Hit
Test: lcov.info Lines: 55.7 % 61 34
Test Date: 2025-01-30 01:10:00 Functions: - 0 0

            Line data    Source code
       1              : import 'dart:typed_data';
       2              : import 'package:walletkit_dart/src/crypto/evm/entities/block_number.dart';
       3              : import 'package:walletkit_dart/walletkit_dart.dart';
       4              : 
       5            6 : final contractAbiErc20 = ContractABI.fromAbi('''[
       6              :   {
       7              :     "constant": true,
       8              :     "inputs": [],
       9              :     "name": "name",
      10              :     "outputs": [
      11              :       {
      12              :         "name": "",
      13              :         "type": "string"
      14              :       }
      15              :     ],
      16              :     "payable": false,
      17              :     "stateMutability": "view",
      18              :     "type": "function"
      19              :   },
      20              :   {
      21              :     "constant": false,
      22              :     "inputs": [
      23              :       {
      24              :         "name": "_spender",
      25              :         "type": "address"
      26              :       },
      27              :       {
      28              :         "name": "_value",
      29              :         "type": "uint256"
      30              :       }
      31              :     ],
      32              :     "name": "approve",
      33              :     "outputs": [
      34              :       {
      35              :         "name": "",
      36              :         "type": "bool"
      37              :       }
      38              :     ],
      39              :     "payable": false,
      40              :     "stateMutability": "nonpayable",
      41              :     "type": "function"
      42              :   },
      43              :   {
      44              :     "constant": true,
      45              :     "inputs": [],
      46              :     "name": "totalSupply",
      47              :     "outputs": [
      48              :       {
      49              :         "name": "",
      50              :         "type": "uint256"
      51              :       }
      52              :     ],
      53              :     "payable": false,
      54              :     "stateMutability": "view",
      55              :     "type": "function"
      56              :   },
      57              :   {
      58              :     "constant": false,
      59              :     "inputs": [
      60              :       {
      61              :         "name": "_from",
      62              :         "type": "address"
      63              :       },
      64              :       {
      65              :         "name": "_to",
      66              :         "type": "address"
      67              :       },
      68              :       {
      69              :         "name": "_value",
      70              :         "type": "uint256"
      71              :       }
      72              :     ],
      73              :     "name": "transferFrom",
      74              :     "outputs": [
      75              :       {
      76              :         "name": "",
      77              :         "type": "bool"
      78              :       }
      79              :     ],
      80              :     "payable": false,
      81              :     "stateMutability": "nonpayable",
      82              :     "type": "function"
      83              :   },
      84              :   {
      85              :     "constant": true,
      86              :     "inputs": [],
      87              :     "name": "decimals",
      88              :     "outputs": [
      89              :       {
      90              :         "name": "",
      91              :         "type": "uint8"
      92              :       }
      93              :     ],
      94              :     "payable": false,
      95              :     "stateMutability": "view",
      96              :     "type": "function"
      97              :   },
      98              :   {
      99              :     "constant": true,
     100              :     "inputs": [
     101              :       {
     102              :         "name": "_owner",
     103              :         "type": "address"
     104              :       }
     105              :     ],
     106              :     "name": "balanceOf",
     107              :     "outputs": [
     108              :       {
     109              :         "name": "balance",
     110              :         "type": "uint256"
     111              :       }
     112              :     ],
     113              :     "payable": false,
     114              :     "stateMutability": "view",
     115              :     "type": "function"
     116              :   },
     117              :   {
     118              :     "constant": true,
     119              :     "inputs": [],
     120              :     "name": "symbol",
     121              :     "outputs": [
     122              :       {
     123              :         "name": "",
     124              :         "type": "string"
     125              :       }
     126              :     ],
     127              :     "payable": false,
     128              :     "stateMutability": "view",
     129              :     "type": "function"
     130              :   },
     131              :   {
     132              :     "constant": false,
     133              :     "inputs": [
     134              :       {
     135              :         "name": "_to",
     136              :         "type": "address"
     137              :       },
     138              :       {
     139              :         "name": "_value",
     140              :         "type": "uint256"
     141              :       }
     142              :     ],
     143              :     "name": "transfer",
     144              :     "outputs": [
     145              :       {
     146              :         "name": "",
     147              :         "type": "bool"
     148              :       }
     149              :     ],
     150              :     "payable": false,
     151              :     "stateMutability": "nonpayable",
     152              :     "type": "function"
     153              :   },
     154              :   {
     155              :     "constant": true,
     156              :     "inputs": [
     157              :       {
     158              :         "name": "_owner",
     159              :         "type": "address"
     160              :       },
     161              :       {
     162              :         "name": "_spender",
     163              :         "type": "address"
     164              :       }
     165              :     ],
     166              :     "name": "allowance",
     167              :     "outputs": [
     168              :       {
     169              :         "name": "",
     170              :         "type": "uint256"
     171              :       }
     172              :     ],
     173              :     "payable": false,
     174              :     "stateMutability": "view",
     175              :     "type": "function"
     176              :   },
     177              :   {
     178              :     "payable": true,
     179              :     "stateMutability": "payable",
     180              :     "type": "fallback"
     181              :   },
     182              :   {
     183              :     "anonymous": false,
     184              :     "inputs": [
     185              :       {
     186              :         "indexed": true,
     187              :         "name": "owner",
     188              :         "type": "address"
     189              :       },
     190              :       {
     191              :         "indexed": true,
     192              :         "name": "spender",
     193              :         "type": "address"
     194              :       },
     195              :       {
     196              :         "indexed": false,
     197              :         "name": "value",
     198              :         "type": "uint256"
     199              :       }
     200              :     ],
     201              :     "name": "Approval",
     202              :     "type": "event"
     203              :   },
     204              :   {
     205              :     "anonymous": false,
     206              :     "inputs": [
     207              :       {
     208              :         "indexed": true,
     209              :         "name": "from",
     210              :         "type": "address"
     211              :       },
     212              :       {
     213              :         "indexed": true,
     214              :         "name": "to",
     215              :         "type": "address"
     216              :       },
     217              :       {
     218              :         "indexed": false,
     219              :         "name": "value",
     220              :         "type": "uint256"
     221              :       }
     222              :     ],
     223              :     "name": "Transfer",
     224              :     "type": "event"
     225              :   }
     226              : ]
     227              :  ''');
     228              : 
     229              : class ERC20Contract extends InternalContract {
     230            2 :   ERC20Contract({
     231              :     required super.contractAddress,
     232              :     required super.rpc,
     233            2 :   }) : super(
     234            2 :           abi: contractAbiErc20,
     235              :         );
     236              : 
     237            0 :   Future<String> transfer({
     238              :     required String sender,
     239              :     required String to,
     240              :     required BigInt value,
     241              :     required Uint8List seed,
     242              :     EvmFeeInformation? feeInfo,
     243              :     List<AccessListItem>? accessList,
     244              :   }) async {
     245            0 :     final function = abi.functions[7];
     246            0 :     assert(function.functionSelectorHex == "a9059cbb");
     247            0 :     return await interact(
     248            0 :       function: function.addValues(values: [to, value]),
     249              :       seed: seed,
     250              :       sender: sender,
     251              :       feeInfo: feeInfo,
     252              :       accessList: accessList,
     253              :     );
     254              :   }
     255              : 
     256            0 :   Future<String> approve({
     257              :     required String sender,
     258              :     required String spender,
     259              :     required BigInt value,
     260              :     required Uint8List seed,
     261              :     EvmFeeInformation? feeInfo,
     262              :   }) async {
     263            0 :     final function = abi.functions[1];
     264            0 :     assert(function.functionSelectorHex == "095ea7b3");
     265              : 
     266            0 :     return await interact(
     267            0 :       function: function.addValues(values: [spender, value]),
     268              :       seed: seed,
     269              :       sender: sender,
     270              :       feeInfo: feeInfo,
     271              :     );
     272              :   }
     273              : 
     274            0 :   Future<RawEvmTransaction> approveTx({
     275              :     required String sender,
     276              :     required String spender,
     277              :     required BigInt value,
     278              :     EvmFeeInformation? feeInfo,
     279              :   }) async {
     280            0 :     final function = abi.functions[1];
     281            0 :     assert(function.functionSelectorHex == "095ea7b3");
     282              : 
     283            0 :     return await buildTransactionForFunction(
     284            0 :       function: function.addValues(values: [spender, value]),
     285              :       sender: sender,
     286              :       feeInfo: feeInfo,
     287              :     );
     288              :   }
     289              : 
     290            1 :   Future<BigInt> getBalance(String address, {BlockNum? atBlock}) async {
     291            3 :     final function = abi.functions[5];
     292            3 :     assert(function.functionSelectorHex == "70a08231");
     293              : 
     294            1 :     final response = await readSafe(
     295            2 :       function: function.addValues(values: [address]),
     296              :       atBlock: atBlock,
     297              :     );
     298            3 :     return response.outputs.first.castValue<BigInt>();
     299              :   }
     300              : 
     301            1 :   Future<String> getName() async {
     302            3 :     final function = abi.functions[0];
     303            3 :     assert(function.functionSelectorHex == "06fdde03");
     304              : 
     305            1 :     final response = await readSafe(
     306            2 :       function: function.addValues(values: []),
     307              :     );
     308              : 
     309            3 :     return response.outputs.first.castValue<String>();
     310              :   }
     311              : 
     312            1 :   Future<String> getSymbol() async {
     313            3 :     final function = abi.functions[6];
     314            3 :     assert(function.functionSelectorHex == "95d89b41");
     315            1 :     final response = await readSafe(
     316            2 :       function: function.addValues(values: []),
     317              :     );
     318              : 
     319            3 :     return response.outputs.first.castValue<String>();
     320              :   }
     321              : 
     322            1 :   Future<BigInt> getSupply() async {
     323            3 :     final function = abi.functions[2];
     324            3 :     assert(function.functionSelectorHex == "18160ddd");
     325            1 :     final response = await readSafe(
     326            2 :       function: function.addValues(values: []),
     327              :     );
     328            3 :     return response.outputs.first.castValue<BigInt>();
     329              :   }
     330              : 
     331            1 :   Future<int> getDecimals() async {
     332            3 :     final function = abi.functions[4];
     333            3 :     assert(function.functionSelectorHex == "313ce567");
     334            1 :     final response = await readSafe(
     335            2 :       function: function.addValues(values: []),
     336              :     );
     337            4 :     return response.outputs.first.castValue<BigInt>().toInt();
     338              :   }
     339              : 
     340            0 :   Future<BigInt> balanceOf({required String address}) async {
     341            0 :     final function = abi.functions[5];
     342            0 :     assert(function.functionSelectorHex == "70a08231");
     343            0 :     final response = await readSafe(
     344            0 :       function: function.addValues(values: []),
     345              :     );
     346            0 :     return response.outputs.first.castValue<BigInt>();
     347              :   }
     348              : 
     349            0 :   Future<BigInt> allowance({
     350              :     required String owner,
     351              :     required String spender,
     352              :   }) async {
     353            0 :     final function = abi.functions[8];
     354            0 :     assert(function.functionSelectorHex == "dd62ed3e");
     355            0 :     final response = await readSafe(
     356            0 :       function: function.addValues(values: [owner, spender]),
     357              :     );
     358            0 :     return response.outputs.first.castValue<BigInt>();
     359              :   }
     360              : }
        

Generated by: LCOV version 2.0-1