├── .commitlintrc.js ├── .czrc ├── .editorconfig ├── .env.example ├── .eslintignore ├── .eslintrc.yaml ├── .gitattributes ├── .github └── workflows │ └── stale.yml ├── .gitignore ├── .lintstagedrc ├── .prettierignore ├── .prettierrc ├── .solcover.js ├── .solhint.json ├── .solhintignore ├── README.md ├── contracts ├── external │ └── ERC20.sol ├── protocols │ ├── arbitrum │ │ ├── aave_v3 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── compound_iii │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── sushiswap │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── uniswap │ │ │ ├── contracts │ │ │ │ ├── interfaces │ │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ │ ├── LICENSE │ │ │ │ │ └── pool │ │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ │ └── libraries │ │ │ │ │ ├── BitMath.sol │ │ │ │ │ ├── FixedPoint128.sol │ │ │ │ │ ├── FixedPoint96.sol │ │ │ │ │ ├── FullMath.sol │ │ │ │ │ ├── LICENSE_GPL │ │ │ │ │ ├── LICENSE_MIT │ │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ │ ├── LiquidityMath.sol │ │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ │ ├── PoolAddress.sol │ │ │ │ │ ├── PositionKey.sol │ │ │ │ │ ├── SafeCast.sol │ │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ │ ├── SwapMath.sol │ │ │ │ │ ├── Tick.sol │ │ │ │ │ ├── TickBitmap.sol │ │ │ │ │ ├── TickMath.sol │ │ │ │ │ ├── TransferHelper.sol │ │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ └── uniswapStaking │ │ │ ├── contracts │ │ │ ├── interfaces │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ ├── LICENSE │ │ │ │ └── pool │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ └── libraries │ │ │ │ ├── BitMath.sol │ │ │ │ ├── FixedPoint128.sol │ │ │ │ ├── FixedPoint96.sol │ │ │ │ ├── FullMath.sol │ │ │ │ ├── LICENSE_GPL │ │ │ │ ├── LICENSE_MIT │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ ├── LiquidityMath.sol │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ ├── PoolAddress.sol │ │ │ │ ├── PositionKey.sol │ │ │ │ ├── SafeCast.sol │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ ├── SwapMath.sol │ │ │ │ ├── Tick.sol │ │ │ │ ├── TickBitmap.sol │ │ │ │ ├── TickMath.sol │ │ │ │ ├── TransferHelper.sol │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ ├── avalanche │ │ ├── aave_v2 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── aave_v3 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── benqi │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ └── pangolin │ │ │ ├── exchange │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ ├── library.sol │ │ │ └── main.sol │ │ │ └── stake │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ ├── base │ │ ├── aave_v3 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── accounts │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── compound_iii │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── erc20 │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── erc4626 │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── metamorpho │ │ │ ├── interface.sol │ │ │ ├── interfaces │ │ │ │ ├── IERC20.sol │ │ │ │ ├── IIrm.sol │ │ │ │ ├── IMetaMorpho.sol │ │ │ │ ├── IMorpho.sol │ │ │ │ ├── IMorphoCallbacks.sol │ │ │ │ ├── IOracle.sol │ │ │ │ └── LICENSE │ │ │ ├── libraries │ │ │ │ ├── ConstantsLib.sol │ │ │ │ ├── ErrorsLib.sol │ │ │ │ ├── EventsLib.sol │ │ │ │ ├── LICENSE │ │ │ │ ├── MarketParamsLib.sol │ │ │ │ ├── MathLib.sol │ │ │ │ ├── SafeTransferLib.sol │ │ │ │ ├── SharesMathLib.sol │ │ │ │ ├── UtilsLib.sol │ │ │ │ └── periphery │ │ │ │ │ ├── MorphoBalancesLib.sol │ │ │ │ │ ├── MorphoLib.sol │ │ │ │ │ └── MorphoStorageLib.sol │ │ │ └── main.sol │ │ ├── morpho-blue │ │ │ ├── helpers.sol │ │ │ ├── interfaces │ │ │ │ ├── IERC20.sol │ │ │ │ ├── IIrm.sol │ │ │ │ ├── IMorpho.sol │ │ │ │ ├── IMorphoCallbacks.sol │ │ │ │ ├── IOracle.sol │ │ │ │ └── LICENSE │ │ │ ├── libraries │ │ │ │ ├── ConstantsLib.sol │ │ │ │ ├── ErrorsLib.sol │ │ │ │ ├── EventsLib.sol │ │ │ │ ├── LICENSE │ │ │ │ ├── MarketParamsLib.sol │ │ │ │ ├── MathLib.sol │ │ │ │ ├── SafeTransferLib.sol │ │ │ │ ├── SharesMathLib.sol │ │ │ │ ├── UtilsLib.sol │ │ │ │ └── periphery │ │ │ │ │ ├── MorphoBalancesLib.sol │ │ │ │ │ ├── MorphoLib.sol │ │ │ │ │ └── MorphoStorageLib.sol │ │ │ └── main.sol │ │ └── uniswap │ │ │ ├── contracts │ │ │ ├── interfaces │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ ├── LICENSE │ │ │ │ └── pool │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ └── libraries │ │ │ │ ├── BitMath.sol │ │ │ │ ├── FixedPoint128.sol │ │ │ │ ├── FixedPoint96.sol │ │ │ │ ├── FullMath.sol │ │ │ │ ├── LICENSE_GPL │ │ │ │ ├── LICENSE_MIT │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ ├── LiquidityMath.sol │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ ├── PoolAddress.sol │ │ │ │ ├── PositionKey.sol │ │ │ │ ├── SafeCast.sol │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ ├── SwapMath.sol │ │ │ │ ├── Tick.sol │ │ │ │ ├── TickBitmap.sol │ │ │ │ ├── TickMath.sol │ │ │ │ ├── TransferHelper.sol │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ ├── fantom │ │ ├── aave_v3 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── accounts │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ └── erc20 │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ ├── mainnet │ │ ├── aave_v2 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── aave_v3 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── aave_v3_lido │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── b.protocol │ │ │ ├── compound │ │ │ │ ├── helpers.sol │ │ │ │ ├── interfaces.sol │ │ │ │ └── main.sol │ │ │ └── maker │ │ │ │ ├── helpers.sol │ │ │ │ ├── interfaces.sol │ │ │ │ └── main.sol │ │ ├── compound │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── compound_iii │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── crvusd │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── erc20 │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── erc4626 │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── euler │ │ │ ├── helpers.sol │ │ │ ├── interface.sol │ │ │ └── main.sol │ │ ├── liquity │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── maker │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── metamorpho │ │ │ ├── interface.sol │ │ │ ├── interfaces │ │ │ │ ├── IERC20.sol │ │ │ │ ├── IIrm.sol │ │ │ │ ├── IMetaMorpho.sol │ │ │ │ ├── IMorpho.sol │ │ │ │ ├── IMorphoCallbacks.sol │ │ │ │ ├── IOracle.sol │ │ │ │ └── LICENSE │ │ │ ├── libraries │ │ │ │ ├── ConstantsLib.sol │ │ │ │ ├── ErrorsLib.sol │ │ │ │ ├── EventsLib.sol │ │ │ │ ├── LICENSE │ │ │ │ ├── MarketParamsLib.sol │ │ │ │ ├── MathLib.sol │ │ │ │ ├── SafeTransferLib.sol │ │ │ │ ├── SharesMathLib.sol │ │ │ │ ├── UtilsLib.sol │ │ │ │ └── periphery │ │ │ │ │ ├── MorphoBalancesLib.sol │ │ │ │ │ ├── MorphoLib.sol │ │ │ │ │ └── MorphoStorageLib.sol │ │ │ └── main.sol │ │ ├── morpho-blue │ │ │ ├── helpers.sol │ │ │ ├── interfaces │ │ │ │ ├── IERC20.sol │ │ │ │ ├── IIrm.sol │ │ │ │ ├── IMorpho.sol │ │ │ │ ├── IMorphoCallbacks.sol │ │ │ │ ├── IOracle.sol │ │ │ │ └── LICENSE │ │ │ ├── libraries │ │ │ │ ├── ConstantsLib.sol │ │ │ │ ├── ErrorsLib.sol │ │ │ │ ├── EventsLib.sol │ │ │ │ ├── LICENSE │ │ │ │ ├── MarketParamsLib.sol │ │ │ │ ├── MathLib.sol │ │ │ │ ├── SafeTransferLib.sol │ │ │ │ ├── SharesMathLib.sol │ │ │ │ ├── UtilsLib.sol │ │ │ │ └── periphery │ │ │ │ │ ├── MorphoBalancesLib.sol │ │ │ │ │ ├── MorphoLib.sol │ │ │ │ │ └── MorphoStorageLib.sol │ │ │ └── main.sol │ │ ├── morpho │ │ │ ├── aave_v2 │ │ │ │ ├── helpers.sol │ │ │ │ ├── interfaces.sol │ │ │ │ └── main.sol │ │ │ ├── aave_v3 │ │ │ │ ├── helpers.sol │ │ │ │ ├── interfaces.sol │ │ │ │ ├── library │ │ │ │ │ ├── MarketLib.sol │ │ │ │ │ ├── Types.sol │ │ │ │ │ ├── Utils.sol │ │ │ │ │ ├── aave-v3-core │ │ │ │ │ │ ├── IERC20.sol │ │ │ │ │ │ ├── interfaces │ │ │ │ │ │ │ ├── IACLManager.sol │ │ │ │ │ │ │ ├── IAToken.sol │ │ │ │ │ │ │ ├── IAaveIncentivesController.sol │ │ │ │ │ │ │ ├── IAaveOracle.sol │ │ │ │ │ │ │ ├── ICreditDelegationToken.sol │ │ │ │ │ │ │ ├── IDefaultInterestRateStrategy.sol │ │ │ │ │ │ │ ├── IDelegationToken.sol │ │ │ │ │ │ │ ├── IERC20WithPermit.sol │ │ │ │ │ │ │ ├── IInitializableAToken.sol │ │ │ │ │ │ │ ├── IInitializableDebtToken.sol │ │ │ │ │ │ │ ├── IL2Pool.sol │ │ │ │ │ │ │ ├── IPool.sol │ │ │ │ │ │ │ ├── IPoolAddressesProvider.sol │ │ │ │ │ │ │ ├── IPoolAddressesProviderRegistry.sol │ │ │ │ │ │ │ ├── IPoolConfigurator.sol │ │ │ │ │ │ │ ├── IPoolDataProvider.sol │ │ │ │ │ │ │ ├── IPriceOracle.sol │ │ │ │ │ │ │ ├── IPriceOracleGetter.sol │ │ │ │ │ │ │ ├── IPriceOracleSentinel.sol │ │ │ │ │ │ │ ├── IReserveInterestRateStrategy.sol │ │ │ │ │ │ │ ├── IScaledBalanceToken.sol │ │ │ │ │ │ │ ├── ISequencerOracle.sol │ │ │ │ │ │ │ ├── IStableDebtToken.sol │ │ │ │ │ │ │ └── IVariableDebtToken.sol │ │ │ │ │ │ └── protocol │ │ │ │ │ │ │ └── libraries │ │ │ │ │ │ │ ├── configration │ │ │ │ │ │ │ └── ReserveConfiguration.sol │ │ │ │ │ │ │ ├── helpers │ │ │ │ │ │ │ └── Errors.sol │ │ │ │ │ │ │ └── types │ │ │ │ │ │ │ ├── ConfiguratorInputTypes.sol │ │ │ │ │ │ │ └── DataTypes.sol │ │ │ │ │ └── math │ │ │ │ │ │ ├── CompoundMath.sol │ │ │ │ │ │ ├── Math.sol │ │ │ │ │ │ ├── PercentageMath.sol │ │ │ │ │ │ └── WadRayMath.sol │ │ │ │ └── main.sol │ │ │ └── compound_v2 │ │ │ │ ├── helpers.sol │ │ │ │ ├── interfaces.sol │ │ │ │ └── main.sol │ │ ├── spark │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── sushiswap │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── ubiquity │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ ├── interfaces │ │ │ │ ├── IERC1155.sol │ │ │ │ ├── IERC165.sol │ │ │ │ └── IERC20.sol │ │ │ └── main.sol │ │ ├── uniswap │ │ │ ├── contracts │ │ │ │ ├── interfaces │ │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ │ ├── LICENSE │ │ │ │ │ └── pool │ │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ │ └── libraries │ │ │ │ │ ├── BitMath.sol │ │ │ │ │ ├── FixedPoint128.sol │ │ │ │ │ ├── FixedPoint96.sol │ │ │ │ │ ├── FullMath.sol │ │ │ │ │ ├── LICENSE_GPL │ │ │ │ │ ├── LICENSE_MIT │ │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ │ ├── LiquidityMath.sol │ │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ │ ├── PoolAddress.sol │ │ │ │ │ ├── PositionKey.sol │ │ │ │ │ ├── SafeCast.sol │ │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ │ ├── SwapMath.sol │ │ │ │ │ ├── Tick.sol │ │ │ │ │ ├── TickBitmap.sol │ │ │ │ │ ├── TickMath.sol │ │ │ │ │ ├── TransferHelper.sol │ │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── uniswapStaking │ │ │ ├── contracts │ │ │ │ ├── interfaces │ │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ │ ├── LICENSE │ │ │ │ │ └── pool │ │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ │ └── libraries │ │ │ │ │ ├── BitMath.sol │ │ │ │ │ ├── FixedPoint128.sol │ │ │ │ │ ├── FixedPoint96.sol │ │ │ │ │ ├── FullMath.sol │ │ │ │ │ ├── LICENSE_GPL │ │ │ │ │ ├── LICENSE_MIT │ │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ │ ├── LiquidityMath.sol │ │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ │ ├── PoolAddress.sol │ │ │ │ │ ├── PositionKey.sol │ │ │ │ │ ├── SafeCast.sol │ │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ │ ├── SwapMath.sol │ │ │ │ │ ├── Tick.sol │ │ │ │ │ ├── TickBitmap.sol │ │ │ │ │ ├── TickMath.sol │ │ │ │ │ ├── TransferHelper.sol │ │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── universeFinance │ │ │ ├── helpers.sol │ │ │ ├── interface.sol │ │ │ └── main.sol │ │ └── yearn_v2 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ ├── optimism │ │ ├── aave_v3 │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── accounts │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── compound_iii │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── erc20 │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ ├── uniswap │ │ │ ├── contracts │ │ │ │ ├── interfaces │ │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ │ ├── LICENSE │ │ │ │ │ └── pool │ │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ │ └── libraries │ │ │ │ │ ├── BitMath.sol │ │ │ │ │ ├── FixedPoint128.sol │ │ │ │ │ ├── FixedPoint96.sol │ │ │ │ │ ├── FullMath.sol │ │ │ │ │ ├── LICENSE_GPL │ │ │ │ │ ├── LICENSE_MIT │ │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ │ ├── LiquidityMath.sol │ │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ │ ├── PoolAddress.sol │ │ │ │ │ ├── PositionKey.sol │ │ │ │ │ ├── SafeCast.sol │ │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ │ ├── SwapMath.sol │ │ │ │ │ ├── Tick.sol │ │ │ │ │ ├── TickBitmap.sol │ │ │ │ │ ├── TickMath.sol │ │ │ │ │ ├── TransferHelper.sol │ │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ │ └── uniswapStaking │ │ │ ├── contracts │ │ │ ├── interfaces │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ ├── LICENSE │ │ │ │ └── pool │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ └── libraries │ │ │ │ ├── BitMath.sol │ │ │ │ ├── FixedPoint128.sol │ │ │ │ ├── FixedPoint96.sol │ │ │ │ ├── FullMath.sol │ │ │ │ ├── LICENSE_GPL │ │ │ │ ├── LICENSE_MIT │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ ├── LiquidityMath.sol │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ ├── PoolAddress.sol │ │ │ │ ├── PositionKey.sol │ │ │ │ ├── SafeCast.sol │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ ├── SwapMath.sol │ │ │ │ ├── Tick.sol │ │ │ │ ├── TickBitmap.sol │ │ │ │ ├── TickMath.sol │ │ │ │ ├── TransferHelper.sol │ │ │ │ └── UnsafeMath.sol │ │ │ ├── helpers.sol │ │ │ ├── interfaces.sol │ │ │ └── main.sol │ └── polygon │ │ ├── aave_v2 │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol │ │ ├── aave_v3 │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol │ │ ├── compound_iii │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol │ │ ├── erc4626 │ │ ├── interfaces.sol │ │ └── main.sol │ │ ├── quickswap │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol │ │ ├── sushiswap │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol │ │ ├── uniswap │ │ ├── contracts │ │ │ ├── interfaces │ │ │ │ ├── IERC20Minimal.sol │ │ │ │ ├── IUniswapV3Pool.sol │ │ │ │ ├── LICENSE │ │ │ │ └── pool │ │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ │ └── IUniswapV3PoolState.sol │ │ │ └── libraries │ │ │ │ ├── BitMath.sol │ │ │ │ ├── FixedPoint128.sol │ │ │ │ ├── FixedPoint96.sol │ │ │ │ ├── FullMath.sol │ │ │ │ ├── LICENSE_GPL │ │ │ │ ├── LICENSE_MIT │ │ │ │ ├── LiquidityAmounts.sol │ │ │ │ ├── LiquidityMath.sol │ │ │ │ ├── LowGasSafeMath.sol │ │ │ │ ├── PoolAddress.sol │ │ │ │ ├── PositionKey.sol │ │ │ │ ├── SafeCast.sol │ │ │ │ ├── SqrtPriceMath.sol │ │ │ │ ├── SwapMath.sol │ │ │ │ ├── Tick.sol │ │ │ │ ├── TickBitmap.sol │ │ │ │ ├── TickMath.sol │ │ │ │ ├── TransferHelper.sol │ │ │ │ └── UnsafeMath.sol │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol │ │ └── uniswapStaking │ │ ├── contracts │ │ ├── interfaces │ │ │ ├── IERC20Minimal.sol │ │ │ ├── IUniswapV3Pool.sol │ │ │ ├── LICENSE │ │ │ └── pool │ │ │ │ ├── IUniswapV3PoolActions.sol │ │ │ │ ├── IUniswapV3PoolDerivedState.sol │ │ │ │ ├── IUniswapV3PoolEvents.sol │ │ │ │ ├── IUniswapV3PoolImmutables.sol │ │ │ │ ├── IUniswapV3PoolOwnerActions.sol │ │ │ │ └── IUniswapV3PoolState.sol │ │ └── libraries │ │ │ ├── BitMath.sol │ │ │ ├── FixedPoint128.sol │ │ │ ├── FixedPoint96.sol │ │ │ ├── FullMath.sol │ │ │ ├── LICENSE_GPL │ │ │ ├── LICENSE_MIT │ │ │ ├── LiquidityAmounts.sol │ │ │ ├── LiquidityMath.sol │ │ │ ├── LowGasSafeMath.sol │ │ │ ├── PoolAddress.sol │ │ │ ├── PositionKey.sol │ │ │ ├── SafeCast.sol │ │ │ ├── SqrtPriceMath.sol │ │ │ ├── SwapMath.sol │ │ │ ├── Tick.sol │ │ │ ├── TickBitmap.sol │ │ │ ├── TickMath.sol │ │ │ ├── TransferHelper.sol │ │ │ └── UnsafeMath.sol │ │ ├── helpers.sol │ │ ├── interfaces.sol │ │ └── main.sol └── utils │ └── dsmath.sol ├── hardhat.config.ts ├── package-lock.json ├── package.json ├── scripts ├── addLiquidity.ts ├── command.ts ├── connectors.ts ├── deploy.ts ├── deployAll.ts ├── deployment │ ├── deploy.ts │ └── deployConnector.ts ├── getUsersToken.ts ├── global-test.ts ├── impersonate.ts └── run-tests.ts ├── tasks ├── accounts.ts ├── clean.ts └── task-names.ts ├── test ├── arbitrum │ ├── aave_v3.test.ts │ ├── compund.iii.test.ts │ ├── sushiswap.test.ts │ └── uniswap.test.ts ├── avalanche │ ├── aave_v2.test.ts │ ├── aave_v3.test.ts │ ├── pangolin.test.ts │ └── pangolin_stake.test.ts ├── consts.ts ├── fantom │ └── aave_v3.test.ts ├── mainnet │ ├── aave_v2.test.ts │ ├── aave_v3.test.ts │ ├── b.protocol │ │ ├── compound.test.ts │ │ └── maker.test.ts │ ├── compound.test.ts │ ├── compund.iii.test.ts │ ├── crv_usd.test.ts │ ├── erc20.test.ts │ ├── erc4626.test.ts │ ├── euler.test.ts │ ├── liquity.test.ts │ ├── maker.test.ts │ ├── metamorpho.ts │ ├── morpho-blue.test.ts │ ├── morpho-v3.test.ts │ ├── morpho.test.ts │ ├── spark.test.ts │ ├── sushiswap.test.ts │ ├── ubiquity.test.ts │ ├── uniswap.test.ts │ ├── uniswapStaking.test.ts │ ├── universe.test.ts │ └── yearnv2.test.ts ├── optimism │ └── aave_v3.test.ts ├── polygon │ ├── aave_v2.test.ts │ ├── aave_v3.test.ts │ ├── compund.iii.test.ts │ ├── quickwap.test.ts │ ├── sushiswap.test.ts │ └── uniswap_v3_staker.test.ts └── utils.ts ├── tsconfig.json ├── types ├── augmentations.d.ts └── index.ts └── yarn.lock /.commitlintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["@commitlint/config-conventional"], 3 | }; 4 | -------------------------------------------------------------------------------- /.czrc: -------------------------------------------------------------------------------- 1 | { 2 | "path": "cz-conventional-changelog" 3 | } 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # All files 7 | [*] 8 | charset = utf-8 9 | end_of_line = lf 10 | indent_size = 2 11 | indent_style = space 12 | insert_final_newline = true 13 | trim_trailing_whitespace = true 14 | 15 | [*.sol] 16 | indent_size = 4 17 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | ALCHEMY_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2 | MNEMONIC=here is where your twelve words mnemonic should be put my friend 3 | PRIVATE_KEY= 4 | networkType = 5 | POLYGON_API_KEY = 6 | SNOWTRACE_API_KEY = 7 | ARBISCAN_API_KEY = 8 | OPTIMISM_API_KEY = 9 | FANTOM_API_KEY = 10 | ETHERSCAN_API_KEY= 11 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # folders 2 | artifacts/ 3 | build/ 4 | cache/ 5 | coverage/ 6 | dist/ 7 | lib/ 8 | node_modules/ 9 | typechain/ 10 | 11 | # files 12 | .solcover.js 13 | coverage.json 14 | -------------------------------------------------------------------------------- /.eslintrc.yaml: -------------------------------------------------------------------------------- 1 | extends: 2 | - "eslint:recommended" 3 | - "plugin:@typescript-eslint/eslint-recommended" 4 | - "plugin:@typescript-eslint/recommended" 5 | - "prettier" 6 | parser: "@typescript-eslint/parser" 7 | parserOptions: 8 | project: "tsconfig.json" 9 | plugins: 10 | - "@typescript-eslint" 11 | root: true 12 | rules: 13 | "@typescript-eslint/no-floating-promises": 14 | - error 15 | - ignoreIIFE: true 16 | ignoreVoid: true 17 | "@typescript-eslint/no-inferrable-types": "off" 18 | "@typescript-eslint/no-unused-vars": 19 | - error 20 | - argsIgnorePattern: _ 21 | varsIgnorePattern: _ 22 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. 2 | # 3 | # You can adjust the behavior by modifying this file. 4 | # For more information, see: 5 | # https://github.com/actions/stale 6 | name: Mark stale issues and pull requests 7 | 8 | on: 9 | schedule: 10 | - cron: '31 4 * * *' 11 | 12 | jobs: 13 | stale: 14 | 15 | runs-on: ubuntu-latest 16 | permissions: 17 | issues: write 18 | pull-requests: write 19 | 20 | steps: 21 | - uses: actions/stale@v3 22 | with: 23 | repo-token: ${{ secrets.GITHUB_TOKEN }} 24 | stale-issue-message: 'Stale issue message' 25 | stale-pr-message: 'Stale pull request message' 26 | stale-issue-label: 'no-issue-activity' 27 | stale-pr-label: 'no-pr-activity' 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .coverage_artifacts/ 3 | .coverage_cache/ 4 | .coverage_contracts/ 5 | .yarn/* 6 | !.yarn/releases 7 | !.yarn/plugins 8 | artifacts/ 9 | build/ 10 | cache/ 11 | coverage/ 12 | dist/ 13 | lib/ 14 | node_modules/ 15 | typechain/ 16 | 17 | # files 18 | *.env 19 | *.log 20 | *.tsbuildinfo 21 | coverage.json 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.{js,json,md,sol,ts}": [ 3 | "prettier --config ./.prettierrc --write" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # folders 2 | artifacts/ 3 | build/ 4 | cache/ 5 | coverage/ 6 | dist/ 7 | lib/ 8 | node_modules/ 9 | typechain/ 10 | 11 | # files 12 | coverage.json 13 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSpacing": true, 4 | "endOfLine":"auto", 5 | "printWidth": 120, 6 | "singleQuote": false, 7 | "tabWidth": 2, 8 | "trailingComma": "all", 9 | "overrides": [ 10 | { 11 | "files": "*.sol", 12 | "options": { 13 | "tabWidth": 4 14 | } 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /.solcover.js: -------------------------------------------------------------------------------- 1 | const shell = require("shelljs"); 2 | 3 | // The environment variables are loaded in hardhat.config.ts 4 | const mnemonic = process.env.MNEMONIC; 5 | if (!mnemonic) { 6 | throw new Error("Please set your MNEMONIC in a .env file"); 7 | } 8 | 9 | module.exports = { 10 | istanbulReporter: ["html", "lcov"], 11 | onCompileComplete: async function (_config) { 12 | await run("typechain"); 13 | }, 14 | onIstanbulComplete: async function (_config) { 15 | // We need to do this because solcover generates bespoke artifacts. 16 | shell.rm("-rf", "./artifacts"); 17 | shell.rm("-rf", "./typechain"); 18 | }, 19 | providerOptions: { 20 | mnemonic, 21 | }, 22 | skipFiles: ["mocks", "test"], 23 | }; 24 | -------------------------------------------------------------------------------- /.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:recommended", 3 | "plugins": ["prettier"], 4 | "rules": { 5 | "code-complexity": ["error", 7], 6 | "compiler-version": ["error", ">=0.8.0"], 7 | "const-name-snakecase": "off", 8 | "constructor-syntax": "error", 9 | "func-visibility": ["error", { "ignoreConstructors": true }], 10 | "max-line-length": ["error", 120], 11 | "not-rely-on-time": "off", 12 | "prettier/prettier": [ 13 | "error", 14 | { 15 | "endOfLine": "auto" 16 | } 17 | ], 18 | "reason-string": ["warn", { "maxLength": 64 }] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.solhintignore: -------------------------------------------------------------------------------- 1 | # folders 2 | .yarn/ 3 | build/ 4 | dist/ 5 | node_modules/ 6 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Pool state that never changes 5 | /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values 6 | interface IUniswapV3PoolImmutables { 7 | /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface 8 | /// @return The contract address 9 | function factory() external view returns (address); 10 | 11 | /// @notice The first of the two tokens of the pool, sorted by address 12 | /// @return The token contract address 13 | function token0() external view returns (address); 14 | 15 | /// @notice The second of the two tokens of the pool, sorted by address 16 | /// @return The token contract address 17 | function token1() external view returns (address); 18 | 19 | /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 20 | /// @return The fee 21 | function fee() external view returns (uint24); 22 | 23 | /// @notice The pool tick spacing 24 | /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive 25 | /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... 26 | /// This value is an int24 to avoid casting even though it is always positive. 27 | /// @return The tick spacing 28 | function tickSpacing() external view returns (int24); 29 | 30 | /// @notice The maximum amount of position liquidity that can use any tick in the range 31 | /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and 32 | /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool 33 | /// @return The max amount of liquidity per tick 34 | function maxLiquidityPerTick() external view returns (uint128); 35 | } 36 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswap/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Pool state that never changes 5 | /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values 6 | interface IUniswapV3PoolImmutables { 7 | /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface 8 | /// @return The contract address 9 | function factory() external view returns (address); 10 | 11 | /// @notice The first of the two tokens of the pool, sorted by address 12 | /// @return The token contract address 13 | function token0() external view returns (address); 14 | 15 | /// @notice The second of the two tokens of the pool, sorted by address 16 | /// @return The token contract address 17 | function token1() external view returns (address); 18 | 19 | /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 20 | /// @return The fee 21 | function fee() external view returns (uint24); 22 | 23 | /// @notice The pool tick spacing 24 | /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive 25 | /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... 26 | /// This value is an int24 to avoid casting even though it is always positive. 27 | /// @return The tick spacing 28 | function tickSpacing() external view returns (int24); 29 | 30 | /// @notice The maximum amount of position liquidity that can use any tick in the range 31 | /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and 32 | /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool 33 | /// @return The max amount of liquidity per tick 34 | function maxLiquidityPerTick() external view returns (uint128); 35 | } 36 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/arbitrum/uniswapStaking/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/avalanche/benqi/helpers.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | import { ComptrollerLensInterface, TokenInterface } from "./interfaces.sol"; 4 | import { DSMath } from "../../../utils/dsmath.sol"; 5 | 6 | contract Helpers is DSMath { 7 | /** 8 | * @dev get Benqi Comptroller 9 | */ 10 | function getComptroller() public pure returns (ComptrollerLensInterface) { 11 | return ComptrollerLensInterface(0x486Af39519B4Dc9a7fCcd318217352830E8AD9b4); 12 | } 13 | 14 | /** 15 | * @dev get Benqi Open Feed Oracle Address 16 | */ 17 | function getOracleAddress() public view returns (address) { 18 | return getComptroller().oracle(); 19 | } 20 | 21 | /** 22 | * @dev get QiAVAX Address 23 | */ 24 | function getQiAVAXAddress() public pure returns (address) { 25 | return 0x5C0401e81Bc07Ca70fAD469b451682c0d747Ef1c; 26 | } 27 | 28 | /** 29 | * @dev get Qi Token Address 30 | */ 31 | function getQiToken() public pure returns (TokenInterface) { 32 | return TokenInterface(0x8729438EB15e2C8B576fCc6AeCdA6A148776C0F5); 33 | } 34 | 35 | struct BenqiData { 36 | uint256 tokenPriceInAvax; 37 | uint256 tokenPriceInUsd; 38 | uint256 exchangeRateStored; 39 | uint256 balanceOfUser; 40 | uint256 borrowBalanceStoredUser; 41 | uint256 totalBorrows; 42 | uint256 totalSupplied; 43 | uint256 borrowCap; 44 | uint256 supplyRatePerTimestamp; 45 | uint256 borrowRatePerTimestamp; 46 | uint256 collateralFactor; 47 | uint256 rewardSpeedQi; 48 | uint256 rewardSpeedAvax; 49 | bool isQied; 50 | bool isBorrowPaused; 51 | } 52 | 53 | struct MetadataExt { 54 | uint256 avaxAccrued; 55 | uint256 qiAccrued; 56 | address delegate; 57 | uint96 votes; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /contracts/protocols/avalanche/pangolin/stake/interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.6; 3 | pragma abicoder v2; 4 | 5 | interface IERC20 { 6 | function totalSupply() external view returns (uint256); 7 | 8 | function balanceOf(address account) external view returns (uint256); 9 | 10 | function allowance(address owner, address spender) external view returns (uint256); 11 | 12 | function approve(address spender, uint256 amount) external returns (bool); 13 | 14 | event Transfer(address indexed from, address indexed to, uint256 value); 15 | event Approval(address indexed owner, address indexed spender, uint256 value); 16 | 17 | // EIP 2612 18 | function permit( 19 | address owner, 20 | address spender, 21 | uint256 value, 22 | uint256 deadline, 23 | uint8 v, 24 | bytes32 r, 25 | bytes32 s 26 | ) external; 27 | } 28 | 29 | interface IStakingRewards { 30 | // Storage 31 | function rewards(address account) external view returns (uint256); 32 | 33 | // View 34 | function balanceOf(address account) external view returns (uint256); 35 | 36 | function rewardsToken() external view returns (address); 37 | 38 | function totalSupply() external view returns (uint256); 39 | } 40 | 41 | interface IMiniChefV2 { 42 | struct UserInfo { 43 | uint256 amount; 44 | int256 rewardDebt; 45 | } 46 | 47 | // Storage 48 | function addedTokens(address token) external view returns (bool); 49 | 50 | function lpToken(uint256 _pid) external view returns (IERC20); 51 | 52 | function userInfo(uint256 _pid, address _user) external view returns (UserInfo memory); 53 | 54 | // View 55 | function pendingReward(uint256 _pid, address _user) external view returns (uint256); 56 | 57 | function poolLength() external view returns (uint256); 58 | } 59 | -------------------------------------------------------------------------------- /contracts/protocols/base/erc20/interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | interface TokenInterface { 5 | function balanceOf(address) external view returns (uint256); 6 | 7 | function allowance(address owner, address spender) external view returns (uint256); 8 | 9 | function decimals() external view returns (uint256); 10 | 11 | function name() external view returns (string memory); 12 | 13 | function symbol() external view returns (string memory); 14 | } 15 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IERC20 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @dev Empty because we only call library functions. It prevents calling transfer (transferFrom) instead of 8 | /// safeTransfer (safeTransferFrom). 9 | interface IERC20 {} 10 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/interfaces/IIrm.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import {MarketParams, Market} from "./IMorpho.sol"; 5 | 6 | /// @title IIrm 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement. 10 | interface IIrm { 11 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`. 12 | /// @dev Assumes that `market` corresponds to `marketParams`. 13 | function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256); 14 | 15 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any 16 | /// storage. 17 | /// @dev Assumes that `market` corresponds to `marketParams`. 18 | function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256); 19 | } 20 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/interfaces/IOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IOracle 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @notice Interface that oracles used by Morpho must implement. 8 | /// @dev It is the user's responsibility to select markets with safe oracles. 9 | interface IOracle { 10 | /// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. 11 | /// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in 12 | /// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` 13 | /// decimals of precision. 14 | function price() external view returns (uint256); 15 | } 16 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/libraries/ConstantsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | /// @dev The maximum fee a market can have (25%). 5 | uint256 constant MAX_FEE = 0.25e18; 6 | 7 | /// @dev Oracle price scale. 8 | uint256 constant ORACLE_PRICE_SCALE = 1e36; 9 | 10 | /// @dev Liquidation cursor. 11 | uint256 constant LIQUIDATION_CURSOR = 0.3e18; 12 | 13 | /// @dev Max liquidation incentive factor. 14 | uint256 constant MAX_LIQUIDATION_INCENTIVE_FACTOR = 1.15e18; 15 | 16 | /// @dev The EIP-712 typeHash for EIP712Domain. 17 | bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"); 18 | 19 | /// @dev The EIP-712 typeHash for Authorization. 20 | bytes32 constant AUTHORIZATION_TYPEHASH = 21 | keccak256("Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)"); 22 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/libraries/MarketParamsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {Id, MarketParams} from "../interfaces/IMorpho.sol"; 5 | 6 | /// @title MarketParamsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to convert a market to its id. 10 | library MarketParamsLib { 11 | /// @notice The length of the data used to compute the id of a market. 12 | /// @dev The length is 5 * 32 because `MarketParams` has 5 variables of 32 bytes each. 13 | uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 5 * 32; 14 | 15 | /// @notice Returns the id of the market `marketParams`. 16 | function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) { 17 | assembly ("memory-safe") { 18 | marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/libraries/MathLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | uint256 constant WAD = 1e18; 5 | 6 | /// @title MathLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to manage fixed-point arithmetic. 10 | library MathLib { 11 | /// @dev Returns (`x` * `y`) / `WAD` rounded down. 12 | function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) { 13 | return mulDivDown(x, y, WAD); 14 | } 15 | 16 | /// @dev Returns (`x` * `WAD`) / `y` rounded down. 17 | function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) { 18 | return mulDivDown(x, WAD, y); 19 | } 20 | 21 | /// @dev Returns (`x` * `WAD`) / `y` rounded up. 22 | function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) { 23 | return mulDivUp(x, WAD, y); 24 | } 25 | 26 | /// @dev Returns (`x` * `y`) / `d` rounded down. 27 | function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 28 | return (x * y) / d; 29 | } 30 | 31 | /// @dev Returns (`x` * `y`) / `d` rounded up. 32 | function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 33 | return (x * y + (d - 1)) / d; 34 | } 35 | 36 | /// @dev Returns the sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1, to approximate a 37 | /// continuous compound interest rate. 38 | function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) { 39 | uint256 firstTerm = x * n; 40 | uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD); 41 | uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD); 42 | 43 | return firstTerm + secondTerm + thirdTerm; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/libraries/SafeTransferLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC20} from "../interfaces/IERC20.sol"; 5 | 6 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 7 | 8 | interface IERC20Internal { 9 | function transfer(address to, uint256 value) external returns (bool); 10 | function transferFrom(address from, address to, uint256 value) external returns (bool); 11 | } 12 | 13 | /// @title SafeTransferLib 14 | /// @author Morpho Labs 15 | /// @custom:contact security@morpho.org 16 | /// @notice Library to manage transfers of tokens, even if calls to the transfer or transferFrom functions are not 17 | /// returning a boolean. 18 | library SafeTransferLib { 19 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 20 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 21 | 22 | (bool success, bytes memory returndata) = 23 | address(token).call(abi.encodeCall(IERC20Internal.transfer, (to, value))); 24 | require(success, ErrorsLib.TRANSFER_REVERTED); 25 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_RETURNED_FALSE); 26 | } 27 | 28 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 29 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 30 | 31 | (bool success, bytes memory returndata) = 32 | address(token).call(abi.encodeCall(IERC20Internal.transferFrom, (from, to, value))); 33 | require(success, ErrorsLib.TRANSFER_FROM_REVERTED); 34 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_FROM_RETURNED_FALSE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/protocols/base/metamorpho/libraries/UtilsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 5 | 6 | /// @title UtilsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library exposing helpers. 10 | /// @dev Inspired by https://github.com/morpho-org/morpho-utils. 11 | library UtilsLib { 12 | /// @dev Returns true if there is exactly one zero among `x` and `y`. 13 | function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) { 14 | assembly { 15 | z := xor(iszero(x), iszero(y)) 16 | } 17 | } 18 | 19 | /// @dev Returns the min of `x` and `y`. 20 | function min(uint256 x, uint256 y) internal pure returns (uint256 z) { 21 | assembly { 22 | z := xor(x, mul(xor(x, y), lt(y, x))) 23 | } 24 | } 25 | 26 | /// @dev Returns `x` safely cast to uint128. 27 | function toUint128(uint256 x) internal pure returns (uint128) { 28 | require(x <= type(uint128).max, ErrorsLib.MAX_UINT128_EXCEEDED); 29 | return uint128(x); 30 | } 31 | 32 | /// @dev Returns max(0, x - y). 33 | function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { 34 | assembly { 35 | z := mul(gt(x, y), sub(x, y)) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IERC20 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @dev Empty because we only call library functions. It prevents calling transfer (transferFrom) instead of 8 | /// safeTransfer (safeTransferFrom). 9 | interface IERC20 {} 10 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/interfaces/IIrm.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import {MarketParams, Market} from "./IMorpho.sol"; 5 | 6 | /// @title IIrm 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement. 10 | interface IIrm { 11 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`. 12 | /// @dev Assumes that `market` corresponds to `marketParams`. 13 | function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256); 14 | 15 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any 16 | /// storage. 17 | /// @dev Assumes that `market` corresponds to `marketParams`. 18 | function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256); 19 | } 20 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/interfaces/IOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IOracle 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @notice Interface that oracles used by Morpho must implement. 8 | /// @dev It is the user's responsibility to select markets with safe oracles. 9 | interface IOracle { 10 | /// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. 11 | /// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in 12 | /// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` 13 | /// decimals of precision. 14 | function price() external view returns (uint256); 15 | } 16 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/libraries/ConstantsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | /// @dev The maximum fee a market can have (25%). 5 | uint256 constant MAX_FEE = 0.25e18; 6 | 7 | /// @dev Oracle price scale. 8 | uint256 constant ORACLE_PRICE_SCALE = 1e36; 9 | 10 | /// @dev Liquidation cursor. 11 | uint256 constant LIQUIDATION_CURSOR = 0.3e18; 12 | 13 | /// @dev Max liquidation incentive factor. 14 | uint256 constant MAX_LIQUIDATION_INCENTIVE_FACTOR = 1.15e18; 15 | 16 | /// @dev The EIP-712 typeHash for EIP712Domain. 17 | bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"); 18 | 19 | /// @dev The EIP-712 typeHash for Authorization. 20 | bytes32 constant AUTHORIZATION_TYPEHASH = 21 | keccak256("Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)"); 22 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/libraries/MarketParamsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {Id, MarketParams} from "../interfaces/IMorpho.sol"; 5 | 6 | /// @title MarketParamsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to convert a market to its id. 10 | library MarketParamsLib { 11 | /// @notice The length of the data used to compute the id of a market. 12 | /// @dev The length is 5 * 32 because `MarketParams` has 5 variables of 32 bytes each. 13 | uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 5 * 32; 14 | 15 | /// @notice Returns the id of the market `marketParams`. 16 | function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) { 17 | assembly ("memory-safe") { 18 | marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/libraries/MathLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | uint256 constant WAD = 1e18; 5 | 6 | /// @title MathLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to manage fixed-point arithmetic. 10 | library MathLib { 11 | /// @dev Returns (`x` * `y`) / `WAD` rounded down. 12 | function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) { 13 | return mulDivDown(x, y, WAD); 14 | } 15 | 16 | /// @dev Returns (`x` * `WAD`) / `y` rounded down. 17 | function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) { 18 | return mulDivDown(x, WAD, y); 19 | } 20 | 21 | /// @dev Returns (`x` * `WAD`) / `y` rounded up. 22 | function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) { 23 | return mulDivUp(x, WAD, y); 24 | } 25 | 26 | /// @dev Returns (`x` * `y`) / `d` rounded down. 27 | function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 28 | return (x * y) / d; 29 | } 30 | 31 | /// @dev Returns (`x` * `y`) / `d` rounded up. 32 | function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 33 | return (x * y + (d - 1)) / d; 34 | } 35 | 36 | /// @dev Returns the sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1, to approximate a 37 | /// continuous compound interest rate. 38 | function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) { 39 | uint256 firstTerm = x * n; 40 | uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD); 41 | uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD); 42 | 43 | return firstTerm + secondTerm + thirdTerm; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/libraries/SafeTransferLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC20} from "../interfaces/IERC20.sol"; 5 | 6 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 7 | 8 | interface IERC20Internal { 9 | function transfer(address to, uint256 value) external returns (bool); 10 | function transferFrom(address from, address to, uint256 value) external returns (bool); 11 | } 12 | 13 | /// @title SafeTransferLib 14 | /// @author Morpho Labs 15 | /// @custom:contact security@morpho.org 16 | /// @notice Library to manage transfers of tokens, even if calls to the transfer or transferFrom functions are not 17 | /// returning a boolean. 18 | library SafeTransferLib { 19 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 20 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 21 | 22 | (bool success, bytes memory returndata) = 23 | address(token).call(abi.encodeCall(IERC20Internal.transfer, (to, value))); 24 | require(success, ErrorsLib.TRANSFER_REVERTED); 25 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_RETURNED_FALSE); 26 | } 27 | 28 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 29 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 30 | 31 | (bool success, bytes memory returndata) = 32 | address(token).call(abi.encodeCall(IERC20Internal.transferFrom, (from, to, value))); 33 | require(success, ErrorsLib.TRANSFER_FROM_REVERTED); 34 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_FROM_RETURNED_FALSE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/libraries/UtilsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 5 | 6 | /// @title UtilsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library exposing helpers. 10 | /// @dev Inspired by https://github.com/morpho-org/morpho-utils. 11 | library UtilsLib { 12 | /// @dev Returns true if there is exactly one zero among `x` and `y`. 13 | function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) { 14 | assembly { 15 | z := xor(iszero(x), iszero(y)) 16 | } 17 | } 18 | 19 | /// @dev Returns the min of `x` and `y`. 20 | function min(uint256 x, uint256 y) internal pure returns (uint256 z) { 21 | assembly { 22 | z := xor(x, mul(xor(x, y), lt(y, x))) 23 | } 24 | } 25 | 26 | /// @dev Returns `x` safely cast to uint128. 27 | function toUint128(uint256 x) internal pure returns (uint128) { 28 | require(x <= type(uint128).max, ErrorsLib.MAX_UINT128_EXCEEDED); 29 | return uint128(x); 30 | } 31 | 32 | /// @dev Returns max(0, x - y). 33 | function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { 34 | assembly { 35 | z := mul(gt(x, y), sub(x, y)) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/base/morpho-blue/main.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.19; 3 | 4 | import { Helpers } from "./helpers.sol"; 5 | import { MarketParams } from "./interfaces/IMorpho.sol"; 6 | 7 | /** 8 | * @title Morpho-Blue Resolver 9 | * @dev Get user position details and market details. 10 | */ 11 | contract MorphoBlueResolver is Helpers { 12 | function getPosition( 13 | address user, 14 | MarketParams[] memory marketParamsArr 15 | ) public view returns (UserData[] memory, MarketData[] memory) { 16 | uint256 length = marketParamsArr.length; 17 | 18 | UserData[] memory userData = new UserData[](length); 19 | MarketData[] memory marketData = new MarketData[](length); 20 | 21 | for (uint256 i = 0; i < length; i++) { 22 | // Update Addresses 23 | if (marketParamsArr[i].collateralToken == getEthAddr()) { 24 | marketParamsArr[i].collateralToken = getWethAddr(); 25 | } 26 | 27 | if (marketParamsArr[i].loanToken == getEthAddr()) { 28 | marketParamsArr[i].loanToken = getWethAddr(); 29 | } 30 | 31 | marketData[i] = getMarketConfig(marketParamsArr[i]); 32 | userData[i] = getUserConfig(marketData[i].id, marketParamsArr[i], user); 33 | } 34 | 35 | return (userData, marketData); 36 | } 37 | } 38 | 39 | contract InstaMorphoBlueResolverBase is MorphoBlueResolver { 40 | string public constant name = "Morpho-Blue-Resolver-v1"; 41 | } 42 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Pool state that never changes 5 | /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values 6 | interface IUniswapV3PoolImmutables { 7 | /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface 8 | /// @return The contract address 9 | function factory() external view returns (address); 10 | 11 | /// @notice The first of the two tokens of the pool, sorted by address 12 | /// @return The token contract address 13 | function token0() external view returns (address); 14 | 15 | /// @notice The second of the two tokens of the pool, sorted by address 16 | /// @return The token contract address 17 | function token1() external view returns (address); 18 | 19 | /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 20 | /// @return The fee 21 | function fee() external view returns (uint24); 22 | 23 | /// @notice The pool tick spacing 24 | /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive 25 | /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... 26 | /// This value is an int24 to avoid casting even though it is always positive. 27 | /// @return The tick spacing 28 | function tickSpacing() external view returns (int24); 29 | 30 | /// @notice The maximum amount of position liquidity that can use any tick in the range 31 | /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and 32 | /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool 33 | /// @return The max amount of liquidity per tick 34 | function maxLiquidityPerTick() external view returns (uint128); 35 | } 36 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/base/uniswap/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/fantom/erc20/interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | interface TokenInterface { 5 | function balanceOf(address) external view returns (uint256); 6 | 7 | function allowance(address owner, address spender) external view returns (uint256); 8 | 9 | function decimals() external view returns (uint256); 10 | 11 | function name() external view returns (string memory); 12 | 13 | function symbol() external view returns (string memory); 14 | } 15 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/erc20/interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | interface TokenInterface { 5 | function balanceOf(address) external view returns (uint256); 6 | 7 | function allowance(address owner, address spender) external view returns (uint256); 8 | 9 | function decimals() external view returns (uint256); 10 | 11 | function name() external view returns (string memory); 12 | 13 | function symbol() external view returns (string memory); 14 | } 15 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/liquity/helpers.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | import { DSMath } from "../../../utils/dsmath.sol"; 4 | import "./interfaces.sol"; 5 | 6 | contract Helpers is DSMath { 7 | TroveManagerLike internal constant troveManager = TroveManagerLike(0xA39739EF8b0231DbFA0DcdA07d7e29faAbCf4bb2); 8 | 9 | StabilityPoolLike internal constant stabilityPool = StabilityPoolLike(0x66017D22b0f8556afDd19FC67041899Eb65a21bb); 10 | 11 | StakingLike internal constant staking = StakingLike(0x4f9Fbb3f1E99B56e0Fe2892e623Ed36A76Fc605d); 12 | 13 | PoolLike internal constant activePool = PoolLike(0xDf9Eb223bAFBE5c5271415C75aeCD68C21fE3D7F); 14 | 15 | PoolLike internal constant defaultPool = PoolLike(0x896a3F03176f05CFbb4f006BfCd8723F2B0D741C); 16 | 17 | HintHelpersLike internal constant hintHelpers = HintHelpersLike(0xE84251b93D9524E0d2e621Ba7dc7cb3579F997C0); 18 | 19 | SortedTrovesLike internal constant sortedTroves = SortedTrovesLike(0x8FdD3fbFEb32b28fb73555518f8b361bCeA741A6); 20 | 21 | PriceFeedOracle internal constant priceFeedOracle = PriceFeedOracle(0x4c517D4e2C851CA76d7eC94B805269Df0f2201De); 22 | 23 | struct Trove { 24 | uint256 collateral; 25 | uint256 debt; 26 | uint256 icr; 27 | } 28 | 29 | struct StabilityDeposit { 30 | uint256 deposit; 31 | uint256 ethGain; 32 | uint256 lqtyGain; 33 | } 34 | 35 | struct Stake { 36 | uint256 amount; 37 | uint256 ethGain; 38 | uint256 lusdGain; 39 | } 40 | 41 | struct Position { 42 | Trove trove; 43 | StabilityDeposit stability; 44 | Stake stake; 45 | } 46 | 47 | struct System { 48 | uint256 borrowFee; 49 | uint256 ethTvl; 50 | uint256 tcr; 51 | bool isInRecoveryMode; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IERC20 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @dev Empty because we only call library functions. It prevents calling transfer (transferFrom) instead of 8 | /// safeTransfer (safeTransferFrom). 9 | interface IERC20 {} 10 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/interfaces/IIrm.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import {MarketParams, Market} from "./IMorpho.sol"; 5 | 6 | /// @title IIrm 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement. 10 | interface IIrm { 11 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`. 12 | /// @dev Assumes that `market` corresponds to `marketParams`. 13 | function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256); 14 | 15 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any 16 | /// storage. 17 | /// @dev Assumes that `market` corresponds to `marketParams`. 18 | function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256); 19 | } 20 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/interfaces/IOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IOracle 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @notice Interface that oracles used by Morpho must implement. 8 | /// @dev It is the user's responsibility to select markets with safe oracles. 9 | interface IOracle { 10 | /// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. 11 | /// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in 12 | /// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` 13 | /// decimals of precision. 14 | function price() external view returns (uint256); 15 | } 16 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/libraries/ConstantsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | /// @dev The maximum fee a market can have (25%). 5 | uint256 constant MAX_FEE = 0.25e18; 6 | 7 | /// @dev Oracle price scale. 8 | uint256 constant ORACLE_PRICE_SCALE = 1e36; 9 | 10 | /// @dev Liquidation cursor. 11 | uint256 constant LIQUIDATION_CURSOR = 0.3e18; 12 | 13 | /// @dev Max liquidation incentive factor. 14 | uint256 constant MAX_LIQUIDATION_INCENTIVE_FACTOR = 1.15e18; 15 | 16 | /// @dev The EIP-712 typeHash for EIP712Domain. 17 | bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"); 18 | 19 | /// @dev The EIP-712 typeHash for Authorization. 20 | bytes32 constant AUTHORIZATION_TYPEHASH = 21 | keccak256("Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)"); 22 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/libraries/MarketParamsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {Id, MarketParams} from "../interfaces/IMorpho.sol"; 5 | 6 | /// @title MarketParamsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to convert a market to its id. 10 | library MarketParamsLib { 11 | /// @notice The length of the data used to compute the id of a market. 12 | /// @dev The length is 5 * 32 because `MarketParams` has 5 variables of 32 bytes each. 13 | uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 5 * 32; 14 | 15 | /// @notice Returns the id of the market `marketParams`. 16 | function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) { 17 | assembly ("memory-safe") { 18 | marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/libraries/MathLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | uint256 constant WAD = 1e18; 5 | 6 | /// @title MathLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to manage fixed-point arithmetic. 10 | library MathLib { 11 | /// @dev Returns (`x` * `y`) / `WAD` rounded down. 12 | function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) { 13 | return mulDivDown(x, y, WAD); 14 | } 15 | 16 | /// @dev Returns (`x` * `WAD`) / `y` rounded down. 17 | function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) { 18 | return mulDivDown(x, WAD, y); 19 | } 20 | 21 | /// @dev Returns (`x` * `WAD`) / `y` rounded up. 22 | function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) { 23 | return mulDivUp(x, WAD, y); 24 | } 25 | 26 | /// @dev Returns (`x` * `y`) / `d` rounded down. 27 | function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 28 | return (x * y) / d; 29 | } 30 | 31 | /// @dev Returns (`x` * `y`) / `d` rounded up. 32 | function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 33 | return (x * y + (d - 1)) / d; 34 | } 35 | 36 | /// @dev Returns the sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1, to approximate a 37 | /// continuous compound interest rate. 38 | function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) { 39 | uint256 firstTerm = x * n; 40 | uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD); 41 | uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD); 42 | 43 | return firstTerm + secondTerm + thirdTerm; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/libraries/SafeTransferLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC20} from "../interfaces/IERC20.sol"; 5 | 6 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 7 | 8 | interface IERC20Internal { 9 | function transfer(address to, uint256 value) external returns (bool); 10 | function transferFrom(address from, address to, uint256 value) external returns (bool); 11 | } 12 | 13 | /// @title SafeTransferLib 14 | /// @author Morpho Labs 15 | /// @custom:contact security@morpho.org 16 | /// @notice Library to manage transfers of tokens, even if calls to the transfer or transferFrom functions are not 17 | /// returning a boolean. 18 | library SafeTransferLib { 19 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 20 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 21 | 22 | (bool success, bytes memory returndata) = 23 | address(token).call(abi.encodeCall(IERC20Internal.transfer, (to, value))); 24 | require(success, ErrorsLib.TRANSFER_REVERTED); 25 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_RETURNED_FALSE); 26 | } 27 | 28 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 29 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 30 | 31 | (bool success, bytes memory returndata) = 32 | address(token).call(abi.encodeCall(IERC20Internal.transferFrom, (from, to, value))); 33 | require(success, ErrorsLib.TRANSFER_FROM_REVERTED); 34 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_FROM_RETURNED_FALSE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/metamorpho/libraries/UtilsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 5 | 6 | /// @title UtilsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library exposing helpers. 10 | /// @dev Inspired by https://github.com/morpho-org/morpho-utils. 11 | library UtilsLib { 12 | /// @dev Returns true if there is exactly one zero among `x` and `y`. 13 | function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) { 14 | assembly { 15 | z := xor(iszero(x), iszero(y)) 16 | } 17 | } 18 | 19 | /// @dev Returns the min of `x` and `y`. 20 | function min(uint256 x, uint256 y) internal pure returns (uint256 z) { 21 | assembly { 22 | z := xor(x, mul(xor(x, y), lt(y, x))) 23 | } 24 | } 25 | 26 | /// @dev Returns `x` safely cast to uint128. 27 | function toUint128(uint256 x) internal pure returns (uint128) { 28 | require(x <= type(uint128).max, ErrorsLib.MAX_UINT128_EXCEEDED); 29 | return uint128(x); 30 | } 31 | 32 | /// @dev Returns max(0, x - y). 33 | function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { 34 | assembly { 35 | z := mul(gt(x, y), sub(x, y)) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IERC20 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @dev Empty because we only call library functions. It prevents calling transfer (transferFrom) instead of 8 | /// safeTransfer (safeTransferFrom). 9 | interface IERC20 {} 10 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/interfaces/IIrm.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import {MarketParams, Market} from "./IMorpho.sol"; 5 | 6 | /// @title IIrm 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement. 10 | interface IIrm { 11 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`. 12 | /// @dev Assumes that `market` corresponds to `marketParams`. 13 | function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256); 14 | 15 | /// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any 16 | /// storage. 17 | /// @dev Assumes that `market` corresponds to `marketParams`. 18 | function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256); 19 | } 20 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/interfaces/IOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title IOracle 5 | /// @author Morpho Labs 6 | /// @custom:contact security@morpho.org 7 | /// @notice Interface that oracles used by Morpho must implement. 8 | /// @dev It is the user's responsibility to select markets with safe oracles. 9 | interface IOracle { 10 | /// @notice Returns the price of 1 asset of collateral token quoted in 1 asset of loan token, scaled by 1e36. 11 | /// @dev It corresponds to the price of 10**(collateral token decimals) assets of collateral token quoted in 12 | /// 10**(loan token decimals) assets of loan token with `36 + loan token decimals - collateral token decimals` 13 | /// decimals of precision. 14 | function price() external view returns (uint256); 15 | } 16 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/libraries/ConstantsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | /// @dev The maximum fee a market can have (25%). 5 | uint256 constant MAX_FEE = 0.25e18; 6 | 7 | /// @dev Oracle price scale. 8 | uint256 constant ORACLE_PRICE_SCALE = 1e36; 9 | 10 | /// @dev Liquidation cursor. 11 | uint256 constant LIQUIDATION_CURSOR = 0.3e18; 12 | 13 | /// @dev Max liquidation incentive factor. 14 | uint256 constant MAX_LIQUIDATION_INCENTIVE_FACTOR = 1.15e18; 15 | 16 | /// @dev The EIP-712 typeHash for EIP712Domain. 17 | bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"); 18 | 19 | /// @dev The EIP-712 typeHash for Authorization. 20 | bytes32 constant AUTHORIZATION_TYPEHASH = 21 | keccak256("Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)"); 22 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/libraries/MarketParamsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {Id, MarketParams} from "../interfaces/IMorpho.sol"; 5 | 6 | /// @title MarketParamsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to convert a market to its id. 10 | library MarketParamsLib { 11 | /// @notice The length of the data used to compute the id of a market. 12 | /// @dev The length is 5 * 32 because `MarketParams` has 5 variables of 32 bytes each. 13 | uint256 internal constant MARKET_PARAMS_BYTES_LENGTH = 5 * 32; 14 | 15 | /// @notice Returns the id of the market `marketParams`. 16 | function id(MarketParams memory marketParams) internal pure returns (Id marketParamsId) { 17 | assembly ("memory-safe") { 18 | marketParamsId := keccak256(marketParams, MARKET_PARAMS_BYTES_LENGTH) 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/libraries/MathLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | uint256 constant WAD = 1e18; 5 | 6 | /// @title MathLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library to manage fixed-point arithmetic. 10 | library MathLib { 11 | /// @dev Returns (`x` * `y`) / `WAD` rounded down. 12 | function wMulDown(uint256 x, uint256 y) internal pure returns (uint256) { 13 | return mulDivDown(x, y, WAD); 14 | } 15 | 16 | /// @dev Returns (`x` * `WAD`) / `y` rounded down. 17 | function wDivDown(uint256 x, uint256 y) internal pure returns (uint256) { 18 | return mulDivDown(x, WAD, y); 19 | } 20 | 21 | /// @dev Returns (`x` * `WAD`) / `y` rounded up. 22 | function wDivUp(uint256 x, uint256 y) internal pure returns (uint256) { 23 | return mulDivUp(x, WAD, y); 24 | } 25 | 26 | /// @dev Returns (`x` * `y`) / `d` rounded down. 27 | function mulDivDown(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 28 | return (x * y) / d; 29 | } 30 | 31 | /// @dev Returns (`x` * `y`) / `d` rounded up. 32 | function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256) { 33 | return (x * y + (d - 1)) / d; 34 | } 35 | 36 | /// @dev Returns the sum of the first three non-zero terms of a Taylor expansion of e^(nx) - 1, to approximate a 37 | /// continuous compound interest rate. 38 | function wTaylorCompounded(uint256 x, uint256 n) internal pure returns (uint256) { 39 | uint256 firstTerm = x * n; 40 | uint256 secondTerm = mulDivDown(firstTerm, firstTerm, 2 * WAD); 41 | uint256 thirdTerm = mulDivDown(secondTerm, firstTerm, 3 * WAD); 42 | 43 | return firstTerm + secondTerm + thirdTerm; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/libraries/SafeTransferLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {IERC20} from "../interfaces/IERC20.sol"; 5 | 6 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 7 | 8 | interface IERC20Internal { 9 | function transfer(address to, uint256 value) external returns (bool); 10 | function transferFrom(address from, address to, uint256 value) external returns (bool); 11 | } 12 | 13 | /// @title SafeTransferLib 14 | /// @author Morpho Labs 15 | /// @custom:contact security@morpho.org 16 | /// @notice Library to manage transfers of tokens, even if calls to the transfer or transferFrom functions are not 17 | /// returning a boolean. 18 | library SafeTransferLib { 19 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 20 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 21 | 22 | (bool success, bytes memory returndata) = 23 | address(token).call(abi.encodeCall(IERC20Internal.transfer, (to, value))); 24 | require(success, ErrorsLib.TRANSFER_REVERTED); 25 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_RETURNED_FALSE); 26 | } 27 | 28 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 29 | require(address(token).code.length > 0, ErrorsLib.NO_CODE); 30 | 31 | (bool success, bytes memory returndata) = 32 | address(token).call(abi.encodeCall(IERC20Internal.transferFrom, (from, to, value))); 33 | require(success, ErrorsLib.TRANSFER_FROM_REVERTED); 34 | require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_FROM_RETURNED_FALSE); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/libraries/UtilsLib.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity ^0.8.0; 3 | 4 | import {ErrorsLib} from "../libraries/ErrorsLib.sol"; 5 | 6 | /// @title UtilsLib 7 | /// @author Morpho Labs 8 | /// @custom:contact security@morpho.org 9 | /// @notice Library exposing helpers. 10 | /// @dev Inspired by https://github.com/morpho-org/morpho-utils. 11 | library UtilsLib { 12 | /// @dev Returns true if there is exactly one zero among `x` and `y`. 13 | function exactlyOneZero(uint256 x, uint256 y) internal pure returns (bool z) { 14 | assembly { 15 | z := xor(iszero(x), iszero(y)) 16 | } 17 | } 18 | 19 | /// @dev Returns the min of `x` and `y`. 20 | function min(uint256 x, uint256 y) internal pure returns (uint256 z) { 21 | assembly { 22 | z := xor(x, mul(xor(x, y), lt(y, x))) 23 | } 24 | } 25 | 26 | /// @dev Returns `x` safely cast to uint128. 27 | function toUint128(uint256 x) internal pure returns (uint128) { 28 | require(x <= type(uint128).max, ErrorsLib.MAX_UINT128_EXCEEDED); 29 | return uint128(x); 30 | } 31 | 32 | /// @dev Returns max(0, x - y). 33 | function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { 34 | assembly { 35 | z := mul(gt(x, y), sub(x, y)) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho-blue/main.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.19; 3 | 4 | import { Helpers } from "./helpers.sol"; 5 | import { MarketParams } from "./interfaces/IMorpho.sol"; 6 | 7 | /** 8 | * @title Morpho-Blue Resolver 9 | * @dev Get user position details and market details. 10 | */ 11 | contract MorphoBlueResolver is Helpers { 12 | function getPosition( 13 | address user, 14 | MarketParams[] memory marketParamsArr 15 | ) public view returns (UserData[] memory, MarketData[] memory) { 16 | uint256 length = marketParamsArr.length; 17 | 18 | UserData[] memory userData = new UserData[](length); 19 | MarketData[] memory marketData = new MarketData[](length); 20 | 21 | for (uint256 i = 0; i < length; i++) { 22 | // Update Addresses 23 | if (marketParamsArr[i].collateralToken == getEthAddr()) { 24 | marketParamsArr[i].collateralToken = getWethAddr(); 25 | } 26 | 27 | if (marketParamsArr[i].loanToken == getEthAddr()) { 28 | marketParamsArr[i].loanToken = getWethAddr(); 29 | } 30 | 31 | marketData[i] = getMarketConfig(marketParamsArr[i]); 32 | userData[i] = getUserConfig(marketData[i].id, marketParamsArr[i], user); 33 | } 34 | 35 | return (userData, marketData); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/IAaveIncentivesController.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | /** 5 | * @title IAaveIncentivesController 6 | * @author Aave 7 | * @notice Defines the basic interface for an Aave Incentives Controller. 8 | * @dev It only contains one single function, needed as a hook on aToken and debtToken transfers. 9 | */ 10 | interface IAaveIncentivesController { 11 | /** 12 | * @dev Called by the corresponding asset on transfer hook in order to update the rewards distribution. 13 | * @dev The units of `totalSupply` and `userBalance` should be the same. 14 | * @param user The address of the user whose asset balance has changed 15 | * @param totalSupply The total supply of the asset prior to user balance change 16 | * @param userBalance The previous user balance prior to balance change 17 | */ 18 | function handleAction( 19 | address user, 20 | uint256 totalSupply, 21 | uint256 userBalance 22 | ) external; 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/IDelegationToken.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | /** 5 | * @title IDelegationToken 6 | * @author Aave 7 | * @notice Implements an interface for tokens with delegation COMP/UNI compatible 8 | */ 9 | interface IDelegationToken { 10 | /** 11 | * @notice Delegate voting power to a delegatee 12 | * @param delegatee The address of the delegatee 13 | */ 14 | function delegate(address delegatee) external; 15 | } 16 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/IERC20WithPermit.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | import { IERC20 } from "../IERC20.sol"; 5 | 6 | /** 7 | * @title IERC20WithPermit 8 | * @author Aave 9 | * @notice Interface for the permit function (EIP-2612) 10 | */ 11 | interface IERC20WithPermit is IERC20 { 12 | /** 13 | * @notice Allow passing a signed message to approve spending 14 | * @dev implements the permit function as for 15 | * https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md 16 | * @param owner The owner of the funds 17 | * @param spender The spender 18 | * @param value The amount 19 | * @param deadline The deadline timestamp, type(uint256).max for max deadline 20 | * @param v Signature param 21 | * @param s Signature param 22 | * @param r Signature param 23 | */ 24 | function permit( 25 | address owner, 26 | address spender, 27 | uint256 value, 28 | uint256 deadline, 29 | uint8 v, 30 | bytes32 r, 31 | bytes32 s 32 | ) external; 33 | } 34 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/IPriceOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | /** 5 | * @title IPriceOracle 6 | * @author Aave 7 | * @notice Defines the basic interface for a Price oracle. 8 | */ 9 | interface IPriceOracle { 10 | /** 11 | * @notice Returns the asset price in the base currency 12 | * @param asset The address of the asset 13 | * @return The price of the asset 14 | */ 15 | function getAssetPrice(address asset) external view returns (uint256); 16 | 17 | /** 18 | * @notice Set the price of the asset 19 | * @param asset The address of the asset 20 | * @param price The price of the asset 21 | */ 22 | function setAssetPrice(address asset, uint256 price) external; 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/IPriceOracleGetter.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | /** 5 | * @title IPriceOracleGetter 6 | * @author Aave 7 | * @notice Interface for the Aave price oracle. 8 | */ 9 | interface IPriceOracleGetter { 10 | /** 11 | * @notice Returns the base currency address 12 | * @dev Address 0x0 is reserved for USD as base currency. 13 | * @return Returns the base currency address. 14 | */ 15 | function BASE_CURRENCY() external view returns (address); 16 | 17 | /** 18 | * @notice Returns the base currency unit 19 | * @dev 1 ether for ETH, 1e8 for USD. 20 | * @return Returns the base currency unit. 21 | */ 22 | function BASE_CURRENCY_UNIT() external view returns (uint256); 23 | 24 | /** 25 | * @notice Returns the asset price in the base currency 26 | * @param asset The address of the asset 27 | * @return The price of the asset 28 | */ 29 | function getAssetPrice(address asset) external view returns (uint256); 30 | } 31 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/IReserveInterestRateStrategy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | import { DataTypes } from "../protocol/libraries/types/DataTypes.sol"; 5 | 6 | /** 7 | * @title IReserveInterestRateStrategy 8 | * @author Aave 9 | * @notice Interface for the calculation of the interest rates 10 | */ 11 | interface IReserveInterestRateStrategy { 12 | /** 13 | * @notice Calculates the interest rates depending on the reserve's state and configurations 14 | * @param params The parameters needed to calculate interest rates 15 | * @return liquidityRate The liquidity rate expressed in rays 16 | * @return stableBorrowRate The stable borrow rate expressed in rays 17 | * @return variableBorrowRate The variable borrow rate expressed in rays 18 | */ 19 | function calculateInterestRates(DataTypes.CalculateInterestRatesParams memory params) 20 | external 21 | view 22 | returns ( 23 | uint256, 24 | uint256, 25 | uint256 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/interfaces/ISequencerOracle.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0 2 | pragma solidity ^0.8.6; 3 | 4 | /** 5 | * @title ISequencerOracle 6 | * @author Aave 7 | * @notice Defines the basic interface for a Sequencer oracle. 8 | */ 9 | interface ISequencerOracle { 10 | /** 11 | * @notice Returns the health status of the sequencer. 12 | * @return roundId The round ID from the aggregator for which the data was retrieved combined with a phase to ensure 13 | * that round IDs get larger as time moves forward. 14 | * @return answer The answer for the latest round: 0 if the sequencer is up, 1 if it is down. 15 | * @return startedAt The timestamp when the round was started. 16 | * @return updatedAt The timestamp of the block in which the answer was updated on L1. 17 | * @return answeredInRound The round ID of the round in which the answer was computed. 18 | */ 19 | function latestRoundData() 20 | external 21 | view 22 | returns ( 23 | uint80 roundId, 24 | int256 answer, 25 | uint256 startedAt, 26 | uint256 updatedAt, 27 | uint80 answeredInRound 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/aave-v3-core/protocol/libraries/types/ConfiguratorInputTypes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: BUSL-1.1 2 | pragma solidity ^0.8.6; 3 | 4 | library ConfiguratorInputTypes { 5 | struct InitReserveInput { 6 | address aTokenImpl; 7 | address stableDebtTokenImpl; 8 | address variableDebtTokenImpl; 9 | uint8 underlyingAssetDecimals; 10 | address interestRateStrategyAddress; 11 | address underlyingAsset; 12 | address treasury; 13 | address incentivesController; 14 | string aTokenName; 15 | string aTokenSymbol; 16 | string variableDebtTokenName; 17 | string variableDebtTokenSymbol; 18 | string stableDebtTokenName; 19 | string stableDebtTokenSymbol; 20 | bytes params; 21 | } 22 | 23 | struct UpdateATokenInput { 24 | address asset; 25 | address treasury; 26 | address incentivesController; 27 | string name; 28 | string symbol; 29 | address implementation; 30 | bytes params; 31 | } 32 | 33 | struct UpdateDebtTokenInput { 34 | address asset; 35 | address incentivesController; 36 | string name; 37 | string symbol; 38 | address implementation; 39 | bytes params; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/morpho/aave_v3/library/math/CompoundMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: AGPL-3.0-only 2 | pragma solidity ^0.8.6; 3 | 4 | /// @title Compound Math Library. 5 | /// @author Morpho Labs. 6 | /// @custom:contact security@morpho.xyz 7 | /// @dev Library to perform Compound's multiplication and division in an efficient way. 8 | library CompoundMath { 9 | /// CONSTANTS /// 10 | 11 | // Only direct number constants and references to such constants are supported by inline assembly. 12 | uint256 internal constant WAD = 1e18; 13 | uint256 internal constant MAX_UINT256 = 2**256 - 1; 14 | 15 | /// INTERNAL /// 16 | 17 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 18 | assembly { 19 | // Revert if x * y > type(uint256).max 20 | // <=> y > 0 and x > type(uint256).max / y 21 | if mul(y, gt(x, div(MAX_UINT256, y))) { 22 | revert(0, 0) 23 | } 24 | 25 | z := div(mul(x, y), WAD) 26 | } 27 | } 28 | 29 | function div(uint256 x, uint256 y) internal pure returns (uint256 z) { 30 | assembly { 31 | // Revert if x * WAD > type(uint256).max or y == 0 32 | // <=> x > type(uint256).max / WAD or y == 0 33 | if iszero(mul(y, lt(x, add(div(MAX_UINT256, WAD), 1)))) { 34 | revert(0, 0) 35 | } 36 | 37 | z := div(mul(WAD, x), y) 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/ubiquity/interfaces/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC165 standard, as defined in the 8 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 9 | * 10 | * Implementers can declare support of contract interfaces, which can then be 11 | * queried by others ({ERC165Checker}). 12 | * 13 | * For an implementation, see {ERC165}. 14 | */ 15 | interface IERC165 { 16 | /** 17 | * @dev Returns true if this contract implements the interface defined by 18 | * `interfaceId`. See the corresponding 19 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 20 | * to learn more about how these ids are created. 21 | * 22 | * This function call must use less than 30 000 gas. 23 | */ 24 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 25 | } 26 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Pool state that never changes 5 | /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values 6 | interface IUniswapV3PoolImmutables { 7 | /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface 8 | /// @return The contract address 9 | function factory() external view returns (address); 10 | 11 | /// @notice The first of the two tokens of the pool, sorted by address 12 | /// @return The token contract address 13 | function token0() external view returns (address); 14 | 15 | /// @notice The second of the two tokens of the pool, sorted by address 16 | /// @return The token contract address 17 | function token1() external view returns (address); 18 | 19 | /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 20 | /// @return The fee 21 | function fee() external view returns (uint24); 22 | 23 | /// @notice The pool tick spacing 24 | /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive 25 | /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... 26 | /// This value is an int24 to avoid casting even though it is always positive. 27 | /// @return The tick spacing 28 | function tickSpacing() external view returns (int24); 29 | 30 | /// @notice The maximum amount of position liquidity that can use any tick in the range 31 | /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and 32 | /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool 33 | /// @return The max amount of liquidity per tick 34 | function maxLiquidityPerTick() external view returns (uint128); 35 | } 36 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswap/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/uniswapStaking/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/universeFinance/interface.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.6; 3 | pragma abicoder v2; 4 | 5 | interface IUniverseAdapter { 6 | function depositProxy( 7 | address universeVault, 8 | uint256 amount0, 9 | uint256 amount1 10 | ) external returns (uint256, uint256); 11 | } 12 | 13 | interface IUniverseResolver { 14 | function getAllVaultAddress() external view returns (address[] memory vaults); 15 | 16 | function checkUniverseVault(address universeVault) external view returns (bool status); 17 | } 18 | 19 | interface IVaultV3 { 20 | function getShares(uint256 amount0Desired, uint256 amount1Desired) 21 | external 22 | view 23 | returns (uint256 share0, uint256 share1); 24 | 25 | function getBals(uint256 share0, uint256 share1) external view returns (uint256 amount0, uint256 amount1); 26 | 27 | function getUserShares(address user) external view returns (uint256 share0, uint256 share1); 28 | 29 | function token0() external view returns (address); 30 | 31 | function token1() external view returns (address); 32 | 33 | struct MaxShares { 34 | uint256 maxToken0Amt; 35 | uint256 maxToken1Amt; 36 | uint256 maxSingeDepositAmt0; 37 | uint256 maxSingeDepositAmt1; 38 | } 39 | 40 | function maxShares() external view returns (MaxShares memory); 41 | 42 | function getTotalAmounts() 43 | external 44 | view 45 | returns ( 46 | uint256 total0, 47 | uint256 total1, 48 | uint256 free0, 49 | uint256 free1, 50 | uint256 utilizationRate0, 51 | uint256 utilizationRate1 52 | ); 53 | 54 | function getPNL() external view returns (uint256 rate, uint256 param); 55 | } 56 | 57 | interface IERC20 { 58 | function decimals() external view returns (uint8); 59 | } 60 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/yearn_v2/helpers.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | import { DSMath } from "../../../utils/dsmath.sol"; 4 | import "./interfaces.sol"; 5 | 6 | contract Helpers is DSMath { 7 | /** 8 | * @dev get Yearn Registry 9 | */ 10 | function getRegistry() public pure returns (YearnRegistryInterface) { 11 | return YearnRegistryInterface(0x50c1a2eA0a861A967D9d0FFE2AE4012c2E053804); 12 | } 13 | 14 | struct VaultData { 15 | address vaultLatestVersion; 16 | address vault; 17 | address want; 18 | uint256 pricePerShare; 19 | uint256 availableDepositLimit; 20 | uint256 totalAssets; 21 | uint256 balanceOf; 22 | uint256 wantBalanceOf; 23 | uint256 expectedShareValue; 24 | uint256 decimals; 25 | bool isDeprecated; 26 | bool emergencyShutdown; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/mainnet/yearn_v2/interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | interface YearnV2Interface { 5 | function emergencyShutdown() external view returns (bool); 6 | 7 | function pricePerShare() external view returns (uint256); 8 | 9 | function availableDepositLimit() external view returns (uint256); 10 | 11 | function totalAssets() external view returns (uint256); 12 | 13 | function balanceOf(address) external view returns (uint256); 14 | 15 | function decimals() external view returns (uint256); 16 | } 17 | 18 | interface YearnRegistryInterface { 19 | function isRegistered(address) external view returns (bool); 20 | 21 | function latestVault(address) external view returns (address); 22 | 23 | function numVaults(address) external view returns (uint256); 24 | 25 | function vaults(address, uint256) external view returns (address); 26 | } 27 | 28 | interface TokenInterface { 29 | function balanceOf(address) external view returns (uint256); 30 | } 31 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/erc20/interfaces.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.8.0; 3 | 4 | interface TokenInterface { 5 | function balanceOf(address) external view returns (uint256); 6 | 7 | function allowance(address owner, address spender) external view returns (uint256); 8 | 9 | function decimals() external view returns (uint256); 10 | 11 | function name() external view returns (string memory); 12 | 13 | function symbol() external view returns (string memory); 14 | } 15 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Pool state that never changes 5 | /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values 6 | interface IUniswapV3PoolImmutables { 7 | /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface 8 | /// @return The contract address 9 | function factory() external view returns (address); 10 | 11 | /// @notice The first of the two tokens of the pool, sorted by address 12 | /// @return The token contract address 13 | function token0() external view returns (address); 14 | 15 | /// @notice The second of the two tokens of the pool, sorted by address 16 | /// @return The token contract address 17 | function token1() external view returns (address); 18 | 19 | /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 20 | /// @return The fee 21 | function fee() external view returns (uint24); 22 | 23 | /// @notice The pool tick spacing 24 | /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive 25 | /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... 26 | /// This value is an int24 to avoid casting even though it is always positive. 27 | /// @return The tick spacing 28 | function tickSpacing() external view returns (int24); 29 | 30 | /// @notice The maximum amount of position liquidity that can use any tick in the range 31 | /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and 32 | /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool 33 | /// @return The max amount of liquidity per tick 34 | function maxLiquidityPerTick() external view returns (uint128); 35 | } 36 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswap/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/optimism/uniswapStaking/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Pool state that never changes 5 | /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values 6 | interface IUniswapV3PoolImmutables { 7 | /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface 8 | /// @return The contract address 9 | function factory() external view returns (address); 10 | 11 | /// @notice The first of the two tokens of the pool, sorted by address 12 | /// @return The token contract address 13 | function token0() external view returns (address); 14 | 15 | /// @notice The second of the two tokens of the pool, sorted by address 16 | /// @return The token contract address 17 | function token1() external view returns (address); 18 | 19 | /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 20 | /// @return The fee 21 | function fee() external view returns (uint24); 22 | 23 | /// @notice The pool tick spacing 24 | /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive 25 | /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... 26 | /// This value is an int24 to avoid casting even though it is always positive. 27 | /// @return The tick spacing 28 | function tickSpacing() external view returns (int24); 29 | 30 | /// @notice The maximum amount of position liquidity that can use any tick in the range 31 | /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and 32 | /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool 33 | /// @return The max amount of liquidity per tick 34 | function maxLiquidityPerTick() external view returns (uint128); 35 | } 36 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswap/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/interfaces/IUniswapV3Pool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | import "./pool/IUniswapV3PoolImmutables.sol"; 5 | import "./pool/IUniswapV3PoolState.sol"; 6 | import "./pool/IUniswapV3PoolDerivedState.sol"; 7 | import "./pool/IUniswapV3PoolActions.sol"; 8 | import "./pool/IUniswapV3PoolOwnerActions.sol"; 9 | import "./pool/IUniswapV3PoolEvents.sol"; 10 | 11 | /// @title The interface for a Uniswap V3 Pool 12 | /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform 13 | /// to the ERC20 specification 14 | /// @dev The pool interface is broken up into many smaller pieces 15 | interface IUniswapV3Pool is 16 | IUniswapV3PoolImmutables, 17 | IUniswapV3PoolState, 18 | IUniswapV3PoolDerivedState, 19 | IUniswapV3PoolActions, 20 | IUniswapV3PoolOwnerActions, 21 | IUniswapV3PoolEvents 22 | { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Permissioned pool actions 5 | /// @notice Contains pool methods that may only be called by the factory owner 6 | interface IUniswapV3PoolOwnerActions { 7 | /// @notice Set the denominator of the protocol's % share of the fees 8 | /// @param feeProtocol0 new protocol fee for token0 of the pool 9 | /// @param feeProtocol1 new protocol fee for token1 of the pool 10 | function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; 11 | 12 | /// @notice Collect the protocol fee accrued to the pool 13 | /// @param recipient The address to which collected protocol fees should be sent 14 | /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 15 | /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 16 | /// @return amount0 The protocol fee collected in token0 17 | /// @return amount1 The protocol fee collected in token1 18 | function collectProtocol( 19 | address recipient, 20 | uint128 amount0Requested, 21 | uint128 amount1Requested 22 | ) external returns (uint128 amount0, uint128 amount1); 23 | } 24 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/FixedPoint128.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint128 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | library FixedPoint128 { 7 | uint256 internal constant Q128 = 0x100000000000000000000000000000000; 8 | } 9 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/FixedPoint96.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.4.0; 3 | 4 | /// @title FixedPoint96 5 | /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) 6 | /// @dev Used in SqrtPriceMath.sol 7 | library FixedPoint96 { 8 | uint8 internal constant RESOLUTION = 96; 9 | uint256 internal constant Q96 = 0x1000000000000000000000000; 10 | } 11 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/LICENSE_MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021 Remco Bloemen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/LiquidityMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math library for liquidity 5 | library LiquidityMath { 6 | /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows 7 | /// @param x The liquidity before change 8 | /// @param y The delta by which liquidity should be changed 9 | /// @return z The liquidity delta 10 | function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { 11 | if (y < 0) { 12 | require((z = x - uint128(-y)) < x, "LS"); 13 | } else { 14 | require((z = x + uint128(y)) >= x, "LA"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/LowGasSafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.7.0; 3 | 4 | /// @title Optimized overflow and underflow safe math operations 5 | /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost 6 | library LowGasSafeMath { 7 | /// @notice Returns x + y, reverts if sum overflows uint256 8 | /// @param x The augend 9 | /// @param y The addend 10 | /// @return z The sum of x and y 11 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 12 | require((z = x + y) >= x); 13 | } 14 | 15 | /// @notice Returns x - y, reverts if underflows 16 | /// @param x The minuend 17 | /// @param y The subtrahend 18 | /// @return z The difference of x and y 19 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x - y) <= x); 21 | } 22 | 23 | /// @notice Returns x * y, reverts if overflows 24 | /// @param x The multiplicand 25 | /// @param y The multiplier 26 | /// @return z The product of x and y 27 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 28 | require(x == 0 || (z = x * y) / x == y); 29 | } 30 | 31 | /// @notice Returns x + y, reverts if overflows or underflows 32 | /// @param x The augend 33 | /// @param y The addend 34 | /// @return z The sum of x and y 35 | function add(int256 x, int256 y) internal pure returns (int256 z) { 36 | require((z = x + y) >= x == (y >= 0)); 37 | } 38 | 39 | /// @notice Returns x - y, reverts if overflows or underflows 40 | /// @param x The minuend 41 | /// @param y The subtrahend 42 | /// @return z The difference of x and y 43 | function sub(int256 x, int256 y) internal pure returns (int256 z) { 44 | require((z = x - y) <= x == (y >= 0)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/PoolAddress.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PoolAddress { 4 | bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; 5 | 6 | struct PoolKey { 7 | address token0; 8 | address token1; 9 | uint24 fee; 10 | } 11 | 12 | function getPoolKey( 13 | address tokenA, 14 | address tokenB, 15 | uint24 fee 16 | ) internal pure returns (PoolKey memory) { 17 | if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); 18 | return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); 19 | } 20 | 21 | function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { 22 | require(key.token0 < key.token1); 23 | pool = address( 24 | uint160( 25 | uint256( 26 | keccak256( 27 | abi.encodePacked( 28 | hex"ff", 29 | factory, 30 | keccak256(abi.encode(key.token0, key.token1, key.fee)), 31 | POOL_INIT_CODE_HASH 32 | ) 33 | ) 34 | ) 35 | ) 36 | ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/PositionKey.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | library PositionKey { 4 | function compute( 5 | address owner, 6 | int24 tickLower, 7 | int24 tickUpper 8 | ) internal pure returns (bytes32) { 9 | return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/SafeCast.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Safe casting methods 5 | /// @notice Contains methods for safely casting between types 6 | library SafeCast { 7 | /// @notice Cast a uint256 to a uint160, revert on overflow 8 | /// @param y The uint256 to be downcasted 9 | /// @return z The downcasted integer, now type uint160 10 | function toUint160(uint256 y) internal pure returns (uint160 z) { 11 | require((z = uint160(y)) == y); 12 | } 13 | 14 | /// @notice Cast a int256 to a int128, revert on overflow or underflow 15 | /// @param y The int256 to be downcasted 16 | /// @return z The downcasted integer, now type int128 17 | function toInt128(int256 y) internal pure returns (int128 z) { 18 | require((z = int128(y)) == y); 19 | } 20 | 21 | /// @notice Cast a uint256 to a int256, revert on overflow 22 | /// @param y The uint256 to be casted 23 | /// @return z The casted integer, now type int256 24 | function toInt256(uint256 y) internal pure returns (int256 z) { 25 | require(y < 2**255); 26 | z = int256(y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/TransferHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.6.0; 3 | 4 | import "../interfaces/IERC20Minimal.sol"; 5 | 6 | /// @title TransferHelper 7 | /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false 8 | library TransferHelper { 9 | /// @notice Transfers tokens from msg.sender to a recipient 10 | /// @dev Calls transfer on token contract, errors with TF if transfer fails 11 | /// @param token The contract address of the token which will be transferred 12 | /// @param to The recipient of the transfer 13 | /// @param value The value of the transfer 14 | function safeTransfer( 15 | address token, 16 | address to, 17 | uint256 value 18 | ) internal { 19 | (bool success, bytes memory data) = token.call( 20 | abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value) 21 | ); 22 | require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /contracts/protocols/polygon/uniswapStaking/contracts/libraries/UnsafeMath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0-or-later 2 | pragma solidity >=0.5.0; 3 | 4 | /// @title Math functions that do not check inputs or outputs 5 | /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks 6 | library UnsafeMath { 7 | /// @notice Returns ceil(x / y) 8 | /// @dev division by 0 has unspecified behavior, and must be checked externally 9 | /// @param x The dividend 10 | /// @param y The divisor 11 | /// @return z The quotient, ceil(x / y) 12 | function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { 13 | assembly { 14 | z := add(div(x, y), gt(mod(x, y), 0)) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /contracts/utils/dsmath.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity >=0.7.0; 3 | 4 | contract DSMath { 5 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 6 | require((z = x + y) >= x, "math-not-safe"); 7 | } 8 | 9 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 10 | z = x - y <= x ? x - y : 0; 11 | } 12 | 13 | function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { 14 | require(y == 0 || (z = x * y) / y == x, "math-not-safe"); 15 | } 16 | 17 | function div(uint256 x, uint256 y) internal pure returns (uint256 z) { 18 | if (y == 0) return type(uint256).max; 19 | z = x / y; 20 | } 21 | 22 | function sqrt(uint256 y) internal pure returns (uint256 z) { 23 | if (y > 3) { 24 | z = y; 25 | uint256 x = y / 2 + 1; 26 | while (x < z) { 27 | z = x; 28 | x = (y / x + x) / 2; 29 | } 30 | } else if (y != 0) { 31 | z = 1; 32 | } 33 | } 34 | 35 | uint256 internal constant WAD = 10**18; 36 | uint256 internal constant RAY = 10**27; 37 | 38 | function rmul(uint256 x, uint256 y) internal pure returns (uint256 z) { 39 | z = add(mul(x, y), RAY / 2) / RAY; 40 | } 41 | 42 | function wmul(uint256 x, uint256 y) internal pure returns (uint256 z) { 43 | z = add(mul(x, y), WAD / 2) / WAD; 44 | } 45 | 46 | function rdiv(uint256 x, uint256 y) internal pure returns (uint256 z) { 47 | z = add(mul(x, RAY), y / 2) / y; 48 | } 49 | 50 | function wdiv(uint256 x, uint256 y) internal pure returns (uint256 z) { 51 | z = add(mul(x, WAD), y / 2) / y; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /scripts/command.ts: -------------------------------------------------------------------------------- 1 | import { spawn } from "child_process"; 2 | 3 | interface ICommand { 4 | readonly cmd: string; 5 | readonly args: string[]; 6 | readonly env: { 7 | [param: string]: string; 8 | }; 9 | } 10 | 11 | export async function execScript(input: ICommand): Promise { 12 | return new Promise((resolve, reject) => { 13 | const cmdEnv = Object.create(process.env); 14 | for (const param in input.env) { 15 | cmdEnv[param] = input.env[param]; 16 | } 17 | 18 | const proc = spawn(input.cmd, [...input.args], { 19 | env: cmdEnv, 20 | shell: true, 21 | stdio: "inherit", 22 | }); 23 | 24 | proc.on("exit", code => { 25 | if (code !== 0) { 26 | reject(code); 27 | return; 28 | } 29 | 30 | resolve(code); 31 | }); 32 | }); 33 | } 34 | -------------------------------------------------------------------------------- /scripts/connectors.ts: -------------------------------------------------------------------------------- 1 | export const connectors: Record> = { 2 | mainnet: ["InstaCompoundIIIResolver", "InstaERC20Resolver", "InstaUniswapV3Resolver"], 3 | polygon: [], 4 | avalanche: [], 5 | base: ["InstaCompoundIIIResolverBase", "InstaERC20ResolverBase", "InstaUniswapV3ResolverBase"], 6 | }; 7 | -------------------------------------------------------------------------------- /scripts/deploy.ts: -------------------------------------------------------------------------------- 1 | import { Contract } from "@ethersproject/contracts"; 2 | // We require the Hardhat Runtime Environment explicitly here. This is optional but useful for running the 3 | // script in a standalone fashion through `node