Error Calling frob using own proxy

Hi,

I’ve run into a problem when I tried calling my custom function on my deployed proxy contract. The function is supposed to open, lock ETH, and draw Dai via the Maker contracts.

Instead of directly transfering the ETH from the caller to the Maker Contract, my custom function is supposed to use the balance of the proxy contract (which I’ve paid beforehands).

function openAndLockETH(
address manager,
address jug,
address ethJoin,
address daiJoin,
uint256 wadD
) public payable {
// Opens ETH-A CDP
bytes32 ilk = bytes32(“ETH-A”);
uint256 cdp = open(manager, ilk, address(this));

    address urn = ManagerLike(manager).urns(cdp);
    address vat = ManagerLike(manager).vat();
    // Receives ETH amount, converts it to WETH and joins it into the vat
    ethJoin_join(ethJoin, urn);
    // Locks WETH amount into the CDP and generates debt
    frob(
        manager,
        cdp,
        toInt(address(this).balance),
        _getDrawDart(vat, jug, urn, ilk, wadD)
    );

I can see that the code breaks on the frob call. The only thing I changed is its parameter from “msg.value” to “address(this).balance”. The error only says “revert: VM error”.

I checked that my contract actually has the sufficient balance and that my proxy worked (if I changed the parameter back, and call the function with fund).

Can someone help me with this? Thanks!

There is where the ETH gets converted to WETH and then joined to the system. In this case if your msg.value is 0, you are basically adding 0 collateral, then frob fails as you do not have collateral in the system.
If you just have ETH or WETH in the proxy address it will not work. The WETH needs to be added to the system via the collateral adapter.
So basically you also need to change this function for taking the ETH or WETH from your proxy address.

1 Like

Thanks for the response!

I’ve changed the ethjoin_join function call to take the proxy’s balance:

ethJoin_join(ethJoin, urn, address(this).balance);

and inside the function as well:

function ethJoin_join(
address apt,
address urn,
uint256 amount
) public {
// Wraps ETH in WETH
GemJoinLike(apt).gem().deposit.value(amount)();
// Approves adapter to take the WETH amount
GemJoinLike(apt).gem().approve(address(apt), amount);
// Joins WETH collateral into the vat
GemJoinLike(apt).join(urn, amount);
}

However, I’m still getting the same error from the frob function call.