Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rearrange refund validation checks [SLT-185] #3172

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors {
/// @inheritdoc IFastBridge
function refund(bytes memory request) external {
bytes32 transactionId = keccak256(request);

if (bridgeStatuses[transactionId] != BridgeStatus.REQUESTED) revert StatusIncorrect();

BridgeTransaction memory transaction = getBridgeTransaction(request);

if (hasRole(REFUNDER_ROLE, msg.sender)) {
Expand All @@ -284,8 +287,7 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors {
if (block.timestamp <= transaction.deadline + REFUND_DELAY) revert DeadlineNotExceeded();
}

// set status to refunded if still in requested state
if (bridgeStatuses[transactionId] != BridgeStatus.REQUESTED) revert StatusIncorrect();
// if all checks passed, set to REFUNDED status
bridgeStatuses[transactionId] = BridgeStatus.REFUNDED;

// transfer origin collateral back to original sender
Expand Down
9 changes: 3 additions & 6 deletions packages/contracts-rfq/test/FastBridgeV2.Src.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -896,40 +896,37 @@ contract FastBridgeV2SrcTest is FastBridgeV2Test {
function test_refund_revert_zeroDelay() public {
bridge({caller: userA, msgValue: 0, params: tokenParams});
vm.expectRevert(DeadlineNotExceeded.selector);
refund({caller: refunder, bridgeTx: ethTx});
refund({caller: refunder, bridgeTx: tokenTx});
}

function test_refund_revert_justBeforeDeadline() public {
bridge({caller: userA, msgValue: 0, params: tokenParams});
skip(DEADLINE);
vm.expectRevert(DeadlineNotExceeded.selector);
refund({caller: refunder, bridgeTx: ethTx});
refund({caller: refunder, bridgeTx: tokenTx});
}

function test_refund_revert_justBeforeDeadline_permisionless(address caller) public {
vm.assume(caller != refunder);
bridge({caller: userA, msgValue: 0, params: tokenParams});
skip(DEADLINE + PERMISSIONLESS_REFUND_DELAY);
vm.expectRevert(DeadlineNotExceeded.selector);
refund({caller: caller, bridgeTx: ethTx});
refund({caller: caller, bridgeTx: tokenTx});
}

function test_refund_revert_statusNull() public {
vm.skip(true); // TODO: unskip when fixed
vm.expectRevert(StatusIncorrect.selector);
refund({caller: refunder, bridgeTx: ethTx});
}

function test_refund_revert_statusProven() public {
vm.skip(true); // TODO: unskip when fixed
bridge({caller: userA, msgValue: 0, params: tokenParams});
prove({caller: relayerA, bridgeTx: tokenTx, destTxHash: hex"01"});
vm.expectRevert(StatusIncorrect.selector);
refund({caller: refunder, bridgeTx: tokenTx});
}

function test_refund_revert_statusClaimed() public {
vm.skip(true); // TODO: unskip when fixed
bridge({caller: userA, msgValue: 0, params: tokenParams});
prove({caller: relayerA, bridgeTx: tokenTx, destTxHash: hex"01"});
skip(CLAIM_DELAY + 1);
Expand Down
Loading