Skip to content

Commit

Permalink
feat: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
d3or committed Feb 21, 2024
1 parent 29e92c7 commit 2fa0adc
Show file tree
Hide file tree
Showing 29 changed files with 7,968 additions and 35,531 deletions.
35,393 changes: 7,378 additions & 28,015 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 7 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hardhat-gas-trackooor",
"version": "1.0.3",
"version": "1.0.4",
"description": "Hardhat plugin to track gas on the transaction level",
"repository": "github:d3or/hardhat-gas-trackooor",
"author": "d3or",
Expand All @@ -21,7 +21,6 @@
"test": "npx mocha test/waffle.ts",
"prepublishOnly": "tsc --project tsconfig.prod.json --resolveJsonModule",
"build": "tsc --project tsconfig.prod.json --resolveJsonModule",
"buidl": "tsc",
"watch": "tsc -w"
},
"files": [
Expand All @@ -31,34 +30,25 @@
"README.md"
],
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@types/chai": "^4.2.14",
"@types/fs-extra": "^5.0.4",
"@types/mocha": "7",
"@types/node": "^8.10.38",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"chai": "^4.2.0",
"dotenv": "^6.2.0",
"ethereum-waffle": "^3.2.1",
"ganache-cli": "^6.4.3",
"hardhat": "^2.6.1",
"hardhat": "^2.20.1",
"mocha": "7",
"source-map-support": "^0.5.12",
"tslib": "^2.3.1",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"prettier": "^2.5.1",
"source-map-support": "^0.5.12",
"ts-node": "^10.5.0",
"tslib": "^2.3.1",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.3.0",
"typescript": "^4.5.5"
},
"dependencies": {
"ethers": "^5.0.0"

},
"peerDependencies": {
"hardhat": "^2.0.2"
}
}
17 changes: 12 additions & 5 deletions src/GasTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ import type * as ethers from 'ethers';
import { GasData, GasTrackerConfig } from './types';

export class GasTracker {
public contract: ethers.Contract;
public contract: ethers.BaseContract;

public options: GasTrackerConfig;

public gasData: GasData;

public highGasThreshold: number = 100000;

constructor(contract: ethers.Contract, options: GasTrackerConfig) {
[key: string]: any;

constructor(
contract: ethers.BaseContract & {
deploymentTransaction(): ethers.ContractTransactionResponse;
},
options: GasTrackerConfig,
) {
this.contract = contract;
this.options = options;

Expand Down Expand Up @@ -97,11 +104,11 @@ export class GasTracker {
// ok so, the hardhat runtime environment is exposed as a global variable, so we can access it here. but like idk how to type it. so we use @ts-ignore :D
// @ts-ignore
const reciept = await hre.ethers.provider.getTransactionReceipt(txHash);
const gas = reciept.gasUsed.toNumber();
// big int to int
const gas = parseInt(reciept.gasUsed.toString());

let bullet = '•';
if (gas > this.highGasThreshold)
bullet = ' ⚠️ ';
if (gas > this.highGasThreshold) bullet = ' ⚠️ ';

if (this?.options?.logAfterTx) {
console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/GetGas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function GetGas(transaction) {
const reciept = await transaction.wait();
return reciept.gasUsed.toNumber();
return parseInt(reciept.gasUsed.toString());
}
14 changes: 0 additions & 14 deletions test/example/.gitignore

This file was deleted.

13 changes: 0 additions & 13 deletions test/example/README.md

This file was deleted.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions test/example/artifacts/contracts/Greeter.sol/Greeter.dbg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/ec59a8b5f6c4cc41759762f84e98a9f9.json"
}
74 changes: 74 additions & 0 deletions test/example/artifacts/contracts/Greeter.sol/Greeter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Greeter",
"sourceName": "contracts/Greeter.sol",
"abi": [
{
"inputs": [
{
"internalType": "string",
"name": "_greeting",
"type": "string"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "greet",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "greeting",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "_greeting",
"type": "string"
}
],
"name": "setGreeting",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "string",
"name": "message",
"type": "string"
}
],
"name": "throwAnError",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x60806040523480156200001157600080fd5b5060405162000d5d38038062000d5d8339818101604052810190620000379190620001e3565b80600090816200004891906200047f565b505062000566565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000b9826200006e565b810181811067ffffffffffffffff82111715620000db57620000da6200007f565b5b80604052505050565b6000620000f062000050565b9050620000fe8282620000ae565b919050565b600067ffffffffffffffff8211156200012157620001206200007f565b5b6200012c826200006e565b9050602081019050919050565b60005b83811015620001595780820151818401526020810190506200013c565b60008484015250505050565b60006200017c620001768462000103565b620000e4565b9050828152602081018484840111156200019b576200019a62000069565b5b620001a884828562000139565b509392505050565b600082601f830112620001c857620001c762000064565b5b8151620001da84826020860162000165565b91505092915050565b600060208284031215620001fc57620001fb6200005a565b5b600082015167ffffffffffffffff8111156200021d576200021c6200005f565b5b6200022b84828501620001b0565b91505092915050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200028757607f821691505b6020821081036200029d576200029c6200023f565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b600060088302620003077fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82620002c8565b620003138683620002c8565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620003606200035a62000354846200032b565b62000335565b6200032b565b9050919050565b6000819050919050565b6200037c836200033f565b620003946200038b8262000367565b848454620002d5565b825550505050565b600090565b620003ab6200039c565b620003b881848462000371565b505050565b5b81811015620003e057620003d4600082620003a1565b600181019050620003be565b5050565b601f8211156200042f57620003f981620002a3565b6200040484620002b8565b8101602085101562000414578190505b6200042c6200042385620002b8565b830182620003bd565b50505b505050565b600082821c905092915050565b6000620004546000198460080262000434565b1980831691505092915050565b60006200046f838362000441565b9150826002028217905092915050565b6200048a8262000234565b67ffffffffffffffff811115620004a657620004a56200007f565b5b620004b282546200026e565b620004bf828285620003e4565b600060209050601f831160018114620004f75760008415620004e2578287015190505b620004ee858262000461565b8655506200055e565b601f1984166200050786620002a3565b60005b8281101562000531578489015182556001820191506020850194506020810190506200050a565b868310156200055157848901516200054d601f89168262000441565b8355505b6001600288020188555050505b505050505050565b6107e780620005766000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063a413686214610051578063cfae32171461006d578063ef690cc01461008b578063fcaaa78f146100a9575b600080fd5b61006b600480360381019061006691906103df565b6100c5565b005b6100756100d8565b60405161008291906104a7565b60405180910390f35b61009361016a565b6040516100a091906104a7565b60405180910390f35b6100c360048036038101906100be91906103df565b6101f8565b005b80600090816100d491906106df565b5050565b6060600080546100e7906104f8565b80601f0160208091040260200160405190810160405280929190818152602001828054610113906104f8565b80156101605780601f1061013557610100808354040283529160200191610160565b820191906000526020600020905b81548152906001019060200180831161014357829003601f168201915b5050505050905090565b60008054610177906104f8565b80601f01602080910402602001604051908101604052809291908181526020018280546101a3906104f8565b80156101f05780601f106101c5576101008083540402835291602001916101f0565b820191906000526020600020905b8154815290600101906020018083116101d357829003601f168201915b505050505081565b6040518060400160405280600781526020017f676f6f64627965000000000000000000000000000000000000000000000000008152506000908161023c91906106df565b5060008190610281576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161027891906104a7565b60405180910390fd5b5050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6102ec826102a3565b810181811067ffffffffffffffff8211171561030b5761030a6102b4565b5b80604052505050565b600061031e610285565b905061032a82826102e3565b919050565b600067ffffffffffffffff82111561034a576103496102b4565b5b610353826102a3565b9050602081019050919050565b82818337600083830152505050565b600061038261037d8461032f565b610314565b90508281526020810184848401111561039e5761039d61029e565b5b6103a9848285610360565b509392505050565b600082601f8301126103c6576103c5610299565b5b81356103d684826020860161036f565b91505092915050565b6000602082840312156103f5576103f461028f565b5b600082013567ffffffffffffffff81111561041357610412610294565b5b61041f848285016103b1565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610462578082015181840152602081019050610447565b60008484015250505050565b600061047982610428565b6104838185610433565b9350610493818560208601610444565b61049c816102a3565b840191505092915050565b600060208201905081810360008301526104c1818461046e565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061051057607f821691505b602082108103610523576105226104c9565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b60006008830261058b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8261054e565b610595868361054e565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b60006105dc6105d76105d2846105ad565b6105b7565b6105ad565b9050919050565b6000819050919050565b6105f6836105c1565b61060a610602826105e3565b84845461055b565b825550505050565b600090565b61061f610612565b61062a8184846105ed565b505050565b5b8181101561064e57610643600082610617565b600181019050610630565b5050565b601f8211156106935761066481610529565b61066d8461053e565b8101602085101561067c578190505b6106906106888561053e565b83018261062f565b50505b505050565b600082821c905092915050565b60006106b660001984600802610698565b1980831691505092915050565b60006106cf83836106a5565b9150826002028217905092915050565b6106e882610428565b67ffffffffffffffff811115610701576107006102b4565b5b61070b82546104f8565b610716828285610652565b600060209050601f8311600181146107495760008415610737578287015190505b61074185826106c3565b8655506107a9565b601f19841661075786610529565b60005b8281101561077f5784890151825560018201915060208501945060208101905061075a565b8683101561079c5784890151610798601f8916826106a5565b8355505b6001600288020188555050505b50505050505056fea2646970667358221220ce7c1055a54701701482a8d58e4ec29012bf93ad0959a11f70def716e78eecbe64736f6c63430008180033",
"deployedBytecode": "0x608060405234801561001057600080fd5b506004361061004c5760003560e01c8063a413686214610051578063cfae32171461006d578063ef690cc01461008b578063fcaaa78f146100a9575b600080fd5b61006b600480360381019061006691906103df565b6100c5565b005b6100756100d8565b60405161008291906104a7565b60405180910390f35b61009361016a565b6040516100a091906104a7565b60405180910390f35b6100c360048036038101906100be91906103df565b6101f8565b005b80600090816100d491906106df565b5050565b6060600080546100e7906104f8565b80601f0160208091040260200160405190810160405280929190818152602001828054610113906104f8565b80156101605780601f1061013557610100808354040283529160200191610160565b820191906000526020600020905b81548152906001019060200180831161014357829003601f168201915b5050505050905090565b60008054610177906104f8565b80601f01602080910402602001604051908101604052809291908181526020018280546101a3906104f8565b80156101f05780601f106101c5576101008083540402835291602001916101f0565b820191906000526020600020905b8154815290600101906020018083116101d357829003601f168201915b505050505081565b6040518060400160405280600781526020017f676f6f64627965000000000000000000000000000000000000000000000000008152506000908161023c91906106df565b5060008190610281576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161027891906104a7565b60405180910390fd5b5050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6102ec826102a3565b810181811067ffffffffffffffff8211171561030b5761030a6102b4565b5b80604052505050565b600061031e610285565b905061032a82826102e3565b919050565b600067ffffffffffffffff82111561034a576103496102b4565b5b610353826102a3565b9050602081019050919050565b82818337600083830152505050565b600061038261037d8461032f565b610314565b90508281526020810184848401111561039e5761039d61029e565b5b6103a9848285610360565b509392505050565b600082601f8301126103c6576103c5610299565b5b81356103d684826020860161036f565b91505092915050565b6000602082840312156103f5576103f461028f565b5b600082013567ffffffffffffffff81111561041357610412610294565b5b61041f848285016103b1565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610462578082015181840152602081019050610447565b60008484015250505050565b600061047982610428565b6104838185610433565b9350610493818560208601610444565b61049c816102a3565b840191505092915050565b600060208201905081810360008301526104c1818461046e565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061051057607f821691505b602082108103610523576105226104c9565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b60006008830261058b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8261054e565b610595868361054e565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b60006105dc6105d76105d2846105ad565b6105b7565b6105ad565b9050919050565b6000819050919050565b6105f6836105c1565b61060a610602826105e3565b84845461055b565b825550505050565b600090565b61061f610612565b61062a8184846105ed565b505050565b5b8181101561064e57610643600082610617565b600181019050610630565b5050565b601f8211156106935761066481610529565b61066d8461053e565b8101602085101561067c578190505b6106906106888561053e565b83018261062f565b50505b505050565b600082821c905092915050565b60006106b660001984600802610698565b1980831691505092915050565b60006106cf83836106a5565b9150826002028217905092915050565b6106e882610428565b67ffffffffffffffff811115610701576107006102b4565b5b61070b82546104f8565b610716828285610652565b600060209050601f8311600181146107495760008415610737578287015190505b61074185826106c3565b8655506107a9565b601f19841661075786610529565b60005b8281101561077f5784890151825560018201915060208501945060208101905061075a565b8683101561079c5784890151610798601f8916826106a5565b8355505b6001600288020188555050505b50505050505056fea2646970667358221220ce7c1055a54701701482a8d58e4ec29012bf93ad0959a11f70def716e78eecbe64736f6c63430008180033",
"linkReferences": {},
"deployedLinkReferences": {}
}
41 changes: 41 additions & 0 deletions test/example/cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"_format": "hh-sol-cache-2",
"files": {
"/Users/deor/Desktop/Code/hardhat-gas-trackooor/test/example/contracts/Greeter.sol": {
"lastModificationDate": 1708530888300,
"contentHash": "f52683cf9f9d602151532e2b73ed62f7",
"sourceName": "contracts/Greeter.sol",
"solcConfig": {
"version": "0.8.24",
"settings": {
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.24"
],
"artifacts": [
"Greeter"
]
}
}
}
23 changes: 0 additions & 23 deletions test/example/contracts/Greeter.sol

This file was deleted.

10 changes: 0 additions & 10 deletions test/example/hardhat.config.ts

This file was deleted.

Loading

0 comments on commit 2fa0adc

Please sign in to comment.