-
Notifications
You must be signed in to change notification settings - Fork 0
/
putEVMContract.ts
41 lines (37 loc) · 1.12 KB
/
putEVMContract.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
import { Account, Address } from '@ethereumjs/util';
import { vm } from './initEVM';
/**
* TODO: Do return type
* @description Put contract into EVM
* @param address - Address of the contract
* @param balanceInNativeToken - Balance of the contract in native token
* @param nonce - Nonce of the contract
* @param code - Code of the contract
* @param storage - Storage of the contract
*/
const putEVMContract = async (
address,
balanceInNativeToken,
nonce,
code,
storage
) => {
let accountData = {
nonce,
balance: BigInt(balanceInNativeToken) * BigInt(10) ** BigInt(18)
};
address = Address.fromString(address);
await vm.stateManager.putAccount(
address,
Account.fromAccountData(accountData)
);
for (const [key, val] of Object.entries(storage)) {
const storageKey = Buffer.from(key, 'hex');
//@ts-expect-error - TODO: Fix this
const storageVal = Buffer.from(val, 'hex');
await vm.stateManager.putContractStorage(address, storageKey, storageVal);
}
const codeBuf = Buffer.from(code, 'hex');
await vm.stateManager.putContractCode(address, codeBuf);
};
export default putEVMContract;