-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/sdk-rfq-endpoint
- Loading branch information
Showing
78 changed files
with
1,635 additions
and
422 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
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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
{ | ||
// This file (like all vscode metadata files) uses JSON with Comments (JSONC) format, which supports: | ||
// - Comments (both single and multi-line) | ||
// - Trailing commas | ||
// - More lenient syntax than standard JSON | ||
|
||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
|
||
// List of extensions which should be recommended for users of this workspace. | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"editorconfig.editorconfig", | ||
"juanblanco.solidity", | ||
"golang.go", | ||
"bierner.markdown-mermaid", | ||
"bpruitt-goddard.mermaid-markdown-syntax-highlighting", | ||
], | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {IAdminV2} from "./interfaces/IAdminV2.sol"; | ||
import {IAdminV2Errors} from "./interfaces/IAdminV2Errors.sol"; | ||
|
||
import {AccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol"; | ||
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {Address} from "@openzeppelin/contracts/utils/Address.sol"; | ||
|
||
contract AdminV2 is AccessControlEnumerable, IAdminV2, IAdminV2Errors { | ||
using SafeERC20 for IERC20; | ||
|
||
/// @notice Address reserved for native gas token (ETH on Ethereum and most L2s, AVAX on Avalanche, etc) | ||
address public constant NATIVE_GAS_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; | ||
|
||
/// @notice Role identifier for Quoter API's off-chain authentication. | ||
/// @dev Only addresses with this role can post FastBridge quotes to the API. | ||
bytes32 public constant QUOTER_ROLE = keccak256("QUOTER_ROLE"); | ||
|
||
/// @notice Role identifier for Prover's on-chain authentication in FastBridge. | ||
/// @dev Only addresses with this role can provide proofs that a FastBridge request has been relayed. | ||
bytes32 public constant PROVER_ROLE = keccak256("PROVER_ROLE"); | ||
|
||
/// @notice Role identifier for Guard's on-chain authentication in FastBridge. | ||
/// @dev Only addresses with this role can dispute submitted relay proofs during the dispute period. | ||
bytes32 public constant GUARD_ROLE = keccak256("GUARD_ROLE"); | ||
|
||
/// @notice Role identifier for Canceler's on-chain authentication in FastBridge. | ||
/// @dev Only addresses with this role can cancel a FastBridge transaction without the cancel delay. | ||
bytes32 public constant CANCELER_ROLE = keccak256("CANCELER_ROLE"); | ||
|
||
/// @notice Role identifier for Governor's on-chain administrative authority. | ||
/// @dev Only addresses with this role can perform administrative tasks within the contract. | ||
bytes32 public constant GOVERNOR_ROLE = keccak256("GOVERNOR_ROLE"); | ||
|
||
/// @notice Denominator for fee rates, represents 100%. | ||
uint256 public constant FEE_BPS = 1e6; | ||
/// @notice Maximum protocol fee rate: 1% on origin amount. | ||
uint256 public constant FEE_RATE_MAX = 0.01e6; | ||
|
||
/// @notice Minimum cancel delay that can be set by the governor. | ||
uint256 public constant MIN_CANCEL_DELAY = 1 hours; | ||
/// @notice Default cancel delay set during the contract deployment. | ||
uint256 public constant DEFAULT_CANCEL_DELAY = 1 days; | ||
|
||
/// @notice Protocol fee rate taken on origin amount deposited in origin chain | ||
uint256 public protocolFeeRate; | ||
|
||
/// @notice Protocol fee amounts accumulated | ||
mapping(address => uint256) public protocolFees; | ||
|
||
/// @notice Delay for a transaction after which it could be permisionlessly cancelled | ||
uint256 public cancelDelay; | ||
|
||
/// @notice This is deprecated and should not be used. | ||
/// @dev Use ZapNative V2 requests instead. | ||
uint256 public immutable chainGasAmount = 0; | ||
|
||
constructor(address _owner) { | ||
_grantRole(DEFAULT_ADMIN_ROLE, _owner); | ||
_setCancelDelay(DEFAULT_CANCEL_DELAY); | ||
} | ||
|
||
/// @notice Allows the contract governor to set the cancel delay. The cancel delay is the time after the transaction | ||
/// deadline after which it can be permissionlessly cancelled, if it hasn't been proven by any of the Relayers. | ||
function setCancelDelay(uint256 newCancelDelay) external onlyRole(GOVERNOR_ROLE) { | ||
_setCancelDelay(newCancelDelay); | ||
} | ||
|
||
/// @notice Allows the contract governor to set the protocol fee rate. The protocol fee is taken from the origin | ||
/// amount only for completed and claimed transactions. | ||
/// @dev The protocol fee is abstracted away from the relayers, they always operate using the amounts after fees: | ||
/// what they see as the origin amount emitted in the log is what they get credited with. | ||
function setProtocolFeeRate(uint256 newFeeRate) external onlyRole(GOVERNOR_ROLE) { | ||
if (newFeeRate > FEE_RATE_MAX) revert FeeRateAboveMax(); | ||
uint256 oldFeeRate = protocolFeeRate; | ||
protocolFeeRate = newFeeRate; | ||
emit FeeRateUpdated(oldFeeRate, newFeeRate); | ||
} | ||
|
||
/// @notice Allows the contract governor to sweep the accumulated protocol fees in the contract. | ||
function sweepProtocolFees(address token, address recipient) external onlyRole(GOVERNOR_ROLE) { | ||
uint256 feeAmount = protocolFees[token]; | ||
if (feeAmount == 0) return; // skip if no accumulated fees | ||
|
||
protocolFees[token] = 0; | ||
emit FeesSwept(token, recipient, feeAmount); | ||
/// Sweep the fees as the last transaction action | ||
if (token == NATIVE_GAS_TOKEN) { | ||
Address.sendValue(payable(recipient), feeAmount); | ||
} else { | ||
IERC20(token).safeTransfer(recipient, feeAmount); | ||
} | ||
} | ||
|
||
/// @notice Internal function to set the cancel delay. Security checks are performed outside of this function. | ||
function _setCancelDelay(uint256 newCancelDelay) private { | ||
if (newCancelDelay < MIN_CANCEL_DELAY) revert CancelDelayBelowMin(); | ||
uint256 oldCancelDelay = cancelDelay; | ||
cancelDelay = newCancelDelay; | ||
emit CancelDelayUpdated(oldCancelDelay, newCancelDelay); | ||
} | ||
} |
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,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
interface IAdminV2 { | ||
event CancelDelayUpdated(uint256 oldCancelDelay, uint256 newCancelDelay); | ||
event FeeRateUpdated(uint256 oldFeeRate, uint256 newFeeRate); | ||
event FeesSwept(address token, address recipient, uint256 amount); | ||
|
||
function setCancelDelay(uint256 newCancelDelay) external; | ||
|
||
function setProtocolFeeRate(uint256 newFeeRate) external; | ||
|
||
function sweepProtocolFees(address token, address recipient) external; | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/contracts-rfq/contracts/interfaces/IAdminV2Errors.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,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
interface IAdminV2Errors { | ||
error CancelDelayBelowMin(); | ||
error FeeRateAboveMax(); | ||
} |
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.