Skip to content

Commit

Permalink
feat: configurable deployBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Dec 4, 2024
1 parent 9fe5765 commit 76db11d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
19 changes: 19 additions & 0 deletions packages/contracts-rfq/contracts/AdminV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,32 @@ contract AdminV2 is AccessControlEnumerable, IAdminV2, IAdminV2Errors {
/// @notice The delay period after which a transaction can be permissionlessly cancelled.
uint256 public cancelDelay;

/// @notice The block number at which the contract was deployed.
/// @dev This used to be immutable in V1, but was adjusted to be mutable in V2 for chains like Arbitrum that
/// implement the `block.number` as the underlying L1 block number rather than the chain's native block number.
/// This is exposed for conveniece for off-chain indexers that need to know the deployment block.
uint256 public deployBlock;

/// @notice This variable is deprecated and should not be used.
/// @dev Use ZapNative V2 requests instead.
uint256 public immutable chainGasAmount = 0;

constructor(address defaultAdmin) {
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
_setCancelDelay(DEFAULT_CANCEL_DELAY);
_setDeployBlock(block.number);
}

/// @inheritdoc IAdminV2
function setCancelDelay(uint256 newCancelDelay) external onlyRole(GOVERNOR_ROLE) {
_setCancelDelay(newCancelDelay);
}

/// @inheritdoc IAdminV2
function setDeployBlock(uint256 blockNumber) external onlyRole(DEFAULT_ADMIN_ROLE) {
_setDeployBlock(blockNumber);
}

/// @inheritdoc IAdminV2
function setProtocolFeeRate(uint256 newFeeRate) external onlyRole(GOVERNOR_ROLE) {
if (newFeeRate > FEE_RATE_MAX) revert FeeRateAboveMax();
Expand Down Expand Up @@ -106,4 +118,11 @@ contract AdminV2 is AccessControlEnumerable, IAdminV2, IAdminV2Errors {
cancelDelay = newCancelDelay;
emit CancelDelayUpdated(oldCancelDelay, newCancelDelay);
}

/// @notice Internal logic to set the deploy block. Security checks are performed outside of this function.
/// @dev This function is marked as private to prevent child contracts from calling it directly.
function _setDeployBlock(uint256 blockNumber) private {
deployBlock = blockNumber;
emit DeployBlockSet(blockNumber);
}
}
6 changes: 1 addition & 5 deletions packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ contract FastBridgeV2 is AdminV2, MulticallTarget, IFastBridgeV2, IFastBridgeV2E
/// @notice This variable is deprecated and should not be used.
/// @dev Replaced by senderNonces.
uint256 public immutable nonce = 0;
/// @notice The block number at which this contract was deployed.
uint256 public immutable deployBlock;

/// @notice Initializes the FastBridgeV2 contract with the provided default admin,
/// sets the default cancel delay, and records the deploy block number.
constructor(address defaultAdmin) AdminV2(defaultAdmin) {
deployBlock = block.number;
}
constructor(address defaultAdmin) AdminV2(defaultAdmin) {}

// ══════════════════════════════════════ EXTERNAL MUTABLE (USER FACING) ═══════════════════════════════════════════

Expand Down
6 changes: 6 additions & 0 deletions packages/contracts-rfq/contracts/interfaces/IAdminV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ pragma solidity ^0.8.4;

interface IAdminV2 {
event CancelDelayUpdated(uint256 oldCancelDelay, uint256 newCancelDelay);
event DeployBlockSet(uint256 blockNumber);
event FeeRateUpdated(uint256 oldFeeRate, uint256 newFeeRate);
event FeesSwept(address token, address recipient, uint256 amount);

/// @notice Allows the governor to set the cancel delay. The cancel delay is the time period after the transaction
/// deadline during which a transaction can be permissionlessly cancelled if it hasn't been proven by any Relayer.
function setCancelDelay(uint256 newCancelDelay) external;

/// @notice Allows the default admin to set the deploy block.
/// @dev This is only relevant for chains like Arbitrum that implement the `block.number` as the underlying L1
/// block number rather than the chain's native block number.
function setDeployBlock(uint256 blockNumber) external;

/// @notice Allows the governor to set the protocol fee rate. The protocol fee is taken from the origin
/// amount and is only applied to completed and claimed transactions.
/// @dev The protocol fee is abstracted away from the relayers; they always operate using the amounts after fees.
Expand Down

0 comments on commit 76db11d

Please sign in to comment.