Skip to content

Commit

Permalink
doc: explain GetTokenDealSlot (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
adhusson committed Feb 24, 2023
1 parent 9b34702 commit 754f4f1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions script/lib/GetTokenDealSlot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ interface SmallERC20 {
contract GetTokenDealSlot is Deployer {
using stdStorage for StdStorage;

/* Read the storage slot used by a token to remember an account's balance.
Uses stdstore to do the following:
1. Record storage accesses.
2. Call token.balanceOf(account) (signature of balanceOf: 0x70a08231) .
3. Log the slot that was read during the call to balanceOf.
4. For convenience, also log the number of decimals used by the token.
The script is intended to be used as follows:
1. Given an anvil node running (with --fork-url <SOME_NODE>)
2. Run
forge script GetTokenDealSlot -vv
3. Parse output for slot: <slot>
4. Run
cast rpc anvil_setStorageAt <token> <slot> <amount>
(or directly do a json-rpc request from e.g. javascript)
*/
function run() public {
address token = envAddressOrName("TOKEN");
address account = envAddressOrName("ACCOUNT");
Expand Down

0 comments on commit 754f4f1

Please sign in to comment.