diff --git a/package-lock.json b/package-lock.json index 0ac9ca5..e0da20c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -569,12 +569,22 @@ "resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz", "integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==" }, + "big-integer": { + "version": "1.6.48", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", + "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==" + }, "binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", "dev": true }, + "blakejs": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.1.0.tgz", + "integrity": "sha1-ad+S75U6qIylGjLfarHFShVfx6U=" + }, "bn.js": { "version": "4.12.0", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", @@ -1028,6 +1038,16 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "ffjavascript": { + "version": "0.2.35", + "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.35.tgz", + "integrity": "sha512-xnC51tWbi0ah4SH+02jEfJyO+P+NiZWnxQrLDLtBYY1Dv3QM5ydxzd+gxnLEfWdT8i1bMM5pIh5P25l6fNCaVQ==", + "requires": { + "big-integer": "^1.6.48", + "wasmcurves": "0.0.14", + "web-worker": "^1.0.0" + } + }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -2647,6 +2667,20 @@ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", "dev": true }, + "wasmcurves": { + "version": "0.0.14", + "resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.0.14.tgz", + "integrity": "sha512-G1iMkxlRaQSdqQ1JrwHcU+awLmwyH6kFKfT8g9obd8MWe+u5oSdFXrODB0zmSI5aGGvJPG+4cAmqCGYv9R+7qg==", + "requires": { + "big-integer": "^1.6.42", + "blakejs": "^1.1.0" + } + }, + "web-worker": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.0.0.tgz", + "integrity": "sha512-BzuMqeKVkKKwHV6tJuwePFcxYMxvC97D448mXTgh/CxXAB4sRtoV26gRPN+JDxsXRR7QZyioMV9O6NzQaASf7Q==" + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index ff8a73c..543e2af 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "dependencies": { "dotenv": "^8.2.0", "ethers": "^5.0.12", + "ffjavascript": "^0.2.35", "yargs": "^16.2.0" }, "devDependencies": { diff --git a/src/biddingCLI.js b/src/biddingCLI.js index 4e724a4..43aa789 100644 --- a/src/biddingCLI.js +++ b/src/biddingCLI.js @@ -1,6 +1,7 @@ const path = require("path"); require("dotenv").config({path:path.join(__dirname, "../config/.env")}); const { ethers } = require("ethers"); +const { getGasPrice } = require("./utils"); const addressSC = require("../config/addressSC.json"); var yargs = require("yargs") .usage(` @@ -75,6 +76,7 @@ commands .option("min", { alias: "minBid", describe: "minimum that you want to bid", type: "string", demandOption: false }) .option("p", { alias: "usePermit", describe: "enable permit feature (default true)", type: "boolean", demandOption: false, default: true }) .option("u", { alias: "units", describe: "choose unit type, wei or ether supported", type: "string", demandOption: false, default: "ether" }) + .option("m", { alias: "multiplier", describe: "gasPrice multiplier", type: "number", demandOption: false, default: 1 }) .option("all", { alias: "all", describe: "bool if the user want to display only his bids or all the current bids", type: "bool", demandOption: false, default: false }); @@ -88,6 +90,7 @@ const slotSets = argv.slotSets ? slotSets.split(",") : [true, true, true, true, const usePermit = argv.usePermit; const units = argv.units; const allBool = argv.all; +const multiplier = argv.multiplier; let amount = argv.amount; let bidAmount = argv.bidAmount; @@ -177,10 +180,15 @@ async function main() { } if(command === "REGISTER") { + // set options + const options = { + gasPrice: await getGasPrice(multiplier, provider) + } + // register coordinator const res = await HermezAuctionContract .connect(wallet) - .setCoordinator(wallet.address, url); + .setCoordinator(wallet.address, url, options); await printEtherscanTx(res, network.chainId); } @@ -219,11 +227,17 @@ async function main() { if(command === "BID") { try { + // set options + const options = { + gasPrice: await getGasPrice(multiplier, provider) + } + const res = await HermezAuctionContract.connect(wallet).processBid( amount, slot, bidAmount, - dataPermit + dataPermit, + options ); await printEtherscanTx(res, network.chainId); } catch (error) { @@ -234,6 +248,11 @@ async function main() { } else if(command === "MULTIBID") { try { + // set options + const options = { + gasPrice: await getGasPrice(multiplier, provider) + } + const res = await HermezAuctionContract.connect(wallet).processMultiBid( amount, startingSlot, @@ -241,7 +260,8 @@ async function main() { slotSets, maxBid, minBid, - dataPermit + dataPermit, + options ); await printEtherscanTx(res, network.chainId); } catch (error) { @@ -260,7 +280,12 @@ async function main() { } else if(command === "CLAIMHEZ") { try { - const res = await HermezAuctionContract.connect(wallet).claimHEZ(); + // set options + const options = { + gasPrice: await getGasPrice(multiplier, provider) + } + + const res = await HermezAuctionContract.connect(wallet).claimHEZ(options); await printEtherscanTx(res, network.chainId); } catch (error) { console.log("gas estimation failed"); diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..b9b535e --- /dev/null +++ b/src/utils.js @@ -0,0 +1,19 @@ +const Scalar = require("ffjavascript").Scalar; + +/** + * Get current average gas price from the last ethereum blocks and multiply it + * @param {Number} multiplier - multiply the average gas price by this parameter + * @param {Object} provider - Provider Object retinrd by 'ethers' + * @returns {Promise} - promise will return the gas price obtained. + */ +async function getGasPrice (multiplier, provider) { + const strAvgGas = await provider.getGasPrice() + const avgGas = Scalar.e(strAvgGas) + const res = (avgGas * Scalar.e(multiplier)) + const retValue = res.toString() + return retValue +} + +module.exports = { + getGasPrice +}; \ No newline at end of file