I am using the following code to successfully find a balance storage slot of Tokens written in Solidity:
async findStorageSlot(tokenAddr: EthAddress): Promise<number | void> {
const token = new Contract(tokenAddr.toString(), ERC20.abi, this.ethersProvider);
const randomAddress = '0x8b359fb7a31620691dc153cddd9d463259bcf29b';
const probeValue = BigNumber.from(356);
const encodedBalance = utils.defaultAbiCoder.encode(['uint'], [probeValue]);
for (let i = 0; i < 100; i++) {
const userBalanceSlot = utils.keccak256(utils.defaultAbiCoder.encode(['address', 'uint'], [randomAddress, i]));
await this.ethereumRpc.setStorageAt(tokenAddr, userBalanceSlot, encodedBalance);
const balance: BigNumber = await token.balanceOf(randomAddress);
if (balance.eq(probeValue)) {
return i;
}
}
return;
}
public async setStorageAt(addr: EthAddress, slot: string, value: string): Promise<any> {
const result = await this.provider.request({
method: 'hardhat_setStorageAt',
params: [addr.toString(), slot, value],
});
return result;
}
But when I try to use this method on a Vyper token the method fails. Is it the case that Vyper's HashMap uses different value slot encoding than Solidity's mapping?
Thank you