Verified contractExactUNLICENSED
LiquidityBookSwapHandler
Address0x9b54917c6f2a7276640fc0e09a9568d65263ceb1
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- Via IR
- yes
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,523,254
- Creation transaction
- 0x33737b13c9…f52220755d
8 files
- contracts/router/modules/LiquidityBookSwapHandler.solmain1.58 KB
- @openzeppelin/contracts/access/Ownable.sol3.1 KB
- @openzeppelin/contracts/utils/Context.sol963 B
- @uniswap/lib/contracts/libraries/TransferHelper.sol1.81 KB
- contracts/router/interfaces/IAkkaMerchantmoev2Pool.sol646 B
- contracts/router/interfaces/ISwapHandler.sol553 B
- contracts/shared/interfaces/IERC20.sol867 B
- contracts/shared/libraries/SafeMath.sol905 B
contracts/router/modules/LiquidityBookSwapHandler.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
import "@uniswap/lib/contracts/libraries/TransferHelper.sol";
import "../interfaces/ISwapHandler.sol";
import "../interfaces/IAkkaMerchantmoev2Pool.sol";
import "../../shared/interfaces/IERC20.sol";
import "../../shared/libraries/SafeMath.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract LiquidityBookSwapHandler is ISwapHandler, Ownable {
using SafeMath for uint;
constructor() Ownable(msg.sender) {}
function executeSwap(
PathDescription memory path,
uint256 amount,
address from,
address to
) external override returns (uint256 amountOut) {
uint256 amountIn = 0;
if (amount == 0) {
amountIn = IERC20(path.srcToken).balanceOf(address(this));
}
else {
amountIn = amount;
}
TransferHelper.safeTransfer(
path.srcToken,
path.pairAddr,
amountIn
);
bool swapForY = (path.dstToken == address(Merchantmoev2Pool(path.pairAddr).getTokenY()));
bytes32 amountsOut = Merchantmoev2Pool(path.pairAddr).swap(swapForY, to);
if (swapForY){
uint256 amountYOut = uint256(amountsOut) >> 128; // Get the higher 128 bits (amountY)
amountOut = amountYOut;
}
else {
uint256 amountXOut = uint256(amountsOut) & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; // Get the lower 128 bits (amountX)
amountOut = amountXOut;
}
return amountOut;
}
}@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
@uniswap/lib/contracts/libraries/TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.6.0;
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 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::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 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::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
contracts/router/interfaces/IAkkaMerchantmoev2Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '../../shared/interfaces/IERC20.sol';
interface Merchantmoev2Pool {
function getBinStep() external view returns (uint16 binStep);
function getActiveId() external view returns (uint24 activeId);
function getTokenX() external view returns (IERC20 tokenX);
function getTokenY() external view returns (IERC20 tokenY);
function getSwapOut(uint128 amountIn, bool swapForY) external view returns (uint128 amountInLeft, uint128 amountOut, uint128 fee) ;
function swap(bool swapForY, address to) external returns (bytes32 amountsOut);
}contracts/router/interfaces/ISwapHandler.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
interface ISwapHandler {
struct PathDescription {
address srcToken;
address dstToken;
address pairAddr;
uint256 fee;
uint256 srcAmount;
uint256 dstMinAmount;
uint256 feeSrc;
uint256 feeDst;
uint256 liquidityType;
bytes data;
}
function executeSwap(
PathDescription memory path,
uint256 amount,
address from,
address to
) external returns (uint256 amountOut);
}contracts/shared/interfaces/IERC20.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
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);
}contracts/shared/libraries/SafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;
// 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');
}
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}Compiler settingsShow
{
"viaIR": true,
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.