I am trying to build a contract that allows user to supply/deposit token to the aavae protocol but i need to make my contract get approval of the token amount to be spent by the contract. I tried using the code bellow which seems fine to me as a beginner but the allowance
//SPDX-License-Identifier:MIT
pragma solidity >=0.8.0 <0.9.0;
interface IWrappedEther{
function deposit() external payable;
function transfer(address dst, uint256 wad) external returns (bool);
function approve(address guy, uint256 wad) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function balanceOf(address _address) external view returns(uint256);
}
contract DeFi{
IWrappedEther wrappedEthereum;
constructor(address _wrappedEthereumContract){
wrappedEthereum = IWrappedEther(_wrappedEthereumContract);
}
bool public isApproved;
function getWrappedEther()public payable{
wrappedEthereum.deposit{value: msg.value}();
wrappedEthereum.transfer(msg.sender, msg.value);
}
function approveToken(address _spender, uint256 _amount) external {
require(wrappedEthereum.approve(_spender, _amount), "Token Spend is not approved");
}
function checkAllowance(address _spender)public view returns(uint256){
return wrappedEthereum.allowance(msg.sender, _spender);
}
function checkBalance()public view returns(uint256){
return wrappedEthereum.balanceOf(msg.sender);
}
}