-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from lidofinance/develop
fix: overrides printing
- Loading branch information
Showing
3 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Contract, ContractTransaction } from 'ethers'; | ||
|
||
export const splitArgsAndOverrides = (contract: Contract, method: string, argsWithOverrides: unknown[]) => { | ||
const fragment = contract.interface.getFunction(method, argsWithOverrides); | ||
|
||
if (!fragment) { | ||
throw new Error(`Method ${method} not found`); | ||
} | ||
|
||
const args = [...argsWithOverrides]; | ||
|
||
// If an overrides was passed in, copy it | ||
let overrides: Omit<ContractTransaction, 'data' | 'to'> = {}; | ||
if (fragment.inputs.length + 1 === args.length) { | ||
overrides = { ...(args.pop() as typeof overrides) }; | ||
} | ||
|
||
return { args, overrides }; | ||
}; |