// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)pragmasolidity ^0.8.0;import"./IAccessControl.sol";
import"../utils/Context.sol";
import"../utils/Strings.sol";
import"../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/abstractcontractAccessControlisContext, IAccessControl, ERC165{
structRoleData {
mapping(address=>bool) members;
bytes32 adminRole;
}
mapping(bytes32=> RoleData) private _roles;
bytes32publicconstant DEFAULT_ADMIN_ROLE =0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/modifieronlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IAccessControl).interfaceId||super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/functionhasRole(bytes32 role, address account) publicviewvirtualoverridereturns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/function_checkRole(bytes32 role) internalviewvirtual{
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/function_checkRole(bytes32 role, address account) internalviewvirtual{
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/functiongetRoleAdmin(bytes32 role) publicviewvirtualoverridereturns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/functiongrantRole(bytes32 role, address account) publicvirtualoverrideonlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/functionrevokeRole(bytes32 role, address account) publicvirtualoverrideonlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/functionrenounceRole(bytes32 role, address account) publicvirtualoverride{
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/function_setupRole(bytes32 role, address account) internalvirtual{
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/function_setRoleAdmin(bytes32 role, bytes32 adminRole) internalvirtual{
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/function_grantRole(bytes32 role, address account) internalvirtual{
if (!hasRole(role, account)) {
_roles[role].members[account] =true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/function_revokeRole(bytes32 role, address account) internalvirtual{
if (hasRole(role, account)) {
_roles[role].members[account] =false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
Contract Source Code
File 2 of 25: Address.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)pragmasolidity ^0.8.1;/**
* @dev Collection of functions related to the address type
*/libraryAddress{
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/functionisContract(address account) internalviewreturns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0// for contracts in construction, since the code is only stored at the end// of the constructor execution.return account.code.length>0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/functionsendValue(addresspayable recipient, uint256 amount) internal{
require(address(this).balance>= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/functionfunctionCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value
) internalreturns (bytesmemory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/functionfunctionCallWithValue(address target,
bytesmemory data,
uint256 value,
stringmemory errorMessage
) internalreturns (bytesmemory) {
require(address(this).balance>= value, "Address: insufficient balance for call");
(bool success, bytesmemory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target, bytesmemory data) internalviewreturns (bytesmemory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/functionfunctionStaticCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalviewreturns (bytesmemory) {
(bool success, bytesmemory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target, bytesmemory data) internalreturns (bytesmemory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/functionfunctionDelegateCall(address target,
bytesmemory data,
stringmemory errorMessage
) internalreturns (bytesmemory) {
(bool success, bytesmemory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/functionverifyCallResultFromTarget(address target,
bool success,
bytesmemory returndata,
stringmemory errorMessage
) internalviewreturns (bytesmemory) {
if (success) {
if (returndata.length==0) {
// only check isContract if the call was successful and the return data is empty// otherwise we already know that it was a contractrequire(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/functionverifyCallResult(bool success,
bytesmemory returndata,
stringmemory errorMessage
) internalpurereturns (bytesmemory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function_revert(bytesmemory returndata, stringmemory errorMessage) privatepure{
// Look for revert reason and bubble it up if presentif (returndata.length>0) {
// The easiest way to bubble the revert reason is using memory via assembly/// @solidity memory-safe-assemblyassembly {
let returndata_size :=mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
Contract Source Code
File 3 of 25: Babylonian.sol
// SPDX-License-Identifier: GPL-3.0pragmasolidity ^0.8.10;libraryBabylonian{
functionsqrt(uint256 y) internalpurereturns (uint256 z) {
if (y >3) {
z = y;
uint256 x = y /2+1;
while (x < z) {
z = x;
x = (y / x + x) /2;
}
} elseif (y !=0) {
z =1;
}
}
}
Contract Source Code
File 4 of 25: Context.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^0.8.0;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 5 of 25: Curve2PoolAdapter.sol
// SPDX-License-Identifier: GPL-3.0/* ******@@@@@@@@@**@*
***@@@@@@@@@@@@@@@@@@@@@@**
*@@@@@@**@@@@@@@@@@@@@@@@@*@@@*
*@@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@*@**
*@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@*
**@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@@@**
**@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@@@@@@@*
**@@@@@@@@@@@@@@@@*************************
**@@@@@@@@***********************************
*@@@***********************&@@@@@@@@@@@@@@@****, ******@@@@*
*********************@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*************
***@@@@@@@@@@@@@@@*****@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@****@@*********
**@@@@@**********************@@@@*****************#@@@@**********
*@@******************************************************
*@************************************
@*******************************
*@*************************
*********************
/$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$
|__ $$ | $$__ $$ /$$__ $$ /$$__ $$
| $$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ | $$ \ $$| $$ \ $$| $$ \ $$
| $$ /$$__ $$| $$__ $$ /$$__ $$ /$$_____/ | $$ | $$| $$$$$$$$| $$ | $$
/$$ | $$| $$ \ $$| $$ \ $$| $$$$$$$$| $$$$$$ | $$ | $$| $$__ $$| $$ | $$
| $$ | $$| $$ | $$| $$ | $$| $$_____/ \____ $$ | $$ | $$| $$ | $$| $$ | $$
| $$$$$$/| $$$$$$/| $$ | $$| $$$$$$$ /$$$$$$$/ | $$$$$$$/| $$ | $$| $$$$$$/
\______/ \______/ |__/ |__/ \_______/|_______/ |_______/ |__/ |__/ \______/ */pragmasolidity ^0.8.10;// Interfacesimport {IStableSwap} from"../interfaces/IStableSwap.sol";
import {IUniswapV2Router02} from"../interfaces/IUniswapV2Router02.sol";
libraryCurve2PoolAdapter{
addressconstant USDC =0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8;
addressconstant USDT =0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9;
addressconstant WETH =0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;
addressconstant SUSHI_ROUTER =0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506;
IUniswapV2Router02 constant sushiRouter = IUniswapV2Router02(SUSHI_ROUTER);
/**
* @notice Swaps a token for 2CRV
* @param _inputToken The token to swap
* @param _amount The token amount to swap
* @param _stableToken The address of the stable token to swap the `_inputToken`
* @param _minStableAmount The minimum output amount of `_stableToken`
* @param _min2CrvAmount The minimum output amount of 2CRV to receive
* @param _recipient The address that's going to receive the 2CRV
* @return The amount of 2CRV received
*/functionswapTokenFor2Crv(
IStableSwap self,
address _inputToken,
uint256 _amount,
address _stableToken,
uint256 _minStableAmount,
uint256 _min2CrvAmount,
address _recipient
) publicreturns (uint256) {
if (_stableToken != USDC && _stableToken != USDT) {
revert INVALID_STABLE_TOKEN();
}
address[] memory route = _swapTokenFor2CrvRoute(_inputToken, _stableToken);
uint256[] memory swapOutputs =
sushiRouter.swapExactTokensForTokens(_amount, _minStableAmount, route, _recipient, block.timestamp);
uint256 stableOutput = swapOutputs[swapOutputs.length-1];
uint256 amountOut = swapStableFor2Crv(self, _stableToken, stableOutput, _min2CrvAmount);
emit SwapTokenFor2Crv(_amount, amountOut, _inputToken);
return amountOut;
}
/**
* @notice Swaps 2CRV for `_outputToken`
* @param _outputToken The output token to receive
* @param _amount The amount of 2CRV to swap
* @param _stableToken The address of the stable token to receive
* @param _minStableAmount The minimum output amount of `_stableToken` to receive
* @param _minTokenAmount The minimum output amount of `_outputToken` to receive
* @param _recipient The address that's going to receive the `_outputToken`
* @return The amount of `_outputToken` received
*/functionswap2CrvForToken(
IStableSwap self,
address _outputToken,
uint256 _amount,
address _stableToken,
uint256 _minStableAmount,
uint256 _minTokenAmount,
address _recipient
) publicreturns (uint256) {
if (_stableToken != USDC && _stableToken != USDT) {
revert INVALID_STABLE_TOKEN();
}
uint256 stableAmount = swap2CrvForStable(self, _stableToken, _amount, _minStableAmount);
address[] memory route = _swapStableForTokenRoute(_outputToken, _stableToken);
uint256[] memory swapOutputs =
sushiRouter.swapExactTokensForTokens(stableAmount, _minTokenAmount, route, _recipient, block.timestamp);
uint256 amountOut = swapOutputs[swapOutputs.length-1];
emit Swap2CrvForToken(_amount, amountOut, _outputToken);
return amountOut;
}
/**
* @notice Swaps 2CRV for a stable token
* @param _stableToken The stable token address
* @param _amount The amount of 2CRV to sell
* @param _minStableAmount The minimum amount stables to receive
* @return The amount of stables received
*/functionswap2CrvForStable(IStableSwap self, address _stableToken, uint256 _amount, uint256 _minStableAmount)
publicreturns (uint256)
{
int128 stableIndex;
if (_stableToken != USDC && _stableToken != USDT) {
revert INVALID_STABLE_TOKEN();
}
if (_stableToken == USDC) {
stableIndex =0;
}
if (_stableToken == USDT) {
stableIndex =1;
}
returnself.remove_liquidity_one_coin(_amount, stableIndex, _minStableAmount);
}
/**
* @notice Swaps a stable token for 2CRV
* @param _stableToken The stable token address
* @param _amount The amount of `_stableToken` to sell
* @param _min2CrvAmount The minimum amount of 2CRV to receive
* @return The amount of 2CRV received
*/functionswapStableFor2Crv(IStableSwap self, address _stableToken, uint256 _amount, uint256 _min2CrvAmount)
publicreturns (uint256)
{
uint256[2] memory deposits;
if (_stableToken != USDC && _stableToken != USDT) {
revert INVALID_STABLE_TOKEN();
}
if (_stableToken == USDC) {
deposits = [_amount, 0];
}
if (_stableToken == USDT) {
deposits = [0, _amount];
}
returnself.add_liquidity(deposits, _min2CrvAmount);
}
function_swapStableForTokenRoute(address _outputToken, address _stableToken)
internalpurereturns (address[] memory)
{
address[] memory route;
if (_outputToken == WETH) {
// handle weth swaps
route =newaddress[](2);
route[0] = _stableToken;
route[1] = _outputToken;
} else {
route =newaddress[](3);
route[0] = _stableToken;
route[1] = WETH;
route[2] = _outputToken;
}
return route;
}
function_swapTokenFor2CrvRoute(address _inputToken, address _stableToken)
internalpurereturns (address[] memory)
{
address[] memory route;
if (_inputToken == WETH) {
// handle weth swaps
route =newaddress[](2);
route[0] = _inputToken;
route[1] = _stableToken;
} else {
route =newaddress[](3);
route[0] = _inputToken;
route[1] = WETH;
route[2] = _stableToken;
}
return route;
}
eventSwap2CrvForToken(uint256 _amountIn, uint256 _amountOut, address _token);
eventSwapTokenFor2Crv(uint256 _amountIn, uint256 _amountOut, address _token);
errorINVALID_STABLE_TOKEN();
}
Contract Source Code
File 6 of 25: ERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)pragmasolidity ^0.8.0;import"./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/abstractcontractERC165isIERC165{
/**
* @dev See {IERC165-supportsInterface}.
*/functionsupportsInterface(bytes4 interfaceId) publicviewvirtualoverridereturns (bool) {
return interfaceId ==type(IERC165).interfaceId;
}
}
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)pragmasolidity ^0.8.0;/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/interfaceIAccessControl{
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/eventRoleAdminChanged(bytes32indexed role, bytes32indexed previousAdminRole, bytes32indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/eventRoleGranted(bytes32indexed role, addressindexed account, addressindexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/eventRoleRevoked(bytes32indexed role, addressindexed account, addressindexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/functionhasRole(bytes32 role, address account) externalviewreturns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/functiongetRoleAdmin(bytes32 role) externalviewreturns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/functiongrantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/functionrevokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/functionrenounceRole(bytes32 role, address account) external;
}
Contract Source Code
File 10 of 25: IERC165.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/interfaceIERC165{
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 11 of 25: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 amount
) externalreturns (bool);
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.10;import {Ownable} from"openzeppelin-contracts/contracts/access/Ownable.sol";
import {IERC20} from"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IIncentiveReceiver} from"../interfaces/IIncentiveReceiver.sol";
import {OneInchZapLib} from"src/libraries/OneInchZapLib.sol";
import {I1inchAggregationRouterV4} from"src/interfaces/I1inchAggregationRouterV4.sol";
import {Keepable, Governable} from"./Keepable.sol";
contractIncentiveReceiverisIIncentiveReceiver, Keepable{
usingOneInchZapLibforI1inchAggregationRouterV4;
I1inchAggregationRouterV4 internal router;
// Registry of allowed depositorsmapping(address=>bool) public depositors;
// Registry of allowed tokensmapping(address=>bool) public destinationTokens;
/**
* @param _governor The address of the owner of this contract
*/constructor(address _governor, addresspayable _router) Governable(_governor) {
router = I1inchAggregationRouterV4(_router);
}
/**
* @notice To enforce only allowed depositors to deposit funds
*/modifieronlyDepositors() {
if (!depositors[msg.sender]) {
revert NotAuthorized();
}
_;
}
/**
* @notice Used by depositors to deposit incentives
* @param _token the address of the asset to be deposited
* @param _amount the amount of `_token` to deposit
*/functiondeposit(address _token, uint256 _amount) externalonlyDepositors{
IERC20(_token).transferFrom(msg.sender, address(this), _amount);
emit Deposit(msg.sender, _token, _amount);
}
/**
* @notice Used to register new depositors
* @param _depositor the address of the new depositor
*/functionaddDepositor(address _depositor) externalonlyGovernor{
_isValidAddress(_depositor);
depositors[_depositor] =true;
emit DepositorAdded(msg.sender, _depositor);
}
functionaddToken(address _token) externalonlyGovernor{
_isValidAddress(_token);
destinationTokens[_token] =true;
emit TokenAdded(msg.sender, _token);
}
/**
* @notice Used to remove depositors
* @param _depositor the address of the depositor to remove
*/functionremoveDepositor(address _depositor) externalonlyGovernor{
depositors[_depositor] =false;
emit DepositorRemoved(msg.sender, _depositor);
}
functionremoveToken(address _token) externalonlyGovernor{
destinationTokens[_token] =false;
emit TokenRemoved(msg.sender, _token);
}
functionupdateRouter(addresspayable _router) externalonlyGovernor{
_isValidAddress(_router);
address oldRouter =address(router);
router = I1inchAggregationRouterV4(_router);
emit UpdateRouter(oldRouter, _router);
}
functionswap(OneInchZapLib.SwapParams calldata _swapParams) externalonlyKeeper{
_isWhitelisted(_swapParams.desc.dstToken);
OneInchZapLib.SwapParams memory swap = _swapParams;
if (swap.desc.dstReceiver !=address(this)) {
revert InvalidReceiver();
}
router.perform1InchSwap(swap);
}
/**
* @notice Moves assets from the strategy to `_to`
* @param _assets An array of IERC20 compatible tokens to move out from the strategy
* @param _withdrawNative `true` if we want to move the native asset from the strategy
*/functionwithdraw(address _to, address[] memory _assets, bool _withdrawNative) externalonlyGovernor{
_isValidAddress(_to);
for (uint256 i; i < _assets.length; i++) {
IERC20 asset = IERC20(_assets[i]);
uint256 assetBalance = asset.balanceOf(address(this));
// No need to transferif (assetBalance ==0) {
continue;
}
// Transfer the ERC20 tokens
asset.transfer(_to, assetBalance);
}
uint256 nativeBalance =address(this).balance;
// Nothing else to doif (_withdrawNative && nativeBalance >0) {
// Transfer the native currencypayable(_to).transfer(nativeBalance);
}
emit Withdrawal(msg.sender, _to, _assets, _withdrawNative);
}
function_isValidAddress(address _address) internalpure{
if (_address ==address(0)) {
revert InvalidAddress();
}
}
function_isWhitelisted(address _token) internalview{
if (!destinationTokens[_token]) {
revert NotWhitelisted();
}
}
/**
* @notice Emitted when a depositor deposits incentives
* @param depositor the contract that deposited
* @param token the address of the asset that was deposited
* @param amount the amount of `token` that was deposited
*/eventDeposit(addressindexed depositor, addressindexed token, uint256 amount);
/**
* @notice Emitted when a new depositor is registered
* @param owner the current owner of this contract
* @param depositor the address of the new depositor
*/eventDepositorAdded(addressindexed owner, addressindexed depositor);
eventTokenAdded(addressindexed owner, addressindexed token);
eventUpdateRouter(addressindexed oldAddress, addressindexed newAddress);
/**
* @notice Emitted when a new depositor is registered
* @param owner the current owner of this contract
* @param depositor the address of the new depositor
*/eventDepositorRemoved(addressindexed owner, addressindexed depositor);
eventTokenRemoved(addressindexed owner, addressindexed depositor);
eventWithdrawal(address owner, address receiver, address[] assets, bool includeNative);
errorNotAuthorized();
errorInvalidAddress();
errorNotWhitelisted();
errorInvalidReceiver();
}
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 22 of 25: SafeERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)pragmasolidity ^0.8.0;import"../IERC20.sol";
import"../extensions/draft-IERC20Permit.sol";
import"../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/librarySafeERC20{
usingAddressforaddress;
functionsafeTransfer(
IERC20 token,
address to,
uint256 value
) internal{
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
functionsafeTransferFrom(
IERC20 token,
addressfrom,
address to,
uint256 value
) internal{
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/functionsafeApprove(
IERC20 token,
address spender,
uint256 value
) internal{
// safeApprove should only be called when setting an initial allowance,// or when resetting it to zero. To increase and decrease it, use// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'require(
(value ==0) || (token.allowance(address(this), spender) ==0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
functionsafeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal{
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
functionsafeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal{
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
functionsafePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal{
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore +1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/function_callOptionalReturn(IERC20 token, bytesmemory data) private{
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that// the target address contains contract code and also asserts for success in the low-level call.bytesmemory returndata =address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length>0) {
// Return data is optionalrequire(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
Contract Source Code
File 23 of 25: Strings.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)pragmasolidity ^0.8.0;/**
* @dev String operations.
*/libraryStrings{
bytes16privateconstant _HEX_SYMBOLS ="0123456789abcdef";
uint8privateconstant _ADDRESS_LENGTH =20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/functiontoString(uint256 value) internalpurereturns (stringmemory) {
// Inspired by OraclizeAPI's implementation - MIT licence// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.solif (value ==0) {
return"0";
}
uint256 temp = value;
uint256 digits;
while (temp !=0) {
digits++;
temp /=10;
}
bytesmemory buffer =newbytes(digits);
while (value !=0) {
digits -=1;
buffer[digits] =bytes1(uint8(48+uint256(value %10)));
value /=10;
}
returnstring(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/functiontoHexString(uint256 value) internalpurereturns (stringmemory) {
if (value ==0) {
return"0x00";
}
uint256 temp = value;
uint256 length =0;
while (temp !=0) {
length++;
temp >>=8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/functiontoHexString(uint256 value, uint256 length) internalpurereturns (stringmemory) {
bytesmemory buffer =newbytes(2* length +2);
buffer[0] ="0";
buffer[1] ="x";
for (uint256 i =2* length +1; i >1; --i) {
buffer[i] = _HEX_SYMBOLS[value &0xf];
value >>=4;
}
require(value ==0, "Strings: hex length insufficient");
returnstring(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/functiontoHexString(address addr) internalpurereturns (stringmemory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
Contract Source Code
File 24 of 25: SushiAdapter.sol
// SPDX-License-Identifier: GPL-3.0/* ******@@@@@@@@@**@*
***@@@@@@@@@@@@@@@@@@@@@@**
*@@@@@@**@@@@@@@@@@@@@@@@@*@@@*
*@@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@*@**
*@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@*
**@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@@@**
**@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@@@@@@@*
**@@@@@@@@@@@@@@@@*************************
**@@@@@@@@***********************************
*@@@***********************&@@@@@@@@@@@@@@@****, ******@@@@*
*********************@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*************
***@@@@@@@@@@@@@@@*****@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@****@@*********
**@@@@@**********************@@@@*****************#@@@@**********
*@@******************************************************
*@************************************
@*******************************
*@*************************
*********************
/$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$
|__ $$ | $$__ $$ /$$__ $$ /$$__ $$
| $$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ | $$ \ $$| $$ \ $$| $$ \ $$
| $$ /$$__ $$| $$__ $$ /$$__ $$ /$$_____/ | $$ | $$| $$$$$$$$| $$ | $$
/$$ | $$| $$ \ $$| $$ \ $$| $$$$$$$$| $$$$$$ | $$ | $$| $$__ $$| $$ | $$
| $$ | $$| $$ | $$| $$ | $$| $$_____/ \____ $$ | $$ | $$| $$ | $$| $$ | $$
| $$$$$$/| $$$$$$/| $$ | $$| $$$$$$$ /$$$$$$$/ | $$$$$$$/| $$ | $$| $$$$$$/
\______/ \______/ |__/ |__/ \_______/|_______/ |_______/ |__/ |__/ \______/ */pragmasolidity ^0.8.10;import {IERC20} from"openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from"openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IUniswapV2Router02} from"../interfaces/IUniswapV2Router02.sol";
librarySushiAdapter{
usingSafeERC20forIERC20;
/**
* Sells the received tokens for the provided amounts for the last token in the route
* Temporary solution until we implement accumulation policy.
* @param self the sushi router used to perform the sale.
* @param _assetAmounts output amount from selling the tokens.
* @param _tokens tokens to sell.
* @param _recepient recepient address.
* @param _routes routes to sell each token
*/functionsellTokens(
IUniswapV2Router02 self,
uint256[] memory _assetAmounts,
address[] memory _tokens,
address _recepient,
address[][] memory _routes
) public{
uint256 amountsLength = _assetAmounts.length;
uint256 tokensLength = _tokens.length;
uint256 routesLength = _routes.length;
require(amountsLength == tokensLength, "SRE1");
require(routesLength == tokensLength, "SRE1");
uint256 deadline =block.timestamp+120;
for (uint256 i =0; i < tokensLength; i++) {
_sellTokens(self, IERC20(_tokens[i]), _assetAmounts[i], _recepient, deadline, _routes[i]);
}
}
/**
* Sells the received tokens for the provided amounts for ETH
* Temporary solution until we implement accumulation policy.
* @param self the sushi router used to perform the sale.
* @param _assetAmounts output amount from selling the tokens.
* @param _tokens tokens to sell.
* @param _recepient recepient address.
* @param _routes routes to sell each token.
*/functionsellTokensForEth(
IUniswapV2Router02 self,
uint256[] memory _assetAmounts,
address[] memory _tokens,
address _recepient,
address[][] memory _routes
) public{
uint256 amountsLength = _assetAmounts.length;
uint256 tokensLength = _tokens.length;
uint256 routesLength = _routes.length;
require(amountsLength == tokensLength, "SRE1");
require(routesLength == tokensLength, "SRE1");
uint256 deadline =block.timestamp+120;
for (uint256 i =0; i < tokensLength; i++) {
_sellTokensForEth(self, IERC20(_tokens[i]), _assetAmounts[i], _recepient, deadline, _routes[i]);
}
}
/**
* Sells one token for a given amount of another.
* @param self the Sushi router used to perform the sale.
* @param _route route to swap the token.
* @param _assetAmount output amount of the last token in the route from selling the first.
* @param _recepient recepient address.
*/functionsellTokensForExactTokens(
IUniswapV2Router02 self,
address[] memory _route,
uint256 _assetAmount,
address _recepient,
address _token
) public{
require(_route.length>=2, "SRE2");
uint256 balance = IERC20(_route[0]).balanceOf(_recepient);
if (balance >0) {
uint256 deadline =block.timestamp+120; // Two minutes
_sellTokens(self, IERC20(_token), _assetAmount, _recepient, deadline, _route);
}
}
function_sellTokensForEth(
IUniswapV2Router02 _sushiRouter,
IERC20 _token,
uint256 _assetAmount,
address _recepient,
uint256 _deadline,
address[] memory _route
) private{
uint256 balance = _token.balanceOf(_recepient);
if (balance >0) {
_sushiRouter.swapExactTokensForETH(balance, _assetAmount, _route, _recepient, _deadline);
}
}
functionswapTokens(
IUniswapV2Router02 self,
uint256 _amountIn,
uint256 _amountOutMin,
address[] memory _path,
address _recepient
) external{
self.swapExactTokensForTokens(_amountIn, _amountOutMin, _path, _recepient, block.timestamp);
}
function_sellTokens(
IUniswapV2Router02 _sushiRouter,
IERC20 _token,
uint256 _assetAmount,
address _recepient,
uint256 _deadline,
address[] memory _route
) private{
uint256 balance = _token.balanceOf(_recepient);
if (balance >0) {
_sushiRouter.swapExactTokensForTokens(balance, _assetAmount, _route, _recepient, _deadline);
}
}
// ERROR MAPPING:// {// "SRE1": "Rewards: token, amount and routes lenght must match",// "SRE2": "Length of route must be at least 2",// }
}
Contract Source Code
File 25 of 25: draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/interfaceIERC20Permit{
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/functionpermit(address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/functionnonces(address owner) externalviewreturns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/// solhint-disable-next-line func-name-mixedcasefunctionDOMAIN_SEPARATOR() externalviewreturns (bytes32);
}