Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00Token Holdings
More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0x60a06040 | 11961280 | 1221 days ago | IN | Create: MooniswapLiquidityProvider | 0 ETH | 0.10563735 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | Value | ||
---|---|---|---|---|---|---|
19823464 | 58 days ago | 0.20243611 ETH | ||||
19823464 | 58 days ago | 0.20243611 ETH | ||||
19785780 | 64 days ago | 0.00681842 ETH | ||||
19785780 | 64 days ago | 0.00681842 ETH | ||||
19209225 | 145 days ago | 0.07215292 ETH | ||||
19209225 | 145 days ago | 0.07215292 ETH | ||||
19204975 | 145 days ago | 0.31117366 ETH | ||||
19204975 | 145 days ago | 0.31117366 ETH | ||||
19110488 | 158 days ago | 0.18947141 ETH | ||||
19110488 | 158 days ago | 0.18947141 ETH | ||||
19070599 | 164 days ago | 0.27768432 ETH | ||||
19070599 | 164 days ago | 0.27768432 ETH | ||||
18967210 | 179 days ago | 0.2086469 ETH | ||||
18967210 | 179 days ago | 0.2086469 ETH | ||||
18885065 | 190 days ago | 0.40273794 ETH | ||||
18885065 | 190 days ago | 0.40273794 ETH | ||||
18806241 | 201 days ago | 0.50635232 ETH | ||||
18806241 | 201 days ago | 0.50635232 ETH | ||||
18767267 | 207 days ago | 0.36676752 ETH | ||||
18767267 | 207 days ago | 0.36676752 ETH | ||||
18759172 | 208 days ago | 0.29556749 ETH | ||||
18759172 | 208 days ago | 0.29556749 ETH | ||||
18732506 | 211 days ago | 0.48984695 ETH | ||||
18732506 | 211 days ago | 0.48984695 ETH | ||||
18690494 | 217 days ago | 0.43233759 ETH |
Loading...
Loading
Contract Name:
MooniswapLiquidityProvider
Compiler Version
v0.6.12+commit.27d51765
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2021 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol"; import "../transformers/LibERC20Transformer.sol"; import "../vendor/ILiquidityProvider.sol"; import "../vendor/IMooniswapPool.sol"; contract MooniswapLiquidityProvider is ILiquidityProvider { using LibERC20TokenV06 for IERC20TokenV06; using LibSafeMathV06 for uint256; using LibRichErrorsV06 for bytes; IEtherTokenV06 private immutable WETH; constructor(IEtherTokenV06 weth) public { WETH = weth; } /// @dev This contract must be payable because takers can transfer funds /// in prior to calling the swap function. receive() external payable {} /// @dev Trades `inputToken` for `outputToken`. The amount of `inputToken` /// to sell must be transferred to the contract prior to calling this /// function to trigger the trade. /// @param inputToken The token being sold. /// @param outputToken The token being bought. /// @param recipient The recipient of the bought tokens. /// @param minBuyAmount The minimum acceptable amount of `outputToken` to buy. /// @param auxiliaryData Arbitrary auxiliary data supplied to the contract. /// @return boughtAmount The amount of `outputToken` bought. function sellTokenForToken( IERC20TokenV06 inputToken, IERC20TokenV06 outputToken, address recipient, uint256 minBuyAmount, bytes calldata auxiliaryData ) external override returns (uint256 boughtAmount) { require( !LibERC20Transformer.isTokenETH(inputToken) && !LibERC20Transformer.isTokenETH(outputToken) && inputToken != outputToken, "MooniswapLiquidityProvider/INVALID_ARGS" ); boughtAmount = _executeSwap( inputToken, outputToken, minBuyAmount, abi.decode(auxiliaryData, (IMooniswapPool)), recipient ); outputToken.compatTransfer(recipient, boughtAmount); } /// @dev Trades ETH for token. ETH must either be attached to this function /// call or sent to the contract prior to calling this function to /// trigger the trade. /// @param outputToken The token being bought. /// @param recipient The recipient of the bought tokens. /// @param minBuyAmount The minimum acceptable amount of `outputToken` to buy. /// @param auxiliaryData Arbitrary auxiliary data supplied to the contract. /// @return boughtAmount The amount of `outputToken` bought. function sellEthForToken( IERC20TokenV06 outputToken, address recipient, uint256 minBuyAmount, bytes calldata auxiliaryData ) external payable override returns (uint256 boughtAmount) { require( !LibERC20Transformer.isTokenETH(outputToken), "MooniswapLiquidityProvider/INVALID_ARGS" ); boughtAmount = _executeSwap( LibERC20Transformer.ETH_TOKEN, outputToken, minBuyAmount, abi.decode(auxiliaryData, (IMooniswapPool)), recipient ); outputToken.compatTransfer(recipient, boughtAmount); } /// @dev Trades token for ETH. The token must be sent to the contract prior /// to calling this function to trigger the trade. /// @param inputToken The token being sold. /// @param recipient The recipient of the bought tokens. /// @param minBuyAmount The minimum acceptable amount of ETH to buy. /// @param auxiliaryData Arbitrary auxiliary data supplied to the contract. /// @return boughtAmount The amount of ETH bought. function sellTokenForEth( IERC20TokenV06 inputToken, address payable recipient, uint256 minBuyAmount, bytes calldata auxiliaryData ) external override returns (uint256 boughtAmount) { require( !LibERC20Transformer.isTokenETH(inputToken), "MooniswapLiquidityProvider/INVALID_ARGS" ); boughtAmount = _executeSwap( inputToken, LibERC20Transformer.ETH_TOKEN, minBuyAmount, abi.decode(auxiliaryData, (IMooniswapPool)), recipient ); recipient.call{value: boughtAmount}(""); } /// @dev Quotes the amount of `outputToken` that would be obtained by /// selling `sellAmount` of `inputToken`. function getSellQuote( IERC20TokenV06 /* inputToken */, IERC20TokenV06 /* outputToken */, uint256 /* sellAmount */ ) external view override returns (uint256) { revert("MooniswapLiquidityProvider/NOT_IMPLEMENTED"); } /// @dev Perform the swap against the curve pool. Handles any combination of /// tokens function _executeSwap( IERC20TokenV06 inputToken, IERC20TokenV06 outputToken, uint256 minBuyAmount, IMooniswapPool pool, address recipient // Only used to log event ) private returns (uint256 boughtAmount) { uint256 sellAmount = LibERC20Transformer.getTokenBalanceOf(inputToken, address(this)); uint256 ethValue = 0; if (inputToken == WETH) { // Selling WETH. Unwrap to ETH. require(!_isTokenEthLike(outputToken), 'MooniswapLiquidityProvider/ETH_TO_ETH'); WETH.withdraw(sellAmount); ethValue = sellAmount; } else if (LibERC20Transformer.isTokenETH(inputToken)) { // Selling ETH directly. ethValue = sellAmount; require(!_isTokenEthLike(outputToken), 'MooniswapLiquidityProvider/ETH_TO_ETH'); } else { // Selling a regular ERC20. require(inputToken != outputToken, 'MooniswapLiquidityProvider/SAME_TOKEN'); inputToken.approveIfBelow(address(pool), sellAmount); } boughtAmount = pool.swap{value: ethValue}( _isTokenEthLike(inputToken) ? IERC20TokenV06(0) : inputToken, _isTokenEthLike(outputToken) ? IERC20TokenV06(0) : outputToken, sellAmount, minBuyAmount, address(0) ); if (outputToken == WETH) { WETH.deposit{value: boughtAmount}(); } emit LiquidityProviderFill( inputToken, outputToken, sellAmount, boughtAmount, bytes32("Mooniswap"), address(pool), msg.sender, recipient ); } /// @dev Check if a token is ETH or WETH. function _isTokenEthLike(IERC20TokenV06 token) private view returns (bool isEthOrWeth) { return LibERC20Transformer.isTokenETH(token) || token == WETH; } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; library LibRichErrorsV06 { // bytes4(keccak256("Error(string)")) bytes4 internal constant STANDARD_ERROR_SELECTOR = 0x08c379a0; // solhint-disable func-name-mixedcase /// @dev ABI encode a standard, string revert error payload. /// This is the same payload that would be included by a `revert(string)` /// solidity statement. It has the function signature `Error(string)`. /// @param message The error string. /// @return The ABI encoded error. function StandardError(string memory message) internal pure returns (bytes memory) { return abi.encodeWithSelector( STANDARD_ERROR_SELECTOR, bytes(message) ); } // solhint-enable func-name-mixedcase /// @dev Reverts an encoded rich revert reason `errorData`. /// @param errorData ABI encoded error data. function rrevert(bytes memory errorData) internal pure { assembly { revert(add(errorData, 0x20), mload(errorData)) } } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol"; import "@0x/contracts-utils/contracts/src/v06/LibBytesV06.sol"; import "./IERC20TokenV06.sol"; library LibERC20TokenV06 { bytes constant private DECIMALS_CALL_DATA = hex"313ce567"; /// @dev Calls `IERC20TokenV06(token).approve()`. /// Reverts if the result fails `isSuccessfulResult()` or the call reverts. /// @param token The address of the token contract. /// @param spender The address that receives an allowance. /// @param allowance The allowance to set. function compatApprove( IERC20TokenV06 token, address spender, uint256 allowance ) internal { bytes memory callData = abi.encodeWithSelector( token.approve.selector, spender, allowance ); _callWithOptionalBooleanResult(address(token), callData); } /// @dev Calls `IERC20TokenV06(token).approve()` and sets the allowance to the /// maximum if the current approval is not already >= an amount. /// Reverts if the result fails `isSuccessfulResult()` or the call reverts. /// @param token The address of the token contract. /// @param spender The address that receives an allowance. /// @param amount The minimum allowance needed. function approveIfBelow( IERC20TokenV06 token, address spender, uint256 amount ) internal { if (token.allowance(address(this), spender) < amount) { compatApprove(token, spender, uint256(-1)); } } /// @dev Calls `IERC20TokenV06(token).transfer()`. /// Reverts if the result fails `isSuccessfulResult()` or the call reverts. /// @param token The address of the token contract. /// @param to The address that receives the tokens /// @param amount Number of tokens to transfer. function compatTransfer( IERC20TokenV06 token, address to, uint256 amount ) internal { bytes memory callData = abi.encodeWithSelector( token.transfer.selector, to, amount ); _callWithOptionalBooleanResult(address(token), callData); } /// @dev Calls `IERC20TokenV06(token).transferFrom()`. /// Reverts if the result fails `isSuccessfulResult()` or the call reverts. /// @param token The address of the token contract. /// @param from The owner of the tokens. /// @param to The address that receives the tokens /// @param amount Number of tokens to transfer. function compatTransferFrom( IERC20TokenV06 token, address from, address to, uint256 amount ) internal { bytes memory callData = abi.encodeWithSelector( token.transferFrom.selector, from, to, amount ); _callWithOptionalBooleanResult(address(token), callData); } /// @dev Retrieves the number of decimals for a token. /// Returns `18` if the call reverts. /// @param token The address of the token contract. /// @return tokenDecimals The number of decimals places for the token. function compatDecimals(IERC20TokenV06 token) internal view returns (uint8 tokenDecimals) { tokenDecimals = 18; (bool didSucceed, bytes memory resultData) = address(token).staticcall(DECIMALS_CALL_DATA); if (didSucceed && resultData.length >= 32) { tokenDecimals = uint8(LibBytesV06.readUint256(resultData, 0)); } } /// @dev Retrieves the allowance for a token, owner, and spender. /// Returns `0` if the call reverts. /// @param token The address of the token contract. /// @param owner The owner of the tokens. /// @param spender The address the spender. /// @return allowance_ The allowance for a token, owner, and spender. function compatAllowance(IERC20TokenV06 token, address owner, address spender) internal view returns (uint256 allowance_) { (bool didSucceed, bytes memory resultData) = address(token).staticcall( abi.encodeWithSelector( token.allowance.selector, owner, spender ) ); if (didSucceed && resultData.length >= 32) { allowance_ = LibBytesV06.readUint256(resultData, 0); } } /// @dev Retrieves the balance for a token owner. /// Returns `0` if the call reverts. /// @param token The address of the token contract. /// @param owner The owner of the tokens. /// @return balance The token balance of an owner. function compatBalanceOf(IERC20TokenV06 token, address owner) internal view returns (uint256 balance) { (bool didSucceed, bytes memory resultData) = address(token).staticcall( abi.encodeWithSelector( token.balanceOf.selector, owner ) ); if (didSucceed && resultData.length >= 32) { balance = LibBytesV06.readUint256(resultData, 0); } } /// @dev Check if the data returned by a non-static call to an ERC20 token /// is a successful result. Supported functions are `transfer()`, /// `transferFrom()`, and `approve()`. /// @param resultData The raw data returned by a non-static call to the ERC20 token. /// @return isSuccessful Whether the result data indicates success. function isSuccessfulResult(bytes memory resultData) internal pure returns (bool isSuccessful) { if (resultData.length == 0) { return true; } if (resultData.length >= 32) { uint256 result = LibBytesV06.readUint256(resultData, 0); if (result == 1) { return true; } } } /// @dev Executes a call on address `target` with calldata `callData` /// and asserts that either nothing was returned or a single boolean /// was returned equal to `true`. /// @param target The call target. /// @param callData The abi-encoded call data. function _callWithOptionalBooleanResult( address target, bytes memory callData ) private { (bool didSucceed, bytes memory resultData) = target.call(callData); if (didSucceed && isSuccessfulResult(resultData)) { return; } LibRichErrorsV06.rrevert(resultData); } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; import "./errors/LibBytesRichErrorsV06.sol"; import "./errors/LibRichErrorsV06.sol"; library LibBytesV06 { using LibBytesV06 for bytes; /// @dev Gets the memory address for a byte array. /// @param input Byte array to lookup. /// @return memoryAddress Memory address of byte array. This /// points to the header of the byte array which contains /// the length. function rawAddress(bytes memory input) internal pure returns (uint256 memoryAddress) { assembly { memoryAddress := input } return memoryAddress; } /// @dev Gets the memory address for the contents of a byte array. /// @param input Byte array to lookup. /// @return memoryAddress Memory address of the contents of the byte array. function contentAddress(bytes memory input) internal pure returns (uint256 memoryAddress) { assembly { memoryAddress := add(input, 32) } return memoryAddress; } /// @dev Copies `length` bytes from memory location `source` to `dest`. /// @param dest memory address to copy bytes to. /// @param source memory address to copy bytes from. /// @param length number of bytes to copy. function memCopy( uint256 dest, uint256 source, uint256 length ) internal pure { if (length < 32) { // Handle a partial word by reading destination and masking // off the bits we are interested in. // This correctly handles overlap, zero lengths and source == dest assembly { let mask := sub(exp(256, sub(32, length)), 1) let s := and(mload(source), not(mask)) let d := and(mload(dest), mask) mstore(dest, or(s, d)) } } else { // Skip the O(length) loop when source == dest. if (source == dest) { return; } // For large copies we copy whole words at a time. The final // word is aligned to the end of the range (instead of after the // previous) to handle partial words. So a copy will look like this: // // #### // #### // #### // #### // // We handle overlap in the source and destination range by // changing the copying direction. This prevents us from // overwriting parts of source that we still need to copy. // // This correctly handles source == dest // if (source > dest) { assembly { // We subtract 32 from `sEnd` and `dEnd` because it // is easier to compare with in the loop, and these // are also the addresses we need for copying the // last bytes. length := sub(length, 32) let sEnd := add(source, length) let dEnd := add(dest, length) // Remember the last 32 bytes of source // This needs to be done here and not after the loop // because we may have overwritten the last bytes in // source already due to overlap. let last := mload(sEnd) // Copy whole words front to back // Note: the first check is always true, // this could have been a do-while loop. // solhint-disable-next-line no-empty-blocks for {} lt(source, sEnd) {} { mstore(dest, mload(source)) source := add(source, 32) dest := add(dest, 32) } // Write the last 32 bytes mstore(dEnd, last) } } else { assembly { // We subtract 32 from `sEnd` and `dEnd` because those // are the starting points when copying a word at the end. length := sub(length, 32) let sEnd := add(source, length) let dEnd := add(dest, length) // Remember the first 32 bytes of source // This needs to be done here and not after the loop // because we may have overwritten the first bytes in // source already due to overlap. let first := mload(source) // Copy whole words back to front // We use a signed comparisson here to allow dEnd to become // negative (happens when source and dest < 32). Valid // addresses in local memory will never be larger than // 2**255, so they can be safely re-interpreted as signed. // Note: the first check is always true, // this could have been a do-while loop. // solhint-disable-next-line no-empty-blocks for {} slt(dest, dEnd) {} { mstore(dEnd, mload(sEnd)) sEnd := sub(sEnd, 32) dEnd := sub(dEnd, 32) } // Write the first 32 bytes mstore(dest, first) } } } } /// @dev Returns a slices from a byte array. /// @param b The byte array to take a slice from. /// @param from The starting index for the slice (inclusive). /// @param to The final index for the slice (exclusive). /// @return result The slice containing bytes at indices [from, to) function slice( bytes memory b, uint256 from, uint256 to ) internal pure returns (bytes memory result) { // Ensure that the from and to positions are valid positions for a slice within // the byte array that is being used. if (from > to) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired, from, to )); } if (to > b.length) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired, to, b.length )); } // Create a new bytes structure and copy contents result = new bytes(to - from); memCopy( result.contentAddress(), b.contentAddress() + from, result.length ); return result; } /// @dev Returns a slice from a byte array without preserving the input. /// When `from == 0`, the original array will match the slice. /// In other cases its state will be corrupted. /// @param b The byte array to take a slice from. Will be destroyed in the process. /// @param from The starting index for the slice (inclusive). /// @param to The final index for the slice (exclusive). /// @return result The slice containing bytes at indices [from, to) function sliceDestructive( bytes memory b, uint256 from, uint256 to ) internal pure returns (bytes memory result) { // Ensure that the from and to positions are valid positions for a slice within // the byte array that is being used. if (from > to) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired, from, to )); } if (to > b.length) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired, to, b.length )); } // Create a new bytes structure around [from, to) in-place. assembly { result := add(b, from) mstore(result, sub(to, from)) } return result; } /// @dev Pops the last byte off of a byte array by modifying its length. /// @param b Byte array that will be modified. /// @return result The byte that was popped off. function popLastByte(bytes memory b) internal pure returns (bytes1 result) { if (b.length == 0) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired, b.length, 0 )); } // Store last byte. result = b[b.length - 1]; assembly { // Decrement length of byte array. let newLen := sub(mload(b), 1) mstore(b, newLen) } return result; } /// @dev Tests equality of two byte arrays. /// @param lhs First byte array to compare. /// @param rhs Second byte array to compare. /// @return equal True if arrays are the same. False otherwise. function equals( bytes memory lhs, bytes memory rhs ) internal pure returns (bool equal) { // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare. // We early exit on unequal lengths, but keccak would also correctly // handle this. return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs); } /// @dev Reads an address from a position in a byte array. /// @param b Byte array containing an address. /// @param index Index in byte array of address. /// @return result address from byte array. function readAddress( bytes memory b, uint256 index ) internal pure returns (address result) { if (b.length < index + 20) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, index + 20 // 20 is length of address )); } // Add offset to index: // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index) // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index) index += 20; // Read address from array memory assembly { // 1. Add index to address of bytes array // 2. Load 32-byte word from memory // 3. Apply 20-byte mask to obtain address result := and(mload(add(b, index)), 0xffffffffffffffffffffffffffffffffffffffff) } return result; } /// @dev Writes an address into a specific position in a byte array. /// @param b Byte array to insert address into. /// @param index Index in byte array of address. /// @param input Address to put into byte array. function writeAddress( bytes memory b, uint256 index, address input ) internal pure { if (b.length < index + 20) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired, b.length, index + 20 // 20 is length of address )); } // Add offset to index: // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index) // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index) index += 20; // Store address into array memory assembly { // The address occupies 20 bytes and mstore stores 32 bytes. // First fetch the 32-byte word where we'll be storing the address, then // apply a mask so we have only the bytes in the word that the address will not occupy. // Then combine these bytes with the address and store the 32 bytes back to memory with mstore. // 1. Add index to address of bytes array // 2. Load 32-byte word from memory // 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address let neighbors := and( mload(add(b, index)), 0xffffffffffffffffffffffff0000000000000000000000000000000000000000 ) // Make sure input address is clean. // (Solidity does not guarantee this) input := and(input, 0xffffffffffffffffffffffffffffffffffffffff) // Store the neighbors and address into memory mstore(add(b, index), xor(input, neighbors)) } } /// @dev Reads a bytes32 value from a position in a byte array. /// @param b Byte array containing a bytes32 value. /// @param index Index in byte array of bytes32 value. /// @return result bytes32 value from byte array. function readBytes32( bytes memory b, uint256 index ) internal pure returns (bytes32 result) { if (b.length < index + 32) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, b.length, index + 32 )); } // Arrays are prefixed by a 256 bit length parameter index += 32; // Read the bytes32 from array memory assembly { result := mload(add(b, index)) } return result; } /// @dev Writes a bytes32 into a specific position in a byte array. /// @param b Byte array to insert <input> into. /// @param index Index in byte array of <input>. /// @param input bytes32 to put into byte array. function writeBytes32( bytes memory b, uint256 index, bytes32 input ) internal pure { if (b.length < index + 32) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired, b.length, index + 32 )); } // Arrays are prefixed by a 256 bit length parameter index += 32; // Read the bytes32 from array memory assembly { mstore(add(b, index), input) } } /// @dev Reads a uint256 value from a position in a byte array. /// @param b Byte array containing a uint256 value. /// @param index Index in byte array of uint256 value. /// @return result uint256 value from byte array. function readUint256( bytes memory b, uint256 index ) internal pure returns (uint256 result) { result = uint256(readBytes32(b, index)); return result; } /// @dev Writes a uint256 into a specific position in a byte array. /// @param b Byte array to insert <input> into. /// @param index Index in byte array of <input>. /// @param input uint256 to put into byte array. function writeUint256( bytes memory b, uint256 index, uint256 input ) internal pure { writeBytes32(b, index, bytes32(input)); } /// @dev Reads an unpadded bytes4 value from a position in a byte array. /// @param b Byte array containing a bytes4 value. /// @param index Index in byte array of bytes4 value. /// @return result bytes4 value from byte array. function readBytes4( bytes memory b, uint256 index ) internal pure returns (bytes4 result) { if (b.length < index + 4) { LibRichErrorsV06.rrevert(LibBytesRichErrorsV06.InvalidByteOperationError( LibBytesRichErrorsV06.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired, b.length, index + 4 )); } // Arrays are prefixed by a 32 byte length field index += 32; // Read the bytes4 from array memory assembly { result := mload(add(b, index)) // Solidity does not require us to clean the trailing bytes. // We do it anyway result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000) } return result; } /// @dev Writes a new length to a byte array. /// Decreasing length will lead to removing the corresponding lower order bytes from the byte array. /// Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array. /// @param b Bytes array to write new length to. /// @param length New length of byte array. function writeLength(bytes memory b, uint256 length) internal pure { assembly { mstore(b, length) } } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; library LibBytesRichErrorsV06 { enum InvalidByteOperationErrorCodes { FromLessThanOrEqualsToRequired, ToLessThanOrEqualsLengthRequired, LengthGreaterThanZeroRequired, LengthGreaterThanOrEqualsFourRequired, LengthGreaterThanOrEqualsTwentyRequired, LengthGreaterThanOrEqualsThirtyTwoRequired, LengthGreaterThanOrEqualsNestedBytesLengthRequired, DestinationLengthGreaterThanOrEqualSourceLengthRequired } // bytes4(keccak256("InvalidByteOperationError(uint8,uint256,uint256)")) bytes4 internal constant INVALID_BYTE_OPERATION_ERROR_SELECTOR = 0x28006595; // solhint-disable func-name-mixedcase function InvalidByteOperationError( InvalidByteOperationErrorCodes errorCode, uint256 offset, uint256 required ) internal pure returns (bytes memory) { return abi.encodeWithSelector( INVALID_BYTE_OPERATION_ERROR_SELECTOR, errorCode, offset, required ); } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; interface IERC20TokenV06 { // solhint-disable no-simple-event-func-name event Transfer( address indexed from, address indexed to, uint256 value ); event Approval( address indexed owner, address indexed spender, uint256 value ); /// @dev send `value` token to `to` from `msg.sender` /// @param to The address of the recipient /// @param value The amount of token to be transferred /// @return True if transfer was successful function transfer(address to, uint256 value) external returns (bool); /// @dev send `value` token to `to` from `from` on the condition it is approved by `from` /// @param from The address of the sender /// @param to The address of the recipient /// @param value The amount of token to be transferred /// @return True if transfer was successful function transferFrom( address from, address to, uint256 value ) external returns (bool); /// @dev `msg.sender` approves `spender` to spend `value` tokens /// @param spender The address of the account able to transfer the tokens /// @param value The amount of wei to be approved for transfer /// @return Always true if the call has enough gas to complete execution function approve(address spender, uint256 value) external returns (bool); /// @dev Query total supply of token /// @return Total supply of token function totalSupply() external view returns (uint256); /// @dev Get the balance of `owner`. /// @param owner The address from which the balance will be retrieved /// @return Balance of owner function balanceOf(address owner) external view returns (uint256); /// @dev Get the allowance for `spender` to spend from `owner`. /// @param owner The address of the account owning tokens /// @param spender The address of the account able to transfer the tokens /// @return Amount of remaining tokens allowed to spent function allowance(address owner, address spender) external view returns (uint256); /// @dev Get the number of decimals this token has. function decimals() external view returns (uint8); }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; import "./IERC20TokenV06.sol"; interface IEtherTokenV06 is IERC20TokenV06 { /// @dev Wrap ether. function deposit() external payable; /// @dev Unwrap ether. function withdraw(uint256 amount) external; }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; import "./errors/LibRichErrorsV06.sol"; import "./errors/LibSafeMathRichErrorsV06.sol"; library LibSafeMathV06 { function safeMul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) { return 0; } uint256 c = a * b; if (c / a != b) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.MULTIPLICATION_OVERFLOW, a, b )); } return c; } function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.DIVISION_BY_ZERO, a, b )); } uint256 c = a / b; return c; } function safeSub(uint256 a, uint256 b) internal pure returns (uint256) { if (b > a) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.SUBTRACTION_UNDERFLOW, a, b )); } return a - b; } function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; if (c < a) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.ADDITION_OVERFLOW, a, b )); } return c; } function max256(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } function min256(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } function safeMul128(uint128 a, uint128 b) internal pure returns (uint128) { if (a == 0) { return 0; } uint128 c = a * b; if (c / a != b) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.MULTIPLICATION_OVERFLOW, a, b )); } return c; } function safeDiv128(uint128 a, uint128 b) internal pure returns (uint128) { if (b == 0) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.DIVISION_BY_ZERO, a, b )); } uint128 c = a / b; return c; } function safeSub128(uint128 a, uint128 b) internal pure returns (uint128) { if (b > a) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.SUBTRACTION_UNDERFLOW, a, b )); } return a - b; } function safeAdd128(uint128 a, uint128 b) internal pure returns (uint128) { uint128 c = a + b; if (c < a) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256BinOpError( LibSafeMathRichErrorsV06.BinOpErrorCodes.ADDITION_OVERFLOW, a, b )); } return c; } function max128(uint128 a, uint128 b) internal pure returns (uint128) { return a >= b ? a : b; } function min128(uint128 a, uint128 b) internal pure returns (uint128) { return a < b ? a : b; } function safeDowncastToUint128(uint256 a) internal pure returns (uint128) { if (a > type(uint128).max) { LibRichErrorsV06.rrevert(LibSafeMathRichErrorsV06.Uint256DowncastError( LibSafeMathRichErrorsV06.DowncastErrorCodes.VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT128, a )); } return uint128(a); } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; library LibSafeMathRichErrorsV06 { // bytes4(keccak256("Uint256BinOpError(uint8,uint256,uint256)")) bytes4 internal constant UINT256_BINOP_ERROR_SELECTOR = 0xe946c1bb; // bytes4(keccak256("Uint256DowncastError(uint8,uint256)")) bytes4 internal constant UINT256_DOWNCAST_ERROR_SELECTOR = 0xc996af7b; enum BinOpErrorCodes { ADDITION_OVERFLOW, MULTIPLICATION_OVERFLOW, SUBTRACTION_UNDERFLOW, DIVISION_BY_ZERO } enum DowncastErrorCodes { VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT32, VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT64, VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT96, VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT128 } // solhint-disable func-name-mixedcase function Uint256BinOpError( BinOpErrorCodes errorCode, uint256 a, uint256 b ) internal pure returns (bytes memory) { return abi.encodeWithSelector( UINT256_BINOP_ERROR_SELECTOR, errorCode, a, b ); } function Uint256DowncastError( DowncastErrorCodes errorCode, uint256 a ) internal pure returns (bytes memory) { return abi.encodeWithSelector( UINT256_DOWNCAST_ERROR_SELECTOR, errorCode, a ); } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol"; library LibERC20Transformer { using LibERC20TokenV06 for IERC20TokenV06; /// @dev ETH pseudo-token address. address constant internal ETH_TOKEN_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; /// @dev ETH pseudo-token. IERC20TokenV06 constant internal ETH_TOKEN = IERC20TokenV06(ETH_TOKEN_ADDRESS); /// @dev Return value indicating success in `IERC20Transformer.transform()`. /// This is just `keccak256('TRANSFORMER_SUCCESS')`. bytes4 constant internal TRANSFORMER_SUCCESS = 0x13c9929e; /// @dev Transfer ERC20 tokens and ETH. /// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`). /// @param to The recipient. /// @param amount The transfer amount. function transformerTransfer( IERC20TokenV06 token, address payable to, uint256 amount ) internal { if (isTokenETH(token)) { to.transfer(amount); } else { token.compatTransfer(to, amount); } } /// @dev Check if a token is the ETH pseudo-token. /// @param token The token to check. /// @return isETH `true` if the token is the ETH pseudo-token. function isTokenETH(IERC20TokenV06 token) internal pure returns (bool isETH) { return address(token) == ETH_TOKEN_ADDRESS; } /// @dev Check the balance of an ERC20 token or ETH. /// @param token An ERC20 or the ETH pseudo-token address (`ETH_TOKEN_ADDRESS`). /// @param owner Holder of the tokens. /// @return tokenBalance The balance of `owner`. function getTokenBalanceOf(IERC20TokenV06 token, address owner) internal view returns (uint256 tokenBalance) { if (isTokenETH(token)) { return owner.balance; } return token.balanceOf(owner); } /// @dev RLP-encode a 32-bit or less account nonce. /// @param nonce A positive integer in the range 0 <= nonce < 2^32. /// @return rlpNonce The RLP encoding. function rlpEncodeNonce(uint32 nonce) internal pure returns (bytes memory rlpNonce) { // See https://github.com/ethereum/wiki/wiki/RLP for RLP encoding rules. if (nonce == 0) { rlpNonce = new bytes(1); rlpNonce[0] = 0x80; } else if (nonce < 0x80) { rlpNonce = new bytes(1); rlpNonce[0] = byte(uint8(nonce)); } else if (nonce <= 0xFF) { rlpNonce = new bytes(2); rlpNonce[0] = 0x81; rlpNonce[1] = byte(uint8(nonce)); } else if (nonce <= 0xFFFF) { rlpNonce = new bytes(3); rlpNonce[0] = 0x82; rlpNonce[1] = byte(uint8((nonce & 0xFF00) >> 8)); rlpNonce[2] = byte(uint8(nonce)); } else if (nonce <= 0xFFFFFF) { rlpNonce = new bytes(4); rlpNonce[0] = 0x83; rlpNonce[1] = byte(uint8((nonce & 0xFF0000) >> 16)); rlpNonce[2] = byte(uint8((nonce & 0xFF00) >> 8)); rlpNonce[3] = byte(uint8(nonce)); } else { rlpNonce = new bytes(5); rlpNonce[0] = 0x84; rlpNonce[1] = byte(uint8((nonce & 0xFF000000) >> 24)); rlpNonce[2] = byte(uint8((nonce & 0xFF0000) >> 16)); rlpNonce[3] = byte(uint8((nonce & 0xFF00) >> 8)); rlpNonce[4] = byte(uint8(nonce)); } } /// @dev Compute the expected deployment address by `deployer` at /// the nonce given by `deploymentNonce`. /// @param deployer The address of the deployer. /// @param deploymentNonce The nonce that the deployer had when deploying /// a contract. /// @return deploymentAddress The deployment address. function getDeployedAddress(address deployer, uint32 deploymentNonce) internal pure returns (address payable deploymentAddress) { // The address of if a deployed contract is the lower 20 bytes of the // hash of the RLP-encoded deployer's account address + account nonce. // See: https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed bytes memory rlpNonce = rlpEncodeNonce(deploymentNonce); return address(uint160(uint256(keccak256(abi.encodePacked( byte(uint8(0xC0 + 21 + rlpNonce.length)), byte(uint8(0x80 + 20)), deployer, rlpNonce ))))); } }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2020 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; interface ILiquidityProvider { /// @dev An optional event an LP can emit for each fill against a source. /// @param inputToken The input token. /// @param outputToken The output token. /// @param inputTokenAmount How much input token was sold. /// @param outputTokenAmount How much output token was bought. /// @param sourceId A bytes32 encoded ascii source ID. E.g., `bytes32('Curve')`/ /// @param sourceAddress An optional address associated with the source (e.g, a curve pool). /// @param sourceId A bytes32 encoded ascii source ID. E.g., `bytes32('Curve')`/ /// @param sourceAddress An optional address associated with the source (e.g, a curve pool). /// @param sender The caller of the LP. /// @param recipient The recipient of the output tokens. event LiquidityProviderFill( IERC20TokenV06 inputToken, IERC20TokenV06 outputToken, uint256 inputTokenAmount, uint256 outputTokenAmount, bytes32 sourceId, address sourceAddress, address sender, address recipient ); /// @dev Trades `inputToken` for `outputToken`. The amount of `inputToken` /// to sell must be transferred to the contract prior to calling this /// function to trigger the trade. /// @param inputToken The token being sold. /// @param outputToken The token being bought. /// @param recipient The recipient of the bought tokens. /// @param minBuyAmount The minimum acceptable amount of `outputToken` to buy. /// @param auxiliaryData Arbitrary auxiliary data supplied to the contract. /// @return boughtAmount The amount of `outputToken` bought. function sellTokenForToken( IERC20TokenV06 inputToken, IERC20TokenV06 outputToken, address recipient, uint256 minBuyAmount, bytes calldata auxiliaryData ) external returns (uint256 boughtAmount); /// @dev Trades ETH for token. ETH must either be attached to this function /// call or sent to the contract prior to calling this function to /// trigger the trade. /// @param outputToken The token being bought. /// @param recipient The recipient of the bought tokens. /// @param minBuyAmount The minimum acceptable amount of `outputToken` to buy. /// @param auxiliaryData Arbitrary auxiliary data supplied to the contract. /// @return boughtAmount The amount of `outputToken` bought. function sellEthForToken( IERC20TokenV06 outputToken, address recipient, uint256 minBuyAmount, bytes calldata auxiliaryData ) external payable returns (uint256 boughtAmount); /// @dev Trades token for ETH. The token must be sent to the contract prior /// to calling this function to trigger the trade. /// @param inputToken The token being sold. /// @param recipient The recipient of the bought tokens. /// @param minBuyAmount The minimum acceptable amount of ETH to buy. /// @param auxiliaryData Arbitrary auxiliary data supplied to the contract. /// @return boughtAmount The amount of ETH bought. function sellTokenForEth( IERC20TokenV06 inputToken, address payable recipient, uint256 minBuyAmount, bytes calldata auxiliaryData ) external returns (uint256 boughtAmount); /// @dev Quotes the amount of `outputToken` that would be obtained by /// selling `sellAmount` of `inputToken`. /// @param inputToken Address of the taker token (what to sell). Use /// the wETH address if selling ETH. /// @param outputToken Address of the maker token (what to buy). Use /// the wETH address if buying ETH. /// @param sellAmount Amount of `inputToken` to sell. /// @return outputTokenAmount Amount of `outputToken` that would be obtained. function getSellQuote( IERC20TokenV06 inputToken, IERC20TokenV06 outputToken, uint256 sellAmount ) external view returns (uint256 outputTokenAmount); }
// SPDX-License-Identifier: Apache-2.0 /* Copyright 2021 ZeroEx Intl. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity ^0.6.5; pragma experimental ABIEncoderV2; import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol"; /// @dev Moooniswap pool interface. interface IMooniswapPool { function swap( IERC20TokenV06 sellToken, IERC20TokenV06 buyToken, uint256 sellAmount, uint256 minBoughtAmount, address referrer ) external payable returns (uint256 boughtAmount); }
{ "remappings": [ "@0x/contracts-utils=/home/cluracan/code/0x-protocol/node_modules/@0x/contracts-utils", "@0x/contracts-erc20=/home/cluracan/code/0x-protocol/contracts/zero-ex/node_modules/@0x/contracts-erc20" ], "optimizer": { "enabled": true, "runs": 1000000, "details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true } }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } }, "evmVersion": "istanbul" }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IEtherTokenV06","name":"weth","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IERC20TokenV06","name":"inputToken","type":"address"},{"indexed":false,"internalType":"contract IERC20TokenV06","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputTokenAmount","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"sourceId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"sourceAddress","type":"address"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"LiquidityProviderFill","type":"event"},{"inputs":[{"internalType":"contract IERC20TokenV06","name":"","type":"address"},{"internalType":"contract IERC20TokenV06","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"getSellQuote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20TokenV06","name":"outputToken","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"minBuyAmount","type":"uint256"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"sellEthForToken","outputs":[{"internalType":"uint256","name":"boughtAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20TokenV06","name":"inputToken","type":"address"},{"internalType":"address payable","name":"recipient","type":"address"},{"internalType":"uint256","name":"minBuyAmount","type":"uint256"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"sellTokenForEth","outputs":[{"internalType":"uint256","name":"boughtAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20TokenV06","name":"inputToken","type":"address"},{"internalType":"contract IERC20TokenV06","name":"outputToken","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"minBuyAmount","type":"uint256"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"sellTokenForToken","outputs":[{"internalType":"uint256","name":"boughtAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60a060405234801561001057600080fd5b506040516111f43803806111f483398101604081905261002f91610044565b60601b6001600160601b031916608052610072565b600060208284031215610055578081fd5b81516001600160a01b038116811461006b578182fd5b9392505050565b60805160601c6111516100a36000398061039c528061046b528061067952806106cd528061095552506111516000f3fe6080604052600436106100435760003560e01c8063343fbcdd1461004f57806365d02b041461008557806369be90ec146100a5578063b52e8458146100c55761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b5061006f61006a366004610d9e565b6100d8565b60405161007c91906110ed565b60405180910390f35b34801561009157600080fd5b5061006f6100a0366004610d1b565b610115565b3480156100b157600080fd5b5061006f6100c0366004610caa565b6101e6565b61006f6100d3366004610caa565b6102c2565b60006040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610fd6565b60405180910390fd5b600061012087610356565b158015610133575061013186610356565b155b801561016b57508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614155b6101a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610f79565b6101b98787866101b386880188610dde565b89610389565b90506101dc73ffffffffffffffffffffffffffffffffffffffff871686836107bd565b9695505050505050565b60006101f186610356565b15610228576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610f79565b61024e8673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee866101b386880188610dde565b90508473ffffffffffffffffffffffffffffffffffffffff168160405161027490610e52565b60006040518083038185875af1925050503d80600081146102b1576040519150601f19603f3d011682016040523d82523d6000602084013e6102b6565b606091505b50505095945050505050565b60006102cd86610356565b15610304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610f79565b61032a73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee87866101b386880188610dde565b905061034d73ffffffffffffffffffffffffffffffffffffffff871686836107bd565b95945050505050565b73ffffffffffffffffffffffffffffffffffffffff811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b919050565b6000806103968730610869565b905060007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1614156104da576103f787610942565b1561042e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90611033565b6040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001690632e1a7d4d906104a09085906004016110ed565b600060405180830381600087803b1580156104ba57600080fd5b505af11580156104ce573d6000803e3d6000fd5b505050508190506105b6565b6104e388610356565b1561052f5750806104f387610942565b1561052a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90611033565b6105b6565b8673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff161415610595576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90611090565b6105b673ffffffffffffffffffffffffffffffffffffffff891686846109a8565b8473ffffffffffffffffffffffffffffffffffffffff1663d5bcb9b5826105dc8b610942565b6105e6578a6105e9565b60005b6105f28b610942565b6105fc578a6105ff565b60005b868b60006040518763ffffffff1660e01b8152600401610623959493929190610ec3565b6020604051808303818588803b15801561063c57600080fd5b505af1158015610650573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906106759190610e01565b92507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff16141561074d577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0846040518263ffffffff1660e01b81526004016000604051808303818588803b15801561073357600080fd5b505af1158015610747573d6000803e3d6000fd5b50505050505b7f83dc79d57dbf7f65897db5b817ef3c45ebb363086f52ba01bb57d0cdef08dace888884867f4d6f6f6e697377617000000000000000000000000000000000000000000000008a338b6040516107aa989796959493929190610f00565b60405180910390a1505095945050505050565b606063a9059cbb60e01b83836040516024016107da929190610e9d565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290506108638482610a84565b50505050565b600061087483610356565b15610897575073ffffffffffffffffffffffffffffffffffffffff81163161093c565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416906370a08231906108e9908590600401610e55565b60206040518083038186803b15801561090157600080fd5b505afa158015610915573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109399190610e01565b90505b92915050565b600061094d82610356565b8061093c57507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161492915050565b6040517fdd62ed3e000000000000000000000000000000000000000000000000000000008152819073ffffffffffffffffffffffffffffffffffffffff85169063dd62ed3e906109fe9030908790600401610e76565b60206040518083038186803b158015610a1657600080fd5b505afa158015610a2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4e9190610e01565b1015610a7f57610a7f83837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610b1e565b505050565b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051610aad9190610e19565b6000604051808303816000865af19150503d8060008114610aea576040519150601f19603f3d011682016040523d82523d6000602084013e610aef565b606091505b5091509150818015610b055750610b0581610b3b565b15610b11575050610b1a565b61086381610b80565b5050565b606063095ea7b360e01b83836040516024016107da929190610e9d565b6000815160001415610b4f57506001610384565b6020825110610384576000610b65836000610b88565b90508060011415610b7a576001915050610384565b50919050565b805160208201fd5b6000610939838360008160200183511015610bb557610bb5610bb06005855185602001610bbe565b610b80565b50016020015190565b6060632800659560e01b848484604051602401610bdd93929190610f57565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b60008083601f840112610c74578182fd5b50813567ffffffffffffffff811115610c8b578182fd5b602083019150836020828501011115610ca357600080fd5b9250929050565b600080600080600060808688031215610cc1578081fd5b8535610ccc816110f6565b94506020860135610cdc816110f6565b935060408601359250606086013567ffffffffffffffff811115610cfe578182fd5b610d0a88828901610c63565b969995985093965092949392505050565b60008060008060008060a08789031215610d33578081fd5b8635610d3e816110f6565b95506020870135610d4e816110f6565b94506040870135610d5e816110f6565b935060608701359250608087013567ffffffffffffffff811115610d80578182fd5b610d8c89828a01610c63565b979a9699509497509295939492505050565b600080600060608486031215610db2578283fd5b8335610dbd816110f6565b92506020840135610dcd816110f6565b929592945050506040919091013590565b600060208284031215610def578081fd5b8135610dfa816110f6565b9392505050565b600060208284031215610e12578081fd5b5051919050565b60008251815b81811015610e395760208186018101518583015201610e1f565b81811115610e475782828501525b509190910192915050565b90565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9586168152938516602085015260408401929092526060830152909116608082015260a00190565b73ffffffffffffffffffffffffffffffffffffffff98891681529688166020880152604087019590955260608601939093526080850191909152841660a0840152831660c083015290911660e08201526101000190565b6060810160088510610f6557fe5b938152602081019290925260409091015290565b60208082526027908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f494e56414c60408201527f49445f4152475300000000000000000000000000000000000000000000000000606082015260800190565b6020808252602a908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f4e4f545f4960408201527f4d504c454d454e54454400000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f4554485f5460408201527f4f5f455448000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f53414d455f60408201527f544f4b454e000000000000000000000000000000000000000000000000000000606082015260800190565b90815260200190565b73ffffffffffffffffffffffffffffffffffffffff8116811461111857600080fd5b5056fea26469706673582212208dfd66b95ca8a19de3bcbee62aa830be1bc55c634e5d014cda5cd066ec676c0464736f6c634300060c0033000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Deployed Bytecode
0x6080604052600436106100435760003560e01c8063343fbcdd1461004f57806365d02b041461008557806369be90ec146100a5578063b52e8458146100c55761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b5061006f61006a366004610d9e565b6100d8565b60405161007c91906110ed565b60405180910390f35b34801561009157600080fd5b5061006f6100a0366004610d1b565b610115565b3480156100b157600080fd5b5061006f6100c0366004610caa565b6101e6565b61006f6100d3366004610caa565b6102c2565b60006040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610fd6565b60405180910390fd5b600061012087610356565b158015610133575061013186610356565b155b801561016b57508573ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614155b6101a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610f79565b6101b98787866101b386880188610dde565b89610389565b90506101dc73ffffffffffffffffffffffffffffffffffffffff871686836107bd565b9695505050505050565b60006101f186610356565b15610228576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610f79565b61024e8673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee866101b386880188610dde565b90508473ffffffffffffffffffffffffffffffffffffffff168160405161027490610e52565b60006040518083038185875af1925050503d80600081146102b1576040519150601f19603f3d011682016040523d82523d6000602084013e6102b6565b606091505b50505095945050505050565b60006102cd86610356565b15610304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90610f79565b61032a73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee87866101b386880188610dde565b905061034d73ffffffffffffffffffffffffffffffffffffffff871686836107bd565b95945050505050565b73ffffffffffffffffffffffffffffffffffffffff811673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee145b919050565b6000806103968730610869565b905060007f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff1614156104da576103f787610942565b1561042e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90611033565b6040517f2e1a7d4d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21690632e1a7d4d906104a09085906004016110ed565b600060405180830381600087803b1580156104ba57600080fd5b505af11580156104ce573d6000803e3d6000fd5b505050508190506105b6565b6104e388610356565b1561052f5750806104f387610942565b1561052a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90611033565b6105b6565b8673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff161415610595576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161010c90611090565b6105b673ffffffffffffffffffffffffffffffffffffffff891686846109a8565b8473ffffffffffffffffffffffffffffffffffffffff1663d5bcb9b5826105dc8b610942565b6105e6578a6105e9565b60005b6105f28b610942565b6105fc578a6105ff565b60005b868b60006040518763ffffffff1660e01b8152600401610623959493929190610ec3565b6020604051808303818588803b15801561063c57600080fd5b505af1158015610650573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906106759190610e01565b92507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff16141561074d577f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff1663d0e30db0846040518263ffffffff1660e01b81526004016000604051808303818588803b15801561073357600080fd5b505af1158015610747573d6000803e3d6000fd5b50505050505b7f83dc79d57dbf7f65897db5b817ef3c45ebb363086f52ba01bb57d0cdef08dace888884867f4d6f6f6e697377617000000000000000000000000000000000000000000000008a338b6040516107aa989796959493929190610f00565b60405180910390a1505095945050505050565b606063a9059cbb60e01b83836040516024016107da929190610e9d565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290506108638482610a84565b50505050565b600061087483610356565b15610897575073ffffffffffffffffffffffffffffffffffffffff81163161093c565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416906370a08231906108e9908590600401610e55565b60206040518083038186803b15801561090157600080fd5b505afa158015610915573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109399190610e01565b90505b92915050565b600061094d82610356565b8061093c57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161492915050565b6040517fdd62ed3e000000000000000000000000000000000000000000000000000000008152819073ffffffffffffffffffffffffffffffffffffffff85169063dd62ed3e906109fe9030908790600401610e76565b60206040518083038186803b158015610a1657600080fd5b505afa158015610a2a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a4e9190610e01565b1015610a7f57610a7f83837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610b1e565b505050565b600060608373ffffffffffffffffffffffffffffffffffffffff1683604051610aad9190610e19565b6000604051808303816000865af19150503d8060008114610aea576040519150601f19603f3d011682016040523d82523d6000602084013e610aef565b606091505b5091509150818015610b055750610b0581610b3b565b15610b11575050610b1a565b61086381610b80565b5050565b606063095ea7b360e01b83836040516024016107da929190610e9d565b6000815160001415610b4f57506001610384565b6020825110610384576000610b65836000610b88565b90508060011415610b7a576001915050610384565b50919050565b805160208201fd5b6000610939838360008160200183511015610bb557610bb5610bb06005855185602001610bbe565b610b80565b50016020015190565b6060632800659560e01b848484604051602401610bdd93929190610f57565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b60008083601f840112610c74578182fd5b50813567ffffffffffffffff811115610c8b578182fd5b602083019150836020828501011115610ca357600080fd5b9250929050565b600080600080600060808688031215610cc1578081fd5b8535610ccc816110f6565b94506020860135610cdc816110f6565b935060408601359250606086013567ffffffffffffffff811115610cfe578182fd5b610d0a88828901610c63565b969995985093965092949392505050565b60008060008060008060a08789031215610d33578081fd5b8635610d3e816110f6565b95506020870135610d4e816110f6565b94506040870135610d5e816110f6565b935060608701359250608087013567ffffffffffffffff811115610d80578182fd5b610d8c89828a01610c63565b979a9699509497509295939492505050565b600080600060608486031215610db2578283fd5b8335610dbd816110f6565b92506020840135610dcd816110f6565b929592945050506040919091013590565b600060208284031215610def578081fd5b8135610dfa816110f6565b9392505050565b600060208284031215610e12578081fd5b5051919050565b60008251815b81811015610e395760208186018101518583015201610e1f565b81811115610e475782828501525b509190910192915050565b90565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9586168152938516602085015260408401929092526060830152909116608082015260a00190565b73ffffffffffffffffffffffffffffffffffffffff98891681529688166020880152604087019590955260608601939093526080850191909152841660a0840152831660c083015290911660e08201526101000190565b6060810160088510610f6557fe5b938152602081019290925260409091015290565b60208082526027908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f494e56414c60408201527f49445f4152475300000000000000000000000000000000000000000000000000606082015260800190565b6020808252602a908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f4e4f545f4960408201527f4d504c454d454e54454400000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f4554485f5460408201527f4f5f455448000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526025908201527f4d6f6f6e69737761704c697175696469747950726f76696465722f53414d455f60408201527f544f4b454e000000000000000000000000000000000000000000000000000000606082015260800190565b90815260200190565b73ffffffffffffffffffffffffffffffffffffffff8116811461111857600080fd5b5056fea26469706673582212208dfd66b95ca8a19de3bcbee62aa830be1bc55c634e5d014cda5cd066ec676c0464736f6c634300060c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
-----Decoded View---------------
Arg [0] : weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.