Skip to content

Commit

Permalink
chore: clean up based on combination of Jan / Riley's feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding committed Feb 21, 2024
1 parent a45875b commit 94de06b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { types } from '@/cli'
import { SUBTASK_LZ_SIGN_AND_SEND } from '@/constants'
import { formatOmniTransaction } from '@/transactions/format'
import { createSignerFactory } from '@/transactions/signer'
import { createGnosisSignerFactory, createSignerFactory } from '@/transactions/signer'
import {
type OmniSignerFactory,
type OmniTransaction,
Expand All @@ -25,13 +25,16 @@ import type { ActionType } from 'hardhat/types'
export interface SignAndSendTaskArgs {
ci?: boolean
transactions: OmniTransaction[]
useSafe?: boolean
createSigner?: OmniSignerFactory
}

const action: ActionType<SignAndSendTaskArgs> = async ({
ci,
transactions,
createSigner = createSignerFactory(),
useSafe = false,
// useSafe will override createSigner using Gnosis factory
createSigner = useSafe ? createGnosisSignerFactory() : createSignerFactory(),
}): Promise<SignAndSendResult> => {
// We only want to be asking users for input if we are not in interactive mode
const isInteractive = !ci
Expand Down Expand Up @@ -164,3 +167,4 @@ subtask(SUBTASK_LZ_SIGN_AND_SEND, 'Sign and send a list of transactions using a
.addFlag('ci', 'Continuous integration (non-interactive) mode. Will not ask for any input from the user')
.addParam('transactions', 'List of OmniTransaction objects', undefined, types.any)
.addParam('createSigner', 'Function that creates a signer for a particular network', undefined, types.any, true)
.addParam('useSafe', 'Use Gnosis Safe for signing. Overrides createSigner.', false, types.boolean, true)
21 changes: 17 additions & 4 deletions packages/devtools-evm-hardhat/src/transactions/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@ import { createProviderFactory } from '@/provider'
import { createGetHreByEid } from '@/runtime'

export const createSignerFactory = (
addressOrIndex?: string | number,
providerFactory = createProviderFactory()
): OmniSignerFactory<OmniSignerEVM> => {
return pMemoize(async (eid) => {
const provider = await providerFactory(eid)
const signer = provider.getSigner(addressOrIndex)

return new OmniSignerEVM(eid, signer)
})
}

export const createGnosisSignerFactory = (
addressOrIndex?: string | number,
providerFactory = createProviderFactory(),
networkEnvironmentFactory = createGetHreByEid()
): OmniSignerFactory => {
): OmniSignerFactory<GnosisOmniSignerEVM> => {
return pMemoize(async (eid) => {
const provider = await providerFactory(eid)
const signer = provider.getSigner(addressOrIndex)

const env = await networkEnvironmentFactory(eid)
const safeConfig = env.network.config.safeConfig
return safeConfig
? new GnosisOmniSignerEVM(eid, signer, safeConfig.safeUrl, safeConfig)
: new OmniSignerEVM(eid, signer)
if (!safeConfig) {
throw new Error('No safe config found for the current network')
}
return new GnosisOmniSignerEVM(eid, signer, safeConfig.safeUrl, safeConfig)
})
}

0 comments on commit 94de06b

Please sign in to comment.