Proxies
Proxies are used in the T-REX protocol to provide the mechanism for upgradeability and flexibility in the deployment and operation of smart contracts. Each contract in the T-REX suite has a specific proxy contract that is adapted to its constructor and calls the correct implementation contract from the implementation authority contract. This ensures that the T-REX protocol can be upgraded and maintained without redeploying all the smart contracts, thus preserving their state and addresses.
How Proxies Work
Proxies in the T-REX protocol follow the proxy pattern, where the proxy contract delegates calls to an implementation contract. The implementation contract contains the actual logic, while the proxy holds the state and delegates calls to the implementation.
Initialization:
When a proxy is deployed, it is initialized with the address of the implementation authority contract. This address is stored in a predefined storage slot using the
keccak256
hash of a specific string to ensure uniqueness.
Delegate Calls:
The proxy contract uses the
delegatecall
opcode to delegate function calls to the implementation contract. This opcode runs the code of the implementation contract in the context of the proxy contract, meaning that the proxy's state is used while executing the logic of the implementation contract.
Fallback Function:
The proxy contains a fallback function that delegates any calls that do not match any existing function to the implementation contract. This allows the proxy to handle a wide range of function calls dynamically.
Upgradeability:
The implementation authority contract can be updated, allowing the proxy to point to a new implementation contract. This upgradeability is managed through the
setImplementationAuthority
function, which ensures that the new implementation authority is valid and contains all necessary implementation addresses.
Example Proxy Contract
Below is an example of a proxy contract for the Claim Topics Registry, demonstrating the initialization and fallback mechanisms:
Abstract Proxy Contract
All proxies in the T-REX protocol implement the AbstractProxy
contract, which provides the foundational mechanisms for handling the implementation authority and delegating calls. Below is the AbstractProxy
contract:
Last updated