@@ -41,7 +41,7 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
41
41
// Represents a delegator's current state
42
42
struct Delegator {
43
43
uint256 bondedAmount; // The amount of bonded tokens
44
- uint256 unbondedAmount ; // The amount of unbonded tokens
44
+ uint256 fees ; // The amount of fees collected
45
45
address delegateAddress; // The address delegated to
46
46
uint256 delegatedAmount; // The amount of tokens delegated to the delegator
47
47
uint256 startRound; // The round the delegator transitions to bonded phase and is delegated to someone
@@ -279,19 +279,8 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
279
279
}
280
280
281
281
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);
295
284
}
296
285
297
286
Bond (_to, msg .sender );
@@ -336,35 +325,46 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
336
325
}
337
326
338
327
/**
339
- * @dev Withdraws withdrawable funds back to the caller after unbonding period.
328
+ * @dev Withdraws bonded stake to the caller after unbonding period.
340
329
*/
341
- function withdraw ()
330
+ function withdrawStake ()
342
331
external
343
332
whenSystemNotPaused
344
333
currentRoundInitialized
345
334
autoClaimTokenPoolsShares
346
335
{
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);
349
338
350
- uint256 amount = 0 ;
339
+ uint256 amount = delegators[msg .sender ].bondedAmount;
340
+ delegators[msg .sender ].bondedAmount = 0 ;
341
+ delegators[msg .sender ].withdrawRound = 0 ;
351
342
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);
357
345
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
+ }
364
348
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 ;
366
363
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 );
368
368
}
369
369
370
370
/*
@@ -575,10 +575,10 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
575
575
}
576
576
577
577
/*
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
579
579
* @param _delegator Address of delegator
580
580
*/
581
- function delegatorStake (address _delegator ) public view returns (uint256 ) {
581
+ function pendingStake (address _delegator ) public view returns (uint256 ) {
582
582
Delegator storage del = delegators[_delegator];
583
583
584
584
// Add rewards from the rounds during which the delegator was bonded to a transcoder
@@ -603,16 +603,16 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
603
603
}
604
604
605
605
/*
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
607
607
* @param _delegator Address of delegator
608
608
*/
609
- function delegatorUnbondedAmount (address _delegator ) public view returns (uint256 ) {
609
+ function pendingFees (address _delegator ) public view returns (uint256 ) {
610
610
Delegator storage del = delegators[_delegator];
611
611
612
612
// Add fees from the rounds during which the delegator was bonded to a transcoder
613
613
if (delegatorStatus (_delegator) == DelegatorStatus.Bonded && transcoderStatus (del.delegateAddress) == TranscoderStatus.Registered) {
614
614
uint256 currentRound = roundsManager ().currentRound ();
615
- uint256 currentUnbondedAmount = del.unbondedAmount ;
615
+ uint256 currentFees = del.fees ;
616
616
uint256 currentBondedAmount = del.bondedAmount;
617
617
618
618
for (uint256 i = del.lastClaimTokenPoolsSharesRound + 1 ; i <= currentRound; i++ ) {
@@ -621,16 +621,16 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
621
621
if (tokenPools.hasClaimableShares ()) {
622
622
bool isTranscoder = _delegator == del.delegateAddress;
623
623
// 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));
625
625
// Calculate new bonded amount with rewards from this round. Updated bonded amount used
626
626
// to calculate fee pool share in next round
627
627
currentBondedAmount = currentBondedAmount.add (tokenPools.rewardPoolShare (currentBondedAmount, isTranscoder));
628
628
}
629
629
}
630
630
631
- return currentUnbondedAmount ;
631
+ return currentFees ;
632
632
} else {
633
- return del.unbondedAmount ;
633
+ return del.fees ;
634
634
}
635
635
}
636
636
@@ -743,12 +743,12 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
743
743
)
744
744
public
745
745
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 )
747
747
{
748
748
Delegator storage del = delegators[_delegator];
749
749
750
750
bondedAmount = del.bondedAmount;
751
- unbondedAmount = del.unbondedAmount ;
751
+ fees = del.fees ;
752
752
delegateAddress = del.delegateAddress;
753
753
delegatedAmount = del.delegatedAmount;
754
754
startRound = del.startRound;
@@ -834,26 +834,25 @@ contract BondingManager is ManagerProxyTarget, IBondingManager {
834
834
835
835
if (del.lastClaimTokenPoolsSharesRound > 0 ) {
836
836
uint256 currentBondedAmount = del.bondedAmount;
837
- uint256 currentUnbondedAmount = del.unbondedAmount ;
837
+ uint256 currentFees = del.fees ;
838
838
839
839
for (uint256 i = del.lastClaimTokenPoolsSharesRound + 1 ; i <= _endRound; i++ ) {
840
840
TokenPools.Data storage tokenPools = transcoders[del.delegateAddress].tokenPoolsPerRound[i];
841
841
842
-
843
842
if (tokenPools.hasClaimableShares ()) {
844
843
bool isTranscoder = _delegator == del.delegateAddress;
845
844
846
845
var (fees, rewards) = tokenPools.claimShare (currentBondedAmount, isTranscoder);
847
846
848
- currentUnbondedAmount = currentUnbondedAmount .add (fees);
847
+ currentFees = currentFees .add (fees);
849
848
currentBondedAmount = currentBondedAmount.add (rewards);
850
849
}
851
850
}
852
851
853
852
// Rewards are bonded by default
854
853
del.bondedAmount = currentBondedAmount;
855
854
// Fees are unbonded by default
856
- del.unbondedAmount = currentUnbondedAmount ;
855
+ del.fees = currentFees ;
857
856
}
858
857
859
858
del.lastClaimTokenPoolsSharesRound = _endRound;
0 commit comments