编译器
0.8.25+commit.b61c2a91
文件 1 的 31:ApprovalHelper.sol
pragma solidity =0.8.25;
import "./CallOptionalReturn.sol";
contract ApprovalHelper is CallOptionalReturn {
function _safeApprove(
address _token,
address _spender,
uint256 _value
)
internal
{
if (_spender == address(0)) {
return;
}
_callOptionalReturn(
_token,
abi.encodeWithSelector(
IERC20.approve.selector,
_spender,
_value
)
);
}
}
文件 2 的 31:CallOptionalReturn.sol
pragma solidity =0.8.25;
import "../InterfaceHub/IERC20.sol";
contract CallOptionalReturn {
function _callOptionalReturn(
address token,
bytes memory data
)
internal
returns (bool call)
{
(
bool success,
bytes memory returndata
) = token.call(
data
);
bool results = returndata.length == 0 || abi.decode(
returndata,
(bool)
);
if (success == false) {
revert();
}
call = success
&& results
&& token.code.length > 0;
}
}
文件 3 的 31:EthenaPowerFarm.sol
pragma solidity =0.8.25;
import "../../GenericPowerManager.sol";
error ApiRoutingCallFailed();
error ApiRoutingDebtRatioTooHigh();
error ApiRoutingTooMuchValueLost();
abstract contract EthenaPowerFarm is GenericPowerManager {
address USDC_UNI_V3_POOL_ETH_MAIN = 0x4e0924d3a751bE199C426d52fb1f2337fa96f736;
constructor(
address _wiseLendingAddress,
address _pendleChildTokenAddress,
address _pendleRouter,
address _entryAsset,
address _pendleSy,
address _underlyingMarket,
address _routerStatic,
address _dexAddress,
uint256 _collateralFactor,
address _powerFarmNFTs,
address _farmAsset,
address _poolAssetAave
)
GenericPowerManager(
_wiseLendingAddress,
_pendleChildTokenAddress,
_pendleRouter,
_entryAsset,
_pendleSy,
_underlyingMarket,
_routerStatic,
_dexAddress,
_collateralFactor,
_powerFarmNFTs
)
{
FARM_ASSET = _farmAsset;
POOL_ASSET_AAVE = _poolAssetAave;
_doApprovals(
_wiseLendingAddress
);
collateralFactorRole = msg.sender;
if (block.chainid == 1) {
UNISWAP_V3_POOL = IUniswapV3PoolPowerFarm(
USDC_UNI_V3_POOL_ETH_MAIN
);
}
}
event WhiteListedExternalContract(
address indexed _contract,
bool _isWhiteListed
);
function setWhiteListForContracts(
address[] memory _whiteList,
bool[] memory _isWhiteListed
)
external
onlyMaster
{
for (uint256 i = 0; i < _whiteList.length; i++) {
_setMapping(
whiteListedExternalContracts,
_whiteList[i],
_isWhiteListed[i]
);
emit WhiteListedExternalContract(
_whiteList[i],
_isWhiteListed[i]
);
}
}
function changeUniV3Pool(
address _newUniV3Pool
)
external
override
onlyMaster
{
UNISWAP_V3_POOL = IUniswapV3PoolPowerFarm(
_newUniV3Pool
);
}
function _setMapping(
mapping(address => bool) storage _mapping,
address _key,
bool _state
)
private
{
_mapping[_key] = _state;
}
function _doApprovals(
address _wiseLendingAddress
)
internal
virtual
override
{
_safeApprove(
POOL_ASSET_AAVE,
_wiseLendingAddress,
MAX_AMOUNT
);
_safeApprove(
FARM_ASSET,
PENDLE_LIMIT_ROUTER_ADDRESS,
MAX_AMOUNT
);
_safeApprove(
address(PENDLE_MARKET),
PENDLE_LIMIT_ROUTER_ADDRESS,
MAX_AMOUNT
);
_safeApprove(
address(PENDLE_MARKET),
address(PENDLE_ROUTER),
MAX_AMOUNT
);
_safeApprove(
FARM_ASSET,
_wiseLendingAddress,
MAX_AMOUNT
);
_safeApprove(
PENDLE_CHILD,
_wiseLendingAddress,
MAX_AMOUNT
);
_safeApprove(
address(PENDLE_MARKET),
PENDLE_CHILD,
MAX_AMOUNT
);
_safeApprove(
FARM_ASSET,
address(AAVE_HUB),
MAX_AMOUNT
);
_safeApprove(
FARM_ASSET,
address(PENDLE_ROUTER),
MAX_AMOUNT
);
}
function _logicOpenPosition(
bytes memory _callData,
bool _isAave,
uint256 _nftId,
uint256 _depositAmount,
uint256 _totalDebtBalancer,
uint256 _allowedSpread
)
internal
virtual
override
{
uint256 ethValueBefore = _getTokensInETH(
FARM_ASSET,
_depositAmount
);
uint256 netLpOut = _routeWithCallData({
_callData: _callData,
_addLiquidity: true
});
(
uint256 receivedShares,
) = IPendleChild(PENDLE_CHILD).depositExactAmount(
netLpOut
);
uint256 ethValueAfter = _getTokensInETH(
PENDLE_CHILD,
receivedShares
)
* _allowedSpread
/ PRECISION_FACTOR_E18;
if (ethValueAfter < ethValueBefore) {
revert ApiRoutingTooMuchValueLost();
}
WISE_LENDING.depositExactAmount(
_nftId,
PENDLE_CHILD,
receivedShares
);
_borrowExactAmount(
_isAave,
_nftId,
_totalDebtBalancer
);
if (_checkDebtRatio(_nftId) == false) {
revert ApiRoutingDebtRatioTooHigh();
}
if (block.chainid == 1) {
_safeTransfer(
FARM_ASSET,
address(UNISWAP_V3_POOL),
_totalDebtBalancer
);
return;
}
_safeTransfer(
FARM_ASSET,
BALANCER_ADDRESS,
_totalDebtBalancer
);
}
function _logicClosePosition(
bytes memory _callData,
uint256 _nftId,
uint256 _borrowShares,
uint256 _lendingShares,
uint256 _totalDebtBalancer,
uint256 _allowedSpread,
address _caller,
bool,
bool _isAave
)
internal
virtual
override
{
_paybackExactShares(
_isAave,
_nftId,
_borrowShares
);
uint256 ethValueBefore = _getTokensInETH(
PENDLE_CHILD,
IPendleChild(PENDLE_CHILD).previewAmountWithdrawShares(
_getCashoutAmount(
PENDLE_CHILD,
_getPositionLendingShares(_nftId)
),
IPendleChild(PENDLE_CHILD).underlyingLpAssetsCurrent()
)
);
_withdrawPendleLPs(
_nftId,
_lendingShares
);
uint256 netTokenOut = _routeWithCallData({
_callData: _callData,
_addLiquidity: false
});
uint256 ethValueAfter = _getTokensInETH(
FARM_ASSET,
netTokenOut
)
* _allowedSpread
/ PRECISION_FACTOR_E18;
if (ethValueAfter < ethValueBefore) {
revert ApiRoutingTooMuchValueLost();
}
_closingRouteToken(
netTokenOut,
_totalDebtBalancer,
_caller
);
}
function _routeWithCallData(
bytes memory _callData,
bool _addLiquidity
)
private
returns (uint256)
{
_verifyCallData({
_callData: _callData,
_addLiquidity: _addLiquidity
});
(
bool success,
bytes memory returnData
) = _callPendleRouter(
_callData
);
if (success == false) {
revert ApiRoutingCallFailed();
}
(
uint256 netTokenOut,
,
) = abi.decode(
returnData,
(
uint256,
uint256,
uint256
)
);
return netTokenOut;
}
}
文件 4 的 31:EthenaPowerFarmDai.sol
pragma solidity =0.8.25;
import "./EthenaPowerFarm.sol";
contract EthenaApiRoutingDai is EthenaPowerFarm {
address public constant AAVE_DAI_ADDRESS = address(
0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE
);
address public constant DAI_ADDRESS = address(
0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1
);
address public constant DAI_ADDRESS_ETH_MAIN = address(
0x6B175474E89094C44Da98b954EedeAC495271d0F
);
address public AAVE_DAI_ADDRESS_ETH_MAIN = 0x018008bfb33d285247A21d44E50697654f754e63;
constructor(
address _wiseLendingAddress,
address _pendleChildTokenAddress,
address _pendleRouter,
address _entryAsset,
address _pendleSy,
address _underlyingMarket,
address _routerStatic,
address _dexAddress,
uint256 _collateralFactor,
address _powerFarmNFTs
)
EthenaPowerFarm(
_wiseLendingAddress,
_pendleChildTokenAddress,
_pendleRouter,
_entryAsset,
_pendleSy,
_underlyingMarket,
_routerStatic,
_dexAddress,
_collateralFactor,
_powerFarmNFTs,
block.chainid == 1
? DAI_ADDRESS_ETH_MAIN
: DAI_ADDRESS,
block.chainid == 1
? AAVE_DAI_ADDRESS_ETH_MAIN
: AAVE_DAI_ADDRESS
)
{}
}
文件 5 的 31:GenericDeclarations.sol
pragma solidity =0.8.25;
import "../InterfaceHub/IAave.sol";
import "../InterfaceHub/IPendle.sol";
import "../InterfaceHub/IAaveHub.sol";
import "../InterfaceHub/IWiseLending.sol";
import "../InterfaceHub/IWiseSecurity.sol";
import "../InterfaceHub/IPositionNFTs.sol";
import "../InterfaceHub/IWiseOracleHub.sol";
import "../InterfaceHub/IBalancerFlashloan.sol";
import "../InterfaceHub/IUniswapV3.sol";
import "../InterfaceHub/IUniswapV2Pool.sol";
import "../InterfaceHub/IUniswapV3PoolPowerFarm.sol";
import "../InterfaceHub/IUniswapFactory.sol";
import "../InterfaceHub/IOraclePendle.sol";
import "../TransferHub/WrapperHelper.sol";
import "../TransferHub/TransferHelper.sol";
import "../TransferHub/ApprovalHelper.sol";
import "../TransferHub/SendValueHelper.sol";
import "./GenericErrors.sol";
contract GenericDeclarations is
WrapperHelper,
TransferHelper,
ApprovalHelper,
SendValueHelper
{
bool public isShutdown;
bool public allowEnter;
uint256 public collateralFactor;
uint256 public minDepositEthAmount;
uint256 internal MAX_PROPORTION = 96
* PRECISION_FACTOR_E18
/ 100;
address public FARM_ASSET;
address public POOL_ASSET_AAVE;
address public PENDLE_LIMIT_ROUTER_ADDRESS;
address public immutable ENTRY_ASSET;
address public immutable PENDLE_CHILD;
IAave public immutable AAVE;
IAaveHub public immutable AAVE_HUB;
IWiseLending public immutable WISE_LENDING;
IWiseOracleHub public immutable ORACLE_HUB;
IWiseSecurity public immutable WISE_SECURITY;
IBalancerVault public immutable BALANCER_VAULT;
IPositionNFTs public immutable POSITION_NFT;
IUniswapV3 public immutable UNISWAP_V3_ROUTER;
IUniswapV2Pool public UNISWAP_V2_POOL;
IUniswapV3PoolPowerFarm public UNISWAP_V3_POOL;
IUniswapFactory public immutable UNISWAP_FACTORY;
IPendleSy public immutable PENDLE_SY;
IPendleRouter public PENDLE_ROUTER;
IPendleMarket public immutable PENDLE_MARKET;
IPendleRouterStatic public immutable PENDLE_ROUTER_STATIC;
IOraclePendle public immutable PT_ORACLE_PENDLE;
address internal immutable WETH_ADDRESS;
address immutable AAVE_ADDRESS;
address immutable AAVE_HUB_ADDRESS;
address immutable AAVE_WETH_ADDRESS;
address public collateralFactorRole;
bool public ethBack;
bool public specialDepegCase;
bool public routingOngoing;
struct FarmData {
uint256 wiseLendingNFT;
uint256 leverage;
uint256 amount;
uint256 amountAfterMintFee;
uint256 timestamp;
}
mapping(uint256 => FarmData) public farmData;
mapping(uint256 => bool) public isAave;
mapping(address => bool) public whiteListedExternalContracts;
event FarmEntry(
uint256 indexed keyId,
uint256 indexed wiseLendingNFT,
uint256 indexed leverage,
uint256 amount,
uint256 amountAfterMintFee,
uint256 timestamp
);
event FarmExit(
uint256 indexed keyId,
uint256 indexed wiseLendingNFT,
uint256 amount,
uint256 timestamp
);
event FarmStatus(
bool indexed state,
uint256 timestamp
);
event ManualPaybackShares(
uint256 indexed keyId,
uint256 indexed wiseLendingNFT,
uint256 amount,
uint256 timestamp
);
event ManualWithdrawShares(
uint256 indexed keyId,
uint256 indexed wiseLendingNFT,
uint256 amount,
uint256 timestamp
);
event MinDepositChange(
uint256 minDepositEthAmount,
uint256 timestamp
);
event ETHReceived(
uint256 amount,
address from
);
event RegistrationFarm(
uint256 nftId,
uint256 timestamp
);
uint256 internal constant ETH_CHAIN_ID = 1;
uint256 internal constant ARB_CHAIN_ID = 42161;
uint256 internal constant FIFTY_PERCENT = 50E16;
uint256 internal constant PRECISION_FACTOR_E18 = 1E18;
uint256 internal constant PRECISION_FACTOR_E16 = 1E16;
uint256 internal constant PRECISION_FACTOR_E18_2X = 2E18;
uint256 internal constant MAX_AMOUNT = type(uint256).max;
uint256 internal constant MAX_LEVERAGE = 15 * PRECISION_FACTOR_E18;
uint24 public constant UNISWAP_V3_FEE = 100;
address internal constant BALANCER_ADDRESS = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
address public constant UNISWAP_FACTORY_V2_ADDRESS = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
uint256 ongoingFlashAmountV3;
constructor(
address _wiseLendingAddress,
address _pendleChildTokenAddress,
address _pendleRouter,
address _entryAsset,
address _pendleSy,
address _underlyingMarket,
address _routerStatic,
address _dexAddress,
uint256 _collateralFactor
)
WrapperHelper(
IWiseLending(_wiseLendingAddress).WETH_ADDRESS()
)
{
PENDLE_ROUTER_STATIC = IPendleRouterStatic(
_routerStatic
);
PENDLE_MARKET = IPendleMarket(
_underlyingMarket
);
PENDLE_SY = IPendleSy(
_pendleSy
);
PENDLE_ROUTER = IPendleRouter(
_pendleRouter
);
UNISWAP_V3_ROUTER = IUniswapV3(
_dexAddress
);
if (block.chainid == ETH_CHAIN_ID) {
UNISWAP_FACTORY = IUniswapFactory(
UNISWAP_FACTORY_V2_ADDRESS
);
}
ENTRY_ASSET = _entryAsset;
PENDLE_CHILD = _pendleChildTokenAddress;
WISE_LENDING = IWiseLending(
_wiseLendingAddress
);
ORACLE_HUB = IWiseOracleHub(
WISE_LENDING.WISE_ORACLE()
);
BALANCER_VAULT = IBalancerVault(
BALANCER_ADDRESS
);
WISE_SECURITY = IWiseSecurity(
WISE_LENDING.WISE_SECURITY()
);
WETH_ADDRESS = WISE_LENDING.WETH_ADDRESS();
AAVE_HUB = IAaveHub(
WISE_SECURITY.AAVE_HUB()
);
AAVE_ADDRESS = AAVE_HUB.AAVE_ADDRESS();
AAVE = IAave(
AAVE_ADDRESS
);
AAVE_HUB_ADDRESS = address(
AAVE_HUB
);
POSITION_NFT = IPositionNFTs(
WISE_LENDING.POSITION_NFT()
);
collateralFactor = _collateralFactor;
AAVE_WETH_ADDRESS = AAVE_HUB.aaveTokenAddress(
AAVE_HUB.WETH_ADDRESS()
);
PT_ORACLE_PENDLE = IOraclePendle(
0x1Fd95db7B7C0067De8D45C0cb35D59796adfD187
);
PENDLE_LIMIT_ROUTER_ADDRESS = 0x000000000000c9B3E2C3Ec88B1B4c0cD853f4321;
minDepositEthAmount = 0.03 ether;
if (block.chainid == ETH_CHAIN_ID) {
minDepositEthAmount = 3 ether;
PT_ORACLE_PENDLE = IOraclePendle(
0x66a1096C6366b2529274dF4f5D8247827fe4CEA8
);
}
}
function changeUniV3Pool(
address _poolAddress
)
external
virtual
{}
function doApprovals()
external
virtual
{
_doApprovals(
address(WISE_LENDING)
);
}
function _doApprovals(
address _wiseLendingAddress
)
internal
virtual
{}
modifier isActive()
{
_isActive();
_;
}
modifier routingOngoingCheck()
{
_routingOngoingCheck();
_;
}
function _routingOngoingCheck()
internal
virtual
{
if (routingOngoing == true) {
revert GenericRoutingOngoing();
}
}
function _isActive()
internal
virtual
view
{
if (isShutdown == true) {
revert GenericDeactivated();
}
}
modifier onlyCollateralFactorRole() {
_onlyCollateralFactorRole();
_;
}
function _onlyCollateralFactorRole()
internal
virtual
{
if (msg.sender != collateralFactorRole) {
revert GenericAccessDenied();
}
}
}
文件 6 的 31:GenericErrors.sol
pragma solidity =0.8.25;
error GenericDeactivated();
error GenericAccessDenied();
error GenericInvalidParam();
error GenericTooManyShares();
error GenericAmountTooSmall();
error GenericLevergeTooHigh();
error GenericDebtRatioTooLow();
error GenericNotBalancerVaultOrSelf();
error GenericDebtRatioTooHigh();
error GenericSendingOnGoing();
error GenericWrongExtRouter(
address _unverifiedExtRouter
);
error GenericWrongPendleSwap(
address _unverifiedPendleSwap
);
error GenericWrongLimitRouter(
address _unverifiedLimitRouter
);
error GenericWrongMarket(
address _unverifiedMarket,
address _expectedMarket
);
error GenericWrongTokenIn(
address _unverifiedTokenIn,
address _expectedTokenIn
);
error GenericWrongTokenOut(
address _unverifiedTokenOut,
address _expectedTokenOut
);
error GenericWrongReceiver(
address _unverifiedReceiver,
address _expectedReceiver
);
error GenericInvalidSelector(
bytes4 _unverifiedSelector,
bytes4 _expectedSelector
);
error GenericRoutingOngoing();
error GenericNotV2Pair(
address,
address
);
error GenericNotV3Pair(
address,
address
);
error GenericNotSender();
error BadDebt(
uint256 amount
);
文件 7 的 31:GenericLeverageLogic.sol
pragma solidity =0.8.25;
import "./GenericMathLogic.sol";
abstract contract GenericLeverageLogic is
GenericMathLogic,
IFlashLoanRecipient
{
function _executeBalancerFlashLoan(
uint256 _nftId,
uint256 _flashAmount,
uint256 _initialAmount,
uint256 _lendingShares,
uint256 _borrowShares,
uint256 _allowedSpread,
bool _ethBack,
bool _isAave,
bytes memory _callData
)
internal
virtual
{
IERC20[] memory tokens = new IERC20[](1);
uint256[] memory amount = new uint256[](1);
tokens[0] = IERC20(FARM_ASSET);
amount[0] = _flashAmount;
allowEnter = true;
if (UNISWAP_V2_POOL != IUniswapV2Pool(address(0))) {
UNISWAP_V2_POOL.swap(
0,
_flashAmount,
address(this),
abi.encode(
_nftId,
_initialAmount,
_lendingShares,
_borrowShares,
_allowedSpread,
msg.sender,
_ethBack,
_isAave,
_callData
)
);
return;
}
if (UNISWAP_V3_POOL != IUniswapV3PoolPowerFarm(address(0))) {
ongoingFlashAmountV3 = _flashAmount;
UNISWAP_V3_POOL.flash(
address(this),
UNISWAP_V3_POOL.token0() == FARM_ASSET
? _flashAmount
: 0,
UNISWAP_V3_POOL.token1() == FARM_ASSET
? _flashAmount
: 0,
abi.encode(
_nftId,
_initialAmount,
_lendingShares,
_borrowShares,
_allowedSpread,
msg.sender,
_ethBack,
_isAave,
_callData
)
);
return;
}
BALANCER_VAULT.flashLoan(
this,
tokens,
amount,
abi.encode(
_nftId,
_initialAmount,
_lendingShares,
_borrowShares,
_allowedSpread,
msg.sender,
_ethBack,
_isAave,
_callData
)
);
}
function uniswapV3FlashCallback(
uint256 _fee0,
uint256 _fee1,
bytes calldata _data
)
external
{
if (msg.sender != address(UNISWAP_V3_POOL)) {
revert GenericNotV3Pair(
msg.sender,
address(UNISWAP_V3_POOL)
);
}
if (allowEnter == false) {
revert GenericAccessDenied();
}
IERC20[] memory tokens = new IERC20[](1);
tokens[0] = IERC20(FARM_ASSET);
uint256[] memory amounts = new uint256[](1);
amounts[0] = ongoingFlashAmountV3;
uint256[] memory feeAmounts = new uint256[](1);
feeAmounts[0] = _fee0 == 0
? _fee1
: _fee0;
this.receiveFlashLoan(
tokens,
amounts,
feeAmounts,
_data
);
}
function _validateEntryConditions(
uint256 _tokenLength,
address _sender
)
private
{
if (allowEnter == false) {
revert GenericAccessDenied();
}
allowEnter = false;
if (_tokenLength == 0) {
revert GenericInvalidParam();
}
if (_sender != BALANCER_ADDRESS ) {
if (_sender != address(this)) {
revert GenericNotBalancerVaultOrSelf();
}
}
}
function receiveFlashLoan(
IERC20[] memory _flashloanToken,
uint256[] memory _flashloanAmounts,
uint256[] memory _feeAmounts,
bytes memory _userData
)
external
virtual
{
_validateEntryConditions(
_flashloanToken.length,
msg.sender
);
_processLoan(
_userData,
_flashloanAmounts[0],
_flashloanAmounts[0] + _feeAmounts[0]
);
}
function uniswapV2Call(
address sender,
uint256 amount0,
uint256 amount1,
bytes calldata data
)
external
{
address token0 = IUniswapV2Pool(msg.sender).token0();
address token1 = IUniswapV2Pool(msg.sender).token1();
address pair = UNISWAP_FACTORY.getPair(
token0,
token1
);
if (msg.sender != address(UNISWAP_V2_POOL)) {
revert GenericNotV2Pair(
msg.sender,
pair
);
}
if (sender != address(this)) {
revert GenericNotSender();
}
IERC20[] memory tokens = new IERC20[](1);
tokens[0] = IERC20(
FARM_ASSET
);
uint256[] memory amounts = new uint256[](1);
amounts[0] = amount0 == 0
? amount1
: amount0;
uint256[] memory feeAmounts = new uint256[](1);
feeAmounts[0] = _calculateFlashLoanFee(
amounts[0]
);
this.receiveFlashLoan(
tokens,
amounts,
feeAmounts,
data
);
}
function _calculateFlashLoanFee(
uint256 amountWithdrawn
)
public
pure
returns (uint256)
{
return (
amountWithdrawn
* 1000
/ 997
) - amountWithdrawn
+ 1;
}
function _processLoan(
bytes memory _userData,
uint256 _flashloanAmount,
uint256 _totalDebtBalancer
)
private
{
(
uint256 nftId,
uint256 initialAmount,
uint256 lendingShares,
uint256 borrowShares,
uint256 allowedSpread,
address caller,
bool ethBack,
bool isAave,
bytes memory callData
) = abi.decode(
_userData,
(
uint256,
uint256,
uint256,
uint256,
uint256,
address,
bool,
bool,
bytes
)
);
if (initialAmount > 0) {
_logicOpenPosition(
callData,
isAave,
nftId,
_flashloanAmount + initialAmount,
_totalDebtBalancer,
allowedSpread
);
return;
}
_logicClosePosition(
callData,
nftId,
borrowShares,
lendingShares,
_totalDebtBalancer,
allowedSpread,
caller,
ethBack,
isAave
);
}
function _logicClosePosition(
bytes memory _callData,
uint256 _nftId,
uint256 _borrowShares,
uint256 _lendingShares,
uint256 _totalDebtBalancer,
uint256 _allowedSpread,
address _caller,
bool _ethBack,
bool _isAave
)
internal
virtual
{}
function _getEthBack(
uint256 _swapAmount,
uint256 _minOutAmount
)
internal
virtual
returns (uint256)
{
uint256 wethAmount = _getTokensUniV3(
_swapAmount,
_minOutAmount,
ENTRY_ASSET,
FARM_ASSET
);
_unwrapETH(
wethAmount
);
return wethAmount;
}
function _getTokensUniV3(
uint256 _amountIn,
uint256 _minOutAmount,
address _tokenIn,
address _tokenOut
)
internal
virtual
returns (uint256)
{
return UNISWAP_V3_ROUTER.exactInputSingle(
IUniswapV3.ExactInputSingleParams(
{
tokenIn: _tokenIn,
tokenOut: _tokenOut,
fee: UNISWAP_V3_FEE,
recipient: address(this),
deadline: block.timestamp,
amountIn: _amountIn,
amountOutMinimum: _minOutAmount,
sqrtPriceLimitX96: 0
}
)
);
}
function _swapStETHintoETH(
uint256 _swapAmount,
uint256 _minOutAmount
)
internal
virtual
returns (uint256)
{}
function _withdrawPendleLPs(
uint256 _nftId,
uint256 _lendingShares
)
internal
virtual
returns (uint256 withdrawnLpsAmount)
{
return IPendleChild(PENDLE_CHILD).withdrawExactShares(
_withdrawExactShares(
_nftId,
PENDLE_CHILD,
_lendingShares
)
);
}
function _withdrawExactShares(
uint256 _nftId,
address _token,
uint256 _lendingShares
)
internal
virtual
returns (uint256 withdrawnAmount)
{
return WISE_LENDING.withdrawExactShares(
_nftId,
_token,
_lendingShares
);
}
function _paybackExactShares(
bool _isAave,
uint256 _nftId,
uint256 _borrowShares
)
internal
virtual
{
if (_isAave == true) {
AAVE_HUB.paybackExactShares(
_nftId,
FARM_ASSET,
_borrowShares
);
return;
}
WISE_LENDING.paybackExactShares(
_nftId,
FARM_ASSET,
_borrowShares
);
}
function _closingRouteToken(
uint256 _tokenAmount,
uint256 _totalDebtBalancer,
address _caller
)
internal
virtual
{
if (FARM_ASSET == WETH_ADDRESS) {
_wrapETH(
_tokenAmount
);
}
address extraPoolAddress = address(UNISWAP_V2_POOL) == address(0x0)
? address(UNISWAP_V3_POOL)
: address(UNISWAP_V2_POOL);
_safeTransfer(
FARM_ASSET,
msg.sender != BALANCER_ADDRESS
? extraPoolAddress
: BALANCER_ADDRESS,
_totalDebtBalancer
);
_safeTransfer(
FARM_ASSET,
_caller,
_tokenAmount - _totalDebtBalancer
);
}
function _closingRouteETH(
uint256 _ethAmount,
uint256 _totalDebtBalancer,
address _caller
)
internal
virtual
{
_wrapETH(
_totalDebtBalancer
);
_safeTransfer(
FARM_ASSET,
msg.sender != BALANCER_ADDRESS
? address(UNISWAP_V2_POOL)
: BALANCER_ADDRESS,
_totalDebtBalancer
);
_sendValue(
_caller,
_ethAmount - _totalDebtBalancer
);
}
function _logicOpenPosition(
bytes memory _callData,
bool _isAave,
uint256 _nftId,
uint256 _depositAmount,
uint256 _totalDebtBalancer,
uint256 _allowedSpread
)
internal
virtual
{}
function _borrowExactAmount(
bool _isAave,
uint256 _nftId,
uint256 _totalDebtBalancer
)
internal
virtual
{
if (_isAave == true) {
AAVE_HUB.borrowExactAmount(
_nftId,
FARM_ASSET,
_totalDebtBalancer
);
return;
}
WISE_LENDING.borrowExactAmount(
_nftId,
FARM_ASSET,
_totalDebtBalancer
);
}
function _coreLiquidation(
uint256 _nftId,
uint256 _nftIdLiquidator,
uint256 _shareAmountToPay
)
internal
virtual
returns (
uint256 paybackAmount,
uint256 receivingAmount
)
{
_checkLiquidatability(
_nftId
);
address paybackToken = isAave[_nftId] == true
? POOL_ASSET_AAVE
: FARM_ASSET;
paybackAmount = _getPaybackAmount(
paybackToken,
_shareAmountToPay
);
uint256 cutoffShares = isAave[_nftId] == true
? _getPositionBorrowSharesAave(_nftId)
* FIFTY_PERCENT
/ PRECISION_FACTOR_E18
: _getPositionBorrowShares(_nftId)
* FIFTY_PERCENT
/ PRECISION_FACTOR_E18;
if (_shareAmountToPay > cutoffShares) {
revert GenericTooManyShares();
}
receivingAmount = WISE_LENDING.coreLiquidationIsolationPools(
_nftId,
_nftIdLiquidator,
msg.sender,
paybackToken,
PENDLE_CHILD,
paybackAmount,
_shareAmountToPay
);
}
function _checkLiquidatability(
uint256 _nftId
)
internal
virtual
view
{
if (specialDepegCase == true) {
return;
}
if (_checkDebtRatio(_nftId) == true) {
revert GenericDebtRatioTooLow();
}
}
function _callPendleRouter(
bytes memory _callData
)
internal
virtual
returns (
bool success,
bytes memory returnData
)
{
routingOngoing = true;
(
success,
returnData
) = address(PENDLE_ROUTER).call(
_callData
);
routingOngoing = false;
}
}
文件 8 的 31:GenericMathLogic.sol
pragma solidity =0.8.25;
import "./GenericDeclarations.sol";
abstract contract GenericMathLogic is GenericDeclarations {
modifier updatePools() {
_checkReentrancy();
_updatePools();
_;
}
function _updatePools()
internal
virtual
{
WISE_LENDING.syncManually(
FARM_ASSET
);
WISE_LENDING.syncManually(
POOL_ASSET_AAVE
);
WISE_LENDING.syncManually(
PENDLE_CHILD
);
}
function _checkReentrancy()
internal
virtual
view
{
if (sendingProgress == true) {
revert GenericAccessDenied();
}
if (WISE_LENDING.sendingProgress() == true) {
revert GenericAccessDenied();
}
if (AAVE_HUB.sendingProgressAaveHub() == true) {
revert GenericAccessDenied();
}
}
function _getPositionBorrowShares(
uint256 _nftId
)
internal
virtual
view
returns (uint256)
{
return WISE_LENDING.getPositionBorrowShares(
_nftId,
FARM_ASSET
);
}
function _getPositionBorrowSharesAave(
uint256 _nftId
)
internal
virtual
view
returns (uint256)
{
return WISE_LENDING.getPositionBorrowShares(
_nftId,
POOL_ASSET_AAVE
);
}
function _getPositionBorrowTokenAmount(
uint256 _nftId
)
internal
virtual
view
returns (uint256 tokenAmount)
{
uint256 positionBorrowShares = _getPositionBorrowShares(
_nftId
);
if (positionBorrowShares > 0) {
tokenAmount = _getPaybackAmount(
FARM_ASSET,
positionBorrowShares
);
}
}
function _getPaybackAmount(
address _poolToken,
uint256 _borrowShares
)
internal
virtual
view
returns (uint256 tokenAmount)
{
return WISE_LENDING.paybackAmount(
_poolToken,
_borrowShares
);
}
function _getPositionBorrowTokenAmountAave(
uint256 _nftId
)
internal
virtual
view
returns (uint256 tokenAmountAave)
{
uint256 positionBorrowSharesAave = _getPositionBorrowSharesAave(
_nftId
);
if (positionBorrowSharesAave == 0) {
return 0;
}
tokenAmountAave = _getPaybackAmount(
POOL_ASSET_AAVE,
positionBorrowSharesAave
);
}
function _getPositionLendingShares(
uint256 _nftId
)
internal
virtual
view
returns (uint256)
{
return WISE_LENDING.getPositionLendingShares(
_nftId,
PENDLE_CHILD
);
}
function _getPostionCollateralTokenAmount(
uint256 _nftId
)
internal
virtual
view
returns (uint256)
{
return _getCashoutAmount(
{
_poolToken: PENDLE_CHILD,
_shares: _getPositionLendingShares(
_nftId
)
}
);
}
function getPositionBorrowETH(
uint256 _nftId
)
public
virtual
view
returns (uint256)
{
uint256 borrowTokenAmount;
uint256 borrowShares = _getPositionBorrowShares(
_nftId
);
if (borrowShares > 0) {
borrowTokenAmount = _getPositionBorrowTokenAmount(
_nftId
);
}
uint256 borrowSharesAave = _getPositionBorrowSharesAave(
_nftId
);
uint256 borrowTokenAmountAave;
if (borrowSharesAave > 0) {
borrowTokenAmountAave = _getPositionBorrowTokenAmountAave(
_nftId
);
}
uint256 tokenValueEth;
if (borrowShares > 0) {
tokenValueEth = _getTokensInETH(
FARM_ASSET,
borrowTokenAmount
);
}
if (borrowTokenAmountAave == 0) {
return tokenValueEth;
}
uint256 tokenValueAaveEth = _getTokensInETH(
POOL_ASSET_AAVE,
borrowTokenAmountAave
);
return tokenValueEth + tokenValueAaveEth;
}
function getTotalWeightedCollateralETH(
uint256 _nftId
)
public
virtual
view
returns (uint256)
{
return _getTokensInETH(
PENDLE_CHILD,
_getPostionCollateralTokenAmount(_nftId)
)
* collateralFactor
/ PRECISION_FACTOR_E18;
}
function _getTokensInETH(
address _tokenAddress,
uint256 _tokenAmount
)
internal
virtual
view
returns (uint256)
{
return ORACLE_HUB.getTokensInETH(
_tokenAddress,
_tokenAmount
);
}
function _getEthInTokens(
address _tokenAddress,
uint256 _ethAmount
)
internal
virtual
view
returns (uint256)
{
return ORACLE_HUB.getTokensFromETH(
_tokenAddress,
_ethAmount
);
}
function getLeverageAmount(
uint256 _initialAmount,
uint256 _leverage
)
public
pure
virtual
returns (uint256)
{
return _initialAmount
* _leverage
/ PRECISION_FACTOR_E18;
}
function _getApproxNetAPY(
uint256 _initialAmount,
uint256 _leverage,
uint256 _wstETHAPY,
bool _isAave
)
internal
virtual
view
returns (
uint256,
bool
)
{
if (_leverage < PRECISION_FACTOR_E18) {
return (
0,
false
);
}
uint256 leveragedAmount = getLeverageAmount(
_initialAmount,
_leverage
);
uint256 flashloanAmount = leveragedAmount
- _initialAmount;
uint256 newBorrowRate = _getNewBorrowRate(
flashloanAmount,
_isAave
);
uint256 leveragedPositivAPY = _wstETHAPY
* _leverage
/ PRECISION_FACTOR_E18;
uint256 leveragedNegativeAPY = newBorrowRate
* (_leverage - PRECISION_FACTOR_E18)
/ PRECISION_FACTOR_E18;
bool isPositive = leveragedPositivAPY >= leveragedNegativeAPY;
uint256 netAPY = isPositive == true
? leveragedPositivAPY - leveragedNegativeAPY
: leveragedNegativeAPY - leveragedPositivAPY;
return (
netAPY,
isPositive
);
}
function _isOutOfRangeAmount(
uint256 _lpWithdrawAmount
)
internal
virtual
view
returns (bool)
{
MarketState memory marketState = PENDLE_MARKET.readState(
address(PENDLE_MARKET)
);
(
,
uint256 userSy,
uint256 userPt
)
= _getUserAssetInfo(
_lpWithdrawAmount,
uint256(marketState.totalLp),
uint256(marketState.totalSy),
uint256(marketState.totalPt)
);
uint256 reducedSy = uint256(marketState.totalSy)
- userSy
- (
PT_ORACLE_PENDLE.getPtToSyRate(
address(PENDLE_MARKET),
1 seconds
)
* userPt
/ PRECISION_FACTOR_E18
);
uint256 totalAssetsReduced = (
PENDLE_SY.exchangeRate()
* reducedSy
/ PRECISION_FACTOR_E18
+ uint256(marketState.totalPt)
);
return uint256(marketState.totalPt)
* PRECISION_FACTOR_E18
/ totalAssetsReduced
> MAX_PROPORTION;
}
function _checkSelector(
bytes memory _callData
)
internal
pure
returns (bytes4 selector)
{
assembly {
selector := mload(add(_callData, 32))
}
}
function _getSlicedData(
bytes memory _callData
)
internal
pure
virtual
returns (bytes memory adjustedData)
{
adjustedData = new bytes(
_callData.length - 4
);
for (uint i = 0; i < adjustedData.length; i++) {
adjustedData[i] = _callData[i + 4];
}
}
function _decodeRemoveLiquidity(
bytes memory _callData
)
internal
pure
returns (
address receiver,
address market,
uint256 netLpToRemove,
TokenOutput memory output,
LimitOrderData memory limit
)
{
bytes memory adjustedData = _getSlicedData(
_callData
);
(
receiver,
market,
netLpToRemove,
output,
limit
) = abi.decode(
adjustedData,
(
address,
address,
uint256,
TokenOutput,
LimitOrderData
)
);
}
function _decodeAddLiquidity(
bytes memory _callData
)
internal
pure
returns (
address receiver,
address market,
uint256 minLpOut,
ApproxParams memory guessPtReceivedFromSy,
TokenInput memory input,
LimitOrderData memory limit
)
{
bytes memory adjustedData = _getSlicedData(
_callData
);
(
receiver,
market,
minLpOut,
guessPtReceivedFromSy,
input,
limit
) = abi.decode(
adjustedData,
(
address,
address,
uint256,
ApproxParams,
TokenInput,
LimitOrderData
)
);
}
function _verifyCallData(
bytes memory _callData,
bool _addLiquidity
)
internal
virtual
{
bytes4 expectedSelector = _addLiquidity == true
? PENDLE_ROUTER.addLiquiditySingleToken.selector
: PENDLE_ROUTER.removeLiquiditySingleToken.selector;
bool verified = _checkSelector(_callData) == expectedSelector;
if (verified == false) {
revert GenericInvalidSelector(
_checkSelector(_callData),
expectedSelector
);
}
if (_addLiquidity == true) {
(
address receiverAddLiq,
address marketAddLiq,
uint256 minLpOut,
ApproxParams memory guessPtReceivedFromSy,
TokenInput memory input,
LimitOrderData memory limitAddLiq
) = _decodeAddLiquidity(
_callData
);
_verifyDecodedAddLiquidity(
receiverAddLiq,
marketAddLiq,
minLpOut,
guessPtReceivedFromSy,
input,
limitAddLiq
);
return;
}
(
address receiver,
address market,
uint256 netLpToRemove,
TokenOutput memory output,
LimitOrderData memory limit
) = _decodeRemoveLiquidity(
_callData
);
_verifyDecodedRemoveLiquidity(
receiver,
market,
netLpToRemove,
output,
limit
);
}
function _verifyDecodedRemoveLiquidity(
address _receiver,
address _market,
uint256,
TokenOutput memory _output,
LimitOrderData memory _limit
)
internal
virtual
{
_verifyStandardData(
_receiver,
_market
);
_verifyContracts(
_output.pendleSwap,
_output.swapData.extRouter,
_limit.limitRouter
);
if (_output.tokenOut != FARM_ASSET) {
revert GenericWrongTokenOut(
_output.tokenOut,
FARM_ASSET
);
}
}
function _verifyDecodedAddLiquidity(
address _receiver,
address _market,
uint256,
ApproxParams memory,
TokenInput memory _input,
LimitOrderData memory _limit
)
internal
virtual
{
_verifyStandardData(
_receiver,
_market
);
_verifyContracts(
_input.pendleSwap,
_input.swapData.extRouter,
_limit.limitRouter
);
if (_input.tokenIn != FARM_ASSET) {
revert GenericWrongTokenIn(
_input.tokenIn,
FARM_ASSET
);
}
}
function _verifyLimitRouter(
address _limitRouter
)
internal
virtual
{
if (whiteListedExternalContracts[_limitRouter] == false) {
revert GenericWrongLimitRouter(
_limitRouter
);
}
}
function _verifyContracts(
address _pendleSwap,
address _extRouter,
address _limitRouter
)
internal
virtual
{
if (whiteListedExternalContracts[_pendleSwap] == false) {
revert GenericWrongPendleSwap(
_pendleSwap
);
}
if (_limitRouter > address(0)) {
_verifyLimitRouter(
_limitRouter
);
}
if (whiteListedExternalContracts[_extRouter] == false) {
revert GenericWrongExtRouter(
_extRouter
);
}
}
function _verifyStandardData(
address _receiver,
address _market
)
internal
virtual
{
if (_receiver != address(this)) {
revert GenericWrongReceiver(
_receiver,
address(this)
);
}
if (_market != address(PENDLE_MARKET)) {
revert GenericWrongMarket(
_market,
address(PENDLE_MARKET)
);
}
}
function _isOutOfRange(
uint256 _nftId
)
internal
virtual
view
returns (bool)
{
return _isOutOfRangeAmount(
IPendleChild(PENDLE_CHILD).previewAmountWithdrawShares(
_getCashoutAmount(
PENDLE_CHILD,
_getPositionLendingShares(
_nftId
)
),
IPendleChild(PENDLE_CHILD).underlyingLpAssetsCurrent()
)
);
}
function _getCashoutAmount(
address _poolToken,
uint256 _shares
)
internal
virtual
view
returns (uint256)
{
return WISE_LENDING.cashoutAmount(
_poolToken,
_shares
);
}
function _getUserAssetInfo(
uint256 _lpToWithdraw,
uint256 _totalLp,
uint256 _totalSy,
uint256 _totalPt
)
internal
virtual
view
returns (
uint256,
uint256,
uint256
)
{
uint256 userProportion = _lpToWithdraw
* PRECISION_FACTOR_E18
/ _totalLp;
return (
userProportion,
userProportion
* _totalSy
/ PRECISION_FACTOR_E18,
userProportion
* _totalPt
/ PRECISION_FACTOR_E18
);
}
function _getNewBorrowRate(
uint256 _borrowAmount,
bool _isAave
)
internal
virtual
view
returns (uint256)
{
address relevantAssetAddress = _isAave == true
? POOL_ASSET_AAVE
: FARM_ASSET;
uint256 totalPool = WISE_LENDING.getTotalPool(
relevantAssetAddress
);
uint256 pseudoPool = WISE_LENDING.getPseudoTotalPool(
relevantAssetAddress
);
if (totalPool > pseudoPool) {
return 0;
}
uint256 newUtilization = PRECISION_FACTOR_E18 - (PRECISION_FACTOR_E18
* (totalPool - _borrowAmount)
/ pseudoPool
);
uint256 pole = _getBorrowRatesData(
relevantAssetAddress
).pole;
uint256 mulFactor = _getBorrowRatesData(
relevantAssetAddress
).multiplicativeFactor;
uint256 baseDivider = pole
* (pole - newUtilization);
return mulFactor
* PRECISION_FACTOR_E18
* newUtilization
/ baseDivider;
}
function _getBorrowRatesData(
address _poolToken
)
internal
virtual
view
returns (BorrowRatesEntry memory)
{
return WISE_LENDING.borrowRatesData(
_poolToken
);
}
function _checkDebtRatio(
uint256 _nftId
)
internal
virtual
view
returns (bool)
{
uint256 borrowShares = isAave[_nftId]
? _getPositionBorrowSharesAave(
_nftId
)
: _getPositionBorrowShares(
_nftId
);
if (borrowShares == 0) {
return true;
}
return getTotalWeightedCollateralETH(_nftId)
>= getPositionBorrowETH(_nftId);
}
function _notBelowMinDepositAmount(
uint256 _amount
)
internal
virtual
view
returns (bool)
{
uint256 equivETH = _getTokensInETH(
ENTRY_ASSET,
_amount
);
return equivETH >= minDepositEthAmount;
}
}
文件 9 的 31:GenericPowerFarm.sol
pragma solidity =0.8.25;
import "./GenericLeverageLogic.sol";
abstract contract GenericPowerFarm is GenericLeverageLogic {
function getApproxNetAPY(
uint256 _initialAmount,
uint256 _leverage,
uint256 _pendleChildApy,
bool _isAave
)
external
virtual
view
returns (
uint256,
bool
)
{
return _getApproxNetAPY(
_initialAmount,
_leverage,
_pendleChildApy,
_isAave
);
}
function getTokenAmountEquivalentInFarmAsset(
uint256 _nftId
)
public
virtual
view
returns (uint256)
{
uint256 collateralValueInEth = _getTokensInETH(
PENDLE_CHILD,
_getPostionCollateralTokenAmount(
_nftId
)
);
uint256 borrowValueInEth = getPositionBorrowETH(
_nftId
);
if (collateralValueInEth < borrowValueInEth) {
revert BadDebt(borrowValueInEth - collateralValueInEth);
}
return _getEthInTokens(
FARM_ASSET,
collateralValueInEth - borrowValueInEth
);
}
function getNewBorrowRate(
uint256 _borrowAmount,
bool _isAave
)
external
virtual
view
returns (uint256)
{
return _getNewBorrowRate(
_borrowAmount,
_isAave
);
}
function getLiveDebtRatio(
uint256 _nftId
)
external
virtual
view
returns (uint256)
{
uint256 borrowShares = isAave[_nftId]
? _getPositionBorrowSharesAave(
_nftId
)
: _getPositionBorrowShares(
_nftId
);
if (borrowShares == 0) {
return 0;
}
uint256 totalCollateral = getTotalWeightedCollateralETH(
_nftId
);
if (totalCollateral == 0) {
return 0;
}
return getPositionBorrowETH(_nftId)
* PRECISION_FACTOR_E18
/ totalCollateral;
}
function setCollateralFactor(
uint256 _newCollateralFactor
)
external
virtual
{}
function liquidatePartiallyFromToken(
uint256 _nftId,
uint256 _nftIdLiquidator,
uint256 _shareAmountToPay
)
external
virtual
routingOngoingCheck
updatePools
returns (
uint256 paybackAmount,
uint256 receivingAmount
)
{
return _coreLiquidation(
_nftId,
_nftIdLiquidator,
_shareAmountToPay
);
}
function _manuallyPaybackShares(
uint256 _nftId,
uint256 _paybackShares
)
internal
virtual
{
address poolAddress = FARM_ASSET;
if (isAave[_nftId] == true) {
poolAddress = POOL_ASSET_AAVE;
}
uint256 paybackAmount = WISE_LENDING.paybackAmount(
poolAddress,
_paybackShares
);
_safeTransferFrom(
poolAddress,
msg.sender,
address(this),
paybackAmount
);
WISE_LENDING.paybackExactShares(
_nftId,
poolAddress,
_paybackShares
);
}
function _manuallyWithdrawShares(
uint256 _nftId,
uint256 _withdrawShares
)
internal
virtual
{
uint256 withdrawAmount = _getCashoutAmount(
PENDLE_CHILD,
_withdrawShares
);
withdrawAmount = _withdrawExactShares(
_nftId,
PENDLE_CHILD,
_withdrawShares
);
_safeTransfer(
PENDLE_CHILD,
msg.sender,
withdrawAmount
);
}
function _openPosition(
bytes memory _callData,
bool _isAave,
uint256 _nftId,
uint256 _initialAmount,
uint256 _leverage,
uint256 _allowedSpread
)
internal
virtual
{
if (_leverage > MAX_LEVERAGE) {
revert GenericLevergeTooHigh();
}
uint256 leveragedAmount = getLeverageAmount(
_initialAmount,
_leverage
);
if (_notBelowMinDepositAmount(leveragedAmount) == false) {
revert GenericAmountTooSmall();
}
_executeBalancerFlashLoan({
_callData: _callData,
_nftId: _nftId,
_flashAmount: leveragedAmount - _initialAmount,
_initialAmount: _initialAmount,
_lendingShares: 0,
_borrowShares: 0,
_allowedSpread: _allowedSpread,
_ethBack: ethBack,
_isAave: _isAave
});
}
function _closingPosition(
bytes memory _callData,
bool _isAave,
uint256 _nftId,
uint256 _allowedSpread,
bool _ethBack
)
internal
virtual
{
uint256 borrowShares = _isAave == false
? _getPositionBorrowShares(
_nftId
)
: _getPositionBorrowSharesAave(
_nftId
);
uint256 borrowTokenAmount = _isAave == false
? _getPositionBorrowTokenAmount(
_nftId
)
: _getPositionBorrowTokenAmountAave(
_nftId
);
_executeBalancerFlashLoan({
_callData: _callData,
_nftId: _nftId,
_flashAmount: borrowTokenAmount,
_initialAmount: 0,
_lendingShares: _getPositionLendingShares(
_nftId
),
_borrowShares: borrowShares,
_allowedSpread: _allowedSpread,
_ethBack: _ethBack,
_isAave: _isAave
});
}
function _registrationFarm(
uint256 _nftId
)
internal
virtual
{
WISE_LENDING.setRegistrationIsolationPool(
_nftId,
true
);
emit RegistrationFarm(
_nftId,
block.timestamp
);
}
}
文件 10 的 31:GenericPowerManager.sol
pragma solidity =0.8.25;
import "../OwnableMaster.sol";
import "./GenericPowerFarm.sol";
import "./PowerFarmNFTs/MinterReserver.sol";
contract GenericPowerManager is
OwnableMaster,
GenericPowerFarm,
MinterReserver
{
receive()
external
payable
virtual
{
emit ETHReceived(
msg.value,
msg.sender
);
if (msg.sender == WETH_ADDRESS) {
return;
}
if (sendingProgress == true) {
revert GenericSendingOnGoing();
}
_sendValue(
master,
msg.value
);
}
constructor(
address _wiseLendingAddress,
address _pendleChildTokenAddress,
address _pendleRouter,
address _entryAsset,
address _pendleSy,
address _underlyingMarket,
address _routerStatic,
address _dexAddress,
uint256 _collateralFactor,
address _powerFarmNFTs
)
OwnableMaster(msg.sender)
MinterReserver(_powerFarmNFTs)
GenericDeclarations(
_wiseLendingAddress,
_pendleChildTokenAddress,
_pendleRouter,
_entryAsset,
_pendleSy,
_underlyingMarket,
_routerStatic,
_dexAddress,
_collateralFactor
)
{}
function setSpecialDepegCase(
bool _state
)
external
virtual
onlyMaster
{
specialDepegCase = _state;
}
function revokeCollateralFactorRole()
public
virtual
onlyCollateralFactorRole
{
collateralFactorRole = ZERO_ADDRESS;
}
function setCollateralFactor(
uint256 _newCollateralFactor
)
external
override
onlyCollateralFactorRole()
{
collateralFactor = _newCollateralFactor;
}
function changeMinDeposit(
uint256 _newMinDeposit
)
external
virtual
onlyMaster
{
minDepositEthAmount = _newMinDeposit;
emit MinDepositChange(
_newMinDeposit,
block.timestamp
);
}
function shutDownFarm(
bool _state
)
external
virtual
onlyMaster
{
isShutdown = _state;
emit FarmStatus(
_state,
block.timestamp
);
}
function enterFarm(
bytes memory _callData,
bool _isAave,
uint256 _amount,
uint256 _leverage,
uint256 _allowedSpread
)
public
virtual
routingOngoingCheck
isActive
updatePools
returns (uint256)
{
_safeTransferFrom(
FARM_ASSET,
msg.sender,
address(this),
_amount
);
return _handleEnterFarm(
_callData,
_isAave,
_getWiseLendingNFT(),
_amount,
_leverage,
_allowedSpread
);
}
function _handleEnterFarm(
bytes memory _callData,
bool _isAave,
uint256 _wiseLendingNFT,
uint256 _amount,
uint256 _leverage,
uint256 _allowedSpread
)
private
returns (uint256)
{
_openPosition(
_callData,
_isAave,
_wiseLendingNFT,
_amount,
_leverage,
_allowedSpread
);
return _handleEntryFarmStorage(
_wiseLendingNFT,
_isAave,
_leverage,
_amount
);
}
function _handleEntryFarmStorage(
uint256 _wiseLendingNFT,
bool _isAave,
uint256 _leverage,
uint256 _amount
)
internal
returns (uint256)
{
uint256 keyId = _reserveKey(
msg.sender,
_wiseLendingNFT
);
isAave[_wiseLendingNFT] = _isAave;
_storeData(
keyId,
_wiseLendingNFT,
_leverage,
_amount,
getTokenAmountEquivalentInFarmAsset(_wiseLendingNFT),
block.timestamp
);
return keyId;
}
function _storeData(
uint256 _keyId,
uint256 _wiseLendingNFT,
uint256 _leverage,
uint256 _amount,
uint256 _amountAfterMintFee,
uint256 _timestamp
)
internal
virtual
{
FarmData memory FarmData = FarmData(
_wiseLendingNFT,
_leverage,
_amount,
_amountAfterMintFee,
_timestamp
);
farmData[_keyId] = FarmData;
emit FarmEntry(
_keyId,
_wiseLendingNFT,
_leverage,
_amount,
_amountAfterMintFee,
_timestamp
);
}
function enterFarmETH(
bytes memory _callData,
bool _isAave,
uint256 _leverage,
uint256 _allowedSpread
)
external
virtual
payable
routingOngoingCheck
isActive
updatePools
returns (uint256)
{
_wrapETH(
msg.value
);
return _handleEnterFarm(
_callData,
_isAave,
_getWiseLendingNFT(),
msg.value,
_leverage,
_allowedSpread
);
}
function _getWiseLendingNFT()
internal
virtual
returns (uint256)
{
if (availableNFTCount == 0) {
uint256 nftId = POSITION_NFT.mintPosition();
_registrationFarm(
nftId
);
POSITION_NFT.approve(
AAVE_HUB_ADDRESS,
nftId
);
return nftId;
}
return availableNFTs[
availableNFTCount--
];
}
function exitFarm(
bytes memory _callData,
uint256 _keyId,
uint256 _allowedSpread,
bool _ethBack
)
external
virtual
routingOngoingCheck
updatePools
onlyKeyOwner(_keyId)
{
uint256 wiseLendingNFT = farmingKeys[
_keyId
];
delete farmingKeys[
_keyId
];
if (reservedKeys[msg.sender] == _keyId) {
reservedKeys[msg.sender] = 0;
} else {
FARMS_NFTS.burnKey(
_keyId
);
}
availableNFTs[
++availableNFTCount
] = wiseLendingNFT;
_closingPosition(
_callData,
isAave[wiseLendingNFT],
wiseLendingNFT,
_allowedSpread,
_ethBack
);
emit FarmExit(
_keyId,
wiseLendingNFT,
_allowedSpread,
block.timestamp
);
}
function manuallyPaybackShares(
uint256 _keyId,
uint256 _paybackShares
)
external
virtual
routingOngoingCheck
updatePools
{
_manuallyPaybackShares(
farmingKeys[_keyId],
_paybackShares
);
emit ManualPaybackShares(
_keyId,
farmingKeys[_keyId],
_paybackShares,
block.timestamp
);
}
function changePendleRouter(
address _newPendleRouter,
address _newLimitRouter
)
external
virtual
onlyMaster
{
PENDLE_ROUTER = IPendleRouter(
_newPendleRouter
);
PENDLE_LIMIT_ROUTER_ADDRESS = _newLimitRouter;
_doApprovals(
address(WISE_LENDING)
);
}
function manuallyWithdrawShares(
uint256 _keyId,
uint256 _withdrawShares
)
external
virtual
routingOngoingCheck
updatePools
onlyKeyOwner(_keyId)
{
uint256 wiseLendingNFT = farmingKeys[
_keyId
];
_manuallyWithdrawShares(
wiseLendingNFT,
_withdrawShares
);
if (_checkDebtRatio(wiseLendingNFT) == false) {
revert GenericDebtRatioTooHigh();
}
emit ManualWithdrawShares(
_keyId,
wiseLendingNFT,
_withdrawShares,
block.timestamp
);
}
}
文件 11 的 31:IAave.sol
pragma solidity =0.8.25;
interface IAave {
struct ReserveData {
ReserveConfigurationMap configuration;
uint128 liquidityIndex;
uint128 currentLiquidityRate;
uint128 variableBorrowIndex;
uint128 currentVariableBorrowRate;
uint128 currentStableBorrowRate;
uint40 lastUpdateTimestamp;
uint16 id;
address aTokenAddress;
address stableDebtTokenAddress;
address variableDebtTokenAddress;
address interestRateStrategyAddress;
uint128 accruedToTreasury;
uint128 unbacked;
uint128 isolationModeTotalDebt;
}
struct ReserveConfigurationMap {
uint256 data;
}
function supply(
address _token,
uint256 _amount,
address _owner,
uint16 _referralCode
)
external;
function withdraw(
address _token,
uint256 _amount,
address _recipient
)
external
returns (uint256);
function getReserveData(
address asset
)
external
view
returns (ReserveData memory);
}
文件 12 的 31:IAaveHub.sol
pragma solidity =0.8.25;
interface IAaveHub {
function AAVE_ADDRESS()
external
view
returns (address);
function WETH_ADDRESS()
external
view
returns (address);
function aaveTokenAddress(
address _underlyingToken
)
external
view
returns (address);
function setAaveTokenAddress(
address _underlyingToken,
address _aaveToken
)
external;
function borrowExactAmount(
uint256 _nftId,
address _underlyingAsset,
uint256 _borrowAmount
)
external
returns (uint256);
function paybackExactShares(
uint256 _nftId,
address _underlyingAsset,
uint256 _shares
)
external
returns (uint256);
function paybackExactAmountETH(
uint256 _nftId
)
external
payable
returns (uint256);
function paybackExactAmount(
uint256 _nftId,
address _underlyingAsset,
uint256 _shares
)
external
returns (uint256);
function depositExactAmount(
uint256 _nftId,
address _underlyingAsset,
uint256 _amount
)
external
returns (uint256);
function depositExactAmountETH(
uint256 _nftId
)
external
payable
returns (uint256);
function depositExactAmountETHMint()
external
payable
returns (uint256);
function withdrawExactShares(
uint256 _nftId,
address _underlyingAsset,
uint256 _shares
)
external
returns (uint256);
function withdrawExactAmount(
uint256 _nftId,
address _token,
uint256 _amount
)
external
returns (uint256);
function sendingProgressAaveHub()
external
view
returns (bool);
function master()
external
view
returns (address);
}
文件 13 的 31:IBalancerFlashloan.sol
pragma solidity =0.8.25;
import "../InterfaceHub/IERC20.sol";
interface IBalancerVault {
function flashLoan(
IFlashLoanRecipient _recipient,
IERC20[] memory _tokens,
uint256[] memory _amounts,
bytes memory _userData
)
external;
}
interface IFlashLoanRecipient {
function receiveFlashLoan(
IERC20[] memory _tokens,
uint256[] memory _amounts,
uint256[] memory _feeAmounts,
bytes memory _userData
)
external;
}
文件 14 的 31:IERC20.sol
pragma solidity =0.8.25;
interface IERC20 {
function totalSupply()
external
view
returns (uint256);
function balanceOf(
address _account
)
external
view
returns (uint256);
function transferFrom(
address _sender,
address _recipient,
uint256 _amount
)
external
returns (bool);
function transfer(
address _recipient,
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 decimals()
external
view
returns (uint8);
event Transfer(
address indexed from,
address indexed to,
uint256 value
);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
event Deposit(
address indexed dst,
uint wad
);
event Withdrawal(
address indexed src,
uint wad
);
}
文件 15 的 31:IOraclePendle.sol
pragma solidity =0.8.25;
interface IOraclePendle {
function getOracleState(
address market,
uint32 duration
)
external
view
returns (
bool increaseCardinalityRequired,
uint16 cardinalityRequired,
bool oldestObservationSatisfied
);
function getPtToAssetRate(
address market,
uint32 duration
)
external
view
returns (uint256 ptToAssetRate);
function getPtToSyRate(
address market,
uint32 duration
)
external
view
returns (uint256 ptToSyRate);
}
文件 16 的 31:IPendle.sol
pragma solidity =0.8.25;
import {IERC20 as IERC20A} from "./IERC20.sol";
struct Order {
uint256 salt;
uint256 expiry;
uint256 nonce;
IPLimitOrderType.OrderType orderType;
address token;
address YT;
address maker;
address receiver;
uint256 makingAmount;
uint256 lnImpliedRate;
uint256 failSafeRate;
bytes permit;
}
struct FillOrderParams {
Order order;
bytes signature;
uint256 makingAmount;
}
struct TokenOutput {
address tokenOut;
uint256 minTokenOut;
address tokenRedeemSy;
address pendleSwap;
SwapData swapData;
}
struct LimitOrderData {
address limitRouter;
uint256 epsSkipMarket;
FillOrderParams[] normalFills;
FillOrderParams[] flashFills;
bytes optData;
}
struct TokenInput {
address tokenIn;
uint256 netTokenIn;
address tokenMintSy;
address pendleSwap;
SwapData swapData;
}
enum SwapType {
NONE,
KYBERSWAP,
ONE_INCH,
ETH_WETH
}
struct SwapData {
SwapType swapType;
address extRouter;
bytes extCalldata;
bool needScale;
}
struct MarketStorage {
int128 totalPt;
int128 totalSy;
uint96 lastLnImpliedRate;
uint16 observationIndex;
uint16 observationCardinality;
uint16 observationCardinalityNext;
}
struct FillResults {
uint256 totalMaking;
uint256 totalTaking;
uint256 totalFee;
uint256 totalNotionalVolume;
uint256[] netMakings;
uint256[] netTakings;
uint256[] netFees;
uint256[] notionalVolumes;
}
struct MarketState {
int256 totalPt;
int256 totalSy;
int256 totalLp;
address treasury;
int256 scalarRoot;
uint256 expiry;
uint256 lnFeeRateRoot;
uint256 reserveFeePercent;
uint256 lastLnImpliedRate;
}
struct LockedPosition {
uint128 amount;
uint128 expiry;
}
struct UserReward {
uint128 index;
uint128 accrued;
}
struct ApproxParams {
uint256 guessMin;
uint256 guessMax;
uint256 guessOffchain;
uint256 maxIteration;
uint256 eps;
}
interface IPendleSy {
function decimals()
external
view
returns (uint8);
function previewDeposit(
address _tokenIn,
uint256 _amountTokenToDeposit
)
external
view
returns (uint256 sharesAmount);
function deposit(
address _receiver,
address _tokenIn,
uint256 _amountTokenToDeposit,
uint256 _minSharesOut
)
external
returns (uint256 sharesAmount);
function exchangeRate()
external
view
returns (uint256);
function redeem(
address _receiver,
uint256 _amountSharesToRedeem,
address _tokenOut,
uint256 _minTokenOut,
bool _burnFromInternalBalance
)
external
returns (uint256 amountTokenOut);
}
interface IPendleYt {
function mintPY(
address _receiverPT,
address _receiverYT
)
external
returns (uint256 pyAmount);
function redeemPY(
address _receiver
)
external
returns (uint256);
function redeemDueInterestAndRewards(
address _user,
bool _redeemInterest,
bool _redeemRewards
)
external
returns (
uint256 interestOut,
uint256[] memory rewardsOut
);
function getRewardTokens()
external
view
returns (address[] memory);
function userReward(
address _token,
address _user
)
external
view
returns (UserReward memory);
function userInterest(
address user
)
external
view
returns (
uint128 lastPYIndex,
uint128 accruedInterest
);
function pyIndexStored()
external
view
returns (uint256);
}
interface IPendleMarket {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
)
external;
function readTokens()
external
view
returns (
address SY,
address PT,
address YT
);
function activeBalance(
address _user
)
external
view
returns (uint256);
function transferFrom(
address _from,
address _to,
uint256 _amount
)
external;
function balanceOf(
address _user
)
external
view
returns (uint256);
function isExpired()
external
view
returns (bool);
function decimals()
external
view
returns (uint8);
function increaseObservationsCardinalityNext(
uint16 _newObservationCardinalityNext
)
external;
function swapExactPtForSy(
address receiver,
uint256 exactPtIn,
bytes calldata data
)
external
returns (
uint256 netSyOut,
uint256 netSyFee
);
function _storage()
external
view
returns (MarketStorage memory);
function getRewardTokens()
external
view
returns (address[] memory);
function readState(
address _router
)
external
view
returns (MarketState memory marketState);
function mint(
address _receiver,
uint256 _netSyDesired,
uint256 _netPtDesired
)
external
returns (uint256[3] memory);
function burn(
address _receiverAddressSy,
address _receiverAddressPt,
uint256 _lpToBurn
)
external
returns (
uint256 syOut,
uint256 ptOut
);
function redeemRewards(
address _user
)
external
returns (uint256[] memory);
function totalSupply()
external
view
returns (uint256);
function userReward(
address _token,
address _user
)
external
view
returns (UserReward memory);
}
interface IPendleChild {
function underlyingLpAssetsCurrent()
external
view
returns (uint256);
function totalLpAssets()
external
view
returns (uint256);
function totalSupply()
external
view
returns (uint256);
function previewUnderlyingLpAssets()
external
view
returns (uint256);
function previewMintShares(
uint256 _underlyingAssetAmount,
uint256 _underlyingLpAssetsCurrent
)
external
view
returns (uint256);
function previewAmountWithdrawShares(
uint256 _shares,
uint256 _underlyingLpAssetsCurrent
)
external
view
returns (uint256);
function previewBurnShares(
uint256 _underlyingAssetAmount,
uint256 _underlyingLpAssetsCurrent
)
external
view
returns (uint256);
function depositExactAmount(
uint256 _amount
)
external
returns (
uint256,
uint256
);
function withdrawExactShares(
uint256 _shares
)
external
returns (uint256);
}
interface IPendleLock {
function increaseLockPosition(
uint128 _additionalAmountToLock,
uint128 _newExpiry
)
external
returns (uint128 newVeBalance);
function withdraw()
external
returns (uint128);
function positionData(
address _user
)
external
view
returns (LockedPosition memory);
function getBroadcastPositionFee(
uint256[] calldata _chainIds
)
external
view
returns (uint256);
}
interface IPendleVoteRewards {
function claimRetail(
address _user,
uint256 _amount,
bytes32[] calldata _merkleProof
)
external
returns (uint256);
}
interface IPendleVoter {
function vote(
address[] memory _pools,
uint64[] memory _weights
)
external;
}
interface IPLimitOrderType {
enum OrderType {
SY_FOR_PT,
PT_FOR_SY,
SY_FOR_YT,
YT_FOR_SY
}
struct StaticOrder {
uint256 salt;
uint256 expiry;
uint256 nonce;
OrderType orderType;
address token;
address YT;
address maker;
address receiver;
uint256 makingAmount;
uint256 lnImpliedRate;
uint256 failSafeRate;
}
}
interface IPendleRouter {
function removeLiquiditySingleToken(
address receiver,
address market,
uint256 netLpToRemove,
TokenOutput calldata output,
LimitOrderData calldata limit
)
external
returns (
uint256 netTokenOut,
uint256 netSyFee,
uint256 netSyInterm
);
function swapTokenToToken(
address receiver,
uint256 minTokenOut,
TokenInput memory inp
)
external
payable
returns (uint256 netTokenOut);
function addLiquiditySingleToken(
address receiver,
address market,
uint256 minLpOut,
ApproxParams memory guessPtReceivedFromSy,
TokenInput memory input,
LimitOrderData memory limit
)
external
payable
returns (
uint256 netLpOut,
uint256 netSyFee,
uint256 netSyInterm
);
function swapSyForExactYt(
address _receiver,
address _market,
uint256 _exactYtOut,
uint256 _maxSyIn
)
external
returns (
uint256 netSyIn,
uint256 netSyFee
);
function swapExactSyForYt(
address _receiver,
address _market,
uint256 _exactSyIn,
uint256 _minYtOut
)
external
returns (
uint256 netYtOut,
uint256 netSyFee
);
function swapSyForExactPt(
address _receiver,
address _market,
uint256 _exactPtOut,
uint256 _maxSyIn
)
external
returns (
uint256 netSyIn,
uint256 netSyFee
);
function swapExactSyForPt(
address _receiver,
address _market,
uint256 _exactSyIn,
uint256 _minPtOut
)
external
returns (
uint256 netPtOut,
uint256 netSyFee
);
function removeLiquiditySingleSy(
address _receiver,
address _market,
uint256 _netLpToRemove,
uint256 _minSyOut
)
external
returns (
uint256 netSyOut,
uint256 netSyFee
);
function addLiquiditySingleSy(
address _receiver,
address _market,
uint256 _netSyIn,
uint256 _minLpOut,
ApproxParams calldata _guessPtReceivedFromSy
)
external
returns (
uint256 netLpOut,
uint256 netSyFee
);
}
interface IPendleRouterStatic {
function addLiquiditySingleSyStatic(
address _market,
uint256 _netSyIn
)
external
view
returns (
uint256 netLpOut,
uint256 netPtFromSwap,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter,
uint256 netSyToSwap
);
function swapExactPtForSyStatic(
address _market,
uint256 _exactPtIn
)
external
view
returns (
uint256 netSyOut,
uint256 netSyFee,
uint256 priceImpact,
uint256 exchangeRateAfter
);
}
文件 17 的 31:IPositionNFTs.sol
pragma solidity =0.8.25;
interface IPositionNFTs {
function transferFrom(
address _from,
address _to,
uint256 _nftId
)
external;
function ownerOf(
uint256 _nftId
)
external
view
returns (address);
function totalSupply()
external
view
returns (uint256);
function reserved(
address _owner
)
external
view
returns (uint256);
function reservePosition()
external;
function mintPosition()
external
returns (uint256);
function tokenOfOwnerByIndex(
address _owner,
uint256 _index
)
external
view
returns (uint256);
function walletOfOwner(
address _owner
)
external
view
returns (uint256[] memory);
function mintPositionForUser(
address _user
)
external
returns (uint256);
function reservePositionForUser(
address _user
)
external
returns (uint256);
function getNextExpectedId()
external
view
returns (uint256);
function getApproved(
uint256 _nftId
)
external
view
returns (address);
function approve(
address _to,
uint256 _nftId
)
external;
function isOwner(
uint256 _nftId,
address _caller
)
external
view
returns (bool);
function FEE_MANAGER_NFT()
external
view
returns (uint256);
}
文件 18 的 31:IPowerFarmsNFTs.sol
pragma solidity =0.8.25;
interface IPowerFarmsNFTs {
function ownerOf(
uint256 _tokenId
)
external
view
returns (address);
function mintKey(
address _keyOwner,
uint256 _keyId
)
external;
function burnKey(
uint256 _keyId
)
external;
}
文件 19 的 31:IUniswapFactory.sol
pragma solidity =0.8.25;
interface IUniswapFactory {
function getPair(
address tokenA,
address tokenB
)
external
view
returns (address pair);
}
文件 20 的 31:IUniswapV2Pool.sol
pragma solidity =0.8.25;
interface IUniswapV2Pool {
function getReserves()
external
view
returns (
uint112 reserve0,
uint112 reserve1,
uint32 blockTimestampLast
);
function token0()
external
view
returns (address);
function token1()
external
view
returns (address);
function totalSupply()
external
view
returns (uint);
function balanceOf(address owner)
external
view
returns (uint);
function getAmountsOut(
uint amountIn,
address[] memory path
)
external
view
returns (uint[] memory amounts);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
returns (uint[] memory amounts);
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;
}
文件 21 的 31:IUniswapV3.sol
pragma solidity =0.8.25;
interface IUniswapV3SwapCallback {
function uniswapV3SwapCallback(
int256 _amount0Delta,
int256 _amount1Delta,
bytes calldata _data
)
external;
}
interface IUniswapV3 is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
function exactInputSingle(
ExactInputSingleParams calldata _params
)
external
payable
returns (uint256 amountOut);
function exactOutputSingle(
ExactOutputSingleParams calldata _params
)
external
payable
returns (uint256 amountIn);
}
文件 22 的 31:IUniswapV3PoolPowerFarm.sol
pragma solidity =0.8.25;
interface IUniswapV3PoolPowerFarm {
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
)
external;
function token0()
external
view
returns (address);
function token1()
external
view
returns (address);
}
文件 23 的 31:IWETH.sol
pragma solidity =0.8.25;
import "./IERC20.sol";
interface IWETH is IERC20 {
function deposit()
external
payable;
function withdraw(
uint256
)
external;
}
文件 24 的 31:IWiseLending.sol
pragma solidity =0.8.25;
struct GlobalPoolEntry {
uint256 totalPool;
uint256 utilization;
uint256 totalBareToken;
uint256 poolFee;
}
struct BorrowPoolEntry {
bool allowBorrow;
uint256 pseudoTotalBorrowAmount;
uint256 totalBorrowShares;
uint256 borrowRate;
}
struct LendingPoolEntry {
uint256 pseudoTotalPool;
uint256 totalDepositShares;
uint256 collateralFactor;
}
struct PoolEntry {
uint256 totalPool;
uint256 utilization;
uint256 totalBareToken;
uint256 poolFee;
}
struct BorrowRatesEntry {
uint256 pole;
uint256 deltaPole;
uint256 minPole;
uint256 maxPole;
uint256 multiplicativeFactor;
}
interface IWiseLending {
function borrowRatesData(
address _pooToken
)
external
view
returns (BorrowRatesEntry memory);
function newBorrowRate(
address _poolToken
)
external;
function calculateBorrowShares(
address _poolToken,
uint256 _amount,
bool _maxSharePrice
)
external
view
returns (uint256);
function borrowPoolData(
address _poolToken
)
external
view
returns (BorrowPoolEntry memory);
function lendingPoolData(
address _poolToken
)
external
view
returns (LendingPoolEntry memory);
function getPositionBorrowShares(
uint256 _nftId,
address _poolToken
)
external
view
returns (uint256);
function getTimeStamp(
address _poolToken
)
external
view
returns (uint256);
function getPureCollateralAmount(
uint256 _nftId,
address _poolToken
)
external
view
returns (uint256);
function isUncollateralized(
uint256 _nftId,
address _poolToken
)
external
view
returns (bool);
function verifiedIsolationPool(
address _poolAddress
)
external
view
returns (bool);
function positionLocked(
uint256 _nftId
)
external
view
returns (bool);
function getTotalBareToken(
address _poolToken
)
external
view
returns (uint256);
function maxDepositValueToken(
address _poolToken
)
external
view
returns (uint256);
function master()
external
view
returns (address);
function WETH_ADDRESS()
external
view
returns (address);
function WISE_ORACLE()
external
view
returns (address);
function POSITION_NFT()
external
view
returns (address);
function FEE_MANAGER()
external
view
returns (address);
function WISE_SECURITY()
external
view
returns (address);
function lastUpdated(
address _poolAddress
)
external
view
returns (uint256);
function isolationPoolRegistered(
uint256 _nftId,
address _isolationPool
)
external
view
returns (bool);
function calculateLendingShares(
address _poolToken,
uint256 _amount,
bool _maxSharePrice
)
external
view
returns (uint256);
function pureCollateralAmount(
uint256 _nftId,
address _poolToken
)
external
returns (uint256);
function getTotalPool(
address _poolToken
)
external
view
returns (uint256);
function depositExactAmount(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external
returns (uint256);
function withdrawOnBehalfExactAmount(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external
returns (uint256);
function syncManually(
address _poolToken
)
external;
function withdrawOnBehalfExactShares(
uint256 _nftId,
address _poolToken,
uint256 _shares
)
external
returns (uint256);
function borrowOnBehalfExactAmount(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external
returns (uint256);
function borrowExactAmount(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external
returns (uint256);
function paybackExactAmountETH(
uint256 _nftId
)
external
payable
returns (uint256);
function solelyDeposit(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external;
function paybackExactAmount(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external
returns (uint256);
function paybackExactShares(
uint256 _nftId,
address _poolToken,
uint256 _shares
)
external
returns (uint256);
function setPoolFee(
address _poolToken,
uint256 _newFee
)
external;
function getPositionLendingShares(
uint256 _nftId,
address _poolToken
)
external
view
returns (uint256);
function collateralizeDeposit(
uint256 _nftId,
address _poolToken
)
external;
function approve(
address _spender,
address _poolToken,
uint256 _amount
)
external;
function withdrawExactShares(
uint256 _nftId,
address _poolToken,
uint256 _shares
)
external
returns (uint256);
function withdrawExactAmount(
uint256 _nftId,
address _poolToken,
uint256 _amount
)
external
returns (uint256);
function poolTokenAddresses()
external
returns (address[] memory);
function corePaybackFeeManager(
address _poolToken,
uint256 _nftId,
uint256 _amount,
uint256 _shares
)
external;
function sendingProgress()
external
view
returns (bool);
function depositExactAmountETH(
uint256 _nftId
)
external
payable
returns (uint256);
function coreLiquidationIsolationPools(
uint256 _nftId,
uint256 _nftIdLiquidator,
address _caller,
address _tokenToPayback,
address _tokenToRecieve,
uint256 _paybackAmount,
uint256 _shareAmountToPay
)
external
returns (uint256 reveiveAmount);
function preparePool(
address _poolToken
)
external;
function getPositionBorrowTokenLength(
uint256 _nftId
)
external
view
returns (uint256);
function getPositionBorrowTokenByIndex(
uint256 _nftId,
uint256 _index
)
external
view
returns (address);
function getPositionLendingTokenByIndex(
uint256 _nftId,
uint256 _index
)
external
view
returns (address);
function getPositionLendingTokenLength(
uint256 _nftId
)
external
view
returns (uint256);
function globalPoolData(
address _poolToken
)
external
view
returns (GlobalPoolEntry memory);
function getGlobalBorrowAmount(
address _token
)
external
view
returns (uint256);
function getPseudoTotalBorrowAmount(
address _token
)
external
view
returns (uint256);
function getInitialBorrowAmountUser(
address _user,
address _token
)
external
view
returns (uint256);
function getPseudoTotalPool(
address _token
)
external
view
returns (uint256);
function getInitialDepositAmountUser(
address _user,
address _token
)
external
view
returns (uint256);
function getGlobalDepositAmount(
address _token
)
external
view
returns (uint256);
function paybackAmount(
address _token,
uint256 _shares
)
external
view
returns (uint256);
function getPositionLendingShares(
address _user,
address _token
)
external
view
returns (uint256);
function cashoutAmount(
address _poolToken,
uint256 _shares
)
external
view
returns (uint256);
function getTotalDepositShares(
address _token
)
external
view
returns (uint256);
function getTotalBorrowShares(
address _token
)
external
view
returns (uint256);
function checkPositionLocked(
uint256 _nftId,
address _caller
)
external
view;
function checkDeposit(
uint256 _nftId,
address _caller,
address _poolToken,
uint256 _amount
)
external
view;
function setRegistrationIsolationPool(
uint256 _nftId,
bool _state
)
external;
}
文件 25 的 31:IWiseOracleHub.sol
pragma solidity =0.8.25;
interface IWiseOracleHub {
function getTokensPriceFromUSD(
address _tokenAddress,
uint256 _usdValue
)
external
view
returns (uint256);
function getTokensPriceInUSD(
address _tokenAddress,
uint256 _tokenAmount
)
external
view
returns (uint256);
function latestResolver(
address _tokenAddress
)
external
view
returns (uint256);
function latestResolverTwap(
address _tokenAddress
)
external
view
returns (uint256);
function getTokensFromUSD(
address _tokenAddress,
uint256 _usdValue
)
external
view
returns (uint256);
function getTokensFromETH(
address _tokenAddress,
uint256 _ethValue
)
external
view
returns (uint256);
function getTokensInUSD(
address _tokenAddress,
uint256 _amount
)
external
view
returns (uint256);
function getTokensInETH(
address _tokenAddress,
uint256 _tokenAmount
)
external
view
returns (uint256);
function chainLinkIsDead(
address _tokenAddress
)
external
view
returns (bool);
function decimalsUSD()
external
pure
returns (uint8);
function addOracle(
address _tokenAddress,
address _priceFeedAddress,
address[] calldata _underlyingFeedTokens
)
external;
function recalibrate(
address _tokenAddress
)
external;
function WETH_ADDRESS()
external
view
returns (address);
function priceFeed(
address _tokenAddress
)
external
view
returns (address);
}
文件 26 的 31:IWiseSecurity.sol
pragma solidity =0.8.25;
struct CurveSwapStructToken {
uint256 curvePoolTokenIndexFrom;
uint256 curvePoolTokenIndexTo;
uint256 curveMetaPoolTokenIndexFrom;
uint256 curveMetaPoolTokenIndexTo;
}
struct CurveSwapStructData {
address curvePool;
address curveMetaPool;
bytes swapBytesPool;
bytes swapBytesMeta;
}
interface IWiseSecurity {
function checkMinDepositValue(
address _poolToken,
uint256 _amount
)
external
view
returns (bool);
function overallETHBorrow(
uint256 _nftId
)
external
view
returns (uint256 buffer);
function overallETHCollateralsBoth(
uint256 _nftId
)
external
view
returns (uint256 weighted, uint256 unweightedamount);
function getLiveDebtRatio(
uint256 _nftId
)
external
view
returns (uint256);
function checkHealthState(
uint256 _nftId,
bool _isPowerFarm
)
external
view;
function checkPoolCondition(
address _token
)
external
view;
function checkPoolWithMinDeposit(
address _poolToken,
uint256 _amount
)
external
view
returns (bool);
function overallETHBorrowHeartbeat(
uint256 _nftId
)
external
view
returns (uint256 buffer);
function checksLiquidation(
uint256 _nftIdLiquidate,
address _tokenToPayback,
uint256 _shareAmountToPay
)
external
view;
function getPositionLendingAmount(
uint256 _nftId,
address _poolToken
)
external
view
returns (uint256);
function getBorrowRate(
address _poolToken
)
external
view
returns (uint256);
function getPositionBorrowAmount(
uint256 _nftId,
address _poolToken
)
external
view
returns (uint256);
function overallUSDCollateralsBare(
uint256 _nftId
)
external
view
returns (uint256 amount);
function overallETHCollateralsBare(
uint256 _nftId
)
external
view
returns (uint256 amount);
function FEE_MANAGER()
external
view
returns (address);
function AAVE_HUB()
external
view
returns (address);
function curveSecurityCheck(
address _poolAddress
)
external;
function prepareCurvePools(
address _poolToken,
CurveSwapStructData calldata _curveSwapStructData,
CurveSwapStructToken calldata _curveSwapStructToken
)
external;
function overallETHBorrowBare(
uint256 _nftId
)
external
view
returns (uint256 amount);
function checksWithdraw(
uint256 _nftId,
address _caller,
address _poolToken
)
external
view
returns (bool);
function checksBorrow(
uint256 _nftId,
address _caller,
address _poolToken
)
external
view
returns (bool);
function checksSolelyWithdraw(
uint256 _nftId,
address _caller,
address _poolToken
)
external
view
returns (bool);
function checkOwnerPosition(
uint256 _nftId,
address _caller
)
external
view;
function checksCollateralizeDeposit(
uint256 _nftIdCaller,
address _caller,
address _poolAddress
)
external
view;
function calculateWishPercentage(
uint256 _nftId,
address _receiveToken,
uint256 _paybackETH,
uint256 _maxFeeETH,
uint256 _baseRewardLiquidation
)
external
view
returns (uint256);
function checkUncollateralizedDeposit(
uint256 _nftIdCaller,
address _poolToken
)
external
view;
function checkPositionLocked(
uint256 _nftId,
address _caller
)
external
view;
function maxFeeETH()
external
view
returns (uint256);
function maxFeeFarmETH()
external
view
returns (uint256);
function baseRewardLiquidation()
external
view
returns (uint256);
function baseRewardLiquidationFarm()
external
view
returns (uint256);
function checksRegister(
uint256 _nftId,
address _caller
)
external
view;
function getLendingRate(
address _poolToken
)
external
view
returns (uint256);
}
文件 27 的 31:MinterReserver.sol
pragma solidity =0.8.25;
import "../../InterfaceHub/IPowerFarmsNFTs.sol";
error InvalidKey();
error AlreadyReserved();
contract MinterReserver {
IPowerFarmsNFTs immutable FARMS_NFTS;
uint256 public totalMinted;
uint256 public totalReserved;
uint256 public availableNFTCount;
mapping(uint256 => uint256) public farmingKeys;
mapping(address => uint256) public reservedKeys;
mapping(uint256 => uint256) public availableNFTs;
modifier onlyKeyOwner(
uint256 _keyId
) {
_onlyKeyOwner(
_keyId
);
_;
}
function _onlyKeyOwner(
uint256 _keyId
)
private
view
{
require(
isOwner(
_keyId,
msg.sender
) == true
);
}
constructor(
address _powerFarmNFTs
) {
FARMS_NFTS = IPowerFarmsNFTs(
_powerFarmNFTs
);
}
function _incrementReserved()
internal
returns (uint256)
{
return ++totalReserved;
}
function _getNextReserveKey()
internal
returns (uint256)
{
return totalMinted + _incrementReserved();
}
function _reserveKey(
address _userAddress,
uint256 _wiseLendingNFT
)
internal
returns (uint256)
{
if (reservedKeys[_userAddress] > 0) {
revert AlreadyReserved();
}
uint256 keyId = _getNextReserveKey();
reservedKeys[_userAddress] = keyId;
farmingKeys[keyId] = _wiseLendingNFT;
return keyId;
}
function isOwner(
uint256 _keyId,
address _owner
)
public
view
returns (bool)
{
if (reservedKeys[_owner] == _keyId) {
return true;
}
if (FARMS_NFTS.ownerOf(_keyId) == _owner) {
return true;
}
return false;
}
function _mintKeyForUser(
uint256 _keyId,
address _userAddress
)
internal
returns (uint256)
{
if (_keyId == 0) {
revert InvalidKey();
}
delete reservedKeys[
_userAddress
];
FARMS_NFTS.mintKey(
_userAddress,
_keyId
);
totalMinted++;
totalReserved--;
return _keyId;
}
function mintReserved()
external
returns (uint256)
{
return _mintKeyForUser(
reservedKeys[
msg.sender
],
msg.sender
);
}
event ERC721Received(
address operator,
address from,
uint256 tokenId,
bytes _data
);
function onERC721Received(
address _operator,
address _from,
uint256 _tokenId,
bytes calldata _data
)
external
returns (bytes4)
{
emit ERC721Received(
_operator,
_from,
_tokenId,
_data
);
return this.onERC721Received.selector;
}
}
文件 28 的 31:OwnableMaster.sol
pragma solidity =0.8.25;
error NoValue();
error NotMaster();
error NotProposed();
contract OwnableMaster {
address public master;
address public proposedMaster;
address internal constant ZERO_ADDRESS = address(0x0);
modifier onlyProposed() {
_onlyProposed();
_;
}
function _onlyMaster()
private
view
{
if (msg.sender == master) {
return;
}
revert NotMaster();
}
modifier onlyMaster() {
_onlyMaster();
_;
}
function _onlyProposed()
private
view
{
if (msg.sender == proposedMaster) {
return;
}
revert NotProposed();
}
event MasterProposed(
address indexed proposer,
address indexed proposedMaster
);
event RenouncedOwnership(
address indexed previousMaster
);
constructor(
address _master
) {
if (_master == ZERO_ADDRESS) {
revert NoValue();
}
master = _master;
}
function proposeOwner(
address _proposedOwner
)
external
onlyMaster
{
if (_proposedOwner == ZERO_ADDRESS) {
revert NoValue();
}
proposedMaster = _proposedOwner;
emit MasterProposed(
msg.sender,
_proposedOwner
);
}
function claimOwnership()
external
onlyProposed
{
master = msg.sender;
}
function renounceOwnership()
external
onlyMaster
{
master = ZERO_ADDRESS;
proposedMaster = ZERO_ADDRESS;
emit RenouncedOwnership(
msg.sender
);
}
}
文件 29 的 31:SendValueHelper.sol
pragma solidity =0.8.25;
error AmountTooSmall();
error SendValueFailed();
contract SendValueHelper {
bool public sendingProgress;
function _sendValue(
address _recipient,
uint256 _amount
)
internal
{
if (address(this).balance < _amount) {
revert AmountTooSmall();
}
sendingProgress = true;
(
bool success
,
) = payable(_recipient).call{
value: _amount
}("");
sendingProgress = false;
if (success == false) {
revert SendValueFailed();
}
}
}
文件 30 的 31:TransferHelper.sol
pragma solidity =0.8.25;
import "./CallOptionalReturn.sol";
contract TransferHelper is CallOptionalReturn {
function _safeTransfer(
address _token,
address _to,
uint256 _value
)
internal
{
_callOptionalReturn(
_token,
abi.encodeWithSelector(
IERC20.transfer.selector,
_to,
_value
)
);
}
function _safeTransferFrom(
address _token,
address _from,
address _to,
uint256 _value
)
internal
{
_callOptionalReturn(
_token,
abi.encodeWithSelector(
IERC20.transferFrom.selector,
_from,
_to,
_value
)
);
}
}
文件 31 的 31:WrapperHelper.sol
pragma solidity =0.8.25;
import "../InterfaceHub/IWETH.sol";
contract WrapperHelper {
IWETH internal immutable WETH;
constructor(
address _wethAddress
)
{
WETH = IWETH(
_wethAddress
);
}
function _wrapETH(
uint256 _value
)
internal
{
WETH.deposit{
value: _value
}();
}
function _unwrapETH(
uint256 _value
)
internal
{
WETH.withdraw(
_value
);
}
}
{
"compilationTarget": {
"contracts/PowerFarms/PendlePowerFarm/Ethena/EthenaPowerFarmDai.sol": "EthenaApiRoutingDai"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 20
},
"remappings": [
":@balancer-labs/=node_modules/@balancer-labs/",
":@chainlink/contracts/=node_modules/@chainlink/contracts/",
":@ensdomains/=node_modules/@ensdomains/",
":@eth-optimism/=node_modules/@eth-optimism/",
":@openzeppelin/=node_modules/@openzeppelin/",
":@pendle/=node_modules/@pendle/",
":@pythnetwork/pyth-sdk-solidity/=node_modules/@pythnetwork/pyth-sdk-solidity/",
":@scroll-tech/=node_modules/@scroll-tech/",
":@uniswap/=node_modules/@uniswap/",
":base64-sol/=node_modules/base64-sol/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":eth-gas-reporter/=node_modules/eth-gas-reporter/",
":forge-std/=lib/forge-std/src/",
":hardhat/=node_modules/hardhat/"
]
}
[{"inputs":[{"internalType":"address","name":"_wiseLendingAddress","type":"address"},{"internalType":"address","name":"_pendleChildTokenAddress","type":"address"},{"internalType":"address","name":"_pendleRouter","type":"address"},{"internalType":"address","name":"_entryAsset","type":"address"},{"internalType":"address","name":"_pendleSy","type":"address"},{"internalType":"address","name":"_underlyingMarket","type":"address"},{"internalType":"address","name":"_routerStatic","type":"address"},{"internalType":"address","name":"_dexAddress","type":"address"},{"internalType":"uint256","name":"_collateralFactor","type":"uint256"},{"internalType":"address","name":"_powerFarmNFTs","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyReserved","type":"error"},{"inputs":[],"name":"AmountTooSmall","type":"error"},{"inputs":[],"name":"ApiRoutingCallFailed","type":"error"},{"inputs":[],"name":"ApiRoutingDebtRatioTooHigh","type":"error"},{"inputs":[],"name":"ApiRoutingTooMuchValueLost","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"BadDebt","type":"error"},{"inputs":[],"name":"GenericAccessDenied","type":"error"},{"inputs":[],"name":"GenericAmountTooSmall","type":"error"},{"inputs":[],"name":"GenericDeactivated","type":"error"},{"inputs":[],"name":"GenericDebtRatioTooHigh","type":"error"},{"inputs":[],"name":"GenericDebtRatioTooLow","type":"error"},{"inputs":[],"name":"GenericInvalidParam","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_unverifiedSelector","type":"bytes4"},{"internalType":"bytes4","name":"_expectedSelector","type":"bytes4"}],"name":"GenericInvalidSelector","type":"error"},{"inputs":[],"name":"GenericLevergeTooHigh","type":"error"},{"inputs":[],"name":"GenericNotBalancerVaultOrSelf","type":"error"},{"inputs":[],"name":"GenericNotSender","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"GenericNotV2Pair","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"GenericNotV3Pair","type":"error"},{"inputs":[],"name":"GenericRoutingOngoing","type":"error"},{"inputs":[],"name":"GenericSendingOnGoing","type":"error"},{"inputs":[],"name":"GenericTooManyShares","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedExtRouter","type":"address"}],"name":"GenericWrongExtRouter","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedLimitRouter","type":"address"}],"name":"GenericWrongLimitRouter","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedMarket","type":"address"},{"internalType":"address","name":"_expectedMarket","type":"address"}],"name":"GenericWrongMarket","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedPendleSwap","type":"address"}],"name":"GenericWrongPendleSwap","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedReceiver","type":"address"},{"internalType":"address","name":"_expectedReceiver","type":"address"}],"name":"GenericWrongReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedTokenIn","type":"address"},{"internalType":"address","name":"_expectedTokenIn","type":"address"}],"name":"GenericWrongTokenIn","type":"error"},{"inputs":[{"internalType":"address","name":"_unverifiedTokenOut","type":"address"},{"internalType":"address","name":"_expectedTokenOut","type":"address"}],"name":"GenericWrongTokenOut","type":"error"},{"inputs":[],"name":"InvalidKey","type":"error"},{"inputs":[],"name":"NoValue","type":"error"},{"inputs":[],"name":"NotMaster","type":"error"},{"inputs":[],"name":"NotProposed","type":"error"},{"inputs":[],"name":"SendValueFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ERC721Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"from","type":"address"}],"name":"ETHReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"keyId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"wiseLendingNFT","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"leverage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountAfterMintFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FarmEntry","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"keyId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"wiseLendingNFT","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FarmExit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"state","type":"bool"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FarmStatus","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"keyId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"wiseLendingNFT","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"ManualPaybackShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"keyId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"wiseLendingNFT","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"ManualWithdrawShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"proposer","type":"address"},{"indexed":true,"internalType":"address","name":"proposedMaster","type":"address"}],"name":"MasterProposed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minDepositEthAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"MinDepositChange","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"RegistrationFarm","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousMaster","type":"address"}],"name":"RenouncedOwnership","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_contract","type":"address"},{"indexed":false,"internalType":"bool","name":"_isWhiteListed","type":"bool"}],"name":"WhiteListedExternalContract","type":"event"},{"inputs":[],"name":"AAVE","outputs":[{"internalType":"contract IAave","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"AAVE_DAI_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"AAVE_DAI_ADDRESS_ETH_MAIN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"AAVE_HUB","outputs":[{"internalType":"contract IAaveHub","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BALANCER_VAULT","outputs":[{"internalType":"contract IBalancerVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DAI_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DAI_ADDRESS_ETH_MAIN","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ENTRY_ASSET","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FARM_ASSET","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ORACLE_HUB","outputs":[{"internalType":"contract IWiseOracleHub","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PENDLE_CHILD","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PENDLE_LIMIT_ROUTER_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PENDLE_MARKET","outputs":[{"internalType":"contract IPendleMarket","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PENDLE_ROUTER","outputs":[{"internalType":"contract IPendleRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PENDLE_ROUTER_STATIC","outputs":[{"internalType":"contract IPendleRouterStatic","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PENDLE_SY","outputs":[{"internalType":"contract IPendleSy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POOL_ASSET_AAVE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POSITION_NFT","outputs":[{"internalType":"contract IPositionNFTs","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PT_ORACLE_PENDLE","outputs":[{"internalType":"contract IOraclePendle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_FACTORY","outputs":[{"internalType":"contract IUniswapFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_FACTORY_V2_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_V2_POOL","outputs":[{"internalType":"contract IUniswapV2Pool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_V3_FEE","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_V3_POOL","outputs":[{"internalType":"contract IUniswapV3PoolPowerFarm","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_V3_ROUTER","outputs":[{"internalType":"contract IUniswapV3","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WISE_LENDING","outputs":[{"internalType":"contract IWiseLending","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WISE_SECURITY","outputs":[{"internalType":"contract IWiseSecurity","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountWithdrawn","type":"uint256"}],"name":"_calculateFlashLoanFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"allowEnter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"availableNFTCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"availableNFTs","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newMinDeposit","type":"uint256"}],"name":"changeMinDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newPendleRouter","type":"address"},{"internalType":"address","name":"_newLimitRouter","type":"address"}],"name":"changePendleRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newUniV3Pool","type":"address"}],"name":"changeUniV3Pool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateralFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"collateralFactorRole","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"doApprovals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_callData","type":"bytes"},{"internalType":"bool","name":"_isAave","type":"bool"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_leverage","type":"uint256"},{"internalType":"uint256","name":"_allowedSpread","type":"uint256"}],"name":"enterFarm","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_callData","type":"bytes"},{"internalType":"bool","name":"_isAave","type":"bool"},{"internalType":"uint256","name":"_leverage","type":"uint256"},{"internalType":"uint256","name":"_allowedSpread","type":"uint256"}],"name":"enterFarmETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"ethBack","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_callData","type":"bytes"},{"internalType":"uint256","name":"_keyId","type":"uint256"},{"internalType":"uint256","name":"_allowedSpread","type":"uint256"},{"internalType":"bool","name":"_ethBack","type":"bool"}],"name":"exitFarm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"farmData","outputs":[{"internalType":"uint256","name":"wiseLendingNFT","type":"uint256"},{"internalType":"uint256","name":"leverage","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"amountAfterMintFee","type":"uint256"},{"internalType":"uint256","name":"timestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"farmingKeys","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_initialAmount","type":"uint256"},{"internalType":"uint256","name":"_leverage","type":"uint256"},{"internalType":"uint256","name":"_pendleChildApy","type":"uint256"},{"internalType":"bool","name":"_isAave","type":"bool"}],"name":"getApproxNetAPY","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_initialAmount","type":"uint256"},{"internalType":"uint256","name":"_leverage","type":"uint256"}],"name":"getLeverageAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"getLiveDebtRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_borrowAmount","type":"uint256"},{"internalType":"bool","name":"_isAave","type":"bool"}],"name":"getNewBorrowRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"getPositionBorrowETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"getTokenAmountEquivalentInFarmAsset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"getTotalWeightedCollateralETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isAave","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_keyId","type":"uint256"},{"internalType":"address","name":"_owner","type":"address"}],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nftId","type":"uint256"},{"internalType":"uint256","name":"_nftIdLiquidator","type":"uint256"},{"internalType":"uint256","name":"_shareAmountToPay","type":"uint256"}],"name":"liquidatePartiallyFromToken","outputs":[{"internalType":"uint256","name":"paybackAmount","type":"uint256"},{"internalType":"uint256","name":"receivingAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_keyId","type":"uint256"},{"internalType":"uint256","name":"_paybackShares","type":"uint256"}],"name":"manuallyPaybackShares","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_keyId","type":"uint256"},{"internalType":"uint256","name":"_withdrawShares","type":"uint256"}],"name":"manuallyWithdrawShares","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minDepositEthAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintReserved","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"address","name":"_from","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_proposedOwner","type":"address"}],"name":"proposeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proposedMaster","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"_flashloanToken","type":"address[]"},{"internalType":"uint256[]","name":"_flashloanAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"_feeAmounts","type":"uint256[]"},{"internalType":"bytes","name":"_userData","type":"bytes"}],"name":"receiveFlashLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"reservedKeys","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"revokeCollateralFactorRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"routingOngoing","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sendingProgress","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newCollateralFactor","type":"uint256"}],"name":"setCollateralFactor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_state","type":"bool"}],"name":"setSpecialDepegCase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_whiteList","type":"address[]"},{"internalType":"bool[]","name":"_isWhiteListed","type":"bool[]"}],"name":"setWhiteListForContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_state","type":"bool"}],"name":"shutDownFarm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"specialDepegCase","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalMinted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalReserved","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV2Call","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee0","type":"uint256"},{"internalType":"uint256","name":"_fee1","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"uniswapV3FlashCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whiteListedExternalContracts","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]