Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 59 additions & 21 deletions contracts/CDKValidium.sol
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ contract CDKValidium is
// Indicates if forced batches are disallowed
bool public isForcedBatchDisallowed;

// Indicates if the MATIC transfer is disabled on sequencing/verifying (default: false)
bool public isFeeTransferDisabled;

/**
* @dev Emitted when the trusted sequencer sends a new batch of transactions
*/
Expand Down Expand Up @@ -338,6 +341,11 @@ contract CDKValidium is
*/
event ActivateForceBatches();

/**
* @dev Emitted when admin updates state of matic transfers
*/
event SetMaticTransferDisabled(bool feeTransferDisabled);

/**
* @dev Emitted when the admin starts the two-step transfer role setting a new pending admin
*/
Expand Down Expand Up @@ -594,8 +602,6 @@ contract CDKValidium is
revert ForceBatchesOverflow();
}

uint256 nonForcedBatchesSequenced = batchesNum -
(currentLastForceBatchSequenced - initLastForceBatchSequenced);

// Update sequencedBatches mapping
sequencedBatches[currentBatchSequenced] = SequencedBatchData({
Expand All @@ -611,12 +617,18 @@ contract CDKValidium is
if (currentLastForceBatchSequenced != initLastForceBatchSequenced)
lastForceBatchSequenced = currentLastForceBatchSequenced;

if (!isFeeTransferDisabled) {

uint256 nonForcedBatchesSequenced = batchesNum -
(currentLastForceBatchSequenced - initLastForceBatchSequenced);

matic.safeTransferFrom(
msg.sender,
address(this),
batchFee * nonForcedBatchesSequenced
);
}
// Pay collateral for every non-forced batch submitted
matic.safeTransferFrom(
msg.sender,
address(this),
batchFee * nonForcedBatchesSequenced
);

// Consolidate pending state if possible
_tryConsolidatePendingState();
Expand Down Expand Up @@ -822,11 +834,13 @@ contract CDKValidium is
}

// Get MATIC reward
matic.safeTransfer(
msg.sender,
calculateRewardPerBatch() *
(finalNewBatch - currentLastVerifiedBatch)
);
if (!isFeeTransferDisabled) {
matic.safeTransfer(
msg.sender,
calculateRewardPerBatch() *
(finalNewBatch - currentLastVerifiedBatch)
);
}
}

/**
Expand Down Expand Up @@ -1022,18 +1036,21 @@ contract CDKValidium is
bytes calldata transactions,
uint256 maticAmount
) public isForceBatchAllowed ifNotEmergencyState {
// Calculate matic collateral
uint256 maticFee = getForcedBatchFee();

if (maticFee > maticAmount) {
revert NotEnoughMaticAmount();
}

if (transactions.length > _MAX_FORCE_BATCH_BYTE_LENGTH) {
revert TransactionsLengthAboveMax();
}

matic.safeTransferFrom(msg.sender, address(this), maticFee);
if (!isFeeTransferDisabled) {
// Calculate matic collateral
uint256 maticFee = getForcedBatchFee();

if (maticFee > maticAmount) {
revert NotEnoughMaticAmount();
}

matic.safeTransferFrom(msg.sender, address(this), maticFee);
}

// Get globalExitRoot global exit root
bytes32 lastGlobalExitRoot = globalExitRootManager
Expand Down Expand Up @@ -1189,7 +1206,7 @@ contract CDKValidium is

emit SetTrustedSequencerURL(newTrustedSequencerURL);
}

/**
* @notice Allow the admin to set a new trusted aggregator address
* @param newTrustedAggregator Address of the new trusted aggregator
Expand Down Expand Up @@ -1311,6 +1328,27 @@ contract CDKValidium is
emit ActivateForceBatches();
}


/**
* @notice Allow the admin to disable matic fee transfers for sequence and verify batches
*/
function disableBatchFee() external onlyAdmin {
isFeeTransferDisabled = true;

emit SetMaticTransferDisabled(true);
}


/**
* @notice Allow the admin to enable matic fee transfers for sequence and verify batches
*/
function enableBatchFee() external onlyAdmin {
isFeeTransferDisabled = false;

emit SetMaticTransferDisabled(true);
}


/**
* @notice Starts the admin role transfer
* This is a two step process, the pending admin must accepted to finalize the process
Expand Down Expand Up @@ -1666,7 +1704,7 @@ contract CDKValidium is
abi.encodePacked(
msg.sender,
oldStateRoot,
oldAccInputHash,
oldAccInputHash,
initNumBatch,
chainID,
forkID,
Expand Down