I have a smart contract that accepts user funds and adds them to an AAVE lending pool (DAI for example). Something like this:

lendingPool.deposit(stableCoinAddress, amount, address(this), 0);

As you can see, smart contract receives minted aTokens. The above code can be called by many users with different deposit amounts at different times.
Later on, somewhere else in the same contract, users can redeem their funds at any arbitrary time with any amount up to their original deposit:

lendingPool.withdraw(stableCoinAddress, amount + interest, userAddress);

I need to calculate and add each user's interest in AAVE pool and add it to the original deposited value, but it sounds kind of complicated. Can anybody give me a hint? (or better than that, a usable piece of code!)

1 Answer 1


I solved this problem by creating a new child smart contract and deploying a new instance (with a new address) for each user upon his first access to the parent contract:

contract userWallet is IERC20 { ... }

then in the parent contract:

_userWallet[_msgSender()] = address(new userWallet(...));

Your Answer

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

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