UNPKG

@sonicxchain/soxswap-periphery

Version:

Peripheral smart contracts for interacting with Soxswap

1,046 lines (1,045 loc) 179 kB
{ "contractName": "AddressStringUtil", "abi": [], "bytecode": "0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea165627a7a72305820a135e34fc440e95d986df9dbd6b33fbb4c1a96e3046babe127b8458965b1841a0029", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea165627a7a72305820a135e34fc440e95d986df9dbd6b33fbb4c1a96e3046babe127b8458965b1841a0029", "sourceMap": "28:1353:9:-;;132:2:-1;166:7;155:9;146:7;137:37;252:7;246:14;243:1;238:23;232:4;229:33;270:1;265:20;;;;222:63;;265:20;274:9;222:63;;298:9;295:1;288:20;328:4;319:7;311:22;352:7;343;336:24", "deployedSourceMap": "28:1353:9:-;;;;;;;;", "source": "pragma solidity >=0.5.0;\r\n\r\nlibrary AddressStringUtil {\r\n\r\n // converts an address to the uppercase hex string, extracting only len bytes (up to 20, multiple of 2)\r\n function toAsciiString(address addr, uint256 len) internal pure returns (string memory) {\r\n require(len % 2 == 0 && len > 0 && len <= 40, 'AddressStringUtil: INVALID_LEN');\r\n\r\n bytes memory s = new bytes(len);\r\n uint256 addrNum = uint256(addr);\r\n for (uint256 i = 0; i < len / 2; i++) {\r\n // shift right and truncate all but the least significant byte to extract the byte at position 19-i\r\n uint8 b = uint8(addrNum >> (8 * (19 - i)));\r\n // first hex character is the most significant 4 bits\r\n uint8 hi = b >> 4;\r\n // second hex character is the least significant 4 bits\r\n uint8 lo = b - (hi << 4);\r\n s[2 * i] = char(hi);\r\n s[2 * i + 1] = char(lo);\r\n }\r\n return string(s);\r\n }\r\n\r\n // hi and lo are only 4 bits and between 0 and 16\r\n // this method converts those values to the unicode/ascii code point for the hex representation\r\n // uses upper case for the characters\r\n function char(uint8 b) private pure returns (bytes1 c) {\r\n if (b < 10) {\r\n return bytes1(b + 0x30);\r\n } else {\r\n return bytes1(b + 0x37);\r\n }\r\n }\r\n}\r\n", "sourcePath": "@sonicxchain/soxswap-lib/contracts/libraries/AddressStringUtil.sol", "ast": { "absolutePath": "@sonicxchain/soxswap-lib/contracts/libraries/AddressStringUtil.sol", "exportedSymbols": { "AddressStringUtil": [ 3654 ] }, "id": 3655, "nodeType": "SourceUnit", "nodes": [ { "id": 3518, "literals": [ "solidity", ">=", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:24:9" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 3654, "linearizedBaseContracts": [ 3654 ], "name": "AddressStringUtil", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 3626, "nodeType": "Block", "src": "260:720:9", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 3540, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 3536, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3532, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3530, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3528, "name": "len", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3522, "src": "279:3:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "%", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 3529, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "285:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "279:7:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "==", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 3531, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "290:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "279:12:9", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "&&", "rightExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3535, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3533, "name": "len", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3522, "src": "295:3:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": ">", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 3534, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "301:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "295:7:9", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "279:23:9", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "&&", "rightExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3539, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3537, "name": "len", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3522, "src": "306:3:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "<=", "rightExpression": { "argumentTypes": null, "hexValue": "3430", "id": 3538, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "313:2:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_40_by_1", "typeString": "int_const 40" }, "value": "40" }, "src": "306:9:9", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "279:36:9", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "41646472657373537472696e675574696c3a20494e56414c49445f4c454e", "id": 3541, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "317:32:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_eab9febfbdce9e67c4279e4c2a77a43766d401ab3f3bd92cdff53b9ffd3f8f3f", "typeString": "literal_string \"AddressStringUtil: INVALID_LEN\"" }, "value": "AddressStringUtil: INVALID_LEN" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_eab9febfbdce9e67c4279e4c2a77a43766d401ab3f3bd92cdff53b9ffd3f8f3f", "typeString": "literal_string \"AddressStringUtil: INVALID_LEN\"" } ], "id": 3527, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 4577, 4578 ], "referencedDeclaration": 4578, "src": "271:7:9", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 3542, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "271:79:9", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 3543, "nodeType": "ExpressionStatement", "src": "271:79:9" }, { "assignments": [ 3545 ], "declarations": [ { "constant": false, "id": 3545, "name": "s", "nodeType": "VariableDeclaration", "scope": 3626, "src": "363:14:9", "stateVariable": false, "storageLocation": "memory", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes" }, "typeName": { "id": 3544, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "363:5:9", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } }, "value": null, "visibility": "internal" } ], "id": 3550, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 3548, "name": "len", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3522, "src": "390:3:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "id": 3547, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "NewExpression", "src": "380:9:9", "typeDescriptions": { "typeIdentifier": "t_function_objectcreation_pure$_t_uint256_$returns$_t_bytes_memory_$", "typeString": "function (uint256) pure returns (bytes memory)" }, "typeName": { "id": 3546, "name": "bytes", "nodeType": "ElementaryTypeName", "src": "384:5:9", "typeDescriptions": { "typeIdentifier": "t_bytes_storage_ptr", "typeString": "bytes" } } }, "id": 3549, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "380:14:9", "typeDescriptions": { "typeIdentifier": "t_bytes_memory", "typeString": "bytes memory" } }, "nodeType": "VariableDeclarationStatement", "src": "363:31:9" }, { "assignments": [ 3552 ], "declarations": [ { "constant": false, "id": 3552, "name": "addrNum", "nodeType": "VariableDeclaration", "scope": 3626, "src": "405:15:9", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 3551, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "405:7:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 3556, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 3554, "name": "addr", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3520, "src": "431:4:9", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 3553, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "423:7:9", "typeDescriptions": { "typeIdentifier": "t_type$_t_uint256_$", "typeString": "type(uint256)" }, "typeName": "uint256" }, "id": 3555, "isConstant": false, "isLValue": false, "isPure": false, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "423:13:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "405:31:9" }, { "body": { "id": 3620, "nodeType": "Block", "src": "485:461:9", "statements": [ { "assignments": [ 3570 ], "declarations": [ { "constant": false, "id": 3570, "name": "b", "nodeType": "VariableDeclaration", "scope": 3620, "src": "613:7:9", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" }, "typeName": { "id": 3569, "name": "uint8", "nodeType": "ElementaryTypeName", "src": "613:5:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "value": null, "visibility": "internal" } ], "id": 3582, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3580, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3572, "name": "addrNum", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3552, "src": "629:7:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": ">>", "rightExpression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3578, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "hexValue": "38", "id": 3573, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "641:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_8_by_1", "typeString": "int_const 8" }, "value": "8" }, "nodeType": "BinaryOperation", "operator": "*", "rightExpression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3576, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "hexValue": "3139", "id": 3574, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "646:2:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_19_by_1", "typeString": "int_const 19" }, "value": "19" }, "nodeType": "BinaryOperation", "operator": "-", "rightExpression": { "argumentTypes": null, "id": 3575, "name": "i", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3558, "src": "651:1:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "646:6:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "id": 3577, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "645:8:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "641:12:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "id": 3579, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "640:14:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "629:25:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "id": 3571, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "623:5:9", "typeDescriptions": { "typeIdentifier": "t_type$_t_uint8_$", "typeString": "type(uint8)" }, "typeName": "uint8" }, "id": 3581, "isConstant": false, "isLValue": false, "isPure": false, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "623:32:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "nodeType": "VariableDeclarationStatement", "src": "613:42:9" }, { "assignments": [ 3584 ], "declarations": [ { "constant": false, "id": 3584, "name": "hi", "nodeType": "VariableDeclaration", "scope": 3620, "src": "737:8:9", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" }, "typeName": { "id": 3583, "name": "uint8", "nodeType": "ElementaryTypeName", "src": "737:5:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "value": null, "visibility": "internal" } ], "id": 3588, "initialValue": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint8", "typeString": "uint8" }, "id": 3587, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3585, "name": "b", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3570, "src": "748:1:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "nodeType": "BinaryOperation", "operator": ">>", "rightExpression": { "argumentTypes": null, "hexValue": "34", "id": 3586, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "753:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_4_by_1", "typeString": "int_const 4" }, "value": "4" }, "src": "748:6:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "nodeType": "VariableDeclarationStatement", "src": "737:17:9" }, { "assignments": [ 3590 ], "declarations": [ { "constant": false, "id": 3590, "name": "lo", "nodeType": "VariableDeclaration", "scope": 3620, "src": "838:8:9", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" }, "typeName": { "id": 3589, "name": "uint8", "nodeType": "ElementaryTypeName", "src": "838:5:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "value": null, "visibility": "internal" } ], "id": 3597, "initialValue": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint8", "typeString": "uint8" }, "id": 3596, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3591, "name": "b", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3570, "src": "849:1:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "nodeType": "BinaryOperation", "operator": "-", "rightExpression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint8", "typeString": "uint8" }, "id": 3594, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3592, "name": "hi", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3584, "src": "854:2:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "nodeType": "BinaryOperation", "operator": "<<", "rightExpression": { "argumentTypes": null, "hexValue": "34", "id": 3593, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "860:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_4_by_1", "typeString": "int_const 4" }, "value": "4" }, "src": "854:7:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } } ], "id": 3595, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "853:9:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "src": "849:13:9", "typeDescriptions": { "typeIdentifier": "t_uint8", "typeString": "uint8" } }, "nodeType": "VariableDeclarationStatement", "src": "838:24:9" }, { "expression": { "argumentTypes": null, "id": 3606, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "baseExpression": { "argumentTypes": null, "id": 3598, "name": "s", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3545, "src": "877:1:9", "typeDescriptions": { "typeIdentifier": "t_bytes_memory_ptr", "typeString": "bytes memory" } }, "id": 3602, "indexExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3601, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "hexValue": "32", "id": 3599, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "879:1:9", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "nodeType": "BinaryOperation", "operator": "*", "rightExpression": { "argumentTypes": null, "id": 3600, "name": "i", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3558, "src": "883:1:9", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } },