Skip to content

Commit

Permalink
Merge pull request #911 from graphprotocol/pcv/fix-cli-wrapcalls
Browse files Browse the repository at this point in the history
fix: override type in CLI to allow wrapping contract calls
  • Loading branch information
pcarranzav authored Jan 12, 2024
2 parents 4827631 + 78bb79f commit 14785af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/contracts/cli/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ import { IL2Staking } from '../build/types/IL2Staking'
import { Interface } from 'ethers/lib/utils'
import { loadArtifact } from './artifacts'

class WrappedContract {
// The meta-class properties
[key: string]: ContractFunction | any
}
export interface NetworkContracts {
EpochManager: EpochManager
DisputeManager: DisputeManager
Expand Down Expand Up @@ -160,7 +164,7 @@ function getWrappedConnect(
// Returns a contract with wrapped calls
// The wrapper will run the tx, wait for confirmation and log the details
function wrapCalls(contract: Contract, contractName: string): Contract {
const wrappedContract = lodash.cloneDeep(contract)
const wrappedContract = lodash.cloneDeep(contract) as WrappedContract

for (const fn of Object.keys(contract.functions)) {
const call: ContractFunction<ContractTransaction> = contract.functions[fn]
Expand All @@ -179,7 +183,7 @@ function wrapCalls(contract: Contract, contractName: string): Contract {
wrappedContract[fn] = override
}

return wrappedContract
return wrappedContract as Contract
}

function logContractCall(
Expand Down
11 changes: 7 additions & 4 deletions packages/sdk/src/deployments/lib/contracts/tx-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import type {
import type { Provider } from '@ethersproject/providers'
import type { ContractParam } from '../types/contract'

class WrappedContract {
// The meta-class properties
[key: string]: ContractFunction | any
}

/**
* Modifies a contract connect function to return a contract wrapped with {@link wrapCalls}
*
Expand Down Expand Up @@ -45,7 +50,7 @@ export function getWrappedConnect(
* @returns the wrapped contract
*/
export function wrapCalls(contract: Contract, contractName: string): Contract {
const wrappedContract = lodash.cloneDeep(contract)
const wrappedContract = lodash.cloneDeep(contract) as WrappedContract

for (const fn of Object.keys(contract.functions)) {
const call: ContractFunction<ContractTransaction> = contract.functions[fn]
Expand All @@ -60,13 +65,11 @@ export function wrapCalls(contract: Contract, contractName: string): Contract {
return tx
}

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
wrappedContract[fn] = override
wrappedContract.functions[fn] = override
}

return wrappedContract
return wrappedContract as Contract
}

function logContractCall(
Expand Down

0 comments on commit 14785af

Please sign in to comment.