Skip to content

Commit

Permalink
Track the unstaking of amounts that aren't full
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Apr 12, 2024
1 parent 214cfa9 commit 32699b1
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions contracts/ethereum/contracts/StakingV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,30 @@ return a
}
unstakingStorage_[_spender].pop();
}

/* ~~~~~~~~~~ INFORMATIONAL ~~~~~~~~~~ */

function stakingPositionsLen(address _account) public view returns (uint) {
return stakedStorage_[_account].length;
}

function stakedPositionInfo(address _account, uint _i) public view returns (bool receivedBonus, uint256 flyVested, uint256 depositTimestamp) {
StakedPrivate storage s = stakedStorage_[_account][_i];
receivedBonus = s.receivedBonus;
flyVested = s.flyVested;
depositTimestamp = s.depositTimestamp;
}

function unstakingPositionsLen(address _account) public view returns (uint) {
return unstakingStorage_[_account].length;
}

function unstakingPositionInfo(address _account, uint _i) public view returns (uint256 flyAmount, uint256 unstakedTimestamp) {
UnstakingPrivate storage s = unstakingStorage_[_account][_i];
flyAmount = s.flyAmount;
unstakedTimestamp = s.unstakedTimestamp;
}

/// @inheritdoc IStaking
function stakingDetails(address _account) public view returns (uint256 flyStaked, uint256 points) {
for (uint i = 0; i < stakedStorage_[_account].length; i++) {
Expand Down Expand Up @@ -294,6 +312,10 @@ return a
// can update the existing staked amount to reduce the FLY that they
// requested, then we can just return here.
stakedStorage_[msg.sender][i].flyVested -= flyRemaining;
unstakingStorage_[msg.sender].push(UnstakingPrivate({
flyAmount: flyRemaining,
unstakedTimestamp: unstakedBy
}));
flyRemaining = 0;
break;
}
Expand All @@ -315,8 +337,8 @@ return a
) public view returns (uint256 shortestSecs) {
for (uint i = 0; i < unstakingStorage_[_spender].length; i++) {
uint256 ts = unstakingStorage_[_spender][i].unstakedTimestamp;
if (block.timestamp > ts) {
uint256 remaining = block.timestamp - ts;
if (ts > block.timestamp) {
uint256 remaining = ts - block.timestamp;
// if we haven't set the shortest number of seconds, we
// set it to whatever we can, or we set it to the
// smallest value.
Expand All @@ -335,7 +357,7 @@ return a
if (len == 0) return 0;
for (uint i = len - 1; i >= 0; i--) {
UnstakingPrivate storage s = unstakingStorage_[msg.sender][i];
// if the timestamp for the time that we need to unstake is less than the
// if the timestamp for the time that we need to unstake is more than the
// current, break out.
if (s.unstakedTimestamp > block.timestamp) {
if (i == 0) break;
Expand Down

0 comments on commit 32699b1

Please sign in to comment.