mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-03-01 18:14:07 +00:00
* Add license & copyright declarations for add-watcher. * Add copyright declarations for cache. * Add copyright declarations for erc20-watcher. * Add copyright declarations for ipld-eth-client. * Add copyright declarations for tracing-client. * Add copyright declarations for uni-watcher. * Add copyright declarations for solidity-mapper. * Add copyright declarations for uni-info-watcher. * Add copyright declarations for util. * Add copyright declarations for lighthouse-watcher. * Change license identifier in .sol files. Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
29 lines
784 B
TypeScript
29 lines
784 B
TypeScript
//
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
//
|
|
|
|
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
|
|
)
|
|
);
|
|
};
|