unstakeToken method

Future<ISendUserOperationResponse> unstakeToken(
  1. UnstakeRequestBody unstakeRequestBody,
  2. EthereumAddress unStakeTokenAddress, [
  3. TxOptions? options
])

Unstakes tokens based on the provided unstakeRequestBody.

This method facilitates token unstaking by interacting with the staking module. unstakeRequestBody contains details about the token unstaking, such as the token address and amount. unStakeTokenAddress is the address of the unstake token contract. options provides additional transaction options.

Implementation

Future<ISendUserOperationResponse> unstakeToken(
  UnstakeRequestBody unstakeRequestBody,
  EthereumAddress unStakeTokenAddress, [
  TxOptions? options,
]) async {
  var DC(:data, :error, :hasError) = await _stakingModule.unstake(
    unstakeRequestBody,
  );

  if (hasError) {
    throw error!;
  }

  var UnstakeRequestBody(:tokenAmount) = unstakeRequestBody;

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

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

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

  final spender = EthereumAddress.fromHex(contractAddress);

  final unstakeCallData = hexToBytes(encodedABI);

  return _processOperation(
    tokenAddress: unStakeTokenAddress,
    spender: spender,
    callData: unstakeCallData,
    amount: amount,
    options: options,
  );
}