stakeToken method

Future<ISendUserOperationResponse> stakeToken(
  1. StakeRequestBody stakeRequestBody, [
  2. TxOptions? options
])

Stakes tokens based on the provided stakeRequestBody.

This method facilitates token staking by interacting with the staking module. stakeRequestBody contains details about the token staking, such as the token address and amount. options provides additional transaction options.

Implementation

Future<ISendUserOperationResponse> stakeToken(
  StakeRequestBody stakeRequestBody, [
  TxOptions? options,
]) async {
  var DC(:data, :error, :hasError) =
      await _stakingModule.stake(stakeRequestBody);

  if (hasError) {
    throw error!;
  }

  var StakeRequestBody(:tokenAmount, :tokenAddress) = stakeRequestBody;

  var StakeResponseBody(:contractAddress, :encodedABI) = data!;

  var TokenDetails(:decimals) = await ContractsUtils.getERC20TokenDetails(
    wallet.proxy.client,
    EthereumAddress.fromHex(tokenAddress),
  );

  final amount = AmountFormat.toBigInt(tokenAmount, decimals);

  final stakeCallData = hexToBytes(encodedABI);

  final spender = EthereumAddress.fromHex(contractAddress);

  return _processOperation(
    tokenAddress: EthereumAddress.fromHex(tokenAddress),
    spender: spender,
    callData: stakeCallData,
    amount: amount,
    options: options,
  );
}