Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

add multiplier gasPrice option #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"dotenv": "^8.2.0",
"ethers": "^5.0.12",
"ffjavascript": "^0.2.35",
"yargs": "^16.2.0"
},
"devDependencies": {
Expand Down
33 changes: 29 additions & 4 deletions src/biddingCLI.js
Original file line number Diff line number Diff line change
@@ -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(`
Expand Down Expand Up @@ -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 });


Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -234,14 +248,20 @@ 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,
endingSlot,
slotSets,
maxBid,
minBid,
dataPermit
dataPermit,
options
);
await printEtherscanTx(res, network.chainId);
} catch (error) {
Expand All @@ -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");
Expand Down
19 changes: 19 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -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
};