forked from aave/gho-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc-utils.ts
113 lines (92 loc) · 3.56 KB
/
misc-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { formatEther } from 'ethers/lib/utils';
import path from 'path';
import fs from 'fs';
import { BigNumber, Signer } from 'ethers';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { tEthereumAddress } from './types';
import { config } from 'dotenv';
import Bluebird from 'bluebird';
import { getWalletBalances } from '@aave/deploy-v3';
config();
declare var hre: HardhatRuntimeEnvironment;
export const evmSnapshot = async () => await hre.ethers.provider.send('evm_snapshot', []);
export const evmRevert = async (id: string) => hre.ethers.provider.send('evm_revert', [id]);
export const timeLatest = async () => {
const block = await hre.ethers.provider.getBlock('latest');
return BigNumber.from(block.timestamp);
};
export const setBlocktime = async (time: number) => {
await hre.ethers.provider.send('evm_setNextBlockTimestamp', [time]);
};
export const advanceTimeAndBlock = async function (forwardTime: number) {
const currentBlockNumber = await hre.ethers.provider.getBlockNumber();
const currentBlock = await hre.ethers.provider.getBlock(currentBlockNumber);
const currentTime = currentBlock.timestamp;
const futureTime = currentTime + forwardTime;
await hre.ethers.provider.send('evm_setNextBlockTimestamp', [futureTime]);
await hre.ethers.provider.send('evm_mine', []);
};
export const mine = async () => {
await hre.ethers.provider.send('evm_mine', []);
};
export const impersonateAccountHardhat = async (account: string): Promise<Signer> => {
await hre.network.provider.send('hardhat_setBalance', [account, '0xFFFFFFFFFFFFFFFFFFFFFFFFF']);
await hre.network.provider.request({
method: 'hardhat_impersonateAccount',
params: [account],
});
return await hre.ethers.getSigner(account);
};
export const setCode = async (address: tEthereumAddress, bytecode: string): Promise<void> => {
await hre.network.provider.request({
method: 'hardhat_setCode',
params: [address, bytecode],
});
};
export const setStorageAt = async (
address: tEthereumAddress,
storageSlot: string,
storageValue: string
): Promise<void> => {
await hre.network.provider.request({
method: 'hardhat_setStorageAt',
params: [address, storageSlot, storageValue],
});
};
export const getProxyImplementationBySlot = async (proxyAddress: tEthereumAddress) => {
const proxyImplementationSlot = await hre.ethers.provider.getStorageAt(
proxyAddress,
'0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
);
return hre.ethers.utils.getAddress(
hre.ethers.utils.defaultAbiCoder.decode(['address'], proxyImplementationSlot).toString()
);
};
export const FULL_DEPLOY = process.env.FULL_DEPLOY === 'true';
export const loadHardhatTasks = (taskFolders: string[]): void =>
taskFolders.forEach((folder) => {
const tasksPath = path.join(__dirname, '../tasks', folder);
fs.readdirSync(tasksPath)
.filter((pth) => pth.includes('.ts') || pth.includes('.js'))
.forEach((task) => {
require(`${tasksPath}/${task}`);
});
});
export const setSignersBalance = async () => {
const signers = await hre.ethers.getSigners();
await Bluebird.each(signers, async (signer) => {
await setBalance(signer.address);
});
const balances = await getWalletBalances();
console.log('Balances');
console.log('========');
console.table(balances);
};
export const setBalance = async (address: string) => {
await hre.ethers.provider.send('hardhat_setBalance', [address, '0x3635c9adc5dea00000']);
console.log(
'Updated balance',
address,
formatEther(await hre.ethers.provider.getBalance(address))
);
};