I have a smart contract that interfaces with Uniswap factory contract and I am calling addLiquidityETH. The TX is, 0x633838ceccac460b55e6a8e5747ec20f60165080570c26a84082b27cfc7471c5. I can confirm the transaction from Metamask but the transaction obviously fails. It doesn't revert or anything. I have no other clue to what's causing the failed transaction. This is all in Kovan. I am attempting to add into the LP from ETH to DAI LP.
Apr 14, 2021, 4:41 PM
That tx is a failed contract creation tx
Apr 14, 2021, 4:44 PM
Yea I am trying to figure out what the bad instruction is
Apr 14, 2021, 4:44 PM
can you link to the addLiquidityETH function on github?
oic, its not the factory its the router
what are you sending in?
tx payload
Apr 14, 2021, 4:46 PM
yes sorry the router. This is the contract address in Kovan, 0x658fC60483F7de7BBB7F25fA838bF81B2B3Dd35e. The function is on line 99, "appAddLiquidityETH".
from my dapp this is what I am passing:
let convertedAmnt = Web3.utils.toWei(amounttoadd,'ether');
const amountIn = new BigNumber(convertedAmnt);
const deadline = Math.floor(Date.now()/1000) + 60 * 20;
const amountTokenMin = new BigNumber(100000000000000000);
const amountETHMin = new BigNumber(100000000000000000);
const amountIn = new BigNumber(convertedAmnt);
const deadline = Math.floor(Date.now()/1000) + 60 * 20;
const amountTokenMin = new BigNumber(100000000000000000);
const amountETHMin = new BigNumber(100000000000000000);
where "amounttoadd" is equals to "0.01" as a test
I hard coded the rest just for a test run.
These are my param setup and the execution syntax:
const params = [{
gasPrice: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), //'0x09184e72a000', // customizable by user during MetaMask confirmation.
gasLimit: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), // customizable by user during MetaMask confirmation.
from: ethereum.selectedAddress, // must match user's active address.
value: web3.utils.toHex(amountIn), // Only required to send ether to the recipient from the initiating external account.
data: anathalp.methods.appAddLiquidityETH(
DAI,
amountIn,
amountTokenMin,
amountETHMin,
ethereum.selectedAddress,
deadline).encodeABI()
}];
const transactionHash = await provider.send('eth_sendTransaction', params)
console.log('transactionHash is ' + transactionHash);
gasPrice: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), //'0x09184e72a000', // customizable by user during MetaMask confirmation.
gasLimit: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), // customizable by user during MetaMask confirmation.
from: ethereum.selectedAddress, // must match user's active address.
value: web3.utils.toHex(amountIn), // Only required to send ether to the recipient from the initiating external account.
data: anathalp.methods.appAddLiquidityETH(
DAI,
amountIn,
amountTokenMin,
amountETHMin,
ethereum.selectedAddress,
deadline).encodeABI()
}];
const transactionHash = await provider.send('eth_sendTransaction', params)
console.log('transactionHash is ' + transactionHash);
I'm attempting to add ETH to DAI LP. Hopefully I'm doing this right
These are the addresses in Kovan that I am working with:
const DAI = '0xfdf7f21eda1fb8aebed2fc8b0e8f72a8f17cf823'
const USDT = '0xfdf7f21eda1fb8aebed2fc8b0e8f72a8f17cf823'
const ETH = '0x0000000000000000000000000000000000000000'
const UNISWAPROUTER02 = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'
const USDT = '0xfdf7f21eda1fb8aebed2fc8b0e8f72a8f17cf823'
const ETH = '0x0000000000000000000000000000000000000000'
const UNISWAPROUTER02 = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'
the repo is private otherwise I would share the link. thanks for any help. Really appreciate it.
Attempt to add to Liquidity DAI/WETH, this is what Metamask looks like
Apr 14, 2021, 4:54 PM
appAddLiquidityETH
is that your contracts own function?
is that your contracts own function?
Apr 14, 2021, 5:02 PM
yes.
Apr 14, 2021, 5:02 PM
what does that functionlook like in your contract?
Apr 14, 2021, 5:02 PM
In the smart contract address:
function appAddLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity) {
IERC20(token).approve(address(uniswap),amountTokenDesired);
uniswap.addLiquidityETH(token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline);
}
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity) {
IERC20(token).approve(address(uniswap),amountTokenDesired);
uniswap.addLiquidityETH(token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline);
}
it eventually calls "addLiquidityETH" function
The source code of the smart contract is in Kovan. Contract address: 0x658fC60483F7de7BBB7F25fA838bF81B2B3Dd35e
Apr 14, 2021, 5:06 PM
did you approve DAI and WETH
Apr 14, 2021, 5:14 PM
Hi. yes I did. Line 103
I'm sure it's something very simple that I am overlooking
Apr 14, 2021, 5:16 PM
I dont see any returns on that function. Seems like it's expecting three return items
might be the issue?
Apr 14, 2021, 5:19 PM
line 103 of what ?
Apr 14, 2021, 5:22 PM
I have to look at this.
Apr 14, 2021, 5:23 PM
Don't you have to pass the eth too to the addLiquidity func?
Apr 14, 2021, 5:28 PM
I pass the eth amount from my meta mask wallet from the dapp
so from the DApp, this is how I setup the parameters before executing the "provider.send"
const params = [{
gasPrice: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), //'0x09184e72a000', // customizable by user during MetaMask confirmation.
gasLimit: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), // customizable by user during MetaMask confirmation.
from: ethereum.selectedAddress, // must match user's active address.
value: web3.utils.toHex(amountIn), // Only required to send ether to the recipient from the initiating external account.
data: anathalp.methods.appAddLiquidityETH(
DAI,
amountIn,
amountTokenMin,
amountETHMin,
ethereum.selectedAddress,
deadline).encodeABI()
}];
const transactionHash = await provider.send('eth_sendTransaction', params)
console.log('transactionHash is ' + transactionHash);
gasPrice: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), //'0x09184e72a000', // customizable by user during MetaMask confirmation.
gasLimit: (sessionStorage.getItem('gweisafelow')).padEnd(9,0), // customizable by user during MetaMask confirmation.
from: ethereum.selectedAddress, // must match user's active address.
value: web3.utils.toHex(amountIn), // Only required to send ether to the recipient from the initiating external account.
data: anathalp.methods.appAddLiquidityETH(
DAI,
amountIn,
amountTokenMin,
amountETHMin,
ethereum.selectedAddress,
deadline).encodeABI()
}];
const transactionHash = await provider.send('eth_sendTransaction', params)
console.log('transactionHash is ' + transactionHash);
I have to check the approve function if it is returning true.
I don't have that check. following an example to the "t" that I've overlook this.
Apr 14, 2021, 5:31 PM
Yeah I understood. But as of the code, your appAddLiquidity func is receiving the eth right?
Apr 14, 2021, 5:31 PM
the uniswap routers function is payable. You have to pass it there as well
Apr 14, 2021, 5:31 PM
yes I believe so
Apr 14, 2021, 5:31 PM
You have to relay it to addLiquidity on uniswap contract
uniswap.addLiquidityETH{ value: msg.value }( token, amountTokenDesired, amountTokenMin, amountETHMin, msg.sender, deadline );
Something like this
*check for syntax errors😅
Apr 14, 2021, 5:33 PM