ERC-20
Overview
Max Total Supply
0.19111872717863469 PUL-LP
Holders
184
Market
Onchain Market Cap
$0.00
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
0.000378328394097383 PUL-LPValue
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
Pair
Compiler Version
v0.8.9+commit.e5eed63a
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later // Inspired by https://www.paradigm.xyz/2021/07/twamm // https://github.com/para-dave/twamm // FrankieIsLost MVP code implementation: https://github.com/FrankieIsLost/TWAMM pragma solidity ^0.8.9; import "./interfaces/IPair.sol"; import "./interfaces/IFactory.sol"; import "./libraries/LongTermOrders.sol"; import "./libraries/BinarySearchTree.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@rari-capital/solmate/src/utils/ReentrancyGuard.sol"; import "prb-math/contracts/PRBMathUD60x18.sol"; contract Pair is IPair, ERC20, ReentrancyGuard { using LongTermOrdersLib for LongTermOrdersLib.LongTermOrders; using BinarySearchTreeLib for BinarySearchTreeLib.Tree; using SafeERC20 for IERC20; using PRBMathUD60x18 for uint256; address public override factory; address public override tokenA; address public override tokenB; address private twamm; uint256 public override rootKLast; ///@notice fee for LP providers, 4 decimal places, i.e. 30 = 0.3% uint256 public constant LP_FEE = 30; ///@notice interval between blocks that are eligible for order expiry uint256 public constant orderBlockInterval = 5; ///@notice map token addresses to current amm reserves mapping(address => uint256) public override reserveMap; ///@notice data structure to handle long term orders LongTermOrdersLib.LongTermOrders internal longTermOrders; constructor( address _tokenA, address _tokenB, address _twamm ) ERC20("Pulsar-LP", "PUL-LP") { factory = msg.sender; tokenA = _tokenA; tokenB = _tokenB; twamm = _twamm; longTermOrders.initialize( tokenA, tokenB, twamm, block.number, orderBlockInterval ); } ///@notice pair contract caller check modifier checkCaller() { require(msg.sender == twamm, "Invalid Caller"); _; } ///@notice get tokenA reserves function tokenAReserves() public view override returns (uint256) { return reserveMap[tokenA]; } ///@notice get tokenB reserves function tokenBReserves() public view override returns (uint256) { return reserveMap[tokenB]; } ///@notice get LP total supply function getTotalSupply() public view override returns (uint256) { return totalSupply(); } // if fee is on, mint liquidity equivalent to 1/(feeArg+1)th of the growth in sqrt(k) function mintFee( uint256 reserveA, uint256 reserveB ) private returns (bool feeOn) { uint32 feeArg = IFactory(factory).feeArg(); address feeTo = IFactory(factory).feeTo(); feeOn = feeTo != address(0); if (feeOn) { if (rootKLast != 0) { uint256 rootK = reserveA .fromUint() .sqrt() .mul(reserveB.fromUint().sqrt()) .toUint(); if (rootK > rootKLast) { uint256 numerator = totalSupply() * (rootK - rootKLast); uint256 denominator = rootK * feeArg + rootKLast; uint256 liquidity = numerator / denominator; if (liquidity > 0) _mint(feeTo, liquidity); } } } else if (rootKLast != 0) { rootKLast = 0; } } ///@notice provide initial liquidity to the amm. This sets the relative price between tokens function provideInitialLiquidity( address to, uint256 amountA, uint256 amountB ) external override checkCaller nonReentrant returns (uint256 lpTokenAmount) { require(amountA > 0 && amountB > 0, "Invalid Amount"); require(totalSupply() == 0, "Liquidity Has Already Been Provided"); reserveMap[tokenA] = amountA; reserveMap[tokenB] = amountB; //initial LP amount is the geometric mean of supplied tokens lpTokenAmount = amountA .fromUint() .sqrt() .mul(amountB.fromUint().sqrt()) .toUint(); bool feeOn = mintFee(0, 0); _mint(to, lpTokenAmount); if (feeOn) rootKLast = lpTokenAmount; emit InitialLiquidityProvided(to, lpTokenAmount, amountA, amountB); } ///@notice provide liquidity to the AMM ///@param lpTokenAmount number of lp tokens to mint with new liquidity function provideLiquidity( address to, uint256 lpTokenAmount ) external override checkCaller nonReentrant returns (uint256 amountAIn, uint256 amountBIn) { //execute virtual orders longTermOrders.executeVirtualOrdersUntilSpecifiedBlock( reserveMap, block.number ); require(lpTokenAmount > 0, "Invalid Amount"); require(totalSupply() != 0, "No Liquidity Has Been Provided Yet"); uint256 reserveA = reserveMap[tokenA]; uint256 reserveB = reserveMap[tokenB]; //the ratio between the number of underlying tokens and the number of lp tokens must remain invariant after mint amountAIn = (lpTokenAmount * reserveA) / totalSupply(); amountBIn = (lpTokenAmount * reserveB) / totalSupply(); reserveMap[tokenA] += amountAIn; reserveMap[tokenB] += amountBIn; bool feeOn = mintFee(reserveA, reserveB); _mint(to, lpTokenAmount); if (feeOn) rootKLast = reserveMap[tokenA] .fromUint() .sqrt() .mul(reserveMap[tokenB].fromUint().sqrt()) .toUint(); emit LiquidityProvided(to, lpTokenAmount, amountAIn, amountBIn); } ///@notice remove liquidity to the AMM ///@param lpTokenAmount number of lp tokens to burn function removeLiquidity( address to, uint256 lpTokenAmount ) external override checkCaller nonReentrant returns (uint256 amountAOut, uint256 amountBOut) { //execute virtual orders longTermOrders.executeVirtualOrdersUntilSpecifiedBlock( reserveMap, block.number ); require(lpTokenAmount > 0, "Invalid Amount"); require( lpTokenAmount <= totalSupply(), "Not Enough Lp Tokens Available" ); uint256 reserveA = reserveMap[tokenA]; uint256 reserveB = reserveMap[tokenB]; //the ratio between the number of underlying tokens and the number of lp tokens must remain invariant after burn amountAOut = (reserveA * lpTokenAmount) / totalSupply(); amountBOut = (reserveB * lpTokenAmount) / totalSupply(); reserveMap[tokenA] -= amountAOut; reserveMap[tokenB] -= amountBOut; bool feeOn = mintFee(reserveA, reserveB); _burn(to, lpTokenAmount); IERC20(tokenA).safeTransfer(twamm, amountAOut); IERC20(tokenB).safeTransfer(twamm, amountBOut); if (feeOn) rootKLast = reserveMap[tokenA] .fromUint() .sqrt() .mul(reserveMap[tokenB].fromUint().sqrt()) .toUint(); emit LiquidityRemoved(to, lpTokenAmount, amountAOut, amountBOut); } ///@notice instant swap a given amount of tokenA against embedded amm function instantSwapFromAToB( address sender, uint256 amountAIn ) external override checkCaller nonReentrant returns (uint256 amountBOut) { require( reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0, "Insufficient Liquidity" ); require(amountAIn > 0, "Invalid Amount"); amountBOut = performInstantSwap(tokenA, tokenB, amountAIn); emit InstantSwapAToB(sender, amountAIn, amountBOut); } ///@notice create a long term order to swap from tokenA ///@param amountAIn total amount of token A to swap ///@param numberOfBlockIntervals number of block intervals over which to execute long term order function longTermSwapFromAToB( address sender, uint256 amountAIn, uint256 numberOfBlockIntervals ) external override checkCaller nonReentrant returns (uint256 orderId) { require( reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0, "Insufficient Liquidity" ); require(amountAIn > 0, "Invalid Amount"); orderId = longTermOrders.longTermSwapFromAToB( sender, amountAIn, numberOfBlockIntervals, reserveMap ); emit LongTermSwapAToB(sender, amountAIn, orderId); } ///@notice instant swap a given amount of tokenB against embedded amm function instantSwapFromBToA( address sender, uint256 amountBIn ) external override checkCaller nonReentrant returns (uint256 amountAOut) { require( reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0, "Insufficient Liquidity" ); require(amountBIn > 0, "Invalid Amount"); amountAOut = performInstantSwap(tokenB, tokenA, amountBIn); emit InstantSwapBToA(sender, amountBIn, amountAOut); } ///@notice create a long term order to swap from tokenB ///@param amountBIn total amount of tokenB to swap ///@param numberOfBlockIntervals number of block intervals over which to execute long term order function longTermSwapFromBToA( address sender, uint256 amountBIn, uint256 numberOfBlockIntervals ) external override checkCaller nonReentrant returns (uint256 orderId) { require( reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0, "Insufficient Liquidity" ); require(amountBIn > 0, "Invalid Amount"); orderId = longTermOrders.longTermSwapFromBToA( sender, amountBIn, numberOfBlockIntervals, reserveMap ); emit LongTermSwapBToA(sender, amountBIn, orderId); } ///@notice stop the execution of a long term order function cancelLongTermSwap( address sender, uint256 orderId ) external override checkCaller nonReentrant returns (uint256 unsoldAmount, uint256 purchasedAmount) { (unsoldAmount, purchasedAmount) = longTermOrders.cancelLongTermSwap( sender, orderId, reserveMap ); emit CancelLongTermOrder( sender, orderId, unsoldAmount, purchasedAmount ); } ///@notice withdraw proceeds from a long term swap function withdrawProceedsFromLongTermSwap( address sender, uint256 orderId ) external override checkCaller nonReentrant returns (uint256 proceeds) { proceeds = longTermOrders.withdrawProceedsFromLongTermSwap( sender, orderId, reserveMap ); emit WithdrawProceedsFromLongTermOrder(sender, orderId, proceeds); } ///@notice private function which implements instant swap logic function performInstantSwap( address from, address to, uint256 amountIn ) private checkCaller returns (uint256 amountOutMinusFee) { //execute virtual orders longTermOrders.executeVirtualOrdersUntilSpecifiedBlock( reserveMap, block.number ); uint256 reserveFrom = reserveMap[from]; uint256 reserveTo = reserveMap[to]; //constant product formula uint256 amountOut = (reserveTo * amountIn) / (reserveFrom + amountIn); //charge LP fee amountOutMinusFee = (amountOut * (10000 - LP_FEE)) / 10000; reserveMap[from] += amountIn; reserveMap[to] -= amountOutMinusFee; IERC20(to).safeTransfer(twamm, amountOutMinusFee); } ///@notice get pair orders total amount function getPairOrdersAmount() external view override returns (uint256) { return longTermOrders.orderId; } ///@notice get user order details function getOrderDetails( uint256 orderId ) external view override returns (LongTermOrdersLib.Order memory) { return longTermOrders.orderMap[orderId]; } ///@notice returns the user order reward factor function getOrderRewardFactor( uint256 orderId ) external view override returns ( uint256 orderRewardFactorAtSubmission, uint256 orderRewardFactorAtExpiring ) { address orderSellToken = longTermOrders.orderMap[orderId].sellTokenId; uint256 orderExpirationBlock = longTermOrders .orderMap[orderId] .expirationBlock; orderRewardFactorAtSubmission = longTermOrders .OrderPoolMap[orderSellToken] .rewardFactorAtSubmission[orderId]; orderRewardFactorAtExpiring = longTermOrders .OrderPoolMap[orderSellToken] .rewardFactorAtBlock[orderExpirationBlock]; } ///@notice returns the current state of the twamm function getTWAMMState() external view override returns ( uint256 lastVirtualOrderBlock, uint256 tokenASalesRate, uint256 tokenBSalesRate, uint256 orderPoolARewardFactor, uint256 orderPoolBRewardFactor ) { lastVirtualOrderBlock = longTermOrders.lastVirtualOrderBlock; tokenASalesRate = longTermOrders.OrderPoolMap[tokenA].currentSalesRate; tokenBSalesRate = longTermOrders.OrderPoolMap[tokenB].currentSalesRate; orderPoolARewardFactor = longTermOrders .OrderPoolMap[tokenA] .rewardFactor; orderPoolBRewardFactor = longTermOrders .OrderPoolMap[tokenB] .rewardFactor; } ///@notice returns cumulative sales rate of orders ending on this block number function getTWAMMSalesRateEnding( uint256 blockNumber ) external view override returns ( uint256 orderPoolASalesRateEnding, uint256 orderPoolBSalesRateEnding ) { orderPoolASalesRateEnding = longTermOrders .OrderPoolMap[tokenA] .salesRateEndingPerBlock[blockNumber]; orderPoolBSalesRateEnding = longTermOrders .OrderPoolMap[tokenB] .salesRateEndingPerBlock[blockNumber]; } ///@notice returns expiries list since last executed function getExpiriesSinceLastExecuted() external view override returns (uint256[] memory) { return longTermOrders .expiryBlockTreeSinceLastExecution .getFutureExpiriesList(); } ///@notice get user orderIds function userIdsCheck( address userAddress ) external view override returns (uint256[] memory) { return longTermOrders.orderIdMap[userAddress]; } ///@notice get user order status based on Ids function orderIdStatusCheck( uint256 orderId ) external view override returns (bool) { return longTermOrders.orderIdStatusMap[orderId]; } ///@notice convenience function to execute virtual orders. Note that this already happens ///before most interactions with the AMM function executeVirtualOrders(uint256 blockNumber) public override { longTermOrders.executeVirtualOrdersUntilSpecifiedBlock( reserveMap, blockNumber ); } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.9; import "../libraries/LongTermOrders.sol"; interface IPair { function factory() external view returns (address); function tokenA() external view returns (address); function tokenB() external view returns (address); function rootKLast() external view returns (uint256); function LP_FEE() external pure returns (uint256); function orderBlockInterval() external pure returns (uint256); function reserveMap(address) external view returns (uint256); function tokenAReserves() external view returns (uint256); function tokenBReserves() external view returns (uint256); function getTotalSupply() external view returns (uint256); event InitialLiquidityProvided( address indexed addr, uint256 lpTokenAmount, uint256 amountA, uint256 amountB ); event LiquidityProvided( address indexed addr, uint256 lpTokenAmount, uint256 amountAIn, uint256 amountBIn ); event LiquidityRemoved( address indexed addr, uint256 lpTokenAmount, uint256 amountAOut, uint256 amountBOut ); event InstantSwapAToB( address indexed addr, uint256 amountAIn, uint256 amountBOut ); event InstantSwapBToA( address indexed addr, uint256 amountBIn, uint256 amountAOut ); event LongTermSwapAToB( address indexed addr, uint256 amountAIn, uint256 orderId ); event LongTermSwapBToA( address indexed addr, uint256 amountBIn, uint256 orderId ); event CancelLongTermOrder( address indexed addr, uint256 orderId, uint256 unsoldAmount, uint256 purchasedAmount ); event WithdrawProceedsFromLongTermOrder( address indexed addr, uint256 orderId, uint256 proceeds ); function provideInitialLiquidity( address to, uint256 amountA, uint256 amountB ) external returns (uint256 lpTokenAmount); function provideLiquidity( address to, uint256 lpTokenAmount ) external returns (uint256 amountAIn, uint256 amountBIn); function removeLiquidity( address to, uint256 lpTokenAmount ) external returns (uint256 amountAOut, uint256 amountBOut); function instantSwapFromAToB( address sender, uint256 amountAIn ) external returns (uint256 amountBOut); function longTermSwapFromAToB( address sender, uint256 amountAIn, uint256 numberOfBlockIntervals ) external returns (uint256 orderId); function instantSwapFromBToA( address sender, uint256 amountBIn ) external returns (uint256 amountAOut); function longTermSwapFromBToA( address sender, uint256 amountBIn, uint256 numberOfBlockIntervals ) external returns (uint256 orderId); function cancelLongTermSwap( address sender, uint256 orderId ) external returns (uint256 unsoldAmount, uint256 purchasedAmount); function withdrawProceedsFromLongTermSwap( address sender, uint256 orderId ) external returns (uint256 proceeds); function getPairOrdersAmount() external view returns (uint256); function getOrderDetails( uint256 orderId ) external view returns (LongTermOrdersLib.Order memory); function getOrderRewardFactor( uint256 orderId ) external view returns ( uint256 orderRewardFactorAtSubmission, uint256 orderRewardFactorAtExpiring ); function getTWAMMState() external view returns ( uint256 lastVirtualOrderBlock, uint256 tokenASalesRate, uint256 tokenBSalesRate, uint256 orderPoolARewardFactor, uint256 orderPoolBRewardFactor ); function getTWAMMSalesRateEnding( uint256 blockNumber ) external view returns ( uint256 orderPoolASalesRateEnding, uint256 orderPoolBSalesRateEnding ); function getExpiriesSinceLastExecuted() external view returns (uint256[] memory); function userIdsCheck( address userAddress ) external view returns (uint256[] memory); function orderIdStatusCheck(uint256 orderId) external view returns (bool); function executeVirtualOrders(uint256 blockNumber) external; }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.9; interface IFactory { event PairCreated( address indexed tokenA, address indexed tokenB, address pair, uint256 ); function getPair( address token0, address token1 ) external view returns (address pair); function allPairs(uint256) external view returns (address pair); function feeArg() external view returns (uint32); function feeTo() external view returns (address); function feeToSetter() external view returns (address); function allPairsLength() external view returns (uint256); function initialize(address _twammAdd) external; function twammAdd() external view returns (address); function createPair( address token0, address token1 ) external returns (address pair); function setFeeArg(uint32) external; function setFeeTo(address) external; function setFeeToSetter(address) external; }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.9; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; // import "prb-math/contracts/PRBMathSD59x18.sol"; import "./OrderPool.sol"; import "./BinarySearchTree.sol"; ///@notice This library handles the state and execution of long term orders. library LongTermOrdersLib { //using PRBMathSD59x18 for int256; using OrderPoolLib for OrderPoolLib.OrderPool; using BinarySearchTreeLib for BinarySearchTreeLib.Tree; using SafeERC20 for IERC20; ///@notice fee for LP providers, 4 decimal places, i.e. 30 = 0.3% uint256 public constant LP_FEE = 30; ///@notice information associated with a long term order struct Order { uint256 id; uint256 submitBlock; uint256 expirationBlock; uint256 saleRate; uint256 sellAmount; uint256 buyAmount; address owner; address sellTokenId; address buyTokenId; } ///@notice structure contains full state related to long term orders struct LongTermOrders { ///@notice minimum block interval between order expiries uint256 orderBlockInterval; ///@notice last virtual orders were executed immediately before this block uint256 lastVirtualOrderBlock; ///@notice token pair being traded in embedded amm address tokenA; address tokenB; ///@notice useful addresses for TWAMM transactions address refTWAMM; ///@notice mapping from token address to pool that is selling that token ///we maintain two order pools, one for each token that is tradable in the AMM mapping(address => OrderPoolLib.OrderPool) OrderPoolMap; ///@notice incrementing counter for order ids uint256 orderId; ///@notice mapping from order ids to Orders mapping(uint256 => Order) orderMap; ///@notice mapping from account address to its corresponding list of order ids mapping(address => uint256[]) orderIdMap; ///@notice mapping from order id to its status (false for nonactive true for active) mapping(uint256 => bool) orderIdStatusMap; ///@notice record all expiry blocks since the latest executed block BinarySearchTreeLib.Tree expiryBlockTreeSinceLastExecution; } ///@notice initialize state function initialize( LongTermOrders storage self, address tokenA, address tokenB, address refTWAMM, uint256 lastVirtualOrderBlock, uint256 orderBlockInterval ) public { self.tokenA = tokenA; self.tokenB = tokenB; self.refTWAMM = refTWAMM; self.lastVirtualOrderBlock = lastVirtualOrderBlock; self.orderBlockInterval = orderBlockInterval; self.expiryBlockTreeSinceLastExecution.insert( lastVirtualOrderBlock - (lastVirtualOrderBlock % orderBlockInterval) ); } ///@notice long term swap token A for token B. Amount represents total amount being sold, numberOfBlockIntervals determines when order expires function longTermSwapFromAToB( LongTermOrders storage self, address sender, uint256 amountA, uint256 numberOfBlockIntervals, mapping(address => uint256) storage reserveMap ) public returns (uint256) { return performLongTermSwap( self, self.tokenA, self.tokenB, sender, amountA, numberOfBlockIntervals, reserveMap ); } ///@notice long term swap token B for token A. Amount represents total amount being sold, numberOfBlockIntervals determines when order expires function longTermSwapFromBToA( LongTermOrders storage self, address sender, uint256 amountB, uint256 numberOfBlockIntervals, mapping(address => uint256) storage reserveMap ) public returns (uint256) { return performLongTermSwap( self, self.tokenB, self.tokenA, sender, amountB, numberOfBlockIntervals, reserveMap ); } ///@notice adds long term swap to order pool function performLongTermSwap( LongTermOrders storage self, address from, address to, address sender, uint256 amount, uint256 numberOfBlockIntervals, mapping(address => uint256) storage reserveMap ) private returns (uint256) { //determine the selling rate based on number of blocks to expiry and total amount uint256 currentBlock = block.number; uint256 lastExpiryBlock = currentBlock - (currentBlock % self.orderBlockInterval); uint256 orderExpiry = self.orderBlockInterval * (numberOfBlockIntervals + 1) + lastExpiryBlock; uint256 sellingRate = (amount * 10000) / (orderExpiry - currentBlock); //multiply by 10000 to reduce precision loss //insert order expiry and update virtual order state self.expiryBlockTreeSinceLastExecution.insert(orderExpiry); executeVirtualOrdersUntilSpecifiedBlock(self, reserveMap, block.number); //add order to correct pool OrderPoolLib.OrderPool storage OrderPool = self.OrderPoolMap[from]; OrderPool.depositOrder(self.orderId, sellingRate, orderExpiry); //add to order map self.orderMap[self.orderId] = Order( self.orderId, currentBlock, orderExpiry, sellingRate, 0, 0, sender, from, to ); // add user's corresponding orderId to orderId mapping list content self.orderIdMap[sender].push(self.orderId); self.orderIdStatusMap[self.orderId] = true; return self.orderId++; } ///@notice cancel long term swap, pay out unsold tokens and well as purchased tokens function cancelLongTermSwap( LongTermOrders storage self, address sender, uint256 orderId, mapping(address => uint256) storage reserveMap ) public returns (uint256, uint256) { //update virtual order state executeVirtualOrdersUntilSpecifiedBlock(self, reserveMap, block.number); Order storage order = self.orderMap[orderId]; require(self.orderIdStatusMap[orderId] == true, "Order Invalid"); require(order.owner == sender, "Sender Must Be Order Owner"); OrderPoolLib.OrderPool storage OrderPoolSell = self.OrderPoolMap[ order.sellTokenId ]; OrderPoolLib.OrderPool storage OrderPoolBuy = self.OrderPoolMap[ order.buyTokenId ]; (uint256 unsoldAmount, uint256 purchasedAmount) = OrderPoolSell .cancelOrder(orderId); require( unsoldAmount > 0 || purchasedAmount > 0, "No Proceeds To Withdraw" ); order.sellAmount = ((block.number - order.submitBlock) * order.saleRate) / 10000; order.buyAmount += purchasedAmount; if ( OrderPoolSell.salesRateEndingPerBlock[order.expirationBlock] == 0 && OrderPoolBuy.salesRateEndingPerBlock[order.expirationBlock] == 0 ) { self.expiryBlockTreeSinceLastExecution.deleteNode( order.expirationBlock ); } // delete orderId from account list self.orderIdStatusMap[orderId] = false; //transfer to owner IERC20(order.buyTokenId).safeTransfer(self.refTWAMM, purchasedAmount); IERC20(order.sellTokenId).safeTransfer(self.refTWAMM, unsoldAmount); return (unsoldAmount, purchasedAmount); } ///@notice withdraw proceeds from a long term swap (can be expired or ongoing) function withdrawProceedsFromLongTermSwap( LongTermOrders storage self, address sender, uint256 orderId, mapping(address => uint256) storage reserveMap ) public returns (uint256) { //update virtual order state executeVirtualOrdersUntilSpecifiedBlock(self, reserveMap, block.number); Order storage order = self.orderMap[orderId]; require(self.orderIdStatusMap[orderId] == true, "Order Invalid"); require(order.owner == sender, "Sender Must Be Order Owner"); OrderPoolLib.OrderPool storage OrderPool = self.OrderPoolMap[ order.sellTokenId ]; uint256 proceeds = OrderPool.withdrawProceeds(orderId); require(proceeds > 0, "No Proceeds To Withdraw"); order.buyAmount += proceeds; if (order.expirationBlock <= block.number) { // delete orderId from account list self.orderIdStatusMap[orderId] = false; order.sellAmount = ((order.expirationBlock - order.submitBlock) * order.saleRate) / 10000; } else { order.sellAmount = ((block.number - order.submitBlock) * order.saleRate) / 10000; } //transfer to owner IERC20(order.buyTokenId).safeTransfer(self.refTWAMM, proceeds); return proceeds; } ///@notice executes all virtual orders between current lastVirtualOrderBlock and blockNumber //also handles orders that expire at end of final block. This assumes that no orders expire inside the given interval function executeVirtualTradesAndOrderExpiries( LongTermOrders storage self, mapping(address => uint256) storage reserveMap, uint256 blockNumber ) private { //amount sold from virtual trades uint256 blockNumberIncrement = blockNumber - self.lastVirtualOrderBlock; uint256 tokenASellAmount = (self .OrderPoolMap[self.tokenA] .currentSalesRate * blockNumberIncrement) / 10000; uint256 tokenBSellAmount = (self .OrderPoolMap[self.tokenB] .currentSalesRate * blockNumberIncrement) / 10000; //initial amm balance uint256 tokenAStart = reserveMap[self.tokenA]; uint256 tokenBStart = reserveMap[self.tokenB]; //updated balances from sales ( uint256 tokenAOut, uint256 tokenBOut, uint256 ammEndTokenA, uint256 ammEndTokenB ) = computeVirtualBalances( tokenAStart, tokenBStart, tokenASellAmount, tokenBSellAmount ); //charge LP fee ammEndTokenA += (tokenAOut * LP_FEE) / 10000; ammEndTokenB += (tokenBOut * LP_FEE) / 10000; tokenAOut = (tokenAOut * (10000 - LP_FEE)) / 10000; tokenBOut = (tokenBOut * (10000 - LP_FEE)) / 10000; //update balances reserves reserveMap[self.tokenA] = ammEndTokenA; reserveMap[self.tokenB] = ammEndTokenB; //distribute proceeds to pools OrderPoolLib.OrderPool storage OrderPoolA = self.OrderPoolMap[ self.tokenA ]; OrderPoolLib.OrderPool storage OrderPoolB = self.OrderPoolMap[ self.tokenB ]; OrderPoolA.distributePayment(tokenBOut); OrderPoolB.distributePayment(tokenAOut); //handle orders expiring at end of interval OrderPoolA.updateStateFromBlockExpiry(blockNumber); OrderPoolB.updateStateFromBlockExpiry(blockNumber); //update last virtual trade block self.lastVirtualOrderBlock = blockNumber; } ///@notice executes all virtual orders until specified block, includ current block. function executeVirtualOrdersUntilSpecifiedBlock( LongTermOrders storage self, mapping(address => uint256) storage reserveMap, uint256 blockNumber ) public { require( blockNumber <= block.number && blockNumber >= self.lastVirtualOrderBlock, "Specified Block Number Invalid!" ); OrderPoolLib.OrderPool storage OrderPoolA = self.OrderPoolMap[ self.tokenA ]; OrderPoolLib.OrderPool storage OrderPoolB = self.OrderPoolMap[ self.tokenB ]; // get list of expiryBlocks given points that are divisible by int blockInterval // then trim the tree to have root tree to be node correponding to the last argument (%5=0) self.expiryBlockTreeSinceLastExecution.processExpiriesListNTrimTree( self.lastVirtualOrderBlock - (self.lastVirtualOrderBlock % self.orderBlockInterval), blockNumber - (blockNumber % self.orderBlockInterval) ); uint256[] storage expiriesList = self .expiryBlockTreeSinceLastExecution .getExpiriesList(); for (uint256 i = 0; i < expiriesList.length; i++) { if ( (OrderPoolA.salesRateEndingPerBlock[expiriesList[i]] > 0 || OrderPoolB.salesRateEndingPerBlock[expiriesList[i]] > 0) && (expiriesList[i] > self.lastVirtualOrderBlock && expiriesList[i] < blockNumber) ) { executeVirtualTradesAndOrderExpiries( self, reserveMap, expiriesList[i] ); } } executeVirtualTradesAndOrderExpiries(self, reserveMap, blockNumber); } ///@notice computes the result of virtual trades by the token pools function computeVirtualBalances( uint256 tokenAStart, uint256 tokenBStart, uint256 tokenAIn, uint256 tokenBIn ) private pure returns ( uint256 tokenAOut, uint256 tokenBOut, uint256 ammEndTokenA, uint256 ammEndTokenB ) { // if ( // tokenAStart == 0 || // tokenBStart == 0 || // tokenAIn == 0 || // tokenBIn == 0 // ) { // //in the case where only one pool is selling, we just perform a normal swap //constant product formula tokenAOut = ((tokenAStart + tokenAIn) * tokenBIn) / (tokenBStart + tokenBIn); tokenBOut = ((tokenBStart + tokenBIn) * tokenAIn) / (tokenAStart + tokenAIn); ammEndTokenA = tokenAStart + tokenAIn - tokenAOut; ammEndTokenB = tokenBStart + tokenBIn - tokenBOut; } // //when both pools sell, we use the TWAMM formula // else { // //signed, fixed point arithmetic // int256 aIn = int256(tokenAIn).fromInt(); // int256 bIn = int256(tokenBIn).fromInt(); // int256 aStart = int256(tokenAStart).fromInt(); // int256 bStart = int256(tokenBStart).fromInt(); // int256 k = aStart.mul(bStart); // int256 c = computeC(aStart, bStart, aIn, bIn); // int256 endA = computeAmmEndTokenA(aIn, bIn, c, k, aStart, bStart); // int256 endB = aStart.div(endA).mul(bStart); // int256 outA = aStart + aIn - endA; // int256 outB = bStart + bIn - endB; // require(outA >= 0 && outB >= 0, "Invalid Amount"); // return ( // uint256(outA.toInt()), // uint256(outB.toInt()), // uint256(endA.toInt()), // uint256(endB.toInt()) // ); // } // } // //helper function for TWAMM formula computation, helps avoid stack depth errors // function computeC( // int256 tokenAStart, // int256 tokenBStart, // int256 tokenAIn, // int256 tokenBIn // ) private pure returns (int256 c) { // int256 c1 = tokenAStart.sqrt().mul(tokenBIn.sqrt()); // int256 c2 = tokenBStart.sqrt().mul(tokenAIn.sqrt()); // int256 cNumerator = c1 - c2; // int256 cDenominator = c1 + c2; // c = cNumerator.div(cDenominator); // } // //helper function for TWAMM formula computation, helps avoid stack depth errors // function computeAmmEndTokenA( // int256 tokenAIn, // int256 tokenBIn, // int256 c, // int256 k, // int256 aStart, // int256 bStart // ) private pure returns (int256 ammEndTokenA) { // //rearranged for numerical stability // int256 eNumerator = PRBMathSD59x18.fromInt(4).mul(tokenAIn).sqrt().mul( // tokenBIn.sqrt() // ); // int256 eDenominator = aStart.sqrt().mul(bStart.sqrt()).inv(); // int256 exponent = eNumerator.mul(eDenominator).exp(); // require(exponent > PRBMathSD59x18.abs(c), "Invalid Amount"); // int256 fraction = (exponent + c).div(exponent - c); // int256 scaling = k.div(tokenBIn).sqrt().mul(tokenAIn.sqrt()); // ammEndTokenA = fraction.mul(scaling); // } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.9; library BinarySearchTreeLib { uint256 private constant TIME_EXTENSION = 50400; struct Node { uint256 parent; uint256 value; uint256 left; uint256 right; } struct Tree { uint256 root; uint256 rootLast; mapping(uint256 => Node) nodes; mapping(uint256 => uint256[]) rootToList; mapping(uint256 => uint256[]) futureExpiries; //map from last divisible root to a list of exipiries sine that root. not ordered } // helper function for insert function insertHelper( Tree storage self, uint256 newValue, uint256 nodeId ) public { // current node Node memory curNode = self.nodes[nodeId]; // if value exists, no need to insert if (newValue != curNode.value) { if (newValue < curNode.value) { if (curNode.left == 0) { self.nodes[curNode.value].left = newValue; self.nodes[newValue] = Node(curNode.value, newValue, 0, 0); } else { insertHelper(self, newValue, curNode.left); } } else { if (curNode.right == 0) { self.nodes[curNode.value].right = newValue; self.nodes[newValue] = Node(curNode.value, newValue, 0, 0); } else { insertHelper(self, newValue, curNode.right); } } } } function insert(Tree storage self, uint256 newValue) public { // no tree exists if (self.root == 0) { self.root = newValue; self.rootLast = newValue; self.nodes[newValue] = Node(0, newValue, 0, 0); self.futureExpiries[self.root].push(newValue); } else { insertHelper(self, newValue, self.root); } } function returnListHelperEx( Tree storage self, uint256 start, uint256 end, uint256 nodeId, uint256 extension ) public { if (start <= end && end < extension) { // current node Node memory curNode = self.nodes[nodeId]; if (curNode.value != 0) { if (curNode.value > start) { returnListHelperEx( self, start, end, curNode.left, extension ); } if (curNode.value <= end && curNode.value >= start) { if ( self.rootToList[self.root].length == 0 || (self.rootToList[self.root].length > 0 && self.rootToList[self.root][ self.rootToList[self.root].length - 1 ] != curNode.value) ) { self.rootToList[self.root].push(curNode.value); } } if (curNode.value <= extension && curNode.value > end) { if ( self.futureExpiries[self.root].length == 0 || (self.futureExpiries[self.root].length > 0 && self.futureExpiries[self.root][ self.futureExpiries[self.root].length - 1 ] != curNode.value) ) { self.futureExpiries[self.root].push(curNode.value); } } if (curNode.value < extension) { returnListHelperEx( self, start, end, curNode.right, extension ); } } } } function deleteNodeHelper( Tree storage self, uint256 deleteValue, uint256 nodeId ) public returns (uint256 newValue) { Node memory curNode = self.nodes[nodeId]; if (curNode.value == deleteValue) { newValue = deleteLeaf(self, curNode.value); } else if (curNode.value < deleteValue) { if (curNode.right == 0) { newValue = 0; } else { newValue = deleteNodeHelper(self, deleteValue, curNode.right); } } else { if (curNode.left == 0) { newValue = 0; } else { newValue = deleteNodeHelper(self, deleteValue, curNode.left); } } } function deleteLeaf( Tree storage self, uint256 nodeId ) public returns (uint256 newNodeId) { Node memory curNode = self.nodes[nodeId]; if (curNode.left != 0) { uint256 tempValue = curNode.left; while (self.nodes[tempValue].right != 0) { tempValue = self.nodes[tempValue].right; } if (tempValue != curNode.left) { if (curNode.parent != 0) { if (curNode.value < curNode.parent) { self.nodes[curNode.parent].left = tempValue; } else { self.nodes[curNode.parent].right = tempValue; } } if (curNode.right != 0) { self.nodes[curNode.right].parent = tempValue; } self.nodes[curNode.left].parent = tempValue; curNode.value = tempValue; deleteNodeHelper(self, tempValue, curNode.left); self.nodes[tempValue] = curNode; self.nodes[nodeId] = Node(0, 0, 0, 0); } else { if (curNode.parent != 0) { if (curNode.value < curNode.parent) { self.nodes[curNode.parent].left = curNode.left; } else { self.nodes[curNode.parent].right = curNode.left; } } if (curNode.right != 0) { self.nodes[curNode.right].parent = curNode.left; } self.nodes[curNode.left].parent = curNode.parent; self.nodes[curNode.left].right = curNode.right; self.nodes[nodeId] = Node(0, 0, 0, 0); } newNodeId = tempValue; } else if (curNode.left == 0 && curNode.right != 0) { uint256 tempValue = curNode.right; if (curNode.parent != 0) { if (curNode.value < curNode.parent) { self.nodes[curNode.parent].left = tempValue; } else { self.nodes[curNode.parent].right = tempValue; } } self.nodes[curNode.right].parent = curNode.parent; self.nodes[nodeId] = Node(0, 0, 0, 0); newNodeId = tempValue; } else { if (curNode.parent != 0) { if (curNode.value < curNode.parent) { self.nodes[curNode.parent].left = 0; } else { self.nodes[curNode.parent].right = 0; } } self.nodes[nodeId] = Node(0, 0, 0, 0); newNodeId = 0; } } function deleteNode( Tree storage self, uint256 deleteValue ) public returns (uint256 newRoot) { if (deleteValue != self.root) { deleteNodeHelper(self, deleteValue, self.root); newRoot = self.root; } else { newRoot = deleteLeaf(self, self.root); self.root = newRoot; } } function trimTreeHelper( Tree storage self, uint256 start, uint256 end, uint256 nodeId ) public { if (start <= end) { // current node Node memory curNode = self.nodes[nodeId]; if (curNode.value != 0) { if (curNode.value < start) { trimTreeHelper(self, start, end, curNode.right); } else if (curNode.value >= start && curNode.value <= end) { uint256 newNodeId = deleteLeaf(self, curNode.value); if (newNodeId != 0) { trimTreeHelper(self, start, end, newNodeId); } } else { trimTreeHelper(self, start, end, curNode.left); } } } } function trimTree( Tree storage self, uint256 start, uint256 end ) public returns (uint256 newRoot) { if (start <= end) { // current root Node memory rootNode = self.nodes[self.root]; if (rootNode.value != 0) { if (rootNode.value < start) { trimTreeHelper(self, start, end, rootNode.right); newRoot = self.root; } else if (rootNode.value >= start && rootNode.value <= end) { newRoot = deleteNode(self, rootNode.value); if (newRoot != 0) { newRoot = trimTree(self, start, end); } } else { trimTreeHelper(self, start, end, rootNode.left); newRoot = self.root; } } } } function processExpiriesListNTrimTree( Tree storage self, uint256 start, uint256 end ) public { if (self.root != 0) { //must have a tree delete self.futureExpiries[self.root]; self.futureExpiries[self.root].push(end); if (self.root == self.rootLast) { delete self.rootToList[self.root]; } returnListHelperEx( self, start, end, self.root, end + TIME_EXTENSION ); self.rootLast = self.root; trimTree(self, start, end); } } function getExpiriesList( Tree storage self ) public view returns (uint256[] storage) { return self.rootToList[self.rootLast]; } function getFutureExpiriesList( Tree storage self ) public view returns (uint256[] storage) { return self.futureExpiries[self.rootLast]; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - amount); } return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(_msgSender(), spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); _afterTokenTransfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Gas optimized reentrancy protection for smart contracts. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol) abstract contract ReentrancyGuard { uint256 private reentrancyStatus = 1; modifier nonReentrant() { require(reentrancyStatus == 1, "REENTRANCY"); reentrancyStatus = 2; _; reentrancyStatus = 1; } }
// SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; import "./PRBMath.sol"; /// @title PRBMathUD60x18 /// @author Paul Razvan Berg /// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18 /// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60 /// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the /// maximum values permitted by the Solidity type uint256. library PRBMathUD60x18 { /// @dev Half the SCALE number. uint256 internal constant HALF_SCALE = 5e17; /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number. uint256 internal constant LOG2_E = 1_442695040888963407; /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have. uint256 internal constant MAX_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_584007913129639935; /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have. uint256 internal constant MAX_WHOLE_UD60x18 = 115792089237316195423570985008687907853269984665640564039457_000000000000000000; /// @dev How many trailing decimals can be represented. uint256 internal constant SCALE = 1e18; /// @notice Calculates the arithmetic average of x and y, rounding down. /// @param x The first operand as an unsigned 60.18-decimal fixed-point number. /// @param y The second operand as an unsigned 60.18-decimal fixed-point number. /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number. function avg(uint256 x, uint256 y) internal pure returns (uint256 result) { // The operations can never overflow. unchecked { // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice. result = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x. /// /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// /// Requirements: /// - x must be less than or equal to MAX_WHOLE_UD60x18. /// /// @param x The unsigned 60.18-decimal fixed-point number to ceil. /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number. function ceil(uint256 x) internal pure returns (uint256 result) { if (x > MAX_WHOLE_UD60x18) { revert PRBMathUD60x18__CeilOverflow(x); } assembly { // Equivalent to "x % SCALE" but faster. let remainder := mod(x, SCALE) // Equivalent to "SCALE - remainder" but faster. let delta := sub(SCALE, remainder) // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster. result := add(x, mul(delta, gt(remainder, 0))) } } /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number. /// /// @dev Uses mulDiv to enable overflow-safe multiplication and division. /// /// Requirements: /// - The denominator cannot be zero. /// /// @param x The numerator as an unsigned 60.18-decimal fixed-point number. /// @param y The denominator as an unsigned 60.18-decimal fixed-point number. /// @param result The quotient as an unsigned 60.18-decimal fixed-point number. function div(uint256 x, uint256 y) internal pure returns (uint256 result) { result = PRBMath.mulDiv(x, SCALE, y); } /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number. /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant). function e() internal pure returns (uint256 result) { result = 2_718281828459045235; } /// @notice Calculates the natural exponent of x. /// /// @dev Based on the insight that e^x = 2^(x * log2(e)). /// /// Requirements: /// - All from "log2". /// - x must be less than 133.084258667509499441. /// /// @param x The exponent as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp(uint256 x) internal pure returns (uint256 result) { // Without this check, the value passed to "exp2" would be greater than 192. if (x >= 133_084258667509499441) { revert PRBMathUD60x18__ExpInputTooBig(x); } // Do the fixed-point multiplication inline to save gas. unchecked { uint256 doubleScaleProduct = x * LOG2_E; result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE); } } /// @notice Calculates the binary exponent of x using the binary fraction method. /// /// @dev See https://ethereum.stackexchange.com/q/79903/24693. /// /// Requirements: /// - x must be 192 or less. /// - The result must fit within MAX_UD60x18. /// /// @param x The exponent as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp2(uint256 x) internal pure returns (uint256 result) { // 2^192 doesn't fit within the 192.64-bit format used internally in this function. if (x >= 192e18) { revert PRBMathUD60x18__Exp2InputTooBig(x); } unchecked { // Convert x to the 192.64-bit fixed-point format. uint256 x192x64 = (x << 64) / SCALE; // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation. result = PRBMath.exp2(x192x64); } } /// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x. /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts. /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions. /// @param x The unsigned 60.18-decimal fixed-point number to floor. /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number. function floor(uint256 x) internal pure returns (uint256 result) { assembly { // Equivalent to "x % SCALE" but faster. let remainder := mod(x, SCALE) // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster. result := sub(x, mul(remainder, gt(remainder, 0))) } } /// @notice Yields the excess beyond the floor of x. /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part. /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of. /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number. function frac(uint256 x) internal pure returns (uint256 result) { assembly { result := mod(x, SCALE) } } /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation. /// /// @dev Requirements: /// - x must be less than or equal to MAX_UD60x18 divided by SCALE. /// /// @param x The basic integer to convert. /// @param result The same number in unsigned 60.18-decimal fixed-point representation. function fromUint(uint256 x) internal pure returns (uint256 result) { unchecked { if (x > MAX_UD60x18 / SCALE) { revert PRBMathUD60x18__FromUintOverflow(x); } result = x * SCALE; } } /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down. /// /// @dev Requirements: /// - x * y must fit within MAX_UD60x18, lest it overflows. /// /// @param x The first operand as an unsigned 60.18-decimal fixed-point number. /// @param y The second operand as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function gm(uint256 x, uint256 y) internal pure returns (uint256 result) { if (x == 0) { return 0; } unchecked { // Checking for overflow this way is faster than letting Solidity do it. uint256 xy = x * y; if (xy / x != y) { revert PRBMathUD60x18__GmOverflow(x, y); } // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE // during multiplication. See the comments within the "sqrt" function. result = PRBMath.sqrt(xy); } } /// @notice Calculates 1 / x, rounding toward zero. /// /// @dev Requirements: /// - x cannot be zero. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse. /// @return result The inverse as an unsigned 60.18-decimal fixed-point number. function inv(uint256 x) internal pure returns (uint256 result) { unchecked { // 1e36 is SCALE * SCALE. result = 1e36 / x; } } /// @notice Calculates the natural logarithm of x. /// /// @dev Based on the insight that ln(x) = log2(x) / log2(e). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm. /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number. function ln(uint256 x) internal pure returns (uint256 result) { // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x) // can return is 196205294292027477728. unchecked { result = (log2(x) * SCALE) / LOG2_E; } } /// @notice Calculates the common logarithm of x. /// /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common /// logarithm based on the insight that log10(x) = log2(x) / log2(10). /// /// Requirements: /// - All from "log2". /// /// Caveats: /// - All from "log2". /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm. /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number. function log10(uint256 x) internal pure returns (uint256 result) { if (x < SCALE) { revert PRBMathUD60x18__LogInputTooSmall(x); } // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined // in this contract. // prettier-ignore assembly { switch x case 1 { result := mul(SCALE, sub(0, 18)) } case 10 { result := mul(SCALE, sub(1, 18)) } case 100 { result := mul(SCALE, sub(2, 18)) } case 1000 { result := mul(SCALE, sub(3, 18)) } case 10000 { result := mul(SCALE, sub(4, 18)) } case 100000 { result := mul(SCALE, sub(5, 18)) } case 1000000 { result := mul(SCALE, sub(6, 18)) } case 10000000 { result := mul(SCALE, sub(7, 18)) } case 100000000 { result := mul(SCALE, sub(8, 18)) } case 1000000000 { result := mul(SCALE, sub(9, 18)) } case 10000000000 { result := mul(SCALE, sub(10, 18)) } case 100000000000 { result := mul(SCALE, sub(11, 18)) } case 1000000000000 { result := mul(SCALE, sub(12, 18)) } case 10000000000000 { result := mul(SCALE, sub(13, 18)) } case 100000000000000 { result := mul(SCALE, sub(14, 18)) } case 1000000000000000 { result := mul(SCALE, sub(15, 18)) } case 10000000000000000 { result := mul(SCALE, sub(16, 18)) } case 100000000000000000 { result := mul(SCALE, sub(17, 18)) } case 1000000000000000000 { result := 0 } case 10000000000000000000 { result := SCALE } case 100000000000000000000 { result := mul(SCALE, 2) } case 1000000000000000000000 { result := mul(SCALE, 3) } case 10000000000000000000000 { result := mul(SCALE, 4) } case 100000000000000000000000 { result := mul(SCALE, 5) } case 1000000000000000000000000 { result := mul(SCALE, 6) } case 10000000000000000000000000 { result := mul(SCALE, 7) } case 100000000000000000000000000 { result := mul(SCALE, 8) } case 1000000000000000000000000000 { result := mul(SCALE, 9) } case 10000000000000000000000000000 { result := mul(SCALE, 10) } case 100000000000000000000000000000 { result := mul(SCALE, 11) } case 1000000000000000000000000000000 { result := mul(SCALE, 12) } case 10000000000000000000000000000000 { result := mul(SCALE, 13) } case 100000000000000000000000000000000 { result := mul(SCALE, 14) } case 1000000000000000000000000000000000 { result := mul(SCALE, 15) } case 10000000000000000000000000000000000 { result := mul(SCALE, 16) } case 100000000000000000000000000000000000 { result := mul(SCALE, 17) } case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) } case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) } case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) } case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) } case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) } case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) } case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) } case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) } case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) } case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) } case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) } case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) } case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) } case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) } case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) } case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) } case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) } case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) } case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) } case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) } case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) } case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) } case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) } case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) } case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) } case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) } case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) } case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) } case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) } case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) } case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) } case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) } case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) } case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) } case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) } case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) } case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) } case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) } case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) } case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) } case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) } case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) } default { result := MAX_UD60x18 } } if (result == MAX_UD60x18) { // Do the fixed-point division inline to save gas. The denominator is log2(10). unchecked { result = (log2(x) * SCALE) / 3_321928094887362347; } } } /// @notice Calculates the binary logarithm of x. /// /// @dev Based on the iterative approximation algorithm. /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation /// /// Requirements: /// - x must be greater than or equal to SCALE, otherwise the result would be negative. /// /// Caveats: /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm. /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number. function log2(uint256 x) internal pure returns (uint256 result) { if (x < SCALE) { revert PRBMathUD60x18__LogInputTooSmall(x); } unchecked { // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n). uint256 n = PRBMath.mostSignificantBit(x / SCALE); // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow // because n is maximum 255 and SCALE is 1e18. result = n * SCALE; // This is y = x * 2^(-n). uint256 y = x >> n; // If y = 1, the fractional part is zero. if (y == SCALE) { return result; } // Calculate the fractional part via the iterative approximation. // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster. for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) { y = (y * y) / SCALE; // Is y^2 > 2 and so in the range [2,4)? if (y >= 2 * SCALE) { // Add the 2^(-m) factor to the logarithm. result += delta; // Corresponds to z/2 on Wikipedia. y >>= 1; } } } } /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal /// fixed-point number. /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function. /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number. /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number. /// @return result The product as an unsigned 60.18-decimal fixed-point number. function mul(uint256 x, uint256 y) internal pure returns (uint256 result) { result = PRBMath.mulDivFixedPoint(x, y); } /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number. function pi() internal pure returns (uint256 result) { result = 3_141592653589793238; } /// @notice Raises x to the power of y. /// /// @dev Based on the insight that x^y = 2^(log2(x) * y). /// /// Requirements: /// - All from "exp2", "log2" and "mul". /// /// Caveats: /// - All from "exp2", "log2" and "mul". /// - Assumes 0^0 is 1. /// /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number. /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number. /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number. function pow(uint256 x, uint256 y) internal pure returns (uint256 result) { if (x == 0) { result = y == 0 ? SCALE : uint256(0); } else { result = exp2(mul(log2(x), y)); } } /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the /// famous algorithm "exponentiation by squaring". /// /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring /// /// Requirements: /// - The result must fit within MAX_UD60x18. /// /// Caveats: /// - All from "mul". /// - Assumes 0^0 is 1. /// /// @param x The base as an unsigned 60.18-decimal fixed-point number. /// @param y The exponent as an uint256. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function powu(uint256 x, uint256 y) internal pure returns (uint256 result) { // Calculate the first iteration of the loop in advance. result = y & 1 > 0 ? x : SCALE; // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster. for (y >>= 1; y > 0; y >>= 1) { x = PRBMath.mulDivFixedPoint(x, x); // Equivalent to "y % 2 == 1" but faster. if (y & 1 > 0) { result = PRBMath.mulDivFixedPoint(result, x); } } } /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number. function scale() internal pure returns (uint256 result) { result = SCALE; } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Requirements: /// - x must be less than MAX_UD60x18 / SCALE. /// /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root. /// @return result The result as an unsigned 60.18-decimal fixed-point . function sqrt(uint256 x) internal pure returns (uint256 result) { unchecked { if (x > MAX_UD60x18 / SCALE) { revert PRBMathUD60x18__SqrtOverflow(x); } // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root). result = PRBMath.sqrt(x * SCALE); } } /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process. /// @param x The unsigned 60.18-decimal fixed-point number to convert. /// @return result The same number in basic integer form. function toUint(uint256 x) internal pure returns (uint256 result) { unchecked { result = x / SCALE; } } }
// SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.9; import "prb-math/contracts/PRBMathUD60x18.sol"; ///@notice An Order Pool is an abstraction for a pool of long term orders that sells a token at a constant rate to the embedded AMM. ///the order pool handles the logic for distributing the proceeds from these sales to the owners of the long term orders through a modified ///version of the staking algorithm from https://uploads-ssl.webflow.com/5ad71ffeb79acc67c8bcdaba/5ad8d1193a40977462982470_scalable-reward-distribution-paper.pdf library OrderPoolLib { using PRBMathUD60x18 for uint256; ///@notice you can think of this as a staking pool where all long term orders are staked. /// The pool is paid when virtual long term orders are executed, and each order is paid proportionally /// by the order's sale rate per block struct OrderPool { ///@notice current rate that tokens are being sold (per block) uint256 currentSalesRate; ///@notice sum of (salesProceeds_k / salesRate_k) over every period k. Stored as a fixed precision floating point number uint256 rewardFactor; ///@notice this maps block numbers to the cumulative sales rate of orders that expire on that block mapping(uint256 => uint256) salesRateEndingPerBlock; ///@notice map order ids to the block in which they expire mapping(uint256 => uint256) orderExpiry; ///@notice map order ids to their sales rate mapping(uint256 => uint256) salesRate; ///@notice reward factor per order at time of submission mapping(uint256 => uint256) rewardFactorAtSubmission; ///@notice reward factor at a specific block mapping(uint256 => uint256) rewardFactorAtBlock; } ///@notice distribute payment amount to pool (in the case of TWAMM, proceeds from trades against amm) function distributePayment(OrderPool storage self, uint256 amount) public { if (self.currentSalesRate != 0) { //floating point arithmetic self.rewardFactor += amount .fromUint() .mul(PRBMathUD60x18.fromUint(10000)) .div(self.currentSalesRate.fromUint()); } } ///@notice deposit an order into the order pool. function depositOrder( OrderPool storage self, uint256 orderId, uint256 amountPerBlock, uint256 orderExpiry ) public { self.currentSalesRate += amountPerBlock; self.rewardFactorAtSubmission[orderId] = self.rewardFactor; self.orderExpiry[orderId] = orderExpiry; self.salesRate[orderId] = amountPerBlock; self.salesRateEndingPerBlock[orderExpiry] += amountPerBlock; } ///@notice when orders expire after a given block, we need to update the state of the pool function updateStateFromBlockExpiry( OrderPool storage self, uint256 blockNumber ) public { uint256 ordersExpiring = self.salesRateEndingPerBlock[blockNumber]; self.currentSalesRate -= ordersExpiring; self.rewardFactorAtBlock[blockNumber] = self.rewardFactor; } ///@notice cancel order and remove from the order pool function cancelOrder( OrderPool storage self, uint256 orderId ) public returns (uint256 unsoldAmount, uint256 purchasedAmount) { uint256 expiry = self.orderExpiry[orderId]; require(expiry > block.number, "Order Already Finished"); //calculate amount that wasn't sold, and needs to be returned uint256 salesRate = self.salesRate[orderId]; uint256 blocksRemaining = expiry - block.number; unsoldAmount = (blocksRemaining * salesRate) / 10000; //calculate amount of other token that was purchased uint256 rewardFactorAtSubmission = self.rewardFactorAtSubmission[ orderId ]; purchasedAmount = (self.rewardFactor - rewardFactorAtSubmission) .mul(salesRate.fromUint()) .div(PRBMathUD60x18.fromUint(10000)) .toUint(); //update state self.currentSalesRate -= salesRate; self.salesRate[orderId] = 0; self.orderExpiry[orderId] = 0; self.salesRateEndingPerBlock[expiry] -= salesRate; } ///@notice withdraw proceeds from pool for a given order. This can be done before or after the order has expired. //If the order has expired, we calculate the reward factor at time of expiry. If order has not yet expired, we //use current reward factor, and update the reward factor at time of staking (effectively creating a new order) function withdrawProceeds( OrderPool storage self, uint256 orderId ) public returns (uint256 totalReward) { uint256 stakedAmount = self.salesRate[orderId]; require(stakedAmount > 0, "Sales Rate Amount Must Be Positive"); uint256 orderExpiry = self.orderExpiry[orderId]; uint256 rewardFactorAtSubmission = self.rewardFactorAtSubmission[ orderId ]; //if order has expired, we need to calculate the reward factor at expiry if (block.number >= orderExpiry) { uint256 rewardFactorAtExpiry = self.rewardFactorAtBlock[ orderExpiry ]; totalReward = (rewardFactorAtExpiry - rewardFactorAtSubmission) .mul(stakedAmount.fromUint()) .div(PRBMathUD60x18.fromUint(10000)) .toUint(); //remove stake self.salesRate[orderId] = 0; } //if order has not yet expired, we just adjust the start else { totalReward = (self.rewardFactor - rewardFactorAtSubmission) .mul(stakedAmount.fromUint()) .div(PRBMathUD60x18.fromUint(10000)) .toUint(); self.rewardFactorAtSubmission[orderId] = self.rewardFactor; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @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 * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason 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 { // 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 assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: Unlicense pragma solidity >=0.8.4; /// @notice Emitted when the result overflows uint256. error PRBMath__MulDivFixedPointOverflow(uint256 prod1); /// @notice Emitted when the result overflows uint256. error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator); /// @notice Emitted when one of the inputs is type(int256).min. error PRBMath__MulDivSignedInputTooSmall(); /// @notice Emitted when the intermediary absolute result overflows int256. error PRBMath__MulDivSignedOverflow(uint256 rAbs); /// @notice Emitted when the input is MIN_SD59x18. error PRBMathSD59x18__AbsInputTooSmall(); /// @notice Emitted when ceiling a number overflows SD59x18. error PRBMathSD59x18__CeilOverflow(int256 x); /// @notice Emitted when one of the inputs is MIN_SD59x18. error PRBMathSD59x18__DivInputTooSmall(); /// @notice Emitted when one of the intermediary unsigned results overflows SD59x18. error PRBMathSD59x18__DivOverflow(uint256 rAbs); /// @notice Emitted when the input is greater than 133.084258667509499441. error PRBMathSD59x18__ExpInputTooBig(int256 x); /// @notice Emitted when the input is greater than 192. error PRBMathSD59x18__Exp2InputTooBig(int256 x); /// @notice Emitted when flooring a number underflows SD59x18. error PRBMathSD59x18__FloorUnderflow(int256 x); /// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18. error PRBMathSD59x18__FromIntOverflow(int256 x); /// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18. error PRBMathSD59x18__FromIntUnderflow(int256 x); /// @notice Emitted when the product of the inputs is negative. error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y); /// @notice Emitted when multiplying the inputs overflows SD59x18. error PRBMathSD59x18__GmOverflow(int256 x, int256 y); /// @notice Emitted when the input is less than or equal to zero. error PRBMathSD59x18__LogInputTooSmall(int256 x); /// @notice Emitted when one of the inputs is MIN_SD59x18. error PRBMathSD59x18__MulInputTooSmall(); /// @notice Emitted when the intermediary absolute result overflows SD59x18. error PRBMathSD59x18__MulOverflow(uint256 rAbs); /// @notice Emitted when the intermediary absolute result overflows SD59x18. error PRBMathSD59x18__PowuOverflow(uint256 rAbs); /// @notice Emitted when the input is negative. error PRBMathSD59x18__SqrtNegativeInput(int256 x); /// @notice Emitted when the calculating the square root overflows SD59x18. error PRBMathSD59x18__SqrtOverflow(int256 x); /// @notice Emitted when addition overflows UD60x18. error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y); /// @notice Emitted when ceiling a number overflows UD60x18. error PRBMathUD60x18__CeilOverflow(uint256 x); /// @notice Emitted when the input is greater than 133.084258667509499441. error PRBMathUD60x18__ExpInputTooBig(uint256 x); /// @notice Emitted when the input is greater than 192. error PRBMathUD60x18__Exp2InputTooBig(uint256 x); /// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18. error PRBMathUD60x18__FromUintOverflow(uint256 x); /// @notice Emitted when multiplying the inputs overflows UD60x18. error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y); /// @notice Emitted when the input is less than 1. error PRBMathUD60x18__LogInputTooSmall(uint256 x); /// @notice Emitted when the calculating the square root overflows UD60x18. error PRBMathUD60x18__SqrtOverflow(uint256 x); /// @notice Emitted when subtraction underflows UD60x18. error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y); /// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library /// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point /// representation. When it does not, it is explicitly mentioned in the NatSpec documentation. library PRBMath { /// STRUCTS /// struct SD59x18 { int256 value; } struct UD60x18 { uint256 value; } /// STORAGE /// /// @dev How many trailing decimals can be represented. uint256 internal constant SCALE = 1e18; /// @dev Largest power of two divisor of SCALE. uint256 internal constant SCALE_LPOTD = 262144; /// @dev SCALE inverted mod 2^256. uint256 internal constant SCALE_INVERSE = 78156646155174841979727994598816262306175212592076161876661_508869554232690281; /// FUNCTIONS /// /// @notice Calculates the binary exponent of x using the binary fraction method. /// @dev Has to use 192.64-bit fixed-point numbers. /// See https://ethereum.stackexchange.com/a/96594/24693. /// @param x The exponent as an unsigned 192.64-bit fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function exp2(uint256 x) internal pure returns (uint256 result) { unchecked { // Start from 0.5 in the 192.64-bit fixed-point format. result = 0x800000000000000000000000000000000000000000000000; // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows // because the initial result is 2^191 and all magic factors are less than 2^65. if (x & 0x8000000000000000 > 0) { result = (result * 0x16A09E667F3BCC909) >> 64; } if (x & 0x4000000000000000 > 0) { result = (result * 0x1306FE0A31B7152DF) >> 64; } if (x & 0x2000000000000000 > 0) { result = (result * 0x1172B83C7D517ADCE) >> 64; } if (x & 0x1000000000000000 > 0) { result = (result * 0x10B5586CF9890F62A) >> 64; } if (x & 0x800000000000000 > 0) { result = (result * 0x1059B0D31585743AE) >> 64; } if (x & 0x400000000000000 > 0) { result = (result * 0x102C9A3E778060EE7) >> 64; } if (x & 0x200000000000000 > 0) { result = (result * 0x10163DA9FB33356D8) >> 64; } if (x & 0x100000000000000 > 0) { result = (result * 0x100B1AFA5ABCBED61) >> 64; } if (x & 0x80000000000000 > 0) { result = (result * 0x10058C86DA1C09EA2) >> 64; } if (x & 0x40000000000000 > 0) { result = (result * 0x1002C605E2E8CEC50) >> 64; } if (x & 0x20000000000000 > 0) { result = (result * 0x100162F3904051FA1) >> 64; } if (x & 0x10000000000000 > 0) { result = (result * 0x1000B175EFFDC76BA) >> 64; } if (x & 0x8000000000000 > 0) { result = (result * 0x100058BA01FB9F96D) >> 64; } if (x & 0x4000000000000 > 0) { result = (result * 0x10002C5CC37DA9492) >> 64; } if (x & 0x2000000000000 > 0) { result = (result * 0x1000162E525EE0547) >> 64; } if (x & 0x1000000000000 > 0) { result = (result * 0x10000B17255775C04) >> 64; } if (x & 0x800000000000 > 0) { result = (result * 0x1000058B91B5BC9AE) >> 64; } if (x & 0x400000000000 > 0) { result = (result * 0x100002C5C89D5EC6D) >> 64; } if (x & 0x200000000000 > 0) { result = (result * 0x10000162E43F4F831) >> 64; } if (x & 0x100000000000 > 0) { result = (result * 0x100000B1721BCFC9A) >> 64; } if (x & 0x80000000000 > 0) { result = (result * 0x10000058B90CF1E6E) >> 64; } if (x & 0x40000000000 > 0) { result = (result * 0x1000002C5C863B73F) >> 64; } if (x & 0x20000000000 > 0) { result = (result * 0x100000162E430E5A2) >> 64; } if (x & 0x10000000000 > 0) { result = (result * 0x1000000B172183551) >> 64; } if (x & 0x8000000000 > 0) { result = (result * 0x100000058B90C0B49) >> 64; } if (x & 0x4000000000 > 0) { result = (result * 0x10000002C5C8601CC) >> 64; } if (x & 0x2000000000 > 0) { result = (result * 0x1000000162E42FFF0) >> 64; } if (x & 0x1000000000 > 0) { result = (result * 0x10000000B17217FBB) >> 64; } if (x & 0x800000000 > 0) { result = (result * 0x1000000058B90BFCE) >> 64; } if (x & 0x400000000 > 0) { result = (result * 0x100000002C5C85FE3) >> 64; } if (x & 0x200000000 > 0) { result = (result * 0x10000000162E42FF1) >> 64; } if (x & 0x100000000 > 0) { result = (result * 0x100000000B17217F8) >> 64; } if (x & 0x80000000 > 0) { result = (result * 0x10000000058B90BFC) >> 64; } if (x & 0x40000000 > 0) { result = (result * 0x1000000002C5C85FE) >> 64; } if (x & 0x20000000 > 0) { result = (result * 0x100000000162E42FF) >> 64; } if (x & 0x10000000 > 0) { result = (result * 0x1000000000B17217F) >> 64; } if (x & 0x8000000 > 0) { result = (result * 0x100000000058B90C0) >> 64; } if (x & 0x4000000 > 0) { result = (result * 0x10000000002C5C860) >> 64; } if (x & 0x2000000 > 0) { result = (result * 0x1000000000162E430) >> 64; } if (x & 0x1000000 > 0) { result = (result * 0x10000000000B17218) >> 64; } if (x & 0x800000 > 0) { result = (result * 0x1000000000058B90C) >> 64; } if (x & 0x400000 > 0) { result = (result * 0x100000000002C5C86) >> 64; } if (x & 0x200000 > 0) { result = (result * 0x10000000000162E43) >> 64; } if (x & 0x100000 > 0) { result = (result * 0x100000000000B1721) >> 64; } if (x & 0x80000 > 0) { result = (result * 0x10000000000058B91) >> 64; } if (x & 0x40000 > 0) { result = (result * 0x1000000000002C5C8) >> 64; } if (x & 0x20000 > 0) { result = (result * 0x100000000000162E4) >> 64; } if (x & 0x10000 > 0) { result = (result * 0x1000000000000B172) >> 64; } if (x & 0x8000 > 0) { result = (result * 0x100000000000058B9) >> 64; } if (x & 0x4000 > 0) { result = (result * 0x10000000000002C5D) >> 64; } if (x & 0x2000 > 0) { result = (result * 0x1000000000000162E) >> 64; } if (x & 0x1000 > 0) { result = (result * 0x10000000000000B17) >> 64; } if (x & 0x800 > 0) { result = (result * 0x1000000000000058C) >> 64; } if (x & 0x400 > 0) { result = (result * 0x100000000000002C6) >> 64; } if (x & 0x200 > 0) { result = (result * 0x10000000000000163) >> 64; } if (x & 0x100 > 0) { result = (result * 0x100000000000000B1) >> 64; } if (x & 0x80 > 0) { result = (result * 0x10000000000000059) >> 64; } if (x & 0x40 > 0) { result = (result * 0x1000000000000002C) >> 64; } if (x & 0x20 > 0) { result = (result * 0x10000000000000016) >> 64; } if (x & 0x10 > 0) { result = (result * 0x1000000000000000B) >> 64; } if (x & 0x8 > 0) { result = (result * 0x10000000000000006) >> 64; } if (x & 0x4 > 0) { result = (result * 0x10000000000000003) >> 64; } if (x & 0x2 > 0) { result = (result * 0x10000000000000001) >> 64; } if (x & 0x1 > 0) { result = (result * 0x10000000000000001) >> 64; } // We're doing two things at the same time: // // 1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for // the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191 // rather than 192. // 2. Convert the result to the unsigned 60.18-decimal fixed-point format. // // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n". result *= SCALE; result >>= (191 - (x >> 64)); } } /// @notice Finds the zero-based index of the first one in the binary representation of x. /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set /// @param x The uint256 number for which to find the index of the most significant bit. /// @return msb The index of the most significant bit as an uint256. function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) { if (x >= 2**128) { x >>= 128; msb += 128; } if (x >= 2**64) { x >>= 64; msb += 64; } if (x >= 2**32) { x >>= 32; msb += 32; } if (x >= 2**16) { x >>= 16; msb += 16; } if (x >= 2**8) { x >>= 8; msb += 8; } if (x >= 2**4) { x >>= 4; msb += 4; } if (x >= 2**2) { x >>= 2; msb += 2; } if (x >= 2**1) { // No need to shift x any more. msb += 1; } } /// @notice Calculates floor(x*y÷denominator) with full precision. /// /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv. /// /// Requirements: /// - The denominator cannot be zero. /// - The result must fit within uint256. /// /// Caveats: /// - This function does not work with fixed-point numbers. /// /// @param x The multiplicand as an uint256. /// @param y The multiplier as an uint256. /// @param denominator The divisor as an uint256. /// @return result The result as an uint256. function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { unchecked { result = prod0 / denominator; } return result; } // Make sure the result is less than 2^256. Also prevents denominator == 0. if (prod1 >= denominator) { revert PRBMath__MulDivOverflow(prod1, denominator); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. unchecked { // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 lpotdod = denominator & (~denominator + 1); assembly { // Divide denominator by lpotdod. denominator := div(denominator, lpotdod) // Divide [prod1 prod0] by lpotdod. prod0 := div(prod0, lpotdod) // Flip lpotdod such that it is 2^256 / lpotdod. If lpotdod is zero, then it becomes one. lpotdod := add(div(sub(0, lpotdod), lpotdod), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * lpotdod; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /// @notice Calculates floor(x*y÷1e18) with full precision. /// /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of /// being rounded to 1e-18. See "Listing 6" and text above it at https://accu.org/index.php/journals/1717. /// /// Requirements: /// - The result must fit within uint256. /// /// Caveats: /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works. /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations: /// 1. x * y = type(uint256).max * SCALE /// 2. (x * y) % SCALE >= SCALE / 2 /// /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number. /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number. /// @return result The result as an unsigned 60.18-decimal fixed-point number. function mulDivFixedPoint(uint256 x, uint256 y) internal pure returns (uint256 result) { uint256 prod0; uint256 prod1; assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } if (prod1 >= SCALE) { revert PRBMath__MulDivFixedPointOverflow(prod1); } uint256 remainder; uint256 roundUpUnit; assembly { remainder := mulmod(x, y, SCALE) roundUpUnit := gt(remainder, 499999999999999999) } if (prod1 == 0) { unchecked { result = (prod0 / SCALE) + roundUpUnit; return result; } } assembly { result := add( mul( or( div(sub(prod0, remainder), SCALE_LPOTD), mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1)) ), SCALE_INVERSE ), roundUpUnit ) } } /// @notice Calculates floor(x*y÷denominator) with full precision. /// /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately. /// /// Requirements: /// - None of the inputs can be type(int256).min. /// - The result must fit within int256. /// /// @param x The multiplicand as an int256. /// @param y The multiplier as an int256. /// @param denominator The divisor as an int256. /// @return result The result as an int256. function mulDivSigned( int256 x, int256 y, int256 denominator ) internal pure returns (int256 result) { if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) { revert PRBMath__MulDivSignedInputTooSmall(); } // Get hold of the absolute values of x, y and the denominator. uint256 ax; uint256 ay; uint256 ad; unchecked { ax = x < 0 ? uint256(-x) : uint256(x); ay = y < 0 ? uint256(-y) : uint256(y); ad = denominator < 0 ? uint256(-denominator) : uint256(denominator); } // Compute the absolute value of (x*y)÷denominator. The result must fit within int256. uint256 rAbs = mulDiv(ax, ay, ad); if (rAbs > uint256(type(int256).max)) { revert PRBMath__MulDivSignedOverflow(rAbs); } // Get the signs of x, y and the denominator. uint256 sx; uint256 sy; uint256 sd; assembly { sx := sgt(x, sub(0, 1)) sy := sgt(y, sub(0, 1)) sd := sgt(denominator, sub(0, 1)) } // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs. // If yes, the result should be negative. result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs); } /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method. /// /// Caveats: /// - This function does not work with fixed-point numbers. /// /// @param x The uint256 number for which to calculate the square root. /// @return result The result as an uint256. function sqrt(uint256 x) internal pure returns (uint256 result) { if (x == 0) { return 0; } // Set the initial guess to the least power of two that is greater than or equal to sqrt(x). uint256 xAux = uint256(x); result = 1; if (xAux >= 0x100000000000000000000000000000000) { xAux >>= 128; result <<= 64; } if (xAux >= 0x10000000000000000) { xAux >>= 64; result <<= 32; } if (xAux >= 0x100000000) { xAux >>= 32; result <<= 16; } if (xAux >= 0x10000) { xAux >>= 16; result <<= 8; } if (xAux >= 0x100) { xAux >>= 8; result <<= 4; } if (xAux >= 0x10) { xAux >>= 4; result <<= 2; } if (xAux >= 0x8) { result <<= 1; } // The operations can never overflow because the result is max 2^127 when it enters this block. unchecked { result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; result = (result + x / result) >> 1; // Seven iterations should be enough uint256 roundedDownResult = x / result; return result >= roundedDownResult ? roundedDownResult : result; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": { "contracts/libraries/BinarySearchTree.sol": { "BinarySearchTreeLib": "0xb110480b7bd32f7ebccfb1a4247a242801530cdc" }, "contracts/libraries/LongTermOrders.sol": { "LongTermOrdersLib": "0xad983b0baee93338ff58f61bbb4f6f74abdb68ce" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_tokenA","type":"address"},{"internalType":"address","name":"_tokenB","type":"address"},{"internalType":"address","name":"_twamm","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"PRBMathUD60x18__FromUintOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"PRBMathUD60x18__SqrtOverflow","type":"error"},{"inputs":[{"internalType":"uint256","name":"prod1","type":"uint256"}],"name":"PRBMath__MulDivFixedPointOverflow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"unsoldAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"purchasedAmount","type":"uint256"}],"name":"CancelLongTermOrder","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountA","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountB","type":"uint256"}],"name":"InitialLiquidityProvided","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountAIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountBOut","type":"uint256"}],"name":"InstantSwapAToB","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountBIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountAOut","type":"uint256"}],"name":"InstantSwapBToA","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountAIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountBIn","type":"uint256"}],"name":"LiquidityProvided","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountAOut","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountBOut","type":"uint256"}],"name":"LiquidityRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountAIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"LongTermSwapAToB","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountBIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"LongTermSwapBToA","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"proceeds","type":"uint256"}],"name":"WithdrawProceedsFromLongTermOrder","type":"event"},{"inputs":[],"name":"LP_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"cancelLongTermSwap","outputs":[{"internalType":"uint256","name":"unsoldAmount","type":"uint256"},{"internalType":"uint256","name":"purchasedAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"executeVirtualOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExpiriesSinceLastExecuted","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"getOrderDetails","outputs":[{"components":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"submitBlock","type":"uint256"},{"internalType":"uint256","name":"expirationBlock","type":"uint256"},{"internalType":"uint256","name":"saleRate","type":"uint256"},{"internalType":"uint256","name":"sellAmount","type":"uint256"},{"internalType":"uint256","name":"buyAmount","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"sellTokenId","type":"address"},{"internalType":"address","name":"buyTokenId","type":"address"}],"internalType":"struct LongTermOrdersLib.Order","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"getOrderRewardFactor","outputs":[{"internalType":"uint256","name":"orderRewardFactorAtSubmission","type":"uint256"},{"internalType":"uint256","name":"orderRewardFactorAtExpiring","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPairOrdersAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"getTWAMMSalesRateEnding","outputs":[{"internalType":"uint256","name":"orderPoolASalesRateEnding","type":"uint256"},{"internalType":"uint256","name":"orderPoolBSalesRateEnding","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTWAMMState","outputs":[{"internalType":"uint256","name":"lastVirtualOrderBlock","type":"uint256"},{"internalType":"uint256","name":"tokenASalesRate","type":"uint256"},{"internalType":"uint256","name":"tokenBSalesRate","type":"uint256"},{"internalType":"uint256","name":"orderPoolARewardFactor","type":"uint256"},{"internalType":"uint256","name":"orderPoolBRewardFactor","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amountAIn","type":"uint256"}],"name":"instantSwapFromAToB","outputs":[{"internalType":"uint256","name":"amountBOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amountBIn","type":"uint256"}],"name":"instantSwapFromBToA","outputs":[{"internalType":"uint256","name":"amountAOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amountAIn","type":"uint256"},{"internalType":"uint256","name":"numberOfBlockIntervals","type":"uint256"}],"name":"longTermSwapFromAToB","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"amountBIn","type":"uint256"},{"internalType":"uint256","name":"numberOfBlockIntervals","type":"uint256"}],"name":"longTermSwapFromBToA","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"orderBlockInterval","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"orderIdStatusCheck","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"}],"name":"provideInitialLiquidity","outputs":[{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"}],"name":"provideLiquidity","outputs":[{"internalType":"uint256","name":"amountAIn","type":"uint256"},{"internalType":"uint256","name":"amountBIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amountAOut","type":"uint256"},{"internalType":"uint256","name":"amountBOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"reserveMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rootKLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenA","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenB","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenBReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"}],"name":"userIdsCheck","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"}],"name":"withdrawProceedsFromLongTermSwap","outputs":[{"internalType":"uint256","name":"proceeds","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405260016005553480156200001657600080fd5b50604051620030b7380380620030b783398101604081905262000039916200023f565b6040805180820182526009815268050756c7361722d4c560bc1b602080830191825283518085019094526006845265050554c2d4c560d41b90840152815191929162000088916003916200017c565b5080516200009e9060049060208401906200017c565b505060068054336001600160a01b0319918216179091556007805482166001600160a01b038781169182179092556008805484168784169081179091556009805490941692861692831790935560405163b71522cf60e01b8152600c6004820152602481019190915260448101929092526064820152436084820152600560a482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce915063b71522cf9060c40160006040518083038186803b1580156200015a57600080fd5b505af41580156200016f573d6000803e3d6000fd5b50505050505050620002c6565b8280546200018a9062000289565b90600052602060002090601f016020900481019282620001ae5760008555620001f9565b82601f10620001c957805160ff1916838001178555620001f9565b82800160010185558215620001f9579182015b82811115620001f9578251825591602001919060010190620001dc565b50620002079291506200020b565b5090565b5b808211156200020757600081556001016200020c565b80516001600160a01b03811681146200023a57600080fd5b919050565b6000806000606084860312156200025557600080fd5b620002608462000222565b9250620002706020850162000222565b9150620002806040850162000222565b90509250925092565b600181811c908216806200029e57607f821691505b60208210811415620002c057634e487b7160e01b600052602260045260246000fd5b50919050565b612de180620002d66000396000f3fe608060405234801561001057600080fd5b506004361061023d5760003560e01c806366f55ece1161013b578063a9059cbb116100b8578063ceb2894c1161007c578063ceb2894c146105fc578063d5d859c11461061c578063dd62ed3e1461062f578063e098ef9714610668578063ec7dd7bb1461067157600080fd5b8063a9059cbb146105b3578063b61aaa54146105c6578063bde1077e146105ce578063c45a0155146105e1578063c4e41b22146105f457600080fd5b806395d89b41116100ff57806395d89b411461051157806398267d2e146105195780639c48a8f91461057a578063a201ccf61461058d578063a457c2d7146105a057600080fd5b806366f55ece146103fa5780636726aec01461041d5780636f9d42d21461047857806370a082311461048b578063769b1cf4146104b457600080fd5b806337bc5e4a116101c95780635e3f27271161018d5780635e3f2727146103b15780635f64b55b146103b95780635fea6120146103cc57806360a9d505146103df578063659509c5146103e757600080fd5b806337bc5e4a1461032357806339509351146103365780633a8c885e146103495780633b4a6bc31461036957806342b98a141461038957600080fd5b806318160ddd1161021057806318160ddd146102cf57806323b872dd146102d757806325ca3964146102ea5780632e0ae375146102ff578063313ce5671461031457600080fd5b806306fdde0314610242578063095ea7b3146102605780630fc63d101461028357806313bf4fd2146102ae575b600080fd5b61024a610691565b6040516102579190612956565b60405180910390f35b61027361026e3660046129a1565b610723565b6040519015158152602001610257565b600754610296906001600160a01b031681565b6040516001600160a01b039091168152602001610257565b6102c16102bc3660046129a1565b61073a565b604051908152602001610257565b6002546102c1565b6102736102e53660046129cd565b61088a565b6102f2610936565b6040516102579190612a0e565b61031261030d366004612a52565b610a0f565b005b60405160128152602001610257565b6102f2610331366004612a6b565b610a83565b6102736103443660046129a1565b610aef565b6102c1610357366004612a6b565b600b6020526000908152604090205481565b6007546001600160a01b03166000908152600b60205260409020546102c1565b61039c6103973660046129a1565b610b2b565b60408051928352602083019190915201610257565b6102c1601e81565b600854610296906001600160a01b031681565b61039c6103da3660046129a1565b610c7f565b6102c1600581565b6102c16103f5366004612a88565b610f73565b610273610408366004612a52565b60009081526015602052604090205460ff1690565b61039c61042b366004612a52565b6007546001600160a01b0390811660009081526011602081815260408084208685526002908101835281852054600854909616855292825280842095845294909101905291909120549091565b6102c1610486366004612a88565b611140565b6102c1610499366004612a6b565b6001600160a01b031660009081526020819052604090205490565b61039c6104c2366004612a52565b600081815260136020908152604080832060078101546002909101546001600160a01b039091168452601183528184209484526005850183528184205490845260069094019091529020549091565b61024a6112e5565b600d546007546001600160a01b0390811660009081526011602090815260408083208054600854909516845292819020805460019485015494909101548251968752928601949094528401929092526060830152608082015260a001610257565b6102c16105883660046129a1565b6112f4565b61039c61059b3660046129a1565b611427565b6102736105ae3660046129a1565b6116f7565b6102736105c13660046129a1565b611790565b6012546102c1565b6102c16105dc366004612a88565b61179d565b600654610296906001600160a01b031681565b6102c161195a565b6008546001600160a01b03166000908152600b60205260409020546102c1565b6102c161062a3660046129a1565b61196a565b6102c161063d366004612abd565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6102c1600a5481565b61068461067f366004612a52565b611a9d565b6040516102579190612af6565b6060600380546106a090612b72565b80601f01602080910402602001604051908101604052809291908181526020018280546106cc90612b72565b80156107195780601f106106ee57610100808354040283529160200191610719565b820191906000526020600020905b8154815290600101906020018083116106fc57829003601f168201915b5050505050905090565b6000610730338484611b90565b5060015b92915050565b6009546000906001600160a01b031633146107705760405162461bcd60e51b815260040161076790612bad565b60405180910390fd5b6005546001146107925760405162461bcd60e51b815260040161076790612bd5565b6002600555604051634b7446ff60e01b8152600c60048201526001600160a01b038416602482015260448101839052600b606482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90634b7446ff9060840160206040518083038186803b1580156107ff57600080fd5b505af4158015610813573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108379190612bf9565b60408051848152602081018390529192506001600160a01b038516917f79ad14fdc35ed5b53e895a80c1e26ecfd7b87c91f1659e6aa84fefb0841a02a291015b60405180910390a2600160055592915050565b6000610897848484611cb5565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561091c5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610767565b6109298533858403611b90565b60019150505b9392505050565b6040516378dbfc8160e11b81526016600482015260609073b110480b7bd32f7ebccfb1a4247a242801530cdc9063f1b7f9029060240160206040518083038186803b15801561098457600080fd5b505af4158015610998573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109bc9190612bf9565b80548060200260200160405190810160405280929190818152602001828054801561071957602002820191906000526020600020905b8154815260200190600101908083116109f2575050505050905090565b6040516357647c7f60e11b8152600c6004820152600b60248201526044810182905273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b158015610a6857600080fd5b505af4158015610a7c573d6000803e3d6000fd5b5050505050565b6001600160a01b038116600090815260146020908152604091829020805483518184028101840190945280845260609392830182828015610ae357602002820191906000526020600020905b815481526020019060010190808311610acf575b50505050509050919050565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610730918590610b26908690612c28565b611b90565b60095460009081906001600160a01b03163314610b5a5760405162461bcd60e51b815260040161076790612bad565b600554600114610b7c5760405162461bcd60e51b815260040161076790612bd5565b60026005556040516303bdeec560e41b8152600c60048201526001600160a01b038516602482015260448101849052600b606482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90633bdeec5090608401604080518083038186803b158015610be857600080fd5b505af4158015610bfc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c209190612c40565b604080518681526020810184905290810182905291935091506001600160a01b038516907f5187cf882c722b1f3c2b67d751013259c0cb8f36161622ce83ae6b8f6f163f539060600160405180910390a2600160055590939092509050565b60095460009081906001600160a01b03163314610cae5760405162461bcd60e51b815260040161076790612bad565b600554600114610cd05760405162461bcd60e51b815260040161076790612bd5565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b158015610d2d57600080fd5b505af4158015610d41573d6000803e3d6000fd5b5050505060008311610d655760405162461bcd60e51b815260040161076790612c64565b600254610dbf5760405162461bcd60e51b815260206004820152602260248201527f4e6f204c697175696469747920486173204265656e2050726f76696465642059604482015261195d60f21b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220546008549093168252902054600254610df58387612c8c565b610dff9190612cc1565b9350610e0a60025490565b610e148287612c8c565b610e1e9190612cc1565b6007546001600160a01b03166000908152600b6020526040812080549295508692909190610e4d908490612c28565b90915550506008546001600160a01b03166000908152600b602052604081208054859290610e7c908490612c28565b9091555060009050610e8e8383611e85565b9050610e9a8787612063565b8015610f15576008546001600160a01b03166000908152600b6020526040902054610f1190610f0390610ed590610ed090612142565b61218f565b6007546001600160a01b03166000908152600b6020526040902054610efd90610ed090612142565b906121e1565b670de0b6b3a7640000900490565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f3bca7014f4c0ccc8016338c79f4c00e82068dbadaf4f01ca5449040fdd39f500906060015b60405180910390a2505060016005555090939092509050565b6009546000906001600160a01b03163314610fa05760405162461bcd60e51b815260040161076790612bad565b600554600114610fc25760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061100957506008546001600160a01b03166000908152600b602052604090205415155b6110255760405162461bcd60e51b815260040161076790612ce3565b600083116110455760405162461bcd60e51b815260040161076790612c64565b60405163233d824760e21b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90638cf6091c9060a40160206040518083038186803b1580156110b457600080fd5b505af41580156110c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ec9190612bf9565b60408051858152602081018390529192506001600160a01b038616917f3f9021da39409c8415526f6f5150f90f549aff31c146178262479dd87789440091015b60405180910390a260016005559392505050565b6009546000906001600160a01b0316331461116d5760405162461bcd60e51b815260040161076790612bad565b60055460011461118f5760405162461bcd60e51b815260040161076790612bd5565b600260055582158015906111a35750600082115b6111bf5760405162461bcd60e51b815260040161076790612c64565b6002541561121b5760405162461bcd60e51b815260206004820152602360248201527f4c69717569646974792048617320416c7265616479204265656e2050726f766960448201526219195960ea1b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220869055600854909216815220829055611265610f03611259610ed085612142565b610efd610ed087612142565b90506000611274600080611e85565b90506112808583612063565b801561128c57600a8290555b60408051838152602081018690529081018490526001600160a01b038616907f9e20617171fe14c750c3beebe1b256358b9688a6e6047c4dd5e1e81c003c44b89060600160405180910390a25060016005559392505050565b6060600480546106a090612b72565b6009546000906001600160a01b031633146113215760405162461bcd60e51b815260040161076790612bad565b6005546001146113435760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061138a57506008546001600160a01b03166000908152600b602052604090205415155b6113a65760405162461bcd60e51b815260040161076790612ce3565b600082116113c65760405162461bcd60e51b815260040161076790612c64565b6008546007546113e3916001600160a01b039081169116846121ed565b60408051848152602081018390529192506001600160a01b038516917f4af12e31478f230aa2cdfffcb6fe9525e6d1862db211087abb6fd8771ccdbe579101610877565b60095460009081906001600160a01b031633146114565760405162461bcd60e51b815260040161076790612bad565b6005546001146114785760405162461bcd60e51b815260040161076790612bd5565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b1580156114d557600080fd5b505af41580156114e9573d6000803e3d6000fd5b505050506000831161150d5760405162461bcd60e51b815260040161076790612c64565b60025483111561155f5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420456e6f756768204c7020546f6b656e7320417661696c61626c6500006044820152606401610767565b6007546001600160a01b039081166000908152600b60205260408082205460085490931682529020546002546115958684612c8c565b61159f9190612cc1565b93506115aa60025490565b6115b48683612c8c565b6115be9190612cc1565b6007546001600160a01b03166000908152600b60205260408120805492955086929091906115ed908490612d13565b90915550506008546001600160a01b03166000908152600b60205260408120805485929061161c908490612d13565b909155506000905061162e8383611e85565b905061163a8787612373565b600954600754611657916001600160a01b039182169116876124be565b600954600854611674916001600160a01b039182169116866124be565b80156116ae576008546001600160a01b03166000908152600b60205260409020546116aa90610f0390610ed590610ed090612142565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f1dc8bb69df2b8e91fbdcbfcf93d951b3f0000f085a95fe3f7946d6161439245d90606001610f5a565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156117795760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610767565b6117863385858403611b90565b5060019392505050565b6000610730338484611cb5565b6009546000906001600160a01b031633146117ca5760405162461bcd60e51b815260040161076790612bad565b6005546001146117ec5760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061183357506008546001600160a01b03166000908152600b602052604090205415155b61184f5760405162461bcd60e51b815260040161076790612ce3565b6000831161186f5760405162461bcd60e51b815260040161076790612c64565b604051632d2f332560e11b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90635a5e664a9060a40160206040518083038186803b1580156118de57600080fd5b505af41580156118f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119169190612bf9565b60408051858152602081018390529192506001600160a01b038616917f3118cfac1ed5d8e668c193690497d56fff82f1aabbdf08f598025b0dfe308727910161112c565b600061196560025490565b905090565b6009546000906001600160a01b031633146119975760405162461bcd60e51b815260040161076790612bad565b6005546001146119b95760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b602052604090205415801590611a0057506008546001600160a01b03166000908152600b602052604090205415155b611a1c5760405162461bcd60e51b815260040161076790612ce3565b60008211611a3c5760405162461bcd60e51b815260040161076790612c64565b600754600854611a59916001600160a01b039081169116846121ed565b60408051848152602081018390529192506001600160a01b038516917f4d8578764edd2464e6964176a4bbedef1497b6bed5dd14e0609ad9149a85e5fe9101610877565b611b0760405180610120016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b50600090815260136020908152604091829020825161012081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546080820152600582015460a082015260068201546001600160a01b0390811660c08301526007830154811660e083015260089092015490911661010082015290565b6001600160a01b038316611bf25760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610767565b6001600160a01b038216611c535760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610767565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316611d195760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610767565b6001600160a01b038216611d7b5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610767565b6001600160a01b03831660009081526020819052604090205481811015611df35760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610767565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611e2a908490612c28565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611e7691815260200190565b60405180910390a35b50505050565b600080600660009054906101000a90046001600160a01b03166001600160a01b031663793855486040518163ffffffff1660e01b815260040160206040518083038186803b158015611ed657600080fd5b505afa158015611eea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0e9190612d2a565b90506000600660009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611f6057600080fd5b505afa158015611f74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f989190612d50565b6001600160a01b038116158015945090915061204d57600a5415612048576000611fd6610f03611fca610ed088612142565b610efd610ed08a612142565b9050600a54811115612046576000600a5482611ff29190612d13565b600254611fff9190612c8c565b90506000600a548563ffffffff16846120189190612c8c565b6120229190612c28565b905060006120308284612cc1565b90508015612042576120428582612063565b5050505b505b61205b565b600a541561205b576000600a555b505092915050565b6001600160a01b0382166120b95760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610767565b80600260008282546120cb9190612c28565b90915550506001600160a01b038216600090815260208190526040812080548392906120f8908490612c28565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f2182111561218157604051633492ffd960e01b815260048101839052602401610767565b50670de0b6b3a76400000290565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218211156121ce57604051636155b67d60e01b815260048101839052602401610767565b610734670de0b6b3a76400008302612510565b600061092f838361268b565b6009546000906001600160a01b0316331461221a5760405162461bcd60e51b815260040161076790612bad565b6040516357647c7f60e11b8152600c6004820152600b602482015243604482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b15801561227257600080fd5b505af4158015612286573d6000803e3d6000fd5b505050506001600160a01b038481166000908152600b6020526040808220549286168252812054906122b88584612c28565b6122c28684612c8c565b6122cc9190612cc1565b90506127106122dc601e82612d13565b6122e69083612c8c565b6122f09190612cc1565b6001600160a01b0388166000908152600b602052604081208054929650879290919061231d908490612c28565b90915550506001600160a01b0386166000908152600b60205260408120805486929061234a908490612d13565b9091555050600954612369906001600160a01b038881169116866124be565b5050509392505050565b6001600160a01b0382166123d35760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610767565b6001600160a01b038216600090815260208190526040902054818110156124475760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610767565b6001600160a01b0383166000908152602081905260408120838303905560028054849290612476908490612d13565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001611ca8565b505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526124b990849061274d565b60008161251f57506000919050565b50600181600160801b81106125395760409190911b9060801c5b6801000000000000000081106125545760209190911b9060401c5b640100000000811061256b5760109190911b9060201c5b6201000081106125805760089190911b9060101c5b61010081106125945760049190911b9060081c5b601081106125a75760029190911b9060041c5b600881106125b757600182901b91505b60018284816125c8576125c8612cab565b048301901c915060018284816125e0576125e0612cab565b048301901c915060018284816125f8576125f8612cab565b048301901c9150600182848161261057612610612cab565b048301901c9150600182848161262857612628612cab565b048301901c9150600182848161264057612640612cab565b048301901c9150600182848161265857612658612cab565b048301901c9150600082848161267057612670612cab565b049050808310156126815782612683565b805b949350505050565b60008080600019848609848602925082811083820303915050670de0b6b3a764000081106126cf5760405163698d9a0160e11b815260048101829052602401610767565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826127095780670de0b6b3a7640000850401945050505050610734565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b60006127a2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661281f9092919063ffffffff16565b8051909150156124b957808060200190518101906127c09190612d6d565b6124b95760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610767565b6060612683848460008585843b6128785760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610767565b600080866001600160a01b031685876040516128949190612d8f565b60006040518083038185875af1925050503d80600081146128d1576040519150601f19603f3d011682016040523d82523d6000602084013e6128d6565b606091505b50915091506128e68282866128f1565b979650505050505050565b6060831561290057508161092f565b8251156129105782518084602001fd5b8160405162461bcd60e51b81526004016107679190612956565b60005b8381101561294557818101518382015260200161292d565b83811115611e7f5750506000910152565b602081526000825180602084015261297581604085016020870161292a565b601f01601f19169190910160400192915050565b6001600160a01b038116811461299e57600080fd5b50565b600080604083850312156129b457600080fd5b82356129bf81612989565b946020939093013593505050565b6000806000606084860312156129e257600080fd5b83356129ed81612989565b925060208401356129fd81612989565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015612a4657835183529284019291840191600101612a2a565b50909695505050505050565b600060208284031215612a6457600080fd5b5035919050565b600060208284031215612a7d57600080fd5b813561092f81612989565b600080600060608486031215612a9d57600080fd5b8335612aa881612989565b95602085013595506040909401359392505050565b60008060408385031215612ad057600080fd5b8235612adb81612989565b91506020830135612aeb81612989565b809150509250929050565b600061012082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160018060a01b0380821660c08501528060e08601511660e085015250506101008084015161205b828501826001600160a01b03169052565b600181811c90821680612b8657607f821691505b60208210811415612ba757634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252600e908201526d24b73b30b634b21021b0b63632b960911b604082015260600190565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b600060208284031215612c0b57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612c3b57612c3b612c12565b500190565b60008060408385031215612c5357600080fd5b505080516020909101519092909150565b6020808252600e908201526d125b9d985b1a5908105b5bdd5b9d60921b604082015260600190565b6000816000190483118215151615612ca657612ca6612c12565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612cde57634e487b7160e01b600052601260045260246000fd5b500490565b602080825260169082015275496e73756666696369656e74204c697175696469747960501b604082015260600190565b600082821015612d2557612d25612c12565b500390565b600060208284031215612d3c57600080fd5b815163ffffffff8116811461092f57600080fd5b600060208284031215612d6257600080fd5b815161092f81612989565b600060208284031215612d7f57600080fd5b8151801515811461092f57600080fd5b60008251612da181846020870161292a565b919091019291505056fea2646970667358221220b96f8a2dd1a5cb727370003ab2c6e6a931c836c539834835135b2c0d513d4f0764736f6c634300080900330000000000000000000000002a1dca74419c2d304a3d359f428ee1a4e9324a90000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000cd43aba971bef65555d877657f83093ddfb885b8
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061023d5760003560e01c806366f55ece1161013b578063a9059cbb116100b8578063ceb2894c1161007c578063ceb2894c146105fc578063d5d859c11461061c578063dd62ed3e1461062f578063e098ef9714610668578063ec7dd7bb1461067157600080fd5b8063a9059cbb146105b3578063b61aaa54146105c6578063bde1077e146105ce578063c45a0155146105e1578063c4e41b22146105f457600080fd5b806395d89b41116100ff57806395d89b411461051157806398267d2e146105195780639c48a8f91461057a578063a201ccf61461058d578063a457c2d7146105a057600080fd5b806366f55ece146103fa5780636726aec01461041d5780636f9d42d21461047857806370a082311461048b578063769b1cf4146104b457600080fd5b806337bc5e4a116101c95780635e3f27271161018d5780635e3f2727146103b15780635f64b55b146103b95780635fea6120146103cc57806360a9d505146103df578063659509c5146103e757600080fd5b806337bc5e4a1461032357806339509351146103365780633a8c885e146103495780633b4a6bc31461036957806342b98a141461038957600080fd5b806318160ddd1161021057806318160ddd146102cf57806323b872dd146102d757806325ca3964146102ea5780632e0ae375146102ff578063313ce5671461031457600080fd5b806306fdde0314610242578063095ea7b3146102605780630fc63d101461028357806313bf4fd2146102ae575b600080fd5b61024a610691565b6040516102579190612956565b60405180910390f35b61027361026e3660046129a1565b610723565b6040519015158152602001610257565b600754610296906001600160a01b031681565b6040516001600160a01b039091168152602001610257565b6102c16102bc3660046129a1565b61073a565b604051908152602001610257565b6002546102c1565b6102736102e53660046129cd565b61088a565b6102f2610936565b6040516102579190612a0e565b61031261030d366004612a52565b610a0f565b005b60405160128152602001610257565b6102f2610331366004612a6b565b610a83565b6102736103443660046129a1565b610aef565b6102c1610357366004612a6b565b600b6020526000908152604090205481565b6007546001600160a01b03166000908152600b60205260409020546102c1565b61039c6103973660046129a1565b610b2b565b60408051928352602083019190915201610257565b6102c1601e81565b600854610296906001600160a01b031681565b61039c6103da3660046129a1565b610c7f565b6102c1600581565b6102c16103f5366004612a88565b610f73565b610273610408366004612a52565b60009081526015602052604090205460ff1690565b61039c61042b366004612a52565b6007546001600160a01b0390811660009081526011602081815260408084208685526002908101835281852054600854909616855292825280842095845294909101905291909120549091565b6102c1610486366004612a88565b611140565b6102c1610499366004612a6b565b6001600160a01b031660009081526020819052604090205490565b61039c6104c2366004612a52565b600081815260136020908152604080832060078101546002909101546001600160a01b039091168452601183528184209484526005850183528184205490845260069094019091529020549091565b61024a6112e5565b600d546007546001600160a01b0390811660009081526011602090815260408083208054600854909516845292819020805460019485015494909101548251968752928601949094528401929092526060830152608082015260a001610257565b6102c16105883660046129a1565b6112f4565b61039c61059b3660046129a1565b611427565b6102736105ae3660046129a1565b6116f7565b6102736105c13660046129a1565b611790565b6012546102c1565b6102c16105dc366004612a88565b61179d565b600654610296906001600160a01b031681565b6102c161195a565b6008546001600160a01b03166000908152600b60205260409020546102c1565b6102c161062a3660046129a1565b61196a565b6102c161063d366004612abd565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6102c1600a5481565b61068461067f366004612a52565b611a9d565b6040516102579190612af6565b6060600380546106a090612b72565b80601f01602080910402602001604051908101604052809291908181526020018280546106cc90612b72565b80156107195780601f106106ee57610100808354040283529160200191610719565b820191906000526020600020905b8154815290600101906020018083116106fc57829003601f168201915b5050505050905090565b6000610730338484611b90565b5060015b92915050565b6009546000906001600160a01b031633146107705760405162461bcd60e51b815260040161076790612bad565b60405180910390fd5b6005546001146107925760405162461bcd60e51b815260040161076790612bd5565b6002600555604051634b7446ff60e01b8152600c60048201526001600160a01b038416602482015260448101839052600b606482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90634b7446ff9060840160206040518083038186803b1580156107ff57600080fd5b505af4158015610813573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108379190612bf9565b60408051848152602081018390529192506001600160a01b038516917f79ad14fdc35ed5b53e895a80c1e26ecfd7b87c91f1659e6aa84fefb0841a02a291015b60405180910390a2600160055592915050565b6000610897848484611cb5565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561091c5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610767565b6109298533858403611b90565b60019150505b9392505050565b6040516378dbfc8160e11b81526016600482015260609073b110480b7bd32f7ebccfb1a4247a242801530cdc9063f1b7f9029060240160206040518083038186803b15801561098457600080fd5b505af4158015610998573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109bc9190612bf9565b80548060200260200160405190810160405280929190818152602001828054801561071957602002820191906000526020600020905b8154815260200190600101908083116109f2575050505050905090565b6040516357647c7f60e11b8152600c6004820152600b60248201526044810182905273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b158015610a6857600080fd5b505af4158015610a7c573d6000803e3d6000fd5b5050505050565b6001600160a01b038116600090815260146020908152604091829020805483518184028101840190945280845260609392830182828015610ae357602002820191906000526020600020905b815481526020019060010190808311610acf575b50505050509050919050565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610730918590610b26908690612c28565b611b90565b60095460009081906001600160a01b03163314610b5a5760405162461bcd60e51b815260040161076790612bad565b600554600114610b7c5760405162461bcd60e51b815260040161076790612bd5565b60026005556040516303bdeec560e41b8152600c60048201526001600160a01b038516602482015260448101849052600b606482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90633bdeec5090608401604080518083038186803b158015610be857600080fd5b505af4158015610bfc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c209190612c40565b604080518681526020810184905290810182905291935091506001600160a01b038516907f5187cf882c722b1f3c2b67d751013259c0cb8f36161622ce83ae6b8f6f163f539060600160405180910390a2600160055590939092509050565b60095460009081906001600160a01b03163314610cae5760405162461bcd60e51b815260040161076790612bad565b600554600114610cd05760405162461bcd60e51b815260040161076790612bd5565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b158015610d2d57600080fd5b505af4158015610d41573d6000803e3d6000fd5b5050505060008311610d655760405162461bcd60e51b815260040161076790612c64565b600254610dbf5760405162461bcd60e51b815260206004820152602260248201527f4e6f204c697175696469747920486173204265656e2050726f76696465642059604482015261195d60f21b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220546008549093168252902054600254610df58387612c8c565b610dff9190612cc1565b9350610e0a60025490565b610e148287612c8c565b610e1e9190612cc1565b6007546001600160a01b03166000908152600b6020526040812080549295508692909190610e4d908490612c28565b90915550506008546001600160a01b03166000908152600b602052604081208054859290610e7c908490612c28565b9091555060009050610e8e8383611e85565b9050610e9a8787612063565b8015610f15576008546001600160a01b03166000908152600b6020526040902054610f1190610f0390610ed590610ed090612142565b61218f565b6007546001600160a01b03166000908152600b6020526040902054610efd90610ed090612142565b906121e1565b670de0b6b3a7640000900490565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f3bca7014f4c0ccc8016338c79f4c00e82068dbadaf4f01ca5449040fdd39f500906060015b60405180910390a2505060016005555090939092509050565b6009546000906001600160a01b03163314610fa05760405162461bcd60e51b815260040161076790612bad565b600554600114610fc25760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061100957506008546001600160a01b03166000908152600b602052604090205415155b6110255760405162461bcd60e51b815260040161076790612ce3565b600083116110455760405162461bcd60e51b815260040161076790612c64565b60405163233d824760e21b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90638cf6091c9060a40160206040518083038186803b1580156110b457600080fd5b505af41580156110c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ec9190612bf9565b60408051858152602081018390529192506001600160a01b038616917f3f9021da39409c8415526f6f5150f90f549aff31c146178262479dd87789440091015b60405180910390a260016005559392505050565b6009546000906001600160a01b0316331461116d5760405162461bcd60e51b815260040161076790612bad565b60055460011461118f5760405162461bcd60e51b815260040161076790612bd5565b600260055582158015906111a35750600082115b6111bf5760405162461bcd60e51b815260040161076790612c64565b6002541561121b5760405162461bcd60e51b815260206004820152602360248201527f4c69717569646974792048617320416c7265616479204265656e2050726f766960448201526219195960ea1b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220869055600854909216815220829055611265610f03611259610ed085612142565b610efd610ed087612142565b90506000611274600080611e85565b90506112808583612063565b801561128c57600a8290555b60408051838152602081018690529081018490526001600160a01b038616907f9e20617171fe14c750c3beebe1b256358b9688a6e6047c4dd5e1e81c003c44b89060600160405180910390a25060016005559392505050565b6060600480546106a090612b72565b6009546000906001600160a01b031633146113215760405162461bcd60e51b815260040161076790612bad565b6005546001146113435760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061138a57506008546001600160a01b03166000908152600b602052604090205415155b6113a65760405162461bcd60e51b815260040161076790612ce3565b600082116113c65760405162461bcd60e51b815260040161076790612c64565b6008546007546113e3916001600160a01b039081169116846121ed565b60408051848152602081018390529192506001600160a01b038516917f4af12e31478f230aa2cdfffcb6fe9525e6d1862db211087abb6fd8771ccdbe579101610877565b60095460009081906001600160a01b031633146114565760405162461bcd60e51b815260040161076790612bad565b6005546001146114785760405162461bcd60e51b815260040161076790612bd5565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b1580156114d557600080fd5b505af41580156114e9573d6000803e3d6000fd5b505050506000831161150d5760405162461bcd60e51b815260040161076790612c64565b60025483111561155f5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420456e6f756768204c7020546f6b656e7320417661696c61626c6500006044820152606401610767565b6007546001600160a01b039081166000908152600b60205260408082205460085490931682529020546002546115958684612c8c565b61159f9190612cc1565b93506115aa60025490565b6115b48683612c8c565b6115be9190612cc1565b6007546001600160a01b03166000908152600b60205260408120805492955086929091906115ed908490612d13565b90915550506008546001600160a01b03166000908152600b60205260408120805485929061161c908490612d13565b909155506000905061162e8383611e85565b905061163a8787612373565b600954600754611657916001600160a01b039182169116876124be565b600954600854611674916001600160a01b039182169116866124be565b80156116ae576008546001600160a01b03166000908152600b60205260409020546116aa90610f0390610ed590610ed090612142565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f1dc8bb69df2b8e91fbdcbfcf93d951b3f0000f085a95fe3f7946d6161439245d90606001610f5a565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156117795760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610767565b6117863385858403611b90565b5060019392505050565b6000610730338484611cb5565b6009546000906001600160a01b031633146117ca5760405162461bcd60e51b815260040161076790612bad565b6005546001146117ec5760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061183357506008546001600160a01b03166000908152600b602052604090205415155b61184f5760405162461bcd60e51b815260040161076790612ce3565b6000831161186f5760405162461bcd60e51b815260040161076790612c64565b604051632d2f332560e11b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce90635a5e664a9060a40160206040518083038186803b1580156118de57600080fd5b505af41580156118f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119169190612bf9565b60408051858152602081018390529192506001600160a01b038616917f3118cfac1ed5d8e668c193690497d56fff82f1aabbdf08f598025b0dfe308727910161112c565b600061196560025490565b905090565b6009546000906001600160a01b031633146119975760405162461bcd60e51b815260040161076790612bad565b6005546001146119b95760405162461bcd60e51b815260040161076790612bd5565b60026005556007546001600160a01b03166000908152600b602052604090205415801590611a0057506008546001600160a01b03166000908152600b602052604090205415155b611a1c5760405162461bcd60e51b815260040161076790612ce3565b60008211611a3c5760405162461bcd60e51b815260040161076790612c64565b600754600854611a59916001600160a01b039081169116846121ed565b60408051848152602081018390529192506001600160a01b038516917f4d8578764edd2464e6964176a4bbedef1497b6bed5dd14e0609ad9149a85e5fe9101610877565b611b0760405180610120016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b50600090815260136020908152604091829020825161012081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546080820152600582015460a082015260068201546001600160a01b0390811660c08301526007830154811660e083015260089092015490911661010082015290565b6001600160a01b038316611bf25760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610767565b6001600160a01b038216611c535760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610767565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316611d195760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610767565b6001600160a01b038216611d7b5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610767565b6001600160a01b03831660009081526020819052604090205481811015611df35760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610767565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611e2a908490612c28565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611e7691815260200190565b60405180910390a35b50505050565b600080600660009054906101000a90046001600160a01b03166001600160a01b031663793855486040518163ffffffff1660e01b815260040160206040518083038186803b158015611ed657600080fd5b505afa158015611eea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0e9190612d2a565b90506000600660009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611f6057600080fd5b505afa158015611f74573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f989190612d50565b6001600160a01b038116158015945090915061204d57600a5415612048576000611fd6610f03611fca610ed088612142565b610efd610ed08a612142565b9050600a54811115612046576000600a5482611ff29190612d13565b600254611fff9190612c8c565b90506000600a548563ffffffff16846120189190612c8c565b6120229190612c28565b905060006120308284612cc1565b90508015612042576120428582612063565b5050505b505b61205b565b600a541561205b576000600a555b505092915050565b6001600160a01b0382166120b95760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610767565b80600260008282546120cb9190612c28565b90915550506001600160a01b038216600090815260208190526040812080548392906120f8908490612c28565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f2182111561218157604051633492ffd960e01b815260048101839052602401610767565b50670de0b6b3a76400000290565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218211156121ce57604051636155b67d60e01b815260048101839052602401610767565b610734670de0b6b3a76400008302612510565b600061092f838361268b565b6009546000906001600160a01b0316331461221a5760405162461bcd60e51b815260040161076790612bad565b6040516357647c7f60e11b8152600c6004820152600b602482015243604482015273ad983b0baee93338ff58f61bbb4f6f74abdb68ce9063aec8f8fe9060640160006040518083038186803b15801561227257600080fd5b505af4158015612286573d6000803e3d6000fd5b505050506001600160a01b038481166000908152600b6020526040808220549286168252812054906122b88584612c28565b6122c28684612c8c565b6122cc9190612cc1565b90506127106122dc601e82612d13565b6122e69083612c8c565b6122f09190612cc1565b6001600160a01b0388166000908152600b602052604081208054929650879290919061231d908490612c28565b90915550506001600160a01b0386166000908152600b60205260408120805486929061234a908490612d13565b9091555050600954612369906001600160a01b038881169116866124be565b5050509392505050565b6001600160a01b0382166123d35760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610767565b6001600160a01b038216600090815260208190526040902054818110156124475760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610767565b6001600160a01b0383166000908152602081905260408120838303905560028054849290612476908490612d13565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001611ca8565b505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526124b990849061274d565b60008161251f57506000919050565b50600181600160801b81106125395760409190911b9060801c5b6801000000000000000081106125545760209190911b9060401c5b640100000000811061256b5760109190911b9060201c5b6201000081106125805760089190911b9060101c5b61010081106125945760049190911b9060081c5b601081106125a75760029190911b9060041c5b600881106125b757600182901b91505b60018284816125c8576125c8612cab565b048301901c915060018284816125e0576125e0612cab565b048301901c915060018284816125f8576125f8612cab565b048301901c9150600182848161261057612610612cab565b048301901c9150600182848161262857612628612cab565b048301901c9150600182848161264057612640612cab565b048301901c9150600182848161265857612658612cab565b048301901c9150600082848161267057612670612cab565b049050808310156126815782612683565b805b949350505050565b60008080600019848609848602925082811083820303915050670de0b6b3a764000081106126cf5760405163698d9a0160e11b815260048101829052602401610767565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826127095780670de0b6b3a7640000850401945050505050610734565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b60006127a2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661281f9092919063ffffffff16565b8051909150156124b957808060200190518101906127c09190612d6d565b6124b95760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610767565b6060612683848460008585843b6128785760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610767565b600080866001600160a01b031685876040516128949190612d8f565b60006040518083038185875af1925050503d80600081146128d1576040519150601f19603f3d011682016040523d82523d6000602084013e6128d6565b606091505b50915091506128e68282866128f1565b979650505050505050565b6060831561290057508161092f565b8251156129105782518084602001fd5b8160405162461bcd60e51b81526004016107679190612956565b60005b8381101561294557818101518382015260200161292d565b83811115611e7f5750506000910152565b602081526000825180602084015261297581604085016020870161292a565b601f01601f19169190910160400192915050565b6001600160a01b038116811461299e57600080fd5b50565b600080604083850312156129b457600080fd5b82356129bf81612989565b946020939093013593505050565b6000806000606084860312156129e257600080fd5b83356129ed81612989565b925060208401356129fd81612989565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015612a4657835183529284019291840191600101612a2a565b50909695505050505050565b600060208284031215612a6457600080fd5b5035919050565b600060208284031215612a7d57600080fd5b813561092f81612989565b600080600060608486031215612a9d57600080fd5b8335612aa881612989565b95602085013595506040909401359392505050565b60008060408385031215612ad057600080fd5b8235612adb81612989565b91506020830135612aeb81612989565b809150509250929050565b600061012082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160018060a01b0380821660c08501528060e08601511660e085015250506101008084015161205b828501826001600160a01b03169052565b600181811c90821680612b8657607f821691505b60208210811415612ba757634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252600e908201526d24b73b30b634b21021b0b63632b960911b604082015260600190565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b600060208284031215612c0b57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612c3b57612c3b612c12565b500190565b60008060408385031215612c5357600080fd5b505080516020909101519092909150565b6020808252600e908201526d125b9d985b1a5908105b5bdd5b9d60921b604082015260600190565b6000816000190483118215151615612ca657612ca6612c12565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612cde57634e487b7160e01b600052601260045260246000fd5b500490565b602080825260169082015275496e73756666696369656e74204c697175696469747960501b604082015260600190565b600082821015612d2557612d25612c12565b500390565b600060208284031215612d3c57600080fd5b815163ffffffff8116811461092f57600080fd5b600060208284031215612d6257600080fd5b815161092f81612989565b600060208284031215612d7f57600080fd5b8151801515811461092f57600080fd5b60008251612da181846020870161292a565b919091019291505056fea2646970667358221220b96f8a2dd1a5cb727370003ab2c6e6a931c836c539834835135b2c0d513d4f0764736f6c63430008090033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000002a1dca74419c2d304a3d359f428ee1a4e9324a90000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000cd43aba971bef65555d877657f83093ddfb885b8
-----Decoded View---------------
Arg [0] : _tokenA (address): 0x2A1DCA74419c2D304A3D359F428eE1A4e9324A90
Arg [1] : _tokenB (address): 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
Arg [2] : _twamm (address): 0xcd43AbA971bEF65555D877657F83093dDFB885b8
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000002a1dca74419c2d304a3d359f428ee1a4e9324a90
Arg [1] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [2] : 000000000000000000000000cd43aba971bef65555d877657f83093ddfb885b8
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.