Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 5,213 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Swap | 21590126 | 17 hrs ago | IN | 0 ETH | 0.0011102 | ||||
Swap | 21589791 | 19 hrs ago | IN | 0 ETH | 0.00099225 | ||||
Swap | 21582390 | 43 hrs ago | IN | 0 ETH | 0.00181319 | ||||
Swap | 21581294 | 47 hrs ago | IN | 0 ETH | 0.01045207 | ||||
Swap | 21577883 | 2 days ago | IN | 0.03450419 ETH | 0.00090774 | ||||
Swap | 21577622 | 2 days ago | IN | 0 ETH | 0.00064669 | ||||
Swap | 21576003 | 2 days ago | IN | 0.15332033 ETH | 0.00319229 | ||||
Swap | 21566043 | 4 days ago | IN | 0 ETH | 0.00232435 | ||||
Swap | 21564617 | 4 days ago | IN | 0 ETH | 0.00199572 | ||||
Swap | 21560079 | 4 days ago | IN | 0 ETH | 0.00134021 | ||||
Swap | 21553061 | 5 days ago | IN | 0 ETH | 0.00143179 | ||||
Swap | 21548818 | 6 days ago | IN | 0 ETH | 0.00104108 | ||||
Swap | 21541812 | 7 days ago | IN | 0.02110195 ETH | 0.00084926 | ||||
Swap | 21541565 | 7 days ago | IN | 0 ETH | 0.00113836 | ||||
Swap | 21541559 | 7 days ago | IN | 0 ETH | 0.00117213 | ||||
Swap | 21541083 | 7 days ago | IN | 0 ETH | 0.00100304 | ||||
Swap | 21539993 | 7 days ago | IN | 0 ETH | 0.00157156 | ||||
Swap | 21535656 | 8 days ago | IN | 0 ETH | 0.0019577 | ||||
Swap | 21535321 | 8 days ago | IN | 0 ETH | 0.00249492 | ||||
Swap | 21530548 | 9 days ago | IN | 0 ETH | 0.00616888 | ||||
Swap | 21523933 | 9 days ago | IN | 0 ETH | 0.00197752 | ||||
Swap | 21521651 | 10 days ago | IN | 0 ETH | 0.00345761 | ||||
Swap | 21518968 | 10 days ago | IN | 0 ETH | 0.00245564 | ||||
Swap | 21517740 | 10 days ago | IN | 0 ETH | 0.00124702 | ||||
Swap | 21517736 | 10 days ago | IN | 0 ETH | 0.00121635 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|
21581294 | 47 hrs ago | 0.00282844 ETH | ||||
21581294 | 47 hrs ago | 0.01707155 ETH | ||||
21581294 | 47 hrs ago | 0.0199 ETH | ||||
21577883 | 2 days ago | 0.03450419 ETH | ||||
21576003 | 2 days ago | 0.02775338 ETH | ||||
21576003 | 2 days ago | 0.05693247 ETH | ||||
21576003 | 2 days ago | 0.06863447 ETH | ||||
21541812 | 7 days ago | 0.02110195 ETH | ||||
21512990 | 11 days ago | 0.01085949 ETH | ||||
21498382 | 13 days ago | 0.0002203 ETH | ||||
21498375 | 13 days ago | 0.0002061 ETH | ||||
21498369 | 13 days ago | 0.0002061 ETH | ||||
21421733 | 24 days ago | 0.055771 ETH | ||||
21342424 | 35 days ago | 0.06217348 ETH | ||||
21318100 | 38 days ago | 0.04849899 ETH | ||||
21318100 | 38 days ago | 0.04831565 ETH | ||||
21316833 | 38 days ago | 0.08417181 ETH | ||||
21316833 | 38 days ago | 0.07854718 ETH | ||||
21312469 | 39 days ago | 0.09295121 ETH | ||||
21311887 | 39 days ago | 0.08587255 ETH | ||||
21301307 | 41 days ago | 0.04133498 ETH | ||||
21300793 | 41 days ago | 0.029376 ETH | ||||
21187670 | 56 days ago | 0.0522952 ETH | ||||
21182181 | 57 days ago | 0.16128115 ETH | ||||
21160568 | 60 days ago | 0.03190823 ETH |
Loading...
Loading
Contract Name:
VeryFastRouter
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {ERC20} from "solmate/tokens/ERC20.sol"; import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import {LSSVMPair} from "./LSSVMPair.sol"; import {LSSVMPairERC20} from "./LSSVMPairERC20.sol"; import {ILSSVMPairERC721} from "./erc721/ILSSVMPairERC721.sol"; import {LSSVMPairERC1155} from "./erc1155/LSSVMPairERC1155.sol"; import {ILSSVMPairFactoryLike} from "./ILSSVMPairFactoryLike.sol"; import {CurveErrorCodes} from "./bonding-curves/CurveErrorCodes.sol"; import {ICurve} from "./bonding-curves/ICurve.sol"; /** * @dev Full-featured router to handle all swap types, with partial fill support */ contract VeryFastRouter { using SafeTransferLib for address payable; using SafeTransferLib for ERC20; uint256 private constant BASE = 1e18; // Bit shift amounts for _findMaxFillableAmtForBuy and _findMaxFillableAmtForSell uint256 private constant FEE_MULTIPLIER_SHIFT_AMOUNT = 160; uint256 private constant DELTA_SHIFT_AMOUNT = 128; ILSSVMPairFactoryLike public immutable factory; struct BuyOrderWithPartialFill { LSSVMPair pair; bool isERC721; uint256[] nftIds; uint256 maxInputAmount; uint256 ethAmount; uint256 expectedSpotPrice; uint256[] maxCostPerNumNFTs; // @dev This is zero-indexed, so maxCostPerNumNFTs[x] = max price we're willing to pay to buy x+1 NFTs } struct SellOrderWithPartialFill { LSSVMPair pair; bool isETHSell; bool isERC721; uint256[] nftIds; bool doPropertyCheck; bytes propertyCheckParams; uint128 expectedSpotPrice; uint256 minExpectedOutput; uint256[] minExpectedOutputPerNumNFTs; } struct Order { BuyOrderWithPartialFill[] buyOrders; SellOrderWithPartialFill[] sellOrders; address payable tokenRecipient; address nftRecipient; bool recycleETH; } struct PartialFillSellArgs { LSSVMPair pair; uint128 spotPrice; uint256 maxNumNFTs; uint256[] minOutputPerNumNFTs; uint256 protocolFeeMultiplier; uint256 nftId; } struct PartialFillSellHelperArgs { LSSVMPair pair; uint256[] minOutputPerNumNFTs; uint256 protocolFeeMultiplier; uint256 nftId; uint256 start; uint256 end; uint128 delta; uint128 spotPrice; uint256 feeMultiplier; uint256 pairTokenBalance; uint256 royaltyAmount; uint256 numItemsToFill; uint256 priceToFillAt; } error VeryFastRouter__InvalidPair(); error VeryFastRouter__BondingCurveQuoteError(); constructor(ILSSVMPairFactoryLike _factory) { factory = _factory; } /** * @dev Meant to be used as a client-side utility * @notice Given a pair and a number of items to buy, calculate the max price paid for 1 up to numNFTs to buy */ function getNFTQuoteForBuyOrderWithPartialFill( LSSVMPair pair, uint256 numNFTs, uint256 slippageScaling, uint256 assetId ) external view returns (uint256[] memory) { uint256[] memory prices = new uint256[](numNFTs); for (uint256 i; i < numNFTs;) { uint128 newSpotPrice = pair.spotPrice(); uint128 newDelta = pair.delta(); // Assume that i items have been bought and get the new params if (i != 0) { (newSpotPrice, newDelta) = _getNewPoolParamsAfterBuying(pair, i); } // Calculate price to purchase the remaining numNFTs - i items uint256 price = _getHypotheticalNewPoolParamsAfterBuying(pair, newSpotPrice, newDelta, numNFTs - i); (,, uint256 royaltyTotal) = pair.calculateRoyaltiesView(assetId, price); price += royaltyTotal; // Set the price to buy numNFTs - i items prices[numNFTs - i - 1] = price; unchecked { ++i; } } // Scale up by slippage amount if (slippageScaling != 0) { for (uint256 i; i < prices.length;) { prices[i] += (prices[i] * slippageScaling / 1e18); unchecked { ++i; } } } return prices; } function _getNewPoolParamsAfterBuying(LSSVMPair pair, uint256 i) internal view returns (uint128 newSpotPrice, uint128 newDelta) { CurveErrorCodes.Error errorCode; (errorCode, newSpotPrice, newDelta,,,) = pair.bondingCurve().getBuyInfo( pair.spotPrice(), pair.delta(), i, pair.fee(), pair.factory().protocolFeeMultiplier() ); if (errorCode != CurveErrorCodes.Error.OK) { revert VeryFastRouter__BondingCurveQuoteError(); } } function _getHypotheticalNewPoolParamsAfterBuying( LSSVMPair pair, uint128 newSpotPrice, uint128 newDelta, uint256 num ) internal view returns (uint256 output) { CurveErrorCodes.Error errorCode; (errorCode,,, output,,) = pair.bondingCurve().getBuyInfo( newSpotPrice, newDelta, num, pair.fee(), pair.factory().protocolFeeMultiplier() ); if (errorCode != CurveErrorCodes.Error.OK) { revert VeryFastRouter__BondingCurveQuoteError(); } } function getPairBaseQuoteTokenBalance(LSSVMPair pair) public view returns (uint256 balance) { ILSSVMPairFactoryLike.PairVariant variant = pair.pairVariant(); if ( variant == ILSSVMPairFactoryLike.PairVariant.ERC721_ETH || variant == ILSSVMPairFactoryLike.PairVariant.ERC1155_ETH ) { balance = address(pair).balance; } else { balance = ERC20(LSSVMPairERC20(address(pair)).token()).balanceOf(address(pair)); } } function _wrapUintAsArray(uint256 valueToWrap) internal pure returns (uint256[] memory) { uint256[] memory arr = new uint256[](1); arr[0] = valueToWrap; return arr; } /** * @dev Meant to be used as a client-side utility * @notice Given a pair and a number of items to sell, calculate the mininum output for selling 1 to numNFTs */ function getNFTQuoteForSellOrderWithPartialFill( LSSVMPair pair, uint256 numNFTs, uint256 slippageScaling, uint256 nftId ) external view returns (uint256[] memory) { uint256[] memory outputAmounts = new uint256[](numNFTs); for (uint256 i; i < numNFTs;) { uint128 newSpotPrice = pair.spotPrice(); uint128 newDelta = pair.delta(); // Assume that i items have been sold and get the new params if (i != 0) { (newSpotPrice, newDelta) = _getNewPoolParamsAfterSelling(pair, i); } // Calculate output to sell the remaining numNFTs - i items, factoring in royalties and fees uint256 output = _getHypotheticalNewPoolParamsAfterSelling(pair, newSpotPrice, newDelta, numNFTs - i); (,, uint256 royaltyTotal) = pair.calculateRoyaltiesView(nftId, output); output -= royaltyTotal; outputAmounts[numNFTs - i - 1] = output; unchecked { ++i; } } // Scale down by slippage amount if (slippageScaling != 0) { for (uint256 i; i < outputAmounts.length;) { outputAmounts[i] -= (outputAmounts[i] * slippageScaling / 1e18); unchecked { ++i; } } } return outputAmounts; } function _getNewPoolParamsAfterSelling(LSSVMPair pair, uint256 i) internal view returns (uint128 newSpotPrice, uint128 newDelta) { CurveErrorCodes.Error errorCode; (errorCode, newSpotPrice, newDelta,,,) = pair.bondingCurve().getSellInfo( pair.spotPrice(), pair.delta(), i, pair.fee(), pair.factory().protocolFeeMultiplier() ); if (errorCode != CurveErrorCodes.Error.OK) { revert VeryFastRouter__BondingCurveQuoteError(); } } function _getHypotheticalNewPoolParamsAfterSelling( LSSVMPair pair, uint128 newSpotPrice, uint128 newDelta, uint256 num ) internal view returns (uint256 output) { CurveErrorCodes.Error errorCode; (errorCode,,, output,,) = pair.bondingCurve().getSellInfo( newSpotPrice, newDelta, num, pair.fee(), pair.factory().protocolFeeMultiplier() ); if (errorCode != CurveErrorCodes.Error.OK) { revert VeryFastRouter__BondingCurveQuoteError(); } } /** * @dev Performs a batch of sells and buys, avoids performing swaps where the price is beyond * Handles selling NFTs for tokens or ETH * Handles buying NFTs with tokens or ETH, * @param swapOrder The struct containing all the swaps to be executed * @return results Indices [0..swapOrder.sellOrders.length-1] contain the actual output amounts of the * sell orders, indices [swapOrder.sellOrders.length..swapOrder.sellOrders.length+swapOrder.buyOrders.length-1] * contain the actual input amounts of the buy orders. */ function swap(Order calldata swapOrder) external payable returns (uint256[] memory results) { uint256 ethAmount = msg.value; // Get protocol to reduce gas on the _findMaxFillableAmtForSell/_findMaxFillableAmtForBuy calls uint256 protocolFeeMultiplier = factory.protocolFeeMultiplier(); results = new uint256[](swapOrder.buyOrders.length + swapOrder.sellOrders.length); // Go through each sell order for (uint256 i; i < swapOrder.sellOrders.length;) { SellOrderWithPartialFill calldata order = swapOrder.sellOrders[i]; uint128 pairSpotPrice = order.pair.spotPrice(); uint256 outputAmount; // If the spot price parameter seen is what we expect it to be... if (pairSpotPrice == order.expectedSpotPrice) { // If the pair is an ETH pair and we opt into recycling ETH, add the output to our total accrued if (order.isETHSell && swapOrder.recycleETH) { // Pass in params for property checking if needed // Then do the swap with the same minExpectedTokenOutput amount if (order.doPropertyCheck) { outputAmount = ILSSVMPairERC721(address(order.pair)).swapNFTsForToken( order.nftIds, order.minExpectedOutput, payable(address(this)), true, msg.sender, order.propertyCheckParams ); } else { outputAmount = order.pair.swapNFTsForToken( order.nftIds, order.minExpectedOutput, payable(address(this)), true, msg.sender ); } // Accumulate ETH amount ethAmount += outputAmount; } // Otherwise, all tokens or ETH received from the sale go to the token recipient else { // Pass in params for property checking if needed // Then do the swap with the same minExpectedTokenOutput amount if (order.doPropertyCheck) { outputAmount = ILSSVMPairERC721(address(order.pair)).swapNFTsForToken( order.nftIds, order.minExpectedOutput, swapOrder.tokenRecipient, true, msg.sender, order.propertyCheckParams ); } else { outputAmount = order.pair.swapNFTsForToken( order.nftIds, order.minExpectedOutput, swapOrder.tokenRecipient, true, msg.sender ); } } } // Otherwise we need to do some partial fill calculations first else { uint256 numItemsToFill; uint256 priceToFillAt; { // Grab royalty for calc in _findMaxFillableAmtForSell (,, uint256 royaltyAmount) = order.pair.calculateRoyaltiesView( order.isERC721 ? order.nftIds[0] : LSSVMPairERC1155(address(order.pair)).nftId(), BASE ); // Calculate the max number of items we can sell (numItemsToFill, priceToFillAt) = _findMaxFillableAmtForSell( order.pair, pairSpotPrice, order.minExpectedOutputPerNumNFTs, protocolFeeMultiplier, royaltyAmount ); } // If we can sell at least 1 item... if (numItemsToFill != 0) { // If property checking is needed, do the property check swap if (order.doPropertyCheck) { outputAmount = ILSSVMPairERC721(address(order.pair)).swapNFTsForToken( order.nftIds[:numItemsToFill], priceToFillAt, swapOrder.tokenRecipient, true, msg.sender, order.propertyCheckParams ); } // Otherwise do a normal sell swap else { // Get subarray if ERC721 if (order.isERC721) { outputAmount = order.pair.swapNFTsForToken( order.nftIds[:numItemsToFill], priceToFillAt, swapOrder.tokenRecipient, true, msg.sender ); } // For 1155 swaps, wrap as number else { outputAmount = order.pair.swapNFTsForToken( _wrapUintAsArray(numItemsToFill), priceToFillAt, swapOrder.tokenRecipient, true, msg.sender ); } } } } results[i] = outputAmount; unchecked { ++i; } } // Go through each buy order for (uint256 i; i < swapOrder.buyOrders.length;) { BuyOrderWithPartialFill calldata order = swapOrder.buyOrders[i]; // @dev We use inputAmount to store the spot price temporarily before it's overwritten // (yes, it's gross) uint256 inputAmount = order.pair.spotPrice(); // If the spot price parameter seen is what we expect it to be... if (inputAmount == order.expectedSpotPrice) { // Then do a direct swap for all items we want inputAmount = order.pair.swapTokenForSpecificNFTs{value: order.ethAmount}( order.nftIds, order.maxInputAmount, swapOrder.nftRecipient, true, msg.sender ); // Deduct ETH amount if it's an ETH swap if (order.ethAmount != 0) { ethAmount -= inputAmount; } } // Otherwise, we need to do some partial fill calculations first else { uint256 numItemsToFill; uint256 priceToFillAt; { (,, uint256 royaltyAmount) = order.pair.calculateRoyaltiesView( order.isERC721 ? order.nftIds[0] : LSSVMPairERC1155(address(order.pair)).nftId(), BASE ); // uint128(inputAmount) is safe because order.pair.spotPrice() returns uint128 (numItemsToFill, priceToFillAt) = _findMaxFillableAmtForBuy( order.pair, uint128(inputAmount), order.maxCostPerNumNFTs, protocolFeeMultiplier, royaltyAmount ); } // Set inputAmount to be 0 (assuming we don't fully meet all criteria for a swap) inputAmount = 0; // Continue if we can fill at least 1 item if (numItemsToFill != 0) { // Set ETH amount to send (is 0 if it's an ERC20 swap) uint256 ethToSendForBuy; if (order.ethAmount != 0) { ethToSendForBuy = priceToFillAt; } // If ERC721 swap if (order.isERC721) { // Get list of actually valid ids to buy uint256[] memory availableIds = _findAvailableIds(order.pair, numItemsToFill, order.nftIds); // Only swap if there are valid IDs to buy if (availableIds.length != 0) { inputAmount = order.pair.swapTokenForSpecificNFTs{value: ethToSendForBuy}( availableIds, priceToFillAt, swapOrder.nftRecipient, true, msg.sender ); } } // If ERC1155 swap else { // The amount to buy is the min(numItemsToFill, erc1155.balanceOf(pair)) { uint256 availableNFTs = IERC1155(order.pair.nft()).balanceOf( address(order.pair), LSSVMPairERC1155(address(order.pair)).nftId() ); numItemsToFill = numItemsToFill < availableNFTs ? numItemsToFill : availableNFTs; } // Only continue if we can fill for nonzero amount of items if (numItemsToFill != 0) { // Do the 1155 swap, with the modified amount to buy inputAmount = order.pair.swapTokenForSpecificNFTs{value: ethToSendForBuy}( _wrapUintAsArray(numItemsToFill), priceToFillAt, swapOrder.nftRecipient, true, msg.sender ); } } // Deduct ETH amount if it's an ETH swap if (order.ethAmount != 0) { ethAmount -= inputAmount; } } } // Store inputAmount in results results[i + swapOrder.sellOrders.length] = inputAmount; unchecked { ++i; } } // Send excess ETH back to token recipient if (ethAmount != 0) { payable(swapOrder.tokenRecipient).safeTransferETH(ethAmount); } } receive() external payable {} /** * Internal helper functions */ /** * @dev Performs a binary search to find the largest value where maxCostPerNumNFTs is still greater than * the pair's bonding curve's getBuyInfo() value. * @param pair The pair to calculate partial fill values for * @param maxCostPerNumNFTs The user's specified maximum price to pay for filling a number of NFTs * @param protocolFeeMultiplier The % set as protocol fee * @param royaltyAmount Royalty amount assuming a cost of BASE, used for cheaper royalty calc * @dev Note that maxPricesPerNumNFTs is 0-indexed */ function _findMaxFillableAmtForBuy( LSSVMPair pair, uint128 spotPrice, uint256[] memory maxCostPerNumNFTs, uint256 protocolFeeMultiplier, uint256 royaltyAmount ) internal view returns (uint256 numItemsToFill, uint256 priceToFillAt) { // Set start and end indices uint256 start = 1; uint256 end = maxCostPerNumNFTs.length; // Cache current pair values uint128 delta = pair.delta(); uint256 feeMultiplierAndBondingCurve = uint96(pair.fee()) << FEE_MULTIPLIER_SHIFT_AMOUNT | uint160(address(pair.bondingCurve())); // Perform binary search while (start <= end) { // uint256 numItems = (start + end)/2; (but we hard-code it below to avoid stack too deep) // We check the price to buy index + 1 ( CurveErrorCodes.Error error, /* newSpotPrice */ , /* newDelta */ , uint256 currentCost, /* tradeFee */ , /* protocolFee */ ) = (ICurve(address(uint160(feeMultiplierAndBondingCurve)))).getBuyInfo( spotPrice, delta, (start + end) / 2, (feeMultiplierAndBondingCurve >> FEE_MULTIPLIER_SHIFT_AMOUNT), protocolFeeMultiplier ); currentCost += currentCost * royaltyAmount / BASE; // If the bonding curve has a math error, or // If the current price is too expensive relative to our max cost, // then we recurse on the left half (i.e. less items) if ( error != CurveErrorCodes.Error.OK || currentCost > maxCostPerNumNFTs[(start + end) / 2 - 1] /* this is the max cost we are willing to pay, zero-indexed */ ) { end = (start + end) / 2 - 1; } // Otherwise, we recurse on the right half (i.e. more items) else { numItemsToFill = (start + end) / 2; start = (start + end) / 2 + 1; priceToFillAt = currentCost; } } } function _findMaxFillableAmtForSell( LSSVMPair pair, uint128 spotPrice, uint256[] memory minOutputPerNumNFTs, uint256 protocolFeeMultiplier, uint256 royaltyAmount ) internal view returns (uint256 numItemsToFill, uint256 priceToFillAt) { // Set start and end indices uint256 start = 1; uint256 end = minOutputPerNumNFTs.length; // Cache current pair values uint256 deltaAndPairTokenBalance; uint256 feeMultiplierAndBondingCurve; { uint128 delta = pair.delta(); uint128 pairTokenBalance = uint128(getPairBaseQuoteTokenBalance(pair)); deltaAndPairTokenBalance = uint256(delta) << DELTA_SHIFT_AMOUNT | pairTokenBalance; } { uint256 feeMultiplier = uint96(pair.fee()); address bondingCurve = address(pair.bondingCurve()); feeMultiplierAndBondingCurve = feeMultiplier << FEE_MULTIPLIER_SHIFT_AMOUNT | uint160(bondingCurve); } // Perform binary search while (start <= end) { // We check the price to sell index + 1 ( CurveErrorCodes.Error error, /* newSpotPrice */ , /* newDelta */ , uint256 currentOutput, /* tradeFee */ , /* protocolFee */ ) = (ICurve(address(uint160(feeMultiplierAndBondingCurve)))).getSellInfo( spotPrice, // get delta from deltaAndPairTokenBalance uint128(deltaAndPairTokenBalance >> DELTA_SHIFT_AMOUNT), (start + end) / 2, // get feeMultiplier from feeMultiplierAndBondingCurve uint96(feeMultiplierAndBondingCurve >> FEE_MULTIPLIER_SHIFT_AMOUNT), protocolFeeMultiplier ); currentOutput -= currentOutput * royaltyAmount / BASE; // If the bonding curve has a math error, or // if the current output is too low relative to our max output, or // if the current output is greater than the pair's token balance, // then we recurse on the left half (i.e. less items) if ( error != CurveErrorCodes.Error.OK || currentOutput < minOutputPerNumNFTs[(start + end) / 2 - 1] /* this is the minimum output we are expecting from the sale, zero-indexed */ || currentOutput > (uint256(uint128(deltaAndPairTokenBalance))) ) { end = (start + end) / 2 - 1; } // Otherwise, we recurse on the right half (i.e. more items) else { numItemsToFill = (start + end) / 2; start = (start + end) / 2 + 1; priceToFillAt = currentOutput; } } } /** * @dev Checks ownership of all desired NFT IDs to see which ones are still fillable * @param pair The pair to check for ownership * @param maxIdsNeeded The maximum amount of NFTs we want, guaranteed to be up to potentialIds.length, but could be less * @param potentialIds The possible NFT IDs that the pair could own * @return idsToBuy Actual NFT IDs owned by the pair, guaranteed to be up to maxIdsNeeded length, but could be less */ function _findAvailableIds(LSSVMPair pair, uint256 maxIdsNeeded, uint256[] memory potentialIds) internal view returns (uint256[] memory) { IERC721 nft = IERC721(pair.nft()); uint256[] memory idsThatExist = new uint256[](maxIdsNeeded); uint256 numIdsFound; // Go through each potential ID, and check to see if it's still owned by the pair // If it is, record the ID for (uint256 i; i < maxIdsNeeded;) { if (nft.ownerOf(potentialIds[i]) == address(pair)) { idsThatExist[numIdsFound] = potentialIds[i]; numIdsFound += 1; } unchecked { ++i; } } // If all ids were found, return the full id list if (numIdsFound == maxIdsNeeded) { return idsThatExist; } // Otherwise, we didn't find enough IDs, so we need to return a subset if (numIdsFound < maxIdsNeeded) { uint256[] memory allIdsFound = new uint256[](numIdsFound); for (uint256 i; i < numIdsFound;) { allIdsFound[i] = idsThatExist[i]; unchecked { ++i; } } return allIdsFound; } uint256[] memory emptyArr = new uint256[](0); return emptyArr; } /** * Restricted functions */ /** * @dev Allows an ERC20 pair contract to transfer ERC20 tokens directly from * the sender, in order to minimize the number of token transfers. Only callable by an ERC20 pair. * @param token The ERC20 token to transfer * @param from The address to transfer tokens from * @param to The address to transfer tokens to * @param amount The amount of tokens to transfer */ function pairTransferERC20From(ERC20 token, address from, address to, uint256 amount) external { // verify caller is a trusted ERC20 pair contract if ( !( factory.isValidPair(msg.sender) && factory.getPairTokenType(msg.sender) == ILSSVMPairFactoryLike.PairTokenType.ERC20 ) ) { revert VeryFastRouter__InvalidPair(); } // transfer tokens to pair token.safeTransferFrom(from, to, amount); } /** * @dev Allows a pair contract to transfer ERC721 NFTs directly from * the sender, in order to minimize the number of token transfers. Only callable by a pair. * @param nft The ERC721 NFT to transfer * @param from The address to transfer tokens from * @param to The address to transfer tokens to * @param id The ID of the NFT to transfer */ function pairTransferNFTFrom(IERC721 nft, address from, address to, uint256 id) external { // verify caller is a trusted pair contract if ( !( factory.isValidPair(msg.sender) && factory.getPairNFTType(msg.sender) == ILSSVMPairFactoryLike.PairNFTType.ERC721 ) ) { revert VeryFastRouter__InvalidPair(); } // transfer NFTs to pair nft.transferFrom(from, to, id); } /** * @dev Allows a pair contract to transfer ERC1155 NFTs directly from * the sender, in order to minimize the number of token transfers. Only callable by a pair. * @param nft The ERC1155 NFT to transfer * @param from The address to transfer tokens from * @param to The address to transfer tokens to * @param ids The IDs of the NFT to transfer * @param amounts The amount of each ID to transfer */ function pairTransferERC1155From( IERC1155 nft, address from, address to, uint256[] calldata ids, uint256[] calldata amounts ) external { // verify caller is a trusted pair contract if ( !( factory.isValidPair(msg.sender) && factory.getPairNFTType(msg.sender) == ILSSVMPairFactoryLike.PairNFTType.ERC1155 ) ) { revert VeryFastRouter__InvalidPair(); } // transfer NFTs to pair nft.safeBatchTransferFrom(from, to, ids, amounts, bytes("")); } }
// 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/transmissions11/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/transmissions11/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 { /*////////////////////////////////////////////////////////////// ETH OPERATIONS //////////////////////////////////////////////////////////////*/ function safeTransferETH(address to, uint256 amount) internal { bool success; /// @solidity memory-safe-assembly 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; /// @solidity memory-safe-assembly 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; /// @solidity memory-safe-assembly 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; /// @solidity memory-safe-assembly 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: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155 is IERC165 { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch( address[] calldata accounts, uint256[] calldata ids ) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {IRoyaltyEngineV1} from "manifoldxyz/IRoyaltyEngineV1.sol"; import {ERC20} from "solmate/tokens/ERC20.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol"; import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; import {LSSVMRouter} from "./LSSVMRouter.sol"; import {ICurve} from "./bonding-curves/ICurve.sol"; import {ILSSVMPairFactoryLike} from "./ILSSVMPairFactoryLike.sol"; import {CurveErrorCodes} from "./bonding-curves/CurveErrorCodes.sol"; import {IOwnershipTransferReceiver} from "./lib/IOwnershipTransferReceiver.sol"; import {OwnableWithTransferCallback} from "./lib/OwnableWithTransferCallback.sol"; /** * @title The base contract for an NFT/TOKEN AMM pair * @author boredGenius, 0xmons, 0xCygaar * @notice This implements the core swap logic from NFT to TOKEN */ abstract contract LSSVMPair is OwnableWithTransferCallback, ERC721Holder, ERC1155Holder { /** * Library usage ** */ using Address for address; /** * Enums ** */ enum PoolType { TOKEN, NFT, TRADE } /** * Constants ** */ /** * @dev 50%, must <= 1 - MAX_PROTOCOL_FEE (set in LSSVMPairFactory) */ uint256 internal constant MAX_TRADE_FEE = 0.5e18; /** * Immutable params ** */ /** * @notice Sudoswap Royalty Engine */ IRoyaltyEngineV1 public immutable ROYALTY_ENGINE; /** * Storage variables ** */ /** * @dev This is generally used to mean the immediate sell price for the next marginal NFT. * However, this should NOT be assumed, as bonding curves may use spotPrice in different ways. * Use getBuyNFTQuote and getSellNFTQuote for accurate pricing info. */ uint128 public spotPrice; /** * @notice The parameter for the pair's bonding curve. * Units and meaning are bonding curve dependent. */ uint128 public delta; /** * @notice The spread between buy and sell prices, set to be a multiplier we apply to the buy price * Fee is only relevant for TRADE pools. Units are in base 1e18. */ uint96 public fee; /** * @notice The address that swapped assets are sent to. * For TRADE pools, assets are always sent to the pool, so this is used to track trade fee. * If set to address(0), will default to owner() for NFT and TOKEN pools. */ address payable internal assetRecipient; /** * Events */ event SwapNFTInPair(uint256 amountOut, uint256[] ids); event SwapNFTInPair(uint256 amountOut, uint256 numNFTs); event SwapNFTOutPair(uint256 amountIn, uint256[] ids); event SwapNFTOutPair(uint256 amountIn, uint256 numNFTs); event SpotPriceUpdate(uint128 newSpotPrice); event TokenDeposit(uint256 amount); event TokenWithdrawal(uint256 amount); event NFTWithdrawal(uint256[] ids); event NFTWithdrawal(uint256 numNFTs); event DeltaUpdate(uint128 newDelta); event FeeUpdate(uint96 newFee); event AssetRecipientChange(address indexed a); /** * Errors */ error LSSVMPair__NotRouter(); error LSSVMPair__CallFailed(); error LSSVMPair__InvalidDelta(); error LSSVMPair__WrongPoolType(); error LSSVMPair__OutputTooSmall(); error LSSVMPair__ZeroSwapAmount(); error LSSVMPair__RoyaltyTooLarge(); error LSSVMPair__TradeFeeTooLarge(); error LSSVMPair__InvalidSpotPrice(); error LSSVMPair__TargetNotAllowed(); error LSSVMPair__NftNotTransferred(); error LSSVMPair__AlreadyInitialized(); error LSSVMPair__FunctionNotAllowed(); error LSSVMPair__DemandedInputTooLarge(); error LSSVMPair__NonTradePoolWithTradeFee(); error LSSVMPair__BondingCurveError(CurveErrorCodes.Error error); constructor(IRoyaltyEngineV1 royaltyEngine) { ROYALTY_ENGINE = royaltyEngine; } /** * @notice Called during pair creation to set initial parameters * @dev Only called once by factory to initialize. * We verify this by making sure that the current owner is address(0). * The Ownable library we use disallows setting the owner to be address(0), so this condition * should only be valid before the first initialize call. * @param _owner The owner of the pair * @param _assetRecipient The address that will receive the TOKEN or NFT sent to this pair during swaps. NOTE: If set to address(0), they will go to the pair itself. * @param _delta The initial delta of the bonding curve * @param _fee The initial % fee taken, if this is a trade pair * @param _spotPrice The initial price to sell an asset into the pair */ function initialize( address _owner, address payable _assetRecipient, uint128 _delta, uint96 _fee, uint128 _spotPrice ) external { if (owner() != address(0)) revert LSSVMPair__AlreadyInitialized(); __Ownable_init(_owner); ICurve _bondingCurve = bondingCurve(); PoolType _poolType = poolType(); if (_poolType != PoolType.TRADE) { if (_fee != 0) revert LSSVMPair__NonTradePoolWithTradeFee(); } else { if (_fee > MAX_TRADE_FEE) revert LSSVMPair__TradeFeeTooLarge(); fee = _fee; } assetRecipient = _assetRecipient; if (!_bondingCurve.validateDelta(_delta)) revert LSSVMPair__InvalidDelta(); if (!_bondingCurve.validateSpotPrice(_spotPrice)) revert LSSVMPair__InvalidSpotPrice(); delta = _delta; spotPrice = _spotPrice; } /** * External state-changing functions */ /** * @notice Sends token to the pair in exchange for a specific set of NFTs * @dev To compute the amount of token to send, call bondingCurve.getBuyInfo * This swap is meant for users who want specific IDs. Also higher chance of * reverting if some of the specified IDs leave the pool before the swap goes through. * @param nftIds The list of IDs of the NFTs to purchase * @param maxExpectedTokenInput The maximum acceptable cost from the sender. If the actual * amount is greater than this value, the transaction will be reverted. * @param nftRecipient The recipient of the NFTs * @param isRouter True if calling from LSSVMRouter, false otherwise. Not used for ETH pairs. * @param routerCaller If isRouter is true, ERC20 tokens will be transferred from this address. Not used for ETH pairs. * @return - The amount of token used for purchase */ function swapTokenForSpecificNFTs( uint256[] calldata nftIds, uint256 maxExpectedTokenInput, address nftRecipient, bool isRouter, address routerCaller ) external payable virtual returns (uint256); /** * @notice Sends a set of NFTs to the pair in exchange for token * @dev To compute the amount of token to that will be received, call bondingCurve.getSellInfo. * @param nftIds The list of IDs of the NFTs to sell to the pair * @param minExpectedTokenOutput The minimum acceptable token received by the sender. If the actual * amount is less than this value, the transaction will be reverted. * @param tokenRecipient The recipient of the token output * @param isRouter True if calling from LSSVMRouter, false otherwise. Not used for * ETH pairs. * @param routerCaller If isRouter is true, ERC20 tokens will be transferred from this address. Not used for * ETH pairs. * @return outputAmount The amount of token received */ function swapNFTsForToken( uint256[] calldata nftIds, uint256 minExpectedTokenOutput, address payable tokenRecipient, bool isRouter, address routerCaller ) external virtual returns (uint256 outputAmount); /** * View functions */ /** * @dev Used as read function to query the bonding curve for buy pricing info * @param numNFTs The number of NFTs to buy from the pair */ function getBuyNFTQuote(uint256 assetId, uint256 numNFTs) external view returns ( CurveErrorCodes.Error error, uint256 newSpotPrice, uint256 newDelta, uint256 inputAmount, uint256 protocolFee, uint256 royaltyAmount ) { uint256 tradeFee; (error, newSpotPrice, newDelta, inputAmount, tradeFee, protocolFee) = bondingCurve().getBuyInfo(spotPrice, delta, numNFTs, fee, factory().protocolFeeMultiplier()); if (numNFTs != 0) { // Calculate the inputAmount minus tradeFee and protocolFee uint256 inputAmountMinusFees = inputAmount - tradeFee - protocolFee; // Compute royalties (,, royaltyAmount) = calculateRoyaltiesView(assetId, inputAmountMinusFees); inputAmount += royaltyAmount; } } /** * @dev Used as read function to query the bonding curve for sell pricing info including royalties * @param numNFTs The number of NFTs to sell to the pair */ function getSellNFTQuote(uint256 assetId, uint256 numNFTs) external view returns ( CurveErrorCodes.Error error, uint256 newSpotPrice, uint256 newDelta, uint256 outputAmount, uint256 protocolFee, uint256 royaltyAmount ) { (error, newSpotPrice, newDelta, outputAmount, /* tradeFee */, protocolFee) = bondingCurve().getSellInfo(spotPrice, delta, numNFTs, fee, factory().protocolFeeMultiplier()); if (numNFTs != 0) { // Compute royalties (,, royaltyAmount) = calculateRoyaltiesView(assetId, outputAmount); // Deduct royalties from outputAmount unchecked { // Safe because we already require outputAmount >= royaltyAmount in _calculateRoyalties() outputAmount -= royaltyAmount; } } } /** * @notice Returns the pair's variant (Pair uses ETH or ERC20) */ function pairVariant() public pure virtual returns (ILSSVMPairFactoryLike.PairVariant); function factory() public pure returns (ILSSVMPairFactoryLike _factory) { uint256 paramsLength = _immutableParamsLength(); assembly { _factory := shr(0x60, calldataload(sub(calldatasize(), paramsLength))) } } /** * @notice Returns the type of bonding curve that parameterizes the pair */ function bondingCurve() public pure returns (ICurve _bondingCurve) { uint256 paramsLength = _immutableParamsLength(); assembly { _bondingCurve := shr(0x60, calldataload(add(sub(calldatasize(), paramsLength), 20))) } } /** * @notice Returns the address of NFT collection that parameterizes the pair */ function nft() public pure returns (address _nft) { uint256 paramsLength = _immutableParamsLength(); assembly { _nft := shr(0x60, calldataload(add(sub(calldatasize(), paramsLength), 40))) } } /** * @notice Returns the pair's type (TOKEN/NFT/TRADE) */ function poolType() public pure returns (PoolType _poolType) { uint256 paramsLength = _immutableParamsLength(); assembly { _poolType := shr(0xf8, calldataload(add(sub(calldatasize(), paramsLength), 60))) } } /** * @notice Returns the address that receives assets when a swap is done with this pair * Can be set to another address by the owner, but has no effect on TRADE pools * If set to address(0), defaults to owner() for NFT/TOKEN pools */ function getAssetRecipient() public view returns (address payable) { // TRADE pools will always receive the asset themselves if (poolType() == PoolType.TRADE) { return payable(address(this)); } address payable _assetRecipient = assetRecipient; // Otherwise, we return the recipient if it's been set // Or, we replace it with owner() if it's address(0) if (_assetRecipient == address(0)) { return payable(owner()); } return _assetRecipient; } /** * @notice Returns the address that receives trade fees when a swap is done with this pair * Only relevant for TRADE pools * If set to address(0), defaults to the pair itself */ function getFeeRecipient() public view returns (address payable _feeRecipient) { _feeRecipient = assetRecipient; if (_feeRecipient == address(0)) { _feeRecipient = payable(address(this)); } } /** * Internal functions */ /** * @notice Calculates the amount needed to be sent into the pair for a buy and adjusts spot price or delta if necessary * @param numNFTs The amount of NFTs to purchase from the pair * @param _bondingCurve The bonding curve to use for price calculation * @param _factory The factory to use for protocol fee lookup * @return tradeFee The amount of tokens to send as trade fee * @return protocolFee The amount of tokens to send as protocol fee * @return inputAmount The amount of tokens total tokens receive */ function _calculateBuyInfoAndUpdatePoolParams(uint256 numNFTs, ICurve _bondingCurve, ILSSVMPairFactoryLike _factory) internal returns (uint256 tradeFee, uint256 protocolFee, uint256 inputAmount) { CurveErrorCodes.Error error; // Save on 2 SLOADs by caching uint128 currentSpotPrice = spotPrice; uint128 currentDelta = delta; uint128 newDelta; uint128 newSpotPrice; (error, newSpotPrice, newDelta, inputAmount, tradeFee, protocolFee) = _bondingCurve.getBuyInfo(currentSpotPrice, currentDelta, numNFTs, fee, _factory.protocolFeeMultiplier()); // Revert if bonding curve had an error if (error != CurveErrorCodes.Error.OK) { revert LSSVMPair__BondingCurveError(error); } // Consolidate writes to save gas if (currentSpotPrice != newSpotPrice || currentDelta != newDelta) { spotPrice = newSpotPrice; delta = newDelta; } // Emit spot price update if it has been updated if (currentSpotPrice != newSpotPrice) { emit SpotPriceUpdate(newSpotPrice); } // Emit delta update if it has been updated if (currentDelta != newDelta) { emit DeltaUpdate(newDelta); } } /** * @notice Calculates the amount needed to be sent by the pair for a sell and adjusts spot price or delta if necessary * @param numNFTs The amount of NFTs to send to the the pair * @param _bondingCurve The bonding curve to use for price calculation * @param _factory The factory to use for protocol fee lookup * @return protocolFee The amount of tokens to send as protocol fee * @return outputAmount The amount of tokens total tokens receive */ function _calculateSellInfoAndUpdatePoolParams( uint256 numNFTs, ICurve _bondingCurve, ILSSVMPairFactoryLike _factory ) internal returns (uint256 protocolFee, uint256 outputAmount) { CurveErrorCodes.Error error; // Save on 2 SLOADs by caching uint128 currentSpotPrice = spotPrice; uint128 currentDelta = delta; uint128 newSpotPrice; uint128 newDelta; (error, newSpotPrice, newDelta, outputAmount, /*tradeFee*/, protocolFee) = _bondingCurve.getSellInfo(currentSpotPrice, currentDelta, numNFTs, fee, _factory.protocolFeeMultiplier()); // Revert if bonding curve had an error if (error != CurveErrorCodes.Error.OK) { revert LSSVMPair__BondingCurveError(error); } // Consolidate writes to save gas if (currentSpotPrice != newSpotPrice || currentDelta != newDelta) { spotPrice = newSpotPrice; delta = newDelta; } // Emit spot price update if it has been updated if (currentSpotPrice != newSpotPrice) { emit SpotPriceUpdate(newSpotPrice); } // Emit delta update if it has been updated if (currentDelta != newDelta) { emit DeltaUpdate(newDelta); } } /** * @notice Pulls the token input of a trade from the trader (including all royalties and fees) * @param inputAmountExcludingRoyalty The amount of tokens to be sent, excluding the royalty (includes protocol fee) * @param royaltyAmounts The amounts of tokens to be sent as royalties * @param royaltyRecipients The recipients of the royalties * @param royaltyTotal The sum of all royaltyAmounts * @param tradeFeeAmount The amount of tokens to be sent as trade fee (if applicable) * @param isRouter Whether or not the caller is LSSVMRouter * @param routerCaller If called from LSSVMRouter, store the original caller * @param protocolFee The protocol fee to be paid */ function _pullTokenInputs( uint256 inputAmountExcludingRoyalty, uint256[] memory royaltyAmounts, address payable[] memory royaltyRecipients, uint256 royaltyTotal, uint256 tradeFeeAmount, bool isRouter, address routerCaller, uint256 protocolFee ) internal virtual; /** * @notice Sends excess tokens back to the caller (if applicable) * @dev Swap callers interacting with an ETH pair must be able to receive ETH (e.g. if the caller sends too much ETH) */ function _refundTokenToSender(uint256 inputAmount) internal virtual; /** * @notice Sends tokens to a recipient * @param tokenRecipient The address receiving the tokens * @param outputAmount The amount of tokens to send */ function _sendTokenOutput(address payable tokenRecipient, uint256 outputAmount) internal virtual; /** * @dev Used internally to grab pair parameters from calldata, see LSSVMPairCloner for technical details */ function _immutableParamsLength() internal pure virtual returns (uint256); /** * Royalty support functions */ function _calculateRoyalties(uint256 assetId, uint256 saleAmount) internal returns (address payable[] memory royaltyRecipients, uint256[] memory royaltyAmounts, uint256 royaltyTotal) { (address payable[] memory recipients, uint256[] memory amounts) = ROYALTY_ENGINE.getRoyalty(nft(), assetId, saleAmount); return _calculateRoyaltiesLogic(recipients, amounts, saleAmount); } /** * @dev Same as _calculateRoyalties, but uses getRoyaltyView to avoid state mutations and is public for external callers */ function calculateRoyaltiesView(uint256 assetId, uint256 saleAmount) public view returns (address payable[] memory royaltyRecipients, uint256[] memory royaltyAmounts, uint256 royaltyTotal) { (address payable[] memory recipients, uint256[] memory amounts) = ROYALTY_ENGINE.getRoyaltyView(nft(), assetId, saleAmount); return _calculateRoyaltiesLogic(recipients, amounts, saleAmount); } /** * @dev Common logic used by _calculateRoyalties() and calculateRoyaltiesView() */ function _calculateRoyaltiesLogic(address payable[] memory recipients, uint256[] memory amounts, uint256 saleAmount) internal view returns (address payable[] memory royaltyRecipients, uint256[] memory royaltyAmounts, uint256 royaltyTotal) { // Cache to save gas uint256 numRecipients = recipients.length; if (numRecipients != 0) { // If a pair has custom Settings, use the overridden royalty amount and only use the first receiver try factory().getSettingsForPair(address(this)) returns (bool settingsEnabled, uint96 bps) { if (settingsEnabled) { royaltyRecipients = new address payable[](1); royaltyRecipients[0] = recipients[0]; royaltyAmounts = new uint256[](1); royaltyAmounts[0] = (saleAmount * bps) / 10000; // Update numRecipients to match new recipients list numRecipients = 1; } else { royaltyRecipients = recipients; royaltyAmounts = amounts; } } catch { // Use the input values to calculate royalties if factory call fails royaltyRecipients = recipients; royaltyAmounts = amounts; } } for (uint256 i; i < numRecipients;) { royaltyTotal += royaltyAmounts[i]; unchecked { ++i; } } // Ensure royalty total is at most 25% of the sale amount // This defends against a rogue Manifold registry that charges extremely high royalties if (royaltyTotal > saleAmount >> 2) { revert LSSVMPair__RoyaltyTooLarge(); } } /** * Owner functions */ /** * @notice Rescues a specified set of NFTs owned by the pair to the owner address. (onlyOwnable modifier is in the implemented function) * @param a The NFT to transfer * @param nftIds The list of IDs of the NFTs to send to the owner */ function withdrawERC721(IERC721 a, uint256[] calldata nftIds) external virtual; /** * @notice Rescues ERC20 tokens from the pair to the owner. Only callable by the owner (onlyOwnable modifier is in the implemented function). * @param a The token to transfer * @param amount The amount of tokens to send to the owner */ function withdrawERC20(ERC20 a, uint256 amount) external virtual; /** * @notice Rescues ERC1155 tokens from the pair to the owner. Only callable by the owner. * @param a The NFT to transfer * @param ids The NFT ids to transfer * @param amounts The amounts of each id to transfer */ function withdrawERC1155(IERC1155 a, uint256[] calldata ids, uint256[] calldata amounts) external virtual; /** * @notice Updates the selling spot price. Only callable by the owner. * @param newSpotPrice The new selling spot price value, in Token */ function changeSpotPrice(uint128 newSpotPrice) external onlyOwner { ICurve _bondingCurve = bondingCurve(); if (!_bondingCurve.validateSpotPrice(newSpotPrice)) revert LSSVMPair__InvalidSpotPrice(); if (spotPrice != newSpotPrice) { spotPrice = newSpotPrice; emit SpotPriceUpdate(newSpotPrice); } } /** * @notice Updates the delta parameter. Only callable by the owner. * @param newDelta The new delta parameter */ function changeDelta(uint128 newDelta) external onlyOwner { ICurve _bondingCurve = bondingCurve(); if (!_bondingCurve.validateDelta(newDelta)) revert LSSVMPair__InvalidDelta(); if (delta != newDelta) { delta = newDelta; emit DeltaUpdate(newDelta); } } /** * @notice Updates the fee taken by the LP. Only callable by the owner. * Only callable if the pool is a Trade pool. Reverts if the fee is >= MAX_FEE. * @param newFee The new LP fee percentage, 18 decimals */ function changeFee(uint96 newFee) external onlyOwner { PoolType _poolType = poolType(); if (_poolType != PoolType.TRADE) revert LSSVMPair__NonTradePoolWithTradeFee(); if (newFee > MAX_TRADE_FEE) revert LSSVMPair__TradeFeeTooLarge(); if (fee != newFee) { fee = newFee; emit FeeUpdate(newFee); } } /** * @notice Changes the address that will receive assets received from * trades. Only callable by the owner. * @param newRecipient The new asset recipient */ function changeAssetRecipient(address payable newRecipient) external onlyOwner { if (assetRecipient != newRecipient) { assetRecipient = newRecipient; emit AssetRecipientChange(newRecipient); } } function _preCallCheck(address target) internal virtual; /** * @notice Allows the pair to make arbitrary external calls to contracts * whitelisted by the protocol. Only callable by the owner. * @param target The contract to call * @param data The calldata to pass to the contract */ function call(address payable target, bytes calldata data) external onlyOwner { ILSSVMPairFactoryLike _factory = factory(); if (!_factory.callAllowed(target)) revert LSSVMPair__TargetNotAllowed(); // Ensure the call isn't calling a banned function bytes4 sig = bytes4(data[:4]); if ( sig == IOwnershipTransferReceiver.onOwnershipTransferred.selector || sig == LSSVMRouter.pairTransferERC20From.selector || sig == LSSVMRouter.pairTransferNFTFrom.selector || sig == LSSVMRouter.pairTransferERC1155From.selector || sig == ILSSVMPairFactoryLike.openLock.selector || sig == ILSSVMPairFactoryLike.closeLock.selector ) { revert LSSVMPair__FunctionNotAllowed(); } // Prevent calling the pair's underlying nft // (We ban calling the underlying NFT/ERC20 to avoid maliciously transferring assets approved for the pair to spend) if (target == nft()) revert LSSVMPair__TargetNotAllowed(); _preCallCheck(target); (bool success,) = target.call{value: 0}(data); if (!success) revert LSSVMPair__CallFailed(); } /** * @notice Allows owner to batch multiple calls, forked from: https://github.com/boringcrypto/BoringSolidity/blob/master/contracts/BoringBatchable.sol * @notice The revert handling is forked from: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/c239e1af8d1a1296577108dd6989a17b57434f8e/contracts/utils/Address.sol#L201 * @dev Intended for withdrawing/altering pool pricing in one tx, only callable by owner, cannot change owner * @param calls The calldata for each call to make * @param revertOnFail Whether or not to revert the entire tx if any of the calls fail. Calls to transferOwnership will revert regardless. */ function multicall(bytes[] calldata calls, bool revertOnFail) external onlyOwner { for (uint256 i; i < calls.length;) { bytes4 sig = bytes4(calls[i][:4]); // We ban calling transferOwnership when ownership if (sig == transferOwnership.selector) revert LSSVMPair__FunctionNotAllowed(); (bool success, bytes memory result) = address(this).delegatecall(calls[i]); if (!success && revertOnFail) { assembly { revert(add(0x20, result), mload(result)) } } unchecked { ++i; } } } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {ERC20} from "solmate/tokens/ERC20.sol"; import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; import {LSSVMPair} from "./LSSVMPair.sol"; import {LSSVMRouter} from "./LSSVMRouter.sol"; import {ILSSVMPairFactoryLike} from "./ILSSVMPairFactoryLike.sol"; /** * @title An NFT/Token pair where the token is an ERC20 * @author boredGenius, 0xmons, 0xCygaar */ abstract contract LSSVMPairERC20 is LSSVMPair { using SafeTransferLib for ERC20; error LSSVMPairERC20__RoyaltyNotPaid(); error LSSVMPairERC20__MsgValueNotZero(); error LSSVMPairERC20__AssetRecipientNotPaid(); /** * @notice Returns the ERC20 token associated with the pair * @dev See LSSVMPairCloner for an explanation on how this works * @dev The last 20 bytes of the immutable data contain the ERC20 token address */ function token() public pure returns (ERC20 _token) { assembly { _token := shr(0x60, calldataload(sub(calldatasize(), 20))) } } /** * @inheritdoc LSSVMPair */ function _pullTokenInputs( uint256 inputAmountExcludingRoyalty, uint256[] memory royaltyAmounts, address payable[] memory royaltyRecipients, uint256, /* royaltyTotal */ uint256 tradeFeeAmount, bool isRouter, address routerCaller, uint256 protocolFee ) internal override { address _assetRecipient = getAssetRecipient(); // Transfer tokens if (isRouter) { // Verify if router is allowed // Locally scoped to avoid stack too deep { (bool routerAllowed,) = factory().routerStatus(LSSVMRouter(payable(msg.sender))); if (!routerAllowed) revert LSSVMPair__NotRouter(); } // Cache state and then call router to transfer tokens from user uint256 beforeBalance = token().balanceOf(_assetRecipient); LSSVMRouter(payable(msg.sender)).pairTransferERC20From( token(), routerCaller, _assetRecipient, inputAmountExcludingRoyalty - protocolFee ); // Verify token transfer (protect pair against malicious router) ERC20 token_ = token(); if (token_.balanceOf(_assetRecipient) - beforeBalance != (inputAmountExcludingRoyalty - protocolFee)) { revert LSSVMPairERC20__AssetRecipientNotPaid(); } // Transfer royalties (if they exist) for (uint256 i; i < royaltyRecipients.length;) { beforeBalance = token_.balanceOf(royaltyRecipients[i]); LSSVMRouter(payable(msg.sender)).pairTransferERC20From( token_, routerCaller, royaltyRecipients[i], royaltyAmounts[i] ); if (token_.balanceOf(royaltyRecipients[i]) - beforeBalance != royaltyAmounts[i]) { revert LSSVMPairERC20__RoyaltyNotPaid(); } unchecked { ++i; } } // Take protocol fee (if it exists) if (protocolFee != 0) { LSSVMRouter(payable(msg.sender)).pairTransferERC20From( token_, routerCaller, address(factory()), protocolFee ); } } else { // Transfer tokens directly (sans the protocol fee) ERC20 token_ = token(); token_.safeTransferFrom(msg.sender, _assetRecipient, inputAmountExcludingRoyalty - protocolFee); // Transfer royalties (if they exists) for (uint256 i; i < royaltyRecipients.length;) { token_.safeTransferFrom(msg.sender, royaltyRecipients[i], royaltyAmounts[i]); unchecked { ++i; } } // Take protocol fee (if it exists) if (protocolFee != 0) { token_.safeTransferFrom(msg.sender, address(factory()), protocolFee); } } // Send trade fee if it exists, is TRADE pool, and fee recipient != pool address // @dev: (note that tokens are sent from the pool and not the caller) if (poolType() == PoolType.TRADE && tradeFeeAmount != 0) { address payable _feeRecipient = getFeeRecipient(); if (_feeRecipient != _assetRecipient) { token().safeTransfer(_feeRecipient, tradeFeeAmount); } } } /** * @inheritdoc LSSVMPair */ function _refundTokenToSender(uint256 inputAmount) internal override { // Do nothing since we transferred the exact input amount } /** * @inheritdoc LSSVMPair */ function _sendTokenOutput(address payable tokenRecipient, uint256 outputAmount) internal override { // Send tokens to caller if (outputAmount != 0) { token().safeTransfer(tokenRecipient, outputAmount); } } /** * @inheritdoc LSSVMPair */ function withdrawERC20(ERC20 a, uint256 amount) external override onlyOwner { a.safeTransfer(msg.sender, amount); if (a == token()) { // emit event since it is the pair token emit TokenWithdrawal(amount); } } function _preCallCheck(address target) internal pure override { if (target == address(token())) revert LSSVMPair__TargetNotAllowed(); } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; interface ILSSVMPairERC721 { function swapNFTsForToken( uint256[] calldata nftIds, uint256 minExpectedTokenOutput, address payable tokenRecipient, bool isRouter, address routerCaller, bytes calldata propertyCheckerParams ) external returns (uint256 outputAmount); }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import {ERC20} from "solmate/tokens/ERC20.sol"; import {LSSVMPair} from "../LSSVMPair.sol"; import {LSSVMRouter} from "../LSSVMRouter.sol"; import {ICurve} from "../bonding-curves/ICurve.sol"; import {ILSSVMPairFactoryLike} from "../ILSSVMPairFactoryLike.sol"; /** * @title LSSVMPairERC1155 * @author boredGenius, 0xmons, 0xCygaar * @notice An NFT/Token pair for an ERC1155 NFT where NFTs with the same ID are considered fungible. */ abstract contract LSSVMPairERC1155 is LSSVMPair { /** * External state-changing functions */ /** * @notice Sends token to the pair in exchange for any `numNFTs` NFTs * @dev To compute the amount of token to send, call bondingCurve.getBuyInfo. * This swap function is meant for users who are ID agnostic * @param numNFTs The number of NFTs to purchase * @param maxExpectedTokenInput The maximum acceptable cost from the sender. If the actual * amount is greater than this value, the transaction will be reverted. * @param nftRecipient The recipient of the NFTs * @param isRouter True if calling from LSSVMRouter, false otherwise. Not used for ETH pairs. * @param routerCaller If isRouter is true, ERC20 tokens will be transferred from this address. Not used for ETH pairs. * @return inputAmount The amount of token used for purchase */ function swapTokenForSpecificNFTs( uint256[] calldata numNFTs, uint256 maxExpectedTokenInput, address nftRecipient, bool isRouter, address routerCaller ) external payable virtual override returns (uint256) { // Store locally to remove extra calls factory().openLock(); // Input validation { if (poolType() == PoolType.TOKEN) revert LSSVMPair__WrongPoolType(); if (numNFTs.length != 1 || numNFTs[0] == 0) revert LSSVMPair__ZeroSwapAmount(); } // Call bonding curve for pricing information uint256 tradeFee; uint256 protocolFee; uint256 inputAmountExcludingRoyalty; (tradeFee, protocolFee, inputAmountExcludingRoyalty) = _calculateBuyInfoAndUpdatePoolParams(numNFTs[0], bondingCurve(), factory()); (address payable[] memory royaltyRecipients, uint256[] memory royaltyAmounts, uint256 royaltyTotal) = _calculateRoyalties(nftId(), inputAmountExcludingRoyalty - protocolFee - tradeFee); // Revert if the input amount is too large if (royaltyTotal + inputAmountExcludingRoyalty > maxExpectedTokenInput) { revert LSSVMPair__DemandedInputTooLarge(); } _pullTokenInputs({ inputAmountExcludingRoyalty: inputAmountExcludingRoyalty, royaltyRecipients: royaltyRecipients, royaltyAmounts: royaltyAmounts, royaltyTotal: royaltyTotal, tradeFeeAmount: 2 * tradeFee, isRouter: isRouter, routerCaller: routerCaller, protocolFee: protocolFee }); _sendAnyNFTsToRecipient(IERC1155(nft()), nftRecipient, numNFTs[0]); _refundTokenToSender(royaltyTotal + inputAmountExcludingRoyalty); factory().closeLock(); emit SwapNFTOutPair(royaltyTotal + inputAmountExcludingRoyalty, numNFTs[0]); return (royaltyTotal + inputAmountExcludingRoyalty); } /** * @notice Sends a set of NFTs to the pair in exchange for token * @dev To compute the amount of token to that will be received, call bondingCurve.getSellInfo. * @param numNFTs The number of NFTs to swap * @param minExpectedTokenOutput The minimum acceptable token received by the sender. If the actual * amount is less than this value, the transaction will be reverted. * @param tokenRecipient The recipient of the token output * @param isRouter True if calling from LSSVMRouter, false otherwise. Not used for ETH pairs. * @param routerCaller If isRouter is true, ERC20 tokens will be transferred from this address. Not used for ETH pairs. * @return outputAmount The amount of token received */ function swapNFTsForToken( uint256[] calldata numNFTs, // @dev this is a bit hacky, to allow for better interop w/ other pair interfaces uint256 minExpectedTokenOutput, address payable tokenRecipient, bool isRouter, address routerCaller ) external virtual override returns (uint256 outputAmount) { // Store locally to remove extra calls ILSSVMPairFactoryLike _factory = factory(); _factory.openLock(); ICurve _bondingCurve = bondingCurve(); // Input validation { if (poolType() == PoolType.NFT) revert LSSVMPair__WrongPoolType(); if (numNFTs.length != 1 || numNFTs[0] == 0) revert LSSVMPair__ZeroSwapAmount(); } // Call bonding curve for pricing information uint256 protocolFee; (protocolFee, outputAmount) = _calculateSellInfoAndUpdatePoolParams(numNFTs[0], _bondingCurve, _factory); // Compute royalties (address payable[] memory royaltyRecipients, uint256[] memory royaltyAmounts, uint256 royaltyTotal) = _calculateRoyalties(nftId(), outputAmount); // Deduct royalties from outputAmount unchecked { // Safe because we already require outputAmount >= royaltyTotal in calculateRoyalties() outputAmount -= royaltyTotal; } if (outputAmount < minExpectedTokenOutput) revert LSSVMPair__OutputTooSmall(); _takeNFTsFromSender(IERC1155(nft()), numNFTs[0], _factory, isRouter, routerCaller); _sendTokenOutput(tokenRecipient, outputAmount); for (uint256 i; i < royaltyRecipients.length;) { _sendTokenOutput(royaltyRecipients[i], royaltyAmounts[i]); unchecked { ++i; } } _sendTokenOutput(payable(address(_factory)), protocolFee); _factory.closeLock(); emit SwapNFTInPair(outputAmount, numNFTs[0]); } /** * View functions */ /** * @notice Returns the ERC-1155 NFT ID this pool uses */ function nftId() public pure returns (uint256 id) { uint256 paramsLength = _immutableParamsLength(); assembly { id := calldataload(add(sub(calldatasize(), paramsLength), 61)) } } /** * Internal functions */ /** * @notice Sends some number of NFTs to a recipient address * @dev Even though we specify the NFT address here, this internal function is only * used to send NFTs associated with this specific pool. * @param _nft The address of the NFT to send * @param nftRecipient The receiving address for the NFTs * @param numNFTs The number of NFTs to send */ function _sendAnyNFTsToRecipient(IERC1155 _nft, address nftRecipient, uint256 numNFTs) internal virtual { _nft.safeTransferFrom(address(this), nftRecipient, nftId(), numNFTs, bytes("")); } /** * @notice Takes NFTs from the caller and sends them into the pair's asset recipient * @dev This is used by the LSSVMPair's swapNFTForToken function. * @param _nft The NFT collection to take from * @param numNFTs The number of NFTs to take * @param isRouter Whether or not to use the router pull flow * @param routerCaller If the caller is a router, passes in which address to pull from (i.e. the router's caller) */ function _takeNFTsFromSender( IERC1155 _nft, uint256 numNFTs, ILSSVMPairFactoryLike factory, bool isRouter, address routerCaller ) internal virtual { address _assetRecipient = getAssetRecipient(); if (isRouter) { // Verify if router is allowed LSSVMRouter router = LSSVMRouter(payable(msg.sender)); (bool routerAllowed,) = factory.routerStatus(router); if (!routerAllowed) revert LSSVMPair__NotRouter(); uint256 _nftId = nftId(); uint256 beforeBalance = _nft.balanceOf(_assetRecipient, _nftId); uint256[] memory ids = new uint256[](1); ids[0] = _nftId; uint256[] memory amounts = new uint256[](1); amounts[0] = numNFTs; router.pairTransferERC1155From(_nft, routerCaller, _assetRecipient, ids, amounts); if (_nft.balanceOf(_assetRecipient, _nftId) - beforeBalance != numNFTs) { revert LSSVMPair__NftNotTransferred(); } } else { // Pull NFTs directly from sender _nft.safeTransferFrom(msg.sender, _assetRecipient, nftId(), numNFTs, bytes("")); } } /** * Owner functions */ /** * @notice Rescues a specified set of NFTs owned by the pair to the owner address. Only callable by the owner. * @param a The NFT to transfer * @param nftIds The list of IDs of the NFTs to send to the owner */ function withdrawERC721(IERC721 a, uint256[] calldata nftIds) external virtual override onlyOwner { uint256 numNFTs = nftIds.length; for (uint256 i; i < numNFTs;) { a.safeTransferFrom(address(this), msg.sender, nftIds[i]); unchecked { ++i; } } } /** * @notice Transfers ERC1155 tokens from the pair to the owner. Only callable by the owner. * @param a The NFT to transfer * @param ids The NFT ids to transfer * @param amounts The amounts of each id to transfer */ function withdrawERC1155(IERC1155 a, uint256[] calldata ids, uint256[] calldata amounts) external virtual override onlyOwner { if (a == IERC1155(nft())) { // Check if we need to emit an event for withdrawing the NFT this pool is trading uint256 _nftId = nftId(); uint256 numNFTs = ids.length; uint256 numPairNFTsWithdrawn; for (uint256 i; i < numNFTs;) { if (ids[i] == _nftId) { numPairNFTsWithdrawn += amounts[i]; } unchecked { ++i; } } if (numPairNFTsWithdrawn != 0) { // Only emit for the pair's NFT emit NFTWithdrawal(numPairNFTsWithdrawn); } } a.safeBatchTransferFrom(address(this), msg.sender, ids, amounts, bytes("")); } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {LSSVMRouter} from "./LSSVMRouter.sol"; interface ILSSVMPairFactoryLike { struct Settings { uint96 bps; address pairAddress; } enum PairNFTType { ERC721, ERC1155 } enum PairTokenType { ETH, ERC20 } enum PairVariant { ERC721_ETH, ERC721_ERC20, ERC1155_ETH, ERC1155_ERC20 } function protocolFeeMultiplier() external view returns (uint256); function protocolFeeRecipient() external view returns (address payable); function callAllowed(address target) external view returns (bool); function authAllowedForToken(address tokenAddress, address proposedAuthAddress) external view returns (bool); function getSettingsForPair(address pairAddress) external view returns (bool settingsEnabled, uint96 bps); function enableSettingsForPair(address settings, address pairAddress) external; function disableSettingsForPair(address settings, address pairAddress) external; function routerStatus(LSSVMRouter router) external view returns (bool allowed, bool wasEverTouched); function isValidPair(address pairAddress) external view returns (bool); function getPairNFTType(address pairAddress) external pure returns (PairNFTType); function getPairTokenType(address pairAddress) external pure returns (PairTokenType); function openLock() external; function closeLock() external; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; contract CurveErrorCodes { enum Error { OK, // No error INVALID_NUMITEMS, // The numItem value is 0 SPOT_PRICE_OVERFLOW, // The updated spot price doesn't fit into 128 bits DELTA_OVERFLOW, // The updated delta doesn't fit into 128 bits SPOT_PRICE_UNDERFLOW // The updated spot price goes too low } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {CurveErrorCodes} from "./CurveErrorCodes.sol"; interface ICurve { /** * @notice Validates if a delta value is valid for the curve. The criteria for * validity can be different for each type of curve, for instance ExponentialCurve * requires delta to be greater than 1. * @param delta The delta value to be validated * @return valid True if delta is valid, false otherwise */ function validateDelta(uint128 delta) external pure returns (bool valid); /** * @notice Validates if a new spot price is valid for the curve. Spot price is generally assumed to be the immediate sell price of 1 NFT to the pool, in units of the pool's paired token. * @param newSpotPrice The new spot price to be set * @return valid True if the new spot price is valid, false otherwise */ function validateSpotPrice(uint128 newSpotPrice) external view returns (bool valid); /** * @notice Given the current state of the pair and the trade, computes how much the user * should pay to purchase an NFT from the pair, the new spot price, and other values. * @param spotPrice The current selling spot price of the pair, in tokens * @param delta The delta parameter of the pair, what it means depends on the curve * @param numItems The number of NFTs the user is buying from the pair * @param feeMultiplier Determines how much fee the LP takes from this trade, 18 decimals * @param protocolFeeMultiplier Determines how much fee the protocol takes from this trade, 18 decimals * @return error Any math calculation errors, only Error.OK means the returned values are valid * @return newSpotPrice The updated selling spot price, in tokens * @return newDelta The updated delta, used to parameterize the bonding curve * @return inputValue The amount that the user should pay, in tokens * @return tradeFee The amount that is sent to the trade fee recipient * @return protocolFee The amount of fee to send to the protocol, in tokens */ function getBuyInfo( uint128 spotPrice, uint128 delta, uint256 numItems, uint256 feeMultiplier, uint256 protocolFeeMultiplier ) external view returns ( CurveErrorCodes.Error error, uint128 newSpotPrice, uint128 newDelta, uint256 inputValue, uint256 tradeFee, uint256 protocolFee ); /** * @notice Given the current state of the pair and the trade, computes how much the user * should receive when selling NFTs to the pair, the new spot price, and other values. * @param spotPrice The current selling spot price of the pair, in tokens * @param delta The delta parameter of the pair, what it means depends on the curve * @param numItems The number of NFTs the user is selling to the pair * @param feeMultiplier Determines how much fee the LP takes from this trade, 18 decimals * @param protocolFeeMultiplier Determines how much fee the protocol takes from this trade, 18 decimals * @return error Any math calculation errors, only Error.OK means the returned values are valid * @return newSpotPrice The updated selling spot price, in tokens * @return newDelta The updated delta, used to parameterize the bonding curve * @return outputValue The amount that the user should receive, in tokens * @return tradeFee The amount that is sent to the trade fee recipient * @return protocolFee The amount of fee to send to the protocol, in tokens */ function getSellInfo( uint128 spotPrice, uint128 delta, uint256 numItems, uint256 feeMultiplier, uint256 protocolFeeMultiplier ) external view returns ( CurveErrorCodes.Error error, uint128 newSpotPrice, uint128 newDelta, uint256 outputValue, uint256 tradeFee, uint256 protocolFee ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @author: manifold.xyz import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; /** * @dev Lookup engine interface */ interface IRoyaltyEngineV1 is IERC165 { /** * Get the royalty for a given token (address, id) and value amount. Does not cache the bps/amounts. Caches the spec for a given token address * * @param tokenAddress - The address of the token * @param tokenId - The id of the token * @param value - The value you wish to get the royalty of * * returns Two arrays of equal length, royalty recipients and the corresponding amount each recipient should get */ function getRoyalty(address tokenAddress, uint256 tokenId, uint256 value) external returns (address payable[] memory recipients, uint256[] memory amounts); /** * View only version of getRoyalty * * @param tokenAddress - The address of the token * @param tokenId - The id of the token * @param value - The value you wish to get the royalty of * * returns Two arrays of equal length, royalty recipients and the corresponding amount each recipient should get */ function getRoyaltyView(address tokenAddress, uint256 tokenId, uint256 value) external view returns (address payable[] memory recipients, uint256[] memory amounts); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol) pragma solidity ^0.8.0; import "../IERC721Receiver.sol"; /** * @dev Implementation of the {IERC721Receiver} interface. * * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. */ contract ERC721Holder is IERC721Receiver { /** * @dev See {IERC721Receiver-onERC721Received}. * * Always returns `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) { return this.onERC721Received.selector; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/utils/ERC1155Holder.sol) pragma solidity ^0.8.0; import "./ERC1155Receiver.sol"; /** * Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens. * * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be * stuck. * * @dev _Available since v3.1._ */ contract ERC1155Holder is ERC1155Receiver { function onERC1155Received( address, address, uint256, uint256, bytes memory ) public virtual override returns (bytes4) { return this.onERC1155Received.selector; } function onERC1155BatchReceived( address, address, uint256[] memory, uint256[] memory, bytes memory ) public virtual override returns (bytes4) { return this.onERC1155BatchReceived.selector; } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.0; import {ERC20} from "solmate/tokens/ERC20.sol"; import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol"; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import {LSSVMPair} from "./LSSVMPair.sol"; import {ILSSVMPairFactoryLike} from "./ILSSVMPairFactoryLike.sol"; import {CurveErrorCodes} from "./bonding-curves/CurveErrorCodes.sol"; contract LSSVMRouter { using SafeTransferLib for address payable; using SafeTransferLib for ERC20; struct PairSwapSpecific { LSSVMPair pair; uint256[] nftIds; } struct RobustPairSwapSpecific { PairSwapSpecific swapInfo; uint256 maxCost; } struct RobustPairSwapSpecificForToken { PairSwapSpecific swapInfo; uint256 minOutput; } struct NFTsForSpecificNFTsTrade { PairSwapSpecific[] nftToTokenTrades; PairSwapSpecific[] tokenToNFTTrades; } struct RobustPairNFTsFoTokenAndTokenforNFTsTrade { RobustPairSwapSpecific[] tokenToNFTTrades; RobustPairSwapSpecificForToken[] nftToTokenTrades; uint256 inputAmount; address payable tokenRecipient; address nftRecipient; } modifier checkDeadline(uint256 deadline) { _checkDeadline(deadline); _; } ILSSVMPairFactoryLike public immutable factory; constructor(ILSSVMPairFactoryLike _factory) { factory = _factory; } /** * ETH swaps */ /** * @notice Swaps ETH into specific NFTs using multiple pairs. * @param swapList The list of pairs to trade with and the IDs of the NFTs to buy from each. * @param ethRecipient The address that will receive the unspent ETH input * @param nftRecipient The address that will receive the NFT output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return remainingValue The unspent ETH amount */ function swapETHForSpecificNFTs( PairSwapSpecific[] calldata swapList, address payable ethRecipient, address nftRecipient, uint256 deadline ) external payable checkDeadline(deadline) returns (uint256 remainingValue) { return _swapETHForSpecificNFTs(swapList, msg.value, ethRecipient, nftRecipient); } /** * @notice Swaps one set of NFTs into another set of specific NFTs using multiple pairs, using * ETH as the intermediary. * @param trade The struct containing all NFT-to-ETH swaps and ETH-to-NFT swaps. * @param minOutput The minimum acceptable total excess ETH received * @param ethRecipient The address that will receive the ETH output * @param nftRecipient The address that will receive the NFT output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return outputAmount The total ETH received */ function swapNFTsForSpecificNFTsThroughETH( NFTsForSpecificNFTsTrade calldata trade, uint256 minOutput, address payable ethRecipient, address nftRecipient, uint256 deadline ) external payable checkDeadline(deadline) returns (uint256 outputAmount) { // Swap NFTs for ETH // minOutput of swap set to 0 since we're doing an aggregate slippage check outputAmount = _swapNFTsForToken(trade.nftToTokenTrades, 0, payable(address(this))); // Add extra value to buy NFTs outputAmount += msg.value; // Swap ETH for specific NFTs // cost <= inputValue = outputAmount - minOutput, so outputAmount' = (outputAmount - minOutput - cost) + minOutput >= minOutput outputAmount = _swapETHForSpecificNFTs( trade.tokenToNFTTrades, outputAmount - minOutput, ethRecipient, nftRecipient ) + minOutput; } /** * ERC20 swaps * * Note: All ERC20 swaps assume that a single ERC20 token is used for all the pairs involved. * Swapping using multiple tokens in the same transaction is possible, but the slippage checks * & the return values will be meaningless, and may lead to undefined behavior. * * Note: The sender should ideally grant infinite token approval to the router in order for NFT-to-NFT * swaps to work smoothly. */ /** * @notice Swaps ERC20 tokens into specific NFTs using multiple pairs. * @param swapList The list of pairs to trade with and the IDs of the NFTs to buy from each. * @param inputAmount The amount of ERC20 tokens to add to the ERC20-to-NFT swaps * @param nftRecipient The address that will receive the NFT output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return remainingValue The unspent token amount */ function swapERC20ForSpecificNFTs( PairSwapSpecific[] calldata swapList, uint256 inputAmount, address nftRecipient, uint256 deadline ) external checkDeadline(deadline) returns (uint256 remainingValue) { return _swapERC20ForSpecificNFTs(swapList, inputAmount, nftRecipient); } /** * @notice Swaps NFTs into ETH/ERC20 using multiple pairs. * @param swapList The list of pairs to trade with and the IDs of the NFTs to sell to each. * @param minOutput The minimum acceptable total tokens received * @param tokenRecipient The address that will receive the token output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return outputAmount The total tokens received */ function swapNFTsForToken( PairSwapSpecific[] calldata swapList, uint256 minOutput, address tokenRecipient, uint256 deadline ) external checkDeadline(deadline) returns (uint256 outputAmount) { return _swapNFTsForToken(swapList, minOutput, payable(tokenRecipient)); } /** * @notice Swaps one set of NFTs into another set of specific NFTs using multiple pairs, using * an ERC20 token as the intermediary. * @param trade The struct containing all NFT-to-ERC20 swaps and ERC20-to-NFT swaps. * @param inputAmount The amount of ERC20 tokens to add to the ERC20-to-NFT swaps * @param minOutput The minimum acceptable total excess tokens received * @param nftRecipient The address that will receive the NFT output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return outputAmount The total ERC20 tokens received */ function swapNFTsForSpecificNFTsThroughERC20( NFTsForSpecificNFTsTrade calldata trade, uint256 inputAmount, uint256 minOutput, address nftRecipient, uint256 deadline ) external checkDeadline(deadline) returns (uint256 outputAmount) { // Swap NFTs for ERC20 // minOutput of swap set to 0 since we're doing an aggregate slippage check // output tokens are sent to msg.sender outputAmount = _swapNFTsForToken(trade.nftToTokenTrades, 0, payable(msg.sender)); // Add extra value to buy NFTs outputAmount += inputAmount; // Swap ERC20 for specific NFTs // cost <= maxCost = outputAmount - minOutput, so outputAmount' = outputAmount - cost >= minOutput // input tokens are taken directly from msg.sender outputAmount = _swapERC20ForSpecificNFTs(trade.tokenToNFTTrades, outputAmount - minOutput, nftRecipient) + minOutput; } /** * Robust Swaps * These are "robust" versions of the NFT<>Token swap functions which will never revert due to slippage * Instead, users specify a per-swap max cost. If the price changes more than the user specifies, no swap is attempted. This allows users to specify a batch of swaps, and execute as many of them as possible. */ /** * @dev Ensure msg.value >= sum of values in maxCostPerPair to make sure the transaction doesn't revert * @param swapList The list of pairs to trade with and the IDs of the NFTs to buy from each. * @param ethRecipient The address that will receive the unspent ETH input * @param nftRecipient The address that will receive the NFT output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return remainingValue The unspent token amount */ function robustSwapETHForSpecificNFTs( RobustPairSwapSpecific[] calldata swapList, address payable ethRecipient, address nftRecipient, uint256 deadline ) public payable virtual checkDeadline(deadline) returns (uint256 remainingValue) { remainingValue = msg.value; uint256 pairCost; CurveErrorCodes.Error error; // Try doing each swap uint256 numSwaps = swapList.length; for (uint256 i; i < numSwaps;) { // Calculate actual cost per swap (error,,, pairCost,,) = swapList[i].swapInfo.pair.getBuyNFTQuote( swapList[i].swapInfo.nftIds[0], swapList[i].swapInfo.nftIds.length ); // If within our maxCost and no error, proceed if (pairCost <= swapList[i].maxCost && error == CurveErrorCodes.Error.OK) { // We know how much ETH to send because we already did the math above // So we just send that much remainingValue -= swapList[i].swapInfo.pair.swapTokenForSpecificNFTs{value: pairCost}( swapList[i].swapInfo.nftIds, pairCost, nftRecipient, true, msg.sender ); } unchecked { ++i; } } // Return remaining value to sender if (remainingValue > 0) { ethRecipient.safeTransferETH(remainingValue); } } /** * @notice Swaps as many ERC20 tokens for specific NFTs as possible, respecting the per-swap max cost. * @param swapList The list of pairs to trade with and the IDs of the NFTs to buy from each. * @param inputAmount The amount of ERC20 tokens to add to the ERC20-to-NFT swaps * @param nftRecipient The address that will receive the NFT output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return remainingValue The unspent token amount */ function robustSwapERC20ForSpecificNFTs( RobustPairSwapSpecific[] calldata swapList, uint256 inputAmount, address nftRecipient, uint256 deadline ) public virtual checkDeadline(deadline) returns (uint256 remainingValue) { remainingValue = inputAmount; uint256 pairCost; CurveErrorCodes.Error error; // Try doing each swap uint256 numSwaps = swapList.length; for (uint256 i; i < numSwaps;) { // Calculate actual cost per swap (error,,, pairCost,,) = swapList[i].swapInfo.pair.getBuyNFTQuote( swapList[i].swapInfo.nftIds[0], swapList[i].swapInfo.nftIds.length ); // If within our maxCost and no error, proceed if (pairCost <= swapList[i].maxCost && error == CurveErrorCodes.Error.OK) { remainingValue -= swapList[i].swapInfo.pair.swapTokenForSpecificNFTs( swapList[i].swapInfo.nftIds, pairCost, nftRecipient, true, msg.sender ); } unchecked { ++i; } } } /** * @notice Swaps as many NFTs for tokens as possible, respecting the per-swap min output * @param swapList The list of pairs to trade with and the IDs of the NFTs to sell to each. * @param tokenRecipient The address that will receive the token output * @param deadline The Unix timestamp (in seconds) at/after which the swap will revert * @return outputAmount The total ETH/ERC20 received */ function robustSwapNFTsForToken( RobustPairSwapSpecificForToken[] calldata swapList, address payable tokenRecipient, uint256 deadline ) public virtual checkDeadline(deadline) returns (uint256 outputAmount) { // Try doing each swap uint256 numSwaps = swapList.length; for (uint256 i; i < numSwaps;) { uint256 pairOutput; // Locally scoped to avoid stack too deep error { CurveErrorCodes.Error error; uint256[] memory nftIds = swapList[i].swapInfo.nftIds; if (nftIds.length == 0) { unchecked { ++i; } continue; } (error,,, pairOutput,,) = swapList[i].swapInfo.pair.getSellNFTQuote(nftIds[0], nftIds.length); if (error != CurveErrorCodes.Error.OK) { unchecked { ++i; } continue; } } // If at least equal to our minOutput, proceed if (pairOutput >= swapList[i].minOutput) { // Do the swap and update outputAmount with how many tokens we got outputAmount += swapList[i].swapInfo.pair.swapNFTsForToken( swapList[i].swapInfo.nftIds, 0, tokenRecipient, true, msg.sender ); } unchecked { ++i; } } } /** * @notice Buys NFTs with ETH and sells them for tokens in one transaction * @param params All the parameters for the swap (packed in struct to avoid stack too deep), containing: * - ethToNFTSwapList The list of NFTs to buy * - nftToTokenSwapList The list of NFTs to sell * - inputAmount The max amount of tokens to send (if ERC20) * - tokenRecipient The address that receives tokens from the NFTs sold * - nftRecipient The address that receives NFTs * - deadline UNIX timestamp deadline for the swap */ function robustSwapETHForSpecificNFTsAndNFTsToToken(RobustPairNFTsFoTokenAndTokenforNFTsTrade calldata params) external payable virtual returns (uint256 remainingValue, uint256 outputAmount) { { remainingValue = msg.value; uint256 pairCost; CurveErrorCodes.Error error; // Try doing each swap uint256 numSwaps = params.tokenToNFTTrades.length; for (uint256 i; i < numSwaps;) { // Calculate actual cost per swap (error,,, pairCost,,) = params.tokenToNFTTrades[i].swapInfo.pair.getBuyNFTQuote( params.tokenToNFTTrades[i].swapInfo.nftIds[0], params.tokenToNFTTrades[i].swapInfo.nftIds.length ); // If within our maxCost and no error, proceed if (pairCost <= params.tokenToNFTTrades[i].maxCost && error == CurveErrorCodes.Error.OK) { // We know how much ETH to send because we already did the math above // So we just send that much remainingValue -= params.tokenToNFTTrades[i].swapInfo.pair.swapTokenForSpecificNFTs{value: pairCost}( params.tokenToNFTTrades[i].swapInfo.nftIds, pairCost, params.nftRecipient, true, msg.sender ); } unchecked { ++i; } } // Return remaining value to sender if (remainingValue > 0) { params.tokenRecipient.safeTransferETH(remainingValue); } } { // Try doing each swap uint256 numSwaps = params.nftToTokenTrades.length; for (uint256 i; i < numSwaps;) { uint256 pairOutput; // Locally scoped to avoid stack too deep error { CurveErrorCodes.Error error; uint256 assetId = params.nftToTokenTrades[i].swapInfo.nftIds[0]; (error,,, pairOutput,,) = params.nftToTokenTrades[i].swapInfo.pair.getSellNFTQuote( assetId, params.nftToTokenTrades[i].swapInfo.nftIds.length ); if (error != CurveErrorCodes.Error.OK) { unchecked { ++i; } continue; } } // If at least equal to our minOutput, proceed if (pairOutput >= params.nftToTokenTrades[i].minOutput) { // Do the swap and update outputAmount with how many tokens we got outputAmount += params.nftToTokenTrades[i].swapInfo.pair.swapNFTsForToken( params.nftToTokenTrades[i].swapInfo.nftIds, 0, params.tokenRecipient, true, msg.sender ); } unchecked { ++i; } } } } /** * @notice Buys NFTs with ERC20, and sells them for tokens in one transaction * @param params All the parameters for the swap (packed in struct to avoid stack too deep), containing: * - ethToNFTSwapList The list of NFTs to buy * - nftToTokenSwapList The list of NFTs to sell * - inputAmount The max amount of tokens to send (if ERC20) * - tokenRecipient The address that receives tokens from the NFTs sold * - nftRecipient The address that receives NFTs * - deadline UNIX timestamp deadline for the swap */ function robustSwapERC20ForSpecificNFTsAndNFTsToToken(RobustPairNFTsFoTokenAndTokenforNFTsTrade calldata params) external virtual returns (uint256 remainingValue, uint256 outputAmount) { { remainingValue = params.inputAmount; uint256 pairCost; CurveErrorCodes.Error error; // Try doing each swap uint256 numSwaps = params.tokenToNFTTrades.length; for (uint256 i; i < numSwaps;) { // Calculate actual cost per swap (error,,, pairCost,,) = params.tokenToNFTTrades[i].swapInfo.pair.getBuyNFTQuote( params.tokenToNFTTrades[i].swapInfo.nftIds[0], params.tokenToNFTTrades[i].swapInfo.nftIds.length ); // If within our maxCost and no error, proceed if (pairCost <= params.tokenToNFTTrades[i].maxCost && error == CurveErrorCodes.Error.OK) { remainingValue -= params.tokenToNFTTrades[i].swapInfo.pair.swapTokenForSpecificNFTs( params.tokenToNFTTrades[i].swapInfo.nftIds, pairCost, params.nftRecipient, true, msg.sender ); } unchecked { ++i; } } } { // Try doing each swap uint256 numSwaps = params.nftToTokenTrades.length; for (uint256 i; i < numSwaps;) { uint256 pairOutput; // Locally scoped to avoid stack too deep error { CurveErrorCodes.Error error; uint256 assetId = params.nftToTokenTrades[i].swapInfo.nftIds[0]; (error,,, pairOutput,,) = params.nftToTokenTrades[i].swapInfo.pair.getSellNFTQuote( assetId, params.nftToTokenTrades[i].swapInfo.nftIds.length ); if (error != CurveErrorCodes.Error.OK) { unchecked { ++i; } continue; } } // If at least equal to our minOutput, proceed if (pairOutput >= params.nftToTokenTrades[i].minOutput) { // Do the swap and update outputAmount with how many tokens we got outputAmount += params.nftToTokenTrades[i].swapInfo.pair.swapNFTsForToken( params.nftToTokenTrades[i].swapInfo.nftIds, 0, params.tokenRecipient, true, msg.sender ); } unchecked { ++i; } } } } receive() external payable {} /** * Restricted functions */ /** * @dev Allows an ERC20 pair contract to transfer ERC20 tokens directly from * the sender, in order to minimize the number of token transfers. Only callable by an ERC20 pair. * @param token The ERC20 token to transfer * @param from The address to transfer tokens from * @param to The address to transfer tokens to * @param amount The amount of tokens to transfer */ function pairTransferERC20From(ERC20 token, address from, address to, uint256 amount) external { // verify caller is a trusted pair contract require(factory.isValidPair(msg.sender), "Not pair"); // verify caller is an ERC20 pair require(factory.getPairTokenType(msg.sender) == ILSSVMPairFactoryLike.PairTokenType.ERC20, "Not ERC20 pair"); // transfer tokens to pair token.safeTransferFrom(from, to, amount); } /** * @dev Allows a pair contract to transfer ERC721 NFTs directly from * the sender, in order to minimize the number of token transfers. Only callable by a pair. * @param nft The ERC721 NFT to transfer * @param from The address to transfer tokens from * @param to The address to transfer tokens to * @param id The ID of the NFT to transfer */ function pairTransferNFTFrom(IERC721 nft, address from, address to, uint256 id) external { // verify caller is a trusted pair contract require(factory.isValidPair(msg.sender), "Not pair"); // transfer NFTs to pair nft.transferFrom(from, to, id); } function pairTransferERC1155From( IERC1155 nft, address from, address to, uint256[] calldata ids, uint256[] calldata amounts ) external { // verify caller is a trusted pair contract require(factory.isValidPair(msg.sender), "Not pair"); nft.safeBatchTransferFrom(from, to, ids, amounts, bytes("")); } /** * Internal functions */ /** * @param deadline The last valid time for a swap */ function _checkDeadline(uint256 deadline) internal view { require(block.timestamp <= deadline, "Deadline passed"); } /** * @notice Internal function used to swap ETH for a specific set of NFTs * @param swapList The list of pairs and swap calldata * @param inputAmount The total amount of ETH to send * @param ethRecipient The address receiving excess ETH * @param nftRecipient The address receiving the NFTs from the pairs * @return remainingValue The unspent token amount */ function _swapETHForSpecificNFTs( PairSwapSpecific[] calldata swapList, uint256 inputAmount, address payable ethRecipient, address nftRecipient ) internal virtual returns (uint256 remainingValue) { remainingValue = inputAmount; uint256 pairCost; CurveErrorCodes.Error error; // Do swaps uint256 numSwaps = swapList.length; for (uint256 i; i < numSwaps;) { // Calculate the cost per swap first to send exact amount of ETH over, saves gas by avoiding the need to send back excess ETH (error,,, pairCost,,) = swapList[i].pair.getBuyNFTQuote(swapList[i].nftIds[0], swapList[i].nftIds.length); // Require no errors require(error == CurveErrorCodes.Error.OK, "Bonding curve error"); // Total ETH taken from sender cannot exceed inputAmount // because otherwise the deduction from remainingValue will fail remainingValue -= swapList[i].pair.swapTokenForSpecificNFTs{value: pairCost}( swapList[i].nftIds, remainingValue, nftRecipient, true, msg.sender ); unchecked { ++i; } } // Return remaining value to sender if (remainingValue > 0) { ethRecipient.safeTransferETH(remainingValue); } } /** * @notice Internal function used to swap an ERC20 token for specific NFTs * @dev Note that we don't need to query the pair's bonding curve first for pricing data because * we just calculate and take the required amount from the caller during swap time. * However, we can't "pull" ETH, which is why for the ETH->NFT swaps, we need to calculate the pricing info * to figure out how much the router should send to the pool. * @param swapList The list of pairs and swap calldata * @param inputAmount The total amount of ERC20 tokens to send * @param nftRecipient The address receiving the NFTs from the pairs * @return remainingValue The unspent token amount */ function _swapERC20ForSpecificNFTs(PairSwapSpecific[] calldata swapList, uint256 inputAmount, address nftRecipient) internal virtual returns (uint256 remainingValue) { remainingValue = inputAmount; // Do swaps uint256 numSwaps = swapList.length; for (uint256 i; i < numSwaps;) { // Tokens are transferred in by the pair calling router.pairTransferERC20From // Total tokens taken from sender cannot exceed inputAmount // because otherwise the deduction from remainingValue will fail remainingValue -= swapList[i].pair.swapTokenForSpecificNFTs( swapList[i].nftIds, remainingValue, nftRecipient, true, msg.sender ); unchecked { ++i; } } } /** * @notice Swaps NFTs for tokens, designed to be used for 1 token at a time * @dev Calling with multiple tokens is permitted, BUT minOutput will be * far from enough of a safety check because different tokens almost certainly have different unit prices. * @param swapList The list of pairs and swap calldata * @param minOutput The minimum number of tokens to be receieved from the swaps * @param tokenRecipient The address that receives the tokens * @return outputAmount The number of tokens to be received */ function _swapNFTsForToken(PairSwapSpecific[] calldata swapList, uint256 minOutput, address payable tokenRecipient) internal virtual returns (uint256 outputAmount) { // Do swaps uint256 numSwaps = swapList.length; for (uint256 i; i < numSwaps;) { // Do the swap for token and then update outputAmount // Note: minExpectedTokenOutput is set to 0 since we're doing an aggregate slippage check below outputAmount += swapList[i].pair.swapNFTsForToken(swapList[i].nftIds, 0, tokenRecipient, true, msg.sender); unchecked { ++i; } } // Aggregate slippage check require(outputAmount >= minOutput, "outputAmount too low"); } }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.4; interface IOwnershipTransferReceiver { function onOwnershipTransferred(address oldOwner, bytes memory data) external payable; }
// SPDX-License-Identifier: AGPL-3.0 pragma solidity ^0.8.4; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import {IOwnershipTransferReceiver} from "./IOwnershipTransferReceiver.sol"; abstract contract OwnableWithTransferCallback { using ERC165Checker for address; using Address for address; bytes4 constant TRANSFER_CALLBACK = type(IOwnershipTransferReceiver).interfaceId; error Ownable_NotOwner(); error Ownable_NewOwnerZeroAddress(); address private _owner; event OwnershipTransferred(address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ function __Ownable_init(address initialOwner) internal { _owner = initialOwner; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { if (owner() != msg.sender) revert Ownable_NotOwner(); _; } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * @param newOwner The new address to become owner * @param data Any additional data to send to the ownership received callback. * Disallows setting to the zero address as a way to more gas-efficiently avoid reinitialization. * When ownership is transferred, if the new owner implements IOwnershipTransferCallback, we make a callback. * Can only be called by the current owner. */ function transferOwnership(address newOwner, bytes calldata data) public payable virtual onlyOwner { if (newOwner == address(0)) revert Ownable_NewOwnerZeroAddress(); _transferOwnership(newOwner); if (newOwner.isContract()) { try IOwnershipTransferReceiver(newOwner).onOwnershipTransferred{value: msg.value}(msg.sender, data) {} // If revert... catch (bytes memory reason) { // If we just transferred to a contract w/ no callback, this is fine if (reason.length == 0) { // i.e., no need to revert } // Otherwise, the callback had an error, and we should revert else { /// @solidity memory-safe-assembly assembly { revert(add(32, reason), mload(reason)) } } } } } /** * @notice Transfers ownership of the contract to a new account (`newOwner`). * @dev Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { _owner = newOwner; emit OwnershipTransferred(newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol) pragma solidity ^0.8.0; import "../IERC1155Receiver.sol"; import "../../../utils/introspection/ERC165.sol"; /** * @dev _Available since v3.1._ */ abstract contract ERC1155Receiver is ERC165, IERC1155Receiver { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.2) (utils/introspection/ERC165Checker.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Library used to query support of an interface declared via {IERC165}. * * Note that these functions return the actual result of the query: they do not * `revert` if an interface is not supported. It is up to the caller to decide * what to do in these cases. */ library ERC165Checker { // As per the EIP-165 spec, no interface should ever match 0xffffffff bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff; /** * @dev Returns true if `account` supports the {IERC165} interface. */ function supportsERC165(address account) internal view returns (bool) { // Any contract that implements ERC165 must explicitly indicate support of // InterfaceId_ERC165 and explicitly indicate non-support of InterfaceId_Invalid return supportsERC165InterfaceUnchecked(account, type(IERC165).interfaceId) && !supportsERC165InterfaceUnchecked(account, _INTERFACE_ID_INVALID); } /** * @dev Returns true if `account` supports the interface defined by * `interfaceId`. Support for {IERC165} itself is queried automatically. * * See {IERC165-supportsInterface}. */ function supportsInterface(address account, bytes4 interfaceId) internal view returns (bool) { // query support of both ERC165 as per the spec and support of _interfaceId return supportsERC165(account) && supportsERC165InterfaceUnchecked(account, interfaceId); } /** * @dev Returns a boolean array where each value corresponds to the * interfaces passed in and whether they're supported or not. This allows * you to batch check interfaces for a contract where your expectation * is that some interfaces may not be supported. * * See {IERC165-supportsInterface}. * * _Available since v3.4._ */ function getSupportedInterfaces( address account, bytes4[] memory interfaceIds ) internal view returns (bool[] memory) { // an array of booleans corresponding to interfaceIds and whether they're supported or not bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length); // query support of ERC165 itself if (supportsERC165(account)) { // query support of each interface in interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { interfaceIdsSupported[i] = supportsERC165InterfaceUnchecked(account, interfaceIds[i]); } } return interfaceIdsSupported; } /** * @dev Returns true if `account` supports all the interfaces defined in * `interfaceIds`. Support for {IERC165} itself is queried automatically. * * Batch-querying can lead to gas savings by skipping repeated checks for * {IERC165} support. * * See {IERC165-supportsInterface}. */ function supportsAllInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool) { // query support of ERC165 itself if (!supportsERC165(account)) { return false; } // query support of each interface in interfaceIds for (uint256 i = 0; i < interfaceIds.length; i++) { if (!supportsERC165InterfaceUnchecked(account, interfaceIds[i])) { return false; } } // all interfaces supported return true; } /** * @notice Query if a contract implements an interface, does not check ERC165 support * @param account The address of the contract to query for support of an interface * @param interfaceId The interface identifier, as specified in ERC-165 * @return true if the contract at account indicates support of the interface with * identifier interfaceId, false otherwise * @dev Assumes that account contains a contract that supports ERC165, otherwise * the behavior of this method is undefined. This precondition can be checked * with {supportsERC165}. * * Some precompiled contracts will falsely indicate support for a given interface, so caution * should be exercised when using this function. * * Interface identification is specified in ERC-165. */ function supportsERC165InterfaceUnchecked(address account, bytes4 interfaceId) internal view returns (bool) { // prepare call bytes memory encodedParams = abi.encodeWithSelector(IERC165.supportsInterface.selector, interfaceId); // perform static call bool success; uint256 returnSize; uint256 returnValue; assembly { success := staticcall(30000, account, add(encodedParams, 0x20), mload(encodedParams), 0x00, 0x20) returnSize := returndatasize() returnValue := mload(0x00) } return success && returnSize >= 0x20 && returnValue > 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev _Available since v3.1._ */ interface IERC1155Receiver is IERC165 { /** * @dev Handles the receipt of a single ERC1155 token type. This function is * called at the end of a `safeTransferFrom` after the balance has been updated. * * NOTE: To accept the transfer, this must return * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` * (i.e. 0xf23a6e61, or its own function selector). * * @param operator The address which initiated the transfer (i.e. msg.sender) * @param from The address which previously owned the token * @param id The ID of the token being transferred * @param value The amount of tokens being transferred * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4); /** * @dev Handles the receipt of a multiple ERC1155 token types. This function * is called at the end of a `safeBatchTransferFrom` after the balances have * been updated. * * NOTE: To accept the transfer(s), this must return * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` * (i.e. 0xbc197c81, or its own function selector). * * @param operator The address which initiated the batch transfer (i.e. msg.sender) * @param from The address which previously owned the token * @param ids An array containing ids of each token being transferred (order and length must match values array) * @param values An array containing amounts of each token being transferred (order and length must match ids array) * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
{ "remappings": [ "@manifoldxyz/=lib/", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@prb/math/=lib/prb-math/src/", "clones-with-immutable-args/=lib/clones-with-immutable-args/src/", "create3-factory/=lib/create3-factory/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "libraries-solidity/=lib/libraries-solidity/contracts/", "manifoldxyz/=lib/royalty-registry-solidity/contracts/", "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/", "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/", "royalty-registry-solidity/=lib/royalty-registry-solidity/contracts/", "solmate/=lib/solmate/src/" ], "optimizer": { "enabled": true, "runs": 1000000 }, "metadata": { "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract ILSSVMPairFactoryLike","name":"_factory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"VeryFastRouter__BondingCurveQuoteError","type":"error"},{"inputs":[],"name":"VeryFastRouter__InvalidPair","type":"error"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract ILSSVMPairFactoryLike","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract LSSVMPair","name":"pair","type":"address"},{"internalType":"uint256","name":"numNFTs","type":"uint256"},{"internalType":"uint256","name":"slippageScaling","type":"uint256"},{"internalType":"uint256","name":"assetId","type":"uint256"}],"name":"getNFTQuoteForBuyOrderWithPartialFill","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract LSSVMPair","name":"pair","type":"address"},{"internalType":"uint256","name":"numNFTs","type":"uint256"},{"internalType":"uint256","name":"slippageScaling","type":"uint256"},{"internalType":"uint256","name":"nftId","type":"uint256"}],"name":"getNFTQuoteForSellOrderWithPartialFill","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract LSSVMPair","name":"pair","type":"address"}],"name":"getPairBaseQuoteTokenBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC1155","name":"nft","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"pairTransferERC1155From","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"token","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"pairTransferERC20From","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC721","name":"nft","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"pairTransferNFTFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"contract LSSVMPair","name":"pair","type":"address"},{"internalType":"bool","name":"isERC721","type":"bool"},{"internalType":"uint256[]","name":"nftIds","type":"uint256[]"},{"internalType":"uint256","name":"maxInputAmount","type":"uint256"},{"internalType":"uint256","name":"ethAmount","type":"uint256"},{"internalType":"uint256","name":"expectedSpotPrice","type":"uint256"},{"internalType":"uint256[]","name":"maxCostPerNumNFTs","type":"uint256[]"}],"internalType":"struct VeryFastRouter.BuyOrderWithPartialFill[]","name":"buyOrders","type":"tuple[]"},{"components":[{"internalType":"contract LSSVMPair","name":"pair","type":"address"},{"internalType":"bool","name":"isETHSell","type":"bool"},{"internalType":"bool","name":"isERC721","type":"bool"},{"internalType":"uint256[]","name":"nftIds","type":"uint256[]"},{"internalType":"bool","name":"doPropertyCheck","type":"bool"},{"internalType":"bytes","name":"propertyCheckParams","type":"bytes"},{"internalType":"uint128","name":"expectedSpotPrice","type":"uint128"},{"internalType":"uint256","name":"minExpectedOutput","type":"uint256"},{"internalType":"uint256[]","name":"minExpectedOutputPerNumNFTs","type":"uint256[]"}],"internalType":"struct VeryFastRouter.SellOrderWithPartialFill[]","name":"sellOrders","type":"tuple[]"},{"internalType":"address payable","name":"tokenRecipient","type":"address"},{"internalType":"address","name":"nftRecipient","type":"address"},{"internalType":"bool","name":"recycleETH","type":"bool"}],"internalType":"struct VeryFastRouter.Order","name":"swapOrder","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256[]","name":"results","type":"uint256[]"}],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60a06040523480156200001157600080fd5b506040516200413738038062004137833981016040819052620000349162000046565b6001600160a01b031660805262000078565b6000602082840312156200005957600080fd5b81516001600160a01b03811681146200007157600080fd5b9392505050565b608051614072620000c5600039600081816101550152818161050c015281816105c301528181610a4601528181610afd01528181610c1c01528181610cd30152610e4c01526140726000f3fe60806040526004361061007f5760003560e01c8063ac482d1d1161004e578063ac482d1d14610123578063c45a015514610143578063ec72bc651461019c578063fe3f8ecc146101af57600080fd5b8063439288b71461008b5780637b872f9e146100c157806387c27373146100e3578063938e37da1461010357600080fd5b3661008657005b600080fd5b34801561009757600080fd5b506100ab6100a63660046135af565b6101dd565b6040516100b89190613625565b60405180910390f35b3480156100cd57600080fd5b506100e16100dc366004613638565b6104de565b005b3480156100ef57600080fd5b506100ab6100fe3660046135af565b610722565b34801561010f57600080fd5b506100e161011e366004613638565b610a18565b34801561012f57600080fd5b506100e161013e3660046136d5565b610bee565b34801561014f57600080fd5b506101777f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100b8565b6100ab6101aa36600461377d565b610e41565b3480156101bb57600080fd5b506101cf6101ca3660046137b8565b611f8f565b6040519081526020016100b8565b606060008467ffffffffffffffff8111156101fa576101fa6137d5565b604051908082528060200260200182016040528015610223578160200160208202803683370190505b50905060005b858110156104575760008773ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561027e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102a29190613822565b905060008873ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156102f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103159190613822565b9050821561032d576103278984612162565b90925090505b60006103448a848461033f888e61386e565b612534565b6040517fa736946b000000000000000000000000000000000000000000000000000000008152600481018990526024810182905290915060009073ffffffffffffffffffffffffffffffffffffffff8c169063a736946b90604401600060405180830381865afa1580156103bc573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526104029190810190613965565b925050508082610412919061386e565b915081866001610422888e61386e565b61042c919061386e565b8151811061043c5761043c613a33565b60200260200101818152505084600101945050505050610229565b5083156104d55760005b81518110156104d357670de0b6b3a76400008583838151811061048657610486613a33565b60200260200101516104989190613a62565b6104a29190613a79565b8282815181106104b4576104b4613a33565b602002602001018181516104c8919061386e565b905250600101610461565b505b95945050505050565b6040517f9294118c0000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639294118c90602401602060405180830381865afa158015610568573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061058c9190613ac2565b8015610656575060006040517f86aa83600000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906386aa836090602401602060405180830381865afa15801561061f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106439190613b1b565b600181111561065457610654613adf565b145b61068c576040517f960d477a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f23b872dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528381166024830152604482018390528516906323b872dd90606401600060405180830381600087803b15801561070457600080fd5b505af1158015610718573d6000803e3d6000fd5b5050505050505050565b606060008467ffffffffffffffff81111561073f5761073f6137d5565b604051908082528060200260200182016040528015610768578160200160208202803683370190505b50905060005b8581101561099c5760008773ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e79190613822565b905060008873ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610836573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085a9190613822565b905082156108725761086c8984612827565b90925090505b60006108898a8484610884888e61386e565b612901565b6040517fa736946b000000000000000000000000000000000000000000000000000000008152600481018990526024810182905290915060009073ffffffffffffffffffffffffffffffffffffffff8c169063a736946b90604401600060405180830381865afa158015610901573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526109479190810190613965565b9250505080826109579190613b38565b915081866001610967888e61386e565b610971919061386e565b8151811061098157610981613a33565b6020026020010181815250508460010194505050505061076e565b5083156104d55760005b81518110156104d357670de0b6b3a7640000858383815181106109cb576109cb613a33565b60200260200101516109dd9190613a62565b6109e79190613a79565b8282815181106109f9576109f9613a33565b60200260200101818151610a0d9190613b38565b9052506001016109a6565b6040517f9294118c0000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639294118c90602401602060405180830381865afa158015610aa2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac69190613ac2565b8015610b90575060016040517f05070c690000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906305070c6990602401602060405180830381865afa158015610b59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7d9190613b1b565b6001811115610b8e57610b8e613adf565b145b610bc6576040517f960d477a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610be873ffffffffffffffffffffffffffffffffffffffff85168484846129dc565b50505050565b6040517f9294118c0000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639294118c90602401602060405180830381865afa158015610c78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c9c9190613ac2565b8015610d66575060016040517f86aa83600000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906386aa836090602401602060405180830381865afa158015610d2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d539190613b1b565b6001811115610d6457610d64613adf565b145b610d9c576040517f960d477a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516020810182526000815290517f2eb2c2d600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff891691632eb2c2d691610e06918a918a918a918a918a918a9190600401613b96565b600060405180830381600087803b158015610e2057600080fd5b505af1158015610e34573d6000803e3d6000fd5b5050505050505050505050565b6060600034905060007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ed99190613c51565b9050610ee86020850185613c6a565b9050610ef48580613c6a565b610eff929150613b38565b67ffffffffffffffff811115610f1757610f176137d5565b604051908082528060200260200182016040528015610f40578160200160208202803683370190505b50925060005b610f536020860186613c6a565b90508110156117935736610f6a6020870187613c6a565b83818110610f7a57610f7a613a33565b9050602002810190610f8c9190613cd2565b90506000610f9d60208301836137b8565b73ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fe7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061100b9190613822565b9050600061101f60e0840160c08501613d10565b6fffffffffffffffffffffffffffffffff16826fffffffffffffffffffffffffffffffff1603611342576110596040840160208501613d2d565b8015611070575061107060a0890160808a01613d2d565b156111f85761108560a0840160808501613d2d565b156111425761109760208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b12e1db86110bf6060860186613c6a565b60e0870135306001336110d560a08c018c613d4a565b6040518963ffffffff1660e01b81526004016110f8989796959493929190613df8565b6020604051808303816000875af1158015611117573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061113b9190613c51565b90506111e7565b61114f60208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c16111776060860186613c6a565b8660e00135306001336040518763ffffffff1660e01b81526004016111a196959493929190613e61565b6020604051808303816000875af11580156111c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e49190613c51565b90505b6111f18187613b38565b9550611766565b61120860a0840160808501613d2d565b156112d45761121a60208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b12e1db86112426060860186613c6a565b60e087013561125760608e0160408f016137b8565b60013361126760a08c018c613d4a565b6040518963ffffffff1660e01b815260040161128a989796959493929190613df8565b6020604051808303816000875af11580156112a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112cd9190613c51565b9050611766565b6112e160208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c16113096060860186613c6a565b60e087013561131e60608e0160408f016137b8565b6001336040518763ffffffff1660e01b815260040161128a96959493929190613e61565b6000808061135360208701876137b8565b73ffffffffffffffffffffffffffffffffffffffff1663a736946b61137e6060890160408a01613d2d565b6114025761138f60208901896137b8565b73ffffffffffffffffffffffffffffffffffffffff1663c6bc51826040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113fd9190613c51565b611428565b61140f6060890189613c6a565b600081811061142057611420613a33565b905060200201355b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526004810191909152670de0b6b3a76400006024820152604401600060405180830381865afa15801561148a573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526114d09190810190613965565b925061153091506114e6905060208801886137b8565b866114f56101008a018a613c6a565b808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508e9250879150612aa79050565b90935091505081156117635761154c60a0860160808701613d2d565b156116255761155e60208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b12e1db86115866060880188613c6a565b611594918691600091613eb2565b848e60400160208101906115a891906137b8565b6001336115b860a08e018e613d4a565b6040518963ffffffff1660e01b81526004016115db989796959493929190613df8565b6020604051808303816000875af11580156115fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161e9190613c51565b9250611763565b6116356060860160408701613d2d565b156116b55761164760208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c161166f6060880188613c6a565b61167d918691600091613eb2565b848e604001602081019061169191906137b8565b6001336040518763ffffffff1660e01b81526004016115db96959493929190613e61565b6116c260208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c16116e684612e93565b838d60400160208101906116fa91906137b8565b6001336040518663ffffffff1660e01b815260040161171d959493929190613ee0565b6020604051808303816000875af115801561173c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117609190613c51565b92505b50505b8087858151811061177957611779613a33565b602002602001018181525050836001019350505050610f46565b5060005b6117a18580613c6a565b9050811015611f5157366117b58680613c6a565b838181106117c5576117c5613a33565b90506020028101906117d79190613f2f565b905060006117e860208301836137b8565b73ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa158015611832573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118569190613822565b6fffffffffffffffffffffffffffffffff1690508160a00135810361194c5761188260208301836137b8565b73ffffffffffffffffffffffffffffffffffffffff16636d8b99f760808401356118af6040860186613c6a565b86606001358c60600160208101906118c791906137b8565b6001336040518863ffffffff1660e01b81526004016118eb96959493929190613e61565b60206040518083038185885af1158015611909573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061192e9190613c51565b905060808201351561194757611944818661386e565b94505b611f12565b6000808061195d60208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663a736946b6119886040880160208901613d2d565b611a0c5761199960208801886137b8565b73ffffffffffffffffffffffffffffffffffffffff1663c6bc51826040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a079190613c51565b611a32565b611a196040880188613c6a565b6000818110611a2a57611a2a613a33565b905060200201355b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526004810191909152670de0b6b3a76400006024820152604401600060405180830381865afa158015611a94573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052611ada9190810190613965565b9250611b399150611af0905060208701876137b8565b85611afe60c0890189613c6a565b808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508d9250879150612ede9050565b600095509093509150508115611f0f576000608085013515611b585750805b611b686040860160208701613d2d565b15611c7c576000611bc4611b7f60208801886137b8565b85611b8d60408a018a613c6a565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061326192505050565b90508051600014611c7657611bdc60208701876137b8565b73ffffffffffffffffffffffffffffffffffffffff16636d8b99f78383868f6060016020810190611c0d91906137b8565b6001336040518763ffffffff1660e01b8152600401611c30959493929190613ee0565b60206040518083038185885af1158015611c4e573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611c739190613c51565b94505b50611ef6565b6000611c8b60208701876137b8565b73ffffffffffffffffffffffffffffffffffffffff166347ccca026040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cf99190613f63565b73ffffffffffffffffffffffffffffffffffffffff1662fdd58e611d2060208901896137b8565b611d2d60208a018a6137b8565b73ffffffffffffffffffffffffffffffffffffffff1663c6bc51826040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9b9190613c51565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015611e09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e2d9190613c51565b9050808410611e3c5780611e3e565b835b9350508215611ef657611e5460208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff16636d8b99f782611e7986612e93565b858e6060016020810190611e8d91906137b8565b6001336040518763ffffffff1660e01b8152600401611eb0959493929190613ee0565b60206040518083038185885af1158015611ece573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611ef39190613c51565b93505b608085013515611f0d57611f0a848961386e565b97505b505b50505b8086611f2160208a018a613c6a565b611f2c915086613b38565b81518110611f3c57611f3c613a33565b60209081029190910101525050600101611797565b508115611f8857611f8882611f6c60608701604088016137b8565b73ffffffffffffffffffffffffffffffffffffffff1690613510565b5050919050565b6000808273ffffffffffffffffffffffffffffffffffffffff16633053fc586040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fdd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120019190613f80565b9050600081600381111561201757612017613adf565b14806120345750600281600381111561203257612032613adf565b145b15612058578273ffffffffffffffffffffffffffffffffffffffff1631915061215c565b8273ffffffffffffffffffffffffffffffffffffffff1663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c79190613f63565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff858116600483015291909116906370a0823190602401602060405180830381865afa158015612135573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121599190613c51565b91505b50919050565b60008060008473ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121d69190613f63565b73ffffffffffffffffffffffffffffffffffffffff1663097cc63d8673ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561223c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122609190613822565b8773ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122cf9190613822565b878973ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561231b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061233f9190613fa1565b8a73ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa15801561238a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123ae9190613f63565b73ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156123f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061241c9190613c51565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b1681526fffffffffffffffffffffffffffffffff958616600482015294909316602485015260448401919091526bffffffffffffffffffffffff166064830152608482015260a40160c060405180830381865afa1580156124aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124ce9190613fcf565b50929650909450919250600091506124e39050565b8160048111156124f5576124f5613adf565b1461252c576040517f5c5c2a6f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b509250929050565b6000808573ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612582573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125a69190613f63565b73ffffffffffffffffffffffffffffffffffffffff1663097cc63d8686868a73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561260f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126339190613fa1565b8b73ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa15801561267e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a29190613f63565b73ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156126ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127109190613c51565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b1681526fffffffffffffffffffffffffffffffff958616600482015294909316602485015260448401919091526bffffffffffffffffffffffff166064830152608482015260a40160c060405180830381865afa15801561279e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c29190613fcf565b50909550929350600092506127d5915050565b8160048111156127e7576127e7613adf565b1461281e576040517f5c5c2a6f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50949350505050565b60008060008473ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612877573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061289b9190613f63565b73ffffffffffffffffffffffffffffffffffffffff16637ca542ac8673ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561223c573d6000803e3d6000fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561294f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129739190613f63565b73ffffffffffffffffffffffffffffffffffffffff16637ca542ac8686868a73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561260f573d6000803e3d6000fd5b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080612aa0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c454400000000000000000000000060448201526064015b60405180910390fd5b5050505050565b60008060006001905060008651905060008060008b73ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2a9190613822565b90506000612b378d611f8f565b9050806fffffffffffffffffffffffffffffffff166080836fffffffffffffffffffffffffffffffff16901b179350505060008b73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015612bb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bd99190613fa1565b6bffffffffffffffffffffffff16905060008c73ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5a9190613f63565b90508073ffffffffffffffffffffffffffffffffffffffff1660a083901b17925050505b828411612e855760008073ffffffffffffffffffffffffffffffffffffffff831663097cc63d8d608087901c6002612cb68a8c613b38565b612cc09190613a79565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526fffffffffffffffffffffffffffffffff9384166004820152929091166024830152604482015260a086901c6064820152608481018d905260a40160c060405180830381865afa158015612d44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d689190613fcf565b5050935050509150670de0b6b3a76400008982612d859190613a62565b612d8f9190613a79565b612d99908261386e565b90506000826004811115612daf57612daf613adf565b141580612df557508a60016002612dc6888a613b38565b612dd09190613a79565b612dda919061386e565b81518110612dea57612dea613a33565b602002602001015181105b80612e115750836fffffffffffffffffffffffffffffffff1681115b15612e3f5760016002612e248789613b38565b612e2e9190613a79565b612e38919061386e565b9450612e7e565b6002612e4b8688613b38565b612e559190613a79565b97506002612e638688613b38565b612e6d9190613a79565b612e78906001613b38565b95508096505b5050612c7e565b505050509550959350505050565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110612ecd57612ecd613a33565b602090810291909101015292915050565b60008060006001905060008651905060008973ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f5e9190613822565b905060008a73ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612fad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fd19190613f63565b60a08c73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561301e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130429190613fa1565b6bffffffffffffffffffffffff16901b6bffffffffffffffffffffffff161773ffffffffffffffffffffffffffffffffffffffff1690505b828411612e855760008073ffffffffffffffffffffffffffffffffffffffff8316637ca542ac8d8660026130ae8a8c613b38565b6130b89190613a79565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526fffffffffffffffffffffffffffffffff9384166004820152929091166024830152604482015260a086901c6064820152608481018d905260a40160c060405180830381865afa15801561313c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131609190613fcf565b5050935050509150670de0b6b3a7640000898261317d9190613a62565b6131879190613a79565b6131919082613b38565b905060008260048111156131a7576131a7613adf565b1415806131ed57508a600160026131be888a613b38565b6131c89190613a79565b6131d2919061386e565b815181106131e2576131e2613a33565b602002602001015181115b1561321b57600160026132008789613b38565b61320a9190613a79565b613214919061386e565b945061325a565b60026132278688613b38565b6132319190613a79565b9750600261323f8688613b38565b6132499190613a79565b613254906001613b38565b95508096505b505061307a565b606060008473ffffffffffffffffffffffffffffffffffffffff166347ccca026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132d49190613f63565b905060008467ffffffffffffffff8111156132f1576132f16137d5565b60405190808252806020026020018201604052801561331a578160200160208202803683370190505b5090506000805b8681101561343d578773ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16636352211e88848151811061336e5761336e613a33565b60200260200101516040518263ffffffff1660e01b815260040161339491815260200190565b602060405180830381865afa1580156133b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d59190613f63565b73ffffffffffffffffffffffffffffffffffffffff16036134355785818151811061340257613402613a33565b602002602001015183838151811061341c5761341c613a33565b6020908102919091010152613432600183613b38565b91505b600101613321565b5085810361344f575091506135099050565b858110156134f45760008167ffffffffffffffff811115613472576134726137d5565b60405190808252806020026020018201604052801561349b578160200160208202803683370190505b50905060005b828110156134e8578381815181106134bb576134bb613a33565b60200260200101518282815181106134d5576134d5613a33565b60209081029190910101526001016134a1565b50935061350992505050565b50506040805160008152602081019091529150505b9392505050565b600080600080600085875af1905080613585576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4554485f5452414e534645525f4641494c4544000000000000000000000000006044820152606401612a97565b505050565b73ffffffffffffffffffffffffffffffffffffffff811681146135ac57600080fd5b50565b600080600080608085870312156135c557600080fd5b84356135d08161358a565b966020860135965060408601359560600135945092505050565b600081518084526020808501945080840160005b8381101561361a578151875295820195908201906001016135fe565b509495945050505050565b60208152600061350960208301846135ea565b6000806000806080858703121561364e57600080fd5b84356136598161358a565b935060208501356136698161358a565b925060408501356136798161358a565b9396929550929360600135925050565b60008083601f84011261369b57600080fd5b50813567ffffffffffffffff8111156136b357600080fd5b6020830191508360208260051b85010111156136ce57600080fd5b9250929050565b600080600080600080600060a0888a0312156136f057600080fd5b87356136fb8161358a565b9650602088013561370b8161358a565b9550604088013561371b8161358a565b9450606088013567ffffffffffffffff8082111561373857600080fd5b6137448b838c01613689565b909650945060808a013591508082111561375d57600080fd5b5061376a8a828b01613689565b989b979a50959850939692959293505050565b60006020828403121561378f57600080fd5b813567ffffffffffffffff8111156137a657600080fd5b820160a0818503121561350957600080fd5b6000602082840312156137ca57600080fd5b81356135098161358a565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6fffffffffffffffffffffffffffffffff811681146135ac57600080fd5b60006020828403121561383457600080fd5b815161350981613804565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b818103818111156138815761388161383f565b92915050565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156138ce576138ce6137d5565b604052919050565b600067ffffffffffffffff8211156138f0576138f06137d5565b5060051b60200190565b600082601f83011261390b57600080fd5b8151602061392061391b836138d6565b613887565b82815260059290921b8401810191818101908684111561393f57600080fd5b8286015b8481101561395a5780518352918301918301613943565b509695505050505050565b60008060006060848603121561397a57600080fd5b835167ffffffffffffffff8082111561399257600080fd5b818601915086601f8301126139a657600080fd5b815160206139b661391b836138d6565b82815260059290921b8401810191818101908a8411156139d557600080fd5b948201945b838610156139fc5785516139ed8161358a565b825294820194908201906139da565b91890151919750909350505080821115613a1557600080fd5b50613a22868287016138fa565b925050604084015190509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80820281158282048414176138815761388161383f565b600082613aaf577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b80151581146135ac57600080fd5b600060208284031215613ad457600080fd5b815161350981613ab4565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600281106135ac57600080fd5b600060208284031215613b2d57600080fd5b815161350981613b0e565b808201808211156138815761388161383f565b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115613b7d57600080fd5b8260051b80836020870137939093016020019392505050565b600073ffffffffffffffffffffffffffffffffffffffff808a1683526020818a168185015260a06040850152613bd060a08501898b613b4b565b91508382036060850152613be5828789613b4b565b91508382036080850152845180835260005b81811015613c12578681018301518482018401528201613bf7565b506000838201830152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909101019998505050505050505050565b600060208284031215613c6357600080fd5b5051919050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112613c9f57600080fd5b83018035915067ffffffffffffffff821115613cba57600080fd5b6020019150600581901b36038213156136ce57600080fd5b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee1833603018112613d0657600080fd5b9190910192915050565b600060208284031215613d2257600080fd5b813561350981613804565b600060208284031215613d3f57600080fd5b813561350981613ab4565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112613d7f57600080fd5b83018035915067ffffffffffffffff821115613d9a57600080fd5b6020019150368190038213156136ce57600080fd5b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60c081526000613e0c60c083018a8c613b4b565b6020830189905273ffffffffffffffffffffffffffffffffffffffff888116604085015287151560608501528616608084015282810360a0840152613e52818587613daf565b9b9a5050505050505050505050565b60a081526000613e7560a08301888a613b4b565b60208301969096525073ffffffffffffffffffffffffffffffffffffffff9384166040820152911515606083015290911660809091015292915050565b60008085851115613ec257600080fd5b83861115613ecf57600080fd5b5050600583901b0193919092039150565b60a081526000613ef360a08301886135ea565b60208301969096525073ffffffffffffffffffffffffffffffffffffffff93841660408201529115156060830152909116608090910152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff21833603018112613d0657600080fd5b600060208284031215613f7557600080fd5b81516135098161358a565b600060208284031215613f9257600080fd5b81516004811061350957600080fd5b600060208284031215613fb357600080fd5b81516bffffffffffffffffffffffff8116811461350957600080fd5b60008060008060008060c08789031215613fe857600080fd5b865160058110613ff757600080fd5b602088015190965061400881613804565b604088015190955061401981613804565b80945050606087015192506080870151915060a08701519050929550929550929556fea264697066735822122040fd0a564444bbe0072a3fdc2cf2a2316e6c30405d74771426670ae8ceda99d164736f6c63430008140033000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc86000
Deployed Bytecode
0x60806040526004361061007f5760003560e01c8063ac482d1d1161004e578063ac482d1d14610123578063c45a015514610143578063ec72bc651461019c578063fe3f8ecc146101af57600080fd5b8063439288b71461008b5780637b872f9e146100c157806387c27373146100e3578063938e37da1461010357600080fd5b3661008657005b600080fd5b34801561009757600080fd5b506100ab6100a63660046135af565b6101dd565b6040516100b89190613625565b60405180910390f35b3480156100cd57600080fd5b506100e16100dc366004613638565b6104de565b005b3480156100ef57600080fd5b506100ab6100fe3660046135af565b610722565b34801561010f57600080fd5b506100e161011e366004613638565b610a18565b34801561012f57600080fd5b506100e161013e3660046136d5565b610bee565b34801561014f57600080fd5b506101777f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100b8565b6100ab6101aa36600461377d565b610e41565b3480156101bb57600080fd5b506101cf6101ca3660046137b8565b611f8f565b6040519081526020016100b8565b606060008467ffffffffffffffff8111156101fa576101fa6137d5565b604051908082528060200260200182016040528015610223578160200160208202803683370190505b50905060005b858110156104575760008773ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561027e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102a29190613822565b905060008873ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156102f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103159190613822565b9050821561032d576103278984612162565b90925090505b60006103448a848461033f888e61386e565b612534565b6040517fa736946b000000000000000000000000000000000000000000000000000000008152600481018990526024810182905290915060009073ffffffffffffffffffffffffffffffffffffffff8c169063a736946b90604401600060405180830381865afa1580156103bc573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526104029190810190613965565b925050508082610412919061386e565b915081866001610422888e61386e565b61042c919061386e565b8151811061043c5761043c613a33565b60200260200101818152505084600101945050505050610229565b5083156104d55760005b81518110156104d357670de0b6b3a76400008583838151811061048657610486613a33565b60200260200101516104989190613a62565b6104a29190613a79565b8282815181106104b4576104b4613a33565b602002602001018181516104c8919061386e565b905250600101610461565b505b95945050505050565b6040517f9294118c0000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff1690639294118c90602401602060405180830381865afa158015610568573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061058c9190613ac2565b8015610656575060006040517f86aa83600000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff16906386aa836090602401602060405180830381865afa15801561061f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106439190613b1b565b600181111561065457610654613adf565b145b61068c576040517f960d477a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f23b872dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528381166024830152604482018390528516906323b872dd90606401600060405180830381600087803b15801561070457600080fd5b505af1158015610718573d6000803e3d6000fd5b5050505050505050565b606060008467ffffffffffffffff81111561073f5761073f6137d5565b604051908082528060200260200182016040528015610768578160200160208202803683370190505b50905060005b8581101561099c5760008773ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156107c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107e79190613822565b905060008873ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610836573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061085a9190613822565b905082156108725761086c8984612827565b90925090505b60006108898a8484610884888e61386e565b612901565b6040517fa736946b000000000000000000000000000000000000000000000000000000008152600481018990526024810182905290915060009073ffffffffffffffffffffffffffffffffffffffff8c169063a736946b90604401600060405180830381865afa158015610901573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526109479190810190613965565b9250505080826109579190613b38565b915081866001610967888e61386e565b610971919061386e565b8151811061098157610981613a33565b6020026020010181815250508460010194505050505061076e565b5083156104d55760005b81518110156104d357670de0b6b3a7640000858383815181106109cb576109cb613a33565b60200260200101516109dd9190613a62565b6109e79190613a79565b8282815181106109f9576109f9613a33565b60200260200101818151610a0d9190613b38565b9052506001016109a6565b6040517f9294118c0000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff1690639294118c90602401602060405180830381865afa158015610aa2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac69190613ac2565b8015610b90575060016040517f05070c690000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff16906305070c6990602401602060405180830381865afa158015610b59573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7d9190613b1b565b6001811115610b8e57610b8e613adf565b145b610bc6576040517f960d477a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610be873ffffffffffffffffffffffffffffffffffffffff85168484846129dc565b50505050565b6040517f9294118c0000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff1690639294118c90602401602060405180830381865afa158015610c78573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c9c9190613ac2565b8015610d66575060016040517f86aa83600000000000000000000000000000000000000000000000000000000081523360048201527f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff16906386aa836090602401602060405180830381865afa158015610d2f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d539190613b1b565b6001811115610d6457610d64613adf565b145b610d9c576040517f960d477a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516020810182526000815290517f2eb2c2d600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff891691632eb2c2d691610e06918a918a918a918a918a918a9190600401613b96565b600060405180830381600087803b158015610e2057600080fd5b505af1158015610e34573d6000803e3d6000fd5b5050505050505050505050565b6060600034905060007f000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc8600073ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ed99190613c51565b9050610ee86020850185613c6a565b9050610ef48580613c6a565b610eff929150613b38565b67ffffffffffffffff811115610f1757610f176137d5565b604051908082528060200260200182016040528015610f40578160200160208202803683370190505b50925060005b610f536020860186613c6a565b90508110156117935736610f6a6020870187613c6a565b83818110610f7a57610f7a613a33565b9050602002810190610f8c9190613cd2565b90506000610f9d60208301836137b8565b73ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610fe7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061100b9190613822565b9050600061101f60e0840160c08501613d10565b6fffffffffffffffffffffffffffffffff16826fffffffffffffffffffffffffffffffff1603611342576110596040840160208501613d2d565b8015611070575061107060a0890160808a01613d2d565b156111f85761108560a0840160808501613d2d565b156111425761109760208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b12e1db86110bf6060860186613c6a565b60e0870135306001336110d560a08c018c613d4a565b6040518963ffffffff1660e01b81526004016110f8989796959493929190613df8565b6020604051808303816000875af1158015611117573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061113b9190613c51565b90506111e7565b61114f60208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c16111776060860186613c6a565b8660e00135306001336040518763ffffffff1660e01b81526004016111a196959493929190613e61565b6020604051808303816000875af11580156111c0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111e49190613c51565b90505b6111f18187613b38565b9550611766565b61120860a0840160808501613d2d565b156112d45761121a60208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b12e1db86112426060860186613c6a565b60e087013561125760608e0160408f016137b8565b60013361126760a08c018c613d4a565b6040518963ffffffff1660e01b815260040161128a989796959493929190613df8565b6020604051808303816000875af11580156112a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112cd9190613c51565b9050611766565b6112e160208401846137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c16113096060860186613c6a565b60e087013561131e60608e0160408f016137b8565b6001336040518763ffffffff1660e01b815260040161128a96959493929190613e61565b6000808061135360208701876137b8565b73ffffffffffffffffffffffffffffffffffffffff1663a736946b61137e6060890160408a01613d2d565b6114025761138f60208901896137b8565b73ffffffffffffffffffffffffffffffffffffffff1663c6bc51826040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113fd9190613c51565b611428565b61140f6060890189613c6a565b600081811061142057611420613a33565b905060200201355b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526004810191909152670de0b6b3a76400006024820152604401600060405180830381865afa15801561148a573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682016040526114d09190810190613965565b925061153091506114e6905060208801886137b8565b866114f56101008a018a613c6a565b808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508e9250879150612aa79050565b90935091505081156117635761154c60a0860160808701613d2d565b156116255761155e60208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b12e1db86115866060880188613c6a565b611594918691600091613eb2565b848e60400160208101906115a891906137b8565b6001336115b860a08e018e613d4a565b6040518963ffffffff1660e01b81526004016115db989796959493929190613df8565b6020604051808303816000875af11580156115fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161e9190613c51565b9250611763565b6116356060860160408701613d2d565b156116b55761164760208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c161166f6060880188613c6a565b61167d918691600091613eb2565b848e604001602081019061169191906137b8565b6001336040518763ffffffff1660e01b81526004016115db96959493929190613e61565b6116c260208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663b1d3f1c16116e684612e93565b838d60400160208101906116fa91906137b8565b6001336040518663ffffffff1660e01b815260040161171d959493929190613ee0565b6020604051808303816000875af115801561173c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117609190613c51565b92505b50505b8087858151811061177957611779613a33565b602002602001018181525050836001019350505050610f46565b5060005b6117a18580613c6a565b9050811015611f5157366117b58680613c6a565b838181106117c5576117c5613a33565b90506020028101906117d79190613f2f565b905060006117e860208301836137b8565b73ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa158015611832573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118569190613822565b6fffffffffffffffffffffffffffffffff1690508160a00135810361194c5761188260208301836137b8565b73ffffffffffffffffffffffffffffffffffffffff16636d8b99f760808401356118af6040860186613c6a565b86606001358c60600160208101906118c791906137b8565b6001336040518863ffffffff1660e01b81526004016118eb96959493929190613e61565b60206040518083038185885af1158015611909573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061192e9190613c51565b905060808201351561194757611944818661386e565b94505b611f12565b6000808061195d60208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff1663a736946b6119886040880160208901613d2d565b611a0c5761199960208801886137b8565b73ffffffffffffffffffffffffffffffffffffffff1663c6bc51826040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119e3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a079190613c51565b611a32565b611a196040880188613c6a565b6000818110611a2a57611a2a613a33565b905060200201355b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526004810191909152670de0b6b3a76400006024820152604401600060405180830381865afa158015611a94573d6000803e3d6000fd5b505050506040513d6000823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052611ada9190810190613965565b9250611b399150611af0905060208701876137b8565b85611afe60c0890189613c6a565b808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508d9250879150612ede9050565b600095509093509150508115611f0f576000608085013515611b585750805b611b686040860160208701613d2d565b15611c7c576000611bc4611b7f60208801886137b8565b85611b8d60408a018a613c6a565b8080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061326192505050565b90508051600014611c7657611bdc60208701876137b8565b73ffffffffffffffffffffffffffffffffffffffff16636d8b99f78383868f6060016020810190611c0d91906137b8565b6001336040518763ffffffff1660e01b8152600401611c30959493929190613ee0565b60206040518083038185885af1158015611c4e573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611c739190613c51565b94505b50611ef6565b6000611c8b60208701876137b8565b73ffffffffffffffffffffffffffffffffffffffff166347ccca026040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cd5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cf99190613f63565b73ffffffffffffffffffffffffffffffffffffffff1662fdd58e611d2060208901896137b8565b611d2d60208a018a6137b8565b73ffffffffffffffffffffffffffffffffffffffff1663c6bc51826040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d77573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9b9190613c51565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e085901b16815273ffffffffffffffffffffffffffffffffffffffff90921660048301526024820152604401602060405180830381865afa158015611e09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e2d9190613c51565b9050808410611e3c5780611e3e565b835b9350508215611ef657611e5460208601866137b8565b73ffffffffffffffffffffffffffffffffffffffff16636d8b99f782611e7986612e93565b858e6060016020810190611e8d91906137b8565b6001336040518763ffffffff1660e01b8152600401611eb0959493929190613ee0565b60206040518083038185885af1158015611ece573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190611ef39190613c51565b93505b608085013515611f0d57611f0a848961386e565b97505b505b50505b8086611f2160208a018a613c6a565b611f2c915086613b38565b81518110611f3c57611f3c613a33565b60209081029190910101525050600101611797565b508115611f8857611f8882611f6c60608701604088016137b8565b73ffffffffffffffffffffffffffffffffffffffff1690613510565b5050919050565b6000808273ffffffffffffffffffffffffffffffffffffffff16633053fc586040518163ffffffff1660e01b8152600401602060405180830381865afa158015611fdd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120019190613f80565b9050600081600381111561201757612017613adf565b14806120345750600281600381111561203257612032613adf565b145b15612058578273ffffffffffffffffffffffffffffffffffffffff1631915061215c565b8273ffffffffffffffffffffffffffffffffffffffff1663fc0c546a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120c79190613f63565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff858116600483015291909116906370a0823190602401602060405180830381865afa158015612135573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121599190613c51565b91505b50919050565b60008060008473ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156121b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121d69190613f63565b73ffffffffffffffffffffffffffffffffffffffff1663097cc63d8673ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561223c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122609190613822565b8773ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122cf9190613822565b878973ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561231b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061233f9190613fa1565b8a73ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa15801561238a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123ae9190613f63565b73ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156123f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061241c9190613c51565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b1681526fffffffffffffffffffffffffffffffff958616600482015294909316602485015260448401919091526bffffffffffffffffffffffff166064830152608482015260a40160c060405180830381865afa1580156124aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124ce9190613fcf565b50929650909450919250600091506124e39050565b8160048111156124f5576124f5613adf565b1461252c576040517f5c5c2a6f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b509250929050565b6000808573ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612582573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125a69190613f63565b73ffffffffffffffffffffffffffffffffffffffff1663097cc63d8686868a73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561260f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126339190613fa1565b8b73ffffffffffffffffffffffffffffffffffffffff1663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa15801561267e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126a29190613f63565b73ffffffffffffffffffffffffffffffffffffffff16631ce4c78b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156126ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127109190613c51565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e088901b1681526fffffffffffffffffffffffffffffffff958616600482015294909316602485015260448401919091526bffffffffffffffffffffffff166064830152608482015260a40160c060405180830381865afa15801561279e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127c29190613fcf565b50909550929350600092506127d5915050565b8160048111156127e7576127e7613adf565b1461281e576040517f5c5c2a6f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50949350505050565b60008060008473ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612877573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061289b9190613f63565b73ffffffffffffffffffffffffffffffffffffffff16637ca542ac8673ffffffffffffffffffffffffffffffffffffffff1663398482d86040518163ffffffff1660e01b8152600401602060405180830381865afa15801561223c573d6000803e3d6000fd5b6000808573ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561294f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129739190613f63565b73ffffffffffffffffffffffffffffffffffffffff16637ca542ac8686868a73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561260f573d6000803e3d6000fd5b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080612aa0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c454400000000000000000000000060448201526064015b60405180910390fd5b5050505050565b60008060006001905060008651905060008060008b73ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b2a9190613822565b90506000612b378d611f8f565b9050806fffffffffffffffffffffffffffffffff166080836fffffffffffffffffffffffffffffffff16901b179350505060008b73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015612bb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bd99190613fa1565b6bffffffffffffffffffffffff16905060008c73ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5a9190613f63565b90508073ffffffffffffffffffffffffffffffffffffffff1660a083901b17925050505b828411612e855760008073ffffffffffffffffffffffffffffffffffffffff831663097cc63d8d608087901c6002612cb68a8c613b38565b612cc09190613a79565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526fffffffffffffffffffffffffffffffff9384166004820152929091166024830152604482015260a086901c6064820152608481018d905260a40160c060405180830381865afa158015612d44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d689190613fcf565b5050935050509150670de0b6b3a76400008982612d859190613a62565b612d8f9190613a79565b612d99908261386e565b90506000826004811115612daf57612daf613adf565b141580612df557508a60016002612dc6888a613b38565b612dd09190613a79565b612dda919061386e565b81518110612dea57612dea613a33565b602002602001015181105b80612e115750836fffffffffffffffffffffffffffffffff1681115b15612e3f5760016002612e248789613b38565b612e2e9190613a79565b612e38919061386e565b9450612e7e565b6002612e4b8688613b38565b612e559190613a79565b97506002612e638688613b38565b612e6d9190613a79565b612e78906001613b38565b95508096505b5050612c7e565b505050509550959350505050565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110612ecd57612ecd613a33565b602090810291909101015292915050565b60008060006001905060008651905060008973ffffffffffffffffffffffffffffffffffffffff166312b495a86040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f5e9190613822565b905060008a73ffffffffffffffffffffffffffffffffffffffff1663eff1d50e6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612fad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fd19190613f63565b60a08c73ffffffffffffffffffffffffffffffffffffffff1663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa15801561301e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130429190613fa1565b6bffffffffffffffffffffffff16901b6bffffffffffffffffffffffff161773ffffffffffffffffffffffffffffffffffffffff1690505b828411612e855760008073ffffffffffffffffffffffffffffffffffffffff8316637ca542ac8d8660026130ae8a8c613b38565b6130b89190613a79565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b1681526fffffffffffffffffffffffffffffffff9384166004820152929091166024830152604482015260a086901c6064820152608481018d905260a40160c060405180830381865afa15801561313c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131609190613fcf565b5050935050509150670de0b6b3a7640000898261317d9190613a62565b6131879190613a79565b6131919082613b38565b905060008260048111156131a7576131a7613adf565b1415806131ed57508a600160026131be888a613b38565b6131c89190613a79565b6131d2919061386e565b815181106131e2576131e2613a33565b602002602001015181115b1561321b57600160026132008789613b38565b61320a9190613a79565b613214919061386e565b945061325a565b60026132278688613b38565b6132319190613a79565b9750600261323f8688613b38565b6132499190613a79565b613254906001613b38565b95508096505b505061307a565b606060008473ffffffffffffffffffffffffffffffffffffffff166347ccca026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132d49190613f63565b905060008467ffffffffffffffff8111156132f1576132f16137d5565b60405190808252806020026020018201604052801561331a578160200160208202803683370190505b5090506000805b8681101561343d578773ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16636352211e88848151811061336e5761336e613a33565b60200260200101516040518263ffffffff1660e01b815260040161339491815260200190565b602060405180830381865afa1580156133b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d59190613f63565b73ffffffffffffffffffffffffffffffffffffffff16036134355785818151811061340257613402613a33565b602002602001015183838151811061341c5761341c613a33565b6020908102919091010152613432600183613b38565b91505b600101613321565b5085810361344f575091506135099050565b858110156134f45760008167ffffffffffffffff811115613472576134726137d5565b60405190808252806020026020018201604052801561349b578160200160208202803683370190505b50905060005b828110156134e8578381815181106134bb576134bb613a33565b60200260200101518282815181106134d5576134d5613a33565b60209081029190910101526001016134a1565b50935061350992505050565b50506040805160008152602081019091529150505b9392505050565b600080600080600085875af1905080613585576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4554485f5452414e534645525f4641494c4544000000000000000000000000006044820152606401612a97565b505050565b73ffffffffffffffffffffffffffffffffffffffff811681146135ac57600080fd5b50565b600080600080608085870312156135c557600080fd5b84356135d08161358a565b966020860135965060408601359560600135945092505050565b600081518084526020808501945080840160005b8381101561361a578151875295820195908201906001016135fe565b509495945050505050565b60208152600061350960208301846135ea565b6000806000806080858703121561364e57600080fd5b84356136598161358a565b935060208501356136698161358a565b925060408501356136798161358a565b9396929550929360600135925050565b60008083601f84011261369b57600080fd5b50813567ffffffffffffffff8111156136b357600080fd5b6020830191508360208260051b85010111156136ce57600080fd5b9250929050565b600080600080600080600060a0888a0312156136f057600080fd5b87356136fb8161358a565b9650602088013561370b8161358a565b9550604088013561371b8161358a565b9450606088013567ffffffffffffffff8082111561373857600080fd5b6137448b838c01613689565b909650945060808a013591508082111561375d57600080fd5b5061376a8a828b01613689565b989b979a50959850939692959293505050565b60006020828403121561378f57600080fd5b813567ffffffffffffffff8111156137a657600080fd5b820160a0818503121561350957600080fd5b6000602082840312156137ca57600080fd5b81356135098161358a565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6fffffffffffffffffffffffffffffffff811681146135ac57600080fd5b60006020828403121561383457600080fd5b815161350981613804565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b818103818111156138815761388161383f565b92915050565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff811182821017156138ce576138ce6137d5565b604052919050565b600067ffffffffffffffff8211156138f0576138f06137d5565b5060051b60200190565b600082601f83011261390b57600080fd5b8151602061392061391b836138d6565b613887565b82815260059290921b8401810191818101908684111561393f57600080fd5b8286015b8481101561395a5780518352918301918301613943565b509695505050505050565b60008060006060848603121561397a57600080fd5b835167ffffffffffffffff8082111561399257600080fd5b818601915086601f8301126139a657600080fd5b815160206139b661391b836138d6565b82815260059290921b8401810191818101908a8411156139d557600080fd5b948201945b838610156139fc5785516139ed8161358a565b825294820194908201906139da565b91890151919750909350505080821115613a1557600080fd5b50613a22868287016138fa565b925050604084015190509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80820281158282048414176138815761388161383f565b600082613aaf577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b80151581146135ac57600080fd5b600060208284031215613ad457600080fd5b815161350981613ab4565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b600281106135ac57600080fd5b600060208284031215613b2d57600080fd5b815161350981613b0e565b808201808211156138815761388161383f565b81835260007f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115613b7d57600080fd5b8260051b80836020870137939093016020019392505050565b600073ffffffffffffffffffffffffffffffffffffffff808a1683526020818a168185015260a06040850152613bd060a08501898b613b4b565b91508382036060850152613be5828789613b4b565b91508382036080850152845180835260005b81811015613c12578681018301518482018401528201613bf7565b506000838201830152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016909101019998505050505050505050565b600060208284031215613c6357600080fd5b5051919050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112613c9f57600080fd5b83018035915067ffffffffffffffff821115613cba57600080fd5b6020019150600581901b36038213156136ce57600080fd5b600082357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffee1833603018112613d0657600080fd5b9190910192915050565b600060208284031215613d2257600080fd5b813561350981613804565b600060208284031215613d3f57600080fd5b813561350981613ab4565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112613d7f57600080fd5b83018035915067ffffffffffffffff821115613d9a57600080fd5b6020019150368190038213156136ce57600080fd5b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60c081526000613e0c60c083018a8c613b4b565b6020830189905273ffffffffffffffffffffffffffffffffffffffff888116604085015287151560608501528616608084015282810360a0840152613e52818587613daf565b9b9a5050505050505050505050565b60a081526000613e7560a08301888a613b4b565b60208301969096525073ffffffffffffffffffffffffffffffffffffffff9384166040820152911515606083015290911660809091015292915050565b60008085851115613ec257600080fd5b83861115613ecf57600080fd5b5050600583901b0193919092039150565b60a081526000613ef360a08301886135ea565b60208301969096525073ffffffffffffffffffffffffffffffffffffffff93841660408201529115156060830152909116608090910152919050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff21833603018112613d0657600080fd5b600060208284031215613f7557600080fd5b81516135098161358a565b600060208284031215613f9257600080fd5b81516004811061350957600080fd5b600060208284031215613fb357600080fd5b81516bffffffffffffffffffffffff8116811461350957600080fd5b60008060008060008060c08789031215613fe857600080fd5b865160058110613ff757600080fd5b602088015190965061400881613804565b604088015190955061401981613804565b80945050606087015192506080870151915060a08701519050929550929550929556fea264697066735822122040fd0a564444bbe0072a3fdc2cf2a2316e6c30405d74771426670ae8ceda99d164736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc86000
-----Decoded View---------------
Arg [0] : _factory (address): 0xA020d57aB0448Ef74115c112D18a9C231CC86000
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000a020d57ab0448ef74115c112d18a9c231cc86000
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ 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.