Verified contractExactUNLICENSED
BebopSwapHandler
Address0x776ec372ea9e99a903b1bfb68ca7007ca01cc6f5
- 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
- 26,132,118
- Creation transaction
- 0x3f2ca25617…8104467731
10 files
- contracts/router/modules/BebopSwapHandler.solmain10.25 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/IAkkaPair.sol2.42 KB
- contracts/router/interfaces/ISwapHandler.sol553 B
- contracts/router/libraries/AkkaLibrary.sol3.56 KB
- contracts/router/libraries/HandlerGas.sol3.03 KB
- contracts/shared/interfaces/IERC20.sol867 B
- contracts/shared/libraries/SafeMath.sol905 B
contracts/router/modules/BebopSwapHandler.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;
import "@uniswap/lib/contracts/libraries/TransferHelper.sol";
import "../interfaces/ISwapHandler.sol";
import "../../shared/interfaces/IERC20.sol";
import "../libraries/AkkaLibrary.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import "../libraries/HandlerGas.sol";
interface Ibebop {
function swapSingle(
Single calldata order,
MakerSignature calldata makerSignature,
uint256 filledTakerAmount
) external;
struct MakerSignature {
bytes signatureBytes;
uint256 flags;
}
struct Single {
uint256 expiry;
address taker_address;
address maker_address;
uint256 maker_nonce;
address taker_token;
address maker_token;
uint256 taker_amount;
uint256 maker_amount;
address receiver;
uint256 packed_commands;
uint256 flags;
}
}
/// @title BebopSwapHandler
/// @notice Router-side handler for Bebop RFQ. Dispatches by the leading selector
/// of the Bebop-provided calldata:
/// * new BebopRouter `swap(...)` (0x9586d0e8) — the current RFQ format
/// (BebopRouter 0xBeb0009A wraps BebopSettlement). We patch only the
/// leading `exactAmount` word to the actual routed input and forward.
/// * legacy BebopSettlement `swapSingle`/`swapAggregate` — kept so a
/// handler-first / backend-second migration has no broken window.
/// `path.pairAddr` is the Bebop-provided `tx.to` (== approvalTarget for
/// one-to-one RFQ = the router), so we approve and call the same address.
contract BebopSwapHandler is ISwapHandler, Ownable {
using SafeMath for uint;
// BebopRouter.swap(int256,(uint256,uint256,int256,address,address,address,
// address,address,address,address,address,address,uint256,uint256,uint256),
// bytes,bytes,bytes,(address,bytes,bytes,uint256)[])
bytes4 private constant SWAP_ROUTER = 0x9586d0e8;
bytes4 private constant SWAP_SINGLE = 0x4dcebcba;
bytes4 private constant SWAP_AGGREGATE = 0xa2f74893;
constructor() Ownable(msg.sender) {}
/// @dev Approve `spender` for exactly `amount` of `token`, resetting any
/// residual allowance to zero first. USDT (and other non-standard
/// tokens) revert inside approve() when overwriting a non-zero
/// allowance — require(!(value != 0 && current != 0)). The Bebop
/// settlement pulls only the actual fill, so the approved-minus-filled
/// surplus lingers as a non-zero allowance; the next USDT leg then
/// reverted "TransferHelper::safeApprove: approve failed" (monitor
/// #115-#130). approve(_, 0) is always allowed, so the reset is safe
/// for standard tokens too (one extra SSTORE).
function _approveExact(address token, address spender, uint256 amount) internal {
HandlerGas.approveResting(token, spender, amount);
}
// ── New BebopRouter path ─────────────────────────────────────────────────
// Calldata layout of swap(int256 exactAmount, BebopRouterOrder order, ...):
// BebopRouterOrder is an all-static struct, so it is encoded inline in the
// head, giving fixed word offsets:
// content[0..4) selector
// content[4..36) exactAmount (NOT covered by routerSignature)
// content[36..68) order.fromAmount (the quoted taker amount = cap)
// We set exactAmount = min(routed amount, order.fromAmount): the router
// pulls exactly that from msg.sender (this handler) and scales the PMM fill
// proportionally. Overfilling past the maker's taker_amount would sweep the
// surplus to Bebop's treasury (BebopRouter.swap line ~285), so we cap.
function _executeBebopRouter(PathDescription memory path, uint256 amount) internal {
bytes memory data = path.data;
require(data.length >= 68, "bebop: short router calldata");
uint256 quotedFromAmount;
assembly {
let base := add(data, 32)
quotedFromAmount := mload(add(base, 36))
}
uint256 fill = amount;
if (quotedFromAmount != 0 && fill > quotedFromAmount) {
fill = quotedFromAmount;
}
// Patch exactAmount (exactIn: positive int256 == fill).
assembly {
let base := add(data, 32)
mstore(add(base, 4), fill)
}
// approvalTarget == router == path.pairAddr for one-to-one RFQ.
_approveExact(path.srcToken, path.pairAddr, fill);
(bool success, bytes memory result) = path.pairAddr.call(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
}
// ── Legacy BebopSettlement paths (kept for migration safety) ──────────────
/// Decodes swapSingle's arguments in place, without copying the calldata.
/// The old version copied every byte after the selector in a Solidity loop
/// (~225k gas per live swapSingle leg). Here `params` points 4 bytes into
/// `data`, so its body starts right after the selector; its length word
/// overlaps the last 28 bytes of data's length word and the selector, so
/// that word is saved and restored around the decode. abi.decode only
/// reads `params` and returns freshly allocated structs.
function decodeSwapSingleParams(bytes memory data)
internal
pure
returns (Ibebop.Single memory order, Ibebop.MakerSignature memory makerSignature, uint256 filledTakerAmount)
{
require(data.length >= 4, "Invalid calldata");
bytes memory params;
uint256 saved;
assembly ("memory-safe") {
params := add(data, 4)
saved := mload(params)
mstore(params, sub(mload(data), 4))
}
(order, makerSignature, filledTakerAmount) = abi.decode(params, (Ibebop.Single, Ibebop.MakerSignature,uint256));
assembly ("memory-safe") {
mstore(params, saved)
}
}
function _executeSwapSingle(PathDescription memory path, uint256 amount) internal {
(Ibebop.Single memory order, Ibebop.MakerSignature memory sig, ) = decodeSwapSingleParams(path.data);
uint256 actualFillAmount = amount;
if (actualFillAmount > order.taker_amount) {
actualFillAmount = order.taker_amount;
}
order.taker_address = address(this);
order.receiver = address(this);
_approveExact(path.srcToken, path.pairAddr, actualFillAmount);
Ibebop(path.pairAddr).swapSingle(order, sig, actualFillAmount);
}
// ABI layout of swapAggregate(Aggregate, MakerSignature[], uint256):
// byte 4: offset to Aggregate data
// byte 36: offset to MakerSignature[] data
// byte 68: filledTakerAmount (static, inline)
// Inside Aggregate struct (at 4 + aggOffset): +32 taker_address, +256 receiver
function _executeSwapAggregate(PathDescription memory path, uint256 amount) internal {
bytes memory data = path.data;
uint256 currentFilled;
uint256 aggOffset;
assembly {
let base := add(data, 32)
currentFilled := mload(add(base, 68))
aggOffset := mload(add(base, 4))
}
uint256 actualFillAmount = (currentFilled == 0 || amount < currentFilled) ? amount : currentFilled;
assembly {
let base := add(data, 32)
let aggStart := add(base, add(4, aggOffset))
mstore(add(aggStart, 32), address()) // taker_address
mstore(add(aggStart, 256), address()) // receiver
mstore(add(base, 68), actualFillAmount) // filledTakerAmount
}
_approveExact(path.srcToken, path.pairAddr, actualFillAmount);
(bool success, bytes memory result) = path.pairAddr.call(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
}
function executeSwap(
PathDescription memory path,
uint256 amount,
address from,
address to
) external override returns (uint256 amountOut) {
bytes memory data = path.data;
require(data.length >= 4, "Invalid calldata");
// amount == 0 resolves to our own balance — i.e. exactly what the
// dispatching module transferred in (repo-wide handler convention;
// both swap modules pass 0 so fee-on-transfer intermediates fill
// with the NET received amount). Taking 0 literally here made the
// legacy paths approve(0) while passing filledTakerAmount=0 — which
// legacy BebopSettlement reads as FULL fill — so every settle pulled
// the whole taker_amount against a zero allowance and reverted
// "ERC20: insufficient allowance" (every ETH bebop leg, 2026-07).
uint256 amountIn = HandlerGas.inputAmount(path.srcToken, amount);
require(amountIn > 0, "bebop: zero input");
bytes4 sel;
assembly {
sel := mload(add(data, 32))
}
if (sel == SWAP_ROUTER) {
_executeBebopRouter(path, amountIn);
} else if (sel == SWAP_SINGLE) {
_executeSwapSingle(path, amountIn);
} else if (sel == SWAP_AGGREGATE) {
_executeSwapAggregate(path, amountIn);
} else {
revert("Unknown Bebop selector");
}
// Oku gas upgrade: the allowance to the settlement rests at 1 unit and
// the handler keeps 1 unit of each token it sweeps (HandlerGas), so no
// slot goes 0 -> x -> 0 in a swap.
HandlerGas.settleAllowance(path.srcToken, path.pairAddr);
uint256 remain = HandlerGas.spendable(path.srcToken);
if (remain > 0){
TransferHelper.safeTransfer(path.srcToken, msg.sender, remain);
}
amountOut = HandlerGas.spendable(path.dstToken);
TransferHelper.safeTransfer(path.dstToken, to, 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/IAkkaPair.sol
pragma solidity 0.8.20;
interface IAkkaPair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure 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);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(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(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
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 initialize(address, address) external;
}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/router/libraries/AkkaLibrary.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.20;
import "../interfaces/IAkkaPair.sol";
import "../../shared/libraries/SafeMath.sol";
library AkkaLibrary {
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, 'PancakeLibrary: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'PancakeLibrary: ZERO_ADDRESS');
}
// fetches and sorts the reserves for a pair
function getReserves(address pairAddr, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IAkkaPair(pairAddr).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, 'PancakeLibrary: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'PancakeLibrary: 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(uint256 amountIn, uint256 reserveIn, uint256 reserveOut, uint256 fee, uint256 feeSrc, uint256 feeDst) internal pure returns (uint256 amountOut) {
require(amountIn > 0, 'PancakeLibrary: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
uint256 amountInWithFeeSrc = amountIn.mul(feeSrc) / 10000;
uint256 amountInWithFee = amountInWithFeeSrc.mul(fee);
uint256 numerator = amountInWithFee.mul(reserveOut);
uint256 denominator = reserveIn.mul(10000).add(amountInWithFee);
amountOut = numerator / denominator;
// amountOut = amountOut.mul(feeDst) / 10000;
}
// 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, uint fee) internal pure returns (uint256 amountIn) {
require(amountOut > 0, 'PancakeLibrary: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(fee);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(uint256 amountIn, address[][] memory path, uint256[][] memory fees) internal view returns (uint256[] memory amounts) {
// require(path.length >= 2, 'PancakeLibrary: INVALID_PATH');
amounts = new uint256[](path.length+1);
amounts[0] = amountIn;
for (uint256 i; i < path.length; i++) {
(uint256 reserveIn, uint256 reserveOut) = getReserves(path[i][0], path[i][1], path[i][2]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut, fees[i][0], fees[i][1], fees[i][2]);
}
}
}contracts/router/libraries/HandlerGas.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "@uniswap/lib/contracts/libraries/TransferHelper.sol";
import "../../shared/interfaces/IERC20.sol";
/// Oku gas upgrade (review items 1-3): handler helpers so that a swap never
/// moves a storage slot 0 -> x -> 0. Such a slot costs 20,000 gas up front
/// and is refunded only at the end of the transaction, and eth_estimateGas
/// (what meta-aggregators rank by) counts the gas before the refund.
/// - allowances rest at 1 unit between swaps (1 -> x -> 1)
/// - balances keep 1 unit (the "dust") when the handler sweeps a token out
library HandlerGas {
uint256 internal constant RESTING_ALLOWANCE = 1;
uint256 internal constant DUST = 1;
/// Lets `spender` pull `amount`, plus the resting unit that stays after
/// an exact pull.
function approveResting(address token, address spender, uint256 amount) internal {
_approve(token, spender, amount + RESTING_ALLOWANCE);
}
/// Brings any allowance other than the resting unit back to it (a
/// partial pull, a spender that does not decrement), so no allowance
/// above 1 unit outlives the swap.
function settleAllowance(address token, address spender) internal {
if (IERC20(token).allowance(address(this), spender) != RESTING_ALLOWANCE) {
_approve(token, spender, RESTING_ALLOWANCE);
}
}
/// This contract's balance of `token` minus the 1-unit dust it keeps
/// (0 when it holds only the dust or less).
function spendable(address token) internal view returns (uint256 amount) {
amount = IERC20(token).balanceOf(address(this));
unchecked {
amount = amount > DUST ? amount - DUST : 0;
}
}
/// The input to spend: `amount`, capped at this contract's balance;
/// `amount == 0` means the balance minus the dust. The module passes the
/// exact amount it sent, but a share-rounding token (eETH, aTokens,
/// cUSDCv3) delivers 1-2 wei less. Spending the full `amount` then took
/// the shortfall from the dust and, once the dust was gone, reverted every
/// later swap of that token. Capped, such a swap spends what it holds (the
/// dust once, then what arrived).
function inputAmount(address token, uint256 amount) internal view returns (uint256 amountIn) {
if (amount == 0) return spendable(token);
amountIn = IERC20(token).balanceOf(address(this));
if (amount < amountIn) amountIn = amount;
}
/// approve(value); for tokens that refuse a nonzero -> nonzero approve
/// (USDT-style), approve(0) first and retry.
function _approve(address token, address spender, uint256 value) private {
(bool ok, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, spender, value));
if (ok && (data.length == 0 || abi.decode(data, (bool)))) return;
TransferHelper.safeApprove(token, spender, 0);
TransferHelper.safeApprove(token, spender, value);
}
}
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.