0

I have a question on Aave Credit Delegation. I have gone through the documentation and based on that tried to set it up so that an address that deposits the collateral can delegate the borrowing power to another user. Assuming the below contract is the depositor and has deposited sufficient collateral, here is the code for approving delegation:

(, , address variableDebtTokenAddress) = dataProvider.getReserveTokensAddresses(
    address(_token)
);
IVariableDebtToken(variableDebtTokenAddress).approveDelegation(_to, _amount);

uint256 allowance = IVariableDebtToken(variableDebtTokenAddress).borrowAllowance(address(this), _to);
console.log("variable approved allowance %s", allowance);   // this shows the correct amount delegated

After that I am trying to borrow to the _to address which is the delegatee:

pool.borrow(address(_token), _amount, variableRate, referral, _to);

btw msg.sender will the delegator in the above call.

This results in error 9 which is for zero collateral. Error: VM Exception while processing transaction: reverted with reason string '9'

This suggests that delegation isnt working and the pool is looking for collateral from the _to user even though it should be using the collateral from the delegator. If I change the borrow receipient to address(this) then borrow works fine.

Can someone please suggest what I could be doing wrong or how can I debug this further? Thanks!

1 Answer 1

0

the borrow() function should be called by the delegatee (the person who will receive the loan.

In your case the delegator is the contract (address(this)).

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.