Skip to content

Commit

Permalink
Merge branch 'master' into feat/relayer-arb-call
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Nov 25, 2024
2 parents 884d9ae + 91dee92 commit 5a6cb3c
Show file tree
Hide file tree
Showing 37 changed files with 1,521 additions and 214 deletions.
51 changes: 51 additions & 0 deletions packages/contracts-rfq/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,57 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.14.5](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-25)

**Note:** Version bump only for package @synapsecns/contracts-rfq





## [0.14.4](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-24)

**Note:** Version bump only for package @synapsecns/contracts-rfq





## [0.14.3](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-23)

**Note:** Version bump only for package @synapsecns/contracts-rfq





## [0.14.2](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-22)

**Note:** Version bump only for package @synapsecns/contracts-rfq





## [0.14.1](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-22)

**Note:** Version bump only for package @synapsecns/contracts-rfq





# [0.14.0](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-22)


### Features

* **contracts-rfq:** Token Zap [SLT-389] ([#3352](https://github.com/synapsecns/sanguine/issues/3352)) ([743e859](https://github.com/synapsecns/sanguine/commit/743e859e3274ed449c6410441bd664ff2aaf9740)), closes [#3382](https://github.com/synapsecns/sanguine/issues/3382)





# [0.13.0](https://github.com/synapsecns/sanguine/compare/@synapsecns/[email protected]...@synapsecns/[email protected]) (2024-11-18)


Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/contracts/Admin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity ^0.8.20;

import {AccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";

import {UniversalTokenLib} from "./libs/UniversalToken.sol";
import {IAdmin} from "./interfaces/IAdmin.sol";
import {UniversalTokenLib} from "./libs/UniversalToken.sol";

contract Admin is IAdmin, AccessControlEnumerable {
using UniversalTokenLib for address;
Expand Down
61 changes: 33 additions & 28 deletions packages/contracts-rfq/contracts/AdminV2.sol
Original file line number Diff line number Diff line change
@@ -1,100 +1,105 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

// ════════════════════════════════════════════════ INTERFACES ═════════════════════════════════════════════════════

import {IAdminV2} from "./interfaces/IAdminV2.sol";
import {IAdminV2Errors} from "./interfaces/IAdminV2Errors.sol";

// ═════════════════════════════════════════════ EXTERNAL IMPORTS ══════════════════════════════════════════════════

import {AccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

/// @title AdminV2
/// @notice Provides administrative functions and controls for managing the FastBridgeV2 contract,
/// including access control and configuration settings.
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)
/// @notice The address reserved for the 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.
/// @notice The role identifier for the 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.
/// @notice The role identifier for the 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.
/// @notice The role identifier for the 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.
/// @notice The role identifier for the 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.
/// @notice The role identifier for the 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%.
/// @notice The denominator for fee rates, representing 100%.
uint256 public constant FEE_BPS = 1e6;
/// @notice Maximum protocol fee rate: 1% on origin amount.
/// @notice The maximum protocol fee rate: 1% of the origin amount.
uint256 public constant FEE_RATE_MAX = 0.01e6;

/// @notice Minimum cancel delay that can be set by the governor.
/// @notice The 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.
/// @notice The default cancel delay set during contract deployment.
uint256 public constant DEFAULT_CANCEL_DELAY = 1 days;

/// @notice Protocol fee rate taken on origin amount deposited in origin chain
/// @notice The protocol fee rate taken on the origin amount deposited in the origin chain.
uint256 public protocolFeeRate;

/// @notice Protocol fee amounts accumulated
/// @notice The accumulated protocol fee amounts.
mapping(address => uint256) public protocolFees;

/// @notice Delay for a transaction after which it could be permisionlessly cancelled
/// @notice The delay period after which a transaction can be permissionlessly cancelled.
uint256 public cancelDelay;

/// @notice This is deprecated and should not be used.
/// @notice This variable 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);
constructor(address defaultAdmin) {
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_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.
/// @inheritdoc IAdminV2
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.
/// @inheritdoc IAdminV2
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.
/// @inheritdoc IAdminV2
function sweepProtocolFees(address token, address recipient) external onlyRole(GOVERNOR_ROLE) {
// Early exit if no accumulated fees.
uint256 feeAmount = protocolFees[token];
if (feeAmount == 0) return; // skip if no accumulated fees

if (feeAmount == 0) return;
// Reset the accumulated fees first.
protocolFees[token] = 0;
emit FeesSwept(token, recipient, feeAmount);
/// Sweep the fees as the last transaction action
// 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.
/// @notice Internal logic to set the cancel delay. Security checks are performed outside of this function.
/// @dev This function is marked as private to prevent child contracts from calling it directly.
function _setCancelDelay(uint256 newCancelDelay) private {
if (newCancelDelay < MIN_CANCEL_DELAY) revert CancelDelayBelowMin();
uint256 oldCancelDelay = cancelDelay;
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-rfq/contracts/FastBridge.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "./libs/Errors.sol";
import {UniversalTokenLib} from "./libs/UniversalToken.sol";
Expand Down
Loading

0 comments on commit 5a6cb3c

Please sign in to comment.