Calling _delegate(address implementation) from a smart contract

Hello Guys,

I just want to keep this simple.

There is a function called deposit present in the implementation contract which is controlled by a proxy with _delegate(address implementation) function.

I would like to call that "deposit" function form an other smart contract, which I am unable to do so.

Lets say <contract a> is the main contract (implementation contract) which has got the deposit function.

Then <contract proxy> is the proxy contract which has got the _delegate(address implementation) function using OpenZeppelin Proxies contract upgrades library.

Within a smart contract, I have to call the deposit function present in the <contract a> through <contract proxy>.

Here is the simple code that I am trying to execute through an other contract called <contract b>.

pragma solidity 0.8.10;

interface IERC20 {
    function approve(address, uint256) external returns (bool);
    function transfer(address, uint256) external returns (bool);
    function balanceOf(address) external view returns (uint);
}

interface proxyContract {
  function deposit(uint256 amount) external;
}

contract myDeposit {
    
    address proxyAddress = <contract proxy>;

    function tokenDeposit(address token, uint256 amount) public
    {
        IERC20(token).approve(proxyAddress, amount);
        proxyContract proxyAddress = proxyContract(proxyAddress);
        proxyAddress.deposit(amount);
    }

}

I get this error:

"execution reverted: SafeERC20: low-level call failed"

Waiting for replies.

Thank you.

Regards,
Harish

Ok. So, I understand that I have to call proxy's fallback function. Now, how do I do that from an other smart contract using solidity?

Hi @harishbp, by calling proxyAddress.deposit(amount), it should automatically invoke the proxy's fallback function which delegates the call to the implementation's function (see https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/Proxy.sol). So I don't think that is the source of the problem.

What is the code of your deposit function. It seems to be executing correctly, but failing due to some ERC20 token failure.