Skip to content
Merged
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
43 changes: 9 additions & 34 deletions contracts/utils/signers.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
const { parseEther } = require("ethers/lib/utils");
const hhHelpers = require("@nomicfoundation/hardhat-network-helpers");
const {
getKmsAddress,
getKmsSigner,
hasAwsKmsCredentials,
} = require("./signersNoHardhat");
const { ethereumAddress, privateKey } = require("./regex");
const { getKmsSigner } = require("./signersNoHardhat");
const { ethereumAddress } = require("./regex");

const log = require("./logger")("utils:signers");

// @oplabs/talos-client ships only in the Talos runner image, not in a plain
// contracts checkout (it's an optional dependency). Load it lazily so hardhat —
// which pulls this module in through tasks/tasks.js — boots without it. The
// require only fires once DATABASE_URL opts into the nonce queue.
let talosClient = null;
function talosClientLib() {
if (!talosClient) talosClient = require("@oplabs/talos-client");
return talosClient;
}

let dbInstance = null;
function getNonceDb() {
if (!process.env.DATABASE_URL) return null;
if (!dbInstance) {
const { createPool, createDb } = talosClientLib();
const pool = createPool({ connectionString: process.env.DATABASE_URL });
dbInstance = createDb(pool);
}
return dbInstance;
// These modules are TypeScript and belong to the standalone Talos runtime.
// Resolve them lazily so importing this legacy CommonJS helper still works in
// Hardhat environments where the optional Talos dependencies are not installed.
function getProvider() {
return require("../tasks/lib/network").getProvider();
}

// Wrap a raw signer with the nonce-queue Proxy when DATABASE_URL is set.
// Returning the raw signer unchanged in dev / fork flows preserves the
// DATABASE_URL gate invariant: no queue engagement without explicit opt-in.
function maybeWrap(rawSigner) {
const db = getNonceDb();
if (!db) return rawSigner;
const { wrapSignerWithNonceQueueV5 } = talosClientLib();
return wrapSignerWithNonceQueueV5(rawSigner, { db });
async function getStandaloneSigner() {
return await require("../tasks/lib/signer").getSigner();
}

/**
Expand Down
Loading