-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from metadock/feat/dock-registry
Dock Registry implementation
- Loading branch information
Showing
36 changed files
with
686 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
AddToAllowlist_Unit_Concrete_Test:test_AddToAllowlist() (gas: 178178) | ||
AddToAllowlist_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 12955) | ||
AddToAllowlist_Unit_Concrete_Test:test_RevertWhen_InvalidZeroCodeModule() (gas: 13123) | ||
CancelInvoice_Integration_Concret_Test:test_CancelInvoice_PaymentMethodLinearStream_StatusOngoing() (gas: 326597) | ||
CancelInvoice_Integration_Concret_Test:test_CancelInvoice_PaymentMethodLinearStream_StatusPending() (gas: 30566) | ||
CancelInvoice_Integration_Concret_Test:test_CancelInvoice_PaymentMethodTranchedStream_StatusOngoing() (gas: 445110) | ||
CancelInvoice_Integration_Concret_Test:test_CancelInvoice_PaymentMethodTranchedStream_StatusPending() (gas: 30566) | ||
CancelInvoice_Integration_Concret_Test:test_CancelInvoice_PaymentMethodTransfer() (gas: 30497) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_InvoiceIsCanceled() (gas: 27177) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_InvoiceIsPaid() (gas: 49663) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodLinearStream_StatusOngoing_SenderNoInitialtStreamSender() (gas: 285668) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodLinearStream_StatusPending_SenderNotInvoiceRecipient() (gas: 20666) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTranchedStream_StatusOngoing_SenderNoInitialtStreamSender() (gas: 402986) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTranchedStream_StatusPending_SenderNotInvoiceRecipient() (gas: 20642) | ||
CancelInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTransfer_SenderNotInvoiceRecipient() (gas: 20575) | ||
CreateContainer_Unit_Concrete_Test:test_CreateContainer_DockIdNonZero() (gas: 2079188) | ||
CreateContainer_Unit_Concrete_Test:test_CreateContainer_DockIdZero() (gas: 1066370) | ||
CreateContainer_Unit_Concrete_Test:test_RevertWhen_CallerNotDockOwner() (gas: 1084452) | ||
CreateInvoice_Integration_Concret_Test:test_CreateInvoice_LinearStream() (gas: 251262) | ||
CreateInvoice_Integration_Concret_Test:test_CreateInvoice_PaymentMethodOneOffTransfer() (gas: 251466) | ||
CreateInvoice_Integration_Concret_Test:test_CreateInvoice_RecurringTransfer() (gas: 252617) | ||
CreateInvoice_Integration_Concret_Test:test_CreateInvoice_Tranched() (gas: 252890) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_CallerNotContract() (gas: 89343) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_EndTimeInThePast() (gas: 102376) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_NonCompliantContainer() (gas: 92598) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodLinearStream_PaymentAssetNativeToken() (gas: 102494) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodRecurringTransfer_PaymentIntervalTooShortForSelectedRecurrence() (gas: 103184) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTranchedStream_PaymentAssetNativeToken() (gas: 103664) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTranchedStream_PaymentIntervalTooShortForSelectedRecurrence() (gas: 103228) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTranchedStream_RecurrenceSetToOneOff() (gas: 101872) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_StartTimeGreaterThanEndTime() (gas: 101700) | ||
CreateInvoice_Integration_Concret_Test:test_RevertWhen_ZeroPaymentAmount() (gas: 81059) | ||
DisableModule_Unit_Concrete_Test:test_DisableModule() (gas: 177591) | ||
DisableModule_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 16425) | ||
EnableModule_Unit_Concrete_Test:test_EnableModule() (gas: 33937) | ||
EnableModule_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 16422) | ||
EnableModule_Unit_Concrete_Test:test_RevertWhen_ModuleNotAllowlisted() (gas: 24667) | ||
Execute_Unit_Concrete_Test:test_Execute() (gas: 84136) | ||
Execute_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 18992) | ||
Execute_Unit_Concrete_Test:test_RevertWhen_ModuleNotEnabled() (gas: 19065) | ||
PayInvoice_Integration_Concret_Test:test_PayInvoice_PaymentMethodLinearStream() (gas: 309543) | ||
PayInvoice_Integration_Concret_Test:test_PayInvoice_PaymentMethodTranchedStream() (gas: 434948) | ||
PayInvoice_Integration_Concret_Test:test_PayInvoice_PaymentMethodTransfer_ERC20Token_Recurring() (gas: 87177) | ||
PayInvoice_Integration_Concret_Test:test_PayInvoice_PaymentMethodTransfer_NativeToken_OneOff() (gas: 63518) | ||
PayInvoice_Integration_Concret_Test:test_RevertWhen_InvoiceAlreadyPaid() (gas: 62518) | ||
PayInvoice_Integration_Concret_Test:test_RevertWhen_InvoiceCanceled() (gas: 29675) | ||
PayInvoice_Integration_Concret_Test:test_RevertWhen_InvoiceNull() (gas: 17874) | ||
PayInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTransfer_NativeTokenTransferFails() (gas: 166006) | ||
PayInvoice_Integration_Concret_Test:test_RevertWhen_PaymentMethodTransfer_PaymentAmountLessThanInvoiceValue() (gas: 31961) | ||
Receive_Unit_Concrete_Test:test_Receive() (gas: 20732) | ||
RemoveFromAllowlist_Unit_Concrete_Test:test_AddToAllowlist() (gas: 22211) | ||
RemoveFromAllowlist_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 12982) | ||
TransferContainerOwnership_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 1083749) | ||
TransferContainerOwnership_Unit_Concrete_Test:test_RevertWhen_InvalidOwnerZeroAddress() (gas: 1081714) | ||
TransferContainerOwnership_Unit_Concrete_Test:test_transferContainerOwnership() (gas: 1089571) | ||
WithdrawERC20_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 16382) | ||
WithdrawERC20_Unit_Concrete_Test:test_RevertWhen_InsufficientERC20ToWithdraw() (gas: 24022) | ||
WithdrawERC20_Unit_Concrete_Test:test_WithdrawERC20() (gas: 90472) | ||
WithdrawLinearStream_Integration_Concret_Test:test_WithdrawLinearStream() (gas: 317093) | ||
WithdrawNative_Unit_Concrete_Test:test_RevertWhen_CallerNotOwner() (gas: 16402) | ||
WithdrawNative_Unit_Concrete_Test:test_RevertWhen_InsufficientNativeToWithdraw() (gas: 16391) | ||
WithdrawNative_Unit_Concrete_Test:test_WithdrawNative() (gas: 37436) | ||
WithdrawTranchedStream_Integration_Concret_Test:test_WithdrawTranchedStream() (gas: 437924) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule openzeppelin-contracts-upgradeable
added at
723f8c
Submodule openzeppelin-foundry-upgrades
added at
4cd15f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.26; | ||
|
||
import { Ownable } from "./abstracts/Ownable.sol"; | ||
import { IDockRegistry } from "./interfaces/IDockRegistry.sol"; | ||
import { Container } from "./Container.sol"; | ||
import { ModuleKeeper } from "./ModuleKeeper.sol"; | ||
import { Errors } from "./libraries/Errors.sol"; | ||
|
||
/// @title DockRegistry | ||
/// @notice See the documentation in {IDockRegistry} | ||
contract DockRegistry is IDockRegistry, Ownable { | ||
/*////////////////////////////////////////////////////////////////////////// | ||
PUBLIC STORAGE | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @inheritdoc IDockRegistry | ||
ModuleKeeper public override moduleKeeper; | ||
|
||
/// @inheritdoc IDockRegistry | ||
mapping(uint256 dockId => address owner) public override ownerOfDock; | ||
|
||
/// @inheritdoc IDockRegistry | ||
mapping(address container => uint256 dockId) public override dockIdOfContainer; | ||
|
||
/// @inheritdoc IDockRegistry | ||
mapping(address container => address owner) public override ownerOfContainer; | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
PRIVATE STORAGE | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Counter to keep track of the next dock ID | ||
uint256 private _dockNextId; | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
CONSTRUCTOR | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Initializes the address of the {ModuleKeeper} contract, registry owner and sets the next dock ID to start from 1 | ||
constructor(address _initialOwner, ModuleKeeper _moduleKeeper) Ownable(_initialOwner) { | ||
_dockNextId = 1; | ||
moduleKeeper = _moduleKeeper; | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
NON-CONSTANT FUNCTIONS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @inheritdoc IDockRegistry | ||
function createContainer( | ||
uint256 dockId, | ||
address owner, | ||
address[] calldata initialModules | ||
) public returns (address container) { | ||
// Checks: a new dock must be created first | ||
if (dockId == 0) { | ||
// Store the ID of the next dock | ||
dockId = _dockNextId; | ||
|
||
// Effects: set the owner of the freshly created dock | ||
ownerOfDock[dockId] = msg.sender; | ||
|
||
// Effects: increment the next dock ID | ||
// Use unchecked because the dock ID cannot realistically overflow | ||
unchecked { | ||
_dockNextId++; | ||
} | ||
} else { | ||
// Checks: `msg.sender` is the dock owner | ||
if (ownerOfDock[dockId] != msg.sender) { | ||
revert Errors.CallerNotDockOwner(); | ||
} | ||
} | ||
|
||
// Interactions: deploy a new {Container} | ||
container = | ||
address(new Container({ _dockRegistry: DockRegistry(address(this)), _initialModules: initialModules })); | ||
|
||
// Assign the ID of the dock to which the new container belongs | ||
dockIdOfContainer[container] = dockId; | ||
|
||
// Assign the owner of the container | ||
ownerOfContainer[container] = owner; | ||
|
||
// Log the {Container} creation | ||
emit ContainerCreated(owner, dockId, container, initialModules); | ||
} | ||
|
||
/// @inheritdoc IDockRegistry | ||
function transferContainerOwnership(address container, address newOwner) external { | ||
// Checks: `msg.sender` is the current owner of the {Container} | ||
address currentOwner = ownerOfContainer[container]; | ||
if (msg.sender != currentOwner) { | ||
revert Errors.CallerNotContainerOwner(); | ||
} | ||
|
||
// Checks: the new owner is not the zero address | ||
if (newOwner == address(0)) { | ||
revert Errors.InvalidOwnerZeroAddress(); | ||
} | ||
|
||
// Effects: update container's ownership | ||
ownerOfContainer[container] = newOwner; | ||
|
||
// Log the ownership transfer | ||
emit ContainerOwnershipTransferred({ container: container, oldOwner: currentOwner, newOwner: newOwner }); | ||
} | ||
|
||
/// @inheritdoc IDockRegistry | ||
function transferDockOwnership(uint256 dockId, address newOwner) external { | ||
// Checks: `msg.sender` is the current owner of the dock | ||
address currentOwner = ownerOfDock[dockId]; | ||
if (msg.sender != currentOwner) { | ||
revert Errors.CallerNotDockOwner(); | ||
} | ||
|
||
// Effects: update dock's ownership | ||
ownerOfDock[dockId] = newOwner; | ||
|
||
// Log the ownership transfer | ||
emit DockOwnershipTransferred({ dockId: dockId, oldOwner: currentOwner, newOwner: newOwner }); | ||
} | ||
|
||
/// @inheritdoc IDockRegistry | ||
function updateModuleKeeper(ModuleKeeper newModuleKeeper) external onlyOwner { | ||
// Effects: update the {ModuleKeeper} address | ||
moduleKeeper = newModuleKeeper; | ||
|
||
// Log the update | ||
emit ModuleKeeperUpdated(newModuleKeeper); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.