I'm attempting to deposit WMATIC on the Polygon chain into AAVEv3, but I'm getting a revert.
I'm running a forked version of Polygon mainnet locally with ganache. I'm using the first account provided by ganache to do my testing.
Here's my script:
const Web3 = require('web3');
const fs = require('fs');
const web3 = new Web3(new Web3.providers.WebsocketProvider('http://127.0.0.1:8545'));
const POOL_ABI = JSON.parse(fs.readFileSync('aavev3/abi/IPool.json'))['abi'];
const PAP_ABI = JSON.parse(fs.readFileSync('aavev3/abi/IPoolAddressesProvider.json'))['abi'];
const WIERC20_ABI = JSON.parse(fs.readFileSync('aavev3/abi/WIERC20.json'));
const WMATIC_ADDR = "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270";
const WETH_ADDR = "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619";
const PAP_ADDR = "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb";
let wmatic_deposit_amount = "800";
let weth_contract = new web3.eth.Contract(WIERC20_ABI, WETH_ADDR);
let wmatic_contract = new web3.eth.Contract(WIERC20_ABI, WMATIC_ADDR);
let pap_contract = new web3.eth.Contract(PAP_ABI, PAP_ADDR);
(async() => {
const deposit_in_wei = web3.utils.toWei(wmatic_deposit_amount);
// Use first account provided by ganache. Should be unlocked.
const user = (await web3.eth.getAccounts())[0];
// Get pool address from pool address provider contract (recommended by aave)
const POOL_ADDR = await pap_contract.methods.getPool().call();
let pool_contract = new web3.eth.Contract(POOL_ABI, POOL_ADDR);
let init_wmatic_balance = web3.utils.fromWei(await wmatic_contract.methods.balanceOf(user).call());
// Quick hack to check if I need to give the account WMATIC
if (init_wmatic_balance < 1) {
await wmatic_contract.methods.deposit().send({from: user, value: deposit_in_wei});
}
await wmatic_contract.methods.approve(POOL_ADDR, deposit_in_wei).send({from: user});
await pool_contract.methods.supply(WMATIC_ADDR, deposit_in_wei, user, 0).send({from: user});
})();
ABIs were taken from the aave repository.
Everything works fine, except the supply call. Here's the error I get:
Error: Transaction has been reverted by the EVM:
{
"transactionHash": "0xe6d12b38de5370c1c568a2872b66d3384cde63e1fa6da9c5553e410e4f7b82bc",
"transactionIndex": 0,
"blockNumber": 28686538,
"blockHash": "0xffb0d1762ac79e0b30f15a37080fa4cbe08f87b082e745df2d3bd6602ee9afc9",
"from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"to": "0x794a61358d6845594f94dc1db02a252b5b4814ad",
"cumulativeGasUsed": 88188,
"gasUsed": 88188,
"contractAddress": null,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"effectiveGasPrice": 2500000011,
"type": "0x2",
"events": {}
}
Package versions:
- node: 18.2.0
- web3: 1.7.3
What is the correct way of supplying assets to AAVEv3 via web3?