Storage Trigger Example
Example: A Storage Access trigger on Total Supply change
Let's say we want to use SendBlocks' storage parsing to notify us when a token's total supply changes. The trigger's slot will depend on the way the token stores its total supply:
Total Supply Variable
This method is used by most tokens: the total supply is stored as a variable in the token contract, which is usually called totalSupply
. In this case we will:
-
Search through the resulting storage layout to find the matching variable:
{ "storage_layout": [ ... { "name": "totalSupply", "first_slot": "0x1", "last_slot": "0x1" }, { "name": "balanceOf", "first_slot": "0x2", "last_slot": "0x2" }, ... ] }
-
Set storage trigger on the variable name inside the analyzed contract.
For example, the Dai Stablecoin (DAI) stores its total supply in a variable called totalSupply
.
Total Supply Slot
Some tokens store the total supply in a pre-defined slot in storage, usually calculated from the hash of some string. Finding the correct slot can be tricky, and it requires going through the token contract's code.
A good example of such a contract is the stETH token. The stETH
contract's total supply slot was originally calculated using the keccak hash of a number of different values, and is now fixed to a specific address for all subsequent versions of the contract.
Using the Storage Access Trigger
Once we've got the variable name or storage slot address, we can create a function to act on changes to the value.
Updated 8 days ago