mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-03-26 18:24:07 +00:00
* Set up typescript build. * Setup eslint in cache package. * Automatic lint fixes. * Fix typescript return types. * Fix typescript argument type warnings. * Set up typescript build and eslint. * Automatic lint fixes. * Fix typescript explicit any warnings. * Add argument types. * Fix return type warnings. * Fix typescript errors. * Implement declaration in types directory. Co-authored-by: nikugogoi <95nikass@gmail.com>
25 lines
743 B
TypeScript
25 lines
743 B
TypeScript
import leftPad from 'left-pad';
|
|
import { ethers } from 'ethers';
|
|
|
|
export const padKey = (input: string): string =>
|
|
leftPad(ethers.utils.hexlify(input).replace('0x', ''), 64, '0');
|
|
|
|
export const getMappingSlot = (mappingSlot: string, key: string): string => {
|
|
const mappingSlotPadded = padKey(mappingSlot);
|
|
const keyPadded = padKey(key);
|
|
const fullKey = keyPadded.concat(mappingSlotPadded);
|
|
const slot = ethers.utils.keccak256(`0x${fullKey}`);
|
|
|
|
return slot;
|
|
};
|
|
|
|
export const getStorageLeafKey = (slot: string): string => ethers.utils.keccak256(slot);
|
|
|
|
export const topictoAddress = (topic: string): string => {
|
|
return ethers.utils.getAddress(
|
|
ethers.utils.hexZeroPad(
|
|
ethers.utils.hexStripZeros(topic), 20
|
|
)
|
|
);
|
|
};
|