Feature Tip: Add private address tag to any address under My Name Tag !
More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 1,318 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Remove Liquidity... | 20506669 | 10 days ago | IN | 0 ETH | 0.00085184 | ||||
Swap P Ts For Ta... | 15973987 | 646 days ago | IN | 0 ETH | 0.00304797 | ||||
Remove Liquidity | 15973967 | 646 days ago | IN | 0 ETH | 0.00357171 | ||||
Swap P Ts For Ta... | 15973680 | 646 days ago | IN | 0 ETH | 0.0032583 | ||||
Add Liquidity Fr... | 15961300 | 647 days ago | IN | 0 ETH | 0.01154087 | ||||
Swap P Ts For Ta... | 15959432 | 648 days ago | IN | 0 ETH | 0.00281183 | ||||
Swap P Ts For Ta... | 15959423 | 648 days ago | IN | 0 ETH | 0.00295566 | ||||
Add Liquidity Fr... | 15957418 | 648 days ago | IN | 0 ETH | 0.00474049 | ||||
Migrate Liquidit... | 15957366 | 648 days ago | IN | 0 ETH | 0.0068955 | ||||
Swap Y Ts For Ta... | 15957331 | 648 days ago | IN | 0 ETH | 0.00460528 | ||||
Swap Target For ... | 15952877 | 649 days ago | IN | 0 ETH | 0.00293809 | ||||
Add Liquidity Fr... | 15922066 | 653 days ago | IN | 0 ETH | 0.01233871 | ||||
Add Liquidity Fr... | 15922056 | 653 days ago | IN | 0 ETH | 0.01428839 | ||||
Add Liquidity Fr... | 15919363 | 653 days ago | IN | 0 ETH | 0.0184739 | ||||
Add Liquidity Fr... | 15917041 | 654 days ago | IN | 0 ETH | 0.01019423 | ||||
Add Liquidity Fr... | 15914456 | 654 days ago | IN | 0 ETH | 0.00964927 | ||||
Remove Liquidity | 15914406 | 654 days ago | IN | 0 ETH | 0.00485296 | ||||
Add Liquidity Fr... | 15913860 | 654 days ago | IN | 0 ETH | 0.00882196 | ||||
Migrate Liquidit... | 15907509 | 655 days ago | IN | 0 ETH | 0.00707403 | ||||
Swap Underlying ... | 15905267 | 655 days ago | IN | 0 ETH | 0.00698036 | ||||
Add Liquidity Fr... | 15904054 | 655 days ago | IN | 0 ETH | 0.01139138 | ||||
Add Liquidity Fr... | 15899058 | 656 days ago | IN | 0 ETH | 0.01544227 | ||||
Add Liquidity Fr... | 15899055 | 656 days ago | IN | 0 ETH | 0.01828453 | ||||
Remove Liquidity | 15899027 | 656 days ago | IN | 0 ETH | 0.00809029 | ||||
Swap Underlying ... | 15898909 | 656 days ago | IN | 0 ETH | 0.00844984 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Name:
Periphery
Compiler Version
v0.8.11+commit.d7f03943
Optimization Enabled:
Yes with 15000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { SafeTransferLib } from "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; import { FixedMath } from "./external/FixedMath.sol"; import { BalancerVault, IAsset } from "./external/balancer/Vault.sol"; import { BalancerPool } from "./external/balancer/Pool.sol"; import { IERC3156FlashBorrower } from "./external/flashloan/IERC3156FlashBorrower.sol"; // Internal references import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; import { Levels } from "@sense-finance/v1-utils/src/libs/Levels.sol"; import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { BaseAdapter as Adapter } from "./adapters/BaseAdapter.sol"; import { BaseFactory as AdapterFactory } from "./adapters/BaseFactory.sol"; import { Divider } from "./Divider.sol"; import { PoolManager } from "@sense-finance/v1-fuse/src/PoolManager.sol"; interface SpaceFactoryLike { function create(address, uint256) external returns (address); function pools(address adapter, uint256 maturity) external view returns (address); } /// @title Periphery contract Periphery is Trust, IERC3156FlashBorrower { using FixedMath for uint256; using SafeTransferLib for ERC20; using Levels for uint256; /* ========== PUBLIC CONSTANTS ========== */ /// @notice Lower bound on the amount of Claim tokens one can swap in for Target uint256 public constant MIN_YT_SWAP_IN = 0.000001e18; /// @notice Acceptable error when estimating the tokens resulting from a specific swap uint256 public constant PRICE_ESTIMATE_ACCEPTABLE_ERROR = 0.00000001e18; /* ========== PUBLIC IMMUTABLES ========== */ /// @notice Sense core Divider address Divider public immutable divider; /// @notice Sense core Divider address BalancerVault public immutable balancerVault; /* ========== PUBLIC MUTABLE STORAGE ========== */ /// @notice Sense core Divider address PoolManager public poolManager; /// @notice Sense core Divider address SpaceFactoryLike public spaceFactory; /// @notice adapter factories -> is supported mapping(address => bool) public factories; /// @notice adapter -> bool mapping(address => bool) public verified; /* ========== DATA STRUCTURES ========== */ struct PoolLiquidity { ERC20[] tokens; uint256[] amounts; uint256 minBptOut; } constructor( address _divider, address _poolManager, address _spaceFactory, address _balancerVault ) Trust(msg.sender) { divider = Divider(_divider); poolManager = PoolManager(_poolManager); spaceFactory = SpaceFactoryLike(_spaceFactory); balancerVault = BalancerVault(_balancerVault); } /* ========== SERIES / ADAPTER MANAGEMENT ========== */ /// @notice Sponsor a new Series in any adapter previously onboarded onto the Divider /// @dev Called by an external address, initializes a new series in the Divider /// @param adapter Adapter to associate with the Series /// @param maturity Maturity date for the Series, in units of unix time /// @param withPool Whether to deploy a Space pool or not (only works for unverified adapters) function sponsorSeries( address adapter, uint256 maturity, bool withPool ) external returns (address pt, address yt) { (, address stake, uint256 stakeSize) = Adapter(adapter).getStakeAndTarget(); // Transfer stakeSize from sponsor into this contract ERC20(stake).safeTransferFrom(msg.sender, address(this), stakeSize); // Approve divider to withdraw stake assets ERC20(stake).approve(address(divider), stakeSize); (pt, yt) = divider.initSeries(adapter, maturity, msg.sender); // Space pool is always created for verified adapters whilst is optional for unverified ones. // Automatically queueing series is only for verified adapters if (verified[adapter]) { poolManager.queueSeries(adapter, maturity, spaceFactory.create(adapter, maturity)); } else { if (withPool) { spaceFactory.create(adapter, maturity); } } emit SeriesSponsored(adapter, maturity, msg.sender); } /// @notice Deploy and onboard a Adapter /// @dev Called by external address, deploy a new Adapter via an Adapter Factory /// @param f Factory to use /// @param target Target to onboard /// @param data Additional encoded data needed to deploy the adapter function deployAdapter( address f, address target, bytes memory data ) external returns (address adapter) { if (!factories[f]) revert Errors.FactoryNotSupported(); adapter = AdapterFactory(f).deployAdapter(target, data); emit AdapterDeployed(adapter); _verifyAdapter(adapter, true); _onboardAdapter(adapter, true); } /* ========== LIQUIDITY UTILS ========== */ /// @notice Swap Target to Principal Tokens of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param tBal Balance of Target to sell /// @param minAccepted Min accepted amount of PT /// @return ptBal amount of PT received function swapTargetForPTs( address adapter, uint256 maturity, uint256 tBal, uint256 minAccepted ) external returns (uint256 ptBal) { ERC20(Adapter(adapter).target()).safeTransferFrom(msg.sender, address(this), tBal); // pull target return _swapTargetForPTs(adapter, maturity, tBal, minAccepted); } /// @notice Swap Underlying to Principal Tokens of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param uBal Balance of Underlying to sell /// @param minAccepted Min accepted amount of PT /// @return ptBal amount of PT received function swapUnderlyingForPTs( address adapter, uint256 maturity, uint256 uBal, uint256 minAccepted ) external returns (uint256 ptBal) { ERC20 underlying = ERC20(Adapter(adapter).underlying()); underlying.safeTransferFrom(msg.sender, address(this), uBal); // pull underlying uint256 tBal = Adapter(adapter).wrapUnderlying(uBal); // wrap underlying into target ptBal = _swapTargetForPTs(adapter, maturity, tBal, minAccepted); } /// @notice Swap Target to Yield Tokens of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param targetIn Balance of Target to sell /// @param targetToBorrow Balance of Target to borrow /// @param minOut Min accepted amount of YT /// @return targetBal amount of Target sent back /// @return ytBal amount of YT received function swapTargetForYTs( address adapter, uint256 maturity, uint256 targetIn, uint256 targetToBorrow, uint256 minOut ) external returns (uint256 targetBal, uint256 ytBal) { ERC20(Adapter(adapter).target()).safeTransferFrom(msg.sender, address(this), targetIn); (targetBal, ytBal) = _flashBorrowAndSwapToYTs(adapter, maturity, targetIn, targetToBorrow, minOut); ERC20(Adapter(adapter).target()).safeTransfer(msg.sender, targetBal); ERC20(divider.yt(adapter, maturity)).safeTransfer(msg.sender, ytBal); } /// @notice Swap Underlying to Yield of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param underlyingIn Balance of Underlying to sell /// @param targetToBorrow Balance of Target to borrow /// @param minOut Min accepted amount of YT /// @return targetBal amount of Target sent back /// @return ytBal amount of YT received function swapUnderlyingForYTs( address adapter, uint256 maturity, uint256 underlyingIn, uint256 targetToBorrow, uint256 minOut ) external returns (uint256 targetBal, uint256 ytBal) { ERC20 underlying = ERC20(Adapter(adapter).underlying()); underlying.safeTransferFrom(msg.sender, address(this), underlyingIn); // Pull Underlying // Wrap Underlying into Target and swap it for YTs uint256 targetIn = Adapter(adapter).wrapUnderlying(underlyingIn); (targetBal, ytBal) = _flashBorrowAndSwapToYTs(adapter, maturity, targetIn, targetToBorrow, minOut); ERC20(Adapter(adapter).target()).safeTransfer(msg.sender, targetBal); ERC20(divider.yt(adapter, maturity)).safeTransfer(msg.sender, ytBal); } /// @notice Swap Principal Tokens for Target of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param ptBal Balance of PT to sell /// @param minAccepted Min accepted amount of Target function swapPTsForTarget( address adapter, uint256 maturity, uint256 ptBal, uint256 minAccepted ) external returns (uint256 tBal) { tBal = _swapPTsForTarget(adapter, maturity, ptBal, minAccepted); // swap Principal Tokens for target ERC20(Adapter(adapter).target()).safeTransfer(msg.sender, tBal); // transfer target to msg.sender } /// @notice Swap Principal Tokens for Underlying of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param ptBal Balance of PT to sell /// @param minAccepted Min accepted amount of Target function swapPTsForUnderlying( address adapter, uint256 maturity, uint256 ptBal, uint256 minAccepted ) external returns (uint256 uBal) { uint256 tBal = _swapPTsForTarget(adapter, maturity, ptBal, minAccepted); // swap Principal Tokens for target uBal = Adapter(adapter).unwrapTarget(tBal); // unwrap target into underlying ERC20(Adapter(adapter).underlying()).safeTransfer(msg.sender, uBal); // transfer underlying to msg.sender } /// @notice Swap YT for Target of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param ytBal Balance of Yield Tokens to swap function swapYTsForTarget( address adapter, uint256 maturity, uint256 ytBal ) external returns (uint256 tBal) { tBal = _swapYTsForTarget(msg.sender, adapter, maturity, ytBal); ERC20(Adapter(adapter).target()).safeTransfer(msg.sender, tBal); } /// @notice Swap YT for Underlying of a particular series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param ytBal Balance of Yield Tokens to swap function swapYTsForUnderlying( address adapter, uint256 maturity, uint256 ytBal ) external returns (uint256 uBal) { uint256 tBal = _swapYTsForTarget(msg.sender, adapter, maturity, ytBal); uBal = Adapter(adapter).unwrapTarget(tBal); ERC20(Adapter(adapter).underlying()).safeTransfer(msg.sender, uBal); } /// @notice Adds liquidity providing target /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param tBal Balance of Target to provide /// @param mode 0 = issues and sell YT, 1 = issue and hold YT /// @param minBptOut Minimum BPT the user will accept out for this transaction /// @dev see return description of _addLiquidity function addLiquidityFromTarget( address adapter, uint256 maturity, uint256 tBal, uint8 mode, uint256 minBptOut ) external returns ( uint256 tAmount, uint256 issued, uint256 lpShares ) { ERC20(Adapter(adapter).target()).safeTransferFrom(msg.sender, address(this), tBal); (tAmount, issued, lpShares) = _addLiquidity(adapter, maturity, tBal, mode, minBptOut); } /// @notice Adds liquidity providing underlying /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param uBal Balance of Underlying to provide /// @param mode 0 = issues and sell YT, 1 = issue and hold YT /// @param minBptOut Minimum BPT the user will accept out for this transaction /// @dev see return description of _addLiquidity function addLiquidityFromUnderlying( address adapter, uint256 maturity, uint256 uBal, uint8 mode, uint256 minBptOut ) external returns ( uint256 tAmount, uint256 issued, uint256 lpShares ) { ERC20 underlying = ERC20(Adapter(adapter).underlying()); underlying.safeTransferFrom(msg.sender, address(this), uBal); // Wrap Underlying into Target uint256 tBal = Adapter(adapter).wrapUnderlying(uBal); (tAmount, issued, lpShares) = _addLiquidity(adapter, maturity, tBal, mode, minBptOut); } /// @notice Removes liquidity providing an amount of LP tokens and returns target /// @dev More info on `minAmountsOut`: https://github.com/balancer-labs/docs-developers/blob/main/resources/joins-and-exits/pool-exits.md#minamountsout /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param lpBal Balance of LP tokens to provide /// @param minAmountsOut minimum accepted amounts of PTs and Target given the amount of LP shares provided /// @param minAccepted only used when removing liquidity on/after maturity and its the min accepted when swapping Principal Tokens to underlying /// @param intoTarget if true, it will try to swap PTs into Target. Will revert if there's not enough liquidity to perform the swap. /// @return tBal amount of target received and ptBal amount of Principal Tokens (in case it's called after maturity and redeem is restricted) function removeLiquidity( address adapter, uint256 maturity, uint256 lpBal, uint256[] memory minAmountsOut, uint256 minAccepted, bool intoTarget ) external returns (uint256 tBal, uint256 ptBal) { (tBal, ptBal) = _removeLiquidity(adapter, maturity, lpBal, minAmountsOut, minAccepted, intoTarget); ERC20(Adapter(adapter).target()).safeTransfer(msg.sender, tBal); // Send Target back to the User } /// @notice Removes liquidity providing an amount of LP tokens and returns underlying /// @dev More info on `minAmountsOut`: https://github.com/balancer-labs/docs-developers/blob/main/resources/joins-and-exits/pool-exits.md#minamountsout /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param lpBal Balance of LP tokens to provide /// @param minAmountsOut minimum accepted amounts of PTs and Target given the amount of LP shares provided /// @param minAccepted only used when removing liquidity on/after maturity and its the min accepted when swapping Principal Tokens to underlying /// @param intoTarget if true, it will try to swap PTs into Target. Will revert if there's not enough liquidity to perform the swap. /// @return uBal amount of underlying received and ptBal Principal Tokens (in case it's called after maturity and redeem is restricted or intoTarget is false) function removeLiquidityAndUnwrapTarget( address adapter, uint256 maturity, uint256 lpBal, uint256[] memory minAmountsOut, uint256 minAccepted, bool intoTarget ) external returns (uint256 uBal, uint256 ptBal) { uint256 tBal; (tBal, ptBal) = _removeLiquidity(adapter, maturity, lpBal, minAmountsOut, minAccepted, intoTarget); ERC20(Adapter(adapter).underlying()).safeTransfer(msg.sender, uBal = Adapter(adapter).unwrapTarget(tBal)); // Send Underlying back to the User } /// @notice Migrates liquidity position from one series to another /// @dev More info on `minAmountsOut`: https://github.com/balancer-labs/docs-developers/blob/main/resources/joins-and-exits/pool-exits.md#minamountsout /// @param srcAdapter Adapter address for the source Series /// @param dstAdapter Adapter address for the destination Series /// @param srcMaturity Maturity date for the source Series /// @param dstMaturity Maturity date for the destination Series /// @param lpBal Balance of LP tokens to provide /// @param minAmountsOut Minimum accepted amounts of PTs and Target given the amount of LP shares provided /// @param minAccepted Min accepted amount of target when swapping Principal Tokens (only used when removing liquidity on/after maturity) /// @param mode 0 = issues and sell YT, 1 = issue and hold YT /// @param intoTarget if true, it will try to swap PTs into Target. Will revert if there's not enough liquidity to perform the swap /// @param minBptOut Minimum BPT the user will accept out for this transaction /// @dev see return description of _addLiquidity. It also returns amount of PTs (in case it's called after maturity and redeem is restricted or inttoTarget is false) function migrateLiquidity( address srcAdapter, address dstAdapter, uint256 srcMaturity, uint256 dstMaturity, uint256 lpBal, uint256[] memory minAmountsOut, uint256 minAccepted, uint8 mode, bool intoTarget, uint256 minBptOut ) external returns ( uint256 tAmount, uint256 issued, uint256 lpShares, uint256 ptBal ) { if (Adapter(srcAdapter).target() != Adapter(dstAdapter).target()) revert Errors.TargetMismatch(); uint256 tBal; (tBal, ptBal) = _removeLiquidity(srcAdapter, srcMaturity, lpBal, minAmountsOut, minAccepted, intoTarget); (tAmount, issued, lpShares) = _addLiquidity(dstAdapter, dstMaturity, tBal, mode, minBptOut); } /* ========== ADMIN ========== */ /// @notice Enable or disable a factory /// @param f Factory's address /// @param isOn Flag setting this factory to enabled or disabled function setFactory(address f, bool isOn) external requiresTrust { if (factories[f] == isOn) revert Errors.ExistingValue(); factories[f] = isOn; emit FactoryChanged(f, isOn); } /// @notice Update the address for the Space Factory /// @param newSpaceFactory The Space Factory addresss to set function setSpaceFactory(address newSpaceFactory) external requiresTrust { spaceFactory = SpaceFactoryLike(newSpaceFactory); emit SpaceFactoryChanged(newSpaceFactory); } /// @notice Update the address for the Pool Manager /// @param newPoolManager The Pool Manager addresss to set function setPoolManager(address newPoolManager) external requiresTrust { poolManager = PoolManager(newPoolManager); emit PoolManagerChanged(newPoolManager); } /// @dev Verifies an Adapter and optionally adds the Target to the money market /// @param adapter Adapter to verify function verifyAdapter(address adapter, bool addToPool) public requiresTrust { _verifyAdapter(adapter, addToPool); } function _verifyAdapter(address adapter, bool addToPool) private { verified[adapter] = true; if (addToPool) poolManager.addTarget(Adapter(adapter).target(), adapter); emit AdapterVerified(adapter); } /// @notice Onboard a single Adapter w/o needing a factory /// @dev Called by a trusted address, approves Target for issuance, and onboards adapter to the Divider /// @param adapter Adapter to onboard /// @param addAdapter Whether to call divider.addAdapter or not (useful e.g when upgrading Periphery) function onboardAdapter(address adapter, bool addAdapter) public { if (!divider.permissionless() && !isTrusted[msg.sender]) revert Errors.OnlyPermissionless(); _onboardAdapter(adapter, addAdapter); } function _onboardAdapter(address adapter, bool addAdapter) private { ERC20 target = ERC20(Adapter(adapter).target()); target.approve(address(divider), type(uint256).max); target.approve(address(adapter), type(uint256).max); ERC20(Adapter(adapter).underlying()).approve(address(adapter), type(uint256).max); if (addAdapter) divider.addAdapter(adapter); emit AdapterOnboarded(adapter); } /* ========== INTERNAL UTILS ========== */ function _swap( address assetIn, address assetOut, uint256 amountIn, bytes32 poolId, uint256 minAccepted ) internal returns (uint256 amountOut) { // approve vault to spend tokenIn ERC20(assetIn).approve(address(balancerVault), amountIn); BalancerVault.SingleSwap memory request = BalancerVault.SingleSwap({ poolId: poolId, kind: BalancerVault.SwapKind.GIVEN_IN, assetIn: IAsset(assetIn), assetOut: IAsset(assetOut), amount: amountIn, userData: hex"" }); BalancerVault.FundManagement memory funds = BalancerVault.FundManagement({ sender: address(this), fromInternalBalance: false, recipient: payable(address(this)), toInternalBalance: false }); amountOut = balancerVault.swap(request, funds, minAccepted, type(uint256).max); emit Swapped(msg.sender, poolId, assetIn, assetOut, amountIn, amountOut, msg.sig); } function _swapPTsForTarget( address adapter, uint256 maturity, uint256 ptBal, uint256 minAccepted ) internal returns (uint256 tBal) { address principalToken = divider.pt(adapter, maturity); ERC20(principalToken).safeTransferFrom(msg.sender, address(this), ptBal); // pull principal BalancerPool pool = BalancerPool(spaceFactory.pools(adapter, maturity)); tBal = _swap(principalToken, Adapter(adapter).target(), ptBal, pool.getPoolId(), minAccepted); // swap Principal Tokens for underlying } function _swapTargetForPTs( address adapter, uint256 maturity, uint256 tBal, uint256 minAccepted ) internal returns (uint256 ptBal) { address principalToken = divider.pt(adapter, maturity); BalancerPool pool = BalancerPool(spaceFactory.pools(adapter, maturity)); ptBal = _swap(Adapter(adapter).target(), principalToken, tBal, pool.getPoolId(), minAccepted); // swap target for Principal Tokens ERC20(principalToken).safeTransfer(msg.sender, ptBal); // transfer bought principal to user } function _swapYTsForTarget( address sender, address adapter, uint256 maturity, uint256 ytBal ) internal returns (uint256 tBal) { address yt = divider.yt(adapter, maturity); // Because there's some margin of error in the pricing functions here, smaller // swaps will be unreliable. Tokens with more than 18 decimals are not supported. if (ytBal * 10**(18 - ERC20(yt).decimals()) <= MIN_YT_SWAP_IN) revert Errors.SwapTooSmall(); BalancerPool pool = BalancerPool(spaceFactory.pools(adapter, maturity)); // Transfer YTs into this contract if needed if (sender != address(this)) ERC20(yt).safeTransferFrom(msg.sender, address(this), ytBal); // Calculate target to borrow by calling AMM bytes32 poolId = pool.getPoolId(); (uint256 pti, uint256 targeti) = pool.getIndices(); (ERC20[] memory tokens, uint256[] memory balances, ) = balancerVault.getPoolTokens(poolId); // Determine how much Target we'll need in to get `ytBal` balance of PT out // (space doesn't directly use of the fields from `SwapRequest` beyond `poolId`, so the values after are placeholders) uint256 targetToBorrow = BalancerPool(pool).onSwap( BalancerPool.SwapRequest({ kind: BalancerVault.SwapKind.GIVEN_OUT, tokenIn: tokens[targeti], tokenOut: tokens[pti], amount: ytBal, poolId: poolId, lastChangeBlock: 0, from: address(0), to: address(0), userData: "" }), balances[targeti], balances[pti] ); // Flash borrow target (following actions in `onFlashLoan`) tBal = _flashBorrowAndSwapFromYTs(adapter, maturity, ytBal, targetToBorrow); } /// @return tAmount if mode = 0, target received from selling YTs, otherwise, returns 0 /// @return issued returns amount of YTs issued (and received) except first provision which returns 0 /// @return lpShares Space LP shares received given the liquidity added function _addLiquidity( address adapter, uint256 maturity, uint256 tBal, uint8 mode, uint256 minBptOut ) internal returns ( uint256 tAmount, uint256 issued, uint256 lpShares ) { // (1) compute target, issue PTs & YTs & add liquidity to space (issued, lpShares) = _computeIssueAddLiq(adapter, maturity, tBal, minBptOut); if (issued > 0) { // issue = 0 means that we are on the first pool provision or that the pt:target ratio is 0:target if (mode == 0) { // (2) Sell YTs tAmount = _swapYTsForTarget(address(this), adapter, maturity, issued); // (3) Send remaining Target back to the User ERC20(Adapter(adapter).target()).safeTransfer(msg.sender, tAmount); } else { // (4) Send YTs back to the User ERC20(divider.yt(adapter, maturity)).safeTransfer(msg.sender, issued); } } } /// @dev Calculates amount of Principal Tokens in target terms (see description on `_computeTarget`) then issues /// PTs and YTs with the calculated amount and finally adds liquidity to space with the PTs issued /// and the diff between the target initially passed and the calculated amount function _computeIssueAddLiq( address adapter, uint256 maturity, uint256 tBal, uint256 minBptOut ) internal returns (uint256 issued, uint256 lpShares) { BalancerPool pool = BalancerPool(spaceFactory.pools(adapter, maturity)); // Compute target (ERC20[] memory tokens, uint256[] memory balances, ) = balancerVault.getPoolTokens(pool.getPoolId()); (uint256 pti, uint256 targeti) = pool.getIndices(); // Ensure we have the right token Indices // We do not add Principal Token liquidity if it haven't been initialized yet bool ptInitialized = balances[pti] != 0; uint256 ptBalInTarget = ptInitialized ? _computeTarget(adapter, balances[pti], balances[targeti], tBal) : 0; // Issue PT & YT (skip if first pool provision) issued = ptBalInTarget > 0 ? divider.issue(adapter, maturity, ptBalInTarget) : 0; // Add liquidity to Space & send the LP Shares to recipient uint256[] memory amounts = new uint256[](2); amounts[targeti] = tBal - ptBalInTarget; amounts[pti] = issued; lpShares = _addLiquidityToSpace(pool, PoolLiquidity(tokens, amounts, minBptOut)); } /// @dev Based on pt:target ratio from current pool reserves and tBal passed /// calculates amount of tBal needed so as to issue PTs that would keep the ratio function _computeTarget( address adapter, uint256 ptiBal, uint256 targetiBal, uint256 tBal ) internal returns (uint256 tBalForIssuance) { return tBal.fmul( ptiBal.fdiv( Adapter(adapter).scale().fmul(FixedMath.WAD - Adapter(adapter).ifee()).fmul(targetiBal) + ptiBal ) ); } function _removeLiquidity( address adapter, uint256 maturity, uint256 lpBal, uint256[] memory minAmountsOut, uint256 minAccepted, bool intoTarget ) internal returns (uint256 tBal, uint256 ptBal) { address target = Adapter(adapter).target(); address pt = divider.pt(adapter, maturity); BalancerPool pool = BalancerPool(spaceFactory.pools(adapter, maturity)); bytes32 poolId = pool.getPoolId(); // (0) Pull LP tokens from sender ERC20(address(pool)).safeTransferFrom(msg.sender, address(this), lpBal); // (1) Remove liquidity from Space uint256 _ptBal; (tBal, _ptBal) = _removeLiquidityFromSpace(poolId, pt, target, minAmountsOut, lpBal); if (divider.mscale(adapter, maturity) > 0) { if (uint256(Adapter(adapter).level()).redeemRestricted()) { ptBal = _ptBal; } else { // (2) Redeem Principal Tokens for Target tBal += divider.redeem(adapter, maturity, _ptBal); } } else { // (2) Sell Principal Tokens for Target (if there are) if (_ptBal > 0 && intoTarget) { tBal += _swap(pt, target, _ptBal, poolId, minAccepted); } else { ptBal = _ptBal; } } if (ptBal > 0) ERC20(pt).safeTransfer(msg.sender, ptBal); // Send PT back to the User } /// @notice Initiates a flash loan of Target, swaps target amount to PTs and combines /// @param adapter adapter /// @param maturity maturity /// @param ytBalIn YT amount the user has sent in /// @param amountToBorrow target amount to borrow /// @return tBal amount of Target obtained from a sale of YTs function _flashBorrowAndSwapFromYTs( address adapter, uint256 maturity, uint256 ytBalIn, uint256 amountToBorrow ) internal returns (uint256 tBal) { ERC20 target = ERC20(Adapter(adapter).target()); uint256 decimals = target.decimals(); uint256 acceptableError = decimals < 9 ? 1 : PRICE_ESTIMATE_ACCEPTABLE_ERROR / 10**(18 - decimals); bytes memory data = abi.encode(adapter, uint256(maturity), ytBalIn, ytBalIn - acceptableError, true); bool result = Adapter(adapter).flashLoan(this, address(target), amountToBorrow, data); if (!result) revert Errors.FlashBorrowFailed(); tBal = target.balanceOf(address(this)); } /// @notice Initiates a flash loan of Target, issues PTs/YTs and swaps the PTs to Target /// @param adapter adapter /// @param maturity taturity /// @param targetIn Target amount the user has sent in /// @param amountToBorrow Target amount to borrow /// @param minOut minimum amount of Target accepted out for the issued PTs /// @return targetBal amount of Target remaining after the flashloan has been paid back /// @return ytBal amount of YTs issued with the borrowed Target and the Target sent in function _flashBorrowAndSwapToYTs( address adapter, uint256 maturity, uint256 targetIn, uint256 amountToBorrow, uint256 minOut ) internal returns (uint256 targetBal, uint256 ytBal) { bytes memory data = abi.encode(adapter, uint256(maturity), targetIn, minOut, false); bool result = Adapter(adapter).flashLoan(this, Adapter(adapter).target(), amountToBorrow, data); if (!result) revert Errors.FlashBorrowFailed(); targetBal = ERC20(Adapter(adapter).target()).balanceOf(address(this)); ytBal = ERC20(divider.yt(adapter, maturity)).balanceOf(address(this)); emit YTsPurchased(msg.sender, adapter, maturity, targetIn, targetBal, ytBal); } /// @dev ERC-3156 Flash loan callback function onFlashLoan( address initiator, address, /* token */ uint256 amountBorrrowed, uint256, /* fee */ bytes calldata data ) external returns (bytes32) { (address adapter, uint256 maturity, uint256 amountIn, uint256 minOut, bool ytToTarget) = abi.decode( data, (address, uint256, uint256, uint256, bool) ); if (msg.sender != address(adapter)) revert Errors.FlashUntrustedBorrower(); if (initiator != address(this)) revert Errors.FlashUntrustedLoanInitiator(); BalancerPool pool = BalancerPool(spaceFactory.pools(adapter, maturity)); if (ytToTarget) { ERC20 target = ERC20(Adapter(adapter).target()); // Swap Target for PTs uint256 ptBal = _swap( address(target), divider.pt(adapter, maturity), target.balanceOf(address(this)), pool.getPoolId(), minOut // min pt out ); // Combine PTs and YTs divider.combine(adapter, maturity, ptBal < amountIn ? ptBal : amountIn); } else { // Issue PTs and YTs divider.issue(adapter, maturity, amountIn + amountBorrrowed); ERC20 pt = ERC20(divider.pt(adapter, maturity)); // Swap PTs for Target _swap( address(pt), Adapter(adapter).target(), pt.balanceOf(address(this)), pool.getPoolId(), minOut // min Target out ); // minOut should be close to amountBorrrowed so that minimal Target dust is sent back to the caller // Flashloaner contract will revert if not enough Target has been swapped out to pay back the loan } return keccak256("ERC3156FlashBorrower.onFlashLoan"); } function _addLiquidityToSpace(BalancerPool pool, PoolLiquidity memory liq) internal returns (uint256 lpBal) { bytes32 poolId = pool.getPoolId(); IAsset[] memory assets = _convertERC20sToAssets(liq.tokens); for (uint8 i; i < liq.tokens.length; i++) { // Tokens and amounts must be in same order liq.tokens[i].approve(address(balancerVault), liq.amounts[i]); } // Behaves like EXACT_TOKENS_IN_FOR_BPT_OUT, user sends precise quantities of tokens, // and receives an estimated but unknown (computed at run time) quantity of BPT BalancerVault.JoinPoolRequest memory request = BalancerVault.JoinPoolRequest({ assets: assets, maxAmountsIn: liq.amounts, userData: abi.encode(liq.amounts, liq.minBptOut), fromInternalBalance: false }); balancerVault.joinPool(poolId, address(this), msg.sender, request); lpBal = ERC20(address(pool)).balanceOf(msg.sender); } function _removeLiquidityFromSpace( bytes32 poolId, address pt, address target, uint256[] memory minAmountsOut, uint256 lpBal ) internal returns (uint256 tBal, uint256 ptBal) { // ExitPoolRequest params (ERC20[] memory tokens, , ) = balancerVault.getPoolTokens(poolId); IAsset[] memory assets = _convertERC20sToAssets(tokens); BalancerVault.ExitPoolRequest memory request = BalancerVault.ExitPoolRequest({ assets: assets, minAmountsOut: minAmountsOut, userData: abi.encode(lpBal), toInternalBalance: false }); balancerVault.exitPool(poolId, address(this), payable(address(this)), request); tBal = ERC20(target).balanceOf(address(this)); ptBal = ERC20(pt).balanceOf(address(this)); } /// @notice From: https://github.com/balancer-labs/balancer-examples/blob/master/packages/liquidity-provision/contracts/LiquidityProvider.sol#L33 /// @dev This helper function is a fast and cheap way to convert between IERC20[] and IAsset[] types function _convertERC20sToAssets(ERC20[] memory tokens) internal pure returns (IAsset[] memory assets) { assembly { assets := tokens } } /* ========== LOGS ========== */ event FactoryChanged(address indexed factory, bool indexed isOn); event SpaceFactoryChanged(address newSpaceFactory); event PoolManagerChanged(address newPoolManager); event SeriesSponsored(address indexed adapter, uint256 indexed maturity, address indexed sponsor); event AdapterDeployed(address indexed adapter); event AdapterOnboarded(address indexed adapter); event AdapterVerified(address indexed adapter); event YTsPurchased( address indexed sender, address adapter, uint256 maturity, uint256 targetIn, uint256 targetReturned, uint256 ytOut ); event Swapped( address indexed sender, bytes32 indexed poolId, address assetIn, address assetOut, uint256 amountIn, uint256 amountOut, bytes4 indexed sig ); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Modern and gas efficient ERC20 + EIP-2612 implementation. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol) /// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it. abstract contract ERC20 { /*/////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); /*/////////////////////////////////////////////////////////////// METADATA STORAGE //////////////////////////////////////////////////////////////*/ string public name; string public symbol; uint8 public immutable decimals; /*/////////////////////////////////////////////////////////////// ERC20 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; /*/////////////////////////////////////////////////////////////// EIP-2612 STORAGE //////////////////////////////////////////////////////////////*/ uint256 internal immutable INITIAL_CHAIN_ID; bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR; mapping(address => uint256) public nonces; /*/////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ constructor( string memory _name, string memory _symbol, uint8 _decimals ) { name = _name; symbol = _symbol; decimals = _decimals; INITIAL_CHAIN_ID = block.chainid; INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); } /*/////////////////////////////////////////////////////////////// ERC20 LOGIC //////////////////////////////////////////////////////////////*/ function approve(address spender, uint256 amount) public virtual returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transfer(address to, uint256 amount) public virtual returns (bool) { balanceOf[msg.sender] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(msg.sender, to, amount); return true; } function transferFrom( address from, address to, uint256 amount ) public virtual returns (bool) { uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount; balanceOf[from] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(from, to, amount); return true; } /*/////////////////////////////////////////////////////////////// EIP-2612 LOGIC //////////////////////////////////////////////////////////////*/ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED"); // Unchecked because the only math done is incrementing // the owner's nonce which cannot realistically overflow. unchecked { address recoveredAddress = ecrecover( keccak256( abi.encodePacked( "\x19\x01", DOMAIN_SEPARATOR(), keccak256( abi.encode( keccak256( "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)" ), owner, spender, value, nonces[owner]++, deadline ) ) ) ), v, r, s ); require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER"); allowance[recoveredAddress][spender] = value; } emit Approval(owner, spender, value); } function DOMAIN_SEPARATOR() public view virtual returns (bytes32) { return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator(); } function computeDomainSeparator() internal view virtual returns (bytes32) { return keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes(name)), keccak256("1"), block.chainid, address(this) ) ); } /*/////////////////////////////////////////////////////////////// INTERNAL MINT/BURN LOGIC //////////////////////////////////////////////////////////////*/ function _mint(address to, uint256 amount) internal virtual { totalSupply += amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(address(0), to, amount); } function _burn(address from, uint256 amount) internal virtual { balanceOf[from] -= amount; // Cannot underflow because a user's balance // will never be larger than the total supply. unchecked { totalSupply -= amount; } emit Transfer(from, address(0), amount); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import {ERC20} from "../tokens/ERC20.sol"; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer. /// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller. library SafeTransferLib { event Debug(bool one, bool two, uint256 retsize); /*/////////////////////////////////////////////////////////////// ETH OPERATIONS //////////////////////////////////////////////////////////////*/ function safeTransferETH(address to, uint256 amount) internal { bool success; assembly { // Transfer the ETH and store if it succeeded or not. success := call(gas(), to, amount, 0, 0, 0, 0) } require(success, "ETH_TRANSFER_FAILED"); } /*/////////////////////////////////////////////////////////////// ERC20 OPERATIONS //////////////////////////////////////////////////////////////*/ function safeTransferFrom( ERC20 token, address from, address to, uint256 amount ) internal { bool success; assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument. mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument. mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), token, 0, freeMemoryPointer, 100, 0, 32) ) } require(success, "TRANSFER_FROM_FAILED"); } function safeTransfer( ERC20 token, address to, uint256 amount ) internal { bool success; assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument. mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), token, 0, freeMemoryPointer, 68, 0, 32) ) } require(success, "TRANSFER_FAILED"); } function safeApprove( ERC20 token, address to, uint256 amount ) internal { bool success; assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument. mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), token, 0, freeMemoryPointer, 68, 0, 32) ) } require(success, "APPROVE_FAILED"); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; /// @title Fixed point arithmetic library /// @author Taken from https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol library FixedMath { uint256 internal constant WAD = 1e18; uint256 internal constant RAY = 1e27; function fmul( uint256 x, uint256 y, uint256 baseUnit ) internal pure returns (uint256) { return mulDivDown(x, y, baseUnit); // Equivalent to (x * y) / baseUnit rounded down. } function fmul(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down. } function fmulUp( uint256 x, uint256 y, uint256 baseUnit ) internal pure returns (uint256) { return mulDivUp(x, y, baseUnit); // Equivalent to (x * y) / baseUnit rounded up. } function fmulUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up. } function fdiv( uint256 x, uint256 y, uint256 baseUnit ) internal pure returns (uint256) { return mulDivDown(x, baseUnit, y); // Equivalent to (x * baseUnit) / y rounded down. } function fdiv(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down. } function fdivUp( uint256 x, uint256 y, uint256 baseUnit ) internal pure returns (uint256) { return mulDivUp(x, baseUnit, y); // Equivalent to (x * baseUnit) / y rounded up. } function fdivUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up. } function mulDivDown( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { assembly { // Store x * y in z for now. z := mul(x, y) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { revert(0, 0) } // Divide z by the denominator. z := div(z, denominator) } } function mulDivUp( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { assembly { // Store x * y in z for now. z := mul(x, y) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { revert(0, 0) } // First, divide z - 1 by the denominator and add 1. // We allow z - 1 to underflow if z is 0, because we multiply the // end result by 0 if z is zero, ensuring we return 0 if z is zero. z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1)) } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; interface IAsset {} interface BalancerVault { struct JoinPoolRequest { IAsset[] assets; uint256[] maxAmountsIn; bytes userData; bool fromInternalBalance; } struct ExitPoolRequest { IAsset[] assets; uint256[] minAmountsOut; bytes userData; bool toInternalBalance; } enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN } enum SwapKind { GIVEN_IN, GIVEN_OUT } struct SingleSwap { bytes32 poolId; SwapKind kind; IAsset assetIn; IAsset assetOut; uint256 amount; bytes userData; } struct FundManagement { address sender; bool fromInternalBalance; address payable recipient; bool toInternalBalance; } function getPoolTokens(bytes32 poolId) external view returns ( ERC20[] memory tokens, uint256[] memory balances, uint256 maxBlockNumber ); function getPool(bytes32 poolId) external view returns (address, PoolSpecialization); function swap( SingleSwap memory singleSwap, FundManagement memory funds, uint256 limit, uint256 deadline ) external payable returns (uint256); function joinPool( bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request ) external payable; function exitPool( bytes32 poolId, address sender, address payable recipient, ExitPoolRequest memory request ) external; }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { BalancerVault } from "./Vault.sol"; interface BalancerPool { function getTimeWeightedAverage(OracleAverageQuery[] memory queries) external view returns (uint256[] memory results); enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT } struct OracleAverageQuery { Variable variable; uint256 secs; uint256 ago; } function getSample(uint256 index) external view returns ( int256 logPairPrice, int256 accLogPairPrice, int256 logBptPrice, int256 accLogBptPrice, int256 logInvariant, int256 accLogInvariant, uint256 timestamp ); function getPoolId() external view returns (bytes32); function getVault() external view returns (address); function totalSupply() external view returns (uint256); struct SwapRequest { BalancerVault.SwapKind kind; ERC20 tokenIn; ERC20 tokenOut; uint256 amount; // Misc data bytes32 poolId; uint256 lastChangeBlock; address from; address to; bytes userData; } function onSwap( SwapRequest memory swapRequest, uint256 currentBalanceTokenIn, uint256 currentBalanceTokenOut ) external returns (uint256 amount); function getIndices() external view returns (uint256 pti, uint256 targeti); }
pragma solidity ^0.8.0; interface IERC3156FlashBorrower { /// @dev Receive a flash loan. /// @param initiator The initiator of the loan. /// @param token The loan currency. /// @param amount The amount of tokens lent. /// @param fee The additional amount of tokens to repay. /// @param data Arbitrary data structure, intended to contain user-defined parameters. /// @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan" function onFlashLoan( address initiator, address token, uint256 amount, uint256 fee, bytes calldata data ) external returns (bytes32); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.4; library Errors { // Auth error CombineRestricted(); error IssuanceRestricted(); error NotAuthorized(); error OnlyYT(); error OnlyDivider(); error OnlyPeriphery(); error OnlyPermissionless(); error RedeemRestricted(); error Untrusted(); // Adapters error TokenNotSupported(); error FlashCallbackFailed(); error SenderNotEligible(); error TargetMismatch(); error TargetNotSupported(); // Divider error AlreadySettled(); error CollectNotSettled(); error GuardCapReached(); error IssuanceFeeCapExceeded(); error IssueOnSettle(); error NotSettled(); // Input & validations error AlreadyInitialized(); error DuplicateSeries(); error ExistingValue(); error InvalidAdapter(); error InvalidMaturity(); error InvalidParam(); error NotImplemented(); error OutOfWindowBoundaries(); error SeriesDoesNotExist(); error SwapTooSmall(); error TargetParamsNotSet(); error PoolParamsNotSet(); error PTParamsNotSet(); // Periphery error FactoryNotSupported(); error FlashBorrowFailed(); error FlashUntrustedBorrower(); error FlashUntrustedLoanInitiator(); error UnexpectedSwapAmount(); error TooMuchLeftoverTarget(); // Fuse error AdapterNotSet(); error FailedBecomeAdmin(); error FailedAddTargetMarket(); error FailedToAddPTMarket(); error FailedAddLpMarket(); error OracleNotReady(); error PoolAlreadyDeployed(); error PoolNotDeployed(); error PoolNotSet(); error SeriesNotQueued(); error TargetExists(); error TargetNotInFuse(); // Tokens error MintFailed(); error RedeemFailed(); error TransferFailed(); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.7.0; library Levels { uint256 private constant _INIT_BIT = 0x1; uint256 private constant _ISSUE_BIT = 0x2; uint256 private constant _COMBINE_BIT = 0x4; uint256 private constant _COLLECT_BIT = 0x8; uint256 private constant _REDEEM_BIT = 0x10; uint256 private constant _REDEEM_HOOK_BIT = 0x20; function initRestricted(uint256 level) internal pure returns (bool) { return level & _INIT_BIT != _INIT_BIT; } function issueRestricted(uint256 level) internal pure returns (bool) { return level & _ISSUE_BIT != _ISSUE_BIT; } function combineRestricted(uint256 level) internal pure returns (bool) { return level & _COMBINE_BIT != _COMBINE_BIT; } function collectDisabled(uint256 level) internal pure returns (bool) { return level & _COLLECT_BIT != _COLLECT_BIT; } function redeemRestricted(uint256 level) internal pure returns (bool) { return level & _REDEEM_BIT != _REDEEM_BIT; } function redeemHookDisabled(uint256 level) internal pure returns (bool) { return level & _REDEEM_HOOK_BIT != _REDEEM_HOOK_BIT; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.7.0; /// @notice Ultra minimal authorization logic for smart contracts. /// @author From https://github.com/Rari-Capital/solmate/blob/fab107565a51674f3a3b5bfdaacc67f6179b1a9b/src/auth/Trust.sol abstract contract Trust { event UserTrustUpdated(address indexed user, bool trusted); mapping(address => bool) public isTrusted; constructor(address initialUser) { isTrusted[initialUser] = true; emit UserTrustUpdated(initialUser, true); } function setIsTrusted(address user, bool trusted) public virtual requiresTrust { isTrusted[user] = trusted; emit UserTrustUpdated(user, trusted); } modifier requiresTrust() { require(isTrusted[msg.sender], "UNTRUSTED"); _; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { SafeTransferLib } from "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; import { IERC3156FlashLender } from "../external/flashloan/IERC3156FlashLender.sol"; import { IERC3156FlashBorrower } from "../external/flashloan/IERC3156FlashBorrower.sol"; // Internal references import { Divider } from "../Divider.sol"; import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; /// @title Assign value to Target tokens abstract contract BaseAdapter is IERC3156FlashLender { using SafeTransferLib for ERC20; /* ========== CONSTANTS ========== */ bytes32 public constant CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan"); /* ========== PUBLIC IMMUTABLES ========== */ /// @notice Sense core Divider address address public immutable divider; /// @notice Target token to divide address public immutable target; /// @notice Underlying for the Target address public immutable underlying; /// @notice Issuance fee uint128 public immutable ifee; /// @notice adapter params AdapterParams public adapterParams; /* ========== DATA STRUCTURES ========== */ struct AdapterParams { /// @notice Oracle address address oracle; /// @notice Token to stake at issuance address stake; /// @notice Amount to stake at issuance uint256 stakeSize; /// @notice Min maturity (seconds after block.timstamp) uint256 minm; /// @notice Max maturity (seconds after block.timstamp) uint256 maxm; /// @notice WAD number representing the percentage of the total /// principal that's set aside for Yield Tokens (e.g. 0.1e18 means that 10% of the principal is reserved). /// @notice If `0`, it means no principal is set aside for Yield Tokens uint64 tilt; /// @notice The number this function returns will be used to determine its access by checking for binary /// digits using the following scheme: <onRedeem(y/n)><collect(y/n)><combine(y/n)><issue(y/n)> /// (e.g. 0101 enables `collect` and `issue`, but not `combine`) uint48 level; /// @notice 0 for monthly, 1 for weekly uint16 mode; } /* ========== METADATA STORAGE ========== */ string public name; string public symbol; constructor( address _divider, address _target, address _underlying, uint128 _ifee, AdapterParams memory _adapterParams ) { divider = _divider; target = _target; underlying = _underlying; ifee = _ifee; adapterParams = _adapterParams; name = string(abi.encodePacked(ERC20(_target).name(), " Adapter")); symbol = string(abi.encodePacked(ERC20(_target).symbol(), "-adapter")); ERC20(_target).approve(divider, type(uint256).max); ERC20(_adapterParams.stake).approve(divider, type(uint256).max); } /// @notice Loan `amount` target to `receiver`, and takes it back after the callback. /// @param receiver The contract receiving target, needs to implement the /// `onFlashLoan(address user, address adapter, uint256 maturity, uint256 amount)` interface. /// @param amount The amount of target lent. /// @param data (encoded adapter address, maturity and YT amount the use has sent in) function flashLoan( IERC3156FlashBorrower receiver, address, /* fee */ uint256 amount, bytes calldata data ) external returns (bool) { if (Divider(divider).periphery() != msg.sender) revert Errors.OnlyPeriphery(); ERC20(target).safeTransfer(address(receiver), amount); bytes32 keccak = IERC3156FlashBorrower(receiver).onFlashLoan(msg.sender, target, amount, 0, data); if (keccak != CALLBACK_SUCCESS) revert Errors.FlashCallbackFailed(); ERC20(target).safeTransferFrom(address(receiver), address(this), amount); return true; } /* ========== REQUIRED VALUE GETTERS ========== */ /// @notice Calculate and return this adapter's Scale value for the current timestamp. To be overriden by child contracts /// @dev For some Targets, such as cTokens, this is simply the exchange rate, or `supply cToken / supply underlying` /// @dev For other Targets, such as AMM LP shares, specialized logic will be required /// @dev This function _must_ return a WAD number representing the current exchange rate /// between the Target and the Underlying. /// @return value WAD Scale value function scale() external virtual returns (uint256); /// @notice Cached scale value getter /// @dev For situations where you need scale from a view function function scaleStored() external view virtual returns (uint256); /// @notice Returns the current price of the underlying in ETH terms function getUnderlyingPrice() external view virtual returns (uint256); /* ========== REQUIRED UTILITIES ========== */ /// @notice Deposits underlying `amount`in return for target. Must be overriden by child contracts /// @param amount Underlying amount /// @return amount of target returned function wrapUnderlying(uint256 amount) external virtual returns (uint256); /// @notice Deposits target `amount`in return for underlying. Must be overriden by child contracts /// @param amount Target amount /// @return amount of underlying returned function unwrapTarget(uint256 amount) external virtual returns (uint256); function flashFee(address token, uint256) external view returns (uint256) { if (token != target) revert Errors.TokenNotSupported(); return 0; } function maxFlashLoan(address token) external view override returns (uint256) { return ERC20(token).balanceOf(address(this)); } /* ========== OPTIONAL HOOKS ========== */ /// @notice Notification whenever the Divider adds or removes Target function notify( address, /* usr */ uint256, /* amt */ bool /* join */ ) public virtual { return; } /// @notice Hook called whenever a user redeems PT function onRedeem( uint256, /* uBal */ uint256, /* mscale */ uint256, /* maxscale */ uint256 /* tBal */ ) public virtual { return; } /* ========== PUBLIC STORAGE ACCESSORS ========== */ function getMaturityBounds() external view returns (uint256, uint256) { return (adapterParams.minm, adapterParams.maxm); } function getStakeAndTarget() external view returns ( address, address, uint256 ) { return (target, adapterParams.stake, adapterParams.stakeSize); } function mode() external view returns (uint256) { return adapterParams.mode; } function tilt() external view returns (uint256) { return adapterParams.tilt; } function level() external view returns (uint256) { return adapterParams.level; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // Internal references import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; import { BaseAdapter } from "./BaseAdapter.sol"; import { Divider } from "../Divider.sol"; abstract contract BaseFactory { /* ========== CONSTANTS ========== */ /// @notice Sets level to `31` by default, which keeps all Divider lifecycle methods public /// (`issue`, `combine`, `collect`, etc), but not the `onRedeem` hook. uint48 public constant DEFAULT_LEVEL = 31; /* ========== PUBLIC IMMUTABLES ========== */ /// @notice Sense core Divider address address public immutable divider; /// @notice target -> adapter mapping(address => address) public adapters; /// @notice params for adapters deployed with this factory FactoryParams public factoryParams; /* ========== DATA STRUCTURES ========== */ struct FactoryParams { address oracle; // oracle address address stake; // token to stake at issuance uint256 stakeSize; // amount to stake at issuance uint256 minm; // min maturity (seconds after block.timstamp) uint256 maxm; // max maturity (seconds after block.timstamp) uint128 ifee; // issuance fee uint16 mode; // 0 for monthly, 1 for weekly uint64 tilt; // tilt } constructor(address _divider, FactoryParams memory _factoryParams) { divider = _divider; factoryParams = _factoryParams; } /* ========== REQUIRED DEPLOY ========== */ /// @notice Deploys both an adapter and a target wrapper for the given _target /// @param _target Address of the Target token /// @param _data Additional data needed to deploy the adapter function deployAdapter(address _target, bytes memory _data) external virtual returns (address adapter) {} /* ========== LOGS ========== */ /// @notice Logs the deployment of the adapter event AdapterAdded(address addr, address indexed target); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol"; import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { SafeTransferLib } from "@rari-capital/solmate/src/utils/SafeTransferLib.sol"; import { ReentrancyGuard } from "@rari-capital/solmate/src/utils/ReentrancyGuard.sol"; import { DateTime } from "./external/DateTime.sol"; import { FixedMath } from "./external/FixedMath.sol"; // Internal references import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; import { Levels } from "@sense-finance/v1-utils/src/libs/Levels.sol"; import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { YT } from "./tokens/YT.sol"; import { Token } from "./tokens/Token.sol"; import { BaseAdapter as Adapter } from "./adapters/BaseAdapter.sol"; /// @title Sense Divider: Divide Assets in Two /// @author fedealconada + jparklev /// @notice You can use this contract to issue, combine, and redeem Sense ERC20 Principal and Yield Tokens contract Divider is Trust, ReentrancyGuard, Pausable { using SafeTransferLib for ERC20; using FixedMath for uint256; using Levels for uint256; /* ========== PUBLIC CONSTANTS ========== */ /// @notice Buffer before and after the actual maturity in which only the sponsor can settle the Series uint256 public constant SPONSOR_WINDOW = 3 hours; /// @notice Buffer after the sponsor window in which anyone can settle the Series uint256 public constant SETTLEMENT_WINDOW = 3 hours; /// @notice 5% issuance fee cap uint256 public constant ISSUANCE_FEE_CAP = 0.05e18; /* ========== PUBLIC MUTABLE STORAGE ========== */ address public periphery; /// @notice Sense community multisig address public immutable cup; /// @notice Principal/Yield tokens deployer address public immutable tokenHandler; /// @notice Permissionless flag bool public permissionless; /// @notice Guarded launch flag bool public guarded = true; /// @notice Number of adapters (including turned off) uint248 public adapterCounter; /// @notice adapter ID -> adapter address mapping(uint256 => address) public adapterAddresses; /// @notice adapter data mapping(address => AdapterMeta) public adapterMeta; /// @notice adapter -> maturity -> Series mapping(address => mapping(uint256 => Series)) public series; /// @notice adapter -> maturity -> user -> lscale (last scale) mapping(address => mapping(uint256 => mapping(address => uint256))) public lscales; /* ========== DATA STRUCTURES ========== */ struct Series { // Principal ERC20 token address pt; // Timestamp of series initialization uint48 issuance; // Yield ERC20 token address yt; // % of underlying principal initially reserved for Yield uint96 tilt; // Actor who initialized the Series address sponsor; // Tracks fees due to the series' settler uint256 reward; // Scale at issuance uint256 iscale; // Scale at maturity uint256 mscale; // Max scale value from this series' lifetime uint256 maxscale; } struct AdapterMeta { // Adapter ID uint248 id; // Adapter enabled/disabled bool enabled; // Max amount of Target allowed to be issued uint256 guard; // Adapter level uint248 level; } constructor(address _cup, address _tokenHandler) Trust(msg.sender) { cup = _cup; tokenHandler = _tokenHandler; } /* ========== MUTATIVE FUNCTIONS ========== */ /// @notice Enable an adapter /// @dev when permissionless is disabled, only the Periphery can onboard adapters /// @dev after permissionless is enabled, anyone can onboard adapters /// @param adapter Adapter's address function addAdapter(address adapter) external whenNotPaused { if (!permissionless && msg.sender != periphery) revert Errors.OnlyPermissionless(); if (adapterMeta[adapter].id > 0 && !adapterMeta[adapter].enabled) revert Errors.InvalidAdapter(); _setAdapter(adapter, true); } /// @notice Initializes a new Series /// @dev Deploys two ERC20 contracts, one for PTs and the other one for YTs /// @dev Transfers some fixed amount of stake asset to this contract /// @param adapter Adapter to associate with the Series /// @param maturity Maturity date for the new Series, in units of unix time /// @param sponsor Sponsor of the Series that puts up a token stake and receives the issuance fees function initSeries( address adapter, uint256 maturity, address sponsor ) external nonReentrant whenNotPaused returns (address pt, address yt) { if (periphery != msg.sender) revert Errors.OnlyPeriphery(); if (!adapterMeta[adapter].enabled) revert Errors.InvalidAdapter(); if (_exists(adapter, maturity)) revert Errors.DuplicateSeries(); if (!_isValid(adapter, maturity)) revert Errors.InvalidMaturity(); // Transfer stake asset stake from caller to adapter (address target, address stake, uint256 stakeSize) = Adapter(adapter).getStakeAndTarget(); // Deploy Principal & Yield Tokens for this new Series (pt, yt) = TokenHandler(tokenHandler).deploy(adapter, adapterMeta[adapter].id, maturity); // Initialize the new Series struct uint256 scale = Adapter(adapter).scale(); series[adapter][maturity].pt = pt; series[adapter][maturity].issuance = uint48(block.timestamp); series[adapter][maturity].yt = yt; series[adapter][maturity].tilt = uint96(Adapter(adapter).tilt()); series[adapter][maturity].sponsor = sponsor; series[adapter][maturity].iscale = scale; series[adapter][maturity].maxscale = scale; ERC20(stake).safeTransferFrom(msg.sender, adapter, stakeSize); emit SeriesInitialized(adapter, maturity, pt, yt, sponsor, target); } /// @notice Settles a Series and transfers the settlement reward to the caller /// @dev The Series' sponsor has a grace period where only they can settle the Series /// @dev After that, the reward becomes MEV /// @param adapter Adapter to associate with the Series /// @param maturity Maturity date for the new Series function settleSeries(address adapter, uint256 maturity) external nonReentrant whenNotPaused { if (!adapterMeta[adapter].enabled) revert Errors.InvalidAdapter(); if (!_exists(adapter, maturity)) revert Errors.SeriesDoesNotExist(); if (_settled(adapter, maturity)) revert Errors.AlreadySettled(); if (!_canBeSettled(adapter, maturity)) revert Errors.OutOfWindowBoundaries(); // The maturity scale value is all a Series needs for us to consider it "settled" uint256 mscale = Adapter(adapter).scale(); series[adapter][maturity].mscale = mscale; if (mscale > series[adapter][maturity].maxscale) { series[adapter][maturity].maxscale = mscale; } // Reward the caller for doing the work of settling the Series at around the correct time (address target, address stake, uint256 stakeSize) = Adapter(adapter).getStakeAndTarget(); ERC20(target).safeTransferFrom(adapter, msg.sender, series[adapter][maturity].reward); ERC20(stake).safeTransferFrom(adapter, msg.sender, stakeSize); emit SeriesSettled(adapter, maturity, msg.sender); } /// @notice Mint Principal & Yield Tokens of a specific Series /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series [unix time] /// @param tBal Balance of Target to deposit /// @dev The balance of PTs and YTs minted will be the same value in units of underlying (less fees) function issue( address adapter, uint256 maturity, uint256 tBal ) external nonReentrant whenNotPaused returns (uint256 uBal) { if (!adapterMeta[adapter].enabled) revert Errors.InvalidAdapter(); if (!_exists(adapter, maturity)) revert Errors.SeriesDoesNotExist(); if (_settled(adapter, maturity)) revert Errors.IssueOnSettle(); uint256 level = adapterMeta[adapter].level; if (level.issueRestricted() && msg.sender != adapter) revert Errors.IssuanceRestricted(); ERC20 target = ERC20(Adapter(adapter).target()); // Take the issuance fee out of the deposited Target, and put it towards the settlement reward uint256 issuanceFee = Adapter(adapter).ifee(); if (issuanceFee > ISSUANCE_FEE_CAP) revert Errors.IssuanceFeeCapExceeded(); uint256 fee = tBal.fmul(issuanceFee); unchecked { // Safety: bounded by the Target's total token supply series[adapter][maturity].reward += fee; } uint256 tBalSubFee = tBal - fee; // Ensure the caller won't hit the issuance cap with this action unchecked { // Safety: bounded by the Target's total token supply if (guarded && target.balanceOf(adapter) + tBal > adapterMeta[address(adapter)].guard) revert Errors.GuardCapReached(); } // Update values on adapter Adapter(adapter).notify(msg.sender, tBalSubFee, true); uint256 scale = level.collectDisabled() ? series[adapter][maturity].iscale : Adapter(adapter).scale(); // Determine the amount of Underlying equal to the Target being sent in (the principal) uBal = tBalSubFee.fmul(scale); // If the caller has not collected on YT before, use the current scale, otherwise // use the harmonic mean of the last and the current scale value lscales[adapter][maturity][msg.sender] = lscales[adapter][maturity][msg.sender] == 0 ? scale : _reweightLScale( adapter, maturity, YT(series[adapter][maturity].yt).balanceOf(msg.sender), uBal, msg.sender, scale ); // Mint equal amounts of PT and YT Token(series[adapter][maturity].pt).mint(msg.sender, uBal); YT(series[adapter][maturity].yt).mint(msg.sender, uBal); target.safeTransferFrom(msg.sender, adapter, tBal); emit Issued(adapter, maturity, uBal, msg.sender); } /// @notice Reconstitute Target by burning PT and YT /// @dev Explicitly burns YTs before maturity, and implicitly does it at/after maturity through `_collect()` /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param uBal Balance of PT and YT to burn function combine( address adapter, uint256 maturity, uint256 uBal ) external nonReentrant whenNotPaused returns (uint256 tBal) { if (!adapterMeta[adapter].enabled) revert Errors.InvalidAdapter(); if (!_exists(adapter, maturity)) revert Errors.SeriesDoesNotExist(); uint256 level = adapterMeta[adapter].level; if (level.combineRestricted() && msg.sender != adapter) revert Errors.CombineRestricted(); // Burn the PT Token(series[adapter][maturity].pt).burn(msg.sender, uBal); // Collect whatever excess is due uint256 collected = _collect(msg.sender, adapter, maturity, uBal, uBal, address(0)); uint256 cscale = series[adapter][maturity].mscale; bool settled = _settled(adapter, maturity); if (!settled) { // If it's not settled, then YT won't be burned automatically in `_collect()` YT(series[adapter][maturity].yt).burn(msg.sender, uBal); // If collect has been restricted, use the initial scale, otherwise use the current scale cscale = level.collectDisabled() ? series[adapter][maturity].iscale : lscales[adapter][maturity][msg.sender]; } // Convert from units of Underlying to units of Target tBal = uBal.fdiv(cscale); ERC20(Adapter(adapter).target()).safeTransferFrom(adapter, msg.sender, tBal); // Notify only when Series is not settled as when it is, the _collect() call above would trigger a _redeemYT which will call notify if (!settled) Adapter(adapter).notify(msg.sender, tBal, false); unchecked { // Safety: bounded by the Target's total token supply tBal += collected; } emit Combined(adapter, maturity, tBal, msg.sender); } /// @notice Burn PT of a Series once it's been settled /// @dev The balance of redeemable Target is a function of the change in Scale /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param uBal Amount of PT to burn, which should be equivalent to the amount of Underlying owed to the caller function redeem( address adapter, uint256 maturity, uint256 uBal ) external nonReentrant whenNotPaused returns (uint256 tBal) { // If a Series is settled, we know that it must have existed as well, so that check is unnecessary if (!_settled(adapter, maturity)) revert Errors.NotSettled(); uint256 level = adapterMeta[adapter].level; if (level.redeemRestricted() && msg.sender == adapter) revert Errors.RedeemRestricted(); // Burn the caller's PT Token(series[adapter][maturity].pt).burn(msg.sender, uBal); // Principal Token holder's share of the principal = (1 - part of the principal that belongs to Yield) uint256 zShare = FixedMath.WAD - series[adapter][maturity].tilt; // If Principal Token are at a loss and Yield have some principal to help cover the shortfall, // take what we can from Yield Token's principal if (series[adapter][maturity].mscale.fdiv(series[adapter][maturity].maxscale) >= zShare) { tBal = (uBal * zShare) / series[adapter][maturity].mscale; } else { tBal = uBal.fdiv(series[adapter][maturity].maxscale); } if (!level.redeemHookDisabled()) { Adapter(adapter).onRedeem(uBal, series[adapter][maturity].mscale, series[adapter][maturity].maxscale, tBal); } ERC20(Adapter(adapter).target()).safeTransferFrom(adapter, msg.sender, tBal); emit PTRedeemed(adapter, maturity, tBal); } function collect( address usr, address adapter, uint256 maturity, uint256 uBalTransfer, address to ) external nonReentrant onlyYT(adapter, maturity) whenNotPaused returns (uint256 collected) { uint256 uBal = YT(msg.sender).balanceOf(usr); return _collect(usr, adapter, maturity, uBal, uBalTransfer > 0 ? uBalTransfer : uBal, to); } /// @notice Collect YT excess before, at, or after maturity /// @dev If `to` is set, we copy the lscale value from usr to this address /// @param usr User who's collecting for their YTs /// @param adapter Adapter address for the Series /// @param maturity Maturity date for the Series /// @param uBal yield Token balance /// @param uBalTransfer original transfer value /// @param to address to set the lscale value from usr function _collect( address usr, address adapter, uint256 maturity, uint256 uBal, uint256 uBalTransfer, address to ) internal returns (uint256 collected) { if (!_exists(adapter, maturity)) revert Errors.SeriesDoesNotExist(); // If the adapter is disabled, its Yield Token can only collect // if associated Series has been settled, which implies that an admin // has backfilled it if (!adapterMeta[adapter].enabled && !_settled(adapter, maturity)) revert Errors.InvalidAdapter(); Series memory _series = series[adapter][maturity]; // Get the scale value from the last time this holder collected (default to maturity) uint256 lscale = lscales[adapter][maturity][usr]; uint256 level = adapterMeta[adapter].level; if (level.collectDisabled()) { // If this Series has been settled, we ensure everyone's YT will // collect yield accrued since issuance if (_settled(adapter, maturity)) { lscale = series[adapter][maturity].iscale; // If the Series is not settled, we ensure no collections can happen } else { return 0; } } // If the Series has been settled, this should be their last collect, so redeem the user's Yield Tokens for them if (_settled(adapter, maturity)) { _redeemYT(usr, adapter, maturity, uBal); } else { // If we're not settled and we're past maturity + the sponsor window, // anyone can settle this Series so revert until someone does if (block.timestamp > maturity + SPONSOR_WINDOW) { revert Errors.CollectNotSettled(); // Otherwise, this is a valid pre-settlement collect and we need to determine the scale value } else { uint256 cscale = Adapter(adapter).scale(); // If this is larger than the largest scale we've seen for this Series, use it if (cscale > _series.maxscale) { _series.maxscale = cscale; lscales[adapter][maturity][usr] = cscale; // If not, use the previously noted max scale value } else { lscales[adapter][maturity][usr] = _series.maxscale; } } } // Determine how much underlying has accrued since the last time this user collected, in units of Target. // (Or take the last time as issuance if they haven't yet) // // Reminder: `Underlying / Scale = Target` // So the following equation is saying, for some amount of Underlying `u`: // "Balance of Target that equaled `u` at the last collection _minus_ Target that equals `u` now" // // Because maxscale must be increasing, the Target balance needed to equal `u` decreases, and that "excess" // is what Yield holders are collecting uint256 tBalNow = uBal.fdivUp(_series.maxscale); // preventive round-up towards the protocol uint256 tBalPrev = uBal.fdiv(lscale); unchecked { collected = tBalPrev > tBalNow ? tBalPrev - tBalNow : 0; } ERC20(Adapter(adapter).target()).safeTransferFrom(adapter, usr, collected); Adapter(adapter).notify(usr, collected, false); // Distribute reward tokens // If this collect is a part of a token transfer to another address, set the receiver's // last collection to a synthetic scale weighted based on the scale on their last collect, // the time elapsed, and the current scale if (to != address(0)) { uint256 ytBal = YT(_series.yt).balanceOf(to); // If receiver holds yields, we set lscale to a computed "synthetic" lscales value that, // for the updated yield balance, still assigns the correct amount of yield. lscales[adapter][maturity][to] = ytBal > 0 ? _reweightLScale(adapter, maturity, ytBal, uBalTransfer, to, _series.maxscale) : _series.maxscale; uint256 tBalTransfer = uBalTransfer.fdiv(_series.maxscale); Adapter(adapter).notify(usr, tBalTransfer, false); Adapter(adapter).notify(to, tBalTransfer, true); } series[adapter][maturity] = _series; emit Collected(adapter, maturity, collected); } /// @notice calculate the harmonic mean of the current scale and the last scale, /// weighted by amounts associated with each function _reweightLScale( address adapter, uint256 maturity, uint256 ytBal, uint256 uBal, address receiver, uint256 scale ) internal view returns (uint256) { // Target Decimals * 18 Decimals [from fdiv] / (Target Decimals * 18 Decimals [from fdiv] / 18 Decimals) // = 18 Decimals, which is the standard for scale values return (ytBal + uBal).fdiv((ytBal.fdiv(lscales[adapter][maturity][receiver]) + uBal.fdiv(scale))); } function _redeemYT( address usr, address adapter, uint256 maturity, uint256 uBal ) internal { // Burn the users's YTs YT(series[adapter][maturity].yt).burn(usr, uBal); // Default principal for a YT uint256 tBal = 0; // Principal Token holder's share of the principal = (1 - part of the principal that belongs to Yield Tokens) uint256 zShare = FixedMath.WAD - series[adapter][maturity].tilt; // If PTs are at a loss and YTs had their principal cut to help cover the shortfall, // calculate how much YTs have left if (series[adapter][maturity].mscale.fdiv(series[adapter][maturity].maxscale) >= zShare) { tBal = uBal.fdiv(series[adapter][maturity].maxscale) - (uBal * zShare) / series[adapter][maturity].mscale; ERC20(Adapter(adapter).target()).safeTransferFrom(adapter, usr, tBal); } // Always notify the Adapter of the full Target balance that will no longer // have its rewards distributed Adapter(adapter).notify(usr, uBal.fdivUp(series[adapter][maturity].maxscale), false); emit YTRedeemed(adapter, maturity, tBal); } /* ========== ADMIN ========== */ /// @notice Enable or disable a adapter /// @param adapter Adapter's address /// @param isOn Flag setting this adapter to enabled or disabled function setAdapter(address adapter, bool isOn) public requiresTrust { _setAdapter(adapter, isOn); } /// @notice Set adapter's guard /// @param adapter Adapter address /// @param cap The max target that can be deposited on the Adapter function setGuard(address adapter, uint256 cap) external requiresTrust { adapterMeta[adapter].guard = cap; emit GuardChanged(adapter, cap); } /// @notice Set guarded mode /// @param _guarded bool function setGuarded(bool _guarded) external requiresTrust { guarded = _guarded; emit GuardedChanged(_guarded); } /// @notice Set periphery's contract /// @param _periphery Target address function setPeriphery(address _periphery) external requiresTrust { periphery = _periphery; emit PeripheryChanged(_periphery); } /// @notice Set paused flag /// @param _paused boolean function setPaused(bool _paused) external requiresTrust { _paused ? _pause() : _unpause(); } /// @notice Set permissioless mode /// @param _permissionless bool function setPermissionless(bool _permissionless) external requiresTrust { permissionless = _permissionless; emit PermissionlessChanged(_permissionless); } /// @notice Backfill a Series' Scale value at maturity if keepers failed to settle it /// @param adapter Adapter's address /// @param maturity Maturity date for the Series /// @param mscale Value to set as the Series' Scale value at maturity /// @param _usrs Values to set on lscales mapping /// @param _lscales Values to set on lscales mapping function backfillScale( address adapter, uint256 maturity, uint256 mscale, address[] calldata _usrs, uint256[] calldata _lscales ) external requiresTrust { if (!_exists(adapter, maturity)) revert Errors.SeriesDoesNotExist(); uint256 cutoff = maturity + SPONSOR_WINDOW + SETTLEMENT_WINDOW; // Admin can never backfill before maturity if (block.timestamp <= cutoff) revert Errors.OutOfWindowBoundaries(); // Set user's last scale values the Series (needed for the `collect` method) for (uint256 i = 0; i < _usrs.length; i++) { lscales[adapter][maturity][_usrs[i]] = _lscales[i]; } if (mscale > 0) { Series memory _series = series[adapter][maturity]; // Set the maturity scale for the Series (needed for `redeem` methods) series[adapter][maturity].mscale = mscale; if (mscale > _series.maxscale) { series[adapter][maturity].maxscale = mscale; } (address target, address stake, uint256 stakeSize) = Adapter(adapter).getStakeAndTarget(); address stakeDst = adapterMeta[adapter].enabled ? cup : _series.sponsor; ERC20(target).safeTransferFrom(adapter, cup, _series.reward); series[adapter][maturity].reward = 0; ERC20(stake).safeTransferFrom(adapter, stakeDst, stakeSize); } emit Backfilled(adapter, maturity, mscale, _usrs, _lscales); } /* ========== INTERNAL VIEWS ========== */ function _exists(address adapter, uint256 maturity) internal view returns (bool) { return series[adapter][maturity].pt != address(0); } function _settled(address adapter, uint256 maturity) internal view returns (bool) { return series[adapter][maturity].mscale > 0; } function _canBeSettled(address adapter, uint256 maturity) internal view returns (bool) { uint256 cutoff = maturity + SPONSOR_WINDOW + SETTLEMENT_WINDOW; // If the sender is the sponsor for the Series if (msg.sender == series[adapter][maturity].sponsor) { return maturity - SPONSOR_WINDOW <= block.timestamp && cutoff >= block.timestamp; } else { return maturity + SPONSOR_WINDOW < block.timestamp && cutoff >= block.timestamp; } } function _isValid(address adapter, uint256 maturity) internal view returns (bool) { (uint256 minm, uint256 maxm) = Adapter(adapter).getMaturityBounds(); if (maturity < block.timestamp + minm || maturity > block.timestamp + maxm) return false; (, , uint256 day, uint256 hour, uint256 minute, uint256 second) = DateTime.timestampToDateTime(maturity); if (hour != 0 || minute != 0 || second != 0) return false; uint256 mode = Adapter(adapter).mode(); if (mode == 0) { return day == 1; } if (mode == 1) { return DateTime.getDayOfWeek(maturity) == 1; } return false; } /* ========== INTERNAL UTILS ========== */ function _setAdapter(address adapter, bool isOn) internal { AdapterMeta memory am = adapterMeta[adapter]; if (am.enabled == isOn) revert Errors.ExistingValue(); am.enabled = isOn; // If this adapter is being added for the first time if (isOn && am.id == 0) { am.id = ++adapterCounter; adapterAddresses[am.id] = adapter; } // Set level and target (can only be done once); am.level = uint248(Adapter(adapter).level()); adapterMeta[adapter] = am; emit AdapterChanged(adapter, am.id, isOn); } /* ========== PUBLIC GETTERS ========== */ /// @notice Returns address of Principal Token function pt(address adapter, uint256 maturity) public view returns (address) { return series[adapter][maturity].pt; } /// @notice Returns address of Yield Token function yt(address adapter, uint256 maturity) public view returns (address) { return series[adapter][maturity].yt; } function mscale(address adapter, uint256 maturity) public view returns (uint256) { return series[adapter][maturity].mscale; } /* ========== MODIFIERS ========== */ modifier onlyYT(address adapter, uint256 maturity) { if (series[adapter][maturity].yt != msg.sender) revert Errors.OnlyYT(); _; } /* ========== LOGS ========== */ /// @notice Admin event Backfilled( address indexed adapter, uint256 indexed maturity, uint256 mscale, address[] _usrs, uint256[] _lscales ); event GuardChanged(address indexed adapter, uint256 cap); event AdapterChanged(address indexed adapter, uint256 indexed id, bool indexed isOn); event PeripheryChanged(address indexed periphery); /// @notice Series lifecycle /// *---- beginning event SeriesInitialized( address adapter, uint256 indexed maturity, address pt, address yt, address indexed sponsor, address indexed target ); /// -***- middle event Issued(address indexed adapter, uint256 indexed maturity, uint256 balance, address indexed sender); event Combined(address indexed adapter, uint256 indexed maturity, uint256 balance, address indexed sender); event Collected(address indexed adapter, uint256 indexed maturity, uint256 collected); /// ----* end event SeriesSettled(address indexed adapter, uint256 indexed maturity, address indexed settler); event PTRedeemed(address indexed adapter, uint256 indexed maturity, uint256 redeemed); event YTRedeemed(address indexed adapter, uint256 indexed maturity, uint256 redeemed); /// *----* misc event GuardedChanged(bool indexed guarded); event PermissionlessChanged(bool indexed permissionless); } contract TokenHandler is Trust { /// @notice Program state address public divider; constructor() Trust(msg.sender) {} function init(address _divider) external requiresTrust { if (divider != address(0)) revert Errors.AlreadyInitialized(); divider = _divider; } function deploy( address adapter, uint248 id, uint256 maturity ) external returns (address pt, address yt) { if (msg.sender != divider) revert Errors.OnlyDivider(); ERC20 target = ERC20(Adapter(adapter).target()); uint8 decimals = target.decimals(); string memory symbol = target.symbol(); (string memory d, string memory m, string memory y) = DateTime.toDateString(maturity); string memory date = DateTime.format(maturity); string memory datestring = string(abi.encodePacked(d, "-", m, "-", y)); string memory adapterId = DateTime.uintToString(id); pt = address( new Token( string(abi.encodePacked(date, " ", symbol, " Sense Principal Token, A", adapterId)), string(abi.encodePacked("sP-", symbol, ":", datestring, ":", adapterId)), decimals, divider ) ); yt = address( new YT( adapter, maturity, string(abi.encodePacked(date, " ", symbol, " Sense Yield Token, A", adapterId)), string(abi.encodePacked("sY-", symbol, ":", datestring, ":", adapterId)), decimals, divider ) ); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External reference import { Clones } from "@openzeppelin/contracts/proxy/Clones.sol"; import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { Bytes32AddressLib } from "@rari-capital/solmate/src/utils/Bytes32AddressLib.sol"; import { PriceOracle } from "./external/PriceOracle.sol"; import { BalancerOracle } from "./external/BalancerOracle.sol"; // Internal references import { UnderlyingOracle } from "./oracles/Underlying.sol"; import { TargetOracle } from "./oracles/Target.sol"; import { PTOracle } from "./oracles/PT.sol"; import { LPOracle } from "./oracles/LP.sol"; import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; import { Divider } from "@sense-finance/v1-core/src/Divider.sol"; import { BaseAdapter as Adapter } from "@sense-finance/v1-core/src/adapters/BaseAdapter.sol"; interface FuseDirectoryLike { function deployPool( string memory name, address implementation, bool enforceWhitelist, uint256 closeFactor, uint256 liquidationIncentive, address priceOracle ) external returns (uint256, address); } interface ComptrollerLike { /// Deploy cToken, add the market to the markets mapping, and set it as listed and set the collateral factor /// Admin function to deploy cToken, set isListed, and add support for the market and set the collateral factor function _deployMarket( bool isCEther, bytes calldata constructorData, uint256 collateralFactorMantissa ) external returns (uint256); /// Accepts transfer of admin rights. msg.sender must be pendingAdmin function _acceptAdmin() external returns (uint256); /// All cTokens addresses mapped by their underlying token addresses function cTokensByUnderlying(address underlying) external view returns (address); /// A list of all markets function markets(address cToken) external view returns (bool, uint256); /// Pause borrowing for a specific market function _setBorrowPaused(address cToken, bool state) external returns (bool); } interface MasterOracleLike { function initialize( address[] memory underlyings, PriceOracle[] memory _oracles, PriceOracle _defaultOracle, address _admin, bool _canAdminOverwrite ) external; function add(address[] calldata underlyings, PriceOracle[] calldata _oracles) external; function getUnderlyingPrice(address cToken) external view returns (uint256); } /// @title Fuse Pool Manager /// @notice Consolidated Fuse interactions contract PoolManager is Trust { /* ========== PUBLIC IMMUTABLES ========== */ /// @notice Implementation of Fuse's comptroller address public immutable comptrollerImpl; /// @notice Implementation of Fuse's cERC20 address public immutable cERC20Impl; /// @notice Fuse's pool directory address public immutable fuseDirectory; /// @notice Sense core Divider address address public immutable divider; /// @notice Implementation of Fuse's master oracle that routes to individual asset oracles address public immutable oracleImpl; /// @notice Sense oracle for SEnse Targets address public immutable targetOracle; /// @notice Sense oracle for Sense Principal Tokens address public immutable ptOracle; /// @notice Sense oracle for Space LP Shares address public immutable lpOracle; /// @notice Sense oracle for Underlying assets address public immutable underlyingOracle; /* ========== PUBLIC MUTABLE STORAGE ========== */ /// @notice Fuse comptroller for the Sense pool address public comptroller; /// @notice Master oracle for Sense's assets deployed on Fuse address public masterOracle; /// @notice Fuse param config AssetParams public targetParams; AssetParams public ptParams; AssetParams public lpTokenParams; /// @notice Series Pools: adapter -> maturity -> (series status (pt/lp shares), AMM pool) mapping(address => mapping(uint256 => Series)) public sSeries; /* ========== ENUMS ========== */ enum SeriesStatus { NONE, QUEUED, ADDED } /* ========== DATA STRUCTURES ========== */ struct AssetParams { address irModel; uint256 reserveFactor; uint256 collateralFactor; } struct Series { // Series addition status SeriesStatus status; // Space pool for this Series address pool; } constructor( address _fuseDirectory, address _comptrollerImpl, address _cERC20Impl, address _divider, address _oracleImpl ) Trust(msg.sender) { fuseDirectory = _fuseDirectory; comptrollerImpl = _comptrollerImpl; cERC20Impl = _cERC20Impl; divider = _divider; oracleImpl = _oracleImpl; targetOracle = address(new TargetOracle()); ptOracle = address(new PTOracle()); lpOracle = address(new LPOracle()); underlyingOracle = address(new UnderlyingOracle()); } function deployPool( string calldata name, uint256 closeFactor, uint256 liqIncentive, address fallbackOracle ) external requiresTrust returns (uint256 _poolIndex, address _comptroller) { masterOracle = Clones.cloneDeterministic(oracleImpl, Bytes32AddressLib.fillLast12Bytes(address(this))); MasterOracleLike(masterOracle).initialize( new address[](0), new PriceOracle[](0), PriceOracle(fallbackOracle), // default oracle used if asset prices can't be found otherwise address(this), // admin true // admin can override existing oracle routes ); (_poolIndex, _comptroller) = FuseDirectoryLike(fuseDirectory).deployPool( name, comptrollerImpl, false, // `whitelist` is always false closeFactor, liqIncentive, masterOracle ); uint256 err = ComptrollerLike(_comptroller)._acceptAdmin(); if (err != 0) revert Errors.FailedBecomeAdmin(); comptroller = _comptroller; emit PoolDeployed(name, _comptroller, _poolIndex, closeFactor, liqIncentive); } function addTarget(address target, address adapter) external requiresTrust returns (address cTarget) { if (comptroller == address(0)) revert Errors.PoolNotDeployed(); if (targetParams.irModel == address(0)) revert Errors.TargetParamsNotSet(); address underlying = Adapter(adapter).underlying(); address[] memory underlyings = new address[](2); underlyings[0] = target; underlyings[1] = underlying; PriceOracle[] memory oracles = new PriceOracle[](2); oracles[0] = PriceOracle(targetOracle); oracles[1] = PriceOracle(underlyingOracle); UnderlyingOracle(underlyingOracle).setUnderlying(underlying, adapter); TargetOracle(targetOracle).setTarget(target, adapter); MasterOracleLike(masterOracle).add(underlyings, oracles); bytes memory constructorData = abi.encode( target, comptroller, targetParams.irModel, ERC20(target).name(), ERC20(target).symbol(), cERC20Impl, hex"", // calldata sent to becomeImplementation (empty bytes b/c it's currently unused) targetParams.reserveFactor, 0 // no admin fee ); // Trying to deploy the same market twice will fail uint256 err = ComptrollerLike(comptroller)._deployMarket(false, constructorData, targetParams.collateralFactor); if (err != 0) revert Errors.FailedAddTargetMarket(); cTarget = ComptrollerLike(comptroller).cTokensByUnderlying(target); emit TargetAdded(target, cTarget); } /// @notice queues a set of (Principal Tokens, LPShare) for a Fuse pool to be deployed once the TWAP is ready /// @dev called by the Periphery, which will know which pool address to set for this Series function queueSeries( address adapter, uint256 maturity, address pool ) external requiresTrust { if (Divider(divider).pt(adapter, maturity) == address(0)) revert Errors.SeriesDoesNotExist(); if (sSeries[adapter][maturity].status != SeriesStatus.NONE) revert Errors.DuplicateSeries(); address cTarget = ComptrollerLike(comptroller).cTokensByUnderlying(Adapter(adapter).target()); if (cTarget == address(0)) revert Errors.TargetNotInFuse(); (bool isListed, ) = ComptrollerLike(comptroller).markets(cTarget); if (!isListed) revert Errors.TargetNotInFuse(); sSeries[adapter][maturity] = Series({ status: SeriesStatus.QUEUED, pool: pool }); emit SeriesQueued(adapter, maturity, pool); } /// @notice open method to add queued Principal Tokens and LPShares to Fuse pool /// @dev this can only be done once the yield space pool has filled its buffer and has a TWAP function addSeries(address adapter, uint256 maturity) external returns (address cPT, address cLPToken) { if (sSeries[adapter][maturity].status != SeriesStatus.QUEUED) revert Errors.SeriesNotQueued(); if (ptParams.irModel == address(0)) revert Errors.PTParamsNotSet(); if (lpTokenParams.irModel == address(0)) revert Errors.PoolParamsNotSet(); address pt = Divider(divider).pt(adapter, maturity); address pool = sSeries[adapter][maturity].pool; (, , , , , , uint256 sampleTs) = BalancerOracle(pool).getSample(BalancerOracle(pool).getTotalSamples() - 1); // Prevent this market from being deployed on Fuse if we're unable to read a TWAP if (sampleTs == 0) revert Errors.OracleNotReady(); address[] memory underlyings = new address[](2); underlyings[0] = pt; underlyings[1] = pool; PriceOracle[] memory oracles = new PriceOracle[](2); oracles[0] = PriceOracle(ptOracle); oracles[1] = PriceOracle(lpOracle); PTOracle(ptOracle).setPrincipal(pt, pool); MasterOracleLike(masterOracle).add(underlyings, oracles); bytes memory constructorDataPrincipal = abi.encode( pt, comptroller, ptParams.irModel, ERC20(pt).name(), ERC20(pt).symbol(), cERC20Impl, hex"", ptParams.reserveFactor, 0 // no admin fee ); uint256 errPrincipal = ComptrollerLike(comptroller)._deployMarket( false, constructorDataPrincipal, ptParams.collateralFactor ); if (errPrincipal != 0) revert Errors.FailedToAddPTMarket(); // LP Share pool token bytes memory constructorDataLpToken = abi.encode( pool, comptroller, lpTokenParams.irModel, ERC20(pool).name(), ERC20(pool).symbol(), cERC20Impl, hex"", lpTokenParams.reserveFactor, 0 // no admin fee ); uint256 errLpToken = ComptrollerLike(comptroller)._deployMarket( false, constructorDataLpToken, lpTokenParams.collateralFactor ); if (errLpToken != 0) revert Errors.FailedAddLpMarket(); cPT = ComptrollerLike(comptroller).cTokensByUnderlying(pt); cLPToken = ComptrollerLike(comptroller).cTokensByUnderlying(pool); ComptrollerLike(comptroller)._setBorrowPaused(cLPToken, true); sSeries[adapter][maturity].status = SeriesStatus.ADDED; emit SeriesAdded(pt, pool); } /* ========== ADMIN ========== */ function setParams(bytes32 what, AssetParams calldata data) external requiresTrust { if (what == "PT_PARAMS") ptParams = data; else if (what == "LP_TOKEN_PARAMS") lpTokenParams = data; else if (what == "TARGET_PARAMS") targetParams = data; else revert Errors.InvalidParam(); emit ParamsSet(what, data); } function execute( address to, uint256 value, bytes memory data, uint256 txGas ) external requiresTrust returns (bool success) { assembly { success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0) } } /* ========== LOGS ========== */ event ParamsSet(bytes32 indexed what, AssetParams data); event PoolDeployed(string name, address comptroller, uint256 poolIndex, uint256 closeFactor, uint256 liqIncentive); event TargetAdded(address indexed target, address indexed cTarget); event SeriesQueued(address indexed adapter, uint256 indexed maturity, address indexed pool); event SeriesAdded(address indexed pt, address indexed lpToken); }
pragma solidity ^0.8.0; import "./IERC3156FlashBorrower.sol"; interface IERC3156FlashLender { /// @dev The amount of currency available to be lent. /// @param token The loan currency. /// @return The amount of `token` that can be borrowed. function maxFlashLoan(address token) external view returns (uint256); /// @dev The fee to be charged for a given loan. /// @param token The loan currency. /// @param amount The amount of tokens lent. /// @return The amount of `token` to be charged for the loan, on top of the returned principal. function flashFee(address token, uint256 amount) external view returns (uint256); /// @dev Initiate a flash loan. /// @param receiver The receiver of the tokens in the loan, and the receiver of the callback. /// @param token The loan currency. /// @param amount The amount of tokens lent. /// @param data Arbitrary data structure, intended to contain user-defined parameters. function flashLoan( IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data ) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { require(!paused(), "Pausable: paused"); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { require(paused(), "Pausable: not paused"); _; } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Gas optimized reentrancy protection for smart contracts. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol) abstract contract ReentrancyGuard { uint256 private locked = 1; modifier nonReentrant() { require(locked == 1, "REENTRANCY"); locked = 2; _; locked = 1; } }
pragma solidity 0.8.11; /// @author Taken from: https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary library DateTime { uint256 constant SECONDS_PER_DAY = 24 * 60 * 60; uint256 constant SECONDS_PER_HOUR = 60 * 60; uint256 constant SECONDS_PER_MINUTE = 60; int256 constant OFFSET19700101 = 2440588; function timestampToDate(uint256 timestamp) internal pure returns ( uint256 year, uint256 month, uint256 day ) { (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); } function timestampToDateTime(uint256 timestamp) internal pure returns ( uint256 year, uint256 month, uint256 day, uint256 hour, uint256 minute, uint256 second ) { (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY); uint256 secs = timestamp % SECONDS_PER_DAY; hour = secs / SECONDS_PER_HOUR; secs = secs % SECONDS_PER_HOUR; minute = secs / SECONDS_PER_MINUTE; second = secs % SECONDS_PER_MINUTE; } function toDateString(uint256 _timestamp) internal pure returns ( string memory d, string memory m, string memory y ) { (uint256 year, uint256 month, uint256 day) = timestampToDate(_timestamp); d = uintToString(day); m = uintToString(month); y = uintToString(year); // append a 0 to numbers < 10 so we should, e.g, 01 instead of just 1 if (day < 10) d = string(abi.encodePacked("0", d)); if (month < 10) m = string(abi.encodePacked("0", m)); } function format(uint256 _timestamp) internal pure returns (string memory datestring) { string[12] memory months = [ "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" ]; (uint256 year, uint256 month, uint256 day) = timestampToDate(_timestamp); uint256 last = day % 10; string memory suffix = "th"; if (day < 11 || day > 20) { if (last == 1) suffix = "st"; if (last == 2) suffix = "nd"; if (last == 3) suffix = "rd"; } return string(abi.encodePacked(uintToString(day), suffix, " ", months[month - 1], " ", uintToString(year))); } function getDayOfWeek(uint256 timestamp) internal pure returns (uint256 dayOfWeek) { uint256 _days = timestamp / SECONDS_PER_DAY; dayOfWeek = ((_days + 3) % 7) + 1; } /// Taken from https://stackoverflow.com/questions/47129173/how-to-convert-uint-to-string-in-solidity function uintToString(uint256 _i) internal pure returns (string memory _uintAsString) { if (_i == 0) return "0"; uint256 j = _i; uint256 len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint256 k = len; while (_i != 0) { k = k - 1; uint8 temp = (48 + uint8(_i - (_i / 10) * 10)); bytes1 b1 = bytes1(temp); bstr[k] = b1; _i /= 10; } return string(bstr); } // ------------------------------------------------------------------------ // Calculate the number of days from 1970/01/01 to year/month/day using // the date conversion algorithm from // http://aa.usno.navy.mil/faq/docs/JD_Formula.php // and subtracting the offset 2440588 so that 1970/01/01 is day 0 // // days = day // - 32075 // + 1461 * (year + 4800 + (month - 14) / 12) / 4 // + 367 * (month - 2 - (month - 14) / 12 * 12) / 12 // - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4 // - offset // ------------------------------------------------------------------------ function _daysFromDate( uint256 year, uint256 month, uint256 day ) internal pure returns (uint256 _days) { require(year >= 1970); int256 _year = int256(year); int256 _month = int256(month); int256 _day = int256(day); int256 __days = _day - 32075 + (1461 * (_year + 4800 + (_month - 14) / 12)) / 4 + (367 * (_month - 2 - ((_month - 14) / 12) * 12)) / 12 - (3 * ((_year + 4900 + (_month - 14) / 12) / 100)) / 4 - OFFSET19700101; _days = uint256(__days); } // ------------------------------------------------------------------------ // Calculate year/month/day from the number of days since 1970/01/01 using // the date conversion algorithm from // http://aa.usno.navy.mil/faq/docs/JD_Formula.php // and adding the offset 2440588 so that 1970/01/01 is day 0 // // int L = days + 68569 + offset // int N = 4 * L / 146097 // L = L - (146097 * N + 3) / 4 // year = 4000 * (L + 1) / 1461001 // L = L - 1461 * year / 4 + 31 // month = 80 * L / 2447 // dd = L - 2447 * month / 80 // L = month / 11 // month = month + 2 - 12 * L // year = 100 * (N - 49) + year + L // ------------------------------------------------------------------------ function _daysToDate(uint256 _days) internal pure returns ( uint256 year, uint256 month, uint256 day ) { int256 __days = int256(_days); int256 L = __days + 68569 + OFFSET19700101; int256 N = (4 * L) / 146097; L = L - (146097 * N + 3) / 4; int256 _year = (4000 * (L + 1)) / 1461001; L = L - (1461 * _year) / 4 + 31; int256 _month = (80 * L) / 2447; int256 _day = L - (2447 * _month) / 80; L = _month / 11; _month = _month + 2 - 12 * L; _year = 100 * (N - 49) + _year + L; year = uint256(_year); month = uint256(_month); day = uint256(_day); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // Internal references import { Divider } from "../Divider.sol"; import { Token } from "./Token.sol"; /// @title Yield Token /// @notice Strips off excess before every transfer contract YT is Token { address public immutable adapter; address public immutable divider; uint256 public immutable maturity; constructor( address _adapter, uint256 _maturity, string memory _name, string memory _symbol, uint8 _decimals, address _divider ) Token(_name, _symbol, _decimals, _divider) { adapter = _adapter; maturity = _maturity; divider = _divider; } function collect() external returns (uint256 _collected) { return Divider(divider).collect(msg.sender, adapter, maturity, 0, address(0)); } function transfer(address to, uint256 value) public override returns (bool) { Divider(divider).collect(msg.sender, adapter, maturity, value, to); return super.transfer(to, value); } function transferFrom( address from, address to, uint256 value ) public override returns (bool) { if (value > 0) Divider(divider).collect(from, adapter, maturity, value, to); return super.transferFrom(from, to, value); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; // Internal references import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; /// @title Base Token contract Token is ERC20, Trust { constructor( string memory _name, string memory _symbol, uint8 _decimals, address _trusted ) ERC20(_name, _symbol, _decimals) Trust(_trusted) {} /// @param usr The address to send the minted tokens /// @param amount The amount to be minted function mint(address usr, uint256 amount) public requiresTrust { _mint(usr, amount); } /// @param usr The address from where to burn tokens from /// @param amount The amount to be burned function burn(address usr, uint256 amount) public requiresTrust { _burn(usr, amount); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for * deploying minimal proxy contracts, also known as "clones". * * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies * > a minimal bytecode implementation that delegates all calls to a known, fixed address. * * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the * deterministic method. * * _Available since v3.4._ */ library Clones { /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create opcode, which should never revert. */ function clone(address implementation) internal returns (address instance) { assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) instance := create(0, ptr, 0x37) } require(instance != address(0), "ERC1167: create failed"); } /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `implementation` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) instance := create2(0, ptr, 0x37, salt) } require(instance != address(0), "ERC1167: create2 failed"); } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000) mstore(add(ptr, 0x38), shl(0x60, deployer)) mstore(add(ptr, 0x4c), salt) mstore(add(ptr, 0x6c), keccak256(ptr, 0x37)) predicted := keccak256(add(ptr, 0x37), 0x55) } } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress(address implementation, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(implementation, salt, address(this)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Library for converting between addresses and bytes32 values. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/Bytes32AddressLib.sol) library Bytes32AddressLib { function fromLast20Bytes(bytes32 bytesValue) internal pure returns (address) { return address(uint160(uint256(bytesValue))); } function fillLast12Bytes(address addressValue) internal pure returns (bytes32) { return bytes32(bytes20(addressValue)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; import { CToken } from "./CToken.sol"; /// @title Price Oracle /// @author Compound /// @notice The minimum interface a contract must implement in order to work as an oracle for Fuse with Sense /// Original from: https://github.com/Rari-Capital/compound-protocol/blob/fuse-final/contracts/PriceOracle.sol abstract contract PriceOracle { /// @notice Indicator that this is a PriceOracle contract (for inspection) bool public constant isPriceOracle = true; /// @notice Get the underlying price of a cToken asset /// @param cToken The cToken to get the underlying price of /// @return The underlying asset price mantissa (scaled by 1e18). /// 0 means the price is unavailable. function getUnderlyingPrice(CToken cToken) external view virtual returns (uint256); /// @notice Get the price of an underlying asset. /// @param underlying The underlying asset to get the price of. /// @return The underlying asset price in ETH as a mantissa (scaled by 1e18). /// 0 means the price is unavailable. function price(address underlying) external view virtual returns (uint256); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; interface BalancerOracle { function getTimeWeightedAverage(OracleAverageQuery[] memory queries) external view returns (uint256[] memory results); enum Variable { PAIR_PRICE, BPT_PRICE, INVARIANT } struct OracleAverageQuery { Variable variable; uint256 secs; uint256 ago; } function getSample(uint256 index) external view returns ( int256 logPairPrice, int256 accLogPairPrice, int256 logBptPrice, int256 accLogBptPrice, int256 logInvariant, int256 accLogInvariant, uint256 timestamp ); function getPoolId() external view returns (bytes32); function getVault() external view returns (address); function getIndices() external view returns (uint256 _pti, uint256 _targeti); function totalSupply() external view returns (uint256); function getTotalSamples() external pure returns (uint256); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { PriceOracle } from "../external/PriceOracle.sol"; import { CToken } from "../external/CToken.sol"; import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; // Internal references import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { FixedMath } from "@sense-finance/v1-core/src/external/FixedMath.sol"; import { BaseAdapter as Adapter } from "@sense-finance/v1-core/src/adapters/BaseAdapter.sol"; contract UnderlyingOracle is PriceOracle, Trust { using FixedMath for uint256; /// @notice underlying address -> adapter address mapping(address => address) public adapters; constructor() Trust(msg.sender) {} function setUnderlying(address underlying, address adapter) external requiresTrust { adapters[underlying] = adapter; } function getUnderlyingPrice(CToken cToken) external view override returns (uint256) { return _price(address(cToken.underlying())); } function price(address underlying) external view override returns (uint256) { return _price(underlying); } function _price(address underlying) internal view returns (uint256) { address adapter = adapters[address(underlying)]; if (adapter == address(0)) revert Errors.AdapterNotSet(); return Adapter(adapter).getUnderlyingPrice(); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { PriceOracle } from "../external/PriceOracle.sol"; import { CToken } from "../external/CToken.sol"; import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; // Internal references import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { Token } from "@sense-finance/v1-core/src/tokens/Token.sol"; import { FixedMath } from "@sense-finance/v1-core/src/external/FixedMath.sol"; import { BaseAdapter as Adapter } from "@sense-finance/v1-core/src/adapters/BaseAdapter.sol"; contract TargetOracle is PriceOracle, Trust { using FixedMath for uint256; /// @notice target address -> adapter address mapping(address => address) public adapters; constructor() Trust(msg.sender) {} function setTarget(address target, address adapter) external requiresTrust { adapters[target] = adapter; } function getUnderlyingPrice(CToken cToken) external view override returns (uint256) { // For the sense Fuse pool, the underlying will be the Target. The semantics here can be a little confusing // as we now have two layers of underlying, cToken -> Target (cToken's underlying) -> Target's underlying Token target = Token(cToken.underlying()); return _price(address(target)); } function price(address target) external view override returns (uint256) { return _price(target); } function _price(address target) internal view returns (uint256) { address adapter = adapters[address(target)]; if (adapter == address(0)) revert Errors.AdapterNotSet(); // Use the cached scale for view function compatibility uint256 scale = Adapter(adapter).scaleStored(); // `Target / Target's underlying` * `Target's underlying / ETH` = `Price of Target in ETH` // // `scale` and the value returned by `getUnderlyingPrice` are expected to be WADs return scale.fmul(Adapter(adapter).getUnderlyingPrice()); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { PriceOracle } from "../external/PriceOracle.sol"; import { CToken } from "../external/CToken.sol"; import { BalancerOracle } from "../external/BalancerOracle.sol"; import { BalancerVault } from "@sense-finance/v1-core/src/external/balancer/Vault.sol"; // Internal references import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; import { Token } from "@sense-finance/v1-core/src/tokens/Token.sol"; import { FixedMath } from "@sense-finance/v1-core/src/external/FixedMath.sol"; import { BaseAdapter as Adapter } from "@sense-finance/v1-core/src/adapters/BaseAdapter.sol"; interface SpaceLike { function getImpliedRateFromPrice(uint256 pTPriceInTarget) external view returns (uint256); function getPriceFromImpliedRate(uint256 impliedRate) external view returns (uint256); function getTotalSamples() external pure returns (uint256); function adapter() external view returns (address); } contract PTOracle is PriceOracle, Trust { using FixedMath for uint256; /// @notice PT address -> pool address for oracle reads mapping(address => address) public pools; /// @notice Minimum implied rate this oracle will tolerate for PTs uint256 public floorRate; uint256 public twapPeriod; constructor() Trust(msg.sender) { floorRate = 3e18; // 300% twapPeriod = 5.5 hours; } function setFloorRate(uint256 _floorRate) external requiresTrust { floorRate = _floorRate; } function setTwapPeriod(uint256 _twapPeriod) external requiresTrust { twapPeriod = _twapPeriod; } function setPrincipal(address pt, address pool) external requiresTrust { pools[pt] = pool; } function getUnderlyingPrice(CToken cToken) external view override returns (uint256) { // The underlying here will be a Principal Token return _price(cToken.underlying()); } function price(address pt) external view override returns (uint256) { return _price(pt); } function _price(address pt) internal view returns (uint256) { BalancerOracle pool = BalancerOracle(pools[address(pt)]); if (pool == BalancerOracle(address(0))) revert Errors.PoolNotSet(); // if getSample(buffer_size) returns 0s, the oracle buffer is not full yet and a price can't be read // https://dev.balancer.fi/references/contracts/apis/pools/weightedpool2tokens#api (, , , , , , uint256 sampleTs) = pool.getSample(SpaceLike(address(pool)).getTotalSamples() - 1); // Revert if the pool's oracle can't be used yet, preventing this market from being deployed // on Fuse until we're able to read a TWAP if (sampleTs == 0) revert Errors.OracleNotReady(); BalancerOracle.OracleAverageQuery[] memory queries = new BalancerOracle.OracleAverageQuery[](1); // The BPT price slot in Space carries the implied rate TWAP queries[0] = BalancerOracle.OracleAverageQuery({ variable: BalancerOracle.Variable.BPT_PRICE, secs: twapPeriod, ago: 1 hours // take the oracle from 1 hour ago plus twapPeriod ago to 1 hour ago }); uint256[] memory results = pool.getTimeWeightedAverage(queries); // note: impliedRate is pulled from the BPT price slot in BalancerOracle.OracleAverageQuery uint256 impliedRate = results[0]; if (impliedRate > floorRate) { impliedRate = floorRate; } address target = Adapter(SpaceLike(address(pool)).adapter()).target(); // `Principal Token / target` * `target / ETH` = `Price of Principal Token in ETH` // // Assumes the caller is the master oracle, which will have its own strategy for getting the underlying price return SpaceLike(address(pool)).getPriceFromImpliedRate(impliedRate).fmul(PriceOracle(msg.sender).price(target)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; // External references import { ERC20 } from "@rari-capital/solmate/src/tokens/ERC20.sol"; import { PriceOracle } from "../external/PriceOracle.sol"; import { CToken } from "../external/CToken.sol"; import { BalancerVault } from "@sense-finance/v1-core/src/external/balancer/Vault.sol"; import { BalancerPool } from "@sense-finance/v1-core/src/external/balancer/Pool.sol"; // Internal references import { Trust } from "@sense-finance/v1-utils/src/Trust.sol"; import { FixedMath } from "@sense-finance/v1-core/src/external/FixedMath.sol"; import { Errors } from "@sense-finance/v1-utils/src/libs/Errors.sol"; import { BaseAdapter as Adapter } from "@sense-finance/v1-core/src/adapters/BaseAdapter.sol"; interface SpaceLike { function getFairBPTPrice(uint256 ptTwapDuration) external view returns (uint256); function adapter() external view returns (address); } contract LPOracle is PriceOracle, Trust { using FixedMath for uint256; /// @notice PT address -> pool address for oracle reads mapping(address => address) public pools; uint256 public twapPeriod; constructor() Trust(msg.sender) { twapPeriod = 5.5 hours; } function setTwapPeriod(uint256 _twapPeriod) external requiresTrust { twapPeriod = _twapPeriod; } function getUnderlyingPrice(CToken cToken) external view override returns (uint256) { // The underlying here will be an LP Token return _price(cToken.underlying()); } function price(address pt) external view override returns (uint256) { return _price(pt); } function _price(address _pool) internal view returns (uint256) { SpaceLike pool = SpaceLike(_pool); address target = Adapter(pool.adapter()).target(); // Price per BPT in ETH terms, where the PT side of the pool is valued using the TWAP oracle return pool.getFairBPTPrice(twapPeriod).fmul(PriceOracle(msg.sender).price(target)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity 0.8.11; /// @title Price Oracle /// @author Compound interface CToken { function underlying() external view returns (address); function mint(uint256 mintAmount) external returns (uint256); function redeem(uint256 redeemTokens) external returns (uint256); function borrow(uint256 borrowAmount) external returns (uint256); function repayBorrow(uint256 repayAmount) external returns (uint256); function exchangeRateCurrent() external returns (uint256); function decimals() external view returns (uint8); }
{ "optimizer": { "enabled": true, "runs": 15000 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_divider","type":"address"},{"internalType":"address","name":"_poolManager","type":"address"},{"internalType":"address","name":"_spaceFactory","type":"address"},{"internalType":"address","name":"_balancerVault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ExistingValue","type":"error"},{"inputs":[],"name":"FactoryNotSupported","type":"error"},{"inputs":[],"name":"FlashBorrowFailed","type":"error"},{"inputs":[],"name":"FlashUntrustedBorrower","type":"error"},{"inputs":[],"name":"FlashUntrustedLoanInitiator","type":"error"},{"inputs":[],"name":"OnlyPermissionless","type":"error"},{"inputs":[],"name":"SwapTooSmall","type":"error"},{"inputs":[],"name":"TargetMismatch","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"}],"name":"AdapterDeployed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"}],"name":"AdapterOnboarded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"}],"name":"AdapterVerified","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"factory","type":"address"},{"indexed":true,"internalType":"bool","name":"isOn","type":"bool"}],"name":"FactoryChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newPoolManager","type":"address"}],"name":"PoolManagerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"adapter","type":"address"},{"indexed":true,"internalType":"uint256","name":"maturity","type":"uint256"},{"indexed":true,"internalType":"address","name":"sponsor","type":"address"}],"name":"SeriesSponsored","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newSpaceFactory","type":"address"}],"name":"SpaceFactoryChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"assetIn","type":"address"},{"indexed":false,"internalType":"address","name":"assetOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"},{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"}],"name":"Swapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"trusted","type":"bool"}],"name":"UserTrustUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"adapter","type":"address"},{"indexed":false,"internalType":"uint256","name":"maturity","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"targetIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"targetReturned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ytOut","type":"uint256"}],"name":"YTsPurchased","type":"event"},{"inputs":[],"name":"MIN_YT_SWAP_IN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_ESTIMATE_ACCEPTABLE_ERROR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"tBal","type":"uint256"},{"internalType":"uint8","name":"mode","type":"uint8"},{"internalType":"uint256","name":"minBptOut","type":"uint256"}],"name":"addLiquidityFromTarget","outputs":[{"internalType":"uint256","name":"tAmount","type":"uint256"},{"internalType":"uint256","name":"issued","type":"uint256"},{"internalType":"uint256","name":"lpShares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"uBal","type":"uint256"},{"internalType":"uint8","name":"mode","type":"uint8"},{"internalType":"uint256","name":"minBptOut","type":"uint256"}],"name":"addLiquidityFromUnderlying","outputs":[{"internalType":"uint256","name":"tAmount","type":"uint256"},{"internalType":"uint256","name":"issued","type":"uint256"},{"internalType":"uint256","name":"lpShares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"balancerVault","outputs":[{"internalType":"contract BalancerVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"f","type":"address"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"deployAdapter","outputs":[{"internalType":"address","name":"adapter","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"divider","outputs":[{"internalType":"contract Divider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"factories","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isTrusted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"srcAdapter","type":"address"},{"internalType":"address","name":"dstAdapter","type":"address"},{"internalType":"uint256","name":"srcMaturity","type":"uint256"},{"internalType":"uint256","name":"dstMaturity","type":"uint256"},{"internalType":"uint256","name":"lpBal","type":"uint256"},{"internalType":"uint256[]","name":"minAmountsOut","type":"uint256[]"},{"internalType":"uint256","name":"minAccepted","type":"uint256"},{"internalType":"uint8","name":"mode","type":"uint8"},{"internalType":"bool","name":"intoTarget","type":"bool"},{"internalType":"uint256","name":"minBptOut","type":"uint256"}],"name":"migrateLiquidity","outputs":[{"internalType":"uint256","name":"tAmount","type":"uint256"},{"internalType":"uint256","name":"issued","type":"uint256"},{"internalType":"uint256","name":"lpShares","type":"uint256"},{"internalType":"uint256","name":"ptBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"initiator","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"amountBorrrowed","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onFlashLoan","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"bool","name":"addAdapter","type":"bool"}],"name":"onboardAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"poolManager","outputs":[{"internalType":"contract PoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"lpBal","type":"uint256"},{"internalType":"uint256[]","name":"minAmountsOut","type":"uint256[]"},{"internalType":"uint256","name":"minAccepted","type":"uint256"},{"internalType":"bool","name":"intoTarget","type":"bool"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"tBal","type":"uint256"},{"internalType":"uint256","name":"ptBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"lpBal","type":"uint256"},{"internalType":"uint256[]","name":"minAmountsOut","type":"uint256[]"},{"internalType":"uint256","name":"minAccepted","type":"uint256"},{"internalType":"bool","name":"intoTarget","type":"bool"}],"name":"removeLiquidityAndUnwrapTarget","outputs":[{"internalType":"uint256","name":"uBal","type":"uint256"},{"internalType":"uint256","name":"ptBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"f","type":"address"},{"internalType":"bool","name":"isOn","type":"bool"}],"name":"setFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bool","name":"trusted","type":"bool"}],"name":"setIsTrusted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newPoolManager","type":"address"}],"name":"setPoolManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newSpaceFactory","type":"address"}],"name":"setSpaceFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"spaceFactory","outputs":[{"internalType":"contract SpaceFactoryLike","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"bool","name":"withPool","type":"bool"}],"name":"sponsorSeries","outputs":[{"internalType":"address","name":"pt","type":"address"},{"internalType":"address","name":"yt","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"ptBal","type":"uint256"},{"internalType":"uint256","name":"minAccepted","type":"uint256"}],"name":"swapPTsForTarget","outputs":[{"internalType":"uint256","name":"tBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"ptBal","type":"uint256"},{"internalType":"uint256","name":"minAccepted","type":"uint256"}],"name":"swapPTsForUnderlying","outputs":[{"internalType":"uint256","name":"uBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"tBal","type":"uint256"},{"internalType":"uint256","name":"minAccepted","type":"uint256"}],"name":"swapTargetForPTs","outputs":[{"internalType":"uint256","name":"ptBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"targetIn","type":"uint256"},{"internalType":"uint256","name":"targetToBorrow","type":"uint256"},{"internalType":"uint256","name":"minOut","type":"uint256"}],"name":"swapTargetForYTs","outputs":[{"internalType":"uint256","name":"targetBal","type":"uint256"},{"internalType":"uint256","name":"ytBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"uBal","type":"uint256"},{"internalType":"uint256","name":"minAccepted","type":"uint256"}],"name":"swapUnderlyingForPTs","outputs":[{"internalType":"uint256","name":"ptBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"underlyingIn","type":"uint256"},{"internalType":"uint256","name":"targetToBorrow","type":"uint256"},{"internalType":"uint256","name":"minOut","type":"uint256"}],"name":"swapUnderlyingForYTs","outputs":[{"internalType":"uint256","name":"targetBal","type":"uint256"},{"internalType":"uint256","name":"ytBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"ytBal","type":"uint256"}],"name":"swapYTsForTarget","outputs":[{"internalType":"uint256","name":"tBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"uint256","name":"ytBal","type":"uint256"}],"name":"swapYTsForUnderlying","outputs":[{"internalType":"uint256","name":"uBal","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"verified","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"adapter","type":"address"},{"internalType":"bool","name":"addToPool","type":"bool"}],"name":"verifyAdapter","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60c06040523480156200001157600080fd5b5060405162005cfc38038062005cfc8339810160408190526200003491620000e3565b3360008181526020818152604091829020805460ff19166001908117909155915191825282917fe95aec380cae16330d146d5499ef7db6f3657e477104a733e771bc09e500d986910160405180910390a2506001600160a01b03938416608052600180549385166001600160a01b03199485161790556002805492851692909316919091179091551660a05262000140565b80516001600160a01b0381168114620000de57600080fd5b919050565b60008060008060808587031215620000fa57600080fd5b6200010585620000c6565b93506200011560208601620000c6565b92506200012560408601620000c6565b91506200013560608601620000c6565b905092959194509250565b60805160a051615ad26200022a6000396000818161026a0152818161248a0152818161259c0152818161386601528181613ef8015281816142520152818161435b0152818161497f0152614a9e015260008181610343015281816107770152818161083901528181610cbc01528181610e1401528181610ef301528181610ff60152818161168201528181611cb101528181611ef00152818161241e015281816127720152818161290901528181612a7201528181612d1201528181612fcd01528181613414015281816135b101528181613b2c01528181613dc6015261413a0152615ad26000f3fe608060405234801561001057600080fd5b50600436106101e55760003560e01c80637ab71cb01161010f578063b16bdcfe116100a2578063dc4c90d311610071578063dc4c90d3146104d9578063f8e8801e146104ec578063fab52689146104ff578063fdb8c0461461052257600080fd5b8063b16bdcfe14610494578063bfe642ca146104a7578063ce3a9128146104ba578063da43f3d6146104c657600080fd5b80638f1f30f0116100de5780638f1f30f01461043857806396d648791461044b57806397a27fbf1461046e578063a23973961461048157600080fd5b80637ab71cb0146103ec5780637aef6715146103ff578063836ce94514610412578063857bee5f1461042557600080fd5b8063318d3c371161018757806349c569cb1161015657806349c569cb1461038b5780634a6370c3146103b3578063560c9876146103c657806371013c10146103d957600080fd5b8063318d3c371461032b578063378efa371461033e578063457dcd291461036557806347c7a2121461037857600080fd5b8063158274a5116101c3578063158274a5146102655780631fc3e733146102a457806323e30c8b146102d75780632d673b7b146102f857600080fd5b80630db065f4146101ea5780630f8b15d3146102225780631393916a14610250575b600080fd5b61020d6101f8366004614c11565b60046020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b610235610230366004614c3d565b61052e565b60408051938452602084019290925290820152606001610219565b61026361025e366004614c9d565b6105ca565b005b61028c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610219565b6102b76102b2366004614cd6565b6106c3565b604080516001600160a01b03938416815292909116602083015201610219565b6102ea6102e5366004614d18565b610acc565b604051908152602001610219565b61030b610306366004614ecf565b6111e9565b604080519485526020850193909352918301526060820152608001610219565b610263610339366004614c9d565b61133b565b61028c7f000000000000000000000000000000000000000000000000000000000000000081565b6102ea610373366004614f8b565b6113c2565b6102ea610386366004614f8b565b611451565b61039e610399366004614fc6565b6114ac565b60408051928352602083019190915201610219565b61039e6103c1366004615046565b61159c565b6102ea6103d436600461508a565b6116d6565b6102636103e7366004614c9d565b6117b9565b6102356103fa366004614c3d565b6118fd565b61026361040d366004614c11565b611a25565b61039e610420366004615046565b611b0b565b60025461028c906001600160a01b031681565b6102ea610446366004614f8b565b611cee565b61020d610459366004614c11565b60006020819052908152604090205460ff1681565b6102ea61047c366004614f8b565b611e0a565b61026361048f366004614c9d565b611eee565b6102ea6104a236600461508a565b611fce565b61028c6104b53660046150bf565b612028565b6102ea64e8d4a5100081565b6102636104d4366004614c11565b612151565b60015461028c906001600160a01b031681565b61039e6104fa366004614fc6565b612230565b61020d61050d366004614c11565b60036020526000908152604090205460ff1681565b6102ea6402540be40081565b60008060006105ac3330888b6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610577573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059b9190615197565b6001600160a01b0316929190612297565b6105b9888888888861235d565b919a90995090975095505050505050565b3360009081526020819052604090205460ff16610648576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e54525553544544000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6001600160a01b0382166000818152602081815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915591519182527fe95aec380cae16330d146d5499ef7db6f3657e477104a733e771bc09e500d986910160405180910390a25050565b600080600080866001600160a01b03166327b327d06040518163ffffffff1660e01b8152600401606060405180830381865afa158015610707573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072b91906151b4565b909350915061074790506001600160a01b038316333084612297565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301526024820183905283169063095ea7b3906044016020604051808303816000875af11580156107cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107f391906151f7565b506040517f3e3972ee0000000000000000000000000000000000000000000000000000000081526001600160a01b038881166004830152602482018890523360448301527f00000000000000000000000000000000000000000000000000000000000000001690633e3972ee9060640160408051808303816000875af1158015610881573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108a59190615214565b6001600160a01b038916600090815260046020526040902054919550935060ff16156109f2576001546002546040517f0ecaea730000000000000000000000000000000000000000000000000000000081526001600160a01b038a81166004830152602482018a905292831692635e883823928b928b9290911690630ecaea73906044016020604051808303816000875af1158015610948573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061096c9190615197565b60405160e085901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b03938416600482015260248101929092529091166044820152606401600060405180830381600087803b1580156109d557600080fd5b505af11580156109e9573d6000803e3d6000fd5b50505050610a8a565b8415610a8a576002546040517f0ecaea730000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526024820189905290911690630ecaea73906044016020604051808303816000875af1158015610a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a889190615197565b505b604051339087906001600160a01b038a16907fe385633dd30b0221b25f7a6f7e18c5992b339b5686322abe8ceb999e81249cd190600090a45050935093915050565b60008080808080610adf87890189615243565b94509450945094509450846001600160a01b0316336001600160a01b031614610b34576040517f4cd0f00a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038c163014610b76576040517f14aa288800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018790526000921690638f38a55590604401602060405180830381865afa158015610be1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c059190615197565b90508115610ee9576000866001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190615197565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b03898116600483015260248201899052919250600091610e109184917f0000000000000000000000000000000000000000000000000000000000000000169063d10eb4b990604401602060405180830381865afa158015610d03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d279190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa158015610d84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da89190615299565b866001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0a9190615299565b8961245a565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ba89bebd8989898510610e505789610e52565b845b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b039093166004840152602483019190915260448201526064016020604051808303816000875af1158015610ebd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ee19190615299565b5050506111b7565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663dfe5ef488787610f248f896152e1565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b039093166004840152602483019190915260448201526064016020604051808303816000875af1158015610f8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb39190615299565b506040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018790526000917f00000000000000000000000000000000000000000000000000000000000000009091169063d10eb4b990604401602060405180830381865afa15801561103f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110639190615197565b90506111b481886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110cb9190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa158015611128573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114c9190615299565b856001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ae9190615299565b8861245a565b50505b507f439148f0bbc682ca079e46d6e2c2f0c1e3b820f1a291b069d8882abf8cf18dd99c9b505050505050505050505050565b6000806000808c6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561122d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112519190615197565b6001600160a01b03168e6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611298573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112bc9190615197565b6001600160a01b0316146112fc576040517f73f3f92700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061130c8f8e8d8d8d8c6126c6565b9250905061131d8e8d838b8a61235d565b809550819650829750505050509a509a509a509a9650505050505050565b3360009081526020819052604090205460ff166113b4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b6113be8282612b3d565b5050565b60006113d085858585612cce565b90506114493382876001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114399190615197565b6001600160a01b03169190612eca565b949350505050565b6000611497333085886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610577573d6000803e3d6000fd5b6114a385858585612f89565b95945050505050565b60008060006114bf8989898989896126c6565b6040517f51c39ea1000000000000000000000000000000000000000000000000000000008152600481018390529093509091506115909033906001600160a01b038c16906351c39ea1906024016020604051808303816000875af115801561152b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061154f9190615299565b9450848b6001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b50965096945050505050565b6000806115e33330878a6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610577573d6000803e3d6000fd5b6115f08787878787613193565b809250819350505061163b3383896001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b038881166004830152602482018890526116cc91339184917f00000000000000000000000000000000000000000000000000000000000000009091169063574e7795906044015b602060405180830381865afa158015611415573d6000803e3d6000fd5b9550959350505050565b6000806116e53386868661356d565b6040517f51c39ea1000000000000000000000000000000000000000000000000000000008152600481018290529091506001600160a01b038616906351c39ea1906024016020604051808303816000875af1158015611748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176c9190615299565b91506117b13383876001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b509392505050565b3360009081526020819052604090205460ff16611832576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b6001600160a01b03821660009081526003602052604090205460ff161515811515141561188b576040517fe2be007400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03821660008181526003602052604080822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915590519092917fe63b400aabb14e166c6cf1b963fc9332222bc4dfe22a7fa4a487411d6cb83b3191a35050565b600080600080886001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611941573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119659190615197565b905061197c6001600160a01b03821633308a612297565b6040517f4aae9fed000000000000000000000000000000000000000000000000000000008152600481018890526000906001600160a01b038b1690634aae9fed906024016020604051808303816000875af11580156119df573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a039190615299565b9050611a128a8a838a8a61235d565b919c909b50909950975050505050505050565b3360009081526020819052604090205460ff16611a9e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b600180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040519081527fe53395243914ebc025ce712146f66fa5e9d3f04b308fae19ac4123350d1cd20f906020015b60405180910390a150565b6000806000876001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b729190615197565b9050611b896001600160a01b038216333089612297565b6040517f4aae9fed000000000000000000000000000000000000000000000000000000008152600481018790526000906001600160a01b038a1690634aae9fed906024016020604051808303816000875af1158015611bec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c109190615299565b9050611c1f8989838989613193565b8094508195505050611c6a33858b6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b038a81166004830152602482018a9052611ce291339186917f00000000000000000000000000000000000000000000000000000000000000009091169063574e7795906044016116af565b50509550959350505050565b600080856001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d539190615197565b9050611d6a6001600160a01b038216333087612297565b6040517f4aae9fed000000000000000000000000000000000000000000000000000000008152600481018590526000906001600160a01b03881690634aae9fed906024016020604051808303816000875af1158015611dcd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611df19190615299565b9050611dff87878387612f89565b979650505050505050565b600080611e1986868686612cce565b6040517f51c39ea1000000000000000000000000000000000000000000000000000000008152600481018290529091506001600160a01b038716906351c39ea1906024016020604051808303816000875af1158015611e7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ea09190615299565b9150611ee53383886001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b50949350505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a1256f9f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f7091906151f7565b158015611f8d57503360009081526020819052604090205460ff16155b15611fc4576040517f8719352c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6113be8282613a98565b6000611fdc3385858561356d565b90506120213382866001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b9392505050565b6001600160a01b03831660009081526003602052604081205460ff1661207a576040517fe459d6aa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f3cad2dcd0000000000000000000000000000000000000000000000000000000081526001600160a01b03851690633cad2dcd906120c19086908690600401615364565b6020604051808303816000875af11580156120e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121049190615197565b6040519091506001600160a01b038216907f5c4dabb7dca79d442edd65b39b410aef25f4eea4a498150e7e442d5ca508f6d590600090a2612146816001612b3d565b612021816001613a98565b3360009081526020819052604090205460ff166121ca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b600280547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040519081527f40f94fbaa39b621298d12a4ed99759484633cff7680c01e6bb3a07ae7aa8d79590602001611b00565b6000806122418888888888886126c6565b809250819350505061228c33838a6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b965096945050505050565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080612356576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c4544000000000000000000000000604482015260640161063f565b5050505050565b600080600061236e88888887613e5c565b9092509050811561244f5760ff85166123d75761238d3089898561356d565b92506123d233848a6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b61244f565b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526024820189905261244f91339185917f00000000000000000000000000000000000000000000000000000000000000009091169063574e7795906044016116af565b955095509592505050565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152602482018590526000919087169063095ea7b3906044016020604051808303816000875af11580156124e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061250a91906151f7565b506040805160c081018252848152600060208083018290526001600160a01b03808b168486015289811660608086019190915260808086018b90528651808501885285815260a087015286519081018752308082529381018590528087019390935282019290925292517f52bbbe290000000000000000000000000000000000000000000000000000000081529192917f0000000000000000000000000000000000000000000000000000000000000000909116906352bbbe29906125f9908590859089907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff906004016153f0565b6020604051808303816000875af1158015612618573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061263c9190615299565b604080516001600160a01b038b811682528a166020820152908101889052606081018290529093507fffffffff000000000000000000000000000000000000000000000000000000006000351690869033907f771a8215d0541283507c0ebd99d6a6406b7254dc8feccdaa6c160c305d68d7489060800160405180910390a4505095945050505050565b6000806000886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015612709573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061272d9190615197565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b038b81166004830152602482018b90529192506000917f0000000000000000000000000000000000000000000000000000000000000000169063d10eb4b990604401602060405180830381865afa1580156127b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127dd9190615197565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038d81166004830152602482018d905292935060009290911690638f38a55590604401602060405180830381865afa15801561284d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128719190615197565b90506000816001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d79190615299565b90506128ee6001600160a01b03831633308d612297565b60006128fd8285878d8f61424b565b809250819850505060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166395197d308f8f6040518363ffffffff1660e01b81526004016129699291906001600160a01b03929092168252602082015260400190565b602060405180830381865afa158015612986573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129aa9190615299565b1115612af057612a1f8d6001600160a01b0316636fd5ae156040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a159190615299565b6010908116141590565b15612a2c57809550612b13565b6040517f2b83cccd0000000000000000000000000000000000000000000000000000000081526001600160a01b038e81166004830152602482018e9052604482018390527f00000000000000000000000000000000000000000000000000000000000000001690632b83cccd906064016020604051808303816000875af1158015612abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612adf9190615299565b612ae990886152e1565b9650612b13565b600081118015612afd5750875b15612b0f57612adf848683858d61245a565b8095505b8515612b2d57612b2d6001600160a01b0385163388612eca565b5050505050965096945050505050565b6001600160a01b038216600090815260046020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015612c9657600160009054906101000a90046001600160a01b03166001600160a01b0316631ec64fef836001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015612be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0a9190615197565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b03918216600482015290851660248201526044016020604051808303816000875af1158015612c70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c949190615197565b505b6040516001600160a01b038316907ff9f4ea4fb47406a3baf9adc8bd38b1c82e5a5fee5de9b3c5af3218400fb530c090600090a25050565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526024820185905260009182917f0000000000000000000000000000000000000000000000000000000000000000169063d10eb4b990604401602060405180830381865afa158015612d59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d7d9190615197565b9050612d946001600160a01b038216333087612297565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038881166004830152602482018890526000921690638f38a55590604401602060405180830381865afa158015612dff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e239190615197565b9050611dff82886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e8b9190615197565b87846001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d6000803e3d6000fd5b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080612f83576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c45440000000000000000000000000000000000604482015260640161063f565b50505050565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526024820185905260009182917f0000000000000000000000000000000000000000000000000000000000000000169063d10eb4b990604401602060405180830381865afa158015613014573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130389190615197565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526024820189905292935060009290911690638f38a55590604401602060405180830381865afa1580156130a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130cc9190615197565b9050613173876001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561310f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131339190615197565b8387846001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d6000803e3d6000fd5b92506131896001600160a01b0383163385612eca565b5050949350505050565b604080516001600160a01b03871660208201529081018590526060810184905260808101829052600060a08201819052908190819060c00160405160208183030381529060405290506000886001600160a01b0316635cffe9de308b6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561322c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132509190615197565b89866040518563ffffffff1660e01b815260040161327194939291906154ad565b6020604051808303816000875af1158015613290573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132b491906151f7565b9050806132ed576040517f87cce7b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561332b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061334f9190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190615299565b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b038b81166004830152602482018b90529195507f00000000000000000000000000000000000000000000000000000000000000009091169063574e779590604401602060405180830381865afa15801561345d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134819190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156134e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135049190615299565b604080516001600160a01b038c168152602081018b9052908101899052606081018690526080810182905290935033907f25841a32c1c1cef7b2d2bcea90bd94fcafbcd2459595475b86087699c16dc4959060a00160405180910390a250509550959350505050565b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301526024820184905260009182917f0000000000000000000000000000000000000000000000000000000000000000169063574e779590604401602060405180830381865afa1580156135f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061361c9190615197565b905064e8d4a51000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613662573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061368691906154df565b6136919060126154fc565b61369c90600a61563f565b6136a6908561564e565b116136dd576040517f81406f4600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018790526000921690638f38a55590604401602060405180830381865afa158015613748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376c9190615197565b90506001600160a01b0387163014613793576137936001600160a01b038316333087612297565b6000816001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156137d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137f79190615299565b9050600080836001600160a01b0316635863056d6040518163ffffffff1660e01b81526004016040805180830381865afa158015613839573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061385d919061568b565b915091506000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f94d4668866040518263ffffffff1660e01b81526004016138b291815260200190565b600060405180830381865afa1580156138cf573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052613915919081019061570a565b50915091506000866001600160a01b0316639d2c110c60405180610120016040528060018081111561394957613949615386565b8152602001868881518110613960576139606157d8565b60200260200101516001600160a01b03168152602001868981518110613988576139886157d8565b60200260200101516001600160a01b031681526020018d81526020018981526020016000815260200160006001600160a01b0316815260200160006001600160a01b03168152602001604051806020016040528060008152508152508487815181106139f6576139f66157d8565b6020026020010151858981518110613a1057613a106157d8565b60200260200101516040518463ffffffff1660e01b8152600401613a3693929190615807565b6020604051808303816000875af1158015613a55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a799190615299565b9050613a878c8c8c846144f1565b9d9c50505050505050505050505050565b6000826001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ad8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613afc9190615197565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60248301529192509082169063095ea7b3906044016020604051808303816000875af1158015613ba7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bcb91906151f7565b506040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602483015282169063095ea7b3906044016020604051808303816000875af1158015613c53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c7791906151f7565b50826001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613cb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cda9190615197565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6024830152919091169063095ea7b3906044016020604051808303816000875af1158015613d63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d8791906151f7565b508115613e23576040517f60d54d410000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301527f000000000000000000000000000000000000000000000000000000000000000016906360d54d4190602401600060405180830381600087803b158015613e0a57600080fd5b505af1158015613e1e573d6000803e3d6000fd5b505050505b6040516001600160a01b038416907fae4a2338a83fc8bfaca3a6cbb54494b5c00e9d8a65dc9cf39135b00da497798290600090a2505050565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038681166004830152602482018690526000928392839290911690638f38a55590604401602060405180830381865afa158015613ecd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef19190615197565b90506000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f94d4668846001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f879190615299565b6040518263ffffffff1660e01b8152600401613fa591815260200190565b600060405180830381865afa158015613fc2573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052614008919081019061570a565b5091509150600080846001600160a01b0316635863056d6040518163ffffffff1660e01b81526004016040805180830381865afa15801561404d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614071919061568b565b915091506000838381518110614089576140896157d8565b60200260200101516000141590506000816140a55760006140e3565b6140e38d8686815181106140bb576140bb6157d8565b60200260200101518786815181106140d5576140d56157d8565b60200260200101518e6147be565b9050600081116140f45760006141a7565b6040517fdfe5ef480000000000000000000000000000000000000000000000000000000081526001600160a01b038e81166004830152602482018e9052604482018390527f0000000000000000000000000000000000000000000000000000000000000000169063dfe5ef48906064016020604051808303816000875af1158015614183573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141a79190615299565b604080516002808252606082018352929b5060009290916020830190803683370190505090506141d7828d6158ce565b8185815181106141e9576141e96157d8565b60200260200101818152505089818681518110614208576142086157d8565b6020026020010181815250506142388860405180606001604052808a81526020018481526020018e8152506148d6565b9850505050505050505094509492505050565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f94d4668896040518263ffffffff1660e01b815260040161429e91815260200190565b600060405180830381865afa1580156142bb573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052614301919081019061570a565b50509050600061430e8290565b9050600060405180608001604052808381526020018881526020018760405160200161433c91815260200190565b60405160208183030381529060405281526020016000151581525090507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638bdb39138b3030856040518563ffffffff1660e01b81526004016143ab94939291906159af565b600060405180830381600087803b1580156143c557600080fd5b505af11580156143d9573d6000803e3d6000fd5b50506040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038b1692506370a082319150602401602060405180830381865afa15801561443a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061445e9190615299565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529095506001600160a01b038a16906370a0823190602401602060405180830381865afa1580156144be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144e29190615299565b93505050509550959350505050565b600080856001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015614532573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145569190615197565b90506000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614598573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145bc91906154df565b60ff1690506000600982106145f5576145d68260126158ce565b6145e190600a6159e1565b6145f0906402540be4006159ed565b6145f8565b60015b9050600088888861460985826158ce565b604080516001600160a01b03909516602086015284019290925260608301526080820152600160a082015260c001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f5cffe9de00000000000000000000000000000000000000000000000000000000825291506000906001600160a01b038b1690635cffe9de906146b390309089908c9088906004016154ad565b6020604051808303816000875af11580156146d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146f691906151f7565b90508061472f576040517f87cce7b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa15801561478c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147b09190615299565b9a9950505050505050505050565b60006114a36148cf856148be866148b88a6001600160a01b031663b8c15a9f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561480c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148309190615a28565b614854906fffffffffffffffffffffffffffffffff16670de0b6b3a76400006158ce565b8b6001600160a01b031663f51e181a6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015614894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148b89190615299565b90614bab565b6148c891906152e1565b8690614bc9565b8390614bab565b600080836001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015614917573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061493b9190615299565b835190915060005b84515160ff82161015614a46578451805160ff8316908110614967576149676157d8565b60200260200101516001600160a01b031663095ea7b37f000000000000000000000000000000000000000000000000000000000000000087602001518460ff16815181106149b7576149b76157d8565b60200260200101516040518363ffffffff1660e01b81526004016149f09291906001600160a01b03929092168252602082015260400190565b6020604051808303816000875af1158015614a0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a3391906151f7565b5080614a3e81615a5a565b915050614943565b50600060405180608001604052808381526020018660200151815260200186602001518760400151604051602001614a7f929190615a7a565b60405160208183030381529060405281526020016000151581525090507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b95cac28843033856040518563ffffffff1660e01b8152600401614aee94939291906159af565b600060405180830381600087803b158015614b0857600080fd5b505af1158015614b1c573d6000803e3d6000fd5b50506040517f70a082310000000000000000000000000000000000000000000000000000000081523360048201526001600160a01b03891692506370a082319150602401602060405180830381865afa158015614b7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ba19190615299565b9695505050505050565b6000614bc08383670de0b6b3a7640000614bda565b90505b92915050565b6000614bc083670de0b6b3a7640000845b828202811515841585830485141716614bf257600080fd5b0492915050565b6001600160a01b0381168114614c0e57600080fd5b50565b600060208284031215614c2357600080fd5b813561202181614bf9565b60ff81168114614c0e57600080fd5b600080600080600060a08688031215614c5557600080fd5b8535614c6081614bf9565b945060208601359350604086013592506060860135614c7e81614c2e565b949793965091946080013592915050565b8015158114614c0e57600080fd5b60008060408385031215614cb057600080fd5b8235614cbb81614bf9565b91506020830135614ccb81614c8f565b809150509250929050565b600080600060608486031215614ceb57600080fd5b8335614cf681614bf9565b9250602084013591506040840135614d0d81614c8f565b809150509250925092565b60008060008060008060a08789031215614d3157600080fd5b8635614d3c81614bf9565b95506020870135614d4c81614bf9565b94506040870135935060608701359250608087013567ffffffffffffffff80821115614d7757600080fd5b818901915089601f830112614d8b57600080fd5b813581811115614d9a57600080fd5b8a6020828501011115614dac57600080fd5b6020830194508093505050509295509295509295565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715614e3857614e38614dc2565b604052919050565b600067ffffffffffffffff821115614e5a57614e5a614dc2565b5060051b60200190565b600082601f830112614e7557600080fd5b81356020614e8a614e8583614e40565b614df1565b82815260059290921b84018101918181019086841115614ea957600080fd5b8286015b84811015614ec45780358352918301918301614ead565b509695505050505050565b6000806000806000806000806000806101408b8d031215614eef57600080fd5b8a35614efa81614bf9565b995060208b0135614f0a81614bf9565b985060408b0135975060608b0135965060808b0135955060a08b013567ffffffffffffffff811115614f3b57600080fd5b614f478d828e01614e64565b95505060c08b0135935060e08b0135614f5f81614c2e565b92506101008b0135614f7081614c8f565b809250506101208b013590509295989b9194979a5092959850565b60008060008060808587031215614fa157600080fd5b8435614fac81614bf9565b966020860135965060408601359560600135945092505050565b60008060008060008060c08789031215614fdf57600080fd5b8635614fea81614bf9565b95506020870135945060408701359350606087013567ffffffffffffffff81111561501457600080fd5b61502089828a01614e64565b9350506080870135915060a087013561503881614c8f565b809150509295509295509295565b600080600080600060a0868803121561505e57600080fd5b853561506981614bf9565b97602087013597506040870135966060810135965060800135945092505050565b60008060006060848603121561509f57600080fd5b83356150aa81614bf9565b95602085013595506040909401359392505050565b6000806000606084860312156150d457600080fd5b83356150df81614bf9565b92506020848101356150f081614bf9565b9250604085013567ffffffffffffffff8082111561510d57600080fd5b818701915087601f83011261512157600080fd5b81358181111561513357615133614dc2565b615163847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601614df1565b9150808252888482850101111561517957600080fd5b80848401858401376000848284010152508093505050509250925092565b6000602082840312156151a957600080fd5b815161202181614bf9565b6000806000606084860312156151c957600080fd5b83516151d481614bf9565b60208501519093506151e581614bf9565b80925050604084015190509250925092565b60006020828403121561520957600080fd5b815161202181614c8f565b6000806040838503121561522757600080fd5b825161523281614bf9565b6020840151909250614ccb81614bf9565b600080600080600060a0868803121561525b57600080fd5b853561526681614bf9565b9450602086013593506040860135925060608601359150608086013561528b81614c8f565b809150509295509295909350565b6000602082840312156152ab57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600082198211156152f4576152f46152b2565b500190565b6000815180845260005b8181101561531f57602081850181015186830182015201615303565b81811115615331576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6001600160a01b038316815260406020820152600061144960408301846152f9565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600281106153ec577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b9052565b60e08152845160e0820152600060208601516154106101008401826153b5565b5060408601516001600160a01b03908116610120840152606087015116610140830152608086015161016083015260a086015160c06101808401526154596101a08401826152f9565b91505061549b60208301866001600160a01b03808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c0015292915050565b60006001600160a01b03808716835280861660208401525083604083015260806060830152614ba160808301846152f9565b6000602082840312156154f157600080fd5b815161202181614c2e565b600060ff821660ff841680821015615516576155166152b2565b90039392505050565b600181815b8085111561557857817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0482111561555e5761555e6152b2565b8085161561556b57918102915b93841c9390800290615524565b509250929050565b60008261558f57506001614bc3565b8161559c57506000614bc3565b81600181146155b257600281146155bc576155d8565b6001915050614bc3565b60ff8411156155cd576155cd6152b2565b50506001821b614bc3565b5060208310610133831016604e8410600b84101617156155fb575081810a614bc3565b615605838361551f565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115615637576156376152b2565b029392505050565b6000614bc060ff841683615580565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615615686576156866152b2565b500290565b6000806040838503121561569e57600080fd5b505080516020909101519092909150565b600082601f8301126156c057600080fd5b815160206156d0614e8583614e40565b82815260059290921b840181019181810190868411156156ef57600080fd5b8286015b84811015614ec457805183529183019183016156f3565b60008060006060848603121561571f57600080fd5b835167ffffffffffffffff8082111561573757600080fd5b818601915086601f83011261574b57600080fd5b8151602061575b614e8583614e40565b82815260059290921b8401810191818101908a84111561577a57600080fd5b948201945b838610156157a157855161579281614bf9565b8252948201949082019061577f565b918901519197509093505050808211156157ba57600080fd5b506157c7868287016156af565b925050604084015190509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b606081526158196060820185516153b5565b6000602085015161583560808401826001600160a01b03169052565b5060408501516001600160a01b03811660a084015250606085015160c0830152608085015160e083015260a0850151610100818185015260c0870151915061012061588a818601846001600160a01b03169052565b60e08801516001600160a01b03166101408601529087015161016085019190915290506158bb6101808401826152f9565b6020840195909552505060400152919050565b6000828210156158e0576158e06152b2565b500390565b600081518084526020808501945080840160005b83811015615915578151875295820195908201906001016158f9565b509495945050505050565b8051608080845281519084018190526000916020919082019060a0860190845b818110156159655783516001600160a01b031683529284019291840191600101615940565b50508285015191508581038387015261597e81836158e5565b925050506040830151848203604086015261599982826152f9565b91505060608301516117b1606086018215159052565b84815260006001600160a01b03808616602084015280851660408401525060806060830152614ba16080830184615920565b6000614bc08383615580565b600082615a23577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600060208284031215615a3a57600080fd5b81516fffffffffffffffffffffffffffffffff8116811461202157600080fd5b600060ff821660ff811415615a7157615a716152b2565b60010192915050565b604081526000615a8d60408301856158e5565b9050826020830152939250505056fea264697066735822122056dca0d2b10eb7769e8cf4038d14d7e56dc9c76b27843e968f78a7f5c963066264736f6c634300080b003300000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0000000000000000000000000f01eb98de53ed964ac3f786b80ed8ce33f05f417000000000000000000000000984682770f1eed90c00cd57b06b151ec12e7c51c000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101e55760003560e01c80637ab71cb01161010f578063b16bdcfe116100a2578063dc4c90d311610071578063dc4c90d3146104d9578063f8e8801e146104ec578063fab52689146104ff578063fdb8c0461461052257600080fd5b8063b16bdcfe14610494578063bfe642ca146104a7578063ce3a9128146104ba578063da43f3d6146104c657600080fd5b80638f1f30f0116100de5780638f1f30f01461043857806396d648791461044b57806397a27fbf1461046e578063a23973961461048157600080fd5b80637ab71cb0146103ec5780637aef6715146103ff578063836ce94514610412578063857bee5f1461042557600080fd5b8063318d3c371161018757806349c569cb1161015657806349c569cb1461038b5780634a6370c3146103b3578063560c9876146103c657806371013c10146103d957600080fd5b8063318d3c371461032b578063378efa371461033e578063457dcd291461036557806347c7a2121461037857600080fd5b8063158274a5116101c3578063158274a5146102655780631fc3e733146102a457806323e30c8b146102d75780632d673b7b146102f857600080fd5b80630db065f4146101ea5780630f8b15d3146102225780631393916a14610250575b600080fd5b61020d6101f8366004614c11565b60046020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b610235610230366004614c3d565b61052e565b60408051938452602084019290925290820152606001610219565b61026361025e366004614c9d565b6105ca565b005b61028c7f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c881565b6040516001600160a01b039091168152602001610219565b6102b76102b2366004614cd6565b6106c3565b604080516001600160a01b03938416815292909116602083015201610219565b6102ea6102e5366004614d18565b610acc565b604051908152602001610219565b61030b610306366004614ecf565b6111e9565b604080519485526020850193909352918301526060820152608001610219565b610263610339366004614c9d565b61133b565b61028c7f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e081565b6102ea610373366004614f8b565b6113c2565b6102ea610386366004614f8b565b611451565b61039e610399366004614fc6565b6114ac565b60408051928352602083019190915201610219565b61039e6103c1366004615046565b61159c565b6102ea6103d436600461508a565b6116d6565b6102636103e7366004614c9d565b6117b9565b6102356103fa366004614c3d565b6118fd565b61026361040d366004614c11565b611a25565b61039e610420366004615046565b611b0b565b60025461028c906001600160a01b031681565b6102ea610446366004614f8b565b611cee565b61020d610459366004614c11565b60006020819052908152604090205460ff1681565b6102ea61047c366004614f8b565b611e0a565b61026361048f366004614c9d565b611eee565b6102ea6104a236600461508a565b611fce565b61028c6104b53660046150bf565b612028565b6102ea64e8d4a5100081565b6102636104d4366004614c11565b612151565b60015461028c906001600160a01b031681565b61039e6104fa366004614fc6565b612230565b61020d61050d366004614c11565b60036020526000908152604090205460ff1681565b6102ea6402540be40081565b60008060006105ac3330888b6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610577573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059b9190615197565b6001600160a01b0316929190612297565b6105b9888888888861235d565b919a90995090975095505050505050565b3360009081526020819052604090205460ff16610648576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e54525553544544000000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6001600160a01b0382166000818152602081815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915591519182527fe95aec380cae16330d146d5499ef7db6f3657e477104a733e771bc09e500d986910160405180910390a25050565b600080600080866001600160a01b03166327b327d06040518163ffffffff1660e01b8152600401606060405180830381865afa158015610707573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061072b91906151b4565b909350915061074790506001600160a01b038316333084612297565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0811660048301526024820183905283169063095ea7b3906044016020604051808303816000875af11580156107cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107f391906151f7565b506040517f3e3972ee0000000000000000000000000000000000000000000000000000000081526001600160a01b038881166004830152602482018890523360448301527f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e01690633e3972ee9060640160408051808303816000875af1158015610881573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108a59190615214565b6001600160a01b038916600090815260046020526040902054919550935060ff16156109f2576001546002546040517f0ecaea730000000000000000000000000000000000000000000000000000000081526001600160a01b038a81166004830152602482018a905292831692635e883823928b928b9290911690630ecaea73906044016020604051808303816000875af1158015610948573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061096c9190615197565b60405160e085901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b03938416600482015260248101929092529091166044820152606401600060405180830381600087803b1580156109d557600080fd5b505af11580156109e9573d6000803e3d6000fd5b50505050610a8a565b8415610a8a576002546040517f0ecaea730000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526024820189905290911690630ecaea73906044016020604051808303816000875af1158015610a64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a889190615197565b505b604051339087906001600160a01b038a16907fe385633dd30b0221b25f7a6f7e18c5992b339b5686322abe8ceb999e81249cd190600090a45050935093915050565b60008080808080610adf87890189615243565b94509450945094509450846001600160a01b0316336001600160a01b031614610b34576040517f4cd0f00a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038c163014610b76576040517f14aa288800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018790526000921690638f38a55590604401602060405180830381865afa158015610be1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c059190615197565b90508115610ee9576000866001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190615197565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b03898116600483015260248201899052919250600091610e109184917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0169063d10eb4b990604401602060405180830381865afa158015610d03573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d279190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa158015610d84573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610da89190615299565b866001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610de6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e0a9190615299565b8961245a565b90507f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e06001600160a01b031663ba89bebd8989898510610e505789610e52565b845b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b039093166004840152602483019190915260448201526064016020604051808303816000875af1158015610ebd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ee19190615299565b5050506111b7565b6001600160a01b037f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e01663dfe5ef488787610f248f896152e1565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526001600160a01b039093166004840152602483019190915260448201526064016020604051808303816000875af1158015610f8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb39190615299565b506040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018790526000917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e09091169063d10eb4b990604401602060405180830381865afa15801561103f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110639190615197565b90506111b481886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa1580156110a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110cb9190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038516906370a0823190602401602060405180830381865afa158015611128573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114c9190615299565b856001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ae9190615299565b8861245a565b50505b507f439148f0bbc682ca079e46d6e2c2f0c1e3b820f1a291b069d8882abf8cf18dd99c9b505050505050505050505050565b6000806000808c6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561122d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112519190615197565b6001600160a01b03168e6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611298573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112bc9190615197565b6001600160a01b0316146112fc576040517f73f3f92700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600061130c8f8e8d8d8d8c6126c6565b9250905061131d8e8d838b8a61235d565b809550819650829750505050509a509a509a509a9650505050505050565b3360009081526020819052604090205460ff166113b4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b6113be8282612b3d565b5050565b60006113d085858585612cce565b90506114493382876001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114399190615197565b6001600160a01b03169190612eca565b949350505050565b6000611497333085886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610577573d6000803e3d6000fd5b6114a385858585612f89565b95945050505050565b60008060006114bf8989898989896126c6565b6040517f51c39ea1000000000000000000000000000000000000000000000000000000008152600481018390529093509091506115909033906001600160a01b038c16906351c39ea1906024016020604051808303816000875af115801561152b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061154f9190615299565b9450848b6001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b50965096945050505050565b6000806115e33330878a6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610577573d6000803e3d6000fd5b6115f08787878787613193565b809250819350505061163b3383896001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b038881166004830152602482018890526116cc91339184917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e09091169063574e7795906044015b602060405180830381865afa158015611415573d6000803e3d6000fd5b9550959350505050565b6000806116e53386868661356d565b6040517f51c39ea1000000000000000000000000000000000000000000000000000000008152600481018290529091506001600160a01b038616906351c39ea1906024016020604051808303816000875af1158015611748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061176c9190615299565b91506117b13383876001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b509392505050565b3360009081526020819052604090205460ff16611832576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b6001600160a01b03821660009081526003602052604090205460ff161515811515141561188b576040517fe2be007400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03821660008181526003602052604080822080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915590519092917fe63b400aabb14e166c6cf1b963fc9332222bc4dfe22a7fa4a487411d6cb83b3191a35050565b600080600080886001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611941573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119659190615197565b905061197c6001600160a01b03821633308a612297565b6040517f4aae9fed000000000000000000000000000000000000000000000000000000008152600481018890526000906001600160a01b038b1690634aae9fed906024016020604051808303816000875af11580156119df573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a039190615299565b9050611a128a8a838a8a61235d565b919c909b50909950975050505050505050565b3360009081526020819052604090205460ff16611a9e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b600180547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040519081527fe53395243914ebc025ce712146f66fa5e9d3f04b308fae19ac4123350d1cd20f906020015b60405180910390a150565b6000806000876001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b729190615197565b9050611b896001600160a01b038216333089612297565b6040517f4aae9fed000000000000000000000000000000000000000000000000000000008152600481018790526000906001600160a01b038a1690634aae9fed906024016020604051808303816000875af1158015611bec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c109190615299565b9050611c1f8989838989613193565b8094508195505050611c6a33858b6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b038a81166004830152602482018a9052611ce291339186917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e09091169063574e7795906044016116af565b50509550959350505050565b600080856001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d539190615197565b9050611d6a6001600160a01b038216333087612297565b6040517f4aae9fed000000000000000000000000000000000000000000000000000000008152600481018590526000906001600160a01b03881690634aae9fed906024016020604051808303816000875af1158015611dcd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611df19190615299565b9050611dff87878387612f89565b979650505050505050565b600080611e1986868686612cce565b6040517f51c39ea1000000000000000000000000000000000000000000000000000000008152600481018290529091506001600160a01b038716906351c39ea1906024016020604051808303816000875af1158015611e7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ea09190615299565b9150611ee53383886001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b50949350505050565b7f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e06001600160a01b031663a1256f9f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f7091906151f7565b158015611f8d57503360009081526020819052604090205460ff16155b15611fc4576040517f8719352c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6113be8282613a98565b6000611fdc3385858561356d565b90506120213382866001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b9392505050565b6001600160a01b03831660009081526003602052604081205460ff1661207a576040517fe459d6aa00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f3cad2dcd0000000000000000000000000000000000000000000000000000000081526001600160a01b03851690633cad2dcd906120c19086908690600401615364565b6020604051808303816000875af11580156120e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121049190615197565b6040519091506001600160a01b038216907f5c4dabb7dca79d442edd65b39b410aef25f4eea4a498150e7e442d5ca508f6d590600090a2612146816001612b3d565b612021816001613a98565b3360009081526020819052604090205460ff166121ca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600960248201527f554e545255535445440000000000000000000000000000000000000000000000604482015260640161063f565b600280547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0383169081179091556040519081527f40f94fbaa39b621298d12a4ed99759484633cff7680c01e6bb3a07ae7aa8d79590602001611b00565b6000806122418888888888886126c6565b809250819350505061228c33838a6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b965096945050505050565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080612356576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c4544000000000000000000000000604482015260640161063f565b5050505050565b600080600061236e88888887613e5c565b9092509050811561244f5760ff85166123d75761238d3089898561356d565b92506123d233848a6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611415573d6000803e3d6000fd5b61244f565b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526024820189905261244f91339185917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e09091169063574e7795906044016116af565b955095509592505050565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c881166004830152602482018590526000919087169063095ea7b3906044016020604051808303816000875af11580156124e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061250a91906151f7565b506040805160c081018252848152600060208083018290526001600160a01b03808b168486015289811660608086019190915260808086018b90528651808501885285815260a087015286519081018752308082529381018590528087019390935282019290925292517f52bbbe290000000000000000000000000000000000000000000000000000000081529192917f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8909116906352bbbe29906125f9908590859089907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff906004016153f0565b6020604051808303816000875af1158015612618573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061263c9190615299565b604080516001600160a01b038b811682528a166020820152908101889052606081018290529093507fffffffff000000000000000000000000000000000000000000000000000000006000351690869033907f771a8215d0541283507c0ebd99d6a6406b7254dc8feccdaa6c160c305d68d7489060800160405180910390a4505095945050505050565b6000806000886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015612709573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061272d9190615197565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b038b81166004830152602482018b90529192506000917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0169063d10eb4b990604401602060405180830381865afa1580156127b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127dd9190615197565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038d81166004830152602482018d905292935060009290911690638f38a55590604401602060405180830381865afa15801561284d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128719190615197565b90506000816001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128d79190615299565b90506128ee6001600160a01b03831633308d612297565b60006128fd8285878d8f61424b565b809250819850505060007f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e06001600160a01b03166395197d308f8f6040518363ffffffff1660e01b81526004016129699291906001600160a01b03929092168252602082015260400190565b602060405180830381865afa158015612986573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129aa9190615299565b1115612af057612a1f8d6001600160a01b0316636fd5ae156040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129f1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a159190615299565b6010908116141590565b15612a2c57809550612b13565b6040517f2b83cccd0000000000000000000000000000000000000000000000000000000081526001600160a01b038e81166004830152602482018e9052604482018390527f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e01690632b83cccd906064016020604051808303816000875af1158015612abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612adf9190615299565b612ae990886152e1565b9650612b13565b600081118015612afd5750875b15612b0f57612adf848683858d61245a565b8095505b8515612b2d57612b2d6001600160a01b0385163388612eca565b5050505050965096945050505050565b6001600160a01b038216600090815260046020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790558015612c9657600160009054906101000a90046001600160a01b03166001600160a01b0316631ec64fef836001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015612be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c0a9190615197565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b03918216600482015290851660248201526044016020604051808303816000875af1158015612c70573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c949190615197565b505b6040516001600160a01b038316907ff9f4ea4fb47406a3baf9adc8bd38b1c82e5a5fee5de9b3c5af3218400fb530c090600090a25050565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526024820185905260009182917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0169063d10eb4b990604401602060405180830381865afa158015612d59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d7d9190615197565b9050612d946001600160a01b038216333087612297565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038881166004830152602482018890526000921690638f38a55590604401602060405180830381865afa158015612dff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e239190615197565b9050611dff82886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e8b9190615197565b87846001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d6000803e3d6000fd5b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080612f83576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c45440000000000000000000000000000000000604482015260640161063f565b50505050565b6040517fd10eb4b90000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301526024820185905260009182917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0169063d10eb4b990604401602060405180830381865afa158015613014573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130389190615197565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b0389811660048301526024820189905292935060009290911690638f38a55590604401602060405180830381865afa1580156130a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130cc9190615197565b9050613173876001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561310f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131339190615197565b8387846001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa15801561118a573d6000803e3d6000fd5b92506131896001600160a01b0383163385612eca565b5050949350505050565b604080516001600160a01b03871660208201529081018590526060810184905260808101829052600060a08201819052908190819060c00160405160208183030381529060405290506000886001600160a01b0316635cffe9de308b6001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561322c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132509190615197565b89866040518563ffffffff1660e01b815260040161327194939291906154ad565b6020604051808303816000875af1158015613290573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132b491906151f7565b9050806132ed576040517f87cce7b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b886001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa15801561332b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061334f9190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190615299565b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b038b81166004830152602482018b90529195507f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e09091169063574e779590604401602060405180830381865afa15801561345d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134819190615197565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156134e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135049190615299565b604080516001600160a01b038c168152602081018b9052908101899052606081018690526080810182905290935033907f25841a32c1c1cef7b2d2bcea90bd94fcafbcd2459595475b86087699c16dc4959060a00160405180910390a250509550959350505050565b6040517f574e77950000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301526024820184905260009182917f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0169063574e779590604401602060405180830381865afa1580156135f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061361c9190615197565b905064e8d4a51000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613662573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061368691906154df565b6136919060126154fc565b61369c90600a61563f565b6136a6908561564e565b116136dd576040517f81406f4600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038781166004830152602482018790526000921690638f38a55590604401602060405180830381865afa158015613748573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061376c9190615197565b90506001600160a01b0387163014613793576137936001600160a01b038316333087612297565b6000816001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa1580156137d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137f79190615299565b9050600080836001600160a01b0316635863056d6040518163ffffffff1660e01b81526004016040805180830381865afa158015613839573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061385d919061568b565b915091506000807f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b031663f94d4668866040518263ffffffff1660e01b81526004016138b291815260200190565b600060405180830381865afa1580156138cf573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052613915919081019061570a565b50915091506000866001600160a01b0316639d2c110c60405180610120016040528060018081111561394957613949615386565b8152602001868881518110613960576139606157d8565b60200260200101516001600160a01b03168152602001868981518110613988576139886157d8565b60200260200101516001600160a01b031681526020018d81526020018981526020016000815260200160006001600160a01b0316815260200160006001600160a01b03168152602001604051806020016040528060008152508152508487815181106139f6576139f66157d8565b6020026020010151858981518110613a1057613a106157d8565b60200260200101516040518463ffffffff1660e01b8152600401613a3693929190615807565b6020604051808303816000875af1158015613a55573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a799190615299565b9050613a878c8c8c846144f1565b9d9c50505050505050505050505050565b6000826001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ad8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613afc9190615197565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b037f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60248301529192509082169063095ea7b3906044016020604051808303816000875af1158015613ba7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613bcb91906151f7565b506040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602483015282169063095ea7b3906044016020604051808303816000875af1158015613c53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c7791906151f7565b50826001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613cb6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cda9190615197565b6040517f095ea7b30000000000000000000000000000000000000000000000000000000081526001600160a01b0385811660048301527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6024830152919091169063095ea7b3906044016020604051808303816000875af1158015613d63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d8791906151f7565b508115613e23576040517f60d54d410000000000000000000000000000000000000000000000000000000081526001600160a01b0384811660048301527f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e016906360d54d4190602401600060405180830381600087803b158015613e0a57600080fd5b505af1158015613e1e573d6000803e3d6000fd5b505050505b6040516001600160a01b038416907fae4a2338a83fc8bfaca3a6cbb54494b5c00e9d8a65dc9cf39135b00da497798290600090a2505050565b6002546040517f8f38a5550000000000000000000000000000000000000000000000000000000081526001600160a01b038681166004830152602482018690526000928392839290911690638f38a55590604401602060405180830381865afa158015613ecd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef19190615197565b90506000807f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b031663f94d4668846001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f879190615299565b6040518263ffffffff1660e01b8152600401613fa591815260200190565b600060405180830381865afa158015613fc2573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052614008919081019061570a565b5091509150600080846001600160a01b0316635863056d6040518163ffffffff1660e01b81526004016040805180830381865afa15801561404d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614071919061568b565b915091506000838381518110614089576140896157d8565b60200260200101516000141590506000816140a55760006140e3565b6140e38d8686815181106140bb576140bb6157d8565b60200260200101518786815181106140d5576140d56157d8565b60200260200101518e6147be565b9050600081116140f45760006141a7565b6040517fdfe5ef480000000000000000000000000000000000000000000000000000000081526001600160a01b038e81166004830152602482018e9052604482018390527f00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0169063dfe5ef48906064016020604051808303816000875af1158015614183573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141a79190615299565b604080516002808252606082018352929b5060009290916020830190803683370190505090506141d7828d6158ce565b8185815181106141e9576141e96157d8565b60200260200101818152505089818681518110614208576142086157d8565b6020026020010181815250506142388860405180606001604052808a81526020018481526020018e8152506148d6565b9850505050505050505094509492505050565b60008060007f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b031663f94d4668896040518263ffffffff1660e01b815260040161429e91815260200190565b600060405180830381865afa1580156142bb573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052614301919081019061570a565b50509050600061430e8290565b9050600060405180608001604052808381526020018881526020018760405160200161433c91815260200190565b60405160208183030381529060405281526020016000151581525090507f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b0316638bdb39138b3030856040518563ffffffff1660e01b81526004016143ab94939291906159af565b600060405180830381600087803b1580156143c557600080fd5b505af11580156143d9573d6000803e3d6000fd5b50506040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038b1692506370a082319150602401602060405180830381865afa15801561443a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061445e9190615299565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529095506001600160a01b038a16906370a0823190602401602060405180830381865afa1580156144be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144e29190615299565b93505050509550959350505050565b600080856001600160a01b031663d4b839926040518163ffffffff1660e01b8152600401602060405180830381865afa158015614532573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145569190615197565b90506000816001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614598573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145bc91906154df565b60ff1690506000600982106145f5576145d68260126158ce565b6145e190600a6159e1565b6145f0906402540be4006159ed565b6145f8565b60015b9050600088888861460985826158ce565b604080516001600160a01b03909516602086015284019290925260608301526080820152600160a082015260c001604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f5cffe9de00000000000000000000000000000000000000000000000000000000825291506000906001600160a01b038b1690635cffe9de906146b390309089908c9088906004016154ad565b6020604051808303816000875af11580156146d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146f691906151f7565b90508061472f576040517f87cce7b800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b038616906370a0823190602401602060405180830381865afa15801561478c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147b09190615299565b9a9950505050505050505050565b60006114a36148cf856148be866148b88a6001600160a01b031663b8c15a9f6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561480c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148309190615a28565b614854906fffffffffffffffffffffffffffffffff16670de0b6b3a76400006158ce565b8b6001600160a01b031663f51e181a6040518163ffffffff1660e01b81526004016020604051808303816000875af1158015614894573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148b89190615299565b90614bab565b6148c891906152e1565b8690614bc9565b8390614bab565b600080836001600160a01b03166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015614917573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061493b9190615299565b835190915060005b84515160ff82161015614a46578451805160ff8316908110614967576149676157d8565b60200260200101516001600160a01b031663095ea7b37f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c887602001518460ff16815181106149b7576149b76157d8565b60200260200101516040518363ffffffff1660e01b81526004016149f09291906001600160a01b03929092168252602082015260400190565b6020604051808303816000875af1158015614a0f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a3391906151f7565b5080614a3e81615a5a565b915050614943565b50600060405180608001604052808381526020018660200151815260200186602001518760400151604051602001614a7f929190615a7a565b60405160208183030381529060405281526020016000151581525090507f000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c86001600160a01b031663b95cac28843033856040518563ffffffff1660e01b8152600401614aee94939291906159af565b600060405180830381600087803b158015614b0857600080fd5b505af1158015614b1c573d6000803e3d6000fd5b50506040517f70a082310000000000000000000000000000000000000000000000000000000081523360048201526001600160a01b03891692506370a082319150602401602060405180830381865afa158015614b7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ba19190615299565b9695505050505050565b6000614bc08383670de0b6b3a7640000614bda565b90505b92915050565b6000614bc083670de0b6b3a7640000845b828202811515841585830485141716614bf257600080fd5b0492915050565b6001600160a01b0381168114614c0e57600080fd5b50565b600060208284031215614c2357600080fd5b813561202181614bf9565b60ff81168114614c0e57600080fd5b600080600080600060a08688031215614c5557600080fd5b8535614c6081614bf9565b945060208601359350604086013592506060860135614c7e81614c2e565b949793965091946080013592915050565b8015158114614c0e57600080fd5b60008060408385031215614cb057600080fd5b8235614cbb81614bf9565b91506020830135614ccb81614c8f565b809150509250929050565b600080600060608486031215614ceb57600080fd5b8335614cf681614bf9565b9250602084013591506040840135614d0d81614c8f565b809150509250925092565b60008060008060008060a08789031215614d3157600080fd5b8635614d3c81614bf9565b95506020870135614d4c81614bf9565b94506040870135935060608701359250608087013567ffffffffffffffff80821115614d7757600080fd5b818901915089601f830112614d8b57600080fd5b813581811115614d9a57600080fd5b8a6020828501011115614dac57600080fd5b6020830194508093505050509295509295509295565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715614e3857614e38614dc2565b604052919050565b600067ffffffffffffffff821115614e5a57614e5a614dc2565b5060051b60200190565b600082601f830112614e7557600080fd5b81356020614e8a614e8583614e40565b614df1565b82815260059290921b84018101918181019086841115614ea957600080fd5b8286015b84811015614ec45780358352918301918301614ead565b509695505050505050565b6000806000806000806000806000806101408b8d031215614eef57600080fd5b8a35614efa81614bf9565b995060208b0135614f0a81614bf9565b985060408b0135975060608b0135965060808b0135955060a08b013567ffffffffffffffff811115614f3b57600080fd5b614f478d828e01614e64565b95505060c08b0135935060e08b0135614f5f81614c2e565b92506101008b0135614f7081614c8f565b809250506101208b013590509295989b9194979a5092959850565b60008060008060808587031215614fa157600080fd5b8435614fac81614bf9565b966020860135965060408601359560600135945092505050565b60008060008060008060c08789031215614fdf57600080fd5b8635614fea81614bf9565b95506020870135945060408701359350606087013567ffffffffffffffff81111561501457600080fd5b61502089828a01614e64565b9350506080870135915060a087013561503881614c8f565b809150509295509295509295565b600080600080600060a0868803121561505e57600080fd5b853561506981614bf9565b97602087013597506040870135966060810135965060800135945092505050565b60008060006060848603121561509f57600080fd5b83356150aa81614bf9565b95602085013595506040909401359392505050565b6000806000606084860312156150d457600080fd5b83356150df81614bf9565b92506020848101356150f081614bf9565b9250604085013567ffffffffffffffff8082111561510d57600080fd5b818701915087601f83011261512157600080fd5b81358181111561513357615133614dc2565b615163847fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601614df1565b9150808252888482850101111561517957600080fd5b80848401858401376000848284010152508093505050509250925092565b6000602082840312156151a957600080fd5b815161202181614bf9565b6000806000606084860312156151c957600080fd5b83516151d481614bf9565b60208501519093506151e581614bf9565b80925050604084015190509250925092565b60006020828403121561520957600080fd5b815161202181614c8f565b6000806040838503121561522757600080fd5b825161523281614bf9565b6020840151909250614ccb81614bf9565b600080600080600060a0868803121561525b57600080fd5b853561526681614bf9565b9450602086013593506040860135925060608601359150608086013561528b81614c8f565b809150509295509295909350565b6000602082840312156152ab57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600082198211156152f4576152f46152b2565b500190565b6000815180845260005b8181101561531f57602081850181015186830182015201615303565b81811115615331576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6001600160a01b038316815260406020820152600061144960408301846152f9565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600281106153ec577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b9052565b60e08152845160e0820152600060208601516154106101008401826153b5565b5060408601516001600160a01b03908116610120840152606087015116610140830152608086015161016083015260a086015160c06101808401526154596101a08401826152f9565b91505061549b60208301866001600160a01b03808251168352602082015115156020840152806040830151166040840152506060810151151560608301525050565b60a082019390935260c0015292915050565b60006001600160a01b03808716835280861660208401525083604083015260806060830152614ba160808301846152f9565b6000602082840312156154f157600080fd5b815161202181614c2e565b600060ff821660ff841680821015615516576155166152b2565b90039392505050565b600181815b8085111561557857817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0482111561555e5761555e6152b2565b8085161561556b57918102915b93841c9390800290615524565b509250929050565b60008261558f57506001614bc3565b8161559c57506000614bc3565b81600181146155b257600281146155bc576155d8565b6001915050614bc3565b60ff8411156155cd576155cd6152b2565b50506001821b614bc3565b5060208310610133831016604e8410600b84101617156155fb575081810a614bc3565b615605838361551f565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115615637576156376152b2565b029392505050565b6000614bc060ff841683615580565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615615686576156866152b2565b500290565b6000806040838503121561569e57600080fd5b505080516020909101519092909150565b600082601f8301126156c057600080fd5b815160206156d0614e8583614e40565b82815260059290921b840181019181810190868411156156ef57600080fd5b8286015b84811015614ec457805183529183019183016156f3565b60008060006060848603121561571f57600080fd5b835167ffffffffffffffff8082111561573757600080fd5b818601915086601f83011261574b57600080fd5b8151602061575b614e8583614e40565b82815260059290921b8401810191818101908a84111561577a57600080fd5b948201945b838610156157a157855161579281614bf9565b8252948201949082019061577f565b918901519197509093505050808211156157ba57600080fd5b506157c7868287016156af565b925050604084015190509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b606081526158196060820185516153b5565b6000602085015161583560808401826001600160a01b03169052565b5060408501516001600160a01b03811660a084015250606085015160c0830152608085015160e083015260a0850151610100818185015260c0870151915061012061588a818601846001600160a01b03169052565b60e08801516001600160a01b03166101408601529087015161016085019190915290506158bb6101808401826152f9565b6020840195909552505060400152919050565b6000828210156158e0576158e06152b2565b500390565b600081518084526020808501945080840160005b83811015615915578151875295820195908201906001016158f9565b509495945050505050565b8051608080845281519084018190526000916020919082019060a0860190845b818110156159655783516001600160a01b031683529284019291840191600101615940565b50508285015191508581038387015261597e81836158e5565b925050506040830151848203604086015261599982826152f9565b91505060608301516117b1606086018215159052565b84815260006001600160a01b03808616602084015280851660408401525060806060830152614ba16080830184615920565b6000614bc08383615580565b600082615a23577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b600060208284031215615a3a57600080fd5b81516fffffffffffffffffffffffffffffffff8116811461202157600080fd5b600060ff821660ff811415615a7157615a716152b2565b60010192915050565b604081526000615a8d60408301856158e5565b9050826020830152939250505056fea264697066735822122056dca0d2b10eb7769e8cf4038d14d7e56dc9c76b27843e968f78a7f5c963066264736f6c634300080b0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0000000000000000000000000f01eb98de53ed964ac3f786b80ed8ce33f05f417000000000000000000000000984682770f1eed90c00cd57b06b151ec12e7c51c000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
-----Decoded View---------------
Arg [0] : _divider (address): 0x86bA3E96Be68563E41c2f5769F1AF9fAf758e6E0
Arg [1] : _poolManager (address): 0xf01eb98de53ed964AC3F786b80ED8ce33f05F417
Arg [2] : _spaceFactory (address): 0x984682770f1EED90C00cd57B06b151EC12e7c51C
Arg [3] : _balancerVault (address): 0xBA12222222228d8Ba445958a75a0704d566BF2C8
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 00000000000000000000000086ba3e96be68563e41c2f5769f1af9faf758e6e0
Arg [1] : 000000000000000000000000f01eb98de53ed964ac3f786b80ed8ce33f05f417
Arg [2] : 000000000000000000000000984682770f1eed90c00cd57b06b151ec12e7c51c
Arg [3] : 000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c8
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.