88
99pragma solidity 0.8.18 ;
1010
11- import "@openzeppelin/contracts/token/ERC20/IERC20.sol " ;
1211import "./IArbitrator.sol " ;
1312import "./IDisputeKit.sol " ;
1413import "./ISortitionModule.sol " ;
14+ import "../libraries/SafeERC20.sol " ;
1515
1616/// @title KlerosCore
1717/// Core arbitrator contract for Kleros v2.
1818/// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts.
1919contract KlerosCore is IArbitrator {
20+ using SafeERC20 for IERC20 ;
21+
2022 // ************************************* //
2123 // * Enums / Structs * //
2224 // ************************************* //
@@ -508,7 +510,7 @@ contract KlerosCore is IArbitrator {
508510 if (! currencyRates[_feeToken].feePaymentAccepted) revert TokenNotAccepted ();
509511 if (_feeAmount < arbitrationCost (_extraData, _feeToken)) revert ArbitrationFeesNotEnough ();
510512
511- require (_safeTransferFrom ( _feeToken, msg .sender , address (this ), _feeAmount), "Transfer failed " );
513+ require (_feeToken. safeTransferFrom ( msg .sender , address (this ), _feeAmount), "Transfer failed " );
512514 return _createDispute (_numberOfChoices, _extraData, _feeToken, _feeAmount);
513515 }
514516
@@ -792,9 +794,9 @@ contract KlerosCore is IArbitrator {
792794 payable (governor).send (round.totalFeesForJurors);
793795 } else {
794796 // The dispute fees were paid in ERC20
795- _safeTransfer ( round.feeToken, governor, round.totalFeesForJurors);
797+ round.feeToken. safeTransfer ( governor, round.totalFeesForJurors);
796798 }
797- _safeTransfer ( pinakion, governor, _params.pnkPenaltiesInRound);
799+ pinakion. safeTransfer ( governor, _params.pnkPenaltiesInRound);
798800 emit LeftoverRewardSent (
799801 _params.disputeID,
800802 _params.round,
@@ -834,21 +836,21 @@ contract KlerosCore is IArbitrator {
834836
835837 // Give back the locked PNKs in case the juror fully unstaked earlier.
836838 if (jurors[account].stakedPnk[dispute.courtID] == 0 ) {
837- _safeTransfer ( pinakion, account, pnkLocked);
839+ pinakion. safeTransfer ( account, pnkLocked);
838840 }
839841
840842 // Transfer the rewards
841843 uint256 pnkReward = ((_params.pnkPenaltiesInRound / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
842844 round.sumPnkRewardPaid += pnkReward;
843845 uint256 feeReward = ((round.totalFeesForJurors / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
844846 round.sumFeeRewardPaid += feeReward;
845- _safeTransfer ( pinakion, account, pnkReward);
847+ pinakion. safeTransfer ( account, pnkReward);
846848 if (round.feeToken == NATIVE_CURRENCY) {
847849 // The dispute fees were paid in ETH
848850 payable (account).send (feeReward);
849851 } else {
850852 // The dispute fees were paid in ERC20
851- _safeTransfer ( round.feeToken, account, feeReward);
853+ round.feeToken. safeTransfer ( account, feeReward);
852854 }
853855 emit TokenAndETHShift (
854856 account,
@@ -866,15 +868,15 @@ contract KlerosCore is IArbitrator {
866868 uint256 leftoverFeeReward = round.totalFeesForJurors - round.sumFeeRewardPaid;
867869 if (leftoverPnkReward != 0 || leftoverFeeReward != 0 ) {
868870 if (leftoverPnkReward != 0 ) {
869- _safeTransfer ( pinakion, governor, leftoverPnkReward);
871+ pinakion. safeTransfer ( governor, leftoverPnkReward);
870872 }
871873 if (leftoverFeeReward != 0 ) {
872874 if (round.feeToken == NATIVE_CURRENCY) {
873875 // The dispute fees were paid in ETH
874876 payable (governor).send (leftoverFeeReward);
875877 } else {
876878 // The dispute fees were paid in ERC20
877- _safeTransfer ( round.feeToken, governor, leftoverFeeReward);
879+ round.feeToken. safeTransfer ( governor, leftoverFeeReward);
878880 }
879881 }
880882 emit LeftoverRewardSent (
@@ -1138,7 +1140,7 @@ contract KlerosCore is IArbitrator {
11381140 if (_stake >= currentStake) {
11391141 transferredAmount = _stake - currentStake;
11401142 if (transferredAmount > 0 ) {
1141- if (_safeTransferFrom ( pinakion, _account, address (this ), transferredAmount)) {
1143+ if (pinakion. safeTransferFrom ( _account, address (this ), transferredAmount)) {
11421144 if (currentStake == 0 ) {
11431145 juror.courtIDs.push (_courtID);
11441146 }
@@ -1151,7 +1153,7 @@ contract KlerosCore is IArbitrator {
11511153 // Keep locked PNKs in the contract and release them after dispute is executed.
11521154 transferredAmount = currentStake - juror.lockedPnk[_courtID] - _penalty;
11531155 if (transferredAmount > 0 ) {
1154- if (_safeTransfer ( pinakion, _account, transferredAmount)) {
1156+ if (pinakion. safeTransfer ( _account, transferredAmount)) {
11551157 for (uint256 i = juror.courtIDs.length ; i > 0 ; i-- ) {
11561158 if (juror.courtIDs[i - 1 ] == _courtID) {
11571159 juror.courtIDs[i - 1 ] = juror.courtIDs[juror.courtIDs.length - 1 ];
@@ -1166,7 +1168,7 @@ contract KlerosCore is IArbitrator {
11661168 } else {
11671169 transferredAmount = currentStake - _stake - _penalty;
11681170 if (transferredAmount > 0 ) {
1169- if (! _safeTransfer ( pinakion, _account, transferredAmount)) {
1171+ if (! pinakion. safeTransfer ( _account, transferredAmount)) {
11701172 return false ;
11711173 }
11721174 }
@@ -1214,38 +1216,6 @@ contract KlerosCore is IArbitrator {
12141216 }
12151217 }
12161218
1217- /// @dev Calls transfer() without reverting.
1218- /// @param _token Token to transfer.
1219- /// @param _to Recepient address.
1220- /// @param _value Amount transferred.
1221- /// @return Whether transfer succeeded or not.
1222- function _safeTransfer (IERC20 _token , address _to , uint256 _value ) internal returns (bool ) {
1223- (bool success , bytes memory data ) = address (_token).call (abi.encodeCall (IERC20 .transfer, (_to, _value)));
1224- return (success && (data.length == 0 || abi.decode (data, (bool ))));
1225- }
1226-
1227- /// @dev Calls transferFrom() without reverting.
1228- /// @param _token Token to transfer.
1229- /// @param _from Sender address.
1230- /// @param _to Recepient address.
1231- /// @param _value Amount transferred.
1232- /// @return Whether transfer succeeded or not.
1233- function _safeTransferFrom (IERC20 _token , address _from , address _to , uint256 _value ) internal returns (bool ) {
1234- (bool success , bytes memory data ) = address (_token).call (
1235- abi.encodeCall (IERC20 .transferFrom, (_from, _to, _value))
1236- );
1237- return (success && (data.length == 0 || abi.decode (data, (bool ))));
1238- }
1239-
1240- /// @dev Increases the allowance granted to `spender` by the caller.
1241- /// @param _token Token to transfer.
1242- /// @param _spender The address which will spend the funds.
1243- /// @param _addedValue The amount of tokens to increase the allowance by.
1244- function _increaseAllowance (IERC20 _token , address _spender , uint256 _addedValue ) public virtual returns (bool ) {
1245- _token.approve (_spender, _token.allowance (address (this ), _spender) + _addedValue);
1246- return true ;
1247- }
1248-
12491219 // ************************************* //
12501220 // * Errors * //
12511221 // ************************************* //
0 commit comments