Skip to content

Commit

Permalink
dwlwgator withdraw flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjay Yadav authored and Sanjay Yadav committed Nov 14, 2023
1 parent 82cc1c8 commit 12bab11
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 155 deletions.
2 changes: 1 addition & 1 deletion contracts/SDCollateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ contract SDCollateral is ISDCollateral, AccessControlUpgradeable, ReentrancyGuar
// HELPER

function getOperatorInfo(address _operator)
internal
public
view
returns (
uint8 _poolId,
Expand Down
10 changes: 5 additions & 5 deletions contracts/SDIncentiveController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import './library/UtilLib.sol';
import './interfaces/IStaderConfig.sol';
import './interfaces/ISDUtilityPool.sol';
import './interfaces/ISDIncentiveController.sol';

/// @title SDIncentiveController
Expand Down Expand Up @@ -70,20 +71,19 @@ contract SDIncentiveController is ISDIncentiveController, AccessControlUpgradeab
/// @notice Calculates the current reward per token.
/// @return The calculated reward per token.
function rewardPerToken() public view returns (uint256) {
if (IERC20(staderConfig.getSDxToken()).totalSupply() == 0) {
uint256 totalSupply = ISDUtilityPool(staderConfig.getSDUtilityPool()).cTokenTotalSupply();
if (totalSupply == 0) {
return rewardPerTokenStored;
}
return
rewardPerTokenStored +
(((block.number - lastUpdateBlockNumber) * emissionPerBlock * 1e18) /
IERC20(staderConfig.getSDxToken()).totalSupply());
rewardPerTokenStored + (((block.number - lastUpdateBlockNumber) * emissionPerBlock * 1e18) / totalSupply);
}

/// @notice Calculates the total accrued reward for an account.
/// @param account The account to calculate rewards for.
/// @return The total accrued reward for the account.
function earned(address account) public view returns (uint256) {
uint256 currentBalance = IERC20(staderConfig.getSDxToken()).balanceOf(account);
uint256 currentBalance = ISDUtilityPool(staderConfig.getSDUtilityPool()).delegatorCTokenBalance(account);
uint256 currentRewardPerToken = rewardPerToken();

return ((currentBalance * (currentRewardPerToken - userRewardPerTokenPaid[account])) / 1e18) + rewards[account];
Expand Down
236 changes: 191 additions & 45 deletions contracts/SDUtilityPool.sol

Large diffs are not rendered by default.

86 changes: 0 additions & 86 deletions contracts/SDX.sol

This file was deleted.

9 changes: 0 additions & 9 deletions contracts/StaderConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ contract StaderConfig is IStaderConfig, AccessControlUpgradeable {
mapping(bytes32 => address) private contractsMap;
mapping(bytes32 => address) private tokensMap;

bytes32 public constant override SDx = keccak256('SDx');
bytes32 public constant override SD_UTILITY_POOL = keccak256('SD_UTILITY_POOL');
bytes32 public constant override SD_INCENTIVE_CONTROLLER = keccak256('SD_INCENTIVE_CONTROLLER');

Expand Down Expand Up @@ -296,10 +295,6 @@ contract StaderConfig is IStaderConfig, AccessControlUpgradeable {
setToken(ETHx, _ethX);
}

function updateSDxToken(address _sdX) external onlyRole(DEFAULT_ADMIN_ROLE) {
setToken(SDx, _sdX);
}

function updateSDUtilityPool(address _utilityPool) external onlyRole(DEFAULT_ADMIN_ROLE) {
setContract(SD_UTILITY_POOL, _utilityPool);
}
Expand Down Expand Up @@ -491,10 +486,6 @@ contract StaderConfig is IStaderConfig, AccessControlUpgradeable {
return tokensMap[ETHx];
}

function getSDxToken() external view override returns (address) {
return tokensMap[SDx];
}

// SETTER HELPERS
function setConstant(bytes32 key, uint256 val) internal {
if (constantsMap[key] == val) {
Expand Down
28 changes: 22 additions & 6 deletions contracts/interfaces/ISDUtilityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,40 @@ pragma solidity 0.8.16;

interface ISDUtilityPool {
error SDTransferFailed();
error CannotFindRequestId();
error SDUtilizeLimitReached();
error InvalidAmountOfWithdraw();
error InsufficientPoolBalance();
error AccrualBlockNumberNotLatest();
error CallerNotAuthorizedToRedeem();
error MaxLimitOnWithdrawRequestCountReached();
error requestIdNotFinalized(uint256 requestId);

event UpdatedStaderConfig(address indexed _staderConfig);
event RequestRedeemed(address caller, uint256 sdToTransfer);
event Delegated(address indexed delegator, uint256 sdAmount, uint256 sdXToMint);
event Redeemed(address indexed delegator, uint256 sdAmount, uint256 sdXAmount);
event Repaid(address indexed utilizer, uint256 repayAmount);

event AccruedFees(uint256 feeAccumulated, uint256 totalProtocolFee, uint256 totalUtilizedSD);

event WithdrawRequestReceived(address caller, uint256 nextRequestId, uint256 sdAmountToWithdraw);

function cTokenTotalSupply() external view returns (uint256);

function delegatorCTokenBalance(address) external view returns (uint256);

function delegate(uint256 sdAmount) external;

// function requestWithdraw(uint256 sdAmount) external return (uint);
function requestWithdraw(uint256 cTokenAmount) external returns (uint256);

function requestWithdrawWithSDAmount(uint256 sdAmount) external returns (uint256);

function finalizeDelegatorWithdrawalRequest() external;

// function claim(uint256 requestId) external;
function claim(uint256 requestId) external;

function redeem(uint256 sdXAmount) external;
function utilize(uint256 utilizeAmount) external;

function utilizeWhileAddingKeys(
address operator,
Expand All @@ -34,9 +50,9 @@ interface ISDUtilityPool {

function accrueFee() external;

function utilizeBalanceCurrent(address account) external returns (uint256);
function utilizerBalanceCurrent(address account) external returns (uint256);

function utilizeBalanceStored(address account) external view returns (uint256);
function utilizerBalanceStored(address account) external view returns (uint256);

function poolUtilization() external view returns (uint256);

Expand All @@ -46,5 +62,5 @@ interface ISDUtilityPool {

function exchangeRateStored() external view returns (uint256);

function getPoolSDBalance() external view returns (uint256);
function getPoolAvailableSDBalance() external view returns (uint256);
}
3 changes: 0 additions & 3 deletions contracts/interfaces/IStaderConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ interface IStaderConfig {
function VALIDATOR_WITHDRAWAL_VAULT_IMPLEMENTATION() external view returns (bytes32);

//SD Utility Pool
function SDx() external view returns (bytes32);

function SD_UTILITY_POOL() external view returns (bytes32);

Expand Down Expand Up @@ -166,8 +165,6 @@ interface IStaderConfig {

function getETHxToken() external view returns (address);

function getSDxToken() external view returns (address);

//checks roles and stader contracts
function onlyStaderContract(address _addr, bytes32 _contractName) external view returns (bool);

Expand Down
9 changes: 9 additions & 0 deletions contracts/interfaces/SDCollateral/ISDCollateral.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ interface ISDCollateral {
function convertSDToETH(uint256 _sdAmount) external view returns (uint256);

function convertETHToSD(uint256 _ethAmount) external view returns (uint256);

function getOperatorInfo(address _operator)
external
view
returns (
uint8 _poolId,
uint256 _operatorId,
uint256 _validatorCount
);
}

0 comments on commit 12bab11

Please sign in to comment.