Skip to content

Commit

Permalink
Merge pull request #118 from PaulRBerg/feat/get-proxy
Browse files Browse the repository at this point in the history
feat: get proxy
  • Loading branch information
PaulRBerg authored Jun 28, 2023
2 parents c4fc47b + 3ee2fc3 commit a2723b7
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 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
37 changes: 25 additions & 12 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 Down Expand Up @@ -98,7 +106,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 @@ -118,11 +126,16 @@ contract PRBProxyRegistry is IPRBProxyRegistry {
});
}

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

/*//////////////////////////////////////////////////////////////////////////
INTERNAL NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @dev See the documentation for the public functions that call this internal function.
/// @dev See the documentation for the user-facing functions that call this internal function.
function _deploy(address owner) internal returns (IPRBProxy proxy) {
// Load the next seed.
bytes32 seed = nextSeeds[tx.origin];
Expand All @@ -138,7 +151,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
Loading

0 comments on commit a2723b7

Please sign in to comment.