-
Notifications
You must be signed in to change notification settings - Fork 32
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/relayer-arb-call
- Loading branch information
Showing
43 changed files
with
1,139 additions
and
258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,17 @@ | |
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
# [0.13.0](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-18) | ||
|
||
|
||
### Features | ||
|
||
* **contracts-rfq:** rework permisionless cancellation [SLT-489] ([#3382](https://github.com/synapsecns/sanguine/issues/3382)) ([7932f41](https://github.com/synapsecns/sanguine/commit/7932f416341a227db295c33f232efde89fd2c50c)) | ||
|
||
|
||
|
||
|
||
|
||
## [0.12.1](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-11) | ||
|
||
**Note:** Version bump only for package @synapsecns/contracts-rfq | ||
|
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
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
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.