From 6137e1328aeb1b700d16d48da317f82f416b5e96 Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 28 Aug 2023 10:15:46 -0700 Subject: [PATCH] Calculate gas for deposit & withdrawal transactions via fee oracle instead of web3 naive methods --- package.json | 2 +- store/application.js | 31 +++++++++++++++---------------- yarn.lock | 8 ++++---- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 32af046..98e2663 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@metamask/onboarding": "^1.0.0", "@nuxtjs/moment": "^1.6.0", "@tornado/snarkjs": "0.1.20-p2", - "@tornado/tornado-oracles": "1.4.0", + "@tornado/tornado-oracles": "^2.0.0", "@tornado/websnark": "0.0.4-p1", "@walletconnect/web3-provider": "1.7.8", "ajv": "^6.10.2", diff --git a/store/application.js b/store/application.js index 8aef8b8..c933018 100644 --- a/store/application.js +++ b/store/application.js @@ -543,16 +543,17 @@ const actions = { } const data = contractInstance.methods.deposit(...params).encodeABI() - const gas = await contractInstance.methods.deposit(...params).estimateGas({ from: ethAccount, value }) + const incompletedTx = { + from: ethAccount, + to: contractInstance._address, + value: numberToHex(value), + data + } + const gasLimit = await rootGetters['fees/oracle'].getGasLimit(incompletedTx, 'other', 10) const callParams = { method: 'eth_sendTransaction', - params: { - to: contractInstance._address, - gas: numberToHex(gas + 50000), - value: numberToHex(value), - data - }, + params: Object.assign({ gasLimit }, incompletedTx), watcherParams: { title: { path: 'depositing', amount, currency }, successTitle: { @@ -775,18 +776,16 @@ const actions = { const params = [instance, proof, ...args] const data = contractInstance.methods.withdraw(...params).encodeABI() - const gas = await contractInstance.methods - .withdraw(...params) - .estimateGas({ from: ethAccount, value: args[5] }) + const incompletedTx = { + data, + value: args[5], + to: contractInstance._address + } + const gasLimit = await rootGetters['fees/oracle'].getGasLimit(incompletedTx, 'user_withdrawal') const callParams = { method: 'eth_sendTransaction', - params: { - data, - value: args[5], - to: contractInstance._address, - gas: numberToHex(gas + 200000) - }, + params: Object.assign({ gasLimit }, incompletedTx), watcherParams: { title: { path: 'withdrawing', amount, currency }, successTitle: { diff --git a/yarn.lock b/yarn.lock index d7e4927..4807a09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2477,10 +2477,10 @@ resolved "https://git.tornado.ws/api/packages/tornado-packages/npm/%40tornado%2Ftornado-config/-/2.0.0/tornado-config-2.0.0.tgz#52bbc179ecb2385f71b4d56e060b68e7dd6fb8b4" integrity sha512-7EkpWNfEm34VEOrbLnPpvd/aUJYnA1L+6/qx2fZ/AfmuJFkjSZ18Z4jvVGNY7ktKIhTu3/Tbze+9l3eNueCNIA== -"@tornado/tornado-oracles@1.4.0": - version "1.4.0" - resolved "https://git.tornado.ws/api/packages/tornado-packages/npm/%40tornado%2Ftornado-oracles/-/1.4.0/tornado-oracles-1.4.0.tgz#78bdb44c538f57abdbecf9deac951d85adc5b74a" - integrity sha512-Qrq0p/AYxUhTs0ZAISumwUhlLRQKoBgAW95P1uMbAGOwKO5z32XS5S17E5CaWzCGZmewVUpx4AxCCSmqY9JNiQ== +"@tornado/tornado-oracles@^2.0.0": + version "2.0.0" + resolved "https://git.tornado.ws/api/packages/tornado-packages/npm/%40tornado%2Ftornado-oracles/-/2.0.0/tornado-oracles-2.0.0.tgz#846761fd65cf5803ead1ad8e69f9d9b57bc1494e" + integrity sha512-dQAJFS3OJPWQ6falfYG2b26A7YGqtQ4bJVvRUebYCyB/AyYmXThAlKaEw+Kd2H8iR4h/qNxUWHMgQykBDOi8Tw== dependencies: "@tornado/gas-price-oracle" "^0.5.3" "@tornado/tornado-config" "^2.0.0"