Skip to main content

PairBeaconProxy

Git Source

Inherits: BeaconProxy

Proxy contract for Ammalgam Pairs that uses a beacon for implementation management and self initialization and reinitialization.

Inherits from OpenZeppelin's BeaconProxy and overrides the _fallback function to ensure the implementation is up-to-date with the beacon before delegating calls. If the implementation changes on the beacon, this proxy knows by storing the implementation at the time of construction. When a change is made, this proxy will call initialize during the _fallback call to ensure the new implementation is properly initialized. This reduces the need to manually upgrade each pair when the beacon changes the implementation.

Functions

constructor

Initializes the proxy with the beacon address from the factory and calls initialize on the implementation.

constructor()
payable
BeaconProxy(
address(IAmmalgamFactory(msg.sender).pairBeacon()),
abi.encodeWithSelector(ITokenController.initialize.selector)
);

_fallback

Overrides the _fallback function to check if the implementation from the beacon has changed. If it has, it upgrades the implementation and calls initialize on the new implementation to ensure proper setup.

function _fallback() internal override;

_setImplementation

Adapted from ERC1967Utils. The original function is private, and we need to set the implementation on first deployment without invoking initialize() again, since initialization was already performed in the BeaconProxy constructor.

function _setImplementation(
address newImplementation
) private;