文件 1 的 30:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 30:AccessControlEnumerable.sol
pragma solidity ^0.8.0;
import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
return _roleMembers[role].at(index);
}
function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
return _roleMembers[role].length();
}
function _grantRole(bytes32 role, address account) internal virtual override {
super._grantRole(role, account);
_roleMembers[role].add(account);
}
function _revokeRole(bytes32 role, address account) internal virtual override {
super._revokeRole(role, account);
_roleMembers[role].remove(account);
}
}
文件 3 的 30:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function sendValue(address payable 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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 4 的 30:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 5 的 30:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 6 的 30:EnumerableSet.sol
pragma solidity ^0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping(bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
set._values[toDeleteIndex] = lastValue;
set._indexes[lastValue] = valueIndex;
}
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
文件 7 的 30:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 8 的 30:IAccessControlEnumerable.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
interface IAccessControlEnumerable is IAccessControl {
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}
文件 9 的 30:IDepositHandler.sol
pragma solidity 0.8.4;
interface IDepositHandler {
struct FungibleTokenDeposit {
address tokenAddress;
uint256 amount;
bool isLP;
}
struct NonFungibleTokenDeposit {
address tokenAddress;
uint256 tokenId;
}
struct MultiTokenDeposit {
address tokenAddress;
uint256 tokenId;
uint256 amount;
}
struct V3LPData {
address tokenAddress;
address token0;
address token1;
uint128 liquidityToRemove;
uint24 fee;
}
}
文件 10 的 30:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 11 的 30:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 12 的 30:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 13 的 30:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 14 的 30:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 15 的 30:IERC721Enumerable.sol
pragma solidity ^0.8.0;
import "../IERC721.sol";
interface IERC721Enumerable is IERC721 {
function totalSupply() external view returns (uint256);
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
function tokenByIndex(uint256 index) external view returns (uint256);
}
文件 16 的 30:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 17 的 30:ILPTokenProcessorV2.sol
pragma solidity 0.8.4;
interface ILPTokenProcessorV2 {
struct TokenSwapInfo {
address tokenAddress;
address routerFactory;
bool isV2;
address referrer;
address vault;
uint256 amount;
uint24 v3PoolFee;
}
function addTokenForSwapping(TokenSwapInfo memory params) external;
function getRouter(address lpTokenAddress) external view returns (address);
function getV3Position(address tokenAddress, uint256 tokenId)
external
view
returns (
address,
address,
uint128,
uint24
);
function isV2LiquidityPoolToken(address tokenAddress) external view returns (bool);
function isV3LiquidityPoolToken(address tokenAddress, uint256 tokenId) external view returns (bool);
function swapTokens(
address sourceToken,
uint256 sourceAmount,
address destinationToken,
address receiver,
address routerAddress,
uint24[] memory poolFees
) external returns (bool);
}
文件 18 的 30:INonfungiblePositionManager.sol
pragma solidity 0.8.4;
pragma abicoder v2;
import { IERC721Enumerable } from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
interface INonfungiblePositionManager is IERC721Enumerable {
function positions(uint256 tokenId)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
uint24 fee,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
struct MintParams {
address token0;
address token1;
uint24 fee;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
}
function mint(MintParams calldata params)
external
payable
returns (
uint256 tokenId,
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
function decreaseLiquidity(DecreaseLiquidityParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
function burn(uint256 tokenId) external payable;
function factory() external view returns (address);
}
文件 19 的 30:IPaymentModule.sol
pragma solidity 0.8.4;
import { IDepositHandler } from "./IDepositHandler.sol";
interface IPaymentModule is IDepositHandler {
struct PaymentHolder {
address tokenAddress;
uint256 amount;
uint256 payment;
}
struct ProcessPaymentParams {
address vault;
address user;
address referrer;
FungibleTokenDeposit[] fungibleTokenDeposits;
NonFungibleTokenDeposit[] nonFungibleTokenDeposits;
MultiTokenDeposit[] multiTokenDeposits;
bool isVesting;
}
function processPayment(ProcessPaymentParams memory params) external payable;
}
文件 20 的 30:IPriceOracleManager.sol
pragma solidity 0.8.4;
interface IPriceOracleManager {
function fetchPriceInUSD(address sourceToken) external;
function getPriceInUSD(address token, uint256 expectedDecimals) external view returns (uint256 price);
}
文件 21 的 30:IPricingModule.sol
pragma solidity 0.8.4;
import { IDepositHandler } from "../interfaces/IDepositHandler.sol";
interface IPricingModule is IDepositHandler {
struct PriceInfo {
address[] v2LpTokens;
uint256[] v2LpAmounts;
V3LPData[] v3LpTokens;
uint256 usdtAmount;
}
function getPrice(
address user,
FungibleTokenDeposit[] memory fungibleTokenDeposits,
NonFungibleTokenDeposit[] memory nonFungibleTokenDeposits,
MultiTokenDeposit[] memory multiTokenDeposits,
bool isVested
) external view returns (PriceInfo memory);
function priceDecimals() external view returns (uint8);
}
文件 22 的 30:ISwapRouterV3.sol
pragma solidity 0.8.4;
interface ISwapRouterV3 {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 amountIn;
uint256 amountOutMinimum;
}
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
function WETH9() external pure returns (address);
function factory() external pure returns (address);
}
文件 23 的 30:IUniswapPair.sol
pragma solidity 0.8.4;
interface IUniswapPair {
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
}
文件 24 的 30:IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
文件 25 的 30:IUniswapV2Router01.sol
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
文件 26 的 30:IUniswapV2Router02.sol
pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
文件 27 的 30:PaymentModuleV1.sol
pragma solidity 0.8.4;
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import { IUniswapV2Pair } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
import { IUniswapV2Router02 } from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import { IDepositHandler } from "../interfaces/IDepositHandler.sol";
import { ILPTokenProcessorV2 } from "../interfaces/ILPTokenProcessorV2.sol";
import { IPaymentModule } from "../interfaces/IPaymentModule.sol";
import { IPricingModule } from "../interfaces/IPricingModule.sol";
import { INonfungiblePositionManager } from "../../common/interfaces/INonfungiblePositionManager.sol";
import { IPriceOracleManager } from "../../common/interfaces/IPriceOracleManager.sol";
import { ISwapRouterV3 } from "../../common/interfaces/ISwapRouterV3.sol";
import { IUniswapPair } from "../../common/interfaces/IUniswapPair.sol";
contract PaymentModuleV1 is IDepositHandler, IPaymentModule, AccessControlEnumerable, IERC721Receiver {
using SafeERC20 for IERC20Metadata;
address public constant burnAddress = 0x000000000000000000000000000000000000dEaD;
bytes32 public constant PAYMENT_ADMIN_ROLE = keccak256("PAYMENT_ADMIN_ROLE");
address public FLOKI;
IERC20Metadata public USDT;
ILPTokenProcessorV2 public lpTokenProcessor;
IPricingModule public pricingModule;
IPriceOracleManager public priceOracle;
address public mainRouter;
bool public isV2Router;
address public nativeWrappedToken;
uint24 public v3PoolFeeForUsdNative = 3000;
uint24 public v3PoolFeeForFlokiNative = 3000;
address public treasury;
bool public convertNativeFeeToUsd = true;
uint256 public constant BASIS_POINTS = 10000;
uint256 public constant referrerBasisPoints = 2500;
uint256 public constant burnBasisPoints = 2500;
uint256 public feeCollectedLastBlock;
uint256 public flokiBurnedLastBlock;
uint256 public referrerShareLastBlock;
event LPTokenProcessorUpdated(address indexed oldProcessor, address indexed newProcessor);
event PriceOracleManagerUpdated(address indexed oldOracle, address indexed newOracle);
event PricingModuleUpdated(address indexed oldModule, address indexed newModule);
event TreasuryAddressUpdated(address indexed oldTreasury, address indexed newTreasury);
event FeeCollected(uint256 indexed previousBlock, address indexed vault, uint256 usdAmount);
event ReferrerSharePaid(uint256 indexed previousBlock, address indexed vault, address referrer, uint256 usdAmount);
event FlokiBurned(uint256 indexed previousBlock, address indexed vault, uint256 usdAmount, uint256 flokiAmount);
event V3PoolFeeForUsdUpdated(uint24 indexed oldFee, uint24 indexed newFee);
event V3PoolFeeForFlokiUpdated(uint24 indexed oldFee, uint24 indexed newFee);
event RouterUpdated(address indexed oldRouter, address indexed newRouter, bool isV3Router);
event UsdTokenUpdated(address indexed oldUsd, address indexed newUsd);
event SlippageUpdated(uint256 indexed oldSlippage, uint256 indexed newSlippage);
constructor(
address flokiAddress,
address lpTokenProcessorAddress,
address pricingModuleAddress,
address treasuryAddress,
address routerAddress,
bool v2Router,
address priceOracleAddress,
address usdAddress
) {
require(pricingModuleAddress != address(0), "PaymentModuleV1::constructor::ZERO: Pricing module cannot be zero address.");
require(routerAddress != address(0), "PaymentModuleV1::constructor::ZERO: Router cannot be zero address.");
FLOKI = flokiAddress;
pricingModule = IPricingModule(pricingModuleAddress);
lpTokenProcessor = ILPTokenProcessorV2(lpTokenProcessorAddress);
priceOracle = IPriceOracleManager(priceOracleAddress);
mainRouter = routerAddress;
isV2Router = v2Router;
treasury = treasuryAddress;
USDT = IERC20Metadata(usdAddress);
nativeWrappedToken = _getNativeWrappedToken();
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
}
function routerForFloki() external view returns (address) {
return mainRouter;
}
function processPayment(ProcessPaymentParams memory params) external payable override onlyRole(PAYMENT_ADMIN_ROLE) {
IPricingModule.PriceInfo memory price = pricingModule.getPrice(
params.user,
params.fungibleTokenDeposits,
params.nonFungibleTokenDeposits,
params.multiTokenDeposits,
params.isVesting
);
_processErc20(params, price);
_processNfts(params, price);
_processMultiToken(params);
uint256 weiToBeRefunded = 0;
if (convertNativeFeeToUsd || msg.value == 0) {
weiToBeRefunded = _processFee(price.usdtAmount, params.user, params.referrer, params.vault);
} else {
weiToBeRefunded = _processNativeFees(price.usdtAmount, params.referrer, params.vault);
}
(bool success, ) = payable(params.user).call{ value: weiToBeRefunded }("");
require(success, "Failed to refund leftover ETH");
}
function _getNativeWrappedToken() private view returns (address) {
if (isV2Router) {
return IUniswapV2Router02(mainRouter).WETH();
} else {
return ISwapRouterV3(mainRouter).WETH9();
}
}
function _processErc20(ProcessPaymentParams memory params, IPricingModule.PriceInfo memory price) private {
for (uint256 i = 0; i < params.fungibleTokenDeposits.length; i++) {
uint256 initialBalance = IERC20Metadata(params.fungibleTokenDeposits[i].tokenAddress).balanceOf(address(this));
IERC20Metadata(params.fungibleTokenDeposits[i].tokenAddress).safeTransferFrom(params.user, address(this), params.fungibleTokenDeposits[i].amount);
uint256 receivedAmount = IERC20Metadata(params.fungibleTokenDeposits[i].tokenAddress).balanceOf(address(this)) - initialBalance;
IERC20Metadata(params.fungibleTokenDeposits[i].tokenAddress).safeTransfer(params.vault, receivedAmount - price.v2LpAmounts[i]);
if (params.fungibleTokenDeposits[i].tokenAddress == price.v2LpTokens[i]) {
IERC20Metadata(params.fungibleTokenDeposits[i].tokenAddress).safeApprove(address(lpTokenProcessor), price.v2LpAmounts[i]);
lpTokenProcessor.addTokenForSwapping(
ILPTokenProcessorV2.TokenSwapInfo({
tokenAddress: params.fungibleTokenDeposits[i].tokenAddress,
routerFactory: _factory(params.fungibleTokenDeposits[i].tokenAddress),
isV2: true,
referrer: params.referrer,
vault: params.vault,
amount: price.v2LpAmounts[i],
v3PoolFee: 0
})
);
}
}
}
function _processNfts(ProcessPaymentParams memory params, IPricingModule.PriceInfo memory price) private {
for (uint256 i = 0; i < params.nonFungibleTokenDeposits.length; i++) {
IERC721(params.nonFungibleTokenDeposits[i].tokenAddress).safeTransferFrom(params.user, address(this), params.nonFungibleTokenDeposits[i].tokenId);
if (params.nonFungibleTokenDeposits[i].tokenAddress == price.v3LpTokens[i].tokenAddress) {
require(price.v3LpTokens[i].liquidityToRemove > 0, "PaymentModuleV1::processPayment::ZERO: Liquidity to remove cannot be zero.");
uint256 initialBalance0 = IERC20Metadata(price.v3LpTokens[i].token0).balanceOf(address(this));
uint256 initialBalance1 = IERC20Metadata(price.v3LpTokens[i].token1).balanceOf(address(this));
INonfungiblePositionManager(price.v3LpTokens[i].tokenAddress).decreaseLiquidity(
INonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: params.nonFungibleTokenDeposits[i].tokenId,
liquidity: price.v3LpTokens[i].liquidityToRemove,
amount0Min: 0,
amount1Min: 0,
deadline: block.timestamp
})
);
INonfungiblePositionManager(price.v3LpTokens[i].tokenAddress).collect(
INonfungiblePositionManager.CollectParams({
tokenId: params.nonFungibleTokenDeposits[i].tokenId,
recipient: address(this),
amount0Max: type(uint128).max,
amount1Max: type(uint128).max
})
);
uint256 amount0Received = IERC20Metadata(price.v3LpTokens[i].token0).balanceOf(address(this)) - initialBalance0;
uint256 amount1Received = IERC20Metadata(price.v3LpTokens[i].token1).balanceOf(address(this)) - initialBalance1;
address factory = INonfungiblePositionManager(price.v3LpTokens[i].tokenAddress).factory();
IERC20Metadata(price.v3LpTokens[i].token0).safeApprove(address(lpTokenProcessor), amount0Received);
IERC20Metadata(price.v3LpTokens[i].token1).safeApprove(address(lpTokenProcessor), amount1Received);
lpTokenProcessor.addTokenForSwapping(
ILPTokenProcessorV2.TokenSwapInfo({
tokenAddress: price.v3LpTokens[i].token0,
routerFactory: factory,
isV2: false,
referrer: params.referrer,
vault: params.vault,
amount: amount0Received,
v3PoolFee: price.v3LpTokens[i].fee
})
);
lpTokenProcessor.addTokenForSwapping(
ILPTokenProcessorV2.TokenSwapInfo({
tokenAddress: price.v3LpTokens[i].token1,
routerFactory: factory,
isV2: false,
referrer: params.referrer,
vault: params.vault,
amount: amount1Received,
v3PoolFee: price.v3LpTokens[i].fee
})
);
}
IERC721(params.nonFungibleTokenDeposits[i].tokenAddress).safeTransferFrom(address(this), params.vault, params.nonFungibleTokenDeposits[i].tokenId);
}
}
function _processMultiToken(ProcessPaymentParams memory params) private {
for (uint256 i = 0; i < params.multiTokenDeposits.length; i++) {
IERC1155(params.multiTokenDeposits[i].tokenAddress).safeTransferFrom(
params.user,
params.vault,
params.multiTokenDeposits[i].tokenId,
params.multiTokenDeposits[i].amount,
""
);
}
}
function _factory(address lpTokenAddress) private view returns (address) {
try IUniswapPair(lpTokenAddress).factory() returns (address factory) {
return factory;
} catch {
return address(0);
}
}
function _processFee(
uint256 usdAmount,
address user,
address referrer,
address vault
) private returns (uint256 weiToBeRefunded) {
require(address(USDT) != address(0), "PaymentModuleV1::processPayment::ZERO: USD payments not enabled.");
if (usdAmount > 0) {
uint256 initialUsdBalance = USDT.balanceOf(address(this));
if (msg.value > 0) {
weiToBeRefunded = _swapNativeToUsd(usdAmount);
} else {
USDT.safeTransferFrom(user, address(this), usdAmount);
}
uint256 newUsdBalance = USDT.balanceOf(address(this));
uint256 usdEarned = newUsdBalance - initialUsdBalance;
require(usdEarned >= usdAmount, "Not enough USD received to cover fees. USD token must not have transfer fees.");
uint256 treasuryUsdShare = usdAmount;
if (referrer != address(0)) {
uint256 referrerUSDTShare = (usdAmount * referrerBasisPoints) / BASIS_POINTS;
USDT.safeTransfer(referrer, referrerUSDTShare);
treasuryUsdShare -= referrerUSDTShare;
emit ReferrerSharePaid(referrerShareLastBlock, vault, referrer, referrerUSDTShare);
referrerShareLastBlock = block.number;
}
if (FLOKI != address(0)) {
uint256 burnShare = (usdAmount * burnBasisPoints) / BASIS_POINTS;
uint256 flokiBalance = IERC20Metadata(FLOKI).balanceOf(burnAddress);
USDT.safeApprove(address(lpTokenProcessor), burnShare);
bool success = lpTokenProcessor.swapTokens(address(USDT), burnShare, FLOKI, burnAddress, mainRouter, _getV3PoolFees());
treasuryUsdShare -= burnShare;
require(success, "Swap failed");
uint256 flokiBurned = IERC20Metadata(FLOKI).balanceOf(burnAddress) - flokiBalance;
emit FlokiBurned(flokiBurnedLastBlock, vault, burnShare, flokiBurned);
flokiBurnedLastBlock = block.number;
}
USDT.safeTransfer(treasury, treasuryUsdShare);
emit FeeCollected(feeCollectedLastBlock, vault, treasuryUsdShare);
feeCollectedLastBlock = block.number;
}
}
function _getV3PoolFees() private view returns (uint24[] memory) {
uint24[] memory fees = new uint24[](2);
fees[0] = v3PoolFeeForUsdNative;
fees[1] = v3PoolFeeForFlokiNative;
return fees;
}
function _processNativeFees(
uint256 usdAmount,
address referrer,
address vault
) private returns (uint256 weiToBeRefunded) {
priceOracle.fetchPriceInUSD(nativeWrappedToken);
uint256 price = priceOracle.getPriceInUSD(nativeWrappedToken, pricingModule.priceDecimals());
require(price > 0, "PaymentModuleV1::processPayment::INVALID: Price from oracle is unavailable.");
uint256 expectedWei = (usdAmount * 1 ether) / price;
require(msg.value >= expectedWei, "PaymentModuleV1::processPayment::INVALID: Not enough Native Tokens sent to cover fees.");
weiToBeRefunded = msg.value - expectedWei;
if (referrer != address(0)) {
uint256 referrerWeiShare = (expectedWei * referrerBasisPoints) / BASIS_POINTS;
(bool referrerSucceeded, ) = payable(referrer).call{ value: referrerWeiShare }("");
require(referrerSucceeded, "Failed to send native share to referrer.");
expectedWei -= referrerWeiShare;
uint256 usdReferrerShare = (usdAmount * referrerBasisPoints) / BASIS_POINTS;
usdAmount -= usdReferrerShare;
emit ReferrerSharePaid(referrerShareLastBlock, vault, referrer, usdReferrerShare);
referrerShareLastBlock = block.number;
}
(bool success, ) = payable(treasury).call{ value: expectedWei }("");
require(success, "Failed to send native token to treasury.");
emit FeeCollected(feeCollectedLastBlock, vault, usdAmount);
feeCollectedLastBlock = block.number;
return weiToBeRefunded;
}
function _swapNativeToUsd(uint256 usdAmount) private returns (uint256 weiToBeRefunded) {
uint256 oldEthBalance = address(this).balance;
if (isV2Router) {
address[] memory path = new address[](2);
path[0] = IUniswapV2Router02(mainRouter).WETH();
path[1] = address(USDT);
IUniswapV2Router02(mainRouter).swapETHForExactTokens{ value: msg.value }(usdAmount, path, address(this), block.timestamp);
} else {
ISwapRouterV3.ExactOutputSingleParams memory params = ISwapRouterV3.ExactOutputSingleParams({
tokenIn: ISwapRouterV3(mainRouter).WETH9(),
tokenOut: address(USDT),
fee: v3PoolFeeForUsdNative,
recipient: address(this),
amountOut: usdAmount,
amountInMaximum: msg.value,
sqrtPriceLimitX96: 0
});
ISwapRouterV3(mainRouter).exactOutputSingle{ value: msg.value }(params);
}
weiToBeRefunded = msg.value - (oldEthBalance - address(this).balance);
}
function setConvertNativeFeeToUsd(bool _convertNativeFeeToUsd) external onlyRole(DEFAULT_ADMIN_ROLE) {
convertNativeFeeToUsd = _convertNativeFeeToUsd;
}
function setFloki(address _floki) external onlyRole(DEFAULT_ADMIN_ROLE) {
FLOKI = _floki;
}
function setUsdToken(address newUsdToken) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(newUsdToken != address(0), "LPTokenProcessorV2::setUsdToken::ZERO: USDT cannot be zero address.");
address oldUsdToken = address(USDT);
USDT = IERC20Metadata(newUsdToken);
emit UsdTokenUpdated(oldUsdToken, newUsdToken);
}
function setLPTokenProcessor(address newProcessor) external onlyRole(DEFAULT_ADMIN_ROLE) {
address oldProcessor = address(lpTokenProcessor);
lpTokenProcessor = ILPTokenProcessorV2(newProcessor);
emit LPTokenProcessorUpdated(oldProcessor, newProcessor);
}
function setPriceOracleManager(address priceOracleAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
address oldPriceOracle = address(priceOracle);
priceOracle = IPriceOracleManager(priceOracleAddress);
emit PriceOracleManagerUpdated(oldPriceOracle, priceOracleAddress);
}
function setPricingModule(address newModule) external onlyRole(DEFAULT_ADMIN_ROLE) {
address oldModule = address(pricingModule);
pricingModule = IPricingModule(newModule);
emit PricingModuleUpdated(oldModule, newModule);
}
function setRouter(address newRouter, bool v2Router) external onlyRole(DEFAULT_ADMIN_ROLE) {
address oldRouter = mainRouter;
mainRouter = newRouter;
isV2Router = v2Router;
nativeWrappedToken = _getNativeWrappedToken();
emit RouterUpdated(oldRouter, newRouter, v2Router);
}
function setV3PoolFeeForUsd(uint24 newFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint24 oldFee = v3PoolFeeForUsdNative;
v3PoolFeeForUsdNative = newFee;
emit V3PoolFeeForUsdUpdated(oldFee, newFee);
}
function setV3PoolFeeForFloki(uint24 newFee) external onlyRole(DEFAULT_ADMIN_ROLE) {
uint24 oldFee = v3PoolFeeForFlokiNative;
v3PoolFeeForFlokiNative = newFee;
emit V3PoolFeeForFlokiUpdated(oldFee, newFee);
}
function setTreasury(address newTreasury) external onlyRole(DEFAULT_ADMIN_ROLE) {
address oldTreasury = treasury;
treasury = newTreasury;
emit TreasuryAddressUpdated(oldTreasury, newTreasury);
}
function adminWithdraw(address tokenAddress, uint256 amount) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (tokenAddress == address(0)) {
(bool success, ) = payable(treasury).call{ value: amount }("");
require(success, "Failed to withdraw ETH");
} else {
IERC20Metadata(tokenAddress).safeTransfer(treasury, amount);
}
}
function notifyFeeCollected(address _vault, uint256 _amount) external onlyRole(DEFAULT_ADMIN_ROLE) {
emit FeeCollected(feeCollectedLastBlock, _vault, _amount);
feeCollectedLastBlock = block.number;
}
function notifyFlokiBurned(
address _vault,
uint256 _usdAmount,
uint256 _flokiAmount
) external onlyRole(DEFAULT_ADMIN_ROLE) {
emit FlokiBurned(flokiBurnedLastBlock, _vault, _usdAmount, _flokiAmount);
flokiBurnedLastBlock = block.number;
}
function notifyReferrerSharePaid(
address _vault,
address _referrer,
uint256 _amount
) external onlyRole(DEFAULT_ADMIN_ROLE) {
emit ReferrerSharePaid(referrerShareLastBlock, _vault, _referrer, _amount);
referrerShareLastBlock = block.number;
}
receive() external payable {}
function onERC721Received(
address,
address,
uint256,
bytes calldata
) external pure override returns (bytes4) {
return this.onERC721Received.selector;
}
}
文件 28 的 30:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
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));
}
}
function safePermit(
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");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 29 的 30:Strings.sol
pragma solidity ^0.8.0;
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(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");
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
文件 30 的 30:draft-IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
{
"compilationTarget": {
"contracts/locker/payment/PaymentModuleV1.sol": "PaymentModuleV1"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 800
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"flokiAddress","type":"address"},{"internalType":"address","name":"lpTokenProcessorAddress","type":"address"},{"internalType":"address","name":"pricingModuleAddress","type":"address"},{"internalType":"address","name":"treasuryAddress","type":"address"},{"internalType":"address","name":"routerAddress","type":"address"},{"internalType":"bool","name":"v2Router","type":"bool"},{"internalType":"address","name":"priceOracleAddress","type":"address"},{"internalType":"address","name":"usdAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"previousBlock","type":"uint256"},{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdAmount","type":"uint256"}],"name":"FeeCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"previousBlock","type":"uint256"},{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"flokiAmount","type":"uint256"}],"name":"FlokiBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldProcessor","type":"address"},{"indexed":true,"internalType":"address","name":"newProcessor","type":"address"}],"name":"LPTokenProcessorUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOracle","type":"address"},{"indexed":true,"internalType":"address","name":"newOracle","type":"address"}],"name":"PriceOracleManagerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldModule","type":"address"},{"indexed":true,"internalType":"address","name":"newModule","type":"address"}],"name":"PricingModuleUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"previousBlock","type":"uint256"},{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"address","name":"referrer","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdAmount","type":"uint256"}],"name":"ReferrerSharePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldRouter","type":"address"},{"indexed":true,"internalType":"address","name":"newRouter","type":"address"},{"indexed":false,"internalType":"bool","name":"isV3Router","type":"bool"}],"name":"RouterUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldSlippage","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newSlippage","type":"uint256"}],"name":"SlippageUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldTreasury","type":"address"},{"indexed":true,"internalType":"address","name":"newTreasury","type":"address"}],"name":"TreasuryAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldUsd","type":"address"},{"indexed":true,"internalType":"address","name":"newUsd","type":"address"}],"name":"UsdTokenUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint24","name":"oldFee","type":"uint24"},{"indexed":true,"internalType":"uint24","name":"newFee","type":"uint24"}],"name":"V3PoolFeeForFlokiUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint24","name":"oldFee","type":"uint24"},{"indexed":true,"internalType":"uint24","name":"newFee","type":"uint24"}],"name":"V3PoolFeeForUsdUpdated","type":"event"},{"inputs":[],"name":"BASIS_POINTS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FLOKI","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAYMENT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"USDT","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"adminWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"burnAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnBasisPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"convertNativeFeeToUsd","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeCollectedLastBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"flokiBurnedLastBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isV2Router","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpTokenProcessor","outputs":[{"internalType":"contract ILPTokenProcessorV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mainRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nativeWrappedToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"notifyFeeCollected","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"uint256","name":"_usdAmount","type":"uint256"},{"internalType":"uint256","name":"_flokiAmount","type":"uint256"}],"name":"notifyFlokiBurned","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_referrer","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"notifyReferrerSharePaid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"priceOracle","outputs":[{"internalType":"contract IPriceOracleManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pricingModule","outputs":[{"internalType":"contract IPricingModule","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"referrer","type":"address"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"isLP","type":"bool"}],"internalType":"struct IDepositHandler.FungibleTokenDeposit[]","name":"fungibleTokenDeposits","type":"tuple[]"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"internalType":"struct IDepositHandler.NonFungibleTokenDeposit[]","name":"nonFungibleTokenDeposits","type":"tuple[]"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct IDepositHandler.MultiTokenDeposit[]","name":"multiTokenDeposits","type":"tuple[]"},{"internalType":"bool","name":"isVesting","type":"bool"}],"internalType":"struct IPaymentModule.ProcessPaymentParams","name":"params","type":"tuple"}],"name":"processPayment","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"referrerBasisPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"referrerShareLastBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"routerForFloki","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_convertNativeFeeToUsd","type":"bool"}],"name":"setConvertNativeFeeToUsd","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_floki","type":"address"}],"name":"setFloki","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newProcessor","type":"address"}],"name":"setLPTokenProcessor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"priceOracleAddress","type":"address"}],"name":"setPriceOracleManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newModule","type":"address"}],"name":"setPricingModule","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newRouter","type":"address"},{"internalType":"bool","name":"v2Router","type":"bool"}],"name":"setRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newTreasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newUsdToken","type":"address"}],"name":"setUsdToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"newFee","type":"uint24"}],"name":"setV3PoolFeeForFloki","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint24","name":"newFee","type":"uint24"}],"name":"setV3PoolFeeForUsd","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"v3PoolFeeForFlokiNative","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"v3PoolFeeForUsdNative","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]