@d3or/slotseek
Version:
A library for finding the storage slots on an ERC20 token for balances and approvals, which can be used to mock the balances and approvals of an address when estimating gas costs of transactions that would fail if the address did not have the required bal
48 lines • 2.42 kB
TypeScript
import { ethers } from "ethers";
/**
* Generate mock data for a given ERC20 token balance
* @param provider - The JsonRpcProvider instance
* @param tokenAddress - The address of the ERC20 token
* @param holderAddress - The address of the holder, used to find the balance slot
* @param mockAddress - The user address to mock the balance for
* @param mockBalance - The balance to mock the balance for, if not provided, defaults to the balance of the holder
* @param maxSlots - The maximum number of slots to search
* @returns An object containing the slot and balance
*
*/
export declare const generateMockBalanceData: (provider: ethers.providers.JsonRpcProvider, { tokenAddress, holderAddress, mockAddress, mockBalanceAmount, maxSlots, }: {
tokenAddress: string;
holderAddress: string;
mockAddress: string;
mockBalanceAmount?: string | undefined;
maxSlots?: number | undefined;
}) => Promise<{
slot: string;
balance: string;
isVyper: boolean;
}>;
/**
* Get the storage slot for a given ERC20 token balance
* @param provider - The JsonRpcProvider instance
* @param erc20Address - The address of the ERC20 token
* @param holderAddress - The address of the holder, used to find the balance slot
* @param maxSlots - The maximum number of slots to search
* @returns An object containing the slot and balance
*
* - This uses a brute force approach to find the storage slot for the balance of the holder, so we can mock it. There are better ways to do this outside of just interacting directly with the contract over RPC, but its difficult to do so without needing to setup more tools/infra, especially for multi chain supoprt and gas estimation at runtime.
*/
export declare const getErc20BalanceStorageSlot: (provider: ethers.providers.JsonRpcProvider, erc20Address: string, holderAddress: string, maxSlots?: number) => Promise<{
slot: string;
balance: ethers.BigNumber;
isVyper: boolean;
}>;
/**
* Get the balance of a given address for a given ERC20 token
* @param provider - The JsonRpcProvider instance
* @param address - The address of the ERC20 token
* @param addressToCheck - The address to check the balance of
* @returns The balance of the address
*
*/
export declare const getErc20Balance: (provider: ethers.providers.JsonRpcProvider, address: string, addressToCheck: string) => Promise<ethers.BigNumber>;
//# sourceMappingURL=balance.d.ts.map