nomad-xyz / nomad-monorepo

Contracts, off-chain agents, and libraries for Nomad
https://nomad.xyz
77 stars 16 forks source link

dApp: JS Number rounding in bridged amount can lead to failing transactions #221

Open mhluongo opened 2 years ago

mhluongo commented 2 years ago

Trying to bridge DAI from Ethereum mainnet to EVMOS after bridging USDT and USDC successfully. After the approval tx, the actual bridging send call errored due to not having enough DAI balance.

Of course, I did have enough DAI balance — I used the "max" button on the bridge form. Unfortunately, my DAI balance had a full 18 decimals, and the amount in the tx request the dApp build had rounded those up.

Transaction failed [ See: https://links.ethers.org/v5-errors-CALL_EXCEPTION ] (transactionHash="0x22b1f56416996e2fcdece1e7ea67b875e8d175fb9b090ef4a318cd05cdd2d933", transaction={"hash":"0x22b1f56416996e2fcdece1e7ea67b875e8d175fb9b090ef4a318cd05cdd2d933","type":2,"accessList":null,"blockHash":null,"blockNumber":null,"transactionIndex":null,"confirmations":0,"from":"0x9eEf87f4C08d8934cB2a3309dF4deC5635338115","gasPrice":{"type":"BigNumber","hex":"0x0dec7ee5a0"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0x0dec7ee5a0"},"gasLimit":{"type":"BigNumber","hex":"0x055730"},"to":"0x88A69B4E698A4B090DF6CF5Bd7B2D47325Ad30A3","value":{"type":"BigNumber","hex":"0x00"},"nonce":825,"data":"0xa9bd12260000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000253dd8c5eeb10fb30000000000000000000000000000000000000000000000000000000000065766d730000000000000000000000009eef87f4c08d8934cb2a3309df4dec56353381150000000000000000000000000000000000000000000000000000000000000000","r":"0xf7c281918bbcd76c790913de16c389b564788b61f53e6b322aa515f6abe64fd2","s":"0x3a955f9c52f5243b5d8d97fa0bd49ada981499dc3449ed7215297bea5748fb7d","v":0,"creates":null,"chainId":0}, receipt={"to":"0x88A69B4E698A4B090DF6CF5Bd7B2D47325Ad30A3","from":"0x9eEf87f4C08d8934cB2a3309dF4deC5635338115","contractAddress":null,"transactionIndex":148,"gasUsed":{"type":"BigNumber","hex":"0xd694"},"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","blockHash":"0x20b2d1e0e3e438f33653d098087f2392a75060600121169299fc35300ab2dca9","transactionHash":"0x22b1f56416996e2fcdece1e7ea67b875e8d175fb9b090ef4a318cd05cdd2d933","logs":[],"blockNumber":14721184,"confirmations":2,"cumulativeGasUsed":{"type":"BigNumber","hex":"0xccbccc"},"effectiveGasPrice":{"type":"BigNumber","hex":"0x0b2c2746f0"},"status":0,"type":2,"byzantium":true}, code=CALL_EXCEPTION, version=providers/5.6.4)

I'd suggest the value of the input in the bridge dApp never be kept as a number, instead keeping it as a string, then either a BigNumber or bigint, depending on what the dApp uses internally/