Skip to content

Commit

Permalink
add donation attack comment and pick up any S tokens in the withdrawAll
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrowDom committed Jan 10, 2025
1 parent 19c60a7 commit 3cbd5c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/contracts/strategies/sonic/SonicStakingStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { IERC20, InitializableAbstractStrategy } from "../../utils/InitializableAbstractStrategy.sol";
import { SonicValidatorDelegator } from "./SonicValidatorDelegator.sol";
import { IWrappedSonic } from "../../interfaces/sonic/IWrappedSonic.sol";

/**
* @title Staking Strategy for Sonic's native S currency
Expand Down Expand Up @@ -94,6 +95,10 @@ contract SonicStakingStrategy is SonicValidatorDelegator {
/// This does not withdraw from delegated validators. That has to be done separately with `undelegate`.
/// Any native S in this strategy will not be withdrawn.
function withdrawAll() external override onlyVaultOrGovernor nonReentrant {
uint256 balance = address(this).balance;

Check warning on line 98 in contracts/contracts/strategies/sonic/SonicStakingStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/sonic/SonicStakingStrategy.sol#L98

Added line #L98 was not covered by tests
if (balance > 0) {
IWrappedSonic(wrappedSonic).deposit{ value: balance }();

Check warning on line 100 in contracts/contracts/strategies/sonic/SonicStakingStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/sonic/SonicStakingStrategy.sol#L100

Added line #L100 was not covered by tests
}
uint256 wSBalance = IERC20(wrappedSonic).balanceOf(address(this));

Check warning on line 102 in contracts/contracts/strategies/sonic/SonicStakingStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/sonic/SonicStakingStrategy.sol#L102

Added line #L102 was not covered by tests
if (wSBalance > 0) {
_withdraw(vaultAddress, wrappedSonic, wSBalance);

Check warning on line 104 in contracts/contracts/strategies/sonic/SonicStakingStrategy.sol

View check run for this annotation

Codecov / codecov/patch

contracts/contracts/strategies/sonic/SonicStakingStrategy.sol#L104

Added line #L104 was not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ abstract contract SonicValidatorDelegator is InitializableAbstractStrategy {

/**
* @notice To receive native S from SFC and Wrapped Sonic (wS)
*
* @dev This does not prevent donating S tokens to the contract
* as wrappedSonic has a `withdrawTo` function where a third party
* owner of wrappedSonic can withdraw to this contract.
*/
receive() external payable {
require(
Expand Down

0 comments on commit 3cbd5c4

Please sign in to comment.