UNPKG

niftyswap

Version:

AMM exchange for ERC-1155 tokens, inspired by Uniswap

730 lines (729 loc) 29.7 kB
{ "id": "e074d454c594d476d3084665c597de82", "_format": "hh-sol-build-info-1", "solcVersion": "0.7.4", "solcLongVersion": "0.7.4+commit.3f05b770", "input": { "language": "Solidity", "sources": { "contracts/interfaces/IWrapAndNiftyswap.sol": { "content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.7.4;\n\ninterface IWrapAndNiftyswap {\n\n /**\n * @notice Wrap ERC-20 to ERC-1155 and swap them\n * @dev User must approve this contract for ERC-20 first\n * @param _maxAmount Maximum amount of ERC-20 user wants to spend\n * @param _recipient Address where to send tokens\n * @param _niftyswapOrder Encoded Niftyswap order passed in data field of safeTransferFrom()\n */\n function wrapAndSwap(uint256 _maxAmount, address _recipient, bytes calldata _niftyswapOrder) external;\n\n /**\n * @notice Accepts only tokenWrapper tokens\n * @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n */\n function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _amount, bytes calldata _data) external returns(bytes4);\n\n /**\n * @notice If receives tracked ERC-1155, it will send a sell order to niftyswap and unwrap received\n * wrapped token. The unwrapped tokens will be sent to the sender.\n * @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n */\n function onERC1155BatchReceived(address, address _from, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external returns(bytes4);\n}" } }, "settings": { "optimizer": { "enabled": true, "runs": 100000, "details": { "yul": true } }, "outputSelection": { "*": { "*": [ "abi", "evm.bytecode", "evm.deployedBytecode", "evm.methodIdentifiers" ], "": [ "ast" ] } } } }, "output": { "contracts": { "contracts/interfaces/IWrapAndNiftyswap.sol": { "IWrapAndNiftyswap": { "abi": [ { "inputs": [ { "internalType": "address", "name": "", "type": "address" }, { "internalType": "address", "name": "_from", "type": "address" }, { "internalType": "uint256[]", "name": "_ids", "type": "uint256[]" }, { "internalType": "uint256[]", "name": "_amounts", "type": "uint256[]" }, { "internalType": "bytes", "name": "_data", "type": "bytes" } ], "name": "onERC1155BatchReceived", "outputs": [ { "internalType": "bytes4", "name": "", "type": "bytes4" } ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_operator", "type": "address" }, { "internalType": "address", "name": "_from", "type": "address" }, { "internalType": "uint256", "name": "_id", "type": "uint256" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }, { "internalType": "bytes", "name": "_data", "type": "bytes" } ], "name": "onERC1155Received", "outputs": [ { "internalType": "bytes4", "name": "", "type": "bytes4" } ], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "uint256", "name": "_maxAmount", "type": "uint256" }, { "internalType": "address", "name": "_recipient", "type": "address" }, { "internalType": "bytes", "name": "_niftyswapOrder", "type": "bytes" } ], "name": "wrapAndSwap", "outputs": [], "stateMutability": "nonpayable", "type": "function" } ], "evm": { "bytecode": { "generatedSources": [], "linkReferences": {}, "object": "", "opcodes": "", "sourceMap": "" }, "deployedBytecode": { "generatedSources": [], "immutableReferences": {}, "linkReferences": {}, "object": "", "opcodes": "", "sourceMap": "" }, "methodIdentifiers": { "onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)": "bc197c81", "onERC1155Received(address,address,uint256,uint256,bytes)": "f23a6e61", "wrapAndSwap(uint256,address,bytes)": "a874d5b6" } } } } }, "sources": { "contracts/interfaces/IWrapAndNiftyswap.sol": { "ast": { "absolutePath": "contracts/interfaces/IWrapAndNiftyswap.sol", "exportedSymbols": { "IWrapAndNiftyswap": [ 46 ] }, "id": 47, "license": "Apache-2.0", "nodeType": "SourceUnit", "nodes": [ { "id": 1, "literals": [ "solidity", "0.7", ".4" ], "nodeType": "PragmaDirective", "src": "39:22:0" }, { "abstract": false, "baseContracts": [], "contractDependencies": [], "contractKind": "interface", "fullyImplemented": false, "id": 46, "linearizedBaseContracts": [ 46 ], "name": "IWrapAndNiftyswap", "nodeType": "ContractDefinition", "nodes": [ { "documentation": { "id": 2, "nodeType": "StructuredDocumentation", "src": "96:347:0", "text": " @notice Wrap ERC-20 to ERC-1155 and swap them\n @dev User must approve this contract for ERC-20 first\n @param _maxAmount Maximum amount of ERC-20 user wants to spend\n @param _recipient Address where to send tokens\n @param _niftyswapOrder Encoded Niftyswap order passed in data field of safeTransferFrom()" }, "functionSelector": "a874d5b6", "id": 11, "implemented": false, "kind": "function", "modifiers": [], "name": "wrapAndSwap", "nodeType": "FunctionDefinition", "parameters": { "id": 9, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 4, "mutability": "mutable", "name": "_maxAmount", "nodeType": "VariableDeclaration", "scope": 11, "src": "467:18:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 3, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "467:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" }, { "constant": false, "id": 6, "mutability": "mutable", "name": "_recipient", "nodeType": "VariableDeclaration", "scope": 11, "src": "487:18:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5, "name": "address", "nodeType": "ElementaryTypeName", "src": "487:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "visibility": "internal" }, { "constant": false, "id": 8, "mutability": "mutable", "name": "_niftyswapOrder", "nodeType": "VariableDeclaration", "scope": 11, "src": "507:30:0", "stateVariable": false, "storageLocation": "calldata", "typeDescriptions": { "typeIdentifier": "t_bytes_calldata_ptr", "typeString": "bytes" }, "typeName": { "id": 7, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "507:5:0", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "visibility": "internal" } ], "src": "466:72:0" }, "returnParameters": { "id": 10, "nodeType": "ParameterList", "parameters": [], "src": "547:0:0" }, "scope": 46, "src": "446:102:0", "stateMutability": "nonpayable", "virtual": false, "visibility": "external" }, { "documentation": { "id": 12, "nodeType": "StructuredDocumentation", "src": "552:157:0", "text": " @notice Accepts only tokenWrapper tokens\n @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`" }, "functionSelector": "f23a6e61", "id": 27, "implemented": false, "kind": "function", "modifiers": [], "name": "onERC1155Received", "nodeType": "FunctionDefinition", "parameters": { "id": 23, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 14, "mutability": "mutable", "name": "_operator", "nodeType": "VariableDeclaration", "scope": 27, "src": "739:17:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 13, "name": "address", "nodeType": "ElementaryTypeName", "src": "739:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "visibility": "internal" }, { "constant": false, "id": 16, "mutability": "mutable", "name": "_from", "nodeType": "VariableDeclaration", "scope": 27, "src": "758:13:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 15, "name": "address", "nodeType": "ElementaryTypeName", "src": "758:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "visibility": "internal" }, { "constant": false, "id": 18, "mutability": "mutable", "name": "_id", "nodeType": "VariableDeclaration", "scope": 27, "src": "773:11:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 17, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "773:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" }, { "constant": false, "id": 20, "mutability": "mutable", "name": "_amount", "nodeType": "VariableDeclaration", "scope": 27, "src": "786:15:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 19, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "786:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" }, { "constant": false, "id": 22, "mutability": "mutable", "name": "_data", "nodeType": "VariableDeclaration", "scope": 27, "src": "803:20:0", "stateVariable": false, "storageLocation": "calldata", "typeDescriptions": { "typeIdentifier": "t_bytes_calldata_ptr", "typeString": "bytes" }, "typeName": { "id": 21, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "803:5:0", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "visibility": "internal" } ], "src": "738:86:0" }, "returnParameters": { "id": 26, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 25, "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "scope": 27, "src": "842:6:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes4", "typeString": "bytes4" }, "typeName": { "id": 24, "name": "bytes4", "nodeType": "ElementaryTypeName", "src": "842:6:0", "typeDescriptions": { "typeIdentifier": "t_bytes4", "typeString": "bytes4" } }, "visibility": "internal" } ], "src": "841:8:0" }, "scope": 46, "src": "712:138:0", "stateMutability": "nonpayable", "virtual": false, "visibility": "external" }, { "documentation": { "id": 28, "nodeType": "StructuredDocumentation", "src": "854:290:0", "text": " @notice If receives tracked ERC-1155, it will send a sell order to niftyswap and unwrap received\n wrapped token. The unwrapped tokens will be sent to the sender.\n @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`" }, "functionSelector": "bc197c81", "id": 45, "implemented": false, "kind": "function", "modifiers": [], "name": "onERC1155BatchReceived", "nodeType": "FunctionDefinition", "parameters": { "id": 41, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 30, "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "scope": 45, "src": "1179:7:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 29, "name": "address", "nodeType": "ElementaryTypeName", "src": "1179:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "visibility": "internal" }, { "constant": false, "id": 32, "mutability": "mutable", "name": "_from", "nodeType": "VariableDeclaration", "scope": 45, "src": "1188:13:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 31, "name": "address", "nodeType": "ElementaryTypeName", "src": "1188:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "visibility": "internal" }, { "constant": false, "id": 35, "mutability": "mutable", "name": "_ids", "nodeType": "VariableDeclaration", "scope": 45, "src": "1203:23:0", "stateVariable": false, "storageLocation": "calldata", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$dyn_calldata_ptr", "typeString": "uint256[]" }, "typeName": { "baseType": { "id": 33, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1203:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 34, "nodeType": "ArrayTypeName", "src": "1203:9:0", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$dyn_storage_ptr", "typeString": "uint256[]" } }, "visibility": "internal" }, { "constant": false, "id": 38, "mutability": "mutable", "name": "_amounts", "nodeType": "VariableDeclaration", "scope": 45, "src": "1228:27:0", "stateVariable": false, "storageLocation": "calldata", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$dyn_calldata_ptr", "typeString": "uint256[]" }, "typeName": { "baseType": { "id": 36, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1228:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 37, "nodeType": "ArrayTypeName", "src": "1228:9:0", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$dyn_storage_ptr", "typeString": "uint256[]" } }, "visibility": "internal" }, { "constant": false, "id": 40, "mutability": "mutable", "name": "_data", "nodeType": "VariableDeclaration", "scope": 45, "src": "1257:20:0", "stateVariable": false, "storageLocation": "calldata", "typeDescriptions": { "typeIdentifier": "t_bytes_calldata_ptr", "typeString": "bytes" }, "typeName": { "id": 39, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "1257:5:0", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "visibility": "internal" } ], "src": "1178:100:0" }, "returnParameters": { "id": 44, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 43, "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "scope": 45, "src": "1296:6:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes4", "typeString": "bytes4" }, "typeName": { "id": 42, "name": "bytes4", "nodeType": "ElementaryTypeName", "src": "1296:6:0", "typeDescriptions": { "typeIdentifier": "t_bytes4", "typeString": "bytes4" } }, "visibility": "internal" } ], "src": "1295:8:0" }, "scope": 46, "src": "1147:157:0", "stateMutability": "nonpayable", "virtual": false, "visibility": "external" } ], "scope": 47, "src": "63:1243:0" } ], "src": "39:1267:0" }, "id": 0 } } } }