@@ -12,6 +12,7 @@ import {
1212 IPoolAdminNFT
1313} from "../interfaces/superfluid/ISuperfluid.sol " ;
1414import { IYieldBackend } from "../interfaces/superfluid/IYieldBackend.sol " ;
15+ import { YieldBackendHelperLib } from "../libs/YieldBackendHelperLib.sol " ;
1516import { SuperfluidToken } from "./SuperfluidToken.sol " ;
1617import { ERC777Helper } from "../libs/ERC777Helper.sol " ;
1718import { SafeERC20 } from "@openzeppelin-v5/contracts/token/ERC20/utils/SafeERC20.sol " ;
@@ -38,6 +39,7 @@ contract SuperToken is
3839 using SafeCast for uint256 ;
3940 using ERC777Helper for ERC777Helper .Operators;
4041 using SafeERC20 for IERC20 ;
42+ using YieldBackendHelperLib for IYieldBackend;
4143
4244 // See: https://eips.ethereum.org/EIPS/eip-1967#admin-address
4345 bytes32 constant private _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103 ;
@@ -204,29 +206,16 @@ contract SuperToken is
204206 function enableYieldBackend (IYieldBackend newYieldBackend ) external onlyAdmin {
205207 require (address (_yieldBackend) == address (0 ), "yield backend already set " );
206208 _yieldBackend = newYieldBackend;
207- (bool success , ) = address (_yieldBackend).delegatecall (
208- abi.encodeCall (IYieldBackend.enable, ())
209- );
210- require (success, "delegatecall failed " );
211- (success, ) = address (_yieldBackend).delegatecall (
212- abi.encodeCall (IYieldBackend.depositMax, ())
213- );
214- require (success, "delegatecall failed " );
209+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.enable, ()));
210+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.depositMax, ()));
215211 // TODO: emit event
216212 }
217213
218214 // withdraws everything and removes allowances
219215 function disableYieldBackend () external onlyAdmin {
220216 require (address (_yieldBackend) != address (0 ), "yield backend not set " );
221- (bool success , ) = address (_yieldBackend).delegatecall (
222- abi.encodeCall (IYieldBackend.withdrawMax, ())
223- );
224- require (success, "delegatecall failed " );
225- (success, ) = address (_yieldBackend).delegatecall (
226- abi.encodeCall (IYieldBackend.disable, ())
227- );
228- // TODO: should this be allowed to fail?
229- require (success, "delegatecall failed " );
217+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.withdrawMax, ()));
218+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.disable, ()));
230219 _yieldBackend = IYieldBackend (address (0 ));
231220 // TODO: emit event
232221 }
@@ -237,10 +226,7 @@ contract SuperToken is
237226
238227 function withdrawSurplusFromYieldBackend () external onlyAdmin {
239228 require (address (_yieldBackend) != address (0 ), "yield backend not set " );
240- (bool success , ) = address (_yieldBackend).delegatecall (
241- abi.encodeCall (IYieldBackend.withdrawSurplus, (_totalSupply))
242- );
243- require (success, "delegatecall failed " );
229+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.withdrawSurplus, (_totalSupply)));
244230 }
245231
246232 /**************************************************************************
@@ -778,10 +764,7 @@ contract SuperToken is
778764 if (! _skipSelfMint) {
779765 if (address (_yieldBackend) != address (0 )) {
780766 // TODO: shall we deposit all, or just the upgradeAmount?
781- (bool success , ) = address (_yieldBackend).delegatecall (
782- abi.encodeCall (IYieldBackend.deposit, (amount))
783- );
784- require (success, "delegatecall failed " );
767+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.deposit, (amount)));
785768 }
786769
787770 _mint (msg .sender , account, amount, userData.length != 0 /* invokeHook */ ,
@@ -802,10 +785,7 @@ contract SuperToken is
802785 if (address (_yieldBackend) != address (0 )) {
803786 _skipSelfMint = true ;
804787 // TODO: we may want to skip if enough underlying already in the contract
805- (bool success , ) = address (_yieldBackend).delegatecall (
806- abi.encodeCall (IYieldBackend.withdraw, (amount))
807- );
808- require (success, "delegatecall failed " );
788+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.withdraw, (amount)));
809789 _skipSelfMint = false ;
810790 }
811791 }
@@ -908,10 +888,7 @@ contract SuperToken is
908888
909889 if (address (_yieldBackend) != address (0 )) {
910890 // TODO: shall we deposit all, or just the upgradeAmount?
911- (bool success , ) = address (_yieldBackend).delegatecall (
912- abi.encodeCall (IYieldBackend.deposit, (actualUpgradedAmount))
913- );
914- require (success, "delegatecall failed " );
891+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.deposit, (actualUpgradedAmount)));
915892 }
916893
917894 _mint (operator, to, adjustedAmount,
@@ -938,10 +915,7 @@ contract SuperToken is
938915
939916 if (address (_yieldBackend) != address (0 )) {
940917 // TODO: we may want to skip if enough underlying already in the contract
941- (bool success , ) = address (_yieldBackend).delegatecall (
942- abi.encodeCall (IYieldBackend.withdraw, (underlyingAmount))
943- );
944- require (success, "delegatecall failed " );
918+ _yieldBackend.dCall (abi.encodeCall (IYieldBackend.withdraw, (underlyingAmount)));
945919 }
946920
947921 uint256 amountBefore = _underlyingToken.balanceOf (address (this ));
0 commit comments