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

SD Collateral Deposit Using SD Reward #208

Closed

Conversation

sanjay-staderlabs
Copy link
Contributor

Below are the changes across SDCollateral.sol and SocializingPool.sol

  1. Function to deposit SD as collateral on behalf of an operator by the sender
  2. Function to claim SocializingPool reward along with depositing a certain amount of SD as collateral to SDCollateral contract
  3. Function to approve max allowance to SDCollateral contract by Socializing Pool controlled by MANAGER
  4. updated test cases for both Socializing Pool and SDCollateral in StaderOracle.t.sol file

if (!IERC20(staderConfig.getStaderToken()).transferFrom(msg.sender, address(this), _sdAmount)) {
revert SDTransferFailed();
}
operatorSDBalance[_operator] += _sdAmount;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although not required here. But it is recommended to follow check-effects-interaction security pattern.
i.e. move line 64 to line 61
https://fravoll.github.io/solidity-patterns/checks_effects_interactions.html

Copy link
Contributor Author

@sanjay-staderlabs sanjay-staderlabs Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it follows this pattern, you do not want to increase operatorSDBalance before you get SD in the contract, the main aim of check-effects-interaction is if your interaction calls get hacked then your storage should not be exploited, if we move line 64 to 61 then in case tranferFrom does not work properly your operatorSDBalance will keep on increasing.
@dulguun-staderlabs would love to hear your thoughts here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transactions are atomic, hence whole txn will revert if transferFrom fails.

Copy link

@manoj9april manoj9april left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sanjay-staderlabs sanjay-staderlabs changed the base branch from mainnet_V0 to feat/SD_Utility_Pool November 28, 2023 04:28
@sanjay-staderlabs sanjay-staderlabs changed the title claiming SD reward along with depositing as collateral SD Collateral Deposit Using SD Reward Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants