Proxy contracts
Last updated
Last updated
A proxy contract is a smart contract that forwards transactions to another implementation contract containing the business logic. The proxy acts as an intermediary, allowing the implementation to be updated without changing the contract address users interact with.
For this example, we will be shadowing USDC to emit a custom event on every transfer. The custom event will be called TransferWithMetadata
, and will contain additional metadata about the transfer, including the before and after balances, and the percent change.
USDC follows a proxy pattern with the following addresses:
Proxy:
Implementation: (as of Jul 2024)
Open the example on the Shadow Playground:
This will open the playground editor at the implementation contract at (as of Jul 2024).
The bulk of the shadow contract changes lives in the FiatTokenV1.sol
file.
At L57, we’ve defined the TransferWithMetadata
event and a helper TransferMetadata
struct:
Then lower down in the same file, we updated the _transfer
function to emit our TransferWithMetadata
shadow event:
You should see your custom TransferWithMetadata
in the output!
If you want to apply these changes on your shadow fork, click the button on the top right corner that says “Apply to your shadow fork”.
This will take you to the editor for your shadow fork, where you can deploy the changes by hitting “Compile > Deploy”.
Events added to an implementation contract are emitted by the proxy contract.
This means that if you are retrieving data via RPC, you'll need to filter by the proxy contract address.
Similarly, if you are setting up a data export, you'll need to select the proxy contract address.
Click “Compile” > “Test Run” in the top right corner, and paste in this transaction hash –– or you can simulate any other transaction that transferred USDC.
So if you want to see a realtime feed of your shadow events, you'll need to navigate to the proxy contract address .