Skip to content

Commit dd3154a

Browse files
committed
fix: slither feedback
1 parent af6dbe0 commit dd3154a

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

contracts/PegOutContract.sol

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity 0.8.25;
44
import {BtcUtils} from "@rsksmart/btc-transaction-solidity-helper/contracts/BtcUtils.sol";
55
import {OwnableDaoContributorUpgradeable} from "./DaoContributor.sol";
66
import {IBridge} from "./interfaces/Bridge.sol";
7-
import {ICollateralManagement} from "./interfaces/CollateralManagement.sol";
7+
import {ICollateralManagement, CollateralManagementSet} from "./interfaces/CollateralManagement.sol";
88
import {IPegOut} from "./interfaces/PegOut.sol";
99
import {Flyover} from "./libraries/Flyover.sol";
1010
import {Quotes} from "./libraries/Quotes.sol";
@@ -33,8 +33,11 @@ contract PegOutContract is
3333
mapping(bytes32 => PegOutRecord) private _pegOutRegistry;
3434

3535
uint256 public dustThreshold;
36+
uint256 public btcBlockTime;
3637
bool private _mainnet;
37-
uint256 private _btcBlockTime;
38+
39+
event DustThresholdSet(uint256 indexed oldThreshold, uint256 indexed newThreshold);
40+
event BtcBlockTimeSet(uint256 indexed oldTime, uint256 indexed newTime);
3841

3942
function depositPegOut(
4043
Quotes.PegOutQuote calldata quote,
@@ -92,6 +95,7 @@ contract PegOutContract is
9295
uint256 dustThreshold_,
9396
address collateralManagement,
9497
bool mainnet,
98+
uint256 btcBlockTime_,
9599
uint256 daoFeePercentage,
96100
address payable daoFeeCollector
97101
) external initializer {
@@ -100,6 +104,25 @@ contract PegOutContract is
100104
_collateralManagement = ICollateralManagement(collateralManagement);
101105
_mainnet = mainnet;
102106
dustThreshold = dustThreshold_;
107+
btcBlockTime = btcBlockTime_;
108+
}
109+
110+
// solhint-disable-next-line comprehensive-interface
111+
function setCollateralManagement(address collateralManagement) external onlyOwner {
112+
emit CollateralManagementSet(address(_collateralManagement), collateralManagement);
113+
_collateralManagement = ICollateralManagement(collateralManagement);
114+
}
115+
116+
// solhint-disable-next-line comprehensive-interface
117+
function setDustThreshold(uint256 threshold) external onlyOwner {
118+
emit DustThresholdSet(dustThreshold, threshold);
119+
dustThreshold = threshold;
120+
}
121+
122+
// solhint-disable-next-line comprehensive-interface
123+
function setBtcBlockTime(uint256 blockTime) external onlyOwner {
124+
emit BtcBlockTimeSet(btcBlockTime, blockTime);
125+
btcBlockTime = blockTime;
103126
}
104127

105128
function refundPegOut(
@@ -124,20 +147,21 @@ contract PegOutContract is
124147
_validateBtcTxAmount(outputs, quote);
125148
_validateBtcTxDestination(outputs, quote);
126149

127-
if (_shouldPenalize(quote, quoteHash, btcBlockHeaderHash)) {
128-
_collateralManagement.slashPegOutCollateral(quote, quoteHash);
129-
}
130-
131150
delete _pegOutQuotes[quoteHash];
132151
_pegOutRegistry[quoteHash].completed = true;
133152
emit PegOutRefunded(quoteHash);
134153

154+
_addDaoContribution(quote.lpRskAddress, quote.productFeeAmount);
155+
156+
if (_shouldPenalize(quote, quoteHash, btcBlockHeaderHash)) {
157+
_collateralManagement.slashPegOutCollateral(quote, quoteHash);
158+
}
159+
135160
uint256 refundAmount = quote.value + quote.callFee + quote.gasFee;
136161
(bool sent, bytes memory reason) = quote.lpRskAddress.call{value: refundAmount}("");
137162
if (!sent) {
138163
revert Flyover.PaymentFailed(quote.lpRskAddress, refundAmount, reason);
139164
}
140-
_addDaoContribution(quote.lpRskAddress, quote.productFeeAmount);
141165
}
142166

143167
function refundUserPegOut(bytes32 quoteHash) external nonReentrant override {
@@ -150,12 +174,12 @@ contract PegOutContract is
150174
uint256 valueToTransfer = quote.value + quote.callFee + quote.productFeeAmount + quote.gasFee;
151175
address addressToTransfer = quote.rskRefundAddress;
152176

153-
emit PegOutUserRefunded(quoteHash, quote.rskRefundAddress, valueToTransfer);
154-
_collateralManagement.slashPegOutCollateral(quote, quoteHash);
155-
156177
delete _pegOutQuotes[quoteHash];
157178
_pegOutRegistry[quoteHash].completed = true;
158179

180+
emit PegOutUserRefunded(quoteHash, quote.rskRefundAddress, valueToTransfer);
181+
_collateralManagement.slashPegOutCollateral(quote, quoteHash);
182+
159183
(bool sent, bytes memory reason) = addressToTransfer.call{value: valueToTransfer}("");
160184
if (!sent) {
161185
revert Flyover.PaymentFailed(addressToTransfer, valueToTransfer, reason);
@@ -196,7 +220,7 @@ contract PegOutContract is
196220
uint256 firstConfirmationTimestamp = BtcUtils.getBtcBlockTimestamp(firstConfirmationHeader);
197221
uint256 expectedConfirmationTime = _pegOutRegistry[quoteHash].depositTimestamp +
198222
quote.transferTime +
199-
_btcBlockTime;
223+
btcBlockTime;
200224

201225
// penalize if the transfer was not made on time
202226
if (firstConfirmationTimestamp > expectedConfirmationTime) {

contracts/interfaces/CollateralManagement.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pragma solidity 0.8.25;
44
import {Flyover} from "../libraries/Flyover.sol";
55
import {Quotes} from "../libraries/Quotes.sol";
66

7+
event CollateralManagementSet(address indexed oldAddress, address indexed newAddress);
8+
79
interface ICollateralManagement {
810
event WithdrawCollateral(address indexed addr, uint indexed amount);
911
event Resigned(address indexed addr);

0 commit comments

Comments
 (0)