mangrove.js
mangrove.js copied to clipboard
Improve API errors for tx that will revert (instead of UNPREDICTABLE_GAS_LIMIT)
Context
If a transaction is going to revert for some reason one will typically get errors of the following kind:
await onchainLP.newAsk({volume:1000, price: 1.002})
Uncaught:
Error: cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"cannot estimate gas; transaction may fail or may require manual gas limit","code":"UNPREDICTABLE_GAS_LIMIT","error": ...
Buried deep inside the error, the actual revert message is given, e.g. something like:
"execution reverted: MultiOwner/debitOnMgv/insufficient\"
Proposed solution
It would be great if the API could intercept these errors, determine the revert reason, and propagate a more telling error. This will be use useful both for developer but probably also for the UI.
A solution could be something along the following lines:
- Define a set of Mangrove errors, in particular error codes for all revert reasons in Mangrove++ contracts
- Create a wrapper that can be used around the sending of tx's inside of mangrove.js
- we might want to expose the wrapper as well
- The wrapper should contain a try-catch where the catch tries to decipher the error message and map it to something more telling
- The mapping should be extensible as people might want to add/modify the error mappings