@@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2;
6
6
import "@openzeppelin/contracts/cryptography/ECDSA.sol " ;
7
7
8
8
import "../upgrades/GraphUpgradeable.sol " ;
9
+ import "../utils/TokenUtils.sol " ;
9
10
10
11
import "./IStaking.sol " ;
11
12
import "./StakingStorage.sol " ;
@@ -695,7 +696,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
695
696
);
696
697
697
698
// Transfer tokens to stake from caller to this contract
698
- _pullTokens (graphToken (), msg .sender , _tokens);
699
+ TokenUtils. pullTokens (graphToken (), msg .sender , _tokens);
699
700
700
701
// Stake the transferred tokens
701
702
_stake (_indexer, _tokens);
@@ -789,10 +790,10 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
789
790
IGraphToken graphToken = graphToken ();
790
791
791
792
// Set apart the reward for the beneficiary and burn remaining slashed stake
792
- _burnTokens (graphToken, _tokens.sub (_reward));
793
+ TokenUtils. burnTokens (graphToken, _tokens.sub (_reward));
793
794
794
795
// Give the beneficiary a reward for slashing
795
- _pushTokens (graphToken, _beneficiary, _reward);
796
+ TokenUtils. pushTokens (graphToken, _beneficiary, _reward);
796
797
797
798
emit StakeSlashed (_indexer, _tokens, _reward, _beneficiary);
798
799
}
@@ -812,7 +813,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
812
813
address delegator = msg .sender ;
813
814
814
815
// Transfer tokens to delegate to this contract
815
- _pullTokens (graphToken (), delegator, _tokens);
816
+ TokenUtils. pullTokens (graphToken (), delegator, _tokens);
816
817
817
818
// Update state
818
819
return _delegate (delegator, _indexer, _tokens);
@@ -971,7 +972,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
971
972
if (queryFees > 0 ) {
972
973
// Pull tokens to collect from the authorized sender
973
974
IGraphToken graphToken = graphToken ();
974
- _pullTokens (graphToken, msg .sender , _tokens);
975
+ TokenUtils. pullTokens (graphToken, msg .sender , _tokens);
975
976
976
977
// -- Collect protocol tax --
977
978
// If the Allocation is not active or closed we are going to charge a 100% protocol tax
@@ -1070,7 +1071,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1070
1071
require (tokensToWithdraw > 0 , "!tokens " );
1071
1072
1072
1073
// Return tokens to the indexer
1073
- _pushTokens (graphToken (), _indexer, tokensToWithdraw);
1074
+ TokenUtils. pushTokens (graphToken (), _indexer, tokensToWithdraw);
1074
1075
1075
1076
emit StakeWithdrawn (_indexer, tokensToWithdraw);
1076
1077
}
@@ -1262,7 +1263,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1262
1263
1263
1264
// When all allocations processed then burn unclaimed fees and prune rebate pool
1264
1265
if (rebatePool.unclaimedAllocationsCount == 0 ) {
1265
- _burnTokens (graphToken, rebatePool.unclaimedFees ());
1266
+ TokenUtils. burnTokens (graphToken, rebatePool.unclaimedFees ());
1266
1267
delete rebates[alloc.closedAtEpoch];
1267
1268
}
1268
1269
@@ -1408,7 +1409,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1408
1409
_delegate (_delegator, _delegateToIndexer, tokensToWithdraw);
1409
1410
} else {
1410
1411
// Return tokens to the delegator
1411
- _pushTokens (graphToken (), _delegator, tokensToWithdraw);
1412
+ TokenUtils. pushTokens (graphToken (), _delegator, tokensToWithdraw);
1412
1413
}
1413
1414
1414
1415
return tokensToWithdraw;
@@ -1484,7 +1485,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1484
1485
// Transfer and call collect()
1485
1486
// This function transfer tokens to a trusted protocol contracts
1486
1487
// Then we call collect() to do the transfer bookeeping
1487
- _pushTokens (_graphToken, address (curation), curationFees);
1488
+ TokenUtils. pushTokens (_graphToken, address (curation), curationFees);
1488
1489
curation.collect (_subgraphDeploymentID, curationFees);
1489
1490
}
1490
1491
return curationFees;
@@ -1505,7 +1506,7 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1505
1506
uint256 _percentage
1506
1507
) private returns (uint256 ) {
1507
1508
uint256 tax = uint256 (_percentage).mul (_tokens).div (MAX_PPM);
1508
- _burnTokens (_graphToken, tax); // Burn tax if any
1509
+ TokenUtils. burnTokens (_graphToken, tax); // Burn tax if any
1509
1510
return tax;
1510
1511
}
1511
1512
@@ -1616,54 +1617,11 @@ contract Staking is StakingV2Storage, GraphUpgradeable, IStaking {
1616
1617
} else {
1617
1618
// Transfer funds to the beneficiary's designated rewards destination if set
1618
1619
address destination = rewardsDestination[_beneficiary];
1619
- _pushTokens (
1620
+ TokenUtils. pushTokens (
1620
1621
_graphToken,
1621
1622
destination == address (0 ) ? _beneficiary : destination,
1622
1623
_amount
1623
1624
);
1624
1625
}
1625
1626
}
1626
-
1627
- /**
1628
- * @dev Burn tokens held by this contract.
1629
- * @param _graphToken Token to burn
1630
- * @param _amount Amount of tokens to burn
1631
- */
1632
- function _burnTokens (IGraphToken _graphToken , uint256 _amount ) private {
1633
- if (_amount > 0 ) {
1634
- _graphToken.burn (_amount);
1635
- }
1636
- }
1637
-
1638
- /**
1639
- * @dev Pull tokens from an address to this contract.
1640
- * @param _graphToken Token to transfer
1641
- * @param _from Address sending the tokens
1642
- * @param _amount Amount of tokens to transfer
1643
- */
1644
- function _pullTokens (
1645
- IGraphToken _graphToken ,
1646
- address _from ,
1647
- uint256 _amount
1648
- ) private {
1649
- if (_amount > 0 ) {
1650
- require (_graphToken.transferFrom (_from, address (this ), _amount), "!transfer " );
1651
- }
1652
- }
1653
-
1654
- /**
1655
- * @dev Push tokens from this contract to a receiving address.
1656
- * @param _graphToken Token to transfer
1657
- * @param _to Address receiving the tokens
1658
- * @param _amount Amount of tokens to transfer
1659
- */
1660
- function _pushTokens (
1661
- IGraphToken _graphToken ,
1662
- address _to ,
1663
- uint256 _amount
1664
- ) private {
1665
- if (_amount > 0 ) {
1666
- require (_graphToken.transfer (_to, _amount), "!transfer " );
1667
- }
1668
- }
1669
1627
}
0 commit comments