forked from sphinx-labs/sphinx
-
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.
- Loading branch information
1 parent
4c2db15
commit e5b9f81
Showing
13 changed files
with
231 additions
and
27 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,6 @@ | ||
--- | ||
'@chugsplash/contracts': minor | ||
'@chugsplash/core': patch | ||
--- | ||
|
||
Add ChugSplashClaimer which will exist on L1 |
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,140 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.15; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { ICrossChainAdapter } from "./interfaces/ICrossChainAdapter.sol"; | ||
import { ChugSplashRegistry } from "./ChugSplashRegistry.sol"; | ||
import { Version } from "./Semver.sol"; | ||
|
||
/** | ||
* @title ChugSplashClaimer | ||
*/ | ||
contract ChugSplashClaimer is Ownable { | ||
event OrganizationIDClaimed(bytes32 indexed orgID, address owner); | ||
|
||
event RegistrationInitiated( | ||
bytes32 indexed orgID, | ||
address indexed originEndpoint, | ||
uint32 indexed destDomainID, | ||
address owner, | ||
address caller | ||
); | ||
|
||
event InitiatorApprovalChanged(bytes32 indexed orgID, address indexed initiator, bool approved); | ||
|
||
event CrossChainAdapterChanged( | ||
address indexed originEndpoint, | ||
uint32 indexed destDomainID, | ||
address crossChainAdapter | ||
); | ||
|
||
ChugSplashRegistry public immutable registry; | ||
|
||
mapping(bytes32 => bool) public organizationIDs; | ||
|
||
mapping(bytes32 => address) public orgIDOwners; | ||
|
||
mapping(bytes32 => mapping(address => bool)) public approvedInitiators; | ||
|
||
// Origin endpoint => destination Domain ID => crossChainAdapter | ||
mapping(address => mapping(uint32 => address)) public crossChainAdapters; | ||
|
||
/** | ||
* @param _owner Address of the owner of the registry. | ||
*/ | ||
constructor(address _owner, ChugSplashRegistry _registry) { | ||
registry = _registry; | ||
_transferOwnership(_owner); | ||
} | ||
|
||
function claimOrganizationID(bytes32 _orgID, address _owner) external { | ||
require(!organizationIDs[_orgID], "ChugSplashClaimer: orgID already claimed"); | ||
organizationIDs[_orgID] = true; | ||
orgIDOwners[_orgID] = _owner; | ||
emit OrganizationIDClaimed(_orgID, _owner); | ||
} | ||
|
||
struct CrossChainMessageInfo { | ||
address payable originEndpoint; | ||
uint32 destDomainID; | ||
uint256 relayerFee; | ||
} | ||
|
||
struct RegistrationInfo { | ||
Version version; | ||
address owner; | ||
bytes managerInitializerData; | ||
} | ||
|
||
function initiateRegistration( | ||
bytes32 _orgID, | ||
CrossChainMessageInfo[] memory _messages, | ||
RegistrationInfo[] memory _registrationInfo | ||
) external payable { | ||
require( | ||
msg.sender == orgIDOwners[_orgID] || approvedInitiators[_orgID][msg.sender], | ||
"ChugSplashClaimer: caller not approved" | ||
); | ||
|
||
for (uint i = 0; i < _messages.length; i++) { | ||
CrossChainMessageInfo memory messageInfo = _messages[i]; | ||
RegistrationInfo memory registration = _registrationInfo[i]; | ||
Version memory version = registration.version; | ||
|
||
address managerImpl = registry.versions(version.major, version.minor, version.patch); | ||
require( | ||
registry.managerImplementations(managerImpl), | ||
"ChugSplashClaimer: invalid manager version" | ||
); | ||
|
||
address crossChainAdapter = crossChainAdapters[messageInfo.originEndpoint][ | ||
messageInfo.destDomainID | ||
]; | ||
require( | ||
crossChainAdapter != address(0), | ||
"ChugSplashClaimer: invalid crossChain adapter" | ||
); | ||
|
||
bytes memory registryCalldata = abi.encodeCall( | ||
ChugSplashRegistry.finalizeRegistration, | ||
(_orgID, registration.owner, version, registration.managerInitializerData) | ||
); | ||
|
||
(bool success, ) = crossChainAdapter.delegatecall( | ||
abi.encodeCall( | ||
ICrossChainAdapter.initiateRegistration, | ||
( | ||
messageInfo.originEndpoint, | ||
messageInfo.destDomainID, | ||
messageInfo.relayerFee, | ||
registryCalldata | ||
) | ||
) | ||
); | ||
require(success, "ChugSplashClaimer: failed to initiate registration"); | ||
|
||
emit RegistrationInitiated( | ||
_orgID, | ||
messageInfo.originEndpoint, | ||
messageInfo.destDomainID, | ||
registration.owner, | ||
msg.sender | ||
); | ||
} | ||
} | ||
|
||
function setInitiatorApproval(bytes32 _orgID, address _initiator, bool _approved) external { | ||
require(msg.sender == orgIDOwners[_orgID], "ChugSplashClaimer: caller not org ID owner"); | ||
approvedInitiators[_orgID][_initiator] = _approved; | ||
emit InitiatorApprovalChanged(_orgID, _initiator, _approved); | ||
} | ||
|
||
function setCrossChainAdapter( | ||
address _originEndpoint, | ||
uint32 _destDomainID, | ||
address _crossChainAdapter | ||
) external onlyOwner { | ||
crossChainAdapters[_originEndpoint][_destDomainID] = _crossChainAdapter; | ||
emit CrossChainAdapterChanged(_originEndpoint, _destDomainID, _crossChainAdapter); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
packages/contracts/contracts/adapters/cross-chain/ConnextCrossChainAdapter.sol
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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.15; | ||
|
||
import { ICrossChainAdapter } from "../../interfaces/ICrossChainAdapter.sol"; | ||
import { IConnext } from "@connext/interfaces/core/IConnext.sol"; | ||
|
||
/** | ||
* @title ConnextCrossChainAdapter | ||
*/ | ||
contract ConnextCrossChainAdapter is ICrossChainAdapter { | ||
address public immutable registry; | ||
|
||
constructor(address _registry) { | ||
registry = _registry; | ||
} | ||
|
||
function initiateRegistration( | ||
address payable _originEndpoint, | ||
uint32 _destDomainID, | ||
uint256 _relayerFee, | ||
bytes memory _calldata | ||
) external { | ||
IConnext(_originEndpoint).xcall{ value: _relayerFee }( | ||
_destDomainID, // _destination: Domain ID of the destination chain | ||
registry, // _to: address of the target contract on the destination chain | ||
address(0), // _asset: address of the token contract (this is unused) | ||
msg.sender, // _delegate: address that can revert or forceLocal on destination | ||
0, // _amount: amount of tokens to transfer (this is unused) | ||
0, // _slippage: this is unused | ||
_calldata // _callData: the encoded calldata to send | ||
); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/contracts/contracts/interfaces/ICrossChainAdapter.sol
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,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.15; | ||
|
||
/** | ||
* @title ICrossChainAdapter | ||
*/ | ||
interface ICrossChainAdapter { | ||
function initiateRegistration( | ||
address payable _originEndpoint, | ||
uint32 _destinationDomainID, | ||
uint256 _relayerFee, | ||
bytes memory _calldata | ||
) external; | ||
} |
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
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
Oops, something went wrong.