I'm having issues with setting up a truffle test to transfer aTokens (aDAI) to my contract. I'm using Aave v2 and running ganache with a fork from mainnnet.

This is what I did so far:

1- Started a mainnet fork w/ the following command, to unlock an account w/ enough DAI and aDAI tokens. ganache-cli -f https://mainnet.infura.io/v3/{YOUR_INFURA_KEY} -m "bla bla bla bla bla bla bla" -i 999 --unlock {UNLOCKED_ACCOUNT}

Grabbed aToken ABI from here: https://github.com/aave/aave-protocol/blob/master/abi/AToken.json

Then, setup an initialization method for my unit tests to transfer some aDai token to my contract:

// loads the aDai token from the Mainnet address
let interestBearingToken = new web3.eth.Contract(aTokenABI, '0x028171bCA77440897B824Ca71D1c56caC55b68A3');

// Check unlocked account balance to make sure it has enough tokens to transfer. I removed the console.log, but I unlocked an account w/ thousands of aDAI.
const aDaiUnlockedBalance = await interestBearingToken.methods.balanceOf(unlockedDaiAccount).call({ from: admin });

// This method fails with: "Returned error: VM Exception while processing transaction: revert"
await interestBearingToken.methods.transfer(MyContractAddress, 10).send({ from: unlockedDaiAccount });

The transfer method fails with : Returned error: VM Exception while processing transaction: revert

At first, I thought that maybe the funds were locked at Aave (due to being used for collateral), so I decided to check if the transfer was allowed, using the following read call:

interestBearingToken.methods.isTransferAllowed(unlockedDaiAccount, daiAmount).call({ from: admin });

This method also fails with Returned error: VM Exception while processing transaction: revert

I thought it could be due to something related to the Proxy used by aTokens, so instead of using the entire aToken ABI as shown above, I decided to use web3.eth.call just to check if the transfer would be allowed, by doing the following:

    let abi =   {
                    "constant": true,
                    "inputs": [
                        "internalType": "address",
                        "name": "_user",
                        "type": "address"
                        "internalType": "uint256",
                        "name": "_amount",
                        "type": "uint256"
                    "name": "isTransferAllowed",
                    "outputs": [
                        "internalType": "bool",
                        "name": "",
                        "type": "bool"
                    "payable": false,
                    "stateMutability": "view",
                    "type": "function"

                let functionData = web3.eth.abi.encodeFunctionCall(abi, [unlockedDaiAccount, daiAmount]);
                let allowed = await web3.eth.call({
                    from: admin,
                    to: '0x028171bCA77440897B824Ca71D1c56caC55b68A3',
                    data: functionData

However, this attempt also reverts with the same error: Returned error: VM Exception while processing transaction: revert

PS: If I use the same steps but instead of aDAI ABI and address (from Aave) I use DAI's ABI and address, everything works.

Local environment:

Truffle v5.1.56 (core: 5.1.56)
Solidity - 0.6.11 (solc-js)
Node v10.23.1
Web3.js v1.2.9

Any ideas of what may be the issue with the above? Any help is appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.