Skip to content

Commit 14785af

Browse files
authored
Merge pull request #911 from graphprotocol/pcv/fix-cli-wrapcalls
fix: override type in CLI to allow wrapping contract calls
2 parents 4827631 + 78bb79f commit 14785af

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/contracts/cli/contracts.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ import { IL2Staking } from '../build/types/IL2Staking'
4545
import { Interface } from 'ethers/lib/utils'
4646
import { loadArtifact } from './artifacts'
4747

48+
class WrappedContract {
49+
// The meta-class properties
50+
[key: string]: ContractFunction | any
51+
}
4852
export interface NetworkContracts {
4953
EpochManager: EpochManager
5054
DisputeManager: DisputeManager
@@ -160,7 +164,7 @@ function getWrappedConnect(
160164
// Returns a contract with wrapped calls
161165
// The wrapper will run the tx, wait for confirmation and log the details
162166
function wrapCalls(contract: Contract, contractName: string): Contract {
163-
const wrappedContract = lodash.cloneDeep(contract)
167+
const wrappedContract = lodash.cloneDeep(contract) as WrappedContract
164168

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

182-
return wrappedContract
186+
return wrappedContract as Contract
183187
}
184188

185189
function logContractCall(

packages/sdk/src/deployments/lib/contracts/tx-log.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import type {
1111
import type { Provider } from '@ethersproject/providers'
1212
import type { ContractParam } from '../types/contract'
1313

14+
class WrappedContract {
15+
// The meta-class properties
16+
[key: string]: ContractFunction | any
17+
}
18+
1419
/**
1520
* Modifies a contract connect function to return a contract wrapped with {@link wrapCalls}
1621
*
@@ -45,7 +50,7 @@ export function getWrappedConnect(
4550
* @returns the wrapped contract
4651
*/
4752
export function wrapCalls(contract: Contract, contractName: string): Contract {
48-
const wrappedContract = lodash.cloneDeep(contract)
53+
const wrappedContract = lodash.cloneDeep(contract) as WrappedContract
4954

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

63-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
64-
// @ts-ignore
6568
wrappedContract[fn] = override
6669
wrappedContract.functions[fn] = override
6770
}
6871

69-
return wrappedContract
72+
return wrappedContract as Contract
7073
}
7174

7275
function logContractCall(

0 commit comments

Comments
 (0)