// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import { IComptroller } from "../interfaces/IComptroller.sol";
/**
* @title Comptroller Manager
* @dev This abstract contract provides mechanisms for managing a comptroller
* reference within contracts.
* It includes functionality to set and update the comptroller via a governance
* process.
* @notice This contract is intended to be inherited by other contracts
* requiring control over comptroller functionalities.
*/
abstract contract ComptrollerManager {
/// @notice The active comptroller contract
IComptroller public comptroller;
/// @notice The proposed new comptroller, pending acceptance
address public proposedComptroller;
/// @dev Error thrown when a zero address is provided where a valid address
/// is required
error ComptrollerManager_EntityCannotBe0Address();
/// @dev Error thrown when an action is taken by an entity other than the
/// comptroller admin
error NotComptrollerAdmin();
/// @dev Error thrown when an action is taken by an entity other than the
/// proposed comptroller
error NotProposedComptroller();
/// @notice Emitted when the comptroller is changed
event ComptrollerChanged(address oldComptroller, address newComptroller);
/**
* @dev Initializes the contract by setting the comptroller.
* @param _comptroller The address of the comptroller.
*/
function _comptrollerInit(address _comptroller) internal virtual {
if (_comptroller == address(0)) {
revert ComptrollerManager_EntityCannotBe0Address();
}
comptroller = IComptroller(_comptroller);
}
/**
* @notice Proposes a new comptroller to be accepted by the new comptroller
* itself.
* @dev Sets a new proposed comptroller, which needs to accept its role to
* be effective.
* @param _comptroller The address of the proposed new comptroller.
*/
function setComptroller(address _comptroller) external virtual {
if (msg.sender != comptroller.admin()) {
revert NotComptrollerAdmin();
}
if (_comptroller == address(0)) {
revert ComptrollerManager_EntityCannotBe0Address();
}
proposedComptroller = _comptroller;
}
/**
* @notice Accepts the role of comptroller, updating the contract's
* comptroller reference.
* @dev The proposed comptroller calls this function to accept the role,
* triggering the ComptrollerChanged event.
*/
function acceptComptroller() external virtual {
if (msg.sender != proposedComptroller) {
revert NotProposedComptroller();
}
emit ComptrollerChanged(address(comptroller), proposedComptroller);
comptroller = IComptroller(proposedComptroller);
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
library Errors {
/*//////////////////////////////////////////////////////////////////////////
GMX FACTORY ERRORS
//////////////////////////////////////////////////////////////////////////*/
error GmxFactory_NotPlatformLogic();
error GmxFactory_TransactionFailedOnTokenTransfer();
error GmxFactory_InsufficientGmxExecutionFee();
error GmxFactory_TokenNotAllowed();
error GmxFactory_DifferentCollateralToken();
error GmxFactory_IncorrectGrossFeeAmount();
error GmxFactory_HigherSizeDelta();
error GmxFactory_NotOwner();
error GmxFactory_NotAdapterOwner();
error GmxFactory_PositionNotOpened();
error GmxFactory_TransferFailed();
error GmxFactory_NotNftHandler();
error GmxFactory_NotPositionRouter();
error GmxFactory_NotAdapter();
error GmxFactory_NotGmxPositionRouter();
error GmxFactory_NotCallBackReceiver();
error GmxFactory_NotEnoughFeeFunds();
error GmxFactory_SameIndexToken();
error GmxFactory_NotComptrollerAdmin();
error GmxFactory_DifferentPath();
error GmxFactory_EntityCannotBe0Address();
error GmxFactory_NotProposedComptroller();
error GmxFactory_PreviosOrderPending();
error GmxFactory_NotPositionNFT();
error GmxFactory_UnknownOrderKey();
/*//////////////////////////////////////////////////////////////////////////
VERTEX FACTORY ERRORS
//////////////////////////////////////////////////////////////////////////*/
error VertexFactory_NotPlatformLogic();
error VertexFactory_TokenNotAllowed();
error VertexFactory_NotComptrollerAdmin();
error VertexFactory_NotProposedComptroller();
error VertexFactory_EntityCannotBe0Address();
error VertexFactory_WrongValueSent(
uint256 valueSent, uint256 expectedFeeAmount
);
error VertexFactory_NotCallbackWallet();
error VertexFactoryCallback_FailedToSendFundsToUser();
error VertexFactoryCallback_FailedToSendFundsToCallbackWallet();
/*//////////////////////////////////////////////////////////////////////////
PLATFORM LOGIC ERRORS
//////////////////////////////////////////////////////////////////////////*/
error PlatformLogic_Unavailable();
error PlatformLogic_NotFactory();
error PlatformLogic_WrongFeeAmount();
error PlatformLogic_GivenZeroAddress();
error PlatformLogic_ExceedsAllowance(uint256 feeAmount);
error PlatformLogic_NotEnoughBalance();
error PlatformLogic_AddressSetInComptrollerIsNotThisOne();
error PlatformLogic_FeeAmountCannotBeNull();
error PlatformLogic_NotComptrollerAdmin();
error PlatformLogic_InvalidSigner();
error PlatformLogic_CodeCreatorIsNotMsgSender();
error PlatformLogic_RefereeNotMsgSender();
error PlatformLogic_ComptrollerCannot0BeAddress();
error PlatformLogic_TransactionFailed();
error PlatformLogic_WrongValueSent(
uint256 expectedFeeAmount, uint256 feeAmountSent
);
error PlatformLogic_ExceedingBps();
error PlatformLogic_NotPositionNFT();
/*//////////////////////////////////////////////////////////////////////////
GXM ADAPTER ERRORS
//////////////////////////////////////////////////////////////////////////*/
error GmxAdapter_IncorrectFeeAmount();
error GmxAdapter_WithdrawFailed();
error GmxAdapter_Unauthorized();
error GmxAdapter_CannotBeZeroAddress();
error GmxAdapter_NotComptrollerAdmin();
error GmxAdapter_NotAdapterOwner();
error GmxAdapter_NotGmxFactory();
error GmxAdapter_NotPositionNFT();
/*//////////////////////////////////////////////////////////////////////////
COMPTROLLER ERRORS
//////////////////////////////////////////////////////////////////////////*/
error Comptroller_CallerNotAdmin();
error Comptroller_AddressNotSet();
error Comptroller_AdminCannotBe0Address();
error Comptroller_UnauthorizedAccount(address unauthorizedUser);
error Comptroller_AddressGivenIsZeroAddress();
/*//////////////////////////////////////////////////////////////////////////
REWARDSCLAIMER ERRORS
//////////////////////////////////////////////////////////////////////////*/
error RewardsClaimer_NotOwner();
error RewardsClaimer_NotPlatformLogic();
error RewardsClaimer_UserHasNoRewardsToClaimOrHasExceededClaimingAmount();
error RewardsClaimer_CannotClaimRewardsInTheSameBlock();
error RewardsClaimer_CannotSendTo0Address();
error RewardsClaimer_NotWhitelistedPlatform();
error RewardsClaimer_ExceedsMaxClaimForPlatform();
error RewardsClaimer_TransferFailed();
/*//////////////////////////////////////////////////////////////////////////
POSITIONNFT ERRORS
//////////////////////////////////////////////////////////////////////////*/
error PositionNFT_CallerIsNotNftHandler();
error PositionNft_NotComptrollerAdmin();
error PositionNFT_NotAdapterOwner();
error PositionNFT_PositionNonExistantOrAlreadyClosed();
error PositionNFT_PositionAlreadyMinted();
error PositionNFT_NotNftOwner();
error PositionNFT_PositionNotClosed();
error PositionNFT_NotPositionOwner(address positionOwner);
error PositionNFT_NotOwner();
error PositionNFT_NotComptrollerAdmin();
error PositionNFT_ComptrollerCannot0BeAddress();
error PositionNFT_NotProposedComptroller();
error PositionNFT_TokenNotAllowed();
error PositonNFT_UserHasAPendingPosition();
/*//////////////////////////////////////////////////////////////////////////
PEARSTAKER ERRORS
//////////////////////////////////////////////////////////////////////////*/
error PearStaker_TransferFailed();
error PearStaker_ExitFeeTransferFailed();
error PearStaker_InsufficientBalance(uint256 balance, uint256 amount);
error PearStaker_InsufficientStakeAmount(uint256 amount);
error StakingRewards_NotPlatformLogic();
error PearStaker_ZeroEarnedAmount();
error PearStaker_StakesAreNotTransferable();
error PearStaker_PearTokenAlreadyInitialized();
error PearStaker_NotComptrollerAdmin();
/*//////////////////////////////////////////////////////////////////////////
FEEREBATEMANAGER ERRORS
//////////////////////////////////////////////////////////////////////////*/
error FeeRebateManager_InvalidTier();
error FeeRebateManager_InvalidRebateTier();
error FeeRebateManager_InvalidDiscountTier();
error FeeRebateManager_AlreadyClaimed();
error FeeRebateManager_NoRebateAvailable();
error FeeRebateManager_InsufficientFunds();
error FeeRebateManager_NotComptrollerAdmin();
error FeeRebateManager_NotFactory();
error FeeRebateManager_NotPlatformLogic();
error FeeRebateManager_TransferFailed();
error FeeRebateManager_RebatesDisabled();
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
/**
* @title IAcceptComptroller
* @notice Interface is used to provide the addresses with a way to call the
* acceptComptroller function
* @notice The acceptComptroller function is implemented accross all
* Comptroller complient contracts and is used as a two step ownership transfer
*/
interface IAcceptComptroller {
function acceptComptroller() external;
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import { IAcceptComptroller } from "./IAcceptComptroller.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title IComptroller
* @dev Interface for the Comptroller, which handles various administrative
* tasks across the platform.
* This interface allows for management of tokens, addresses, and certain key
* settings across the system.
*/
interface IComptroller {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
event ComptrollerTransferAdmin(address oldAdmin, address newAdmin);
event ComptrollerAcceptNewAdmin(address oldAdmin, address newAdmin);
event SetAllowedToken(IERC20 token, bool allowed);
event SetGmxFactory(address oldAddress, address newAddress);
event SetVertexFactory(address oldAddress, address newAddress);
event SetCallBackReceiver(address oldAddress, address newAddress);
event SetGmxAdapter(address oldAddress, address newAddress);
event SetPlatformLogic(address oldAddress, address newAddress);
event SetPositionNft(address oldAddress, address newAddress);
event SetGmxReader(address oldAddress, address newAddress);
event SetGmxVault(address oldAddress, address newAddress);
event SetGmxRouter(address oldAddress, address newAddress);
event SetGmxExchangeRouter(address oldAddress, address newAddress);
event SetReferralCode(bytes32 oldReferralCode, bytes32 newReferralCode);
event SetMaxCallbackgasLimit(uint256 oldLimit, uint256 newLimit);
event SetEthUsdAggregator(address oldAddress, address newAddress);
event SetArbRewardsClaimer(address oldAddress, address newAddress);
event SetStPearToken(address oldAddress, address newAddress);
event SetFeeRebateManager(address oldAddress, address newAddress);
/*//////////////////////////////////////////////////////////////////////////
SETTER FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Transfers administrative control to a new admin.
/// @param newAdmin The address to which the admin role will be transferred.
function transferAdmin(address newAdmin) external;
/// @notice Accepts the role of admin for the caller.
function acceptAdmin() external;
/// @notice Accepts a comptroller assignment to ensure continuity in
/// dependent contracts.
/// @param acceptControllerContract The contract address that needs to
/// accept the comptroller change.
function acceptComptroller(IAcceptComptroller acceptControllerContract)
external;
/// @notice Sets a unique referral code for identifying transactions
/// originating from Pear's systems.
/// @param code The new referral code to set.
function setReferralCode(bytes32 code) external;
/// @notice Assigns the callback receiver contract which handles
/// post-transaction events.
/// @param receiver The address of the new callback receiver contract.
function setCallBackReceiver(address receiver) external;
/// @notice Sets the address of the GMX Factory contract responsible for
/// order management.
/// @param factory The address of the GMX Factory contract.
function setGmxFactory(address factory) external;
/// @param factory The address of the Vertex Factory contract.
function setVertexFactory(address factory) external;
/// @notice Sets the address of the GMX Adapter used for interfacing with
/// external contracts.
/// @param adapter The new adapter address.
function setGmxAdapter(address adapter) external;
/// @notice Sets the address of the platform logic contract which contains
/// core business logic.
/// @param _platformLogic The address of the platform logic contract.
function setPlatformLogic(address _platformLogic) external;
/// @notice Sets the address of the Position NFT contract, managing NFTs
/// that represent positions.
/// @param _positionNft The new Position NFT address.
function setPositionNft(address _positionNft) external;
/// @notice Sets the address of the GMX Reader contract used for reading
/// contract states and variables.
/// @param _reader The new reader contract address.
function setGmxReader(address _reader) external;
/// @notice Sets the address of the GMX Vault, where assets are managed and
/// stored.
/// @param _vault The new vault address.
function setGmxVault(address _vault) external;
/// @notice Sets the address of the GMX Router, managing routing of
/// transactions.
/// @param _router The new router address.
function setGmxRouter(address _router) external;
/// @notice Sets the address of the GMX Exchange Router for handling
/// exchange operations.
/// @param _exchangeRouter The new exchange router address.
function setGmxExchangeRouter(address _exchangeRouter) external;
/// @notice Sets whether a token is allowed for payments and other
/// transactions.
/// @param tokenFeePaymentAddress The token address to set the allowance
/// status.
/// @param allowed The allowance status, true if allowed.
function setAllowedToken(
IERC20 tokenFeePaymentAddress,
bool allowed
)
external;
/// @notice Sets the maximum gas limit for callbacks to prevent excessive
/// gas usage.
/// @param _maxCallbackgasLimit The new maximum callback gas limit.
function setMaxCallbackGasLimit(uint256 _maxCallbackgasLimit) external;
/// @notice Sets the address for the ETH/USD price aggregator.
/// @param _ethUsdAggregator The new ETH/USD aggregator address.
function setEthUsdAggregator(address _ethUsdAggregator) external;
/// @notice Sets the address for the Arbitrage Rewards Claimer.
/// @param _arbRewardsClaimer The new Arbitrage Rewards Claimer address.
function setArbRewardsClaimer(address _arbRewardsClaimer) external;
function setStPearToken(address _stPearToken) external;
function setFeeRebateManager(address _feeRebateManager) external;
/*//////////////////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Returns the address of the current administrator.
/// @return admin The administrator's address.
function admin() external view returns (address);
/// @notice Returns the current GMX referral code.
/// @return The GMX referral code.
function gmxReferralCode() external view returns (bytes32);
/// @notice Checks if a token is allowed for transactions.
/// @param token The token address to check.
/// @return true if the token is allowed, false otherwise.
function allowedTokens(IERC20 token) external view returns (bool);
/// @notice Checks if a token is allowed as collateral.
/// @param token The token address to check.
/// @return true if the token is allowed as collateral, false otherwise.
function allowedCollateralTokens(address token)
external
view
returns (bool);
/// @notice Returns the address of the GMX Exchange Router.
/// @return The address of the exchange router.
function getExchangeRouter() external view returns (address);
/// @notice Returns the address of the GMX Vault.
/// @return The address of the vault.
function getVault() external view returns (address);
/// @notice Returns the address of the GMX Router.
/// @return The address of the router.
function getRouter() external view returns (address);
/// @notice Returns the address of the GMX Reader.
/// @return The address of the reader.
function getReader() external view returns (address);
/// @notice Returns the address of the GMX Factory.
/// @return The address of the factory.
function getGmxFactory() external view returns (address);
/// @notice Returns the address of the Vertex Factory.
/// @return The address of the factory.
function getVertexFactory() external view returns (address);
/// @notice Returns the address of the GMX Callback Receiver.
/// @return The address of the callback receiver.
function getCallBackReceiver() external view returns (address);
/// @notice Returns the address of the GMX Adapter.
/// @return The address of the adapter.
function getGmxAdapter() external view returns (address);
/// @notice Returns the address of the Platform Logic.
/// @return The address of the platform logic.
function getPlatformLogic() external view returns (address);
/// @notice Returns the address of the Position NFT.
/// @return The address of the position NFT.
function getPositionNft() external view returns (address);
/// @notice Returns the maximum callback gas limit.
/// @return The maximum callback gas limit.
function getMaxCallBackLimit() external view returns (uint256);
/// @notice Returns the address of the data store.
/// @return The address of the data store.
function getDatastore() external view returns (address);
/// @notice Returns the address of the ETH/USD price aggregator.
/// @return The address of the ETH/USD price aggregator.
function getEthUsdAggregator() external view returns (address);
function getArbRewardsClaimer()
external
view
returns (address arbRewardsClaimer);
function getStPearToken() external view returns (address stPearToken);
function getFeeRebateManager() external view returns (address feeRebateManager);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed 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.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (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.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens 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.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @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].
*
* CAUTION: See Security Considerations above.
*/
function permit(
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.
*/
function nonces(address owner) external view returns (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-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
/// @title Interface for FeeRebateManager
/// @notice This contract is used to manage the fee rebates for the users
interface IFeeRebateManager {
struct TradeDetails {
uint256 monthlyVolume;
uint256 monthlyFee;
bool isClaimed;
}
struct RebateTier {
uint256 monthlyVolumeThreshold;
uint256 rebatePercentage;
}
struct DiscountTier {
uint256 stakedAmountThreshold;
uint256 discountPercentage;
}
function epochStartTime() external view returns (uint256);
function isFeeRebateEnabled() external view returns (bool);
function rebateTiers(uint256) external view returns (uint256, uint256);
function discountTiers(uint256) external view returns (uint256, uint256);
function userTradeDetails(
address,
uint256
)
external
view
returns (uint256, uint256, bool);
function setIsFeeRebateEnabled(bool _isFeeRebateEnabled) external;
function setRebateTier(
uint256 tier,
uint256 monthlyVolumeThreshold,
uint256 rebatePercentage
)
external;
function setDiscountTier(
uint256 tier,
uint256 stakedAmountThreshold,
uint256 discountPercentage
)
external;
function getCurrentMonthId() external view returns (uint256);
function calculateFeeDiscount(address _user)
external
view
returns (uint256);
function calculateFeeRebate(uint256 totalVolume)
external
view
returns (uint256);
function updateTradeDetails(
address _user,
uint256 _volume,
uint256 _fee
)
external;
function claimRebate(uint256 monthId) external;
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title IPlatformLogic Interface
/// @notice Interface for defining the core logic and rules for trading
/// operations.
interface IPlatformLogic {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
event BackendVerifierChanged(
address oldBackendVerifier, address newBackendVerifier
);
event ManagePositionFeeChanged(
uint256 oldManagePositionFee, uint256 newManagePositionFee
);
event PlatformFeeChanged(uint256 oldPlatformFee, uint256 newPlatformFee);
event MintFeeChanged(uint256 oldMintFee, uint256 newMintFee);
event RefereeDiscountChanged(
uint256 oldRefereeDiscount, uint256 newRefereeDiscount
);
event ReferrerFeeChanged(
uint256 oldReferrerFeeChanged, uint256 newReferrerFeeChanged
);
event PearTreasuryChanged(address oldTreasury, address newTreasury);
event PearStakingContractChanged(
address oldPearStakingContract, address newPearStakingContract
);
event TreasuryFeeSplitChanged(
uint256 oldTreasuryFee, uint256 newTreasuryFee
);
event ReferralCodeAdded(address indexed referrer, bytes32 code);
event ReferralCodeEdited(
address indexed referrer, bytes32 code, address admin
);
event Referred(
address indexed referrer,
address indexed referee,
address indexed adapter,
uint256 amount
);
event RefereeAdded(address indexed referee, bytes32 code);
event RefereeEdited(address indexed referee, bytes32 code, address admin);
event FactorySet(address factory, bool state);
event PendingTokenWithdrawal(address referrer, uint256 amount);
event PendingEthWithdrawal(address referrer, uint256 amount);
event TokenWithdrawal(address withdrawer, uint256 amount);
event EthWithdrawal(address withdrawer, uint256 amount);
event FeesPaid(
address indexed user,
uint256 indexed feeAmount,
uint256 indexed grossAmountAfterFee
);
event FeesPaidToStakingContract(
address indexed stakingContract, uint256 indexed feeAmount
);
event FeesPaidToPearTreasury(
address indexed pearTreasury, uint256 indexed feeAmount
);
event SetRefereeFeeAmount(
address indexed positionHolder,
address indexed adapterAddress,
uint256 indexed feeAmount,
bool isLong
);
event SetPendingReferrerFeeAmount(
address adapter, address referrer, uint256 amount
);
event ArbRewardsFeeSplitChanged(
uint256 oldArbRewardsFeeSplit, uint256 newArbRewardsFeeSplit
);
event PlatformLogic_AddedRewards(
address indexed user, uint256 indexed amount
);
/*//////////////////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////////////////*/
struct ReferralCode {
/// @notice address of the person wanting to create a referral code
address referrer;
/// @notice the bytes32 version of a referral code - converted by the
/// backend
bytes32 referralCode;
/// @notice the EIP-712 signature of all other fields in the
/// ReferralCode struct. For a referralCode to be valid, it must be
/// signed by the backendVerifier
bytes signature;
}
/*//////////////////////////////////////////////////////////////////////////
SETTERS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Sets the arb rewards is active or not.
function setGmxArbRewardActive(bool _isArbRewardActive) external;
/// @notice Sets the arb rewards is active or not.
function setVertexArbRewardActive(bool _isArbRewardActive) external;
/// @notice Sets the arb rewards is active or not.
function setSymmArbRewardActive(bool _isArbRewardActive) external;
/// @notice Sets a new backend verifier address.
/// @param _newBackendVerifier The new address to be used as the backend
/// verifier.
function setBackendVerifierAddress(address _newBackendVerifier) external;
/// @notice Sets the discount percentage for referees.
/// @param _refereeDiscount The new discount percentage for referees.
function setRefereeDiscount(uint256 _refereeDiscount) external;
/// @notice Sets the referral fee percentage.
/// @param _referrerFee The new referral fee percentage.
function setReferrerFee(uint256 _referrerFee) external;
/// @notice Sets the platform fee percentage.
/// @param _platformFee The new platform fee percentage.
function setPlatformFee(uint256 _platformFee) external;
/// @notice Sets the fee split percentage that goes to the treasury.
/// @param _treasuryFeeSplit The new treasury fee split percentage.
function setTreasuryFeeSplit(uint256 _treasuryFeeSplit) external;
/// @notice Sets the fee split percentage that goes to arb for platforms
/// rewards.
function setGmxArbRewardsFeeSplit(uint256 _arbRewardsFeeSplit) external;
/// @notice Sets the fee split percentage that goes to arb for platforms
/// rewards.
function setVertexArbRewardsFeeSplit(uint256 _arbRewardsFeeSplit)
external;
/// @notice Sets the fee split percentage that goes to arb for platforms
/// rewards.
function setSymmArbRewardsFeeSplit(uint256 _arbRewardsFeeSplit) external;
/// @notice Sets a new Pear Treasury address.
/// @param _newTreasury The new address for the Pear Treasury.
function setPearTreasury(address payable _newTreasury) external;
/// @notice Sets a new Pear Staking Contract address.
/// @param _newStakingContract The new address for the Pear Staking
/// Contract.
function setPearStakingContract(address payable _newStakingContract)
external;
/// @notice Adds or removes a factory address.
/// @param _factory The factory address to be added or removed.
/// @param _state The state to set for the factory address (true for add,
/// false for remove).
function setFactory(address _factory, bool _state) external;
/// @notice Sets the mint fee for a specific functionality in the platform.
/// @param _mintFee The new mint fee.
function setMintPositionFee(uint256 _mintFee) external;
/*//////////////////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Creates a new referral code.
/// @param _referralCode The referral code data to be created.
/// @return A boolean indicating success of the operation.
function createReferralCode(ReferralCode memory _referralCode)
external
returns (bool);
/// @notice Associates a referee with a referral code.
/// @param _referralCode The referral code to associate the referee with.
/// @param _referee The address of the referee being associated.
/// @return A boolean indicating success of the operation.
function addReferee(
bytes32 _referralCode,
address _referee
)
external
returns (bool);
/// @notice Associates a referee with a referral code.
/// @notice Can only be called by Gmx Factory
/// @param _referralCode The referral code to associate the referee with.
/// @param _referee The address of the referee being associated.
/// @return A boolean indicating success of the operation.
function addRefereeFromFactory(
bytes32 _referralCode,
address _referee
)
external
returns (bool);
/// @notice Edits the referral code of a referrer.
/// @param _referrer The address of the referrer whose code is being edited.
/// @param _referralCode The new referral code to be associated with the
/// referrer.
function editReferralCode(
address _referrer,
bytes32 _referralCode
)
external;
function getPlatformFeeOfOrder(
address referee,
uint256 grossAmount
)
external
view
returns (uint256);
/// @notice Applies platform fee logic for Ethereum Vertex.
function applyPlatformFeeEthVertex(
address _referee,
uint256 _feeAmountAfterDiscountAndWithdrawal,
uint256 _feeAmountAfterDiscount,
uint256 _referrerWithdrawal,
bool _isReferralProgramApplied
)
external
payable;
/// @notice Applies mint fee logic for ETH GMX.
function applyMintFeeEthGmx(address _referee) external payable;
/// @notice Applies platform fee logic for ETH GMX.
/// @param adapter The address of the adapter contract for order
/// @param _referee The address of the user being charged the fee.
/// @param _grossAmount The total transaction amount before fees.
/// @param _factory The address of the factory implementing the logic.
/// @return feeAmount The amount of fee to be applied.
/// @return referrerWithdrawal The amount of fee for referrer
function applyPlatformFeeETHGmx(
address adapter,
address _referee,
uint256 _grossAmount,
address _factory
)
external
returns (uint256 feeAmount, uint256 referrerWithdrawal);
/// @notice Checks the amount of token fees pending withdrawal by a
/// referrer.
/// @param _referrer The address of the referrer.
/// @return The amount of fees pending withdrawal.
function checkPendingTokenWithdrawals(
address _referrer,
IERC20 _token
)
external
view
returns (uint256);
/// @notice Allows a user to withdraw their accumulated token fees.
/// @param _token The ERC20 token address for which the fees are withdrawn.
function withdrawTokenFees(IERC20 _token) external;
/// @notice Allows a user to withdraw their accumulated eth fees from
/// referral logic.
function withdrawEthFees() external;
/// @notice Calculates fees based on the provided amount and basis points.
/// @param _amount The amount on which the fee is to be calculated.
/// @param _bps Basis points used to calculate the fee.
/// @return The calculated fee amount.
function calculateFees(
uint256 _amount,
uint256 _bps
)
external
pure
returns (uint256);
/// @notice Edits the referral code of referred users.
/// @param _referrer The address of the referrer whose referred users' code
/// is being edited.
/// @param _referralCode The new referral code to be associated with the
/// referred users.
function editReferredUsers(
address _referrer,
bytes32 _referralCode
)
external;
/// @notice Splits fees between stakers and the treasure.
/// @param _referee The address of the user involved in the transaction.
/// @param _adapterAddress The address of the adapter involved in the
/// transaction.
/// @param _isLong isLong
/// @param _amount The amount of fees to be split.
function splitBetweenStakersAndTreasuryEth(
address _referee,
address _adapterAddress,
bool _isLong,
uint256 _amount
)
external;
/// @notice Adds token fees for withdrawal by a referrer.
/// @param _referrer The address of the referrer.
/// @param _amount The amount of fees to be added for withdrawal.
/// @param _token The ERC20 token address for which the fees are added.
function addTokenFeesForWithdrawal(
address _referrer,
uint256 _amount,
IERC20 _token
)
external;
/// @notice function to calculate the platform fee for a given user on
/// Vertex's side
function calculatePlatformFeeEthVertex(
address _referee,
uint256 _grossAmount
)
external
returns (
uint256 _feeAmountAfterDiscountAndWithdrawal,
uint256 _feeAmountAfterDiscount,
uint256 _referrerWithdrawal,
bool _isReferralProgramApplied
);
/// @notice Sets the fee amount for a referee.
/// @param _referee The address of the referee.
/// @param _adapterAddress The address of the adapter involved in the
/// transaction.
/// @param _isLong isLong
/// @param _feeAmount The fee amount to be set.
function setRefereeFeeAmount(
address _referee,
address _adapterAddress,
bool _isLong,
uint256 _feeAmount
)
external;
/// @notice Handles token amount when a position fails.
/// @param _referee The address of the user involved in the failed
/// transaction.
/// @param _adapterAddress The address of the adapter involved in the
/// transaction.
/// @param _isLong isLong
/// @param _feeAmount The fee amount involved in the failed transaction.
function handleTokenAmountWhenPositionHasFailed(
address _referee,
address _adapterAddress,
bool _isLong,
uint256 _feeAmount
)
external;
/*//////////////////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice View function to get the address used to sign and validate
/// referral codes.
function backendVerifier() external view returns (address);
/// @notice View function to get the platform fee as a percentage of the
/// margin size.
function platformFee() external view returns (uint256);
/// @notice View function to get the mint fee in USDC used in a specific
/// function.
function mintFeeInUsdc() external view returns (uint256);
/// @notice View function to get the percentage of the platform fee
/// allocated to referrers.
function referrerFee() external view returns (uint256);
/// @notice View function to get the discount percentage for referees off
/// the platform fee.
function refereeDiscount() external view returns (uint256);
/// @notice View function to get the portion of fees sent to the Pear
/// Treasury.
function treasuryFeeSplit() external view returns (uint256);
/// @notice View function to get the arb rewards is active or not.
function isGmxArbRewardActive() external view returns (bool);
/// @notice View function to get the arb rewards is active or not.
function isVertexArbRewardActive() external view returns (bool);
/// @notice View function to get the arb rewards is active or not.
function isSymmArbRewardActive() external view returns (bool);
/// @notice View function to get the % of ArbRewardsFeeSplit - e.g 7000 -
/// 70%
function gmxArbRewardsFeeSplit() external view returns (uint256);
/// @notice View function to get the % of ArbRewardsFeeSplit - e.g 7000 -
/// 70%
function vertexArbRewardsFeeSplit() external view returns (uint256);
/// @notice View function to get the % of ArbRewardsFeeSplit - e.g 7000 -
/// 70%
function symmArbRewardsFeeSplit() external view returns (uint256);
/// @notice View function to get the address of the Pear Treasury.
function PearTreasury() external view returns (address payable);
/// @notice View function to get the address of the Pear Staking Contract.
function PearStakingContract() external view returns (address payable);
/// @notice Checks if the given address is a registered factory.
/// @param _factory The address to check.
/// @return A boolean indicating whether the address is a registered
/// factory.
function checkFactory(address _factory) external view returns (bool);
/// @notice Retrieves the current platform fee.
/// @return The platform fee as a percentage.
function viewPlatformFee() external view returns (uint256);
/// @notice Retrieves the current referee discount.
/// @return The discount percentage for referees.
function viewRefereeDiscount() external view returns (uint256);
/// @notice Retrieves the owner of a specific referral code.
/// @param _referralCode The referral code to check.
/// @return codeOwner The address of the owner of the referral code.
function viewReferralCodeOwner(bytes32 _referralCode)
external
view
returns (address codeOwner);
/// @notice Retrieves the referral code associated with a referrer.
/// @param _referrer The address of the referrer.
/// @return code The referral code associated with the referrer.
function viewReferrersCode(address _referrer)
external
view
returns (bytes32 code);
/// @notice Retrieves the referral code used by a referred user.
/// @param _referredUser The address of the referred user.
/// @return code The referral code used by the referred user.
function viewReferredUser(address _referredUser)
external
view
returns (bytes32 code);
/// @notice Retrieves the fee amount set for a referee.
/// @param _referee The address of the referee.
/// @param _adapterAddress The address of the adapter involved in the
/// transaction.
/// @param _isLong isLong
/// @return The fee amount set for the referee.
function viewRefereeFeeAmount(
address _referee,
address _adapterAddress,
bool _isLong
)
external
view
returns (uint256);
/// @notice Checks who referred a given user.
/// @param _referredUser The address of the user being checked.
/// @return referrer The address of the referrer.
function checkReferredUser(address _referredUser)
external
view
returns (address referrer);
/// @notice Retrieves the current chain ID.
/// @return The chain ID of the current blockchain.
function getChainID() external view returns (uint256);
/// @notice Retrieves the current referrer fee.
/// @return The referrer fee as a percentage.
function viewReferrerFee() external view returns (uint256);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title Vertex Factory Interface
/// @notice Interface for managing platform fees, callbacks, and token
/// withdrawals in a trading environment.
interface IVertexFactory {
/*//////////////////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////////////////*/
event PlatformFeeCallbackApplied(
address indexed user,
uint256 orderId,
uint256 feeAmountAfterDiscountAndWithdrawal,
uint256 indexed feeAmountAfterDiscount,
uint256 referrerWithdrawal,
bool indexed isReferralProgramApplied,
uint256 grossAmount
);
event TokenWithdrawnFromVertexFactory(
IERC20 indexed token,
uint256 indexed amount,
address indexed withdrawAddress
);
event EthWithdrawnFromVertexFactory(
uint256 indexed amount, address indexed withdrawAddress
);
event CallbackWalletChanged(
address indexed oldCallbackWallet, address indexed newCallbackWallet
);
event BaseGasFeeChanged(
uint256 indexed oldBaseGasFee, uint256 indexed newBaseGasFee
);
event VertexCallback_Unsuccessful(
address indexed user,
uint256 orderId,
uint256 indexed feeAmountAfterDiscountAndWithdrawal,
uint256 grossAmount
);
event VertexCallback_Successful(
address indexed user,
uint256 orderId,
uint256 indexed feeAmountAfterDiscountAndWithdrawal,
uint256 grossAmount
);
/*//////////////////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @notice Function to view the base gas fee
function baseGasFee() external view returns (uint256);
/// @notice Function to view the callback wallet address
function callbackWallet() external view returns (address payable);
/**
* @notice Calculates and applies the platform fees based on the given gross
* amount and manages referral interactions.
* @dev This function handles fee calculations, referral program
* applications, and ensures that the required ETH
* is present for the transaction including the base gas fee.
* @param _grossAmount The total gross amount from which fees will be
* calculated.
* @param referralCode The referral code used to credit the referrer, if
* applicable.
* @return orderId The id of the order
* @return _feeAmount The final fee amount after discounts and withdrawals
* have been applied.
* @return _feeAmountAfterDiscount The fee amount after applying discounts
* but before any withdrawals.
* @return _referrerWithdrawal The amount withdrawn by the referrer, if any,
* as part of the referral program.
* @return _isReferralProgramApplied A boolean indicating whether the
* referral program was applied.
*
* Emits a {PlatformFeeCallbackApplied} event upon successful calculation
* and application of fees.
*/
function applyPlatformFeeEth(
uint256 _grossAmount,
bytes32 referralCode
)
external
payable
returns (
uint256 orderId,
uint256 _feeAmount, // = _feeAmountAfterDiscountAndWithdrawal
uint256 _feeAmountAfterDiscount,
uint256 _referrerWithdrawal,
bool _isReferralProgramApplied
);
/**
*
* @param _referee the address of the user that is opening the position
* @param _isSuccess the success of the callback
* @param orderId the id or the order
* @param _feeAmountAfterDiscountAndWithdrawal the fee amount after discount
* and withdrawal
* @param _feeAmountAfterDiscount the fee amount after discount
* @param _referrerWithdrawal the referrer withdrawal
* @param _isReferralProgramApplied is the referral program applied
*/
/// @notice used to be called by Backend for callback execution
function vertexCallback(
address payable _referee,
bool _isSuccess,
uint256 orderId,
uint256 _grossAmount,
uint256 _feeAmountAfterDiscountAndWithdrawal,
uint256 _feeAmountAfterDiscount,
uint256 _referrerWithdrawal,
bool _isReferralProgramApplied
)
external
payable;
/// @notice Function to set the base gas fee
function setBaseGasFee(uint256 _baseGasFee) external;
/// @notice Function to set the callback wallet address
function setCallbackWallet(address payable _callbackWallet) external;
/// @notice Function to withdraw token fees from the vertex factory to
/// prevent stuck funds
function withdrawTokenFees(
IERC20 _token,
uint256 _amount,
address _withdrawAddress
)
external;
/// @notice Function to withdraw eth fees from the vertex factory to
/// prevent stuck funds
function withdrawEth(uint256 _amount, address _withdrawAddress) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../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.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @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, bytes memory 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.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IComptroller } from "../interfaces/IComptroller.sol";
import { SafeERC20 } from
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IPlatformLogic } from "../interfaces/IPlatformLogic.sol";
import { IVertexFactory } from "../interfaces/IVertexFactory.sol";
import { ComptrollerManager } from "./../helpers/ComptrollerManager.sol";
import { IFeeRebateManager } from "../interfaces/IFeeRebateManager.sol";
import { ReentrancyGuard } from
"@openzeppelin-upgradeable/lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
import { Errors } from "./../libraries/Errors.sol";
/**
* @title Vertex Factory
* @dev Manages transactional logic related to platform operations, handling fee
* calculations, referrals, and
* callbacks within a DeFi environment. It orchestrates interactions between
* different ecosystem components
* to ensure seamless operation, governance, and security. It integrates with
* Comptroller for governance and
* Platform Logic for operational control.
* @notice The contract handles critical functions such as managing callback
* mechanisms for transaction fees
* and referral systems, setting base gas fees, and authorizing withdrawal
* operations. It ensures only
* designated wallet addresses can initiate specific high-level operations,
* maintaining a robust security posture.
*
* Functions include:
* - applyPlatformFeeEth: Calculates and applies platform fees, manages
* referrals, and handles callback payments.
* - vertexCallback: Handles the logic for successful or unsuccessful callbacks,
* adjusting platform fees accordingly.
* - setBaseGasFee: Admin-only function to update the base gas fee for
* transactions.
* - setCallbackWallet: Restricts changes to the callback wallet to admin users.
* - withdrawTokenFees: Allows admin withdrawal of token fees collected by the
* factory.
* - withdrawEth: Enables admin to withdraw ETH collected as fees.
*
* Modifiers used:
* - onlyCallbackWallet: Ensures only the designated callback wallet can call
* certain functions.
* - onlyAdmin: Restricts access to admin-only functions, ensuring that only
* authorized personnel can perform critical operations.
* - onlyAllowedTokens: Checks if the token involved in operations is allowed
* under the current governance policies.
*/
contract VertexFactory is
IVertexFactory,
ComptrollerManager,
ReentrancyGuard
{
/// @notice Using SafeErc20 as a standard
using SafeERC20 for IERC20;
/// @notice The base gas fee for a transaction
uint256 public override baseGasFee;
/// @notice The address of the CallbackWallet
address payable public override callbackWallet;
mapping(address user => uint256 orderId) public ordersId;
modifier onlyCallbackWallet() {
if (msg.sender != callbackWallet) {
revert Errors.VertexFactory_NotCallbackWallet();
}
_;
}
/// @notice Modifier to restrict access to only the contract owner.
modifier onlyAdmin() {
if (comptroller.admin() != msg.sender) {
revert Errors.VertexFactory_NotComptrollerAdmin();
}
_;
}
/// @notice Modifier to restrict access to only the allowed tokens set in
/// Comptroller
modifier onlyAllowedTokens(IERC20 _token) {
if (comptroller.allowedTokens(_token) != true) {
revert Errors.VertexFactory_TokenNotAllowed();
}
_;
}
/**
* @param _comptroller Address of the Comptroller instance containing the
* contract's admin
* @param _callbackWallet Address of the wallet that will receive the gas
* @param _baseGasFee The base gas fee for a transaction
*/
constructor(
IComptroller _comptroller,
address payable _callbackWallet,
uint256 _baseGasFee
) {
comptroller = _comptroller;
callbackWallet = _callbackWallet;
baseGasFee = _baseGasFee;
}
/// @inheritdoc IVertexFactory
function applyPlatformFeeEth(
uint256 _grossAmount,
bytes32 referralCode
)
public
payable
nonReentrant
returns (
uint256 orderId,
uint256 _feeAmount, // = _feeAmountAfterDiscountAndWithdrawal
uint256 _feeAmountAfterDiscount,
uint256 _referrerWithdrawal,
bool _isReferralProgramApplied
)
{
ordersId[msg.sender] += 1;
orderId = ordersId[msg.sender];
address platformLogic = comptroller.getPlatformLogic();
if (referralCode != 0) {
IPlatformLogic(platformLogic).addRefereeFromFactory(
referralCode, msg.sender
);
}
// calculating the fee Amounts needed for later use in PlatformLogic
(
_feeAmount, // = _feeAmountAfterDiscountAndWithdrawal
_feeAmountAfterDiscount,
_referrerWithdrawal,
_isReferralProgramApplied
) = IPlatformLogic(platformLogic).calculatePlatformFeeEthVertex(
msg.sender, _grossAmount
);
{
uint256 expectedFeeValue = _feeAmountAfterDiscount + baseGasFee;
// checks if the msg.value(gas fee and amount sent) is equal to
// the one, _feeAmountAfterDiscount is returned as original
// feeAmount
// without doscount in the function, so we can always use this param
// here
// we are allowing the expectedFeeValue to be greater than the
// msg.value so if gas spikes arise the frontend can send more gas
if (msg.value < expectedFeeValue) {
revert Errors.VertexFactory_WrongValueSent(
msg.value, expectedFeeValue
);
}
}
// sending the gas fee funds to the callbackWallet
// previously - we've sent the baseGasFee to the callbackWallet
// now we are sending all of the remaining gas fee to the callbackWallet
// by substracing the _feeAmountAfterDiscount from the msg.value
(bool _success,) = callbackWallet.call{
value: (msg.value - _feeAmountAfterDiscount)
}("");
if (!_success) {
revert
Errors
.VertexFactoryCallback_FailedToSendFundsToCallbackWallet();
}
emit PlatformFeeCallbackApplied(
msg.sender,
orderId,
_feeAmount,
_feeAmountAfterDiscount,
_referrerWithdrawal,
_isReferralProgramApplied,
_grossAmount
);
return (
orderId,
_feeAmount,
_feeAmountAfterDiscount,
_referrerWithdrawal,
_isReferralProgramApplied
);
}
/// @inheritdoc IVertexFactory
function vertexCallback(
address payable _referee,
bool _isSuccess,
uint256 orderId,
uint256 _grossAmount,
uint256 _feeAmountAfterDiscountAndWithdrawal,
uint256 _feeAmountAfterDiscount,
uint256 _referrerWithdrawal,
bool _isReferralProgramApplied
)
external
payable
override
onlyCallbackWallet
nonReentrant
{
address platformLogic = comptroller.getPlatformLogic();
if (_isSuccess) {
// When the operation is successful, this applies the calculated
// platform fees
// to the referee's account, supporting referral and reward
// distribution mechanisms.
// It ensures that the correct fee amounts are charged based on
// previously established
// discounts and the referral program status.
IPlatformLogic(platformLogic).applyPlatformFeeEthVertex{
value: msg.value
}(
_referee,
_feeAmountAfterDiscountAndWithdrawal,
_feeAmountAfterDiscount,
_referrerWithdrawal,
_isReferralProgramApplied
);
// Save trade details for fee rebate on monthly basis
IFeeRebateManager(comptroller.getFeeRebateManager())
.updateTradeDetails(_referee, _grossAmount, _feeAmountAfterDiscount);
// This event is emitted if the callback operation is successful
emit VertexCallback_Successful(
_referee, orderId, _feeAmountAfterDiscount, _grossAmount
);
} else {
// If the operation fails, this block attempts to refund the
// calculated fee
// amount back to the user's (_referee's) address.
// This ensures that users are not financially penalized for failed
// operations
// within the platform, maintaining fairness and trust.
(bool _success,) =
_referee.call{ value: _feeAmountAfterDiscount }("");
if (!_success) {
revert Errors.VertexFactoryCallback_FailedToSendFundsToUser();
}
// This event is emitted if the callback operation is unsuccessful,
// providing an audit trail for failed refunds.
emit VertexCallback_Unsuccessful(
_referee, orderId, _feeAmountAfterDiscount, _grossAmount
);
}
}
/// @inheritdoc IVertexFactory
function setBaseGasFee(uint256 _baseGasFee)
external
override
onlyCallbackWallet
{
emit BaseGasFeeChanged(baseGasFee, _baseGasFee);
baseGasFee = _baseGasFee;
}
/// @inheritdoc IVertexFactory
function setCallbackWallet(address payable _callbackWallet)
external
override
onlyAdmin
{
emit CallbackWalletChanged(callbackWallet, _callbackWallet);
callbackWallet = _callbackWallet;
}
/// @inheritdoc IVertexFactory
function withdrawTokenFees(
IERC20 _token,
uint256 _amount,
address _withdrawAddress
)
external
override
onlyAdmin
{
_token.safeTransfer(_withdrawAddress, _amount);
emit TokenWithdrawnFromVertexFactory(_token, _amount, _withdrawAddress);
}
/// @inheritdoc IVertexFactory
function withdrawEth(
uint256 _amount,
address _withdrawAddress
)
external
override
onlyAdmin
{
(bool _success,) = _withdrawAddress.call{ value: _amount }("");
if (!_success) {
revert Errors.VertexFactoryCallback_FailedToSendFundsToUser();
}
emit EthWithdrawnFromVertexFactory(_amount, _withdrawAddress);
}
}
{
"compilationTarget": {
"src/factory/VertexFactory.sol": "VertexFactory"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 2000
},
"remappings": [
":@openzeppelin-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":@openzeppelin/=lib/openzeppelin-contracts/",
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@solady/=lib/solady/src/",
":@soladytokens/=lib/solady/src/tokens/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":solady/=lib/solady/"
]
}
[{"inputs":[{"internalType":"contract IComptroller","name":"_comptroller","type":"address"},{"internalType":"address payable","name":"_callbackWallet","type":"address"},{"internalType":"uint256","name":"_baseGasFee","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"ComptrollerManager_EntityCannotBe0Address","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"NotComptrollerAdmin","type":"error"},{"inputs":[],"name":"NotProposedComptroller","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"VertexFactoryCallback_FailedToSendFundsToCallbackWallet","type":"error"},{"inputs":[],"name":"VertexFactoryCallback_FailedToSendFundsToUser","type":"error"},{"inputs":[],"name":"VertexFactory_NotCallbackWallet","type":"error"},{"inputs":[],"name":"VertexFactory_NotComptrollerAdmin","type":"error"},{"inputs":[{"internalType":"uint256","name":"valueSent","type":"uint256"},{"internalType":"uint256","name":"expectedFeeAmount","type":"uint256"}],"name":"VertexFactory_WrongValueSent","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldBaseGasFee","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newBaseGasFee","type":"uint256"}],"name":"BaseGasFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldCallbackWallet","type":"address"},{"indexed":true,"internalType":"address","name":"newCallbackWallet","type":"address"}],"name":"CallbackWalletChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldComptroller","type":"address"},{"indexed":false,"internalType":"address","name":"newComptroller","type":"address"}],"name":"ComptrollerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"withdrawAddress","type":"address"}],"name":"EthWithdrawnFromVertexFactory","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmountAfterDiscountAndWithdrawal","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"feeAmountAfterDiscount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"referrerWithdrawal","type":"uint256"},{"indexed":true,"internalType":"bool","name":"isReferralProgramApplied","type":"bool"},{"indexed":false,"internalType":"uint256","name":"grossAmount","type":"uint256"}],"name":"PlatformFeeCallbackApplied","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"token","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"address","name":"withdrawAddress","type":"address"}],"name":"TokenWithdrawnFromVertexFactory","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"feeAmountAfterDiscountAndWithdrawal","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"grossAmount","type":"uint256"}],"name":"VertexCallback_Successful","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"feeAmountAfterDiscountAndWithdrawal","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"grossAmount","type":"uint256"}],"name":"VertexCallback_Unsuccessful","type":"event"},{"inputs":[],"name":"acceptComptroller","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_grossAmount","type":"uint256"},{"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"applyPlatformFeeEth","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"_feeAmount","type":"uint256"},{"internalType":"uint256","name":"_feeAmountAfterDiscount","type":"uint256"},{"internalType":"uint256","name":"_referrerWithdrawal","type":"uint256"},{"internalType":"bool","name":"_isReferralProgramApplied","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"baseGasFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"callbackWallet","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"comptroller","outputs":[{"internalType":"contract IComptroller","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"ordersId","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proposedComptroller","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_baseGasFee","type":"uint256"}],"name":"setBaseGasFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_callbackWallet","type":"address"}],"name":"setCallbackWallet","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_comptroller","type":"address"}],"name":"setComptroller","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_referee","type":"address"},{"internalType":"bool","name":"_isSuccess","type":"bool"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"_grossAmount","type":"uint256"},{"internalType":"uint256","name":"_feeAmountAfterDiscountAndWithdrawal","type":"uint256"},{"internalType":"uint256","name":"_feeAmountAfterDiscount","type":"uint256"},{"internalType":"uint256","name":"_referrerWithdrawal","type":"uint256"},{"internalType":"bool","name":"_isReferralProgramApplied","type":"bool"}],"name":"vertexCallback","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_withdrawAddress","type":"address"}],"name":"withdrawEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_withdrawAddress","type":"address"}],"name":"withdrawTokenFees","outputs":[],"stateMutability":"nonpayable","type":"function"}]