Skip to content

Commit

Permalink
feat: add "getProxy" getter
Browse files Browse the repository at this point in the history
refactor: make proxies mapping internal
  • Loading branch information
PaulRBerg committed Jun 17, 2023
1 parent a15da64 commit 5e0ad6b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/PRBProxyAnnex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract PRBProxyAnnex is
PRBProxyStorage // 1 inherited component
{
/*//////////////////////////////////////////////////////////////////////////
PUBLIC STORAGE
USER-FACING STORAGE
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IPRBProxyAnnex
Expand Down
35 changes: 24 additions & 11 deletions src/PRBProxyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract PRBProxyRegistry is IPRBProxyRegistry {
string public constant override VERSION = "4.0.0-beta.5";

/*//////////////////////////////////////////////////////////////////////////
PUBLIC STORAGE
USER-FACING STORAGE
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IPRBProxyRegistry
Expand All @@ -43,34 +43,42 @@ contract PRBProxyRegistry is IPRBProxyRegistry {
/// @inheritdoc IPRBProxyRegistry
mapping(address origin => bytes32 seed) public override nextSeeds;

/// @inheritdoc IPRBProxyRegistry
mapping(address owner => IPRBProxy proxy) public override proxies;
/*//////////////////////////////////////////////////////////////////////////
INTERNAL STORAGE
//////////////////////////////////////////////////////////////////////////*/

/// @dev Maps owner addresses to proxy contracts.
mapping(address owner => IPRBProxy proxy) internal _proxies;

/*//////////////////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////////////////*/

/// @notice Check that the owner does not have a proxy.
modifier noProxy(address owner) {
IPRBProxy proxy = proxies[owner];
IPRBProxy proxy = _proxies[owner];
if (address(proxy) != address(0)) {
revert PRBProxyRegistry_OwnerHasProxy(owner, proxy);
}
_;
}

/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
USER-FACING CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IPRBProxyRegistry
function deploy() external override noProxy(msg.sender) returns (IPRBProxy proxy) {
proxy = _deploy({ owner: msg.sender });
function getProxy(address owner) external view returns (IPRBProxy proxy) {
proxy = _proxies[owner];
}

/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @inheritdoc IPRBProxyRegistry
function deployFor(address owner) public override noProxy(owner) returns (IPRBProxy proxy) {
proxy = _deploy(owner);
function deploy() external override noProxy(msg.sender) returns (IPRBProxy proxy) {
proxy = _deploy({ owner: msg.sender });
}

/// @inheritdoc IPRBProxyRegistry
Expand All @@ -96,7 +104,7 @@ contract PRBProxyRegistry is IPRBProxyRegistry {
delete constructorParams;

// Associate the the owner with the proxy in the mapping.
proxies[owner] = proxy;
_proxies[owner] = proxy;

// Increment the seed.
// Using unchecked arithmetic here because this cannot realistically overflow, ever.
Expand All @@ -116,6 +124,11 @@ contract PRBProxyRegistry is IPRBProxyRegistry {
});
}

/// @inheritdoc IPRBProxyRegistry
function deployFor(address owner) public override noProxy(owner) returns (IPRBProxy proxy) {
proxy = _deploy(owner);
}

/*//////////////////////////////////////////////////////////////////////////
INTERNAL NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand All @@ -134,7 +147,7 @@ contract PRBProxyRegistry is IPRBProxyRegistry {
delete constructorParams;

// Associate the the owner with the proxy in the mapping.
proxies[owner] = proxy;
_proxies[owner] = proxy;

// Increment the seed.
// We're using unchecked arithmetic here because this cannot realistically overflow, ever.
Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/IPRBProxyRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ interface IPRBProxyRegistry {
/// @dev The proxy constructor fetches these parameters.
function constructorParams() external view returns (address owner, address target, bytes memory data);

/// @notice Retrieves the proxy for the provided owner.
/// @param owner The address of the user to make the query for.
function getProxy(address owner) external view returns (IPRBProxy proxy);

/// @notice The seed that will be used to deploy the next proxy for the provided origin.
/// @param origin The externally owned account (EOA) that is part of the CREATE2 salt.
function nextSeeds(address origin) external view returns (bytes32 seed);

/// @notice The address of the current proxy for the provided owner.
/// @param owner The address of the user to make the query for.
function proxies(address owner) external view returns (IPRBProxy proxy);

/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand Down
2 changes: 1 addition & 1 deletion test/registry/deploy-and-execute/deployAndExecute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ contract DeployAndExecute_Test is Registry_Test {
changePrank({ txOrigin: origin, msgSender: owner });
registry.deployAndExecute(target, data);

address actualProxyAddress = address(registry.proxies(owner));
address actualProxyAddress = address(registry.getProxy(owner));
address expectedProxyAddress = computeProxyAddress(origin, SEED_ZERO);
assertEq(actualProxyAddress, expectedProxyAddress, "proxy address mismatch");
}
Expand Down
2 changes: 1 addition & 1 deletion test/registry/deploy-for/deployFor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract DeployFor_Test is Registry_Test {
changePrank({ txOrigin: origin, msgSender: operator });
registry.deployFor(owner);

address actualProxyAddress = address(registry.proxies(owner));
address actualProxyAddress = address(registry.getProxy(owner));
address expectedProxyAddress = computeProxyAddress(origin, SEED_ZERO);
assertEq(actualProxyAddress, expectedProxyAddress, "proxy address mismatch");
}
Expand Down
2 changes: 1 addition & 1 deletion test/registry/deploy/deploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract Deploy_Test is Registry_Test {
function testFuzz_Deploy_UpdateProxies(address origin, address owner) external whenOwnerDoesNotHaveProxy {
changePrank({ txOrigin: origin, msgSender: owner });
registry.deploy();
address actualProxy = address(registry.proxies(owner));
address actualProxy = address(registry.getProxy(owner));
address expectedProxy = computeProxyAddress({ origin: origin, seed: SEED_ZERO });
assertEq(actualProxy, expectedProxy, "proxy mapping mismatch");
}
Expand Down
2 changes: 1 addition & 1 deletion test/utils/Precompiles.sol

Large diffs are not rendered by default.

0 comments on commit 5e0ad6b

Please sign in to comment.