Skip to content

Commit

Permalink
Bridge implementation for sovereign chains + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Sep 16, 2024
1 parent 095fdf2 commit 184f75d
Show file tree
Hide file tree
Showing 6 changed files with 3,445 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/interfaces/IBasePolygonZkEVMGlobalExitRoot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ interface IBasePolygonZkEVMGlobalExitRoot {
*/
error OnlyAllowedContracts();

/**
* @dev Thrown when the caller is not the trusted sequencer
*/
error OnlyTrustedSequencer();

function updateExitRoot(bytes32 newRollupExitRoot) external;

function globalExitRootMap(
Expand Down
178 changes: 178 additions & 0 deletions contracts/v2/interfaces/IPolygonZkEVMBridgeL2SovereignChains.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// SPDX-License-Identifier: AGPL-3.0

pragma solidity ^0.8.20;
import "../../interfaces/IBasePolygonZkEVMGlobalExitRoot.sol";

interface IPolygonZkEVMBridgeL2SovereignChains {
/**
* @dev Thrown when the destination network is invalid
*/
error DestinationNetworkInvalid();

/**
* @dev Thrown when the amount does not match msg.value
*/
error AmountDoesNotMatchMsgValue();

/**
* @dev Thrown when user is bridging tokens and is also sending a value
*/
error MsgValueNotZero();

/**
* @dev Thrown when the Ether transfer on claimAsset fails
*/
error EtherTransferFailed();

/**
* @dev Thrown when the message transaction on claimMessage fails
*/
error MessageFailed();

/**
* @dev Thrown when the global exit root does not exist
*/
error GlobalExitRootInvalid();

/**
* @dev Thrown when the smt proof does not match
*/
error InvalidSmtProof();

/**
* @dev Thrown when an index is already claimed
*/
error AlreadyClaimed();

/**
* @dev Thrown when the owner of permit does not match the sender
*/
error NotValidOwner();

/**
* @dev Thrown when the spender of the permit does not match this contract address
*/
error NotValidSpender();

/**
* @dev Thrown when the amount of the permit does not match
*/
error NotValidAmount();

/**
* @dev Thrown when the permit data contains an invalid signature
*/
error NotValidSignature();

/**
* @dev Thrown when sender is not the rollup manager
*/
error OnlyRollupManager();

/**
* @dev Thrown when sender is not the bridge manager
* @notice Bridge manager can set custom mapping for any token
*/
error OnlyBridgeManager();

/**
* @dev Thrown when the permit data contains an invalid signature
*/
error NativeTokenIsEther();

/**
* @dev Thrown when the permit data contains an invalid signature
*/
error NoValueInMessagesOnGasTokenNetworks();

/**
* @dev Thrown when the permit data contains an invalid signature
*/
error GasTokenNetworkMustBeZeroOnEther();

/**
* @dev Thrown when the wrapped token deployment fails
*/
error FailedTokenWrappedDeployment();

/**
* @dev Thrown when bridge manager address is invalid
*/
error NotValidBridgeManager();

function wrappedTokenToTokenInfo(
address destinationAddress
) external view returns (uint32, address);

function updateGlobalExitRoot() external;

function activateEmergencyState() external;

function deactivateEmergencyState() external;

function bridgeAsset(
uint32 destinationNetwork,
address destinationAddress,
uint256 amount,
address token,
bool forceUpdateGlobalExitRoot,
bytes calldata permitData
) external payable;

function bridgeMessage(
uint32 destinationNetwork,
address destinationAddress,
bool forceUpdateGlobalExitRoot,
bytes calldata metadata
) external payable;

function bridgeMessageWETH(
uint32 destinationNetwork,
address destinationAddress,
uint256 amountWETH,
bool forceUpdateGlobalExitRoot,
bytes calldata metadata
) external;

function claimAsset(
bytes32[32] calldata smtProofLocalExitRoot,
bytes32[32] calldata smtProofRollupExitRoot,
uint256 globalIndex,
bytes32 mainnetExitRoot,
bytes32 rollupExitRoot,
uint32 originNetwork,
address originTokenAddress,
uint32 destinationNetwork,
address destinationAddress,
uint256 amount,
bytes calldata metadata
) external;

function claimMessage(
bytes32[32] calldata smtProofLocalExitRoot,
bytes32[32] calldata smtProofRollupExitRoot,
uint256 globalIndex,
bytes32 mainnetExitRoot,
bytes32 rollupExitRoot,
uint32 originNetwork,
address originAddress,
uint32 destinationNetwork,
address destinationAddress,
uint256 amount,
bytes calldata metadata
) external;

function initialize(
uint32 _networkID,
address _gasTokenAddress,
uint32 _gasTokenNetwork,
IBasePolygonZkEVMGlobalExitRoot _globalExitRootManager,
address _polygonRollupManager,
bytes memory _gasTokenMetadata,
address _bridgeManager
) external;

function getTokenMetadata(
address token
) external view returns (bytes memory);
}
11 changes: 11 additions & 0 deletions contracts/v2/interfaces/IPolygonZkEVMBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ interface IPolygonZkEVMBridgeV2 {
*/
error OnlyRollupManager();

/**
* @dev Thrown when sender is not the bridge manager
* @notice Bridge manager can set custom mapping for any token
*/
error OnlyBridgeManager();

/**
* @dev Thrown when the permit data contains an invalid signature
*/
Expand All @@ -89,6 +95,11 @@ interface IPolygonZkEVMBridgeV2 {
*/
error FailedTokenWrappedDeployment();

/**
* @dev Thrown when bridge manager address is invalid
*/
error NotValidBridgeManager();

function wrappedTokenToTokenInfo(
address destinationAddress
) external view returns (uint32, address);
Expand Down
Loading

0 comments on commit 184f75d

Please sign in to comment.