Contract Address Details

0xCA9093676010Fe3c22B764f730B15d2543FD754F

Contract Name
EnergiswapRouterUpgrade_1
Creator
0x069994–523777 at 0xdcc70f–3d29cc
Balance
0.00 NRG
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
274,441 Transfers
Gas Used
Fetching gas used...
Last Balance Update
957507
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
EnergiswapRouterUpgrade_1




Optimization enabled
true
Compiler version
v0.5.16+commit.9c3226ce




Optimization runs
200
EVM Version
istanbul




Verified at
2021-11-28 21:13:21.948449Z

Constructor Arguments

0000000000000000000000002d4eb90118f6fba1191f26eb39f7ff0573f63c220000000000000000000000005e20ef450d204809f23cf1681d8504bc3a18369a000000000000000000000000335adfaa6e499ddeb066efb6d2753ec1baa521de000000000000000000000000de82ca6c25dc770b6304827ad1a2e191602739b6

Arg [0] (address) : 0x2d4eb90118f6fba1191f26eb39f7ff0573f63c22
Arg [1] (address) : 0x5e20ef450d204809f23cf1681d8504bc3a18369a
Arg [2] (address) : 0x335adfaa6e499ddeb066efb6d2753ec1baa521de
Arg [3] (address) : 0xde82ca6c25dc770b6304827ad1a2e191602739b6

              

Contract source code

pragma solidity 0.5.16;
// File: ../../../interfaces/IEnergiswapGovernedContract.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
interface IEnergiswapGovernedContract {
function proxy() external returns(address);
}
// File: ../../../interfaces/IStorageBase.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
interface IStorageBase {
function setOwner(address _newOwner) external;
}
// File: ../../../EnergiswapGovernedContract.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
pragma solidity = 0.5.16;
/**
* Genesis version of GovernedContract common base.
*
* Base Consensus interface for upgradable contracts.
* Unlike common approach, the implementation is NOT expected to be
* called through delegatecall() to minimize risks of shared storage.
*
* NOTE: it MUST NOT change after blockchain launch!
*/
contract EnergiswapGovernedContract is IEnergiswapGovernedContract {
address public proxy;
constructor(address _proxy) public {
proxy = _proxy;
}
modifier requireProxy {
require(msg.sender == proxy, "EnergiswapGovernedContract: FORBIDDEN, not proxy");
_;
}
function getProxy() internal view returns(address _proxy) {
_proxy = proxy;
}
// solium-disable-next-line no-empty-blocks
function _migrate(address) internal {}
function _destroy(address _newImpl) internal {
selfdestruct(address(uint160(_newImpl)));
}
function _callerAddress()
internal view
returns (address payable)
{
if (msg.sender == proxy) {
// This is guarantee of the GovernedProxy
// solium-disable-next-line security/no-tx-origin
return tx.origin;
} else {
return msg.sender;
}
}
}
// File: ../../IEnergiswapRouter.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
//import { EnergiswapRouterStorage } from '../energiswapRouter/EnergiswapRouter.sol';
interface IEnergiswapRouter {
function _storage() external view returns (address);
function destroy(address _newImpl) external;
function migrate(address _oldImpl) external;
function() external payable;
function removeLiquidityNRGSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external returns (uint amountNRG);
function removeLiquidityNRGWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountNRG);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactNRGForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForNRGSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityNRG(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountNRG, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityNRG(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountNRG);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityNRGWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountNRG);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactNRGForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactNRG(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForNRG(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapNRGForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
// File: ../../../interfaces/IGovernedContract.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/**
* Genesis version of GovernedContract interface.
*
* Base Consensus interface for upgradable contracts.
* Unlike common approach, the implementation is NOT expected to be
* called through delegatecall() to minimize risks of shared storage.
*
* NOTE: it MUST NOT change after blockchain launch!
*/
interface IGovernedContract {
// Return actual proxy address for secure validation
function proxy() external returns(address);
// It must check that the caller is the proxy
// and copy all required data from the old address.
function migrate(IGovernedContract _oldImpl) external;
// It must check that the caller is the proxy
// and self destruct to the new address.
function destroy(IGovernedContract _newImpl) external;
// function () external payable; // This line (from original Energi IGovernedContract) is commented because it
// makes truffle migrations fail
}
// File: ../../../interfaces/IProposal.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
pragma solidity >=0.5.0;
interface IProposal {
function parent() external view returns(address);
function created_block() external view returns(uint);
function deadline() external view returns(uint);
function fee_payer() external view returns(address payable);
function fee_amount() external view returns(uint);
function accepted_weight() external view returns(uint);
function rejected_weight() external view returns(uint);
function total_weight() external view returns(uint);
function quorum_weight() external view returns(uint);
function isFinished() external view returns(bool);
function isAccepted() external view returns(bool);
function withdraw() external;
function destroy() external;
function collect() external;
function voteAccept() external;
function voteReject() external;
function setFee() external payable;
function canVote(address owner) external view returns(bool);
}
// File: ../../../interfaces/IUpgradeProposal.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
pragma solidity >=0.5.0;
/**
* Interface of UpgradeProposal
*/
contract IUpgradeProposal is IProposal {
function impl() external view returns(IGovernedContract);
}
// File: ../../../interfaces/IGovernedProxy.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
pragma solidity >=0.5.0;
//pragma experimental SMTChecker;
/**
* Genesis version of IGovernedProxy interface.
*
* Base Consensus interface for upgradable contracts proxy.
* Unlike common approach, the implementation is NOT expected to be
* called through delegatecall() to minimize risks of shared storage.
*
* NOTE: it MUST NOT change after blockchain launch!
*/
interface IGovernedProxy {
event UpgradeProposal(
IGovernedContract indexed impl,
IUpgradeProposal proposal
);
event Upgraded(
IGovernedContract indexed impl,
IUpgradeProposal proposal
);
function impl() external view returns(IGovernedContract);
function proposeUpgrade(IGovernedContract _newImpl, uint _period)
external payable returns(IUpgradeProposal);
function upgrade(IUpgradeProposal _proposal) external;
function upgradeProposalImpl(IUpgradeProposal _proposal) external view returns(IGovernedContract new_impl);
function listUpgradeProposals() external view returns(IUpgradeProposal[] memory proposals);
function collectUpgradeProposal(IUpgradeProposal _proposal) external;
function () external payable;
}
// File: ../../IEnergiswapRouterGovernedProxy.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.5.0;
interface IEnergiswapRouterGovernedProxy {
event UpgradeProposal(
IGovernedContract indexed impl,
IUpgradeProposal proposal
);
event Upgraded(
IGovernedContract indexed impl,
IUpgradeProposal proposal
);
function impl() external view returns (address);
function spork_proxy() external view returns (address);
function safeTransferFrom(address token, address from, address to, uint value) external;
function proposeUpgrade(IGovernedContract _newImpl, uint _period) external payable returns(IUpgradeProposal);
function upgrade(IUpgradeProposal _proposal) external;
function upgradeProposalImpl(IUpgradeProposal _proposal) external view returns(IGovernedContract new_impl);
function listUpgradeProposals() external view returns(IUpgradeProposal[] memory proposals);
function collectUpgradeProposal(IUpgradeProposal _proposal) external;
function proxy() external view returns (address);
function migrate(IGovernedContract) external pure;
function destroy(IGovernedContract) external pure;
function () external payable;
}
// File: ../../../interfaces/ISporkRegistry.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
pragma solidity >=0.5.0;
interface ISporkRegistry {
function createUpgradeProposal(
IGovernedContract _impl,
uint _period,
address payable _fee_payer
)
external payable
returns (IUpgradeProposal);
function consensusGasLimits()
external view
returns(uint callGas, uint xferGas);
}
// File: ../../../NonReentrant.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/**
* A little helper to protect contract from being re-entrant in state
* modifying functions.
*/
contract NonReentrant {
uint private entry_guard;
modifier noReentry {
require(entry_guard == 0, "Reentry");
entry_guard = 1;
_;
entry_guard = 0;
}
}
// File: ../../EnergiswapRouterGovernedProxy.sol
// Copyright (C) 2020 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
/**
* SC-9: This contract has no chance of being updated. It must be stupid simple.
*
* If another upgrade logic is required in the future - it can be done as proxy stage II.
*/
contract EnergiswapRouterGovernedProxy is IEnergiswapRouterGovernedProxy, NonReentrant {
IGovernedContract public impl;
IGovernedProxy public spork_proxy;
mapping(address => IGovernedContract) public upgrade_proposals;
IUpgradeProposal[] public upgrade_proposal_list;
modifier senderOrigin {
// Internal calls are expected to use impl directly.
// That's due to use of call() instead of delegatecall() on purpose.
// solium-disable-next-line security/no-tx-origin
require(tx.origin == msg.sender, "EnergiswapRouterGovernedProxy: FORBIDDEN, only direct calls are allowed!");
_;
}
modifier requireImpl {
require(msg.sender == address(impl), "EnergiswapRouterGovernedProxy: FORBIDDEN, not impl");
_;
}
constructor(address _impl, address payable _sporkProxy) public {
impl = IGovernedContract(_impl);
spork_proxy = IGovernedProxy(_sporkProxy);
}
function safeTransferFrom(address token, address from, address to, uint value) external requireImpl {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'EnergiswapGovernedProxy: TRANSFER_FROM_FAILED');
}
/**
* Pre-create a new contract first.
* Then propose upgrade based on that.
*/
function proposeUpgrade(IGovernedContract _newImpl, uint _period)
external payable
senderOrigin
noReentry
returns(IUpgradeProposal)
{
require(_newImpl != impl, "Already active!");
require(_newImpl.proxy() == address(this), "Wrong proxy!");
ISporkRegistry spork_reg = ISporkRegistry(address(spork_proxy.impl()));
IUpgradeProposal proposal = spork_reg.createUpgradeProposal.value(msg.value)(_newImpl, _period, msg.sender);
upgrade_proposals[address(proposal)] = _newImpl;
upgrade_proposal_list.push(proposal);
emit UpgradeProposal(_newImpl, proposal);
return proposal;
}
/**
* Once proposal is accepted, anyone can activate that.
*/
function upgrade(IUpgradeProposal _proposal)
external
noReentry
{
IGovernedContract new_impl = upgrade_proposals[address(_proposal)];
require(new_impl != impl, "Already active!"); // in case it changes in the flight
require(address(new_impl) != address(0), "Not registered!");
require(_proposal.isAccepted(), "Not accepted!");
IGovernedContract old_impl = impl;
new_impl.migrate(old_impl);
impl = new_impl;
old_impl.destroy(new_impl);
// SECURITY: prevent downgrade attack
_cleanupProposal(_proposal);
// Return fee ASAP
_proposal.destroy();
emit Upgraded(new_impl, _proposal);
}
/**
* Map proposal to implementation
*/
function upgradeProposalImpl(IUpgradeProposal _proposal)
external view
returns(IGovernedContract new_impl)
{
new_impl = upgrade_proposals[address(_proposal)];
}
/**
* Lists all available upgrades
*/
function listUpgradeProposals()
external view
returns(IUpgradeProposal[] memory proposals)
{
uint len = upgrade_proposal_list.length;
proposals = new IUpgradeProposal[](len);
for (uint i = 0; i < len; ++i) {
proposals[i] = upgrade_proposal_list[i];
}
return proposals;
}
/**
* Once proposal is reject, anyone can start collect procedure.
*/
function collectUpgradeProposal(IUpgradeProposal _proposal)
external
noReentry
{
IGovernedContract new_impl = upgrade_proposals[address(_proposal)];
require(address(new_impl) != address(0), "Not registered!");
_proposal.collect();
delete upgrade_proposals[address(_proposal)];
_cleanupProposal(_proposal);
}
function _cleanupProposal(IUpgradeProposal _proposal) internal {
delete upgrade_proposals[address(_proposal)];
uint len = upgrade_proposal_list.length;
for (uint i = 0; i < len; ++i) {
if (upgrade_proposal_list[i] == _proposal) {
upgrade_proposal_list[i] = upgrade_proposal_list[len - 1];
upgrade_proposal_list.pop();
break;
}
}
}
/**
* Related to above
*/
function proxy() external view returns (address) {
return address(this);
}
/**
* SECURITY: prevent on-behalf-of calls
*/
function migrate(IGovernedContract) external pure {
revert("Good try");
}
/**
* SECURITY: prevent on-behalf-of calls
*/
function destroy(IGovernedContract) external pure {
revert("Good try");
}
/**
* Proxy all other calls to implementation.
*/
function ()
external
payable
senderOrigin
{
// SECURITY: senderOrigin() modifier is mandatory
IGovernedContract impl_m = impl;
// solium-disable-next-line security/no-inline-assembly
assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize())
let res := call(sub(gas(), 10000), impl_m, callvalue(), ptr, calldatasize(), 0, 0)
// NOTE: returndatasize should allow repeatable calls
// what should save one opcode.
returndatacopy(ptr, 0, returndatasize())
switch res
case 0 {
revert(ptr, returndatasize())
}
default {
return(ptr, returndatasize())
}
}
}
}
// File: ../../EnergiswapRouterAutoProxy.sol
// Copyright (C) 2020 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
contract EnergiswapRouterAutoProxy is EnergiswapGovernedContract {
constructor (
address _proxy,
address _impl,
address payable _sporkProxy
) public EnergiswapGovernedContract(_proxy) {
// If _proxy is set to address(0), a new EnergiswapRouterGovernedProxy is deployed
if(_proxy == address(0)){
_proxy = address(new EnergiswapRouterGovernedProxy(_impl, _sporkProxy));
}
proxy = _proxy;
}
}
// File: ../../../StorageBase.sol
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
/**
* Base for contract storage (SC-14).
*
* NOTE: it MUST NOT change after blockchain launch!
*/
contract StorageBase {
address payable internal owner;
modifier requireOwner {
require(msg.sender == address(owner), "Not owner!");
_;
}
constructor() public {
owner = msg.sender;
}
function setOwner(IGovernedContract _newOwner) external requireOwner {
owner = address(uint160(address(_newOwner)));
}
function kill() external requireOwner {
selfdestruct(msg.sender);
}
}
// File: ../../../interfaces/IWhitelist.sol
// Copyright 2021 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
interface IWhitelist {
function isWhitelisted(address _item) external view returns (bool);
}
// File: ../../IEnergiswapRouterStorage.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
interface IEnergiswapRouterStorage {
function getFactory() external view returns(address _factory);
function getWNRG() external view returns(address _WNRG);
}
// File: ../../../energiswapFactory/IEnergiswapFactory.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
interface IEnergiswapFactory {
function initialized() external view returns (bool);
function _storage() external view returns (address);
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function initialize(address _routerProxy, address _pairsManagerProxy, address _pairsERC20Proxy) external;
function destroy(address _newImpl) external;
function migrate(address _oldImpl) external;
function createPair(
address tokenA,
address tokenB
) external returns (address pairProxy);
function setFeeTo(address _feeTo) external;
function setFeeToSetter(address _feeToSetter) external;
function feeTo() external view returns (address _feeTo);
function feeToSetter() external view returns (address _feeToSetter);
function sporkProxy() external view returns (address _sporkProxy);
function getPair(address tokenA, address tokenB) external view returns (address _pair);
function allPairs(uint index) external view returns (address _pair);
function allPairsLength() external view returns (uint);
}
// File: ../../../interfaces/IERC20.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
// File: ../../../interfaces/IWNRG.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
interface IWNRG {
function deposit() external payable;
function withdraw(uint amount) external;
}
// File: ../../../energiswapPairsManager/IEnergiswapPairsManager.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
interface IEnergiswapPairsManager {
event Mint(address indexed pair, address indexed sender, uint amount0, uint amount1, address indexed to);
event Burn(address indexed pair, address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(address indexed sender, uint112 reserve0, uint112 reserve1);
function _storage() external view returns (address);
function destroy(address _newImpl) external;
function migrate(address _oldImpl) external;
function registerPair(address _pairProxy, address _pairStorage, address _erc20Storage) external;
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function approve(address spender, uint value) external returns (bool result);
function transfer(address to, uint value) external returns (bool result);
function transferFrom(address from, address to, uint value) external returns (bool result);
function redeemLiquidity(address router, address owner, uint value) external returns (bool result);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
function emitApproval(address pair, address owner, address spender, uint value) external;
function emitTransfer(address pair, address from, address to, uint value) external;
function factory() external view returns (address _factory);
function getReserves(address pair) external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast);
function token0(address pair) external view returns (address _token0);
function token1(address pair) external view returns (address _token1);
function price0CumulativeLast(address pair) external view returns (uint _price0CumulativeLast);
function price1CumulativeLast(address pair) external view returns (uint _price1CumulativeLast);
function kLast(address pair) external view returns (uint _kLast);
}
// File: ../../../energiswapPair/IEnergiswapPairProxy.sol
// Copyright 2019 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
pragma solidity >=0.5.0;
/**
* Genesis version of IGovernedProxy interface.
*
* Base Consensus interface for upgradable contracts proxy.
* Unlike common approach, the implementation is NOT expected to be
* called through delegatecall() to minimize risks of shared storage.
*
* NOTE: it MUST NOT change after blockchain launch!
*/
interface IEnergiswapPairProxy {
function pairsManagerProxy() external view returns (address);
function pairsERC20Proxy() external view returns (address);
function routerProxy() external view returns (address);
function emitMint(address sender, uint amount0, uint amount1, address to) external;
function emitBurn(address sender, uint amount0, uint amount1, address to) external;
function emitSwap(address sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address to) external;
function emitSync(uint112 reserve0, uint112 reserve1) external;
function emitApproval(address owner, address spender, uint value) external;
function emitTransfer(address from, address to, uint value) external;
function safeTransfer(address token, address to, uint value, bytes4 SELECTOR) external;
function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast);
function token0() external view returns (address _token0);
function token1() external view returns (address _token1);
function price0CumulativeLast() external view returns (uint _price0CumulativeLast);
function price1CumulativeLast() external view returns (uint _price1CumulativeLast);
function kLast() external view returns (uint _kLast);
function name() external view returns(string memory _name);
function symbol() external view returns(string memory _symbol);
function decimals() external view returns(uint8 _decimals);
function totalSupply() external view returns (uint _totalSupply);
function balanceOf(address account) external view returns (uint _balance);
function allowance(address owner, address spender) external view returns (uint _allowance);
function nonce(address owner) external view returns(uint _nonce);
function () external payable;
}
// File: ../../../libraries/SafeMath.sol
pragma solidity = 0.5.16;
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
// File: ../../../libraries/EnergiswapLibrary.sol
// Copyright (C) 2020 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
library EnergiswapLibrary {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'EnergiswapLibrary: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'EnergiswapLibrary: ZERO_ADDRESS');
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
address payable pairProxy = address(uint160(IEnergiswapFactory(factory).getPair(tokenA, tokenB)));
(uint reserve0, uint reserve1,) = IEnergiswapPairProxy(pairProxy).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'EnergiswapLibrary: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'EnergiswapLibrary: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'EnergiswapLibrary: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'EnergiswapLibrary: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997); // 0.3% fee
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'EnergiswapLibrary: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'EnergiswapLibrary: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'EnergiswapLibrary: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'EnergiswapLibrary: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
}
// File: ../../../libraries/TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity = 0.5.16;
// helper methods for interacting with ERC20 tokens and sending WNRG that do not consistently return true/false
library TransferHelper {
function safeApprove(address token, address to, uint 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, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(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, uint value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(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 safeTransferNRG(address to, uint value) internal {
(bool success, ) = to.call.value(value)(new bytes(0));
require(success, 'TransferHelper: NRG_TRANSFER_FAILED');
}
}
// File: ../../EnergiswapRouter.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
contract EnergiswapRouterStorage is StorageBase, IEnergiswapRouterStorage {
address private factoryProxy;
address private pairsManagerProxy;
address private WNRG;
constructor(
address _factoryProxy,
address _WNRG
) public {
factoryProxy = _factoryProxy;
WNRG = _WNRG;
}
function getFactory() external view returns(address _factory) {
_factory = address(IGovernedProxy(address(uint160(factoryProxy))).impl());
}
function getWNRG() external view returns(address _WNRG) {
_WNRG = WNRG;
}
}
contract EnergiswapRouter is EnergiswapRouterAutoProxy, IEnergiswapRouter {
using SafeMath for uint;
EnergiswapRouterStorage public _storage;
modifier ensure(uint deadline) {
require(deadline >= block.timestamp, 'EnergiswapRouter: EXPIRED');
_;
}
constructor(
address _factoryProxy,
address _WNRG,
address _sporkProxy,
address _proxy // If set to address(0), EnergiswapRouterGovernedProxy will be deployed by EnergiswapRouterAutoProxy
) public EnergiswapRouterAutoProxy(
_proxy,
address(this),
address(uint160(_sporkProxy))
) {
_storage = new EnergiswapRouterStorage(_factoryProxy, _WNRG); // Deploy EnergiswapRouterStorage contract
}
// This function must be called in order to upgrade to a new EnergiswapRouter implementation
function destroy(address _newImpl) external requireProxy {
// Updates EnergiswapRouterStorage contract with new EnergiswapRouter implementation address as owner
IStorageBase(address(_storage)).setOwner(_newImpl);
// Self-destruct
_destroy(_newImpl);
}
// This function (placeholder) would be called on the new implementation if necessary for the upgrade
function migrate(address _oldImpl) external requireProxy {
_migrate(_oldImpl);
}
function() external payable {
address WNRG = _storage.getWNRG();
assert(msg.sender == WNRG); // only accept WNRG via fallback from the WNRG contract
}
// Get pair proxy address from tokens addresses
function pairFor(address tokenA, address tokenB) internal view returns (address pair) {
pair = IEnergiswapFactory(_storage.getFactory()).getPair(tokenA, tokenB);
}
// **** ADD LIQUIDITY ****
function _addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin
) internal returns (uint amountA, uint amountB) {
// create the pair if it doesn't exist yet
if (pairFor(tokenA, tokenB) == address(0)) {
IEnergiswapFactory(_storage.getFactory()).createPair(
tokenA,
tokenB
);
}
(uint reserveA, uint reserveB) = EnergiswapLibrary.getReserves(
_storage.getFactory(),
tokenA,
tokenB
);
if (reserveA == 0 && reserveB == 0) {
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
uint amountBOptimal = EnergiswapLibrary.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
require(amountBOptimal >= amountBMin, 'EnergiswapRouter: INSUFFICIENT_B_AMOUNT');
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint amountAOptimal = EnergiswapLibrary.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
require(amountAOptimal >= amountAMin, 'EnergiswapRouter: INSUFFICIENT_A_AMOUNT');
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {
(amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);
address pair = pairFor(tokenA, tokenB);
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(tokenA, tx.origin, pair, amountA);
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(tokenB, tx.origin, pair, amountB);
liquidity = IEnergiswapPairsManager(pair).mint(to);
}
function addLiquidityNRG(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external payable ensure(deadline) returns (uint amountToken, uint amountNRG, uint liquidity) {
address WNRG = _storage.getWNRG();
(amountToken, amountNRG) = _addLiquidity(
token,
WNRG,
amountTokenDesired,
msg.value,
amountTokenMin,
amountNRGMin
);
address pair = pairFor(token, WNRG);
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(token, tx.origin, pair, amountToken);
IWNRG(WNRG).deposit.value(amountNRG)();
assert(IERC20(WNRG).transfer(pair, amountNRG));
liquidity = IEnergiswapPairsManager(pair).mint(to);
// refund dust wnrg, if any
if (msg.value > amountNRG) TransferHelper.safeTransferNRG(tx.origin, msg.value - amountNRG);
}
// **** REMOVE LIQUIDITY ****
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) public ensure(deadline) returns (uint amountA, uint amountB) {
address pair = pairFor(tokenA, tokenB);
IEnergiswapPairsManager(pair).redeemLiquidity(address(proxy), tx.origin, liquidity); // send liquidity to pair
(uint amount0, uint amount1) = IEnergiswapPairsManager(pair).burn(to);
(address token0,) = EnergiswapLibrary.sortTokens(tokenA, tokenB);
(amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);
require(amountA >= amountAMin, 'EnergiswapRouter: INSUFFICIENT_A_AMOUNT');
require(amountB >= amountBMin, 'EnergiswapRouter: INSUFFICIENT_B_AMOUNT');
}
function removeLiquidityNRG(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) public ensure(deadline) returns (uint amountToken, uint amountNRG) {
address WNRG = _storage.getWNRG();
(amountToken, amountNRG) = removeLiquidity(
token,
WNRG,
liquidity,
amountTokenMin,
amountNRGMin,
address(this),
deadline
);
TransferHelper.safeTransfer(token, to, amountToken);
IWNRG(WNRG).withdraw(amountNRG);
TransferHelper.safeTransferNRG(to, amountNRG);
}
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB) {
address pair = pairFor(tokenA, tokenB);
uint value = approveMax ? uint(-1) : liquidity;
IEnergiswapPairsManager(pair).permit(tx.origin, address(proxy), value, deadline, v, r, s);
(amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);
}
function removeLiquidityNRGWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountNRG) {
address WNRG = _storage.getWNRG();
address pair = pairFor(token, WNRG);
uint value = approveMax ? uint(-1) : liquidity;
IEnergiswapPairsManager(pair).permit(tx.origin, address(proxy), value, deadline, v, r, s);
(amountToken, amountNRG) = removeLiquidityNRG(token, liquidity, amountTokenMin, amountNRGMin, to, deadline);
}
// **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****
function removeLiquidityNRGSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) public ensure(deadline) returns (uint amountNRG) {
address WNRG = _storage.getWNRG();
(, amountNRG) = removeLiquidity(
token,
WNRG,
liquidity,
amountTokenMin,
amountNRGMin,
address(this),
deadline
);
TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this)));
IWNRG(WNRG).withdraw(amountNRG);
TransferHelper.safeTransferNRG(to, amountNRG);
}
function removeLiquidityNRGWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountNRG) {
address WNRG = _storage.getWNRG();
address pair = pairFor(token, WNRG);
uint value = approveMax ? uint(-1) : liquidity;
IEnergiswapPairsManager(pair).permit(tx.origin, address(proxy), value, deadline, v, r, s);
amountNRG = removeLiquidityNRGSupportingFeeOnTransferTokens(
token, liquidity, amountTokenMin, amountNRGMin, to, deadline
);
}
// **** SWAP ****
// requires the initial amount to have already been sent to the first pair
function _swap(uint[] memory amounts, address[] memory path, address _to) internal {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = EnergiswapLibrary.sortTokens(input, output);
uint amountOut = amounts[i + 1];
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to;
IEnergiswapPairsManager(pairFor(input, output)).swap(
amount0Out, amount1Out, to, new bytes(0)
);
}
}
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external ensure(deadline) returns (uint[] memory amounts) {
amounts = EnergiswapLibrary.getAmountsOut(_storage.getFactory(), amountIn, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT');
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], tx.origin, pairFor(path[0], path[1]), amounts[0]);
_swap(amounts, path, to);
}
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external ensure(deadline) returns (uint[] memory amounts) {
amounts = EnergiswapLibrary.getAmountsIn(_storage.getFactory(), amountOut, path);
require(amounts[0] <= amountInMax, 'EnergiswapRouter: EXCESSIVE_INPUT_AMOUNT');
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], tx.origin, pairFor(path[0], path[1]), amounts[0]);
_swap(amounts, path, to);
}
function swapExactNRGForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[0] == WNRG, 'EnergiswapRouter: INVALID_PATH');
amounts = EnergiswapLibrary.getAmountsOut(_storage.getFactory(), msg.value, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT');
IWNRG(WNRG).deposit.value(amounts[0])();
assert(IERC20(WNRG).transfer(pairFor(path[0], path[1]), amounts[0]));
_swap(amounts, path, to);
}
function swapTokensForExactNRG(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[path.length - 1] == WNRG, 'EnergiswapRouter: INVALID_PATH');
amounts = EnergiswapLibrary.getAmountsIn(_storage.getFactory(), amountOut, path);
require(amounts[0] <= amountInMax, 'EnergiswapRouter: EXCESSIVE_INPUT_AMOUNT');
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], tx.origin, pairFor(path[0], path[1]), amounts[0]);
_swap(amounts, path, address(this));
IWNRG(WNRG).withdraw(amounts[amounts.length - 1]);
TransferHelper.safeTransferNRG(to, amounts[amounts.length - 1]);
}
function swapExactTokensForNRG(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[path.length - 1] == WNRG, 'EnergiswapRouter: INVALID_PATH');
amounts = EnergiswapLibrary.getAmountsOut(_storage.getFactory(), amountIn, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT');
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], tx.origin, pairFor(path[0], path[1]), amounts[0]);
_swap(amounts, path, address(this));
IWNRG(WNRG).withdraw(amounts[amounts.length - 1]);
TransferHelper.safeTransferNRG(to, amounts[amounts.length - 1]);
}
function swapNRGForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[0] == WNRG, 'EnergiswapRouter: INVALID_PATH');
amounts = EnergiswapLibrary.getAmountsIn(_storage.getFactory(), amountOut, path);
require(amounts[0] <= msg.value, 'EnergiswapRouter: EXCESSIVE_INPUT_AMOUNT');
IWNRG(WNRG).deposit.value(amounts[0])();
assert(IERC20(WNRG).transfer(pairFor(path[0], path[1]), amounts[0]));
_swap(amounts, path, to);
// refund dust wnrg, if any
if (msg.value > amounts[0]) TransferHelper.safeTransferNRG(tx.origin, msg.value - amounts[0]);
}
// **** SWAP (supporting fee-on-transfer tokens) ****
// requires the initial amount to have already been sent to the first pair
function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = EnergiswapLibrary.sortTokens(input, output);
address pair = pairFor(input, output);
uint amountInput;
uint amountOutput;
{ // scope to avoid stack too deep errors
(uint reserve0, uint reserve1,) = IEnergiswapPairProxy(address(uint160(pair))).getReserves();
(uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
amountInput = IERC20(input).balanceOf(pair).sub(reserveInput);
amountOutput = EnergiswapLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);
}
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0));
address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to;
IEnergiswapPairsManager(pair).swap(amount0Out, amount1Out, to, new bytes(0));
}
}
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external ensure(deadline) {
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], tx.origin, pairFor(path[0], path[1]), amountIn);
uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to);
_swapSupportingFeeOnTransferTokens(path, to);
require(
IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
'EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT'
);
}
function swapExactNRGForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
payable
ensure(deadline)
{
address WNRG = _storage.getWNRG();
require(path[0] == WNRG, 'EnergiswapRouter: INVALID_PATH');
uint amountIn = msg.value;
IWNRG(WNRG).deposit.value(amountIn)();
assert(IERC20(WNRG).transfer(pairFor(path[0], path[1]), amountIn));
uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to);
_swapSupportingFeeOnTransferTokens(path, to);
require(
IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
'EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT'
);
}
function swapExactTokensForNRGSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
ensure(deadline)
{
address WNRG = _storage.getWNRG();
require(path[path.length - 1] == WNRG, 'EnergiswapRouter: INVALID_PATH');
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], tx.origin, pairFor(path[0], path[1]), amountIn);
_swapSupportingFeeOnTransferTokens(path, address(this));
uint amountOut = IERC20(WNRG).balanceOf(address(this));
require(amountOut >= amountOutMin, 'EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT');
IWNRG(WNRG).withdraw(amountOut);
TransferHelper.safeTransferNRG(to, amountOut);
}
// **** LIBRARY FUNCTIONS ****
function quote(uint amountA, uint reserveA, uint reserveB) public pure returns (uint amountB) {
return EnergiswapLibrary.quote(amountA, reserveA, reserveB);
}
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut)
public
pure
returns (uint amountOut)
{
return EnergiswapLibrary.getAmountOut(amountIn, reserveIn, reserveOut);
}
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut)
public
pure
returns (uint amountIn)
{
return EnergiswapLibrary.getAmountIn(amountOut, reserveIn, reserveOut);
}
function getAmountsOut(uint amountIn, address[] memory path)
public
view
returns (uint[] memory amounts)
{
return EnergiswapLibrary.getAmountsOut(_storage.getFactory(), amountIn, path);
}
function getAmountsIn(uint amountOut, address[] memory path)
public
view
returns (uint[] memory amounts)
{
return EnergiswapLibrary.getAmountsIn(_storage.getFactory(), amountOut, path);
}
}
// File: IEnergiswapRouterUpgrade_1.sol
// Copyright 2021 The Energi Core Authors
// This file is part of Energi Core.
//
// Energi Core is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Energi Core is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Energi Core. If not, see <http://www.gnu.org/licenses/>.
// Energi Governance system is the fundamental part of Energi Core.
// NOTE: It's not allowed to change the compiler due to byte-to-byte
// match requirement.
interface IEnergiswapRouterUpgrade_1 {
function _storage() external view returns (address);
function destroy(address _newImpl) external;
function migrate(address _oldImpl) external;
function() external payable;
function removeLiquidityNRGSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external returns (uint amountNRG);
function removeLiquidityNRGWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountNRG);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactNRGForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForNRGSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityNRG(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountNRG, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityNRG(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountNRG);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityNRGWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountNRG);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactNRGForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactNRG(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForNRG(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapNRGForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
}
// File: ../../../energiswapPairsManager/upgrades/1_fix_evil_proxy_vulnerability_and_implement_referral_rewards/IEnergiswapPairsManagerUpgrade_1.sol
// Copyright (C) 2021 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
interface IEnergiswapPairsManagerUpgrade_1 {
event Mint(address indexed pair, address indexed sender, uint amount0, uint amount1, address indexed to);
event Burn(address indexed pair, address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(address indexed sender, uint112 reserve0, uint112 reserve1);
function _storage() external view returns (address);
function destroy(address _newImpl) external;
function migrate(address _oldImpl) external;
function registerPair(address _pairProxy, address _pairStorage, address _erc20Storage) external;
function mint(address pair, address from, address to) external returns (uint liquidity);
function burn(address pair, address from, address to) external returns (uint amount0, uint amount1);
function swap(address pair, address from, uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function redeemLiquidity(address pair, address owner, uint value) external returns (bool result);
function skim(address to) external;
function sync() external;
function approve(address spender, uint value) external returns (bool result);
function transfer(address to, uint value) external returns (bool result);
function transferFrom(address from, address to, uint value) external returns (bool result);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
function emitApproval(address pair, address owner, address spender, uint value) external;
function emitTransfer(address pair, address from, address to, uint value) external;
function safeTransfer(address pair, address token, address to, uint value) external;
function setCumulativePrices(
address pair,
uint price0CumulativeLast,
uint price1CumulativeLast
) external;
function factory() external view returns (address _factory);
function getReserves(address pair) external view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast);
function getTokens(address pair) external view returns (address, address);
function token0(address pair) external view returns (address _token0);
function token1(address pair) external view returns (address _token1);
function getCumulativePrices(address pair) external view returns (uint, uint);
function price0CumulativeLast(address pair) external view returns (uint _price0CumulativeLast);
function price1CumulativeLast(address pair) external view returns (uint _price1CumulativeLast);
}
// File: ../../../interfaces/IReferral.sol
// Copyright (C) 2021 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
interface IReferral {
function referrer(address _referee) external view returns (address);
}
// File: EnergiswapLibraryUpgrade_1.sol
// Copyright (C) 2021 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity = 0.5.16;
library EnergiswapLibraryUpgrade_1 {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, "EnergiswapLibrary: IDENTICAL_ADDRESSES");
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), "EnergiswapLibrary: ZERO_ADDRESS");
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
address payable pairProxy = address(uint160(IEnergiswapFactory(factory).getPair(tokenA, tokenB)));
(uint reserve0, uint reserve1,) = IEnergiswapPairProxy(pairProxy).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, "EnergiswapLibrary: INSUFFICIENT_AMOUNT");
require(reserveA > 0 && reserveB > 0, "EnergiswapLibrary: INSUFFICIENT_LIQUIDITY");
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut, address referrer) internal pure returns (uint amountOut) {
require(amountIn > 0, "EnergiswapLibrary: INSUFFICIENT_INPUT_AMOUNT");
require(reserveIn > 0 && reserveOut > 0, "EnergiswapLibrary: INSUFFICIENT_LIQUIDITY");
uint amountInWithFee = referrer == address(0)
? amountIn.mul(9970) // Users who are not referred pay 0.3% fee
: amountIn.mul(9973); // Referees pay 0.27% fee
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(10000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut, address referrer) internal pure returns (uint amountIn) {
require(amountOut > 0, "EnergiswapLibrary: INSUFFICIENT_OUTPUT_AMOUNT");
require(reserveIn > 0 && reserveOut > 0, "EnergiswapLibrary: INSUFFICIENT_LIQUIDITY");
uint numerator = reserveIn.mul(amountOut).mul(10000);
uint denominator = referrer == address(0)
? reserveOut.sub(amountOut).mul(9970) // Users who are not referred pay 0.3% fee
: reserveOut.sub(amountOut).mul(9973); // Referees pay 0.27% fee
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path, address referrer) internal view returns (uint[] memory amounts) {
require(path.length >= 2, "EnergiswapLibrary: INVALID_PATH");
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut, referrer);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path, address referrer) internal view returns (uint[] memory amounts) {
require(path.length >= 2, "EnergiswapLibrary: INVALID_PATH");
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut, referrer);
}
}
}
// File: EnergiswapRouterUpgrade_1.sol
// Copyright (C) 2021 Energi Core
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
contract EnergiswapRouterUpgrade_1 is EnergiswapRouterAutoProxy, IEnergiswapRouterUpgrade_1 {
using SafeMath for uint;
EnergiswapRouterStorage public _storage;
address public pairsManagerProxyAddress;
address public whitelistProxyAddress;
address public referralProxyAddress;
modifier ensure(uint deadline) {
require(deadline >= block.timestamp, "EnergiswapRouter: EXPIRED");
_;
}
modifier requireWhitelisted {
require(msg.sender == proxy || IWhitelist(getWhitelistImpl()).isWhitelisted(msg.sender), "EnergiswapRouter: FORBIDDEN, not whitelisted");
_;
}
function pairsManager() private view returns(address _pairsManager) {
_pairsManager = address(IGovernedProxy(address(uint160(pairsManagerProxyAddress))).impl());
}
function getWhitelistImpl() private view returns(address _whitelist) {
_whitelist = address(IGovernedProxy(address(uint160(whitelistProxyAddress))).impl());
}
function getReferrer(address _user) private view returns(address _referrer) {
address referralImpl = address(IGovernedProxy(address(uint160(referralProxyAddress))).impl());
_referrer = IReferral(referralImpl).referrer(_user);
}
function getSender() private view returns(address _sender){
// Determine sender to allow whitelisted contracts to interact
// If msg.sender is a whitelisted contract, this contract is the sender
// Else, tx.origin is the sender
_sender = IWhitelist(getWhitelistImpl()).isWhitelisted(msg.sender) ? msg.sender : tx.origin;
}
constructor(
address _proxy, // If set to address(0), EnergiswapRouterGovernedProxy will be deployed by EnergiswapRouterAutoProxy
address _pairsManagerProxyAddress,
address _whitelistProxyAddress,
address _referralProxyAddress
) public EnergiswapRouterAutoProxy(
_proxy,
address(this),
address(0)
) {
pairsManagerProxyAddress = _pairsManagerProxyAddress;
whitelistProxyAddress = _whitelistProxyAddress;
referralProxyAddress = _referralProxyAddress;
}
// This function must be called in order to upgrade to a new EnergiswapRouter implementation
function destroy(address _newImpl) external requireProxy {
// Updates EnergiswapRouterStorage contract with new EnergiswapRouter implementation address as owner
IStorageBase(address(_storage)).setOwner(_newImpl);
// Self-destruct
_destroy(_newImpl);
}
function migrate(address _oldImpl) external requireProxy {
_storage = EnergiswapRouterStorage(IEnergiswapRouterUpgrade_1(address(uint160(_oldImpl)))._storage());
_migrate(_oldImpl);
}
function() external payable {
address WNRG = _storage.getWNRG();
assert(msg.sender == WNRG); // only accept WNRG via fallback from the WNRG contract
}
// Get pair proxy address from tokens addresses
function pairFor(address tokenA, address tokenB) internal view returns (address pair) {
pair = IEnergiswapFactory(_storage.getFactory()).getPair(tokenA, tokenB);
}
// **** ADD LIQUIDITY ****
function _addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin
) internal returns (uint amountA, uint amountB) {
// create the pair if it doesn't exist yet
if (pairFor(tokenA, tokenB) == address(0)) {
IEnergiswapFactory(_storage.getFactory()).createPair(
tokenA,
tokenB
);
}
(uint reserveA, uint reserveB) = EnergiswapLibraryUpgrade_1.getReserves(
_storage.getFactory(),
tokenA,
tokenB
);
if (reserveA == 0 && reserveB == 0) {
(amountA, amountB) = (amountADesired, amountBDesired);
} else {
uint amountBOptimal = EnergiswapLibraryUpgrade_1.quote(amountADesired, reserveA, reserveB);
if (amountBOptimal <= amountBDesired) {
require(amountBOptimal >= amountBMin, "EnergiswapRouter: INSUFFICIENT_B_AMOUNT");
(amountA, amountB) = (amountADesired, amountBOptimal);
} else {
uint amountAOptimal = EnergiswapLibraryUpgrade_1.quote(amountBDesired, reserveB, reserveA);
assert(amountAOptimal <= amountADesired);
require(amountAOptimal >= amountAMin, "EnergiswapRouter: INSUFFICIENT_A_AMOUNT");
(amountA, amountB) = (amountAOptimal, amountBDesired);
}
}
}
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external requireWhitelisted ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {
(amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);
address pair = pairFor(tokenA, tokenB);
address sender = getSender();
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(tokenA, sender, pair, amountA);
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(tokenB, sender, pair, amountB);
liquidity = IEnergiswapPairsManagerUpgrade_1(pairsManager()).mint(pair, sender, to);
}
function addLiquidityNRG(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) external requireWhitelisted payable ensure(deadline) returns (uint amountToken, uint amountNRG, uint liquidity) {
address WNRG = _storage.getWNRG();
(amountToken, amountNRG) = _addLiquidity(
token,
WNRG,
amountTokenDesired,
msg.value,
amountTokenMin,
amountNRGMin
);
address pair = pairFor(token, WNRG);
address sender = getSender();
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(token, sender, pair, amountToken);
IWNRG(WNRG).deposit.value(amountNRG)();
assert(IERC20(WNRG).transfer(pair, amountNRG));
liquidity = IEnergiswapPairsManagerUpgrade_1(pairsManager()).mint(pair, sender, to);
// refund dust wnrg, if any
if (msg.value > amountNRG) TransferHelper.safeTransferNRG(sender, msg.value - amountNRG);
}
// **** REMOVE LIQUIDITY ****
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) public requireWhitelisted ensure(deadline) returns (uint amountA, uint amountB) {
address pair = pairFor(tokenA, tokenB);
address sender = getSender();
IEnergiswapPairsManagerUpgrade_1(pairsManager()).redeemLiquidity(pair, sender, liquidity); // send liquidity to pair
(uint amount0, uint amount1) = IEnergiswapPairsManagerUpgrade_1(pairsManager()).burn(pair, sender, to);
(address token0,) = EnergiswapLibraryUpgrade_1.sortTokens(tokenA, tokenB);
(amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);
require(amountA >= amountAMin, "EnergiswapRouter: INSUFFICIENT_A_AMOUNT");
require(amountB >= amountBMin, "EnergiswapRouter: INSUFFICIENT_B_AMOUNT");
}
function removeLiquidityNRG(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) public requireWhitelisted ensure(deadline) returns (uint amountToken, uint amountNRG) {
address WNRG = _storage.getWNRG();
(amountToken, amountNRG) = removeLiquidity(
token,
WNRG,
liquidity,
amountTokenMin,
amountNRGMin,
address(this),
deadline
);
TransferHelper.safeTransfer(token, to, amountToken);
IWNRG(WNRG).withdraw(amountNRG);
TransferHelper.safeTransferNRG(to, amountNRG);
}
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external requireWhitelisted returns (uint amountA, uint amountB) {
address pair = pairFor(tokenA, tokenB);
uint value = approveMax ? uint(-1) : liquidity;
IEnergiswapPairsManagerUpgrade_1(address(uint160(pair))).permit(getSender(), address(proxy), value, deadline, v, r, s);
(amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);
}
function removeLiquidityNRGWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external requireWhitelisted returns (uint amountToken, uint amountNRG) {
address WNRG = _storage.getWNRG();
address pair = pairFor(token, WNRG);
uint value = approveMax ? uint(-1) : liquidity;
IEnergiswapPairsManagerUpgrade_1(pair).permit(getSender(), address(proxy), value, deadline, v, r, s);
(amountToken, amountNRG) = removeLiquidityNRG(token, liquidity, amountTokenMin, amountNRGMin, to, deadline);
}
// **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****
function removeLiquidityNRGSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline
) public requireWhitelisted ensure(deadline) returns (uint amountNRG) {
address WNRG = _storage.getWNRG();
(, amountNRG) = removeLiquidity(
token,
WNRG,
liquidity,
amountTokenMin,
amountNRGMin,
address(this),
deadline
);
TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this)));
IWNRG(WNRG).withdraw(amountNRG);
TransferHelper.safeTransferNRG(to, amountNRG);
}
function removeLiquidityNRGWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountNRGMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external requireWhitelisted returns (uint amountNRG) {
address WNRG = _storage.getWNRG();
address pair = pairFor(token, WNRG);
uint value = approveMax ? uint(-1) : liquidity;
IEnergiswapPairsManagerUpgrade_1(pair).permit(getSender(), address(proxy), value, deadline, v, r, s);
amountNRG = removeLiquidityNRGSupportingFeeOnTransferTokens(
token, liquidity, amountTokenMin, amountNRGMin, to, deadline
);
}
// **** SWAP ****
// requires the initial amount to have already been sent to the first pair
function _swap(address sender, uint[] memory amounts, address[] memory path, address _to) internal {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = EnergiswapLibraryUpgrade_1.sortTokens(input, output);
uint amountOut = amounts[i + 1];
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to;
IEnergiswapPairsManagerUpgrade_1(pairsManager()).swap(
pairFor(input, output), sender, amount0Out, amount1Out, to, new bytes(0)
);
}
}
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external requireWhitelisted ensure(deadline) returns (uint[] memory amounts) {
address sender = getSender();
address referrer = getReferrer(sender);
amounts = EnergiswapLibraryUpgrade_1.getAmountsOut(_storage.getFactory(), amountIn, path, referrer);
require(amounts[amounts.length - 1] >= amountOutMin, "EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT");
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], sender, pairFor(path[0], path[1]), amounts[0]);
_swap(sender, amounts, path, to);
}
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external requireWhitelisted ensure(deadline) returns (uint[] memory amounts) {
address sender = getSender();
address referrer = getReferrer(sender);
amounts = EnergiswapLibraryUpgrade_1.getAmountsIn(_storage.getFactory(), amountOut, path, referrer);
require(amounts[0] <= amountInMax, "EnergiswapRouter: EXCESSIVE_INPUT_AMOUNT");
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], sender, pairFor(path[0], path[1]), amounts[0]);
_swap(sender, amounts, path, to);
}
function swapExactNRGForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
requireWhitelisted
payable
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[0] == WNRG, "EnergiswapRouter: INVALID_PATH");
address sender = getSender();
address referrer = getReferrer(sender);
amounts = EnergiswapLibraryUpgrade_1.getAmountsOut(_storage.getFactory(), msg.value, path, referrer);
require(amounts[amounts.length - 1] >= amountOutMin, "EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT");
IWNRG(WNRG).deposit.value(amounts[0])();
assert(IERC20(WNRG).transfer(pairFor(path[0], path[1]), amounts[0]));
_swap(sender, amounts, path, to);
}
function swapTokensForExactNRG(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
requireWhitelisted
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[path.length - 1] == WNRG, "EnergiswapRouter: INVALID_PATH");
address sender = getSender();
address referrer = getReferrer(sender);
amounts = EnergiswapLibraryUpgrade_1.getAmountsIn(_storage.getFactory(), amountOut, path, referrer);
require(amounts[0] <= amountInMax, "EnergiswapRouter: EXCESSIVE_INPUT_AMOUNT");
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], sender, pairFor(path[0], path[1]), amounts[0]);
_swap(sender, amounts, path, address(this));
IWNRG(WNRG).withdraw(amounts[amounts.length - 1]);
TransferHelper.safeTransferNRG(to, amounts[amounts.length - 1]);
}
function swapExactTokensForNRG(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
requireWhitelisted
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[path.length - 1] == WNRG, "EnergiswapRouter: INVALID_PATH");
address sender = getSender();
address referrer = getReferrer(sender);
amounts = EnergiswapLibraryUpgrade_1.getAmountsOut(_storage.getFactory(), amountIn, path, referrer);
require(amounts[amounts.length - 1] >= amountOutMin, "EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT");
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], sender, pairFor(path[0], path[1]), amounts[0]);
_swap(sender, amounts, path, address(this));
IWNRG(WNRG).withdraw(amounts[amounts.length - 1]);
TransferHelper.safeTransferNRG(to, amounts[amounts.length - 1]);
}
function swapNRGForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
requireWhitelisted
payable
ensure(deadline)
returns (uint[] memory amounts)
{
address WNRG = _storage.getWNRG();
require(path[0] == WNRG, "EnergiswapRouter: INVALID_PATH");
address sender = getSender();
address referrer = getReferrer(sender);
amounts = EnergiswapLibraryUpgrade_1.getAmountsIn(_storage.getFactory(), amountOut, path, referrer);
require(amounts[0] <= msg.value, "EnergiswapRouter: EXCESSIVE_INPUT_AMOUNT");
IWNRG(WNRG).deposit.value(amounts[0])();
assert(IERC20(WNRG).transfer(pairFor(path[0], path[1]), amounts[0]));
_swap(sender, amounts, path, to);
// refund dust wnrg, if any
if (msg.value > amounts[0]) TransferHelper.safeTransferNRG(sender, msg.value - amounts[0]);
}
// **** SWAP (supporting fee-on-transfer tokens) ****
// requires the initial amount to have already been sent to the first pair
function _swapSupportingFeeOnTransferTokens(address[] memory path, address _to) internal {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = EnergiswapLibraryUpgrade_1.sortTokens(input, output);
address pair = pairFor(input, output);
address sender = getSender();
uint amountInput;
uint amountOutput;
{ // scope to avoid stack too deep errors
(uint reserve0, uint reserve1,) = IEnergiswapPairsManagerUpgrade_1(pairsManager()).getReserves(pair);
(uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
amountInput = IERC20(input).balanceOf(pair).sub(reserveInput);
address referrer = getReferrer(sender);
amountOutput = EnergiswapLibraryUpgrade_1.getAmountOut(amountInput, reserveInput, reserveOutput, referrer);
}
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0));
address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to;
IEnergiswapPairsManagerUpgrade_1(pairsManager()).swap(pair, sender, amount0Out, amount1Out, to, new bytes(0));
}
}
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external requireWhitelisted ensure(deadline) {
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], getSender(), pairFor(path[0], path[1]), amountIn);
uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to);
_swapSupportingFeeOnTransferTokens(path, to);
require(
IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
"EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT"
);
}
function swapExactNRGForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
requireWhitelisted
payable
ensure(deadline)
{
address WNRG = _storage.getWNRG();
require(path[0] == WNRG, "EnergiswapRouter: INVALID_PATH");
uint amountIn = msg.value;
IWNRG(WNRG).deposit.value(amountIn)();
assert(IERC20(WNRG).transfer(pairFor(path[0], path[1]), amountIn));
uint balanceBefore = IERC20(path[path.length - 1]).balanceOf(to);
_swapSupportingFeeOnTransferTokens(path, to);
require(
IERC20(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
"EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT"
);
}
function swapExactTokensForNRGSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
)
external
requireWhitelisted
ensure(deadline)
{
address WNRG = _storage.getWNRG();
require(path[path.length - 1] == WNRG, "EnergiswapRouter: INVALID_PATH");
address sender = getSender();
IEnergiswapRouterGovernedProxy(address(uint160(proxy))).safeTransferFrom(path[0], sender, pairFor(path[0], path[1]), amountIn);
_swapSupportingFeeOnTransferTokens(path, address(this));
uint amountOut = IERC20(WNRG).balanceOf(address(this));
require(amountOut >= amountOutMin, "EnergiswapRouter: INSUFFICIENT_OUTPUT_AMOUNT");
IWNRG(WNRG).withdraw(amountOut);
TransferHelper.safeTransferNRG(to, amountOut);
}
}

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[{"type":"address","name":"_proxy","internalType":"address"},{"type":"address","name":"_pairsManagerProxyAddress","internalType":"address"},{"type":"address","name":"_whitelistProxyAddress","internalType":"address"},{"type":"address","name":"_referralProxyAddress","internalType":"address"}]},{"type":"fallback","stateMutability":"payable","payable":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"contract EnergiswapRouterStorage"}],"name":"_storage","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"addLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"uint256","name":"amountADesired","internalType":"uint256"},{"type":"uint256","name":"amountBDesired","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountNRG","internalType":"uint256"},{"type":"uint256","name":"liquidity","internalType":"uint256"}],"name":"addLiquidityNRG","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"amountTokenDesired","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountNRGMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"destroy","inputs":[{"type":"address","name":"_newImpl","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"migrate","inputs":[{"type":"address","name":"_oldImpl","internalType":"address"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"pairsManagerProxyAddress","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"proxy","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"referralProxyAddress","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"removeLiquidity","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountNRG","internalType":"uint256"}],"name":"removeLiquidityNRG","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountNRGMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountNRG","internalType":"uint256"}],"name":"removeLiquidityNRGSupportingFeeOnTransferTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountNRGMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountToken","internalType":"uint256"},{"type":"uint256","name":"amountNRG","internalType":"uint256"}],"name":"removeLiquidityNRGWithPermit","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountNRGMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountNRG","internalType":"uint256"}],"name":"removeLiquidityNRGWithPermitSupportingFeeOnTransferTokens","inputs":[{"type":"address","name":"token","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountTokenMin","internalType":"uint256"},{"type":"uint256","name":"amountNRGMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256","name":"amountA","internalType":"uint256"},{"type":"uint256","name":"amountB","internalType":"uint256"}],"name":"removeLiquidityWithPermit","inputs":[{"type":"address","name":"tokenA","internalType":"address"},{"type":"address","name":"tokenB","internalType":"address"},{"type":"uint256","name":"liquidity","internalType":"uint256"},{"type":"uint256","name":"amountAMin","internalType":"uint256"},{"type":"uint256","name":"amountBMin","internalType":"uint256"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"},{"type":"bool","name":"approveMax","internalType":"bool"},{"type":"uint8","name":"v","internalType":"uint8"},{"type":"bytes32","name":"r","internalType":"bytes32"},{"type":"bytes32","name":"s","internalType":"bytes32"}],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactNRGForTokens","inputs":[{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"swapExactNRGForTokensSupportingFeeOnTransferTokens","inputs":[{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForNRG","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"swapExactTokensForNRGSupportingFeeOnTransferTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapExactTokensForTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"swapExactTokensForTokensSupportingFeeOnTransferTokens","inputs":[{"type":"uint256","name":"amountIn","internalType":"uint256"},{"type":"uint256","name":"amountOutMin","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapNRGForExactTokens","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapTokensForExactNRG","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"uint256","name":"amountInMax","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[{"type":"uint256[]","name":"amounts","internalType":"uint256[]"}],"name":"swapTokensForExactTokens","inputs":[{"type":"uint256","name":"amountOut","internalType":"uint256"},{"type":"uint256","name":"amountInMax","internalType":"uint256"},{"type":"address[]","name":"path","internalType":"address[]"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"deadline","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"whitelistProxyAddress","inputs":[],"constant":true}]
            

Deployed ByteCode

0x6080604052600436106101495760003560e01c8063a645aa08116100b6578063d4a63a851161006f578063d4a63a851461090d578063ddfb899b146109a3578063de34e75214610a27578063e1c8f91e14610aac578063e8e3370014610aff578063ec55688914610b6157610149565b8063a645aa081461076a578063b4a1824c1461077f578063baa2abde146107d2578063c3fb90d61461082f578063ce5494bb14610844578063d06755ec1461087757610149565b806338ed17391161010857806338ed17391461044d5780635c11d795146104e357806368a1b8b5146105795780638803dbee146105ec57806395e7c1f8146106825780639db8625d1461070657610149565b806289add4146101d1578062f55d9d1461020257806305a09791146102375780630cfb6b3e1461024c5780632195995c1461033257806326a30fb1146103c9575b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561018e57600080fd5b505afa1580156101a2573d6000803e3d6000fd5b505050506040513d60208110156101b857600080fd5b50519050336001600160a01b038216146101ce57fe5b50005b3480156101dd57600080fd5b506101e6610b76565b604080516001600160a01b039092168252519081900360200190f35b34801561020e57600080fd5b506102356004803603602081101561022557600080fd5b50356001600160a01b0316610b85565b005b34801561024357600080fd5b506101e6610c40565b34801561025857600080fd5b506102e2600480360360a081101561026f57600080fd5b813591602081013591810190606081016040820135600160201b81111561029557600080fd5b8201836020820111156102a757600080fd5b803590602001918460208302840111600160201b831117156102c857600080fd5b91935091506001600160a01b038135169060200135610c4f565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561031e578181015183820152602001610306565b505050509050019250505060405180910390f35b34801561033e57600080fd5b506103b0600480360361016081101561035657600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c08101359060e081013515159060ff610100820135169061012081013590610140013561117d565b6040805192835260208301919091528051918290030190f35b610235600480360360808110156103df57600080fd5b81359190810190604081016020820135600160201b81111561040057600080fd5b82018360208201111561041257600080fd5b803590602001918460208302840111600160201b8311171561043357600080fd5b91935091506001600160a01b038135169060200135611345565b34801561045957600080fd5b506102e2600480360360a081101561047057600080fd5b813591602081013591810190606081016040820135600160201b81111561049657600080fd5b8201836020820111156104a857600080fd5b803590602001918460208302840111600160201b831117156104c957600080fd5b91935091506001600160a01b038135169060200135611837565b3480156104ef57600080fd5b50610235600480360360a081101561050657600080fd5b813591602081013591810190606081016040820135600160201b81111561052c57600080fd5b82018360208201111561053e57600080fd5b803590602001918460208302840111600160201b8311171561055f57600080fd5b91935091506001600160a01b038135169060200135611bd6565b34801561058557600080fd5b506103b0600480360361014081101561059d57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e08201351690610100810135906101200135611f55565b3480156105f857600080fd5b506102e2600480360360a081101561060f57600080fd5b813591602081013591810190606081016040820135600160201b81111561063557600080fd5b82018360208201111561064757600080fd5b803590602001918460208302840111600160201b8311171561066857600080fd5b91935091506001600160a01b03813516906020013561218f565b6102e26004803603608081101561069857600080fd5b81359190810190604081016020820135600160201b8111156106b957600080fd5b8201836020820111156106cb57600080fd5b803590602001918460208302840111600160201b831117156106ec57600080fd5b91935091506001600160a01b0381351690602001356123d3565b61074c600480360360c081101561071c57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135612882565b60408051938452602084019290925282820152519081900360600190f35b34801561077657600080fd5b506101e6612c92565b34801561078b57600080fd5b506103b0600480360360c08110156107a257600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135612ca1565b3480156107de57600080fd5b506103b0600480360360e08110156107f557600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359091169060c00135612ec8565b34801561083b57600080fd5b506101e66131f5565b34801561085057600080fd5b506102356004803603602081101561086757600080fd5b50356001600160a01b0316613204565b34801561088357600080fd5b506102e2600480360360a081101561089a57600080fd5b813591602081013591810190606081016040820135600160201b8111156108c057600080fd5b8201836020820111156108d257600080fd5b803590602001918460208302840111600160201b831117156108f357600080fd5b91935091506001600160a01b0381351690602001356132d8565b34801561091957600080fd5b50610235600480360360a081101561093057600080fd5b813591602081013591810190606081016040820135600160201b81111561095657600080fd5b82018360208201111561096857600080fd5b803590602001918460208302840111600160201b8311171561098957600080fd5b91935091506001600160a01b038135169060200135613605565b6102e2600480360360808110156109b957600080fd5b81359190810190604081016020820135600160201b8111156109da57600080fd5b8201836020820111156109ec57600080fd5b803590602001918460208302840111600160201b83111715610a0d57600080fd5b91935091506001600160a01b038135169060200135613a35565b348015610a3357600080fd5b50610a9a6004803603610140811015610a4b57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a08101359060c081013515159060ff60e08201351690610100810135906101200135613ef3565b60408051918252519081900360200190f35b348015610ab857600080fd5b50610a9a600480360360c0811015610acf57600080fd5b506001600160a01b0381358116916020810135916040820135916060810135916080820135169060a00135614123565b348015610b0b57600080fd5b5061074c6004803603610100811015610b2357600080fd5b506001600160a01b038135811691602081013582169160408201359160608101359160808201359160a08101359160c0820135169060e001356143bb565b348015610b6d57600080fd5b506101e6614731565b6003546001600160a01b031681565b6000546001600160a01b03163314610bce5760405162461bcd60e51b8152600401808060200182810382526030815260200180615dc86030913960400191505060405180910390fd5b600154604080516313af403560e01b81526001600160a01b038481166004830152915191909216916313af403591602480830192600092919082900301818387803b158015610c1c57600080fd5b505af1158015610c30573d6000803e3d6000fd5b50505050610c3d81614740565b50565b6002546001600160a01b031681565b6000546060906001600160a01b0316331480610cf05750610c6e61474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015610cc357600080fd5b505afa158015610cd7573d6000803e3d6000fd5b505050506040513d6020811015610ced57600080fd5b50515b610d2b5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8142811015610d6f576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b158015610db457600080fd5b505afa158015610dc8573d6000803e3d6000fd5b505050506040513d6020811015610dde57600080fd5b505190506001600160a01b03811687876000198101818110610dfc57fe5b905060200201356001600160a01b03166001600160a01b031614610e55576040805162461bcd60e51b815260206004820152601e6024820152600080516020615f0b833981519152604482015290519081900360640190fd5b6000610e5f6147c2565b90506000610e6c8261485e565b9050610f24600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b158015610ebf57600080fd5b505afa158015610ed3573d6000803e3d6000fd5b505050506040513d6020811015610ee957600080fd5b50516040805160208c810282810182019093528c82528f928e918e91829185019084908082843760009201919091525087925061494e915050565b94508985600081518110610f3457fe5b60200260200101511115610f795760405162461bcd60e51b8152600401808060200182810382526028815260200180615df86028913960400191505060405180910390fd5b600080546001600160a01b03169063d9fc4b61908b908b9081610f9857fe5b905060200201356001600160a01b031684610feb8d8d6000818110610fb957fe5b905060200201356001600160a01b03168e8e6001818110610fd657fe5b905060200201356001600160a01b0316614a86565b89600081518110610ff857fe5b60200260200101516040518563ffffffff1660e01b815260040180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b03168152602001828152602001945050505050600060405180830381600087803b15801561108157600080fd5b505af1158015611095573d6000803e3d6000fd5b505050506110d982868b8b80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250309250614b49915050565b826001600160a01b0316632e1a7d4d866001885103815181106110f857fe5b60200260200101516040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561113657600080fd5b505af115801561114a573d6000803e3d6000fd5b5050505061116f878660018851038151811061116257fe5b6020026020010151614d89565b505050509695505050505050565b6000805481906001600160a01b031633148061121e575061119c61474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156111f157600080fd5b505afa158015611205573d6000803e3d6000fd5b505050506040513d602081101561121b57600080fd5b50515b6112595760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b60006112658e8e614a86565b9050600087611274578c611278565b6000195b9050816001600160a01b031663d505accf6112916147c2565b60008054604080516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909116602484015260448301869052606483018e905260ff8c16608484015260a483018b905260c483018a90525160e48084019382900301818387803b15801561130457600080fd5b505af1158015611318573d6000803e3d6000fd5b5050505061132b8f8f8f8f8f8f8f612ec8565b809450819550505050509b509b9950505050505050505050565b6000546001600160a01b03163314806113e3575061136161474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156113b657600080fd5b505afa1580156113ca573d6000803e3d6000fd5b505050506040513d60208110156113e057600080fd5b50515b61141e5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8042811015611462576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b1580156114a757600080fd5b505afa1580156114bb573d6000803e3d6000fd5b505050506040513d60208110156114d157600080fd5b505190506001600160a01b03811686866000816114ea57fe5b905060200201356001600160a01b03166001600160a01b031614611543576040805162461bcd60e51b815260206004820152601e6024820152600080516020615f0b833981519152604482015290519081900360640190fd5b6000349050816001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b15801561158357600080fd5b505af1158015611597573d6000803e3d6000fd5b5050505050816001600160a01b031663a9059cbb6115d8898960008181106115bb57fe5b905060200201356001600160a01b03168a8a6001818110610fd657fe5b836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561162857600080fd5b505af115801561163c573d6000803e3d6000fd5b505050506040513d602081101561165257600080fd5b505161165a57fe5b60008787600019810181811061166c57fe5b905060200201356001600160a01b03166001600160a01b03166370a08231876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156116d157600080fd5b505afa1580156116e5573d6000803e3d6000fd5b505050506040513d60208110156116fb57600080fd5b50516040805160208a810282810182019093528a825292935061173d9290918b918b9182918501908490808284376000920191909152508a9250614e81915050565b886117ef828a8a600019810181811061175257fe5b905060200201356001600160a01b03166001600160a01b03166370a082318a6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156117b757600080fd5b505afa1580156117cb573d6000803e3d6000fd5b505050506040513d60208110156117e157600080fd5b50519063ffffffff6151ec16565b101561182c5760405162461bcd60e51b815260040180806020018281038252602c815260200180615e20602c913960400191505060405180910390fd5b505050505050505050565b6000546060906001600160a01b03163314806118d8575061185661474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156118ab57600080fd5b505afa1580156118bf573d6000803e3d6000fd5b505050506040513d60208110156118d557600080fd5b50515b6119135760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8142811015611957576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b60006119616147c2565b9050600061196e8261485e565b9050611a26600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b1580156119c157600080fd5b505afa1580156119d5573d6000803e3d6000fd5b505050506040513d60208110156119eb57600080fd5b50516040805160208b810282810182019093528b82528e928d918d918291850190849080828437600092019190915250879250615242915050565b93508884600186510381518110611a3957fe5b60200260200101511015611a7e5760405162461bcd60e51b815260040180806020018281038252602c815260200180615e20602c913960400191505060405180910390fd5b600080546001600160a01b03169063d9fc4b61908a908a9081611a9d57fe5b905060200201356001600160a01b031684611adb8c8c6000818110611abe57fe5b905060200201356001600160a01b03168d8d6001818110610fd657fe5b88600081518110611ae857fe5b60200260200101516040518563ffffffff1660e01b815260040180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b03168152602001828152602001945050505050600060405180830381600087803b158015611b7157600080fd5b505af1158015611b85573d6000803e3d6000fd5b50505050611bc982858a8a808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508c9250614b49915050565b5050509695505050505050565b6000546001600160a01b0316331480611c745750611bf261474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015611c4757600080fd5b505afa158015611c5b573d6000803e3d6000fd5b505050506040513d6020811015611c7157600080fd5b50515b611caf5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8042811015611cf3576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600080546001600160a01b03169063d9fc4b61908790879081611d1257fe5b905060200201356001600160a01b0316611d2a6147c2565b611d3a898960008181106115bb57fe5b604080516001600160e01b031960e087901b1681526001600160a01b039485166004820152928416602484015292166044820152606481018b90529051608480830192600092919082900301818387803b158015611d9757600080fd5b505af1158015611dab573d6000803e3d6000fd5b505050506000858560018888905003818110611dc357fe5b905060200201356001600160a01b03166001600160a01b03166370a08231856040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015611e2857600080fd5b505afa158015611e3c573d6000803e3d6000fd5b505050506040513d6020811015611e5257600080fd5b50516040805160208881028281018201909352888252929350611e94929091899189918291850190849080828437600092019190915250889250614e81915050565b86611f0e8288886000198101818110611ea957fe5b905060200201356001600160a01b03166001600160a01b03166370a08231886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156117b757600080fd5b1015611f4b5760405162461bcd60e51b815260040180806020018281038252602c815260200180615e20602c913960400191505060405180910390fd5b5050505050505050565b6000805481906001600160a01b0316331480611ff65750611f7461474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015611fc957600080fd5b505afa158015611fdd573d6000803e3d6000fd5b505050506040513d6020811015611ff357600080fd5b50515b6120315760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561207657600080fd5b505afa15801561208a573d6000803e3d6000fd5b505050506040513d60208110156120a057600080fd5b5051905060006120b08e83614a86565b90506000886120bf578d6120c3565b6000195b9050816001600160a01b031663d505accf6120dc6147c2565b60008054604080516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909116602484015260448301869052606483018f905260ff8d16608484015260a483018c905260c483018b90525160e48084019382900301818387803b15801561214f57600080fd5b505af1158015612163573d6000803e3d6000fd5b505050506121758f8f8f8f8f8f612ca1565b80955081965050505050509a509a98505050505050505050565b6000546060906001600160a01b031633148061223057506121ae61474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561220357600080fd5b505afa158015612217573d6000803e3d6000fd5b505050506040513d602081101561222d57600080fd5b50515b61226b5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b81428110156122af576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b60006122b96147c2565b905060006122c68261485e565b905061237e600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b15801561231957600080fd5b505afa15801561232d573d6000803e3d6000fd5b505050506040513d602081101561234357600080fd5b50516040805160208b810282810182019093528b82528e928d918d91829185019084908082843760009201919091525087925061494e915050565b9350888460008151811061238e57fe5b60200260200101511115611a7e5760405162461bcd60e51b8152600401808060200182810382526028815260200180615df86028913960400191505060405180910390fd5b6000546060906001600160a01b031633148061247457506123f261474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561244757600080fd5b505afa15801561245b573d6000803e3d6000fd5b505050506040513d602081101561247157600080fd5b50515b6124af5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b81428110156124f3576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561253857600080fd5b505afa15801561254c573d6000803e3d6000fd5b505050506040513d602081101561256257600080fd5b505190506001600160a01b038116878760008161257b57fe5b905060200201356001600160a01b03166001600160a01b0316146125d4576040805162461bcd60e51b815260206004820152601e6024820152600080516020615f0b833981519152604482015290519081900360640190fd5b60006125de6147c2565b905060006125eb8261485e565b90506126a3600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b15801561263e57600080fd5b505afa158015612652573d6000803e3d6000fd5b505050506040513d602081101561266857600080fd5b50516040805160208c810282810182019093528c825234928e918e918291850190849080828437600092019190915250879250615242915050565b945089856001875103815181106126b657fe5b602002602001015110156126fb5760405162461bcd60e51b815260040180806020018281038252602c815260200180615e20602c913960400191505060405180910390fd5b826001600160a01b031663d0e30db08660008151811061271757fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b15801561274a57600080fd5b505af115801561275e573d6000803e3d6000fd5b5050505050826001600160a01b031663a9059cbb61279f8b8b600081811061278257fe5b905060200201356001600160a01b03168c8c6001818110610fd657fe5b876000815181106127ac57fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561280357600080fd5b505af1158015612817573d6000803e3d6000fd5b505050506040513d602081101561282d57600080fd5b505161283557fe5b61287582868b8b808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508d9250614b49915050565b5050505095945050505050565b60008054819081906001600160a01b031633148061292557506128a361474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156128f857600080fd5b505afa15801561290c573d6000803e3d6000fd5b505050506040513d602081101561292257600080fd5b50515b6129605760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b83428110156129a4576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b1580156129e957600080fd5b505afa1580156129fd573d6000803e3d6000fd5b505050506040513d6020811015612a1357600080fd5b50519050612a258b828c348d8d615363565b90955093506000612a368c83614a86565b90506000612a426147c2565b90506000809054906101000a90046001600160a01b03166001600160a01b031663d9fc4b618e83858b6040518563ffffffff1660e01b815260040180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b03168152602001828152602001945050505050600060405180830381600087803b158015612aec57600080fd5b505af1158015612b00573d6000803e3d6000fd5b50505050826001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b158015612b3f57600080fd5b505af1158015612b53573d6000803e3d6000fd5b50506040805163a9059cbb60e01b81526001600160a01b038781166004830152602482018c90529151918816945063a9059cbb935060448082019350602092918290030181600087803b158015612ba957600080fd5b505af1158015612bbd573d6000803e3d6000fd5b505050506040513d6020811015612bd357600080fd5b5051612bdb57fe5b612be36155f0565b6040805163318c2e2160e11b81526001600160a01b03858116600483015284811660248301528c81166044830152915192909116916363185c42916064808201926020929091908290030181600087803b158015612c4057600080fd5b505af1158015612c54573d6000803e3d6000fd5b505050506040513d6020811015612c6a57600080fd5b5051945034861015612c8257612c8281873403614d89565b5050505096509650969350505050565b6004546001600160a01b031681565b6000805481906001600160a01b0316331480612d425750612cc061474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015612d1557600080fd5b505afa158015612d29573d6000803e3d6000fd5b505050506040513d6020811015612d3f57600080fd5b50515b612d7d5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8242811015612dc1576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b158015612e0657600080fd5b505afa158015612e1a573d6000803e3d6000fd5b505050506040513d6020811015612e3057600080fd5b50519050612e438a828b8b8b308b612ec8565b9094509250612e538a8786615635565b806001600160a01b0316632e1a7d4d846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015612e9957600080fd5b505af1158015612ead573d6000803e3d6000fd5b50505050612ebb8684614d89565b5050965096945050505050565b6000805481906001600160a01b0316331480612f695750612ee761474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015612f3c57600080fd5b505afa158015612f50573d6000803e3d6000fd5b505050506040513d6020811015612f6657600080fd5b50515b612fa45760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8242811015612fe8576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b6000612ff48b8b614a86565b905060006130006147c2565b905061300a6155f0565b6040805163cebdd1bb60e01b81526001600160a01b0385811660048301528481166024830152604482018e90529151929091169163cebdd1bb916064808201926020929091908290030181600087803b15801561306657600080fd5b505af115801561307a573d6000803e3d6000fd5b505050506040513d602081101561309057600080fd5b50600090508061309e6155f0565b60408051631168473b60e21b81526001600160a01b03878116600483015286811660248301528c8116604483015282519316926345a11cec926064808401939192918290030181600087803b1580156130f657600080fd5b505af115801561310a573d6000803e3d6000fd5b505050506040513d604081101561312057600080fd5b5080516020909101519092509050600061313a8f8f615798565b509050806001600160a01b03168f6001600160a01b03161461315d578183613160565b82825b90985096508b8810156131a45760405162461bcd60e51b8152600401808060200182810382526027815260200180615d546027913960400191505060405180910390fd5b8a8710156131e35760405162461bcd60e51b8152600401808060200182810382526027815260200180615d7b6027913960400191505060405180910390fd5b50505050505097509795505050505050565b6001546001600160a01b031681565b6000546001600160a01b0316331461324d5760405162461bcd60e51b8152600401808060200182810382526030815260200180615dc86030913960400191505060405180910390fd5b806001600160a01b031663c3fb90d66040518163ffffffff1660e01b815260040160206040518083038186803b15801561328657600080fd5b505afa15801561329a573d6000803e3d6000fd5b505050506040513d60208110156132b057600080fd5b5051600180546001600160a01b0319166001600160a01b03909216919091179055610c3d8181565b6000546060906001600160a01b031633148061337957506132f761474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561334c57600080fd5b505afa158015613360573d6000803e3d6000fd5b505050506040513d602081101561337657600080fd5b50515b6133b45760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b81428110156133f8576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561343d57600080fd5b505afa158015613451573d6000803e3d6000fd5b505050506040513d602081101561346757600080fd5b505190506001600160a01b0381168787600019810181811061348557fe5b905060200201356001600160a01b03166001600160a01b0316146134de576040805162461bcd60e51b815260206004820152601e6024820152600080516020615f0b833981519152604482015290519081900360640190fd5b60006134e86147c2565b905060006134f58261485e565b90506135ad600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b15801561354857600080fd5b505afa15801561355c573d6000803e3d6000fd5b505050506040513d602081101561357257600080fd5b50516040805160208c810282810182019093528c82528f928e918e918291850190849080828437600092019190915250879250615242915050565b945089856001875103815181106135c057fe5b60200260200101511015610f795760405162461bcd60e51b815260040180806020018281038252602c815260200180615e20602c913960400191505060405180910390fd5b6000546001600160a01b03163314806136a3575061362161474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561367657600080fd5b505afa15801561368a573d6000803e3d6000fd5b505050506040513d60208110156136a057600080fd5b50515b6136de5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8042811015613722576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561376757600080fd5b505afa15801561377b573d6000803e3d6000fd5b505050506040513d602081101561379157600080fd5b505190506001600160a01b038116868660001981018181106137af57fe5b905060200201356001600160a01b03166001600160a01b031614613808576040805162461bcd60e51b815260206004820152601e6024820152600080516020615f0b833981519152604482015290519081900360640190fd5b60006138126147c2565b600080549192506001600160a01b039091169063d9fc4b6190899089908161383657fe5b905060200201356001600160a01b0316836138578b8b600081811061278257fe5b604080516001600160e01b031960e087901b1681526001600160a01b039485166004820152928416602484015292166044820152606481018d90529051608480830192600092919082900301818387803b1580156138b457600080fd5b505af11580156138c8573d6000803e3d6000fd5b5050505061390a878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250309250614e81915050565b604080516370a0823160e01b815230600482015290516000916001600160a01b038516916370a0823191602480820192602092909190829003018186803b15801561395457600080fd5b505afa158015613968573d6000803e3d6000fd5b505050506040513d602081101561397e57600080fd5b50519050888110156139c15760405162461bcd60e51b815260040180806020018281038252602c815260200180615e20602c913960400191505060405180910390fd5b826001600160a01b0316632e1a7d4d826040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b158015613a0757600080fd5b505af1158015613a1b573d6000803e3d6000fd5b50505050613a298682614d89565b50505050505050505050565b6000546060906001600160a01b0316331480613ad65750613a5461474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015613aa957600080fd5b505afa158015613abd573d6000803e3d6000fd5b505050506040513d6020811015613ad357600080fd5b50515b613b115760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8142811015613b55576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b158015613b9a57600080fd5b505afa158015613bae573d6000803e3d6000fd5b505050506040513d6020811015613bc457600080fd5b505190506001600160a01b0381168787600081613bdd57fe5b905060200201356001600160a01b03166001600160a01b031614613c36576040805162461bcd60e51b815260206004820152601e6024820152600080516020615f0b833981519152604482015290519081900360640190fd5b6000613c406147c2565b90506000613c4d8261485e565b9050613d05600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b158015613ca057600080fd5b505afa158015613cb4573d6000803e3d6000fd5b505050506040513d6020811015613cca57600080fd5b50516040805160208c810282810182019093528c82528e928e918e91829185019084908082843760009201919091525087925061494e915050565b94503485600081518110613d1557fe5b60200260200101511115613d5a5760405162461bcd60e51b8152600401808060200182810382526028815260200180615df86028913960400191505060405180910390fd5b826001600160a01b031663d0e30db086600081518110613d7657fe5b60200260200101516040518263ffffffff1660e01b81526004016000604051808303818588803b158015613da957600080fd5b505af1158015613dbd573d6000803e3d6000fd5b5050505050826001600160a01b031663a9059cbb613de18b8b600081811061278257fe5b87600081518110613dee57fe5b60200260200101516040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b158015613e4557600080fd5b505af1158015613e59573d6000803e3d6000fd5b505050506040513d6020811015613e6f57600080fd5b5051613e7757fe5b613eb782868b8b808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152508d9250614b49915050565b84600081518110613ec457fe5b6020026020010151341115612875576128758286600081518110613ee457fe5b60200260200101513403614d89565b600080546001600160a01b0316331480613f925750613f1061474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015613f6557600080fd5b505afa158015613f79573d6000803e3d6000fd5b505050506040513d6020811015613f8f57600080fd5b50515b613fcd5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561401257600080fd5b505afa158015614026573d6000803e3d6000fd5b505050506040513d602081101561403c57600080fd5b50519050600061404c8d83614a86565b905060008761405b578c61405f565b6000195b9050816001600160a01b031663d505accf6140786147c2565b60008054604080516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909116602484015260448301869052606483018e905260ff8c16608484015260a483018b905260c483018a90525160e48084019382900301818387803b1580156140eb57600080fd5b505af11580156140ff573d6000803e3d6000fd5b505050506141118e8e8e8e8e8e614123565b9e9d5050505050505050505050505050565b600080546001600160a01b03163314806141c2575061414061474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561419557600080fd5b505afa1580156141a9573d6000803e3d6000fd5b505050506040513d60208110156141bf57600080fd5b50515b6141fd5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b8142811015614241576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b600154604080516317d28c5760e31b815290516000926001600160a01b03169163be9462b8916004808301926020929190829003018186803b15801561428657600080fd5b505afa15801561429a573d6000803e3d6000fd5b505050506040513d60208110156142b057600080fd5b505190506142c389828a8a8a308a612ec8565b604080516370a0823160e01b8152306004820152905191955061434792508b9188916001600160a01b038416916370a0823191602480820192602092909190829003018186803b15801561431657600080fd5b505afa15801561432a573d6000803e3d6000fd5b505050506040513d602081101561434057600080fd5b5051615635565b806001600160a01b0316632e1a7d4d846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561438d57600080fd5b505af11580156143a1573d6000803e3d6000fd5b505050506143af8584614d89565b50509695505050505050565b60008054819081906001600160a01b031633148061445e57506143dc61474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561443157600080fd5b505afa158015614445573d6000803e3d6000fd5b505050506040513d602081101561445b57600080fd5b50515b6144995760405162461bcd60e51b815260040180806020018281038252602c815260200180615f57602c913960400191505060405180910390fd5b83428110156144dd576040805162461bcd60e51b81526020600482015260196024820152600080516020615e79833981519152604482015290519081900360640190fd5b6144eb8c8c8c8c8c8c615363565b909450925060006144fc8d8d614a86565b905060006145086147c2565b90506000809054906101000a90046001600160a01b03166001600160a01b031663d9fc4b618f83858a6040518563ffffffff1660e01b815260040180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b03168152602001828152602001945050505050600060405180830381600087803b1580156145b257600080fd5b505af11580156145c6573d6000803e3d6000fd5b505050506000809054906101000a90046001600160a01b03166001600160a01b031663d9fc4b618e8385896040518563ffffffff1660e01b815260040180856001600160a01b03166001600160a01b03168152602001846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b03168152602001828152602001945050505050600060405180830381600087803b15801561467257600080fd5b505af1158015614686573d6000803e3d6000fd5b505050506146926155f0565b6040805163318c2e2160e11b81526001600160a01b03858116600483015284811660248301528b81166044830152915192909116916363185c42916064808201926020929091908290030181600087803b1580156146ef57600080fd5b505af1158015614703573d6000803e3d6000fd5b505050506040513d602081101561471957600080fd5b5051959e949d50949b50929950505050505050505050565b6000546001600160a01b031681565b806001600160a01b0316ff5b60035460408051638abf607760e01b815290516000926001600160a01b031691638abf6077916004808301926020929190829003018186803b15801561479157600080fd5b505afa1580156147a5573d6000803e3d6000fd5b505050506040513d60208110156147bb57600080fd5b5051919050565b60006147cc61474c565b6001600160a01b0316633af32abf336040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561482157600080fd5b505afa158015614835573d6000803e3d6000fd5b505050506040513d602081101561484b57600080fd5b50516148575732614859565b335b905090565b6004805460408051638abf607760e01b8152905160009384936001600160a01b031692638abf60779281830192602092829003018186803b1580156148a257600080fd5b505afa1580156148b6573d6000803e3d6000fd5b505050506040513d60208110156148cc57600080fd5b50516040805163167801e160e11b81526001600160a01b038681166004830152915192935090831691632cf003c291602480820192602092909190829003018186803b15801561491b57600080fd5b505afa15801561492f573d6000803e3d6000fd5b505050506040513d602081101561494557600080fd5b50519392505050565b60606002835110156149a7576040805162461bcd60e51b815260206004820152601f60248201527f456e65726769737761704c6962726172793a20494e56414c49445f5041544800604482015290519081900360640190fd5b82516040519080825280602002602001820160405280156149d2578160200160208202803883390190505b50905083816001835103815181106149e657fe5b60209081029190910101528251600019015b8015614a7d57600080614a3588876001860381518110614a1457fe5b6020026020010151888681518110614a2857fe5b6020026020010151615876565b91509150614a58848481518110614a4857fe5b60200260200101518383886159c3565b846001850381518110614a6757fe5b60209081029190910101525050600019016149f8565b50949350505050565b60015460408051632233163960e21b815290516000926001600160a01b0316916388cc58e4916004808301926020929190829003018186803b158015614acb57600080fd5b505afa158015614adf573d6000803e3d6000fd5b505050506040513d6020811015614af557600080fd5b50516040805163e6a4390560e01b81526001600160a01b03868116600483015285811660248301529151919092169163e6a43905916044808301926020929190829003018186803b15801561491b57600080fd5b60005b6001835103811015614d8257600080848381518110614b6757fe5b6020026020010151858460010181518110614b7e57fe5b6020026020010151915091506000614b968383615798565b5090506000878560010181518110614baa57fe5b60200260200101519050600080836001600160a01b0316866001600160a01b031614614bd857826000614bdc565b6000835b91509150600060028a51038810614bf35788614c13565b614c13868b8a60020181518110614c0657fe5b6020026020010151614a86565b9050614c1d6155f0565b6001600160a01b031663b69cbf9f614c358989614a86565b8e86868660006040519080825280601f01601f191660200182016040528015614c65576020820181803883390190505b506040518763ffffffff1660e01b815260040180876001600160a01b03166001600160a01b03168152602001866001600160a01b03166001600160a01b03168152602001858152602001848152602001836001600160a01b03166001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b83811015614d06578181015183820152602001614cee565b50505050905090810190601f168015614d335780820380516001836020036101000a031916815260200191505b50975050505050505050600060405180830381600087803b158015614d5757600080fd5b505af1158015614d6b573d6000803e3d6000fd5b505060019099019850614b4c975050505050505050565b5050505050565b604080516000808252602082019092526001600160a01b0384169083906040518082805190602001908083835b60208310614dd55780518252601f199092019160209182019101614db6565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114614e37576040519150601f19603f3d011682016040523d82523d6000602084013e614e3c565b606091505b5050905080614e7c5760405162461bcd60e51b8152600401808060200182810382526023815260200180615e996023913960400191505060405180910390fd5b505050565b60005b6001835103811015614e7c57600080848381518110614e9f57fe5b6020026020010151858460010181518110614eb657fe5b6020026020010151915091506000614ece8383615798565b5090506000614edd8484614a86565b90506000614ee96147c2565b9050600080600080614ef96155f0565b6001600160a01b0316633e99c1e4876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060606040518083038186803b158015614f4e57600080fd5b505afa158015614f62573d6000803e3d6000fd5b505050506040513d6060811015614f7857600080fd5b5080516020909101516001600160701b0391821693501690506000806001600160a01b038b8116908a1614614fae578284614fb1565b83835b9150915061500f828c6001600160a01b03166370a082318b6040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b1580156117b757600080fd5b9550600061501c8861485e565b905061502a87848484615ade565b95505050505050600080866001600160a01b0316896001600160a01b03161461505557826000615059565b6000835b91509150600060028d51038b10615070578b615083565b615083898e8d60020181518110614c0657fe5b905061508d6155f0565b6001600160a01b031663b69cbf9f888886868660006040519080825280601f01601f1916602001820160405280156150cc576020820181803883390190505b506040518763ffffffff1660e01b815260040180876001600160a01b03166001600160a01b03168152602001866001600160a01b03166001600160a01b03168152602001858152602001848152602001836001600160a01b03166001600160a01b0316815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561516d578181015183820152602001615155565b50505050905090810190601f16801561519a5780820380516001836020036101000a031916815260200191505b50975050505050505050600060405180830381600087803b1580156151be57600080fd5b505af11580156151d2573d6000803e3d6000fd5b50506001909c019b50614e849a5050505050505050505050565b8082038281111561523c576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b92915050565b606060028351101561529b576040805162461bcd60e51b815260206004820152601f60248201527f456e65726769737761704c6962726172793a20494e56414c49445f5041544800604482015290519081900360640190fd5b82516040519080825280602002602001820160405280156152c6578160200160208202803883390190505b50905083816000815181106152d757fe5b60200260200101818152505060005b6001845103811015614a7d5760008061531c8887858151811061530557fe5b6020026020010151888660010181518110614a2857fe5b9150915061533f84848151811061532f57fe5b6020026020010151838388615ade565b84846001018151811061534e57fe5b602090810291909101015250506001016152e6565b600080806153718989614a86565b6001600160a01b0316141561547b57600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b1580156153ce57600080fd5b505afa1580156153e2573d6000803e3d6000fd5b505050506040513d60208110156153f857600080fd5b5051604080516364e329cb60e11b81526001600160a01b038b811660048301528a811660248301529151919092169163c9c653969160448083019260209291908290030181600087803b15801561544e57600080fd5b505af1158015615462573d6000803e3d6000fd5b505050506040513d602081101561547857600080fd5b50505b600080615502600160009054906101000a90046001600160a01b03166001600160a01b03166388cc58e46040518163ffffffff1660e01b815260040160206040518083038186803b1580156154cf57600080fd5b505afa1580156154e3573d6000803e3d6000fd5b505050506040513d60208110156154f957600080fd5b50518b8b615876565b91509150816000148015615514575080155b1561552457879350869250612ebb565b6000615531898484615bf5565b905087811161558457858110156155795760405162461bcd60e51b8152600401808060200182810382526027815260200180615d7b6027913960400191505060405180910390fd5b8894509250826155e2565b6000615591898486615bf5565b90508981111561559d57fe5b878110156155dc5760405162461bcd60e51b8152600401808060200182810382526027815260200180615d546027913960400191505060405180910390fd5b94508793505b505050965096945050505050565b60025460408051638abf607760e01b815290516000926001600160a01b031691638abf6077916004808301926020929190829003018186803b15801561479157600080fd5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106156b25780518252601f199092019160209182019101615693565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114615714576040519150601f19603f3d011682016040523d82523d6000602084013e615719565b606091505b5091509150818015615747575080511580615747575080806020019051602081101561574457600080fd5b50515b614d82576040805162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c454400604482015290519081900360640190fd5b600080826001600160a01b0316846001600160a01b031614156157ec5760405162461bcd60e51b8152600401808060200182810382526026815260200180615da26026913960400191505060405180910390fd5b826001600160a01b0316846001600160a01b03161061580c57828461580f565b83835b90925090506001600160a01b03821661586f576040805162461bcd60e51b815260206004820152601f60248201527f456e65726769737761704c6962726172793a205a45524f5f4144445245535300604482015290519081900360640190fd5b9250929050565b60008060006158858585615798565b506040805163e6a4390560e01b81526001600160a01b038881166004830152878116602483015291519293506000929189169163e6a4390591604480820192602092909190829003018186803b1580156158de57600080fd5b505afa1580156158f2573d6000803e3d6000fd5b505050506040513d602081101561590857600080fd5b505160408051630240bc6b60e21b8152905191925060009182916001600160a01b03851691630902f1ac91600480820192606092909190829003018186803b15801561595357600080fd5b505afa158015615967573d6000803e3d6000fd5b505050506040513d606081101561597d57600080fd5b5080516020909101516001600160701b0391821693501690506001600160a01b03888116908516146159b05780826159b3565b81815b909a909950975050505050505050565b6000808511615a035760405162461bcd60e51b815260040180806020018281038252602d815260200180615e4c602d913960400191505060405180910390fd5b600084118015615a135750600083115b615a4e5760405162461bcd60e51b8152600401808060200182810382526029815260200180615ebc6029913960400191505060405180910390fd5b6000615a72612710615a66878963ffffffff615ca116565b9063ffffffff615ca116565b905060006001600160a01b03841615615aa057615a9b6126f5615a66878a63ffffffff6151ec16565b615ab6565b615ab66126f2615a66878a63ffffffff6151ec16565b9050615ad36001828481615ac657fe5b049063ffffffff615d0416565b979650505050505050565b6000808511615b1e5760405162461bcd60e51b815260040180806020018281038252602c815260200180615f2b602c913960400191505060405180910390fd5b600084118015615b2e5750600083115b615b695760405162461bcd60e51b8152600401808060200182810382526029815260200180615ebc6029913960400191505060405180910390fd5b60006001600160a01b03831615615b9157615b8c866126f563ffffffff615ca116565b615ba3565b615ba3866126f263ffffffff615ca116565b90506000615bb7828663ffffffff615ca116565b90506000615bdd83615bd18961271063ffffffff615ca116565b9063ffffffff615d0416565b9050808281615be857fe5b0498975050505050505050565b6000808411615c355760405162461bcd60e51b8152600401808060200182810382526026815260200180615ee56026913960400191505060405180910390fd5b600083118015615c455750600082115b615c805760405162461bcd60e51b8152600401808060200182810382526029815260200180615ebc6029913960400191505060405180910390fd5b82615c91858463ffffffff615ca116565b81615c9857fe5b04949350505050565b6000811580615cbc57505080820282828281615cb957fe5b04145b61523c576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b8082018281101561523c576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe456e6572676973776170526f757465723a20494e53554646494349454e545f415f414d4f554e54456e6572676973776170526f757465723a20494e53554646494349454e545f425f414d4f554e54456e65726769737761704c6962726172793a204944454e544943414c5f414444524553534553456e6572676973776170476f7665726e6564436f6e74726163743a20464f5242494444454e2c206e6f742070726f7879456e6572676973776170526f757465723a204558434553534956455f494e5055545f414d4f554e54456e6572676973776170526f757465723a20494e53554646494349454e545f4f55545055545f414d4f554e54456e65726769737761704c6962726172793a20494e53554646494349454e545f4f55545055545f414d4f554e54456e6572676973776170526f757465723a2045585049524544000000000000005472616e7366657248656c7065723a204e52475f5452414e534645525f4641494c4544456e65726769737761704c6962726172793a20494e53554646494349454e545f4c4951554944495459456e65726769737761704c6962726172793a20494e53554646494349454e545f414d4f554e54456e6572676973776170526f757465723a20494e56414c49445f504154480000456e65726769737761704c6962726172793a20494e53554646494349454e545f494e5055545f414d4f554e54456e6572676973776170526f757465723a20464f5242494444454e2c206e6f742077686974656c6973746564a265627a7a72315820040448fac157d12e5e2f52d19dff4059286e5c227b1f73146348134b90cfe53f64736f6c63430005100032