-
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 #12 from lidofinance/develop
develop
- Loading branch information
Showing
5 changed files
with
47 additions
and
40 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
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,34 @@ | ||
import chalk from 'chalk'; | ||
import { AbstractSigner, Contract } from 'ethers'; | ||
import { stringify } from './stringify'; | ||
|
||
const title = chalk.gray; | ||
const value = chalk.blue.bold; | ||
|
||
export const printTx = async (contract: Contract, method: string, args: unknown[] = []) => { | ||
const provider = contract.runner?.provider; | ||
|
||
if (!provider) { | ||
throw new Error('Provider is not set'); | ||
} | ||
|
||
if (!(contract.runner instanceof AbstractSigner)) { | ||
throw new Error('Runner is not a signer'); | ||
} | ||
|
||
const signer = contract.runner; | ||
const from = await signer.getAddress(); | ||
|
||
const network = await provider.getNetwork(); | ||
const to = await contract.getAddress(); | ||
|
||
const parsedArgs = args.map((arg) => stringify(arg)); | ||
const call = `${method}(${parsedArgs})`; | ||
const data = contract.interface.encodeFunctionData(method, args); | ||
|
||
console.log(title('chain:'), value(network.name)); | ||
console.log(title(' from:'), value(from)); | ||
console.log(title(' to:'), value(to)); | ||
console.log(title(' call:'), value(call)); | ||
console.log(title(' data:'), value(data)); | ||
}; |