[BUG] RPC return cannot estimate gas; error when staking LP
fsy412 opened this issue · 12 comments
Version
- Godwoken v1 mainnet
Describe the bug
We are encountering an issue when staking the large amount of LP,
RPC return below error,
Stake LP error Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT
We use ether.js for interaction with smart contract, below is the code for staking the LP,
async function depositPool(pid, amount) {
const { ethereum } = window
const provider = new ethers.providers.Web3Provider(ethereum)
const signer = provider.getSigner()
const masterGardener = new ethers.Contract(CONFIG.MasterGardener, MasterGardener.abi, signer)
let tx = await masterGardener.deposit(pid, ethers.utils.parseEther(amount.toString()), ethers.constants.AddressZero)
await tx.wait()
}
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Staking is ok with large amount of LP
Screenshots or Logs
If applicable, add screenshots or logs to help explain your problem.
some logs...
Additional context
Add any other context about the problem here.
Can you provide an example of the transaction(without signature)?
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="executio method: 'estimateGas', transaction: { from: '0x46a72053Eb37acced9B442B1e0Ef5dA28D7aA5ee', to: '0x274e13daf1C9795d7B48A637de8910662f0F6af1', data: '0x8dbdbe6d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006c6b935b8bbd4000000000000000000000000000000000000000000000000000000000000000000000', accessList: null },
error: ProviderError: execution reverted: ds-math-sub-underflow
}
error: ProviderError: execution reverted: ds-math-sub-underflow
I searched for ds-math-sub-underflow
and found this link: https://ethereum.stackexchange.com/questions/97032/uniswapv2-addliquidity-revert-ds-math-sub-underflow
Can you confirm that you have enough funds to make the deposit?
I have 2080 lp , the despoit amount is 2000
Could you consider lowering the deposit amount to 1000?
When put 1600 lp to despoit , it's wokring ok
1800 is also ok
I am reviewing the contract code and it appears that you cannot deposit using your maximum
balance. You must reserve a certain value.
How much do you need to pay for gas?
Why maximum balance cannot be deposited?
This issue is reported by the Dapp user.
They will get confused if the maximum balance can not be deposited.
Depend on the user how much they wanna pay for gas
I apologize for my mistake. I mistakenly reviewed the incorrect code. Could you please provide a repository that reproduces the issue, including the contract code? You can make it private and invite me to access it.
Invited you to a repo lp-stake
Here is where the error occurs: https://github.com/YokaiSwap/yokai-swap-core/blob/main/contracts/YokaiERC20.sol#L75
The maximum transfer amount is 10 million as it aligns with the initial allowance.
The newer version of MetaMask forces the user to input the allowance,
We don't call approve every time when user stakes, they always had the initial allowance.
Once they use a value greater than the initial allowance it causes this issue.