Contract Address Details
contract
0x1FCc3B22955e76Ca48bF025f1A6993685975Bb9e
- Contract Name
- PegSwap
- Creator
- 0xa5d008–c12dab at 0xc4f81c–58529c
- Balance
- 0 xDAI ( )
- Tokens
-
Fetching tokens...
- Transactions
- 171 Transactions
- Transfers
- 326 Transfers
- Gas Used
- 30,053,179
- Last Balance Update
- 22963719
Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
- Contract name:
- PegSwap
- Optimization enabled
- true
- Compiler version
- v0.6.6+commit.6c089d02
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2021-03-13T18:00:24.280185Z
Contract source code
// File: @chainlink/contracts/src/v0.6/Owned.sol // SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @title The Owned contract * @notice A contract with helpers for basic contract ownership. */ contract Owned { address public owner; address private pendingOwner; event OwnershipTransferRequested( address indexed from, address indexed to ); event OwnershipTransferred( address indexed from, address indexed to ); constructor() public { owner = msg.sender; } /** * @dev Allows an owner to begin transferring ownership to a new address, * pending. */ function transferOwnership(address _to) external onlyOwner() { pendingOwner = _to; emit OwnershipTransferRequested(owner, _to); } /** * @dev Allows an ownership transfer to be completed by the recipient. */ function acceptOwnership() external { require(msg.sender == pendingOwner, "Must be proposed owner"); address oldOwner = owner; owner = msg.sender; pendingOwner = address(0); emit OwnershipTransferred(oldOwner, msg.sender); } /** * @dev Reverts if called by anyone other than the contract owner. */ modifier onlyOwner() { require(msg.sender == owner, "Only callable by owner"); _; } } // File: @openzeppelin/contracts/utils/Context.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File: @openzeppelin/contracts/token/ERC20/IERC20.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts/math/SafeMath.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts/token/ERC20/ERC20.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) private _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name_, string memory symbol_) public { _name = name_; _symbol = symbol_; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal virtual { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } } // File: @openzeppelin/contracts/utils/ReentrancyGuard.sol // SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor () internal { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // File: contracts/v0.6/token/ERC677Receiver.sol pragma solidity ^0.6.0; abstract contract ERC677Receiver { function onTokenTransfer(address _sender, uint _value, bytes memory _data) public virtual; } // File: contracts/v0.6/PegSwap.sol pragma solidity >=0.6.0 <0.8.0; /** * @notice This contract provides a one-to-one swap between pairs of tokens. It * is controlled by an owner who manages liquidity pools for all pairs. Most * users should only interact with the swap, onTokenTransfer, and * getSwappableAmount functions. */ contract PegSwap is Owned, ReentrancyGuard { using SafeMath for uint256; event LiquidityUpdated( uint256 amount, address indexed source, address indexed target ); event TokensSwapped( uint256 amount, address indexed source, address indexed target, address indexed caller ); event StuckTokensRecovered( uint256 amount, address indexed target ); mapping(address => mapping(address => uint256)) private s_swappableAmount; /** * @dev Disallows direct send by setting a default function without the `payable` flag. */ fallback() external {} /** * @notice deposits tokens from the target of a swap pair but does not return * any. WARNING: Liquidity added through this method is only retrievable by * the owner of the contract. * @param amount count of liquidity being added * @param source the token that can be swapped for what is being deposited * @param target the token that can is being deposited for swapping */ function addLiquidity( uint256 amount, address source, address target ) external { bool allowed = owner == msg.sender || _hasLiquidity(source, target); // By only allowing the owner to add a new pair, we reduce the potential of // possible attacks mounted by malicious token contracts. require(allowed, "only owner can add pairs"); _addLiquidity(amount, source, target); require(ERC20(target).transferFrom(msg.sender, address(this), amount), "transferFrom failed"); } /** * @notice withdraws tokens from the target of a swap pair. * @dev Only callable by owner * @param amount count of liquidity being removed * @param source the token that can be swapped for what is being removed * @param target the token that can is being withdrawn from swapping */ function removeLiquidity( uint256 amount, address source, address target ) external onlyOwner() { _removeLiquidity(amount, source, target); require(ERC20(target).transfer(msg.sender, amount), "transfer failed"); } /** * @notice exchanges the source token for target token * @param amount count of tokens being swapped * @param source the token that is being given * @param target the token that is being taken */ function swap( uint256 amount, address source, address target ) external nonReentrant() { _removeLiquidity(amount, source, target); _addLiquidity(amount, target, source); emit TokensSwapped(amount, source, target, msg.sender); require(ERC20(source).transferFrom(msg.sender, address(this), amount), "transferFrom failed"); require(ERC20(target).transfer(msg.sender, amount), "transfer failed"); } /** * @notice send funds that were accidentally transferred back to the owner. This * allows rescuing of funds, and poses no additional risk as the owner could * already withdraw any funds intended to be swapped. WARNING: If not called * correctly this method can throw off the swappable token balances, but that * can be recovered from by transferring the discrepancy back to the swap. * @dev Only callable by owner * @param amount count of tokens being moved * @param target the token that is being moved */ function recoverStuckTokens( uint256 amount, address target ) external onlyOwner() { emit StuckTokensRecovered(amount, target); require(ERC20(target).transfer(msg.sender, amount), "transfer failed"); } /** * @notice swap tokens in one transaction if the sending token supports ERC677 * @param sender address that initially initiated the call to the source token * @param amount count of tokens sent for the swap * @param targetData address of target token encoded as a bytes array */ function onTokenTransfer( address sender, uint256 amount, bytes calldata targetData ) external { address source = msg.sender; address target = abi.decode(targetData, (address)); _removeLiquidity(amount, source, target); _addLiquidity(amount, target, source); emit TokensSwapped(amount, source, target, sender); require(ERC20(target).transfer(sender, amount), "transfer failed"); } /** * @notice returns the amount of tokens for a pair that are available to swap * @param source the token that is being given * @param target the token that is being taken * @return amount count of tokens available to swap */ function getSwappableAmount( address source, address target ) public view returns( uint256 amount ) { return s_swappableAmount[source][target]; } // PRIVATE function _addLiquidity( uint256 amount, address source, address target ) private { uint256 newAmount = getSwappableAmount(source, target).add(amount); s_swappableAmount[source][target] = newAmount; emit LiquidityUpdated(newAmount, source, target); } function _removeLiquidity( uint256 amount, address source, address target ) private { uint256 newAmount = getSwappableAmount(source, target).sub(amount); s_swappableAmount[source][target] = newAmount; emit LiquidityUpdated(newAmount, source, target); } function _hasLiquidity( address source, address target ) private returns ( bool hasLiquidity ) { if (getSwappableAmount(source, target) > 0) return true; if (getSwappableAmount(target, source) > 0) return true; return false; } }
Contract ABI
[{"type":"event","name":"LiquidityUpdated","inputs":[{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"source","internalType":"address","indexed":true},{"type":"address","name":"target","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferRequested","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"from","internalType":"address","indexed":true},{"type":"address","name":"to","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"StuckTokensRecovered","inputs":[{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"target","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"TokensSwapped","inputs":[{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"address","name":"source","internalType":"address","indexed":true},{"type":"address","name":"target","internalType":"address","indexed":true},{"type":"address","name":"caller","internalType":"address","indexed":true}],"anonymous":false},{"type":"fallback","stateMutability":"nonpayable"},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"acceptOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addLiquidity","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"source","internalType":"address"},{"type":"address","name":"target","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"amount","internalType":"uint256"}],"name":"getSwappableAmount","inputs":[{"type":"address","name":"source","internalType":"address"},{"type":"address","name":"target","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"onTokenTransfer","inputs":[{"type":"address","name":"sender","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"bytes","name":"targetData","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"recoverStuckTokens","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"target","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeLiquidity","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"source","internalType":"address"},{"type":"address","name":"target","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"swap","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"source","internalType":"address"},{"type":"address","name":"target","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"_to","internalType":"address"}]}]
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100935760003560e01c806379ba50971161006657806379ba5097146101695780638da5cb5b14610171578063a4c0ed3614610195578063f2fde38b1461021a578063f31abcc41461024057610093565b806316094ece146100955780632b7f0923146100d5578063442d77b0146101095780634910630a14610135575b005b6100c3600480360360408110156100ab57600080fd5b506001600160a01b0381358116916020013516610274565b60408051918252519081900360200190f35b610093600480360360608110156100eb57600080fd5b508035906001600160a01b03602082013581169160400135166102a1565b6100936004803603604081101561011f57600080fd5b50803590602001356001600160a01b03166104f7565b6100936004803603606081101561014b57600080fd5b508035906001600160a01b0360208201358116916040013516610650565b61009361079c565b61017961084b565b604080516001600160a01b039092168252519081900360200190f35b610093600480360360608110156101ab57600080fd5b6001600160a01b03823516916020810135918101906060810160408201356401000000008111156101db57600080fd5b8201836020820111156101ed57600080fd5b8035906020019184600183028401116401000000008311171561020f57600080fd5b50909250905061085a565b6100936004803603602081101561023057600080fd5b50356001600160a01b03166109bc565b6100936004803603606081101561025657600080fd5b508035906001600160a01b0360208201358116916040013516610a65565b6001600160a01b038083166000908152600360209081526040808320938516835292905220545b92915050565b6002805414156102f8576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b60028055610307838383610b8b565b610312838284610c10565b336001600160a01b0316816001600160a01b0316836001600160a01b03167fee68281800fd374dbd49d54fe359343466bfeac7fcd7971e268acf415097345b866040518082815260200191505060405180910390a4604080516323b872dd60e01b81523360048201523060248201526044810185905290516001600160a01b038416916323b872dd9160648083019260209291908290030181600087803b1580156103bc57600080fd5b505af11580156103d0573d6000803e3d6000fd5b505050506040513d60208110156103e657600080fd5b505161042f576040805162461bcd60e51b81526020600482015260136024820152721d1c985b9cd9995c919c9bdb4819985a5b1959606a1b604482015290519081900360640190fd5b6040805163a9059cbb60e01b81523360048201526024810185905290516001600160a01b0383169163a9059cbb9160448083019260209291908290030181600087803b15801561047e57600080fd5b505af1158015610492573d6000803e3d6000fd5b505050506040513d60208110156104a857600080fd5b50516104ed576040805162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b5050600160025550565b6000546001600160a01b0316331461054f576040805162461bcd60e51b815260206004820152601660248201527527b7363c9031b0b63630b1363290313c9037bbb732b960511b604482015290519081900360640190fd5b6040805183815290516001600160a01b038316917f9e491d87752491d550c542a9393e549a5fe64736584d59fdf01e9711e5e27f5a919081900360200190a26040805163a9059cbb60e01b81523360048201526024810184905290516001600160a01b0383169163a9059cbb9160448083019260209291908290030181600087803b1580156105dd57600080fd5b505af11580156105f1573d6000803e3d6000fd5b505050506040513d602081101561060757600080fd5b505161064c576040805162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b5050565b600080546001600160a01b031633148061066f575061066f8383610c2c565b9050806106c3576040805162461bcd60e51b815260206004820152601860248201527f6f6e6c79206f776e65722063616e206164642070616972730000000000000000604482015290519081900360640190fd5b6106ce848484610c10565b604080516323b872dd60e01b81523360048201523060248201526044810186905290516001600160a01b038416916323b872dd9160648083019260209291908290030181600087803b15801561072357600080fd5b505af1158015610737573d6000803e3d6000fd5b505050506040513d602081101561074d57600080fd5b5051610796576040805162461bcd60e51b81526020600482015260136024820152721d1c985b9cd9995c919c9bdb4819985a5b1959606a1b604482015290519081900360640190fd5b50505050565b6001546001600160a01b031633146107f4576040805162461bcd60e51b815260206004820152601660248201527526bab9ba10313290383937b837b9b2b21037bbb732b960511b604482015290519081900360640190fd5b60008054336001600160a01b0319808316821784556001805490911690556040516001600160a01b0390921692909183917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a350565b6000546001600160a01b031681565b3360008383602081101561086d57600080fd5b50356001600160a01b03169050610885858383610b8b565b610890858284610c10565b856001600160a01b0316816001600160a01b0316836001600160a01b03167fee68281800fd374dbd49d54fe359343466bfeac7fcd7971e268acf415097345b886040518082815260200191505060405180910390a4806001600160a01b031663a9059cbb87876040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561094557600080fd5b505af1158015610959573d6000803e3d6000fd5b505050506040513d602081101561096f57600080fd5b50516109b4576040805162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b505050505050565b6000546001600160a01b03163314610a14576040805162461bcd60e51b815260206004820152601660248201527527b7363c9031b0b63630b1363290313c9037bbb732b960511b604482015290519081900360640190fd5b600180546001600160a01b0319166001600160a01b0383811691821790925560008054604051929316917fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae12789190a350565b6000546001600160a01b03163314610abd576040805162461bcd60e51b815260206004820152601660248201527527b7363c9031b0b63630b1363290313c9037bbb732b960511b604482015290519081900360640190fd5b610ac8838383610b8b565b6040805163a9059cbb60e01b81523360048201526024810185905290516001600160a01b0383169163a9059cbb9160448083019260209291908290030181600087803b158015610b1757600080fd5b505af1158015610b2b573d6000803e3d6000fd5b505050506040513d6020811015610b4157600080fd5b5051610b86576040805162461bcd60e51b815260206004820152600f60248201526e1d1c985b9cd9995c8819985a5b1959608a1b604482015290519081900360640190fd5b505050565b6000610ba784610b9b8585610274565b9063ffffffff610c6a16565b6001600160a01b0380851660008181526003602090815260408083209488168084529482529182902085905581518581529151949550929391927f9832bb3eced80e5d53e74bd87d617aff406ef3afd433670cd9b3dcbf3ba99d8c92918290030190a350505050565b6000610ba784610c208585610274565b9063ffffffff610cc716565b600080610c398484610274565b1115610c475750600161029b565b6000610c538385610274565b1115610c615750600161029b565b50600092915050565b600082821115610cc1576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b600082820183811015610d21576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b939250505056fea2646970667358221220ffe553a4e0b4056093e60de734f736e4382e68f02936d0e121b913b4bae54d5464736f6c63430006060033