Closed kevinbluer closed 1 year ago
You know what I just realized... maybe there's a way for this plugin to remove the need for the user to define the dashboard network themselves. Can HH plugins define networks... is that kosher?
Ooh yeah OK I think we should probably read up on how hardhat-foundry works and just emulate that. Nevermind, it doesn't specifically add networks from Foundry to HH. But it does make use of extendConfig
, which I think is what we want.
So that being said, I think we should update the plugin to add a "truffle-dashboard"
network automatically and manage it entirely. That name is a little long, so users might want to change it to something other than the default, so we should still allow configuration. I'm thinking this:
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@truffle/dashboard-hardhat-plugin";
const config: HardhatUserConfig = {
// ... rest of hh config ...
truffle: {
dashboardNetworkName: "truffle-dashboard"
}
};
export default config;
I was originally thinking we needed a whole section for Truffle Dashboard, but that would mean we'd have to decide between truffle: { dashboard: { ... } }
and "truffle-dashboard": { ... }
(neither of which is ideal). And it's clunky.
But! We don't need to add all that configuration if we just assume that the user is configuring Truffle Dashboard via truffle-config.js
in their HH project directory. We already have a way to configure Truffle Dashboard, and that's truffle-config.js
! We can just have this plugin just do a TruffleConfig.detect()
and use the Dashboard configuration automatically from that!
This eliminates support for the case where users want to run a customized truffle dashboard
from a different directory, but I'm not sure that's necessary? This path forward just seems too good to pass up with the de-duplication it offers.
The only thing left for the user to configure in hardhat.config.ts
is the name of the Dashboard network we add automatically. Neat huh?
Did some more digging on the above and chatted with @alcuadrado, who confirms the limitation I describe here.
So I really want this sort of thing:
hardhat.config.ts
i.e., the plugin should minimize the configuration options it adds in that truffle
namespace. Instead, we should allow people to override the Dashboard network the same way they would override any HTTP network in their Hardhat config. This plugin should then fill in the gaps between Hardhat's defaults and the user-specified network params.
It's worth noting here that the way Hardhat does config is by separating user config from complete config with defaults. It defines types for the HardhatUserConfig
(e.g. HttpNetworkUserConfig
), where most fields are optional, and it has separate types for the HardhatConfig
, where everything is filled in. Key points here:
The problem with my example is that Hardhat does this:
timeout
property.HttpNetworkUserConfig
.url
is missing and fail.Presumably this fails because there's no good default value for Hardhat to use for url
in the output HttpNetworkConfig
, and Hardhat isn't architected to consult plugins for missing network configurations.
Now, we can add a fresh network just fine, but if we want users to override this Truffle Dashboard network, I can think of two options:
url: ""
property, which the plugin would overwrite, or,userConfig.networks[networkName]
object.With the latter option, we're looking at something like this:
hardhat.config.ts
Not ideal. I'm thinking this approach is probably still not terrible... it still seems nice for @truffle/dashboard-hardhat-plugin to supply the network config itself.
But... will lots of people want to configure the timeout or other settings? I was going to suggest default to just disable the timeout altogether for this network, but seems like opinions could easily differ for that (and other settings like gasMultiplier
). Bit annoying for these settings to live inside this other truffle.dashboard
namespace.
As a small consolation, we can control whether the plugin does this network management by adding a truffle.dashboard.manageNetwork: boolean
property, so there's a trivial way to offer an "eject button" to the old/plugin-less behavior.
This is now done!
@truffle/dashboard-hardhat-plugin supports customization starting in v0.2.0 of that package.
Issue
When using the Truffle Dashboard Hardhat Plugin, the target host and port are currently hardcoded to the defaults (
localhost
and24012
respectively). As highlighted in this conversation this should be made user configurable by allowing users to specifying them in the Hardhat config.