@@ -41,7 +41,7 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
4141 // Represents a delegator's current state
4242 struct Delegator {
4343 uint256 bondedAmount; // The amount of bonded tokens
44- uint256 unbondedAmount ; // The amount of unbonded tokens
44+ uint256 fees ; // The amount of fees collected
4545 address delegateAddress; // The address delegated to
4646 uint256 delegatedAmount; // The amount of tokens delegated to the delegator
4747 uint256 startRound; // The round the delegator transitions to bonded phase and is delegated to someone
@@ -279,19 +279,8 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
279279 }
280280
281281 if (_amount > 0 ) {
282- if (_amount > del.unbondedAmount) {
283- // If amount to bond is greater than the delegator's unbonded amount
284- // use the delegator's unbonded amount and transfer the rest from the sender
285- uint256 transferAmount = _amount.sub (del.unbondedAmount);
286- // Set unbonded amount to 0
287- del.unbondedAmount = 0 ;
288- // Transfer the token to the Minter
289- livepeerToken ().transferFrom (msg .sender , minter (), transferAmount);
290- } else {
291- // If the amount to bond is less than or equal to the delegator's unbonded amount
292- // just use the delegator's unbonded amount
293- del.unbondedAmount = del.unbondedAmount.sub (_amount);
294- }
282+ // Transfer the LPT to the Minter
283+ livepeerToken ().transferFrom (msg .sender , minter (), _amount);
295284 }
296285
297286 Bond (_to, msg .sender );
@@ -336,35 +325,46 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
336325 }
337326
338327 /**
339- * @dev Withdraws withdrawable funds back to the caller after unbonding period.
328+ * @dev Withdraws bonded stake to the caller after unbonding period.
340329 */
341- function withdraw ()
330+ function withdrawStake ()
342331 external
343332 whenSystemNotPaused
344333 currentRoundInitialized
345334 autoClaimTokenPoolsShares
346335 {
347- // Delegator must either have unbonded tokens or be in the unbonded state
348- require (delegators[ msg . sender ].unbondedAmount > 0 || delegatorStatus (msg .sender ) == DelegatorStatus.Unbonded);
336+ // Delegator must be in the unbonded state
337+ require (delegatorStatus (msg .sender ) == DelegatorStatus.Unbonded);
349338
350- uint256 amount = 0 ;
339+ uint256 amount = delegators[msg .sender ].bondedAmount;
340+ delegators[msg .sender ].bondedAmount = 0 ;
341+ delegators[msg .sender ].withdrawRound = 0 ;
351342
352- if (delegators[msg .sender ].unbondedAmount > 0 ) {
353- // Withdraw unbonded amount
354- amount = amount.add (delegators[msg .sender ].unbondedAmount);
355- delegators[msg .sender ].unbondedAmount = 0 ;
356- }
343+ // Tell Minter to transfer stake (LPT) to the delegator
344+ minter ().transferTokens (msg .sender , amount);
357345
358- if (delegatorStatus (msg .sender ) == DelegatorStatus.Unbonded) {
359- // Withdraw bonded amount which is now unbonded
360- amount = amount.add (delegators[msg .sender ].bondedAmount);
361- delegators[msg .sender ].bondedAmount = 0 ;
362- delegators[msg .sender ].withdrawRound = 0 ;
363- }
346+ WithdrawStake (msg .sender );
347+ }
364348
365- minter ().transferTokens (msg .sender , amount);
349+ /**
350+ * @dev Withdraws fees to the caller
351+ */
352+ function withdrawFees ()
353+ external
354+ whenSystemNotPaused
355+ currentRoundInitialized
356+ autoClaimTokenPoolsShares
357+ {
358+ // Delegator must have fees
359+ require (delegators[msg .sender ].fees > 0 );
360+
361+ uint256 amount = delegators[msg .sender ].fees;
362+ delegators[msg .sender ].fees = 0 ;
366363
367- Withdraw (msg .sender );
364+ // Tell Minter to transfer fees (ETH) to the delegator
365+ minter ().withdrawETH (msg .sender , amount);
366+
367+ WithdrawFees (msg .sender );
368368 }
369369
370370 /*
@@ -575,10 +575,10 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
575575 }
576576
577577 /*
578- * @dev Returns bonded stake for a delegator. Includes reward pool shares since lastClaimTokenPoolsSharesRound
578+ * @dev Returns pending bonded stake for a delegator. Includes reward pool shares since lastClaimTokenPoolsSharesRound
579579 * @param _delegator Address of delegator
580580 */
581- function delegatorStake (address _delegator ) public view returns (uint256 ) {
581+ function pendingStake (address _delegator ) public view returns (uint256 ) {
582582 Delegator storage del = delegators[_delegator];
583583
584584 // Add rewards from the rounds during which the delegator was bonded to a transcoder
@@ -603,16 +603,16 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
603603 }
604604
605605 /*
606- * @dev Returns unbonded amount for a delegator. Includes fee pool shares since lastClaimTokenPoolsSharesRound
606+ * @dev Returns pending fees for a delegator. Includes fee pool shares since lastClaimTokenPoolsSharesRound
607607 * @param _delegator Address of delegator
608608 */
609- function delegatorUnbondedAmount (address _delegator ) public view returns (uint256 ) {
609+ function pendingFees (address _delegator ) public view returns (uint256 ) {
610610 Delegator storage del = delegators[_delegator];
611611
612612 // Add fees from the rounds during which the delegator was bonded to a transcoder
613613 if (delegatorStatus (_delegator) == DelegatorStatus.Bonded && transcoderStatus (del.delegateAddress) == TranscoderStatus.Registered) {
614614 uint256 currentRound = roundsManager ().currentRound ();
615- uint256 currentUnbondedAmount = del.unbondedAmount ;
615+ uint256 currentFees = del.fees ;
616616 uint256 currentBondedAmount = del.bondedAmount;
617617
618618 for (uint256 i = del.lastClaimTokenPoolsSharesRound + 1 ; i <= currentRound; i++ ) {
@@ -621,16 +621,16 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
621621 if (tokenPools.hasClaimableShares ()) {
622622 bool isTranscoder = _delegator == del.delegateAddress;
623623 // Calculate and add fee pool share from this round
624- currentUnbondedAmount = currentUnbondedAmount .add (tokenPools.feePoolShare (currentBondedAmount, isTranscoder));
624+ currentFees = currentFees .add (tokenPools.feePoolShare (currentBondedAmount, isTranscoder));
625625 // Calculate new bonded amount with rewards from this round. Updated bonded amount used
626626 // to calculate fee pool share in next round
627627 currentBondedAmount = currentBondedAmount.add (tokenPools.rewardPoolShare (currentBondedAmount, isTranscoder));
628628 }
629629 }
630630
631- return currentUnbondedAmount ;
631+ return currentFees ;
632632 } else {
633- return del.unbondedAmount ;
633+ return del.fees ;
634634 }
635635 }
636636
@@ -743,12 +743,12 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
743743 )
744744 public
745745 view
746- returns (uint256 bondedAmount , uint256 unbondedAmount , address delegateAddress , uint256 delegatedAmount , uint256 startRound , uint256 withdrawRound , uint256 lastClaimTokenPoolsSharesRound )
746+ returns (uint256 bondedAmount , uint256 fees , address delegateAddress , uint256 delegatedAmount , uint256 startRound , uint256 withdrawRound , uint256 lastClaimTokenPoolsSharesRound )
747747 {
748748 Delegator storage del = delegators[_delegator];
749749
750750 bondedAmount = del.bondedAmount;
751- unbondedAmount = del.unbondedAmount ;
751+ fees = del.fees ;
752752 delegateAddress = del.delegateAddress;
753753 delegatedAmount = del.delegatedAmount;
754754 startRound = del.startRound;
@@ -834,26 +834,25 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
834834
835835 if (del.lastClaimTokenPoolsSharesRound > 0 ) {
836836 uint256 currentBondedAmount = del.bondedAmount;
837- uint256 currentUnbondedAmount = del.unbondedAmount ;
837+ uint256 currentFees = del.fees ;
838838
839839 for (uint256 i = del.lastClaimTokenPoolsSharesRound + 1 ; i <= _endRound; i++ ) {
840840 TokenPools.Data storage tokenPools = transcoders[del.delegateAddress].tokenPoolsPerRound[i];
841841
842-
843842 if (tokenPools.hasClaimableShares ()) {
844843 bool isTranscoder = _delegator == del.delegateAddress;
845844
846845 var (fees, rewards) = tokenPools.claimShare (currentBondedAmount, isTranscoder);
847846
848- currentUnbondedAmount = currentUnbondedAmount .add (fees);
847+ currentFees = currentFees .add (fees);
849848 currentBondedAmount = currentBondedAmount.add (rewards);
850849 }
851850 }
852851
853852 // Rewards are bonded by default
854853 del.bondedAmount = currentBondedAmount;
855854 // Fees are unbonded by default
856- del.unbondedAmount = currentUnbondedAmount ;
855+ del.fees = currentFees ;
857856 }
858857
859858 del.lastClaimTokenPoolsSharesRound = _endRound;
0 commit comments