Address Contract Verified
Address
0x1FCC3e6F76F7a96CD2b9D09F1D3C041Ca1403c57
Balance
0 ETH
Nonce
1
Code Size
22809 bytes
Creator
0xe750ad66...45E3 at tx 0xaf182785...ce4059
Indexed Transactions
0 (1 on-chain, 0.6% indexed)
Contract Bytecode
22809 bytes
0x60806040526004361061024f5760003560e01c80639a4f809c11610138578063b4658bfb116100b0578063ea7faa611161007f578063f6e0f6a511610064578063f6e0f6a51461069d578063fd5f995b146106bd578063fe55a3ef146106dd5761024f565b8063ea7faa611461066a578063f6274f661461068a5761024f565b8063b4658bfb146105f5578063d0a55fb014610615578063dab400f314610635578063dd11d2251461064a5761024f565b8063aa6b21cd11610107578063ad354eeb116100ec578063ad354eeb14610586578063b09f1fb1146105b5578063b10a33f4146105d55761024f565b8063aa6b21cd14610546578063aa77476c146105665761024f565b80639a4f809c146104d15780639baa45a8146104f15780639f0434f514610511578063a0edcef5146105315761024f565b8063487b5c20116101cb57806386a0c8d71161019a5780639240529c1161017f5780639240529c1461047e578063935c82a41461049157806395480889146104b15761024f565b806386a0c8d71461043c5780638fd3ab801461045c5761024f565b8063487b5c20146103ab5780636ae4b4f7146103cd5780636b52a4a8146103ef5780637d49ec1a1461041c5761024f565b8063346693c5116102225780633cd2f026116102075780633cd2f0261461033d578063414e4ccf1461035d578063438cdfc51461037e5761024f565b8063346693c5146102f057806337f381d81461031d5761024f565b8063016a6d6514610254578063031b905c1461028a5780630f0e8cf71461029f5780631fb09795146102c1575b600080fd5b34801561026057600080fd5b5061027461026f366004614bb6565b6106fd565b60405161028191906150b4565b60405180910390f35b34801561029657600080fd5b50610274610718565b3480156102ab57600080fd5b506102bf6102ba366004614705565b61073c565b005b3480156102cd57600080fd5b506102e16102dc366004614a1e565b6107ec565b60405161028193929190615677565b3480156102fc57600080fd5b5061031061030b366004614bb6565b610904565b6040516102819190615669565b34801561032957600080fd5b506102e1610338366004614bd2565b6109bc565b34801561034957600080fd5b506102bf610358366004614696565b610abc565b61037061036b366004614ac7565b610aef565b6040516102819291906157c2565b34801561038a57600080fd5b5061039e610399366004614c08565b610b99565b60405161028191906157a5565b3480156103b757600080fd5b506103c0610c6a565b60405161028191906157f3565b3480156103d957600080fd5b506103e2610c8e565b60405161028191906152f1565b3480156103fb57600080fd5b5061040f61040a36600461449b565b610cc7565b60405161028191906150a9565b34801561042857600080fd5b506102bf610437366004614a02565b610d15565b34801561044857600080fd5b506102bf610457366004614705565b610d96565b34801561046857600080fd5b50610471610e37565b6040516102819190615236565b61039e61048c366004614a7c565b611355565b34801561049d57600080fd5b506102bf6104ac366004614597565b611418565b3480156104bd57600080fd5b506103106104cc366004614a02565b61143f565b3480156104dd57600080fd5b506102bf6104ec3660046149c2565b6114ca565b3480156104fd57600080fd5b506102bf61050c366004614814565b6114d6565b34801561051d57600080fd5b506102bf61052c3660046144d3565b611506565b34801561053d57600080fd5b506103c0611594565b34801561055257600080fd5b50610370610561366004614c48565b6115b8565b34801561057257600080fd5b50610370610581366004614c08565b611666565b34801561059257600080fd5b506105a66105a13660046148b3565b6116d4565b6040516102819392919061500b565b3480156105c157600080fd5b506102bf6105d03660046145e7565b61193a565b3480156105e157600080fd5b506102bf6105f0366004614597565b611a53565b34801561060157600080fd5b506105a661061036600461477f565b611a7a565b34801561062157600080fd5b506102bf6106303660046149c2565b611cd5565b34801561064157600080fd5b50610274611ce1565b34801561065657600080fd5b50610274610665366004614a02565b611d05565b34801561067657600080fd5b506102bf61068536600461456a565b611d13565b610370610698366004614a7c565b611daf565b3480156106a957600080fd5b506102bf6106b8366004614915565b611e4d565b3480156106c957600080fd5b506102bf6106d83660046144d3565b611e7d565b3480156106e957600080fd5b506102bf6106f8366004614bb6565b611f04565b600061071061070b83611f81565b6120b8565b90505b919050565b7f000000000000000000000000000000000000000000000001000000030000000081565b8151835114801561074e575080518351145b61078d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107849061541c565b60405180910390fd5b60005b83518110156107e6576107de338583815181106107a957fe5b60200260200101518584815181106107bd57fe5b60200260200101518585815181106107d157fe5b602002602001015161210a565b600101610790565b50505050565b6107f46140e7565b6000806108008561143f565b92506108916040518060a001604052808760a0015173ffffffffffffffffffffffffffffffffffffffff168152602001876000015173ffffffffffffffffffffffffffffffffffffffff16815260200187604001516fffffffffffffffffffffffffffffffff16815260200187606001516fffffffffffffffffffffffffffffffff168152602001858152506121f2565b83519092506000906108b1906108ac36889003880188614ccd565b61231b565b90508073ffffffffffffffffffffffffffffffffffffffff168660a0015173ffffffffffffffffffffffffffffffffffffffff1614806108fa57506108fa8660a0015182610cc7565b9150509250925092565b61090c6140e7565b610915826106fd565b8152600061092161246c565b608084015173ffffffffffffffffffffffffffffffffffffffff9081166000908152600292909201602090815260408084208751841685528252808420828801519093168452919052902054606084015161010085015161012086015192935061098f928592919085612479565b60c083015173ffffffffffffffffffffffffffffffffffffffff166109b657600060208301525b50919050565b6109c46140e7565b6000806109d085610904565b9250610a616040518060a00160405280876080015173ffffffffffffffffffffffffffffffffffffffff168152602001876000015173ffffffffffffffffffffffffffffffffffffffff16815260200187604001516fffffffffffffffffffffffffffffffff16815260200187606001516fffffffffffffffffffffffffffffffff168152602001858152506121f2565b91506000610a7384600001518661231b565b90508073ffffffffffffffffffffffffffffffffffffffff16866080015173ffffffffffffffffffffffffffffffffffffffff1614806108fa57506108fa866080015182610cc7565b60005b81811015610aea57610ae2838383818110610ad657fe5b9050602002013561256c565b600101610abf565b505050565b600080333014610b0a57610b0a610b05336127ba565b612872565b610b12614109565b610b7f6040518060a001604052808a8152602001898152602001886fffffffffffffffffffffffffffffffff1681526020018773ffffffffffffffffffffffffffffffffffffffff1681526020018673ffffffffffffffffffffffffffffffffffffffff1681525061287a565b602081015160409091015190999098509650505050505050565b6000610ba3614109565b6040805160c081018252868152602081018690526fffffffffffffffffffffffffffffffff85169181019190915233606082018190526000608083015260a0820152610bee90612c4d565b9050826fffffffffffffffffffffffffffffffff1681602001516fffffffffffffffffffffffffffffffff161015610c5e57610c5e610b05610c2f876106fd565b83602001516fffffffffffffffffffffffffffffffff16866fffffffffffffffffffffffffffffffff16612ff6565b60400151949350505050565b7f000000000000000000000000000000000000000000000000000000000000000090565b6040518060400160405280600b81526020017f4c696d69744f726465727300000000000000000000000000000000000000000081525081565b6000610cd161246c565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260049290920160209081526040808420928616845291905290205460ff1690505b92915050565b6000610d2082611d05565b90508160a0015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614158015610d6d5750610d6b8260a0015133610cc7565b155b15610d8457610d84610b0582338560a001516130b4565b610d92818360a001516130ec565b5050565b81518351148015610da8575080518351145b610dde576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107849061541c565b60005b83518110156107e657610e2f33858381518110610dfa57fe5b6020026020010151858481518110610e0e57fe5b6020026020010151858581518110610e2257fe5b602002602001015161315f565b600101610de1565b6000610e627f3cd2f02600000000000000000000000000000000000000000000000000000000613237565b610e8b7ff6274f6600000000000000000000000000000000000000000000000000000000613237565b610eb47faa77476c00000000000000000000000000000000000000000000000000000000613237565b610edd7f9240529c00000000000000000000000000000000000000000000000000000000613237565b610f067f438cdfc500000000000000000000000000000000000000000000000000000000613237565b610f2f7f414e4ccf00000000000000000000000000000000000000000000000000000000613237565b610f587faa6b21cd00000000000000000000000000000000000000000000000000000000613237565b610f817f7d49ec1a00000000000000000000000000000000000000000000000000000000613237565b610faa7ffe55a3ef00000000000000000000000000000000000000000000000000000000613237565b610fd37f9baa45a800000000000000000000000000000000000000000000000000000000613237565b610ffc7ff6e0f6a500000000000000000000000000000000000000000000000000000000613237565b6110257fd0a55fb000000000000000000000000000000000000000000000000000000000613237565b61104e7fb10a33f400000000000000000000000000000000000000000000000000000000613237565b6110777f86a0c8d700000000000000000000000000000000000000000000000000000000613237565b6110a07f9f0434f500000000000000000000000000000000000000000000000000000000613237565b6110c97f9a4f809c00000000000000000000000000000000000000000000000000000000613237565b6110f27f935c82a400000000000000000000000000000000000000000000000000000000613237565b61111b7f0f0e8cf700000000000000000000000000000000000000000000000000000000613237565b6111447ffd5f995b00000000000000000000000000000000000000000000000000000000613237565b61116d7f9548088900000000000000000000000000000000000000000000000000000000613237565b6111967f346693c500000000000000000000000000000000000000000000000000000000613237565b6111bf7fdd11d22500000000000000000000000000000000000000000000000000000000613237565b6111e87f016a6d6500000000000000000000000000000000000000000000000000000000613237565b6112117f487b5c2000000000000000000000000000000000000000000000000000000000613237565b61123a7fb09f1fb100000000000000000000000000000000000000000000000000000000613237565b6112637f1fb0979500000000000000000000000000000000000000000000000000000000613237565b61128c7f37f381d800000000000000000000000000000000000000000000000000000000613237565b6112b57fb4658bfb00000000000000000000000000000000000000000000000000000000613237565b6112de7fad354eeb00000000000000000000000000000000000000000000000000000000613237565b6113077fea7faa6100000000000000000000000000000000000000000000000000000000613237565b6113307f6b52a4a800000000000000000000000000000000000000000000000000000000613237565b507f2c64c5ef0000000000000000000000000000000000000000000000000000000090565b600061135f614109565b6113cc6040518060a00160405280878152602001868152602001856fffffffffffffffffffffffffffffffff1681526020013373ffffffffffffffffffffffffffffffffffffffff1681526020013373ffffffffffffffffffffffffffffffffffffffff1681525061287a565b9050826fffffffffffffffffffffffffffffffff1681602001516fffffffffffffffffffffffffffffffff16101561140d5761140d610b05610c2f87611d05565b8051610c5e906132c3565b6114228433610cc7565b61143357611433610b058533613366565b6107e68484848461210a565b6114476140e7565b61145082611d05565b8152600061145c61246c565b60a084015173ffffffffffffffffffffffffffffffffffffffff908116600090815260019290920160209081526040808420875184168552825280842082880151909316845291905290205460608401516101408501516101608601519293506109b6928592919085612479565b610aea3384848461210a565b60005b8151811015610d92576114fe8282815181106114f157fe5b6020026020010151610d15565b6001016114d9565b81518351148015611518575080518351145b61154e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107849061541c565b6115588433610cc7565b61156957611569610b058533613366565b60005b835181101561158d5761158585858381518110610dfa57fe5b60010161156c565b5050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000803330146115ce576115ce610b05336127ba565b6115d6614109565b61164b6040518060c001604052808b81526020018a8152602001896fffffffffffffffffffffffffffffffff1681526020018873ffffffffffffffffffffffffffffffffffffffff16815260200187151581526020018673ffffffffffffffffffffffffffffffffffffffff16815250612c4d565b6020810151604090910151909a909950975050505050505050565b600080611671614109565b6040805160c081018252878152602081018790526fffffffffffffffffffffffffffffffff86169181019190915233606082018190526000608083015260a08201526116bc90612c4d565b60208101516040909101519097909650945050505050565b60608080858414611711576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078490615362565b8567ffffffffffffffff8111801561172857600080fd5b5060405190808252806020026020018201604052801561176257816020015b61174f6140e7565b8152602001906001900390816117475790505b5092508567ffffffffffffffff8111801561177c57600080fd5b506040519080825280602002602001820160405280156117a6578160200160208202803683370190505b5091508567ffffffffffffffff811180156117c057600080fd5b506040519080825280602002602001820160405280156117ea578160200160208202803683370190505b50905060005b8681101561192f57306337f381d889898481811061180a57fe5b9050610140020188888581811061181d57fe5b9050608002016040518363ffffffff1660e01b81526004016118409291906156ad565b60a06040518083038186803b15801561185857600080fd5b505afa9250505080156118a6575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019092526118a391810190614b3a565b60015b6118af57611927565b828785815181106118bc57fe5b6020026020010181905250818685815181106118d457fe5b60200260200101906fffffffffffffffffffffffffffffffff1690816fffffffffffffffffffffffffffffffff16815250508085858151811061191357fe5b911515602092830291909101909101525050505b6001016117f0565b509450945094915050565b333214611973576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610784906153bf565b600061197d61246c565b905060005b8351811015611a1257336000908152600383016020526040812085518592908790859081106119ad57fe5b60209081029190910181015173ffffffffffffffffffffffffffffffffffffffff16825281019190915260400160002080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055600101611982565b507f02dfead5eb769b298e82dd9650b31c40559a3d42701dbf53c931bc2682847c31338484604051611a4693929190614f15565b60405180910390a1505050565b611a5d8433610cc7565b611a6e57611a6e610b058533613366565b6107e68484848461315f565b60608080858414611ab7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078490615362565b8567ffffffffffffffff81118015611ace57600080fd5b50604051908082528060200260200182016040528015611b0857816020015b611af56140e7565b815260200190600190039081611aed5790505b5092508567ffffffffffffffff81118015611b2257600080fd5b50604051908082528060200260200182016040528015611b4c578160200160208202803683370190505b5091508567ffffffffffffffff81118015611b6657600080fd5b50604051908082528060200260200182016040528015611b90578160200160208202803683370190505b50905060005b8681101561192f5730631fb09795898984818110611bb057fe5b90506101800201888885818110611bc357fe5b9050608002016040518363ffffffff1660e01b8152600401611be6929190615533565b60a06040518083038186803b158015611bfe57600080fd5b505afa925050508015611c4c575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252611c4991810190614b3a565b60015b611c5557611ccd565b82878581518110611c6257fe5b602002602001018190525081868581518110611c7a57fe5b60200260200101906fffffffffffffffffffffffffffffffff1690816fffffffffffffffffffffffffffffffff168152505080858581518110611cb957fe5b911515602092830291909101909101525050505b600101611b96565b610aea3384848461315f565b7ffe3a8808ff7909b8c36164e6e9a076597c21c3fc2ec6f2c8ac04529c41ce507e81565b600061071061070b83613421565b6000611d1d61246c565b336000818152600483016020908152604080832073ffffffffffffffffffffffffffffffffffffffff891684529091529081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016861515179055519192507f6ea9dbe8b2cc119348716a9220a0742ad62b7884ecb0ff4b32cd508121fd937991611a46919086908690614ee4565b600080611dba614109565b611e276040518060a00160405280888152602001878152602001866fffffffffffffffffffffffffffffffff1681526020013373ffffffffffffffffffffffffffffffffffffffff1681526020013373ffffffffffffffffffffffffffffffffffffffff1681525061287a565b9050611e3681600001516132c3565b602081015160409091015190969095509350505050565b60005b8151811015610d9257611e75828281518110611e6857fe5b6020026020010151611f04565b600101611e50565b81518351148015611e8f575080518351145b611ec5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107849061541c565b611ecf8433610cc7565b611ee057611ee0610b058533613366565b60005b835181101561158d57611efc858583815181106107a957fe5b600101611ee3565b6000611f0f826106fd565b9050816080015173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614158015611f5c5750611f5a826080015133610cc7565b155b15611f7357611f73610b05823385608001516130b4565b610d928183608001516130ec565b60006040517fe593d3fdfa8b60e5e17a1b2204662ecbe15c23f2084b9ad5bae40359540a7da98152825173ffffffffffffffffffffffffffffffffffffffff166020820152602083015173ffffffffffffffffffffffffffffffffffffffff16604082015260408301516fffffffffffffffffffffffffffffffff16606082015260608301516fffffffffffffffffffffffffffffffff166080820152608083015173ffffffffffffffffffffffffffffffffffffffff1660a082015260a083015173ffffffffffffffffffffffffffffffffffffffff1660c082015260c083015173ffffffffffffffffffffffffffffffffffffffff1660e082015260e083015161010082015261010083015167ffffffffffffffff166101208201526101208301516101408201526101608120915050919050565b60007ffe3a8808ff7909b8c36164e6e9a076597c21c3fc2ec6f2c8ac04529c41ce507e826040516020016120ed929190614e59565b604051602081830303815290604052805190602001209050919050565b600061211461246c565b73ffffffffffffffffffffffffffffffffffffffff8087166000908152600283016020908152604080832089851684528252808320938816835292905220549091508281111561216b5761216b610b058483613598565b73ffffffffffffffffffffffffffffffffffffffff80871660009081526002840160209081526040808320898516845282528083209388168352929052819020849055517ffe7ffb1edfe79f4df716cb2dcad21cf2f31b104d816a7976ba1e6e4653c1efb1906121e2908890889088908890614fae565b60405180910390a1505050505050565b600081604001516fffffffffffffffffffffffffffffffff166000148061222d575060608201516fffffffffffffffffffffffffffffffff16155b1561223a57506000610713565b6001826080015160200151600481111561225057fe5b1461225d57506000610713565b60006122b68360800151604001518460600151036fffffffffffffffffffffffffffffffff1684606001516fffffffffffffffffffffffffffffffff1685604001516fffffffffffffffffffffffffffffffff166135ce565b90506122d3816122ce856020015186600001516135ec565b61371e565b905061231461230f8285604001516fffffffffffffffffffffffffffffffff1686606001516fffffffffffffffffffffffffffffffff16613734565b613758565b9392505050565b60006123278383613784565b60028251600381111561233657fe5b141561239e576001838360200151846040015185606001516040516000815260200160405260405161236b9493929190615218565b6020604051602081039080840390855afa15801561238d573d6000803e3d6000fd5b505050602060405103519050612443565b6003825160038111156123ad57fe5b14156124435760007f19457468657265756d205369676e6564204d6573736167653a0a33320000000060005283601c52603c6000209050600181846020015185604001518660600151604051600081526020016040526040516124139493929190615218565b6020604051602081039080840390855afa158015612435573d6000803e3d6000fd5b505050602060405103519150505b73ffffffffffffffffffffffffffffffffffffffff8116610d0f57610d0f610b05600585613830565b600080610d0f6007613866565b600061248361246c565b865160009081526020829052604090819020546fffffffffffffffffffffffffffffffff808216928a01839052929350918716116124da576020870160025b908160048111156124cf57fe5b81525050505061158d565b7f800000000000000000000000000000000000000000000000000000000000000081161561250d576020870160036124c2565b504267ffffffffffffffff168467ffffffffffffffff1611612547576020860160045b9081600481111561253d57fe5b815250505061158d565b8282111561255a57602086016003612530565b60016020870181905250505050505050565b6040517f319bed9a00000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000795e7d412dd832f094291108fdf0298cb65bdab2169063319bed9a906125e19085906004016150b4565b602060405180830381600087803b1580156125fb57600080fd5b505af115801561260f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061263391906149a6565b905060007f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc273ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b81526004016126909190614e92565b60206040518083038186803b1580156126a857600080fd5b505afa1580156126bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126e09190614ce8565b90506001811115610aea576040517fa3b4a32700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000a26e80e7dea86279c6d778d702cc413e6cffa777169063a3b4a3279061278390859081907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff870190600401614eb3565b600060405180830381600087803b15801561279d57600080fd5b505af11580156127b1573d6000803e3d6000fd5b50505050505050565b60607ff0ec779b0bcda6d84abf99ee2c67647d1100ebbb553a9c2d1c2ba1579592832c826040516024016127ee9190614e92565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091529050919050565b805160208201fd5b612882614109565b61288a6140e7565b82516128959061143f565b90506001816020015160048111156128a957fe5b146128ce576128ce610b058260000151836020015160048111156128c957fe5b613881565b825160c0015173ffffffffffffffffffffffffffffffffffffffff16158015906129305750826060015173ffffffffffffffffffffffffffffffffffffffff16836000015160c0015173ffffffffffffffffffffffffffffffffffffffff1614155b1561295357612953610b0582600001518560600151866000015160c001516138b7565b825160e0015173ffffffffffffffffffffffffffffffffffffffff16158015906129b55750826080015173ffffffffffffffffffffffffffffffffffffffff16836000015160e0015173ffffffffffffffffffffffffffffffffffffffff1614155b156129d8576129d8610b0582600001518560800151866000015160e001516138ef565b60006129ec8260000151856020015161231b565b9050836000015160a0015173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614158015612a3f5750835160a00151612a3d9082610cc7565b155b15612a5b578151845160a00151612a5b91610b05918490613927565b5082516101200151612a6c9061395f565b8252604080516101408101825282518152845160a09081015173ffffffffffffffffffffffffffffffffffffffff9081166020808501919091526060808901805184168688015251831681860152885151831660808601528851909101519091169183019190915285518301516fffffffffffffffffffffffffffffffff90811660c0840152865190910151811660e083015285830151811661010083015291830151909116610120820152612b2190613a34565b6fffffffffffffffffffffffffffffffff908116604085015290811660208401528351608001511615612bd857612ba382602001516fffffffffffffffffffffffffffffffff168460000151606001516fffffffffffffffffffffffffffffffff168560000151608001516fffffffffffffffffffffffffffffffff166135ce565b6fffffffffffffffffffffffffffffffff166060808401829052845160208101519186015161010090910151612bd893613bf5565b8051835160a08101516060808701516101008401518451602080870151908a01516040808c0151968c01518c51610120909a015191517fab614d2b738543c0ea21f56347cf696a3a0c42a7cbec3212a5ca22a4dcff21249b612c3f9b909a9993909161510d565b60405180910390a150919050565b612c55614109565b612c5d6140e7565b8251612c6890610904565b9050600181602001516004811115612c7c57fe5b14612c9c57612c9c610b058260000151836020015160048111156128c957fe5b6000612ca661246c565b845160c0015190915073ffffffffffffffffffffffffffffffffffffffff163214801590612d0c5750835160c0015173ffffffffffffffffffffffffffffffffffffffff166000908152600382016020908152604080832032845290915290205460ff16155b15612d28578151845160c00151612d2891610b05913290613ceb565b50825160a0015173ffffffffffffffffffffffffffffffffffffffff1615801590612d8b5750826060015173ffffffffffffffffffffffffffffffffffffffff16836000015160a0015173ffffffffffffffffffffffffffffffffffffffff1614155b15612dae57612dae610b0582600001518560600151866000015160a001516138b7565b6000612dc28260000151856020015161231b565b905083600001516080015173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614158015612e155750835160800151612e139082610cc7565b155b15612e31578151845160800151612e3191610b05918490613927565b50604080516101408101825282518152845160809081015173ffffffffffffffffffffffffffffffffffffffff166020830152850151612f7c92820190612e7c578560600151612e7e565b305b73ffffffffffffffffffffffffffffffffffffffff1681526020018560a0015173ffffffffffffffffffffffffffffffffffffffff16815260200185600001516000015173ffffffffffffffffffffffffffffffffffffffff16815260200185600001516020015173ffffffffffffffffffffffffffffffffffffffff1681526020018560000151604001516fffffffffffffffffffffffffffffffff1681526020018560000151606001516fffffffffffffffffffffffffffffffff16815260200185604001516fffffffffffffffffffffffffffffffff16815260200183604001516fffffffffffffffffffffffffffffffff16815250613a34565b6fffffffffffffffffffffffffffffffff908116604080860182905292909116602080860182905284518751608081015160608a015182519483015160e09093015197517f829fa99d94dc4636925b38632e625736a614c154d55006b7ab6bea979c210c3298612c3f98959793969295929493929161518d565b60607f21948612b5ef214ec0508df4901600e07a810a371be76b25d59ade73826e3d9784848460405160240161302e939291906151f1565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915290509392505050565b60607f88b2c08e4a5f57d416ad23dad18c20497ccfe684b1379b28fd564adaf582b80f84848460405160240161302e939291906150e1565b60006130f661246c565b6000848152602082905260409081902080547f8000000000000000000000000000000000000000000000000000000000000000179055519091507fa6eb7cdc219e1518ced964e9a34e61d68a94e4f1569db3e84256ba981ba5275390611a4690859085906150bd565b600061316961246c565b73ffffffffffffffffffffffffffffffffffffffff808716600090815260018301602090815260408083208985168452825280832093881683529290522054909150828111156131c0576131c0610b058483613598565b73ffffffffffffffffffffffffffffffffffffffff80871660009081526001840160209081526040808320898516845282528083209388168352929052819020849055517fa91fe7ae62fce669df2c7f880f8c14d178531aae72515558e5c948e37c32a572906121e2908890889088908890614fae565b6040517f6eb224cb0000000000000000000000000000000000000000000000000000000081523090636eb224cb906132959084907f0000000000000000000000001fcc3e6f76f7a96cd2b9d09f1d3c041ca1403c5790600401615263565b600060405180830381600087803b1580156132af57600080fd5b505af115801561158d573d6000803e3d6000fd5b80341180156132d25750333014155b156133635760006132e33483613d23565b905060003373ffffffffffffffffffffffffffffffffffffffff168260405161330b90614e8f565b60006040518083038185875af1925050503d8060008114613348576040519150601f19603f3d011682016040523d82523d6000602084013e61334d565b606091505b5050905080610aea57610aea610b053384613d42565b50565b60607f84356db366796dc6e2aeb1ad74b631fe4e5ec6a650464da6059e9f95c8810a10838360405160240161339c929190614f87565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152905092915050565b60006040517fce918627cb55462ddbb85e73de69a8b322f2bc88f4507c52fcad6d4c33c29d498152825173ffffffffffffffffffffffffffffffffffffffff166020820152602083015173ffffffffffffffffffffffffffffffffffffffff16604082015260408301516fffffffffffffffffffffffffffffffff16606082015260608301516fffffffffffffffffffffffffffffffff16608082015260808301516fffffffffffffffffffffffffffffffff1660a082015260a083015173ffffffffffffffffffffffffffffffffffffffff1660c082015260c083015173ffffffffffffffffffffffffffffffffffffffff1660e082015260e083015173ffffffffffffffffffffffffffffffffffffffff1661010082015261010083015173ffffffffffffffffffffffffffffffffffffffff1661012082015261012083015161014082015261014083015167ffffffffffffffff166101608201526101608301516101808201526101a08120915050919050565b60607fb12bc7e7d341f4431d6faf05f991ee3b779183e341b24243064e10c886cd1873838360405160240161339c9291906157e5565b60006135e4836135de8685613d78565b90613da9565b949350505050565b60006123148373ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e84306040518363ffffffff1660e01b815260040161362c929190614f87565b60206040518083038186803b15801561364457600080fd5b505afa158015613658573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061367c9190614ce8565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8616906370a08231906136ce908790600401614e92565b60206040518083038186803b1580156136e657600080fd5b505afa1580156136fa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122ce9190614ce8565b600081831061372d5781612314565b5090919050565b60006135e4836135de613748826001613d23565b6137528887613d78565b90613dd3565b60006fffffffffffffffffffffffffffffffff82111561378057613780610b05600384613def565b5090565b60408101517ffffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641411115806137db575060608101517f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a111155b156137ee576137ee610b05600584613830565b6000815160038111156137fd57fe5b141561381157613811610b05600384613830565b60018151600381111561382057fe5b1415610d9257610d92610b056000845b60607ff18f11f3027e735c758137924b262d4d3aff0037dcd785aca3c699fa05d960bd838360405160240161339c9291906152e3565b6000608082600881111561387657fe5b600101901b92915050565b60607f47ab394e41470191eaf9fa542e84ac483a12665fbd616eb8d1c022ced6c94000838360405160240161339c929190615207565b60607f5d3300180a4547b3e27137be832d3ebf56f1ba5ebb30dd580999c61f77fa639684848460405160240161302e939291906150e1565b60607f15e6a383bb02d79ee933b927fbecba78cdde16cba84b94a99661f44bcce3b73684848460405160240161302e939291906150e1565b60607ff13e65d925201525f3d71a731833b19bb26e44cfbd97caf72a366b73866f712484848460405160240161302e939291906150e1565b60008061396a613e0c565b90508061397b576000915050610713565b600061398684613e38565b905060008173ffffffffffffffffffffffffffffffffffffffff16836040516139ae90614e8f565b60006040518083038185875af1925050503d80600081146139eb576040519150601f19603f3d011682016040523d82523d6000602084013e6139f0565b606091505b5050905080613a2b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610784906154d6565b50909392505050565b600080613a73836101000151613a6e8561012001518660e001516fffffffffffffffffffffffffffffffff16613e8590919063ffffffff16565b613ee6565b9150613abe826fffffffffffffffffffffffffffffffff168460e001516fffffffffffffffffffffffffffffffff168560c001516fffffffffffffffffffffffffffffffff166135ce565b90506fffffffffffffffffffffffffffffffff82161580613aef57506fffffffffffffffffffffffffffffffff8116155b15613aff57506000905080613bf0565b610120830151613b21906fffffffffffffffffffffffffffffffff1683613f19565b6fffffffffffffffffffffffffffffffff16613b3b61246c565b845160009081526020919091526040908190209190915583015173ffffffffffffffffffffffffffffffffffffffff16301415613b9c57613b978360a001518460200151846fffffffffffffffffffffffffffffffff16613f6e565b613bc6565b613bc68360a0015184604001518560200151856fffffffffffffffffffffffffffffffff16613bf5565b613bf0836080015184602001518560600151846fffffffffffffffffffffffffffffffff16613bf5565b915091565b73ffffffffffffffffffffffffffffffffffffffff8416301415613c45576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078490615479565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416600482015273ffffffffffffffffffffffffffffffffffffffff83166024820152816044820152602081606483600073ffffffffffffffffffffffffffffffffffffffff8a165af13d600183511460208210151681151782169150816127b157806000843e8083fd5b60607fc0972f3cc4234ca2091de7e7bc7081494bd29ac280167d66f0d44168973b163484848460405160240161302e939291906150e1565b600082821115613d3c57613d3c610b0560028585614050565b50900390565b60607fbde95cc2119e0200d80642397198abfcf98e6e4dddd0de9c6320d86252ad40ab838360405160240161339c929190614fe5565b600082613d8757506000610d0f565b82820282848281613d9457fe5b041461231457612314610b0560018686614050565b600081613dbf57613dbf610b0560038585614050565b6000828481613dca57fe5b04949350505050565b60008282018381101561231457612314610b0560008686614050565b606063c996af7b60e01b838360405160240161339c9291906152cc565b63ffffffff7f0000000000000000000000000000000000000000000000000000000000000000163a0290565b60006107107f000000000000000000000000795e7d412dd832f094291108fdf0298cb65bdab27f56efbfef148a2c7c8190d8c6eb112d767ccf1cc4ae41ba6a221e5a66a6a247ee8461406f565b6000826fffffffffffffffffffffffffffffffff16826fffffffffffffffffffffffffffffffff161115613d3c57613d3c610b056002856fffffffffffffffffffffffffffffffff16856fffffffffffffffffffffffffffffffff16614050565b6000816fffffffffffffffffffffffffffffffff16836fffffffffffffffffffffffffffffffff161061372d5781612314565b60008282016fffffffffffffffffffffffffffffffff808516908216101561231457612314610b056000866fffffffffffffffffffffffffffffffff16866fffffffffffffffffffffffffffffffff16614050565b73ffffffffffffffffffffffffffffffffffffffff8316301415613fbe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161078490615479565b6040517fa9059cbb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83166004820152816024820152602081604483600073ffffffffffffffffffffffffffffffffffffffff89165af13d6001835114602082101516811517821691508161404857806000843e8083fd5b505050505050565b606063e946c1bb60e01b84848460405160240161302e939291906152ab565b6040516000906140a9907fff0000000000000000000000000000000000000000000000000000000000000090869085908790602001614df5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190528051602090910120949350505050565b6040805160608101909152600080825260208201908152600060209091015290565b60408051608081018252600080825260208201819052918101829052606081019190915290565b8035610d0f81615888565b600082601f83011261414b578081fd5b813561415e6141598261582b565b615804565b81815291506020808301908481018184028601820187101561417f57600080fd5b60005b848110156141a757813561419581615888565b84529282019290820190600101614182565b505050505092915050565b60008083601f8401126141c3578182fd5b50813567ffffffffffffffff8111156141da578182fd5b6020830191508360206080830285010111156141f557600080fd5b9250929050565b600082601f83011261420c578081fd5b813561421a6141598261582b565b81815291506020808301908481018184028601820187101561423b57600080fd5b60005b848110156141a75781358452928201929082019060010161423e565b8035610d0f816158aa565b6000610180808385031215614278578182fd5b61428181615804565b91505061428e8383614130565b815261429d8360208401614130565b60208201526142af8360408401614478565b60408201526142c18360608401614478565b60608201526142d38360808401614478565b60808201526142e58360a08401614130565b60a08201526142f78360c08401614130565b60c08201526143098360e08401614130565b60e082015261010061431d84828501614130565b90820152610120828101359082015261014061433b84828501614483565b818301525061016080830135818301525092915050565b6000610140808385031215614365578182fd5b61436e81615804565b91505061437b8383614130565b815261438a8360208401614130565b602082015261439c8360408401614478565b60408201526143ae8360608401614478565b60608201526143c08360808401614130565b60808201526143d28360a08401614130565b60a08201526143e48360c08401614130565b60c082015260e082013560e082015261010061440284828501614483565b818301525061012080830135818301525092915050565b60006080828403121561442a578081fd5b6144346080615804565b90508135614441816158b8565b8152602082013560ff8116811461445757600080fd5b80602083015250604082013560408201526060820135606082015292915050565b8035610d0f816158c5565b803567ffffffffffffffff81168114610d0f57600080fd5b600080604083850312156144ad578182fd5b82356144b881615888565b915060208301356144c881615888565b809150509250929050565b600080600080608085870312156144e8578182fd5b84356144f381615888565b9350602085013567ffffffffffffffff8082111561450f578384fd5b61451b8883890161413b565b94506040870135915080821115614530578384fd5b61453c8883890161413b565b93506060870135915080821115614551578283fd5b5061455e878288016141fc565b91505092959194509250565b6000806040838503121561457c578182fd5b823561458781615888565b915060208301356144c8816158aa565b600080600080608085870312156145ac578182fd5b84356145b781615888565b935060208501356145c781615888565b925060408501356145d781615888565b9396929550929360600135925050565b600080604083850312156145f9578182fd5b823567ffffffffffffffff81111561460f578283fd5b8301601f8101851361461f578283fd5b803561462d6141598261582b565b80828252602080830192508085018982838702880101111561464d578788fd5b8795505b8486101561467857803561466481615888565b845260019590950194928101928101614651565b5081965061468889828a0161425a565b955050505050509250929050565b600080602083850312156146a8578182fd5b823567ffffffffffffffff808211156146bf578384fd5b818501915085601f8301126146d2578384fd5b8135818111156146e0578485fd5b86602080830285010111156146f3578485fd5b60209290920196919550909350505050565b600080600060608486031215614719578081fd5b833567ffffffffffffffff80821115614730578283fd5b61473c8783880161413b565b94506020860135915080821115614751578283fd5b61475d8783880161413b565b93506040860135915080821115614772578283fd5b506108fa868287016141fc565b60008060008060408587031215614794578182fd5b843567ffffffffffffffff808211156147ab578384fd5b818701915087601f8301126147be578384fd5b8135818111156147cc578485fd5b886020610180830285010111156147e1578485fd5b6020928301965094509086013590808211156147fb578384fd5b50614808878288016141b2565b95989497509550505050565b60006020808385031215614826578182fd5b823567ffffffffffffffff81111561483c578283fd5b8301601f8101851361484c578283fd5b803561485a6141598261582b565b81815283810190838501610180808502860187018a1015614879578788fd5b8795505b848610156148a55761488f8a83614265565b845260019590950194928601929081019061487d565b509098975050505050505050565b600080600080604085870312156148c8578182fd5b843567ffffffffffffffff808211156148df578384fd5b818701915087601f8301126148f2578384fd5b813581811115614900578485fd5b886020610140830285010111156147e1578485fd5b60006020808385031215614927578182fd5b823567ffffffffffffffff81111561493d578283fd5b8301601f8101851361494d578283fd5b803561495b6141598261582b565b81815283810190838501610140808502860187018a101561497a578788fd5b8795505b848610156148a5576149908a83614352565b845260019590950194928601929081019061497e565b6000602082840312156149b7578081fd5b815161231481615888565b6000806000606084860312156149d6578081fd5b83356149e181615888565b925060208401356149f181615888565b929592945050506040919091013590565b60006101808284031215614a14578081fd5b6123148383614265565b600080828403610200811215614a32578283fd5b614a3c8585614265565b925060807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8082011215614a6d578182fd5b50610180830190509250929050565b60008060006102208486031215614a91578081fd5b614a9b8585614265565b9250614aab856101808601614419565b9150610200840135614abc816158c5565b809150509250925092565b60008060008060006102608688031215614adf578283fd5b614ae98787614265565b9450614af9876101808801614419565b9350610200860135614b0a816158c5565b9250610220860135614b1b81615888565b9150610240860135614b2c81615888565b809150509295509295909350565b600080600083850360a0811215614b4f578182fd5b6060811215614b5c578182fd5b50614b676060615804565b84518152602085015160058110614b7c578283fd5b60208201526040850151614b8f816158c5565b60408201526060850151909350614ba5816158c5565b6080850151909250614abc816158aa565b60006101408284031215614bc8578081fd5b6123148383614352565b6000806101c08385031215614be5578182fd5b614bef8484614352565b9150614bff846101408501614419565b90509250929050565b60008060006101e08486031215614c1d578081fd5b614c278585614352565b9250614c37856101408601614419565b91506101c0840135614abc816158c5565b6000806000806000806102408789031215614c61578384fd5b614c6b8888614352565b9550614c7b886101408901614419565b94506101c0870135614c8c816158c5565b93506101e0870135614c9d81615888565b9250610200870135614cae816158aa565b9150610220870135614cbf81615888565b809150509295509295509295565b600060808284031215614cde578081fd5b6123148383614419565b600060208284031215614cf9578081fd5b5051919050565b73ffffffffffffffffffffffffffffffffffffffff169052565b6000815180845260208085019450808401835b83811015614d4b578151151587529582019590820190600101614d2d565b509495945050505050565b80518252602081015160058110614d6957fe5b60208301526040908101516fffffffffffffffffffffffffffffffff16910152565b8035614d96816158b8565b614d9f8161587e565b8252602081013560ff8116808214614db657600080fd5b60208401525060408181013590830152606090810135910152565b6fffffffffffffffffffffffffffffffff169052565b67ffffffffffffffff169052565b7fff0000000000000000000000000000000000000000000000000000000000000094909416845260609290921b7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000001660018401526015830152603582015260550190565b7f190100000000000000000000000000000000000000000000000000000000000081526002810192909252602282015260420190565b90565b73ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152604081019190915260600190565b73ffffffffffffffffffffffffffffffffffffffff9384168152919092166020820152901515604082015260600190565b60006060820173ffffffffffffffffffffffffffffffffffffffff808716845260206060818601528287518085526080870191508289019450855b81811015614f6e578551851683529483019491830191600101614f50565b5050809450505050508215156040830152949350505050565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b73ffffffffffffffffffffffffffffffffffffffff9485168152928416602084015292166040820152606081019190915260800190565b73ffffffffffffffffffffffffffffffffffffffff929092168252602082015260400190565b60608082528451828201819052600091906020906080850190828901855b8281101561504c5761503c848351614d56565b9285019290840190600101615029565b505050848103828601528651808252908201925086820190845b8181101561508957615079858451614dd1565b9383019391830191600101615066565b50505050828103604084015261509f8185614d1a565b9695505050505050565b901515815260200190565b90815260200190565b91825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b92835273ffffffffffffffffffffffffffffffffffffffff918216602084015216604082015260600190565b9a8b5273ffffffffffffffffffffffffffffffffffffffff998a1660208c015297891660408b015295881660608a015293871660808901529190951660a08701526fffffffffffffffffffffffffffffffff94851660c0870152841660e08601529092166101008401526101208301919091526101408201526101600190565b97885273ffffffffffffffffffffffffffffffffffffffff968716602089015294861660408801529285166060870152931660808501526fffffffffffffffffffffffffffffffff92831660a085015290911660c083015260e08201526101000190565b9283526020830191909152604082015260600190565b91825260ff16602082015260400190565b93845260ff9290921660208401526040830152606082015260800190565b7fffffffff0000000000000000000000000000000000000000000000000000000091909116815260200190565b7fffffffff0000000000000000000000000000000000000000000000000000000092909216825273ffffffffffffffffffffffffffffffffffffffff16602082015260400190565b606081016152b88561587e565b938152602081019290925260409091015290565b604081016152d98461587e565b9281526020015290565b60408101600684106152d957fe5b6000602080835283518082850152825b8181101561531d57858101830151858201604001528201615301565b8181111561532e5783604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b6020808252602c908201527f4e61746976654f7264657273466561747572652f4d49534d4154434845445f4160408201527f525241595f4c454e475448530000000000000000000000000000000000000000606082015260800190565b60208082526027908201527f4e61746976654f7264657273466561747572652f4e4f5f434f4e54524143545f60408201527f4f524947494e5300000000000000000000000000000000000000000000000000606082015260800190565b60208082526038908201527f4e61746976654f7264657273466561747572652f4d49534d4154434845445f5060408201527f4149525f4f52444552535f41525241595f4c454e475448530000000000000000606082015260800190565b60208082526024908201527f466978696e546f6b656e5370656e6465722f43414e4e4f545f494e564f4b455f60408201527f53454c4600000000000000000000000000000000000000000000000000000000606082015260800190565b60208082526027908201527f466978696e50726f746f636f6c466565732f45544845525f5452414e5346455260408201527f5f46414c49454400000000000000000000000000000000000000000000000000606082015260800190565b61020081016020840161554f8361554a8388614130565b614d00565b615559818661584b565b90506155686020840182614d00565b506155766040850185615858565b6155836040840182614dd1565b506155916060850185615858565b61559e6060840182614dd1565b506155ac6080850185615858565b6155b96080840182614dd1565b506155c760a085018561584b565b6155d460a0840182614d00565b506155e260c085018561584b565b6155ef60c0840182614d00565b506155fd60e085018561584b565b61560a60e0840182614d00565b5061010061561a8186018661584b565b61562682850182614d00565b5050610120848101359083015261014061564281860186615865565b61564e82850182614de7565b50506101608481013590830152612314610180830184614d8b565b60608101610d0f8284614d56565b60a081016156858286614d56565b6fffffffffffffffffffffffffffffffff841660608301528215156080830152949350505050565b6101c08101602084016156c48361554a8388614130565b6156ce818661584b565b90506156dd6020840182614d00565b506156eb6040850185615858565b6156f86040840182614dd1565b506157066060850185615858565b6157136060840182614dd1565b50615721608085018561584b565b61572e6080840182614d00565b5061573c60a085018561584b565b61574960a0840182614d00565b5061575760c085018561584b565b61576460c0840182614d00565b5060e084013560e083015261010061577e81860186615865565b61578a82850182614de7565b50506101208481013590830152612314610140830184614d8b565b6fffffffffffffffffffffffffffffffff91909116815260200190565b6fffffffffffffffffffffffffffffffff92831681529116602082015260400190565b918252602082015260400190565b63ffffffff91909116815260200190565b60405181810167ffffffffffffffff8111828210171561582357600080fd5b604052919050565b600067ffffffffffffffff821115615841578081fd5b5060209081020190565b6000823561231481615888565b60008235612314816158c5565b6000823567ffffffffffffffff81168114612314578182fd5b6004811061336357fe5b73ffffffffffffffffffffffffffffffffffffffff8116811461336357600080fd5b801515811461336357600080fd5b6004811061336357600080fd5b6fffffffffffffffffffffffffffffffff8116811461336357600080fdfea26469706673582212200d4fa0cd807b502aa06dc0a690fcd3107813fa7da68fdc5324ca75ee5340158f64736f6c634300060c0033
Verified Source Code Full Match
Compiler: v0.6.12+commit.27d51765
EVM: istanbul
Optimization: Yes (1000000 runs)
NativeOrdersFeature.sol 98 lines
// 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 "../migrations/LibMigrate.sol";
import "./interfaces/IFeature.sol";
import "./interfaces/INativeOrdersFeature.sol";
import "./native_orders/NativeOrdersSettlement.sol";
/// @dev Feature for interacting with limit and RFQ orders.
contract NativeOrdersFeature is
IFeature,
NativeOrdersSettlement
{
/// @dev Name of this feature.
string public constant override FEATURE_NAME = "LimitOrders";
/// @dev Version of this feature.
uint256 public immutable override FEATURE_VERSION = _encodeVersion(1, 3, 0);
constructor(
address zeroExAddress,
IEtherTokenV06 weth,
IStaking staking,
FeeCollectorController feeCollectorController,
uint32 protocolFeeMultiplier
)
public
NativeOrdersSettlement(
zeroExAddress,
weth,
staking,
feeCollectorController,
protocolFeeMultiplier
)
{
// solhint-disable no-empty-blocks
}
/// @dev Initialize and register this feature.
/// Should be delegatecalled by `Migrate.migrate()`.
/// @return success `LibMigrate.SUCCESS` on success.
function migrate()
external
returns (bytes4 success)
{
_registerFeatureFunction(this.transferProtocolFeesForPools.selector);
_registerFeatureFunction(this.fillLimitOrder.selector);
_registerFeatureFunction(this.fillRfqOrder.selector);
_registerFeatureFunction(this.fillOrKillLimitOrder.selector);
_registerFeatureFunction(this.fillOrKillRfqOrder.selector);
_registerFeatureFunction(this._fillLimitOrder.selector);
_registerFeatureFunction(this._fillRfqOrder.selector);
_registerFeatureFunction(this.cancelLimitOrder.selector);
_registerFeatureFunction(this.cancelRfqOrder.selector);
_registerFeatureFunction(this.batchCancelLimitOrders.selector);
_registerFeatureFunction(this.batchCancelRfqOrders.selector);
_registerFeatureFunction(this.cancelPairLimitOrders.selector);
_registerFeatureFunction(this.cancelPairLimitOrdersWithSigner.selector);
_registerFeatureFunction(this.batchCancelPairLimitOrders.selector);
_registerFeatureFunction(this.batchCancelPairLimitOrdersWithSigner.selector);
_registerFeatureFunction(this.cancelPairRfqOrders.selector);
_registerFeatureFunction(this.cancelPairRfqOrdersWithSigner.selector);
_registerFeatureFunction(this.batchCancelPairRfqOrders.selector);
_registerFeatureFunction(this.batchCancelPairRfqOrdersWithSigner.selector);
_registerFeatureFunction(this.getLimitOrderInfo.selector);
_registerFeatureFunction(this.getRfqOrderInfo.selector);
_registerFeatureFunction(this.getLimitOrderHash.selector);
_registerFeatureFunction(this.getRfqOrderHash.selector);
_registerFeatureFunction(this.getProtocolFeeMultiplier.selector);
_registerFeatureFunction(this.registerAllowedRfqOrigins.selector);
_registerFeatureFunction(this.getLimitOrderRelevantState.selector);
_registerFeatureFunction(this.getRfqOrderRelevantState.selector);
_registerFeatureFunction(this.batchGetLimitOrderRelevantStates.selector);
_registerFeatureFunction(this.batchGetRfqOrderRelevantStates.selector);
_registerFeatureFunction(this.registerAllowedOrderSigner.selector);
_registerFeatureFunction(this.isValidOrderSigner.selector);
return LibMigrate.MIGRATE_SUCCESS;
}
}
LibMigrate.sol 52 lines
// 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-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "../errors/LibOwnableRichErrors.sol";
library LibMigrate {
/// @dev Magic bytes returned by a migrator to indicate success.
/// This is `keccack('MIGRATE_SUCCESS')`.
bytes4 internal constant MIGRATE_SUCCESS = 0x2c64c5ef;
using LibRichErrorsV06 for bytes;
/// @dev Perform a delegatecall and ensure it returns the magic bytes.
/// @param target The call target.
/// @param data The call data.
function delegatecallMigrateFunction(
address target,
bytes memory data
)
internal
{
(bool success, bytes memory resultData) = target.delegatecall(data);
if (!success ||
resultData.length != 32 ||
abi.decode(resultData, (bytes4)) != MIGRATE_SUCCESS)
{
LibOwnableRichErrors.MigrateCallFailedError(target, resultData).rrevert();
}
}
}
LibRichErrorsV06.sol 56 lines
// 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))
}
}
}
LibOwnableRichErrors.sol 63 lines
// 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 LibOwnableRichErrors {
// solhint-disable func-name-mixedcase
function OnlyOwnerError(
address sender,
address owner
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OnlyOwnerError(address,address)")),
sender,
owner
);
}
function TransferOwnerToZeroError()
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("TransferOwnerToZeroError()"))
);
}
function MigrateCallFailedError(address target, bytes memory resultData)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("MigrateCallFailedError(address,bytes)")),
target,
resultData
);
}
}
IFeature.sol 34 lines
// 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;
/// @dev Basic interface for a feature contract.
interface IFeature {
// solhint-disable func-name-mixedcase
/// @dev The name of this feature set.
function FEATURE_NAME() external view returns (string memory name);
/// @dev The version of this feature set.
function FEATURE_VERSION() external view returns (uint256 version);
}
INativeOrdersFeature.sol 438 lines
// 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 "../libs/LibSignature.sol";
import "../libs/LibNativeOrder.sol";
import "./INativeOrdersEvents.sol";
/// @dev Feature for interacting with limit orders.
interface INativeOrdersFeature is
INativeOrdersEvents
{
/// @dev Transfers protocol fees from the `FeeCollector` pools into
/// the staking contract.
/// @param poolIds Staking pool IDs
function transferProtocolFeesForPools(bytes32[] calldata poolIds)
external;
/// @dev Fill a limit order. The taker and sender will be the caller.
/// @param order The limit order. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// the caller.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token amount to fill this order with.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillLimitOrder(
LibNativeOrder.LimitOrder calldata order,
LibSignature.Signature calldata signature,
uint128 takerTokenFillAmount
)
external
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);
/// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.
/// The taker will be the caller.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token amount to fill this order with.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillRfqOrder(
LibNativeOrder.RfqOrder calldata order,
LibSignature.Signature calldata signature,
uint128 takerTokenFillAmount
)
external
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);
/// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.
/// The taker will be the caller. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// the caller.
/// @param order The limit order.
/// @param signature The order signature.
/// @param takerTokenFillAmount How much taker token to fill this order with.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillOrKillLimitOrder(
LibNativeOrder.LimitOrder calldata order,
LibSignature.Signature calldata signature,
uint128 takerTokenFillAmount
)
external
payable
returns (uint128 makerTokenFilledAmount);
/// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.
/// The taker will be the caller.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount How much taker token to fill this order with.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillOrKillRfqOrder(
LibNativeOrder.RfqOrder calldata order,
LibSignature.Signature calldata signature,
uint128 takerTokenFillAmount
)
external
returns (uint128 makerTokenFilledAmount);
/// @dev Fill a limit order. Internal variant. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// `msg.sender` (not `sender`).
/// @param order The limit order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token to fill this order with.
/// @param taker The order taker.
/// @param sender The order sender.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function _fillLimitOrder(
LibNativeOrder.LimitOrder calldata order,
LibSignature.Signature calldata signature,
uint128 takerTokenFillAmount,
address taker,
address sender
)
external
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);
/// @dev Fill an RFQ order. Internal variant.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token to fill this order with.
/// @param taker The order taker.
/// @param useSelfBalance Whether to use the ExchangeProxy's transient
/// balance of taker tokens to fill the order.
/// @param recipient The recipient of the maker tokens.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function _fillRfqOrder(
LibNativeOrder.RfqOrder calldata order,
LibSignature.Signature calldata signature,
uint128 takerTokenFillAmount,
address taker,
bool useSelfBalance,
address recipient
)
external
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount);
/// @dev Cancel a single limit order. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param order The limit order.
function cancelLimitOrder(LibNativeOrder.LimitOrder calldata order)
external;
/// @dev Cancel a single RFQ order. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param order The RFQ order.
function cancelRfqOrder(LibNativeOrder.RfqOrder calldata order)
external;
/// @dev Mark what tx.origin addresses are allowed to fill an order that
/// specifies the message sender as its txOrigin.
/// @param origins An array of origin addresses to update.
/// @param allowed True to register, false to unregister.
function registerAllowedRfqOrigins(address[] memory origins, bool allowed)
external;
/// @dev Cancel multiple limit orders. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param orders The limit orders.
function batchCancelLimitOrders(LibNativeOrder.LimitOrder[] calldata orders)
external;
/// @dev Cancel multiple RFQ orders. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param orders The RFQ orders.
function batchCancelRfqOrders(LibNativeOrder.RfqOrder[] calldata orders)
external;
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairLimitOrders(
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
external;
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same maker and pair require the
/// new salt to be >= the old salt.
/// @param maker The maker for which to cancel.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairLimitOrdersWithSigner(
address maker,
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
external;
/// @dev Cancel all limit orders for a given maker and pairs with salts less
/// than the values provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairLimitOrders(
IERC20TokenV06[] calldata makerTokens,
IERC20TokenV06[] calldata takerTokens,
uint256[] calldata minValidSalts
)
external;
/// @dev Cancel all limit orders for a given maker and pairs with salts less
/// than the values provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same maker and pair require the
/// new salt to be >= the old salt.
/// @param maker The maker for which to cancel.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairLimitOrdersWithSigner(
address maker,
IERC20TokenV06[] memory makerTokens,
IERC20TokenV06[] memory takerTokens,
uint256[] memory minValidSalts
)
external;
/// @dev Cancel all RFQ orders for a given maker and pair with a salt less
/// than the value provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairRfqOrders(
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
external;
/// @dev Cancel all RFQ orders for a given maker and pair with a salt less
/// than the value provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same maker and pair require the
/// new salt to be >= the old salt.
/// @param maker The maker for which to cancel.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairRfqOrdersWithSigner(
address maker,
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
external;
/// @dev Cancel all RFQ orders for a given maker and pairs with salts less
/// than the values provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairRfqOrders(
IERC20TokenV06[] calldata makerTokens,
IERC20TokenV06[] calldata takerTokens,
uint256[] calldata minValidSalts
)
external;
/// @dev Cancel all RFQ orders for a given maker and pairs with salts less
/// than the values provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same maker and pair require the
/// new salt to be >= the old salt.
/// @param maker The maker for which to cancel.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairRfqOrdersWithSigner(
address maker,
IERC20TokenV06[] memory makerTokens,
IERC20TokenV06[] memory takerTokens,
uint256[] memory minValidSalts
)
external;
/// @dev Get the order info for a limit order.
/// @param order The limit order.
/// @return orderInfo Info about the order.
function getLimitOrderInfo(LibNativeOrder.LimitOrder calldata order)
external
view
returns (LibNativeOrder.OrderInfo memory orderInfo);
/// @dev Get the order info for an RFQ order.
/// @param order The RFQ order.
/// @return orderInfo Info about the order.
function getRfqOrderInfo(LibNativeOrder.RfqOrder calldata order)
external
view
returns (LibNativeOrder.OrderInfo memory orderInfo);
/// @dev Get the canonical hash of a limit order.
/// @param order The limit order.
/// @return orderHash The order hash.
function getLimitOrderHash(LibNativeOrder.LimitOrder calldata order)
external
view
returns (bytes32 orderHash);
/// @dev Get the canonical hash of an RFQ order.
/// @param order The RFQ order.
/// @return orderHash The order hash.
function getRfqOrderHash(LibNativeOrder.RfqOrder calldata order)
external
view
returns (bytes32 orderHash);
/// @dev Get the protocol fee multiplier. This should be multiplied by the
/// gas price to arrive at the required protocol fee to fill a native order.
/// @return multiplier The protocol fee multiplier.
function getProtocolFeeMultiplier()
external
view
returns (uint32 multiplier);
/// @dev Get order info, fillable amount, and signature validity for a limit order.
/// Fillable amount is determined using balances and allowances of the maker.
/// @param order The limit order.
/// @param signature The order signature.
/// @return orderInfo Info about the order.
/// @return actualFillableTakerTokenAmount How much of the order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValid Whether the signature is valid.
function getLimitOrderRelevantState(
LibNativeOrder.LimitOrder calldata order,
LibSignature.Signature calldata signature
)
external
view
returns (
LibNativeOrder.OrderInfo memory orderInfo,
uint128 actualFillableTakerTokenAmount,
bool isSignatureValid
);
/// @dev Get order info, fillable amount, and signature validity for an RFQ order.
/// Fillable amount is determined using balances and allowances of the maker.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @return orderInfo Info about the order.
/// @return actualFillableTakerTokenAmount How much of the order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValid Whether the signature is valid.
function getRfqOrderRelevantState(
LibNativeOrder.RfqOrder calldata order,
LibSignature.Signature calldata signature
)
external
view
returns (
LibNativeOrder.OrderInfo memory orderInfo,
uint128 actualFillableTakerTokenAmount,
bool isSignatureValid
);
/// @dev Batch version of `getLimitOrderRelevantState()`, without reverting.
/// Orders that would normally cause `getLimitOrderRelevantState()`
/// to revert will have empty results.
/// @param orders The limit orders.
/// @param signatures The order signatures.
/// @return orderInfos Info about the orders.
/// @return actualFillableTakerTokenAmounts How much of each order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValids Whether each signature is valid for the order.
function batchGetLimitOrderRelevantStates(
LibNativeOrder.LimitOrder[] calldata orders,
LibSignature.Signature[] calldata signatures
)
external
view
returns (
LibNativeOrder.OrderInfo[] memory orderInfos,
uint128[] memory actualFillableTakerTokenAmounts,
bool[] memory isSignatureValids
);
/// @dev Batch version of `getRfqOrderRelevantState()`, without reverting.
/// Orders that would normally cause `getRfqOrderRelevantState()`
/// to revert will have empty results.
/// @param orders The RFQ orders.
/// @param signatures The order signatures.
/// @return orderInfos Info about the orders.
/// @return actualFillableTakerTokenAmounts How much of each order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValids Whether each signature is valid for the order.
function batchGetRfqOrderRelevantStates(
LibNativeOrder.RfqOrder[] calldata orders,
LibSignature.Signature[] calldata signatures
)
external
view
returns (
LibNativeOrder.OrderInfo[] memory orderInfos,
uint128[] memory actualFillableTakerTokenAmounts,
bool[] memory isSignatureValids
);
/// @dev Register a signer who can sign on behalf of msg.sender
/// This allows one to sign on behalf of a contract that calls this function
/// @param signer The address from which you plan to generate signatures
/// @param allowed True to register, false to unregister.
function registerAllowedOrderSigner(
address signer,
bool allowed
)
external;
/// @dev checks if a given address is registered to sign on behalf of a maker address
/// @param maker The maker address encoded in an order (can be a contract)
/// @param signer The address that is providing a signature
function isValidOrderSigner(
address maker,
address signer
)
external
view
returns (bool isAllowed);
}
IERC20TokenV06.sol 96 lines
// 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);
}
LibSignature.sol 152 lines
// 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-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "../../errors/LibSignatureRichErrors.sol";
/// @dev A library for validating signatures.
library LibSignature {
using LibRichErrorsV06 for bytes;
// '\x19Ethereum Signed Message:\n32\x00\x00\x00\x00' in a word.
uint256 private constant ETH_SIGN_HASH_PREFIX =
0x19457468657265756d205369676e6564204d6573736167653a0a333200000000;
/// @dev Exclusive upper limit on ECDSA signatures 'R' values.
/// The valid range is given by fig (282) of the yellow paper.
uint256 private constant ECDSA_SIGNATURE_R_LIMIT =
uint256(0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141);
/// @dev Exclusive upper limit on ECDSA signatures 'S' values.
/// The valid range is given by fig (283) of the yellow paper.
uint256 private constant ECDSA_SIGNATURE_S_LIMIT = ECDSA_SIGNATURE_R_LIMIT / 2 + 1;
/// @dev Allowed signature types.
enum SignatureType {
ILLEGAL,
INVALID,
EIP712,
ETHSIGN
}
/// @dev Encoded EC signature.
struct Signature {
// How to validate the signature.
SignatureType signatureType;
// EC Signature data.
uint8 v;
// EC Signature data.
bytes32 r;
// EC Signature data.
bytes32 s;
}
/// @dev Retrieve the signer of a signature.
/// Throws if the signature can't be validated.
/// @param hash The hash that was signed.
/// @param signature The signature.
/// @return recovered The recovered signer address.
function getSignerOfHash(
bytes32 hash,
Signature memory signature
)
internal
pure
returns (address recovered)
{
// Ensure this is a signature type that can be validated against a hash.
_validateHashCompatibleSignature(hash, signature);
if (signature.signatureType == SignatureType.EIP712) {
// Signed using EIP712
recovered = ecrecover(
hash,
signature.v,
signature.r,
signature.s
);
} else if (signature.signatureType == SignatureType.ETHSIGN) {
// Signed using `eth_sign`
// Need to hash `hash` with "\x19Ethereum Signed Message:\n32" prefix
// in packed encoding.
bytes32 ethSignHash;
assembly {
// Use scratch space
mstore(0, ETH_SIGN_HASH_PREFIX) // length of 28 bytes
mstore(28, hash) // length of 32 bytes
ethSignHash := keccak256(0, 60)
}
recovered = ecrecover(
ethSignHash,
signature.v,
signature.r,
signature.s
);
}
// `recovered` can be null if the signature values are out of range.
if (recovered == address(0)) {
LibSignatureRichErrors.SignatureValidationError(
LibSignatureRichErrors.SignatureValidationErrorCodes.BAD_SIGNATURE_DATA,
hash
).rrevert();
}
}
/// @dev Validates that a signature is compatible with a hash signee.
/// @param hash The hash that was signed.
/// @param signature The signature.
function _validateHashCompatibleSignature(
bytes32 hash,
Signature memory signature
)
private
pure
{
// Ensure the r and s are within malleability limits.
if (uint256(signature.r) >= ECDSA_SIGNATURE_R_LIMIT ||
uint256(signature.s) >= ECDSA_SIGNATURE_S_LIMIT)
{
LibSignatureRichErrors.SignatureValidationError(
LibSignatureRichErrors.SignatureValidationErrorCodes.BAD_SIGNATURE_DATA,
hash
).rrevert();
}
// Always illegal signature.
if (signature.signatureType == SignatureType.ILLEGAL) {
LibSignatureRichErrors.SignatureValidationError(
LibSignatureRichErrors.SignatureValidationErrorCodes.ILLEGAL,
hash
).rrevert();
}
// Always invalid.
if (signature.signatureType == SignatureType.INVALID) {
LibSignatureRichErrors.SignatureValidationError(
LibSignatureRichErrors.SignatureValidationErrorCodes.ALWAYS_INVALID,
hash
).rrevert();
}
// Solidity should check that the signature type is within enum range for us
// when abi-decoding.
}
}
LibSignatureRichErrors.sol 69 lines
// 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 LibSignatureRichErrors {
enum SignatureValidationErrorCodes {
ALWAYS_INVALID,
INVALID_LENGTH,
UNSUPPORTED,
ILLEGAL,
WRONG_SIGNER,
BAD_SIGNATURE_DATA
}
// solhint-disable func-name-mixedcase
function SignatureValidationError(
SignatureValidationErrorCodes code,
bytes32 hash,
address signerAddress,
bytes memory signature
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("SignatureValidationError(uint8,bytes32,address,bytes)")),
code,
hash,
signerAddress,
signature
);
}
function SignatureValidationError(
SignatureValidationErrorCodes code,
bytes32 hash
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("SignatureValidationError(uint8,bytes32)")),
code,
hash
);
}
}
LibNativeOrder.sol 320 lines
// 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-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
import "../../errors/LibNativeOrdersRichErrors.sol";
/// @dev A library for common native order operations.
library LibNativeOrder {
using LibSafeMathV06 for uint256;
using LibRichErrorsV06 for bytes;
enum OrderStatus {
INVALID,
FILLABLE,
FILLED,
CANCELLED,
EXPIRED
}
/// @dev A standard OTC or OO limit order.
struct LimitOrder {
IERC20TokenV06 makerToken;
IERC20TokenV06 takerToken;
uint128 makerAmount;
uint128 takerAmount;
uint128 takerTokenFeeAmount;
address maker;
address taker;
address sender;
address feeRecipient;
bytes32 pool;
uint64 expiry;
uint256 salt;
}
/// @dev An RFQ limit order.
struct RfqOrder {
IERC20TokenV06 makerToken;
IERC20TokenV06 takerToken;
uint128 makerAmount;
uint128 takerAmount;
address maker;
address taker;
address txOrigin;
bytes32 pool;
uint64 expiry;
uint256 salt;
}
/// @dev An OTC limit order.
struct OtcOrder {
IERC20TokenV06 makerToken;
IERC20TokenV06 takerToken;
uint128 makerAmount;
uint128 takerAmount;
address maker;
address taker;
address txOrigin;
uint256 expiryAndNonce; // [uint64 expiry, uint64 nonceBucket, uint128 nonce]
}
/// @dev Info on a limit or RFQ order.
struct OrderInfo {
bytes32 orderHash;
OrderStatus status;
uint128 takerTokenFilledAmount;
}
/// @dev Info on an OTC order.
struct OtcOrderInfo {
bytes32 orderHash;
OrderStatus status;
}
uint256 private constant UINT_128_MASK = (1 << 128) - 1;
uint256 private constant UINT_64_MASK = (1 << 64) - 1;
uint256 private constant ADDRESS_MASK = (1 << 160) - 1;
// The type hash for limit orders, which is:
// keccak256(abi.encodePacked(
// "LimitOrder(",
// "address makerToken,",
// "address takerToken,",
// "uint128 makerAmount,",
// "uint128 takerAmount,",
// "uint128 takerTokenFeeAmount,",
// "address maker,",
// "address taker,",
// "address sender,",
// "address feeRecipient,",
// "bytes32 pool,",
// "uint64 expiry,",
// "uint256 salt"
// ")"
// ))
uint256 private constant _LIMIT_ORDER_TYPEHASH =
0xce918627cb55462ddbb85e73de69a8b322f2bc88f4507c52fcad6d4c33c29d49;
// The type hash for RFQ orders, which is:
// keccak256(abi.encodePacked(
// "RfqOrder(",
// "address makerToken,",
// "address takerToken,",
// "uint128 makerAmount,",
// "uint128 takerAmount,",
// "address maker,",
// "address taker,",
// "address txOrigin,",
// "bytes32 pool,",
// "uint64 expiry,",
// "uint256 salt"
// ")"
// ))
uint256 private constant _RFQ_ORDER_TYPEHASH =
0xe593d3fdfa8b60e5e17a1b2204662ecbe15c23f2084b9ad5bae40359540a7da9;
// The type hash for OTC orders, which is:
// keccak256(abi.encodePacked(
// "OtcOrder(",
// "address makerToken,",
// "address takerToken,",
// "uint128 makerAmount,",
// "uint128 takerAmount,",
// "address maker,",
// "address taker,",
// "address txOrigin,",
// "uint256 expiryAndNonce"
// ")"
// ))
uint256 private constant _OTC_ORDER_TYPEHASH =
0x2f754524de756ae72459efbe1ec88c19a745639821de528ac3fb88f9e65e35c8;
/// @dev Get the struct hash of a limit order.
/// @param order The limit order.
/// @return structHash The struct hash of the order.
function getLimitOrderStructHash(LimitOrder memory order)
internal
pure
returns (bytes32 structHash)
{
// The struct hash is:
// keccak256(abi.encode(
// TYPE_HASH,
// order.makerToken,
// order.takerToken,
// order.makerAmount,
// order.takerAmount,
// order.takerTokenFeeAmount,
// order.maker,
// order.taker,
// order.sender,
// order.feeRecipient,
// order.pool,
// order.expiry,
// order.salt,
// ))
assembly {
let mem := mload(0x40)
mstore(mem, _LIMIT_ORDER_TYPEHASH)
// order.makerToken;
mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))
// order.takerToken;
mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))
// order.makerAmount;
mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))
// order.takerAmount;
mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))
// order.takerTokenFeeAmount;
mstore(add(mem, 0xA0), and(UINT_128_MASK, mload(add(order, 0x80))))
// order.maker;
mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))
// order.taker;
mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))
// order.sender;
mstore(add(mem, 0x100), and(ADDRESS_MASK, mload(add(order, 0xE0))))
// order.feeRecipient;
mstore(add(mem, 0x120), and(ADDRESS_MASK, mload(add(order, 0x100))))
// order.pool;
mstore(add(mem, 0x140), mload(add(order, 0x120)))
// order.expiry;
mstore(add(mem, 0x160), and(UINT_64_MASK, mload(add(order, 0x140))))
// order.salt;
mstore(add(mem, 0x180), mload(add(order, 0x160)))
structHash := keccak256(mem, 0x1A0)
}
}
/// @dev Get the struct hash of a RFQ order.
/// @param order The RFQ order.
/// @return structHash The struct hash of the order.
function getRfqOrderStructHash(RfqOrder memory order)
internal
pure
returns (bytes32 structHash)
{
// The struct hash is:
// keccak256(abi.encode(
// TYPE_HASH,
// order.makerToken,
// order.takerToken,
// order.makerAmount,
// order.takerAmount,
// order.maker,
// order.taker,
// order.txOrigin,
// order.pool,
// order.expiry,
// order.salt,
// ))
assembly {
let mem := mload(0x40)
mstore(mem, _RFQ_ORDER_TYPEHASH)
// order.makerToken;
mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))
// order.takerToken;
mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))
// order.makerAmount;
mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))
// order.takerAmount;
mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))
// order.maker;
mstore(add(mem, 0xA0), and(ADDRESS_MASK, mload(add(order, 0x80))))
// order.taker;
mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))
// order.txOrigin;
mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))
// order.pool;
mstore(add(mem, 0x100), mload(add(order, 0xE0)))
// order.expiry;
mstore(add(mem, 0x120), and(UINT_64_MASK, mload(add(order, 0x100))))
// order.salt;
mstore(add(mem, 0x140), mload(add(order, 0x120)))
structHash := keccak256(mem, 0x160)
}
}
/// @dev Get the struct hash of an OTC order.
/// @param order The OTC order.
/// @return structHash The struct hash of the order.
function getOtcOrderStructHash(OtcOrder memory order)
internal
pure
returns (bytes32 structHash)
{
// The struct hash is:
// keccak256(abi.encode(
// TYPE_HASH,
// order.makerToken,
// order.takerToken,
// order.makerAmount,
// order.takerAmount,
// order.maker,
// order.taker,
// order.txOrigin,
// order.expiryAndNonce,
// ))
assembly {
let mem := mload(0x40)
mstore(mem, _OTC_ORDER_TYPEHASH)
// order.makerToken;
mstore(add(mem, 0x20), and(ADDRESS_MASK, mload(order)))
// order.takerToken;
mstore(add(mem, 0x40), and(ADDRESS_MASK, mload(add(order, 0x20))))
// order.makerAmount;
mstore(add(mem, 0x60), and(UINT_128_MASK, mload(add(order, 0x40))))
// order.takerAmount;
mstore(add(mem, 0x80), and(UINT_128_MASK, mload(add(order, 0x60))))
// order.maker;
mstore(add(mem, 0xA0), and(ADDRESS_MASK, mload(add(order, 0x80))))
// order.taker;
mstore(add(mem, 0xC0), and(ADDRESS_MASK, mload(add(order, 0xA0))))
// order.txOrigin;
mstore(add(mem, 0xE0), and(ADDRESS_MASK, mload(add(order, 0xC0))))
// order.expiryAndNonce;
mstore(add(mem, 0x100), mload(add(order, 0xE0)))
structHash := keccak256(mem, 0x120)
}
}
/// @dev Refund any leftover protocol fees in `msg.value` to `msg.sender`.
/// @param ethProtocolFeePaid How much ETH was paid in protocol fees.
function refundExcessProtocolFeeToSender(uint256 ethProtocolFeePaid)
internal
{
if (msg.value > ethProtocolFeePaid && msg.sender != address(this)) {
uint256 refundAmount = msg.value.safeSub(ethProtocolFeePaid);
(bool success,) = msg
.sender
.call{value: refundAmount}("");
if (!success) {
LibNativeOrdersRichErrors.ProtocolFeeRefundFailed(
msg.sender,
refundAmount
).rrevert();
}
}
}
}
LibSafeMathV06.sol 205 lines
// 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);
}
}
LibSafeMathRichErrorsV06.sol 79 lines
// 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
);
}
}
LibNativeOrdersRichErrors.sol 205 lines
// 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 LibNativeOrdersRichErrors {
// solhint-disable func-name-mixedcase
function ProtocolFeeRefundFailed(
address receiver,
uint256 refundAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("ProtocolFeeRefundFailed(address,uint256)")),
receiver,
refundAmount
);
}
function OrderNotFillableByOriginError(
bytes32 orderHash,
address txOrigin,
address orderTxOrigin
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OrderNotFillableByOriginError(bytes32,address,address)")),
orderHash,
txOrigin,
orderTxOrigin
);
}
function OrderNotFillableError(
bytes32 orderHash,
uint8 orderStatus
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OrderNotFillableError(bytes32,uint8)")),
orderHash,
orderStatus
);
}
function OrderNotSignedByMakerError(
bytes32 orderHash,
address signer,
address maker
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OrderNotSignedByMakerError(bytes32,address,address)")),
orderHash,
signer,
maker
);
}
function InvalidSignerError(
address maker,
address signer
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("InvalidSignerError(address,address)")),
maker,
signer
);
}
function OrderNotFillableBySenderError(
bytes32 orderHash,
address sender,
address orderSender
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OrderNotFillableBySenderError(bytes32,address,address)")),
orderHash,
sender,
orderSender
);
}
function OrderNotFillableByTakerError(
bytes32 orderHash,
address taker,
address orderTaker
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OrderNotFillableByTakerError(bytes32,address,address)")),
orderHash,
taker,
orderTaker
);
}
function CancelSaltTooLowError(
uint256 minValidSalt,
uint256 oldMinValidSalt
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("CancelSaltTooLowError(uint256,uint256)")),
minValidSalt,
oldMinValidSalt
);
}
function FillOrKillFailedError(
bytes32 orderHash,
uint256 takerTokenFilledAmount,
uint256 takerTokenFillAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("FillOrKillFailedError(bytes32,uint256,uint256)")),
orderHash,
takerTokenFilledAmount,
takerTokenFillAmount
);
}
function OnlyOrderMakerAllowed(
bytes32 orderHash,
address sender,
address maker
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OnlyOrderMakerAllowed(bytes32,address,address)")),
orderHash,
sender,
maker
);
}
function BatchFillIncompleteError(
bytes32 orderHash,
uint256 takerTokenFilledAmount,
uint256 takerTokenFillAmount
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("BatchFillIncompleteError(bytes32,uint256,uint256)")),
orderHash,
takerTokenFilledAmount,
takerTokenFillAmount
);
}
}
INativeOrdersEvents.sol 126 lines
// 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/IERC20TokenV06.sol";
import "../libs/LibSignature.sol";
import "../libs/LibNativeOrder.sol";
/// @dev Events emitted by NativeOrdersFeature.
interface INativeOrdersEvents {
/// @dev Emitted whenever a `LimitOrder` is filled.
/// @param orderHash The canonical hash of the order.
/// @param maker The maker of the order.
/// @param taker The taker of the order.
/// @param feeRecipient Fee recipient of the order.
/// @param takerTokenFilledAmount How much taker token was filled.
/// @param makerTokenFilledAmount How much maker token was filled.
/// @param protocolFeePaid How much protocol fee was paid.
/// @param pool The fee pool associated with this order.
event LimitOrderFilled(
bytes32 orderHash,
address maker,
address taker,
address feeRecipient,
address makerToken,
address takerToken,
uint128 takerTokenFilledAmount,
uint128 makerTokenFilledAmount,
uint128 takerTokenFeeFilledAmount,
uint256 protocolFeePaid,
bytes32 pool
);
/// @dev Emitted whenever an `RfqOrder` is filled.
/// @param orderHash The canonical hash of the order.
/// @param maker The maker of the order.
/// @param taker The taker of the order.
/// @param takerTokenFilledAmount How much taker token was filled.
/// @param makerTokenFilledAmount How much maker token was filled.
/// @param pool The fee pool associated with this order.
event RfqOrderFilled(
bytes32 orderHash,
address maker,
address taker,
address makerToken,
address takerToken,
uint128 takerTokenFilledAmount,
uint128 makerTokenFilledAmount,
bytes32 pool
);
/// @dev Emitted whenever a limit or RFQ order is cancelled.
/// @param orderHash The canonical hash of the order.
/// @param maker The order maker.
event OrderCancelled(
bytes32 orderHash,
address maker
);
/// @dev Emitted whenever Limit orders are cancelled by pair by a maker.
/// @param maker The maker of the order.
/// @param makerToken The maker token in a pair for the orders cancelled.
/// @param takerToken The taker token in a pair for the orders cancelled.
/// @param minValidSalt The new minimum valid salt an order with this pair must
/// have.
event PairCancelledLimitOrders(
address maker,
address makerToken,
address takerToken,
uint256 minValidSalt
);
/// @dev Emitted whenever RFQ orders are cancelled by pair by a maker.
/// @param maker The maker of the order.
/// @param makerToken The maker token in a pair for the orders cancelled.
/// @param takerToken The taker token in a pair for the orders cancelled.
/// @param minValidSalt The new minimum valid salt an order with this pair must
/// have.
event PairCancelledRfqOrders(
address maker,
address makerToken,
address takerToken,
uint256 minValidSalt
);
/// @dev Emitted when new addresses are allowed or disallowed to fill
/// orders with a given txOrigin.
/// @param origin The address doing the allowing.
/// @param addrs The address being allowed/disallowed.
/// @param allowed Indicates whether the address should be allowed.
event RfqOrderOriginsAllowed(
address origin,
address[] addrs,
bool allowed
);
/// @dev Emitted when new order signers are registered
/// @param maker The maker address that is registering a designated signer.
/// @param signer The address that will sign on behalf of maker.
/// @param allowed Indicates whether the address should be allowed.
event OrderSignerRegistered(
address maker,
address signer,
bool allowed
);
}
NativeOrdersSettlement.sol 624 lines
// 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/IERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol";
import "../../errors/LibNativeOrdersRichErrors.sol";
import "../../fixins/FixinCommon.sol";
import "../../storage/LibNativeOrdersStorage.sol";
import "../../vendor/v3/IStaking.sol";
import "../interfaces/INativeOrdersEvents.sol";
import "../libs/LibSignature.sol";
import "../libs/LibNativeOrder.sol";
import "./NativeOrdersCancellation.sol";
import "./NativeOrdersProtocolFees.sol";
/// @dev Mixin for settling limit and RFQ orders.
abstract contract NativeOrdersSettlement is
INativeOrdersEvents,
NativeOrdersCancellation,
NativeOrdersProtocolFees,
FixinCommon
{
using LibSafeMathV06 for uint128;
using LibRichErrorsV06 for bytes;
/// @dev Params for `_settleOrder()`.
struct SettleOrderInfo {
// Order hash.
bytes32 orderHash;
// Maker of the order.
address maker;
// The address holding the taker tokens.
address payer;
// Recipient of the maker tokens.
address recipient;
// Maker token.
IERC20TokenV06 makerToken;
// Taker token.
IERC20TokenV06 takerToken;
// Maker token amount.
uint128 makerAmount;
// Taker token amount.
uint128 takerAmount;
// Maximum taker token amount to fill.
uint128 takerTokenFillAmount;
// How much taker token amount has already been filled in this order.
uint128 takerTokenFilledAmount;
}
/// @dev Params for `_fillLimitOrderPrivate()`
struct FillLimitOrderPrivateParams {
// The limit order.
LibNativeOrder.LimitOrder order;
// The order signature.
LibSignature.Signature signature;
// Maximum taker token to fill this order with.
uint128 takerTokenFillAmount;
// The order taker.
address taker;
// The order sender.
address sender;
}
/// @dev Params for `_fillRfqOrderPrivate()`
struct FillRfqOrderPrivateParams {
LibNativeOrder.RfqOrder order;
// The order signature.
LibSignature.Signature signature;
// Maximum taker token to fill this order with.
uint128 takerTokenFillAmount;
// The order taker.
address taker;
// Whether to use the Exchange Proxy's balance
// of taker tokens.
bool useSelfBalance;
// The recipient of the maker tokens.
address recipient;
}
// @dev Fill results returned by `_fillLimitOrderPrivate()` and
/// `_fillRfqOrderPrivate()`.
struct FillNativeOrderResults {
uint256 ethProtocolFeePaid;
uint128 takerTokenFilledAmount;
uint128 makerTokenFilledAmount;
uint128 takerTokenFeeFilledAmount;
}
constructor(
address zeroExAddress,
IEtherTokenV06 weth,
IStaking staking,
FeeCollectorController feeCollectorController,
uint32 protocolFeeMultiplier
)
public
NativeOrdersCancellation(zeroExAddress)
NativeOrdersProtocolFees(weth, staking, feeCollectorController, protocolFeeMultiplier)
{
// solhint-disable no-empty-blocks
}
/// @dev Fill a limit order. The taker and sender will be the caller.
/// @param order The limit order. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// the caller.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token amount to fill this order with.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillLimitOrder(
LibNativeOrder.LimitOrder memory order,
LibSignature.Signature memory signature,
uint128 takerTokenFillAmount
)
public
payable
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
_fillLimitOrderPrivate(FillLimitOrderPrivateParams({
order: order,
signature: signature,
takerTokenFillAmount: takerTokenFillAmount,
taker: msg.sender,
sender: msg.sender
}));
LibNativeOrder.refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);
(takerTokenFilledAmount, makerTokenFilledAmount) = (
results.takerTokenFilledAmount,
results.makerTokenFilledAmount
);
}
/// @dev Fill an RFQ order for up to `takerTokenFillAmount` taker tokens.
/// The taker will be the caller. ETH should be attached to pay the
/// protocol fee.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token amount to fill this order with.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillRfqOrder(
LibNativeOrder.RfqOrder memory order,
LibSignature.Signature memory signature,
uint128 takerTokenFillAmount
)
public
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
_fillRfqOrderPrivate(FillRfqOrderPrivateParams({
order: order,
signature: signature,
takerTokenFillAmount: takerTokenFillAmount,
taker: msg.sender,
useSelfBalance: false,
recipient: msg.sender
}));
(takerTokenFilledAmount, makerTokenFilledAmount) = (
results.takerTokenFilledAmount,
results.makerTokenFilledAmount
);
}
/// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.
/// The taker will be the caller. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// the caller.
/// @param order The limit order.
/// @param signature The order signature.
/// @param takerTokenFillAmount How much taker token to fill this order with.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillOrKillLimitOrder(
LibNativeOrder.LimitOrder memory order,
LibSignature.Signature memory signature,
uint128 takerTokenFillAmount
)
public
payable
returns (uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
_fillLimitOrderPrivate(FillLimitOrderPrivateParams({
order: order,
signature: signature,
takerTokenFillAmount: takerTokenFillAmount,
taker: msg.sender,
sender: msg.sender
}));
// Must have filled exactly the amount requested.
if (results.takerTokenFilledAmount < takerTokenFillAmount) {
LibNativeOrdersRichErrors.FillOrKillFailedError(
getLimitOrderHash(order),
results.takerTokenFilledAmount,
takerTokenFillAmount
).rrevert();
}
LibNativeOrder.refundExcessProtocolFeeToSender(results.ethProtocolFeePaid);
makerTokenFilledAmount = results.makerTokenFilledAmount;
}
/// @dev Fill an RFQ order for exactly `takerTokenFillAmount` taker tokens.
/// The taker will be the caller. ETH protocol fees can be
/// attached to this call. Any unspent ETH will be refunded to
/// the caller.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount How much taker token to fill this order with.
/// @return makerTokenFilledAmount How much maker token was filled.
function fillOrKillRfqOrder(
LibNativeOrder.RfqOrder memory order,
LibSignature.Signature memory signature,
uint128 takerTokenFillAmount
)
public
returns (uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
_fillRfqOrderPrivate(FillRfqOrderPrivateParams({
order: order,
signature: signature,
takerTokenFillAmount: takerTokenFillAmount,
taker: msg.sender,
useSelfBalance: false,
recipient: msg.sender
}));
// Must have filled exactly the amount requested.
if (results.takerTokenFilledAmount < takerTokenFillAmount) {
LibNativeOrdersRichErrors.FillOrKillFailedError(
getRfqOrderHash(order),
results.takerTokenFilledAmount,
takerTokenFillAmount
).rrevert();
}
makerTokenFilledAmount = results.makerTokenFilledAmount;
}
/// @dev Fill a limit order. Internal variant. ETH protocol fees can be
/// attached to this call.
/// @param order The limit order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token to fill this order with.
/// @param taker The order taker.
/// @param sender The order sender.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function _fillLimitOrder(
LibNativeOrder.LimitOrder memory order,
LibSignature.Signature memory signature,
uint128 takerTokenFillAmount,
address taker,
address sender
)
public
virtual
payable
onlySelf
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
_fillLimitOrderPrivate(FillLimitOrderPrivateParams(
order,
signature,
takerTokenFillAmount,
taker,
sender
));
(takerTokenFilledAmount, makerTokenFilledAmount) = (
results.takerTokenFilledAmount,
results.makerTokenFilledAmount
);
}
/// @dev Fill an RFQ order. Internal variant.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @param takerTokenFillAmount Maximum taker token to fill this order with.
/// @param taker The order taker.
/// @param useSelfBalance Whether to use the ExchangeProxy's transient
/// balance of taker tokens to fill the order.
/// @param recipient The recipient of the maker tokens.
/// @return takerTokenFilledAmount How much maker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function _fillRfqOrder(
LibNativeOrder.RfqOrder memory order,
LibSignature.Signature memory signature,
uint128 takerTokenFillAmount,
address taker,
bool useSelfBalance,
address recipient
)
public
virtual
onlySelf
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
FillNativeOrderResults memory results =
_fillRfqOrderPrivate(FillRfqOrderPrivateParams(
order,
signature,
takerTokenFillAmount,
taker,
useSelfBalance,
recipient
));
(takerTokenFilledAmount, makerTokenFilledAmount) = (
results.takerTokenFilledAmount,
results.makerTokenFilledAmount
);
}
/// @dev Mark what tx.origin addresses are allowed to fill an order that
/// specifies the message sender as its txOrigin.
/// @param origins An array of origin addresses to update.
/// @param allowed True to register, false to unregister.
function registerAllowedRfqOrigins(
address[] memory origins,
bool allowed
)
external
{
require(msg.sender == tx.origin,
"NativeOrdersFeature/NO_CONTRACT_ORIGINS");
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
for (uint256 i = 0; i < origins.length; i++) {
stor.originRegistry[msg.sender][origins[i]] = allowed;
}
emit RfqOrderOriginsAllowed(msg.sender, origins, allowed);
}
/// @dev Fill a limit order. Private variant. Does not refund protocol fees.
/// @param params Function params.
/// @return results Results of the fill.
function _fillLimitOrderPrivate(FillLimitOrderPrivateParams memory params)
private
returns (FillNativeOrderResults memory results)
{
LibNativeOrder.OrderInfo memory orderInfo = getLimitOrderInfo(params.order);
// Must be fillable.
if (orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {
LibNativeOrdersRichErrors.OrderNotFillableError(
orderInfo.orderHash,
uint8(orderInfo.status)
).rrevert();
}
// Must be fillable by the taker.
if (params.order.taker != address(0) && params.order.taker != params.taker) {
LibNativeOrdersRichErrors.OrderNotFillableByTakerError(
orderInfo.orderHash,
params.taker,
params.order.taker
).rrevert();
}
// Must be fillable by the sender.
if (params.order.sender != address(0) && params.order.sender != params.sender) {
LibNativeOrdersRichErrors.OrderNotFillableBySenderError(
orderInfo.orderHash,
params.sender,
params.order.sender
).rrevert();
}
// Signature must be valid for the order.
{
address signer = LibSignature.getSignerOfHash(
orderInfo.orderHash,
params.signature
);
if (signer != params.order.maker && !isValidOrderSigner(params.order.maker, signer)) {
LibNativeOrdersRichErrors.OrderNotSignedByMakerError(
orderInfo.orderHash,
signer,
params.order.maker
).rrevert();
}
}
// Pay the protocol fee.
results.ethProtocolFeePaid = _collectProtocolFee(params.order.pool);
// Settle between the maker and taker.
(results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(
SettleOrderInfo({
orderHash: orderInfo.orderHash,
maker: params.order.maker,
payer: params.taker,
recipient: params.taker,
makerToken: IERC20TokenV06(params.order.makerToken),
takerToken: IERC20TokenV06(params.order.takerToken),
makerAmount: params.order.makerAmount,
takerAmount: params.order.takerAmount,
takerTokenFillAmount: params.takerTokenFillAmount,
takerTokenFilledAmount: orderInfo.takerTokenFilledAmount
})
);
// Pay the fee recipient.
if (params.order.takerTokenFeeAmount > 0) {
results.takerTokenFeeFilledAmount = uint128(LibMathV06.getPartialAmountFloor(
results.takerTokenFilledAmount,
params.order.takerAmount,
params.order.takerTokenFeeAmount
));
_transferERC20TokensFrom(
params.order.takerToken,
params.taker,
params.order.feeRecipient,
uint256(results.takerTokenFeeFilledAmount)
);
}
emit LimitOrderFilled(
orderInfo.orderHash,
params.order.maker,
params.taker,
params.order.feeRecipient,
address(params.order.makerToken),
address(params.order.takerToken),
results.takerTokenFilledAmount,
results.makerTokenFilledAmount,
results.takerTokenFeeFilledAmount,
results.ethProtocolFeePaid,
params.order.pool
);
}
/// @dev Fill an RFQ order. Private variant.
/// @param params Function params.
/// @return results Results of the fill.
function _fillRfqOrderPrivate(FillRfqOrderPrivateParams memory params)
private
returns (FillNativeOrderResults memory results)
{
LibNativeOrder.OrderInfo memory orderInfo = getRfqOrderInfo(params.order);
// Must be fillable.
if (orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {
LibNativeOrdersRichErrors.OrderNotFillableError(
orderInfo.orderHash,
uint8(orderInfo.status)
).rrevert();
}
{
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
// Must be fillable by the tx.origin.
if (
params.order.txOrigin != tx.origin &&
!stor.originRegistry[params.order.txOrigin][tx.origin]
) {
LibNativeOrdersRichErrors.OrderNotFillableByOriginError(
orderInfo.orderHash,
tx.origin,
params.order.txOrigin
).rrevert();
}
}
// Must be fillable by the taker.
if (params.order.taker != address(0) && params.order.taker != params.taker) {
LibNativeOrdersRichErrors.OrderNotFillableByTakerError(
orderInfo.orderHash,
params.taker,
params.order.taker
).rrevert();
}
// Signature must be valid for the order.
{
address signer = LibSignature.getSignerOfHash(
orderInfo.orderHash,
params.signature
);
if (
signer != params.order.maker &&
!isValidOrderSigner(params.order.maker, signer)
) {
LibNativeOrdersRichErrors.OrderNotSignedByMakerError(
orderInfo.orderHash,
signer,
params.order.maker
).rrevert();
}
}
// Settle between the maker and taker.
(results.takerTokenFilledAmount, results.makerTokenFilledAmount) = _settleOrder(
SettleOrderInfo({
orderHash: orderInfo.orderHash,
maker: params.order.maker,
payer: params.useSelfBalance ? address(this) : params.taker,
recipient: params.recipient,
makerToken: IERC20TokenV06(params.order.makerToken),
takerToken: IERC20TokenV06(params.order.takerToken),
makerAmount: params.order.makerAmount,
takerAmount: params.order.takerAmount,
takerTokenFillAmount: params.takerTokenFillAmount,
takerTokenFilledAmount: orderInfo.takerTokenFilledAmount
})
);
emit RfqOrderFilled(
orderInfo.orderHash,
params.order.maker,
params.taker,
address(params.order.makerToken),
address(params.order.takerToken),
results.takerTokenFilledAmount,
results.makerTokenFilledAmount,
params.order.pool
);
}
/// @dev Settle the trade between an order's maker and taker.
/// @param settleInfo Information needed to execute the settlement.
/// @return takerTokenFilledAmount How much taker token was filled.
/// @return makerTokenFilledAmount How much maker token was filled.
function _settleOrder(SettleOrderInfo memory settleInfo)
private
returns (uint128 takerTokenFilledAmount, uint128 makerTokenFilledAmount)
{
// Clamp the taker token fill amount to the fillable amount.
takerTokenFilledAmount = LibSafeMathV06.min128(
settleInfo.takerTokenFillAmount,
settleInfo.takerAmount.safeSub128(settleInfo.takerTokenFilledAmount)
);
// Compute the maker token amount.
// This should never overflow because the values are all clamped to
// (2^128-1).
makerTokenFilledAmount = uint128(LibMathV06.getPartialAmountFloor(
uint256(takerTokenFilledAmount),
uint256(settleInfo.takerAmount),
uint256(settleInfo.makerAmount)
));
if (takerTokenFilledAmount == 0 || makerTokenFilledAmount == 0) {
// Nothing to do.
return (0, 0);
}
// Update filled state for the order.
LibNativeOrdersStorage
.getStorage()
.orderHashToTakerTokenFilledAmount[settleInfo.orderHash] =
// OK to overwrite the whole word because we shouldn't get to this
// function if the order is cancelled.
settleInfo.takerTokenFilledAmount.safeAdd128(takerTokenFilledAmount);
if (settleInfo.payer == address(this)) {
// Transfer this -> maker.
_transferERC20Tokens(
settleInfo.takerToken,
settleInfo.maker,
takerTokenFilledAmount
);
} else {
// Transfer taker -> maker.
_transferERC20TokensFrom(
settleInfo.takerToken,
settleInfo.payer,
settleInfo.maker,
takerTokenFilledAmount
);
}
// Transfer maker -> recipient.
_transferERC20TokensFrom(
settleInfo.makerToken,
settleInfo.maker,
settleInfo.recipient,
makerTokenFilledAmount
);
}
/// @dev register a signer who can sign on behalf of msg.sender
/// @param signer The address from which you plan to generate signatures
/// @param allowed True to register, false to unregister.
function registerAllowedOrderSigner(
address signer,
bool allowed
)
external
{
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
stor.orderSignerRegistry[msg.sender][signer] = allowed;
emit OrderSignerRegistered(msg.sender, signer, allowed);
}
}
IEtherTokenV06.sol 33 lines
// 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;
}
LibMathV06.sol 229 lines
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2019 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 "./LibSafeMathV06.sol";
import "./errors/LibRichErrorsV06.sol";
import "./errors/LibMathRichErrorsV06.sol";
library LibMathV06 {
using LibSafeMathV06 for uint256;
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// Reverts if rounding error is >= 0.1%
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return partialAmount Partial value of target rounded down.
function safeGetPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
if (isRoundingErrorFloor(
numerator,
denominator,
target
)) {
LibRichErrorsV06.rrevert(LibMathRichErrorsV06.RoundingError(
numerator,
denominator,
target
));
}
partialAmount = numerator.safeMul(target).safeDiv(denominator);
return partialAmount;
}
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// Reverts if rounding error is >= 0.1%
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return partialAmount Partial value of target rounded up.
function safeGetPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
if (isRoundingErrorCeil(
numerator,
denominator,
target
)) {
LibRichErrorsV06.rrevert(LibMathRichErrorsV06.RoundingError(
numerator,
denominator,
target
));
}
// safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// ceil(a / b) = floor((a + b - 1) / b)
// To implement `ceil(a / b)` using safeDiv.
partialAmount = numerator.safeMul(target)
.safeAdd(denominator.safeSub(1))
.safeDiv(denominator);
return partialAmount;
}
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return partialAmount Partial value of target rounded down.
function getPartialAmountFloor(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
partialAmount = numerator.safeMul(target).safeDiv(denominator);
return partialAmount;
}
/// @dev Calculates partial value given a numerator and denominator rounded down.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to calculate partial of.
/// @return partialAmount Partial value of target rounded up.
function getPartialAmountCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (uint256 partialAmount)
{
// safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
// ceil(a / b) = floor((a + b - 1) / b)
// To implement `ceil(a / b)` using safeDiv.
partialAmount = numerator.safeMul(target)
.safeAdd(denominator.safeSub(1))
.safeDiv(denominator);
return partialAmount;
}
/// @dev Checks if rounding error >= 0.1% when rounding down.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return isError Rounding error is present.
function isRoundingErrorFloor(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (bool isError)
{
if (denominator == 0) {
LibRichErrorsV06.rrevert(LibMathRichErrorsV06.DivisionByZeroError());
}
// The absolute rounding error is the difference between the rounded
// value and the ideal value. The relative rounding error is the
// absolute rounding error divided by the absolute value of the
// ideal value. This is undefined when the ideal value is zero.
//
// The ideal value is `numerator * target / denominator`.
// Let's call `numerator * target % denominator` the remainder.
// The absolute error is `remainder / denominator`.
//
// When the ideal value is zero, we require the absolute error to
// be zero. Fortunately, this is always the case. The ideal value is
// zero iff `numerator == 0` and/or `target == 0`. In this case the
// remainder and absolute error are also zero.
if (target == 0 || numerator == 0) {
return false;
}
// Otherwise, we want the relative rounding error to be strictly
// less than 0.1%.
// The relative error is `remainder / (numerator * target)`.
// We want the relative error less than 1 / 1000:
// remainder / (numerator * denominator) < 1 / 1000
// or equivalently:
// 1000 * remainder < numerator * target
// so we have a rounding error iff:
// 1000 * remainder >= numerator * target
uint256 remainder = mulmod(
target,
numerator,
denominator
);
isError = remainder.safeMul(1000) >= numerator.safeMul(target);
return isError;
}
/// @dev Checks if rounding error >= 0.1% when rounding up.
/// @param numerator Numerator.
/// @param denominator Denominator.
/// @param target Value to multiply with numerator/denominator.
/// @return isError Rounding error is present.
function isRoundingErrorCeil(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (bool isError)
{
if (denominator == 0) {
LibRichErrorsV06.rrevert(LibMathRichErrorsV06.DivisionByZeroError());
}
// See the comments in `isRoundingError`.
if (target == 0 || numerator == 0) {
// When either is zero, the ideal value and rounded value are zero
// and there is no rounding error. (Although the relative error
// is undefined.)
return false;
}
// Compute remainder as before
uint256 remainder = mulmod(
target,
numerator,
denominator
);
remainder = denominator.safeSub(remainder) % denominator;
isError = remainder.safeMul(1000) >= numerator.safeMul(target);
return isError;
}
}
LibMathRichErrorsV06.sol 58 lines
// 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 LibMathRichErrorsV06 {
// bytes4(keccak256("DivisionByZeroError()"))
bytes internal constant DIVISION_BY_ZERO_ERROR =
hex"a791837c";
// bytes4(keccak256("RoundingError(uint256,uint256,uint256)"))
bytes4 internal constant ROUNDING_ERROR_SELECTOR =
0x339f3de2;
// solhint-disable func-name-mixedcase
function DivisionByZeroError()
internal
pure
returns (bytes memory)
{
return DIVISION_BY_ZERO_ERROR;
}
function RoundingError(
uint256 numerator,
uint256 denominator,
uint256 target
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
ROUNDING_ERROR_SELECTOR,
numerator,
denominator,
target
);
}
}
FixinCommon.sol 87 lines
// 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-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "../errors/LibCommonRichErrors.sol";
import "../errors/LibOwnableRichErrors.sol";
import "../features/interfaces/IOwnableFeature.sol";
import "../features/interfaces/ISimpleFunctionRegistryFeature.sol";
/// @dev Common feature utilities.
abstract contract FixinCommon {
using LibRichErrorsV06 for bytes;
/// @dev The implementation address of this feature.
address internal immutable _implementation;
/// @dev The caller must be this contract.
modifier onlySelf() virtual {
if (msg.sender != address(this)) {
LibCommonRichErrors.OnlyCallableBySelfError(msg.sender).rrevert();
}
_;
}
/// @dev The caller of this function must be the owner.
modifier onlyOwner() virtual {
{
address owner = IOwnableFeature(address(this)).owner();
if (msg.sender != owner) {
LibOwnableRichErrors.OnlyOwnerError(
msg.sender,
owner
).rrevert();
}
}
_;
}
constructor() internal {
// Remember this feature's original address.
_implementation = address(this);
}
/// @dev Registers a function implemented by this feature at `_implementation`.
/// Can and should only be called within a `migrate()`.
/// @param selector The selector of the function whose implementation
/// is at `_implementation`.
function _registerFeatureFunction(bytes4 selector)
internal
{
ISimpleFunctionRegistryFeature(address(this)).extend(selector, _implementation);
}
/// @dev Encode a feature version as a `uint256`.
/// @param major The major version number of the feature.
/// @param minor The minor version number of the feature.
/// @param revision The revision number of the feature.
/// @return encodedVersion The encoded version number.
function _encodeVersion(uint32 major, uint32 minor, uint32 revision)
internal
pure
returns (uint256 encodedVersion)
{
return (uint256(major) << 64) | (uint256(minor) << 32) | uint256(revision);
}
}
LibCommonRichErrors.sol 49 lines
// 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 LibCommonRichErrors {
// solhint-disable func-name-mixedcase
function OnlyCallableBySelfError(address sender)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("OnlyCallableBySelfError(address)")),
sender
);
}
function IllegalReentrancyError(bytes4 selector, uint256 reentrancyFlags)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
bytes4(keccak256("IllegalReentrancyError(bytes4,uint256)")),
selector,
reentrancyFlags
);
}
}
IOwnableFeature.sol 46 lines
// 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-utils/contracts/src/v06/interfaces/IOwnableV06.sol";
// solhint-disable no-empty-blocks
/// @dev Owner management and migration features.
interface IOwnableFeature is
IOwnableV06
{
/// @dev Emitted when `migrate()` is called.
/// @param caller The caller of `migrate()`.
/// @param migrator The migration contract.
/// @param newOwner The address of the new owner.
event Migrated(address caller, address migrator, address newOwner);
/// @dev Execute a migration function in the context of the ZeroEx contract.
/// The result of the function being called should be the magic bytes
/// 0x2c64c5ef (`keccack('MIGRATE_SUCCESS')`). Only callable by the owner.
/// The owner will be temporarily set to `address(this)` inside the call.
/// Before returning, the owner will be set to `newOwner`.
/// @param target The migrator contract address.
/// @param newOwner The address of the new owner.
/// @param data The call data.
function migrate(address target, bytes calldata data, address newOwner) external;
}
IOwnableV06.sol 37 lines
// 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 IOwnableV06 {
/// @dev Emitted by Ownable when ownership is transferred.
/// @param previousOwner The previous owner of the contract.
/// @param newOwner The new owner of the contract.
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/// @dev Transfers ownership of the contract to a new address.
/// @param newOwner The address that will become the owner.
function transferOwnership(address newOwner) external;
/// @dev The owner of this contract.
/// @return ownerAddress The owner address.
function owner() external view returns (address ownerAddress);
}
ISimpleFunctionRegistryFeature.sol 61 lines
// 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;
/// @dev Basic registry management features.
interface ISimpleFunctionRegistryFeature {
/// @dev A function implementation was updated via `extend()` or `rollback()`.
/// @param selector The function selector.
/// @param oldImpl The implementation contract address being replaced.
/// @param newImpl The replacement implementation contract address.
event ProxyFunctionUpdated(bytes4 indexed selector, address oldImpl, address newImpl);
/// @dev Roll back to a prior implementation of a function.
/// @param selector The function selector.
/// @param targetImpl The address of an older implementation of the function.
function rollback(bytes4 selector, address targetImpl) external;
/// @dev Register or replace a function.
/// @param selector The function selector.
/// @param impl The implementation contract for the function.
function extend(bytes4 selector, address impl) external;
/// @dev Retrieve the length of the rollback history for a function.
/// @param selector The function selector.
/// @return rollbackLength The number of items in the rollback history for
/// the function.
function getRollbackLength(bytes4 selector)
external
view
returns (uint256 rollbackLength);
/// @dev Retrieve an entry in the rollback history for a function.
/// @param selector The function selector.
/// @param idx The index in the rollback history.
/// @return impl An implementation address for the function at
/// index `idx`.
function getRollbackEntryAtIndex(bytes4 selector, uint256 idx)
external
view
returns (address impl);
}
LibNativeOrdersStorage.sol 61 lines
// 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 "./LibStorage.sol";
/// @dev Storage helpers for `NativeOrdersFeature`.
library LibNativeOrdersStorage {
/// @dev Storage bucket for this feature.
struct Storage {
// How much taker token has been filled in order.
// The lower `uint128` is the taker token fill amount.
// The high bit will be `1` if the order was directly cancelled.
mapping(bytes32 => uint256) orderHashToTakerTokenFilledAmount;
// The minimum valid order salt for a given maker and order pair (maker, taker)
// for limit orders.
mapping(address => mapping(address => mapping(address => uint256)))
limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt;
// The minimum valid order salt for a given maker and order pair (maker, taker)
// for RFQ orders.
mapping(address => mapping(address => mapping(address => uint256)))
rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt;
// For a given order origin, which tx.origin addresses are allowed to
// fill the order.
mapping(address => mapping(address => bool)) originRegistry;
// For a given maker address, which addresses are allowed to
// sign on its behalf.
mapping(address => mapping(address => bool)) orderSignerRegistry;
}
/// @dev Get the storage bucket for this contract.
function getStorage() internal pure returns (Storage storage stor) {
uint256 storageSlot = LibStorage.getStorageSlot(
LibStorage.StorageId.NativeOrders
);
// Dip into assembly to change the slot pointed to by the local
// variable `stor`.
// See https://solidity.readthedocs.io/en/v0.6.8/assembly.html?highlight=slot#access-to-external-variables-functions-and-libraries
assembly { stor_slot := storageSlot }
}
}
LibStorage.sol 59 lines
// 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;
/// @dev Common storage helpers
library LibStorage {
/// @dev What to bit-shift a storage ID by to get its slot.
/// This gives us a maximum of 2**128 inline fields in each bucket.
uint256 private constant STORAGE_SLOT_EXP = 128;
/// @dev Storage IDs for feature storage buckets.
/// WARNING: APPEND-ONLY.
enum StorageId {
Proxy,
SimpleFunctionRegistry,
Ownable,
TokenSpender,
TransformERC20,
MetaTransactions,
ReentrancyGuard,
NativeOrders,
OtcOrders
}
/// @dev Get the storage slot given a storage ID. We assign unique, well-spaced
/// slots to storage bucket variables to ensure they do not overlap.
/// See: https://solidity.readthedocs.io/en/v0.6.6/assembly.html#access-to-external-variables-functions-and-libraries
/// @param storageId An entry in `StorageId`
/// @return slot The storage slot.
function getStorageSlot(StorageId storageId)
internal
pure
returns (uint256 slot)
{
// This should never overflow with a reasonable `STORAGE_SLOT_EXP`
// because Solidity will do a range check on `storageId` during the cast.
return (uint256(storageId) + 1) << STORAGE_SLOT_EXP;
}
}
IStaking.sol 25 lines
// 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 IStaking {
function joinStakingPoolAsMaker(bytes32) external;
function payProtocolFee(address, address, uint256) external payable;
}
NativeOrdersCancellation.sol 432 lines
// 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/IERC20TokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "../../errors/LibNativeOrdersRichErrors.sol";
import "../../storage/LibNativeOrdersStorage.sol";
import "../interfaces/INativeOrdersEvents.sol";
import "../libs/LibSignature.sol";
import "../libs/LibNativeOrder.sol";
import "./NativeOrdersInfo.sol";
/// @dev Feature for cancelling limit and RFQ orders.
abstract contract NativeOrdersCancellation is
INativeOrdersEvents,
NativeOrdersInfo
{
using LibRichErrorsV06 for bytes;
/// @dev Highest bit of a uint256, used to flag cancelled orders.
uint256 private constant HIGH_BIT = 1 << 255;
constructor(
address zeroExAddress
)
internal
NativeOrdersInfo(zeroExAddress)
{
// solhint-disable no-empty-blocks
}
/// @dev Cancel a single limit order. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param order The limit order.
function cancelLimitOrder(LibNativeOrder.LimitOrder memory order)
public
{
bytes32 orderHash = getLimitOrderHash(order);
if (msg.sender != order.maker && !isValidOrderSigner(order.maker, msg.sender)) {
LibNativeOrdersRichErrors.OnlyOrderMakerAllowed(
orderHash,
msg.sender,
order.maker
).rrevert();
}
_cancelOrderHash(orderHash, order.maker);
}
/// @dev Cancel a single RFQ order. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param order The RFQ order.
function cancelRfqOrder(LibNativeOrder.RfqOrder memory order)
public
{
bytes32 orderHash = getRfqOrderHash(order);
if (msg.sender != order.maker && !isValidOrderSigner(order.maker, msg.sender)) {
LibNativeOrdersRichErrors.OnlyOrderMakerAllowed(
orderHash,
msg.sender,
order.maker
).rrevert();
}
_cancelOrderHash(orderHash, order.maker);
}
/// @dev Cancel multiple limit orders. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param orders The limit orders.
function batchCancelLimitOrders(LibNativeOrder.LimitOrder[] memory orders)
public
{
for (uint256 i = 0; i < orders.length; ++i) {
cancelLimitOrder(orders[i]);
}
}
/// @dev Cancel multiple RFQ orders. The caller must be the maker or a valid order signer.
/// Silently succeeds if the order has already been cancelled.
/// @param orders The RFQ orders.
function batchCancelRfqOrders(LibNativeOrder.RfqOrder[] memory orders)
public
{
for (uint256 i = 0; i < orders.length; ++i) {
cancelRfqOrder(orders[i]);
}
}
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairLimitOrders(
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
public
{
_cancelPairLimitOrders(msg.sender, makerToken, takerToken, minValidSalt);
}
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param maker the maker for whom the msg.sender is the signer.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairLimitOrdersWithSigner(
address maker,
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
public
{
// verify that the signer is authorized for the maker
if (!isValidOrderSigner(maker, msg.sender)) {
LibNativeOrdersRichErrors.InvalidSignerError(
maker,
msg.sender
).rrevert();
}
_cancelPairLimitOrders(maker, makerToken, takerToken, minValidSalt);
}
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairLimitOrders(
IERC20TokenV06[] memory makerTokens,
IERC20TokenV06[] memory takerTokens,
uint256[] memory minValidSalts
)
public
{
require(
makerTokens.length == takerTokens.length &&
makerTokens.length == minValidSalts.length,
"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS"
);
for (uint256 i = 0; i < makerTokens.length; ++i) {
_cancelPairLimitOrders(
msg.sender,
makerTokens[i],
takerTokens[i],
minValidSalts[i]
);
}
}
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param maker the maker for whom the msg.sender is the signer.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairLimitOrdersWithSigner(
address maker,
IERC20TokenV06[] memory makerTokens,
IERC20TokenV06[] memory takerTokens,
uint256[] memory minValidSalts
)
public
{
require(
makerTokens.length == takerTokens.length &&
makerTokens.length == minValidSalts.length,
"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS"
);
if (!isValidOrderSigner(maker, msg.sender)) {
LibNativeOrdersRichErrors.InvalidSignerError(
maker,
msg.sender
).rrevert();
}
for (uint256 i = 0; i < makerTokens.length; ++i) {
_cancelPairLimitOrders(
maker,
makerTokens[i],
takerTokens[i],
minValidSalts[i]
);
}
}
/// @dev Cancel all RFQ orders for a given maker and pair with a salt less
/// than the value provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairRfqOrders(
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
public
{
_cancelPairRfqOrders(msg.sender, makerToken, takerToken, minValidSalt);
}
/// @dev Cancel all RFQ orders for a given maker and pair with a salt less
/// than the value provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param maker the maker for whom the msg.sender is the signer.
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function cancelPairRfqOrdersWithSigner(
address maker,
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
public
{
if (!isValidOrderSigner(maker, msg.sender)) {
LibNativeOrdersRichErrors.InvalidSignerError(
maker,
msg.sender
).rrevert();
}
_cancelPairRfqOrders(maker, makerToken, takerToken, minValidSalt);
}
/// @dev Cancel all RFQ orders for a given maker and pair with a salt less
/// than the value provided. The caller must be the maker. Subsequent
/// calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairRfqOrders(
IERC20TokenV06[] memory makerTokens,
IERC20TokenV06[] memory takerTokens,
uint256[] memory minValidSalts
)
public
{
require(
makerTokens.length == takerTokens.length &&
makerTokens.length == minValidSalts.length,
"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS"
);
for (uint256 i = 0; i < makerTokens.length; ++i) {
_cancelPairRfqOrders(
msg.sender,
makerTokens[i],
takerTokens[i],
minValidSalts[i]
);
}
}
/// @dev Cancel all RFQ orders for a given maker and pairs with salts less
/// than the values provided. The caller must be a signer registered to the maker.
/// Subsequent calls to this function with the same caller and pair require the
/// new salt to be >= the old salt.
/// @param maker the maker for whom the msg.sender is the signer.
/// @param makerTokens The maker tokens.
/// @param takerTokens The taker tokens.
/// @param minValidSalts The new minimum valid salts.
function batchCancelPairRfqOrdersWithSigner(
address maker,
IERC20TokenV06[] memory makerTokens,
IERC20TokenV06[] memory takerTokens,
uint256[] memory minValidSalts
)
public
{
require(
makerTokens.length == takerTokens.length &&
makerTokens.length == minValidSalts.length,
"NativeOrdersFeature/MISMATCHED_PAIR_ORDERS_ARRAY_LENGTHS"
);
if (!isValidOrderSigner(maker, msg.sender)) {
LibNativeOrdersRichErrors.InvalidSignerError(
maker,
msg.sender
).rrevert();
}
for (uint256 i = 0; i < makerTokens.length; ++i) {
_cancelPairRfqOrders(
maker,
makerTokens[i],
takerTokens[i],
minValidSalts[i]
);
}
}
/// @dev Cancel a limit or RFQ order directly by its order hash.
/// @param orderHash The order's order hash.
/// @param maker The order's maker.
function _cancelOrderHash(bytes32 orderHash, address maker)
private
{
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
// Set the high bit on the raw taker token fill amount to indicate
// a cancel. It's OK to cancel twice.
stor.orderHashToTakerTokenFilledAmount[orderHash] |= HIGH_BIT;
emit OrderCancelled(orderHash, maker);
}
/// @dev Cancel all RFQ orders for a given maker and pair with a salt less
/// than the value provided.
/// @param maker The target maker address
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function _cancelPairRfqOrders(
address maker,
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
private
{
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
uint256 oldMinValidSalt =
stor.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt
[maker]
[address(makerToken)]
[address(takerToken)];
// New min salt must >= the old one.
if (oldMinValidSalt > minValidSalt) {
LibNativeOrdersRichErrors.
CancelSaltTooLowError(minValidSalt, oldMinValidSalt)
.rrevert();
}
stor.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt
[maker]
[address(makerToken)]
[address(takerToken)] = minValidSalt;
emit PairCancelledRfqOrders(
maker,
address(makerToken),
address(takerToken),
minValidSalt
);
}
/// @dev Cancel all limit orders for a given maker and pair with a salt less
/// than the value provided.
/// @param maker The target maker address
/// @param makerToken The maker token.
/// @param takerToken The taker token.
/// @param minValidSalt The new minimum valid salt.
function _cancelPairLimitOrders(
address maker,
IERC20TokenV06 makerToken,
IERC20TokenV06 takerToken,
uint256 minValidSalt
)
private
{
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
uint256 oldMinValidSalt =
stor.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt
[maker]
[address(makerToken)]
[address(takerToken)];
// New min salt must >= the old one.
if (oldMinValidSalt > minValidSalt) {
LibNativeOrdersRichErrors.
CancelSaltTooLowError(minValidSalt, oldMinValidSalt)
.rrevert();
}
stor.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt
[maker]
[address(makerToken)]
[address(takerToken)] = minValidSalt;
emit PairCancelledLimitOrders(
maker,
address(makerToken),
address(takerToken),
minValidSalt
);
}
}
NativeOrdersInfo.sol 414 lines
// 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/IERC20TokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibMathV06.sol";
import "../../fixins/FixinEIP712.sol";
import "../../fixins/FixinTokenSpender.sol";
import "../../storage/LibNativeOrdersStorage.sol";
import "../libs/LibSignature.sol";
import "../libs/LibNativeOrder.sol";
/// @dev Feature for getting info about limit and RFQ orders.
abstract contract NativeOrdersInfo is
FixinEIP712,
FixinTokenSpender
{
using LibSafeMathV06 for uint256;
using LibRichErrorsV06 for bytes;
// @dev Params for `_getActualFillableTakerTokenAmount()`.
struct GetActualFillableTakerTokenAmountParams {
address maker;
IERC20TokenV06 makerToken;
uint128 orderMakerAmount;
uint128 orderTakerAmount;
LibNativeOrder.OrderInfo orderInfo;
}
/// @dev Highest bit of a uint256, used to flag cancelled orders.
uint256 private constant HIGH_BIT = 1 << 255;
constructor(
address zeroExAddress
)
internal
FixinEIP712(zeroExAddress)
{
// solhint-disable no-empty-blocks
}
/// @dev Get the order info for a limit order.
/// @param order The limit order.
/// @return orderInfo Info about the order.
function getLimitOrderInfo(LibNativeOrder.LimitOrder memory order)
public
view
returns (LibNativeOrder.OrderInfo memory orderInfo)
{
// Recover maker and compute order hash.
orderInfo.orderHash = getLimitOrderHash(order);
uint256 minValidSalt = LibNativeOrdersStorage.getStorage()
.limitOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt
[order.maker]
[address(order.makerToken)]
[address(order.takerToken)];
_populateCommonOrderInfoFields(
orderInfo,
order.takerAmount,
order.expiry,
order.salt,
minValidSalt
);
}
/// @dev Get the order info for an RFQ order.
/// @param order The RFQ order.
/// @return orderInfo Info about the order.
function getRfqOrderInfo(LibNativeOrder.RfqOrder memory order)
public
view
returns (LibNativeOrder.OrderInfo memory orderInfo)
{
// Recover maker and compute order hash.
orderInfo.orderHash = getRfqOrderHash(order);
uint256 minValidSalt = LibNativeOrdersStorage.getStorage()
.rfqOrdersMakerToMakerTokenToTakerTokenToMinValidOrderSalt
[order.maker]
[address(order.makerToken)]
[address(order.takerToken)];
_populateCommonOrderInfoFields(
orderInfo,
order.takerAmount,
order.expiry,
order.salt,
minValidSalt
);
// Check for missing txOrigin.
if (order.txOrigin == address(0)) {
orderInfo.status = LibNativeOrder.OrderStatus.INVALID;
}
}
/// @dev Get the canonical hash of a limit order.
/// @param order The limit order.
/// @return orderHash The order hash.
function getLimitOrderHash(LibNativeOrder.LimitOrder memory order)
public
view
returns (bytes32 orderHash)
{
return _getEIP712Hash(
LibNativeOrder.getLimitOrderStructHash(order)
);
}
/// @dev Get the canonical hash of an RFQ order.
/// @param order The RFQ order.
/// @return orderHash The order hash.
function getRfqOrderHash(LibNativeOrder.RfqOrder memory order)
public
view
returns (bytes32 orderHash)
{
return _getEIP712Hash(
LibNativeOrder.getRfqOrderStructHash(order)
);
}
/// @dev Get order info, fillable amount, and signature validity for a limit order.
/// Fillable amount is determined using balances and allowances of the maker.
/// @param order The limit order.
/// @param signature The order signature.
/// @return orderInfo Info about the order.
/// @return actualFillableTakerTokenAmount How much of the order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValid Whether the signature is valid.
function getLimitOrderRelevantState(
LibNativeOrder.LimitOrder memory order,
LibSignature.Signature calldata signature
)
public
view
returns (
LibNativeOrder.OrderInfo memory orderInfo,
uint128 actualFillableTakerTokenAmount,
bool isSignatureValid
)
{
orderInfo = getLimitOrderInfo(order);
actualFillableTakerTokenAmount = _getActualFillableTakerTokenAmount(
GetActualFillableTakerTokenAmountParams({
maker: order.maker,
makerToken: order.makerToken,
orderMakerAmount: order.makerAmount,
orderTakerAmount: order.takerAmount,
orderInfo: orderInfo
})
);
address signerOfHash = LibSignature.getSignerOfHash(orderInfo.orderHash, signature);
isSignatureValid =
(order.maker == signerOfHash) ||
isValidOrderSigner(order.maker, signerOfHash);
}
/// @dev Get order info, fillable amount, and signature validity for an RFQ order.
/// Fillable amount is determined using balances and allowances of the maker.
/// @param order The RFQ order.
/// @param signature The order signature.
/// @return orderInfo Info about the order.
/// @return actualFillableTakerTokenAmount How much of the order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValid Whether the signature is valid.
function getRfqOrderRelevantState(
LibNativeOrder.RfqOrder memory order,
LibSignature.Signature memory signature
)
public
view
returns (
LibNativeOrder.OrderInfo memory orderInfo,
uint128 actualFillableTakerTokenAmount,
bool isSignatureValid
)
{
orderInfo = getRfqOrderInfo(order);
actualFillableTakerTokenAmount = _getActualFillableTakerTokenAmount(
GetActualFillableTakerTokenAmountParams({
maker: order.maker,
makerToken: order.makerToken,
orderMakerAmount: order.makerAmount,
orderTakerAmount: order.takerAmount,
orderInfo: orderInfo
})
);
address signerOfHash = LibSignature.getSignerOfHash(orderInfo.orderHash, signature);
isSignatureValid =
(order.maker == signerOfHash) ||
isValidOrderSigner(order.maker, signerOfHash);
}
/// @dev Batch version of `getLimitOrderRelevantState()`, without reverting.
/// Orders that would normally cause `getLimitOrderRelevantState()`
/// to revert will have empty results.
/// @param orders The limit orders.
/// @param signatures The order signatures.
/// @return orderInfos Info about the orders.
/// @return actualFillableTakerTokenAmounts How much of each order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValids Whether each signature is valid for the order.
function batchGetLimitOrderRelevantStates(
LibNativeOrder.LimitOrder[] calldata orders,
LibSignature.Signature[] calldata signatures
)
external
view
returns (
LibNativeOrder.OrderInfo[] memory orderInfos,
uint128[] memory actualFillableTakerTokenAmounts,
bool[] memory isSignatureValids
)
{
require(
orders.length == signatures.length,
"NativeOrdersFeature/MISMATCHED_ARRAY_LENGTHS"
);
orderInfos = new LibNativeOrder.OrderInfo[](orders.length);
actualFillableTakerTokenAmounts = new uint128[](orders.length);
isSignatureValids = new bool[](orders.length);
for (uint256 i = 0; i < orders.length; ++i) {
try
this.getLimitOrderRelevantState(orders[i], signatures[i])
returns (
LibNativeOrder.OrderInfo memory orderInfo,
uint128 actualFillableTakerTokenAmount,
bool isSignatureValid
)
{
orderInfos[i] = orderInfo;
actualFillableTakerTokenAmounts[i] = actualFillableTakerTokenAmount;
isSignatureValids[i] = isSignatureValid;
}
catch {}
}
}
/// @dev Batch version of `getRfqOrderRelevantState()`, without reverting.
/// Orders that would normally cause `getRfqOrderRelevantState()`
/// to revert will have empty results.
/// @param orders The RFQ orders.
/// @param signatures The order signatures.
/// @return orderInfos Info about the orders.
/// @return actualFillableTakerTokenAmounts How much of each order is fillable
/// based on maker funds, in taker tokens.
/// @return isSignatureValids Whether each signature is valid for the order.
function batchGetRfqOrderRelevantStates(
LibNativeOrder.RfqOrder[] calldata orders,
LibSignature.Signature[] calldata signatures
)
external
view
returns (
LibNativeOrder.OrderInfo[] memory orderInfos,
uint128[] memory actualFillableTakerTokenAmounts,
bool[] memory isSignatureValids
)
{
require(
orders.length == signatures.length,
"NativeOrdersFeature/MISMATCHED_ARRAY_LENGTHS"
);
orderInfos = new LibNativeOrder.OrderInfo[](orders.length);
actualFillableTakerTokenAmounts = new uint128[](orders.length);
isSignatureValids = new bool[](orders.length);
for (uint256 i = 0; i < orders.length; ++i) {
try
this.getRfqOrderRelevantState(orders[i], signatures[i])
returns (
LibNativeOrder.OrderInfo memory orderInfo,
uint128 actualFillableTakerTokenAmount,
bool isSignatureValid
)
{
orderInfos[i] = orderInfo;
actualFillableTakerTokenAmounts[i] = actualFillableTakerTokenAmount;
isSignatureValids[i] = isSignatureValid;
}
catch {}
}
}
/// @dev Populate `status` and `takerTokenFilledAmount` fields in
/// `orderInfo`, which use the same code path for both limit and
/// RFQ orders.
/// @param orderInfo `OrderInfo` with `orderHash` and `maker` filled.
/// @param takerAmount The order's taker token amount..
/// @param expiry The order's expiry.
/// @param salt The order's salt.
/// @param salt The minimum valid salt for the maker and pair combination.
function _populateCommonOrderInfoFields(
LibNativeOrder.OrderInfo memory orderInfo,
uint128 takerAmount,
uint64 expiry,
uint256 salt,
uint256 minValidSalt
)
private
view
{
LibNativeOrdersStorage.Storage storage stor =
LibNativeOrdersStorage.getStorage();
// Get the filled and direct cancel state.
{
// The high bit of the raw taker token filled amount will be set
// if the order was cancelled.
uint256 rawTakerTokenFilledAmount =
stor.orderHashToTakerTokenFilledAmount[orderInfo.orderHash];
orderInfo.takerTokenFilledAmount = uint128(rawTakerTokenFilledAmount);
if (orderInfo.takerTokenFilledAmount >= takerAmount) {
orderInfo.status = LibNativeOrder.OrderStatus.FILLED;
return;
}
if (rawTakerTokenFilledAmount & HIGH_BIT != 0) {
orderInfo.status = LibNativeOrder.OrderStatus.CANCELLED;
return;
}
}
// Check for expiration.
if (expiry <= uint64(block.timestamp)) {
orderInfo.status = LibNativeOrder.OrderStatus.EXPIRED;
return;
}
// Check if the order was cancelled by salt.
if (minValidSalt > salt) {
orderInfo.status = LibNativeOrder.OrderStatus.CANCELLED;
return;
}
orderInfo.status = LibNativeOrder.OrderStatus.FILLABLE;
}
/// @dev Calculate the actual fillable taker token amount of an order
/// based on maker allowance and balances.
function _getActualFillableTakerTokenAmount(
GetActualFillableTakerTokenAmountParams memory params
)
private
view
returns (uint128 actualFillableTakerTokenAmount)
{
if (params.orderMakerAmount == 0 || params.orderTakerAmount == 0) {
// Empty order.
return 0;
}
if (params.orderInfo.status != LibNativeOrder.OrderStatus.FILLABLE) {
// Not fillable.
return 0;
}
// Get the fillable maker amount based on the order quantities and
// previously filled amount
uint256 fillableMakerTokenAmount = LibMathV06.getPartialAmountFloor(
uint256(
params.orderTakerAmount
- params.orderInfo.takerTokenFilledAmount
),
uint256(params.orderTakerAmount),
uint256(params.orderMakerAmount)
);
// Clamp it to the amount of maker tokens we can spend on behalf of the
// maker.
fillableMakerTokenAmount = LibSafeMathV06.min256(
fillableMakerTokenAmount,
_getSpendableERC20BalanceOf(params.makerToken, params.maker)
);
// Convert to taker token amount.
return LibMathV06.getPartialAmountCeil(
fillableMakerTokenAmount,
uint256(params.orderMakerAmount),
uint256(params.orderTakerAmount)
).safeDowncastToUint128();
}
/// @dev checks if a given address is registered to sign on behalf of a maker address
/// @param maker The maker address encoded in an order (can be a contract)
/// @param signer The address that is providing a signature
function isValidOrderSigner(
address maker,
address signer
)
public
view
returns (bool isValid)
{
// returns false if it the mapping doesn't exist
return LibNativeOrdersStorage.getStorage()
.orderSignerRegistry
[maker]
[signer];
}
}
FixinEIP712.sol 69 lines
// 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-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "../errors/LibCommonRichErrors.sol";
import "../errors/LibOwnableRichErrors.sol";
/// @dev EIP712 helpers for features.
abstract contract FixinEIP712 {
/// @dev The domain hash separator for the entire exchange proxy.
bytes32 public immutable EIP712_DOMAIN_SEPARATOR;
constructor(address zeroExAddress) internal {
// Compute `EIP712_DOMAIN_SEPARATOR`
{
uint256 chainId;
assembly { chainId := chainid() }
EIP712_DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256(
"EIP712Domain("
"string name,"
"string version,"
"uint256 chainId,"
"address verifyingContract"
")"
),
keccak256("ZeroEx"),
keccak256("1.0.0"),
chainId,
zeroExAddress
)
);
}
}
function _getEIP712Hash(bytes32 structHash)
internal
view
returns (bytes32 eip712Hash)
{
return keccak256(abi.encodePacked(
hex"1901",
EIP712_DOMAIN_SEPARATOR,
structHash
));
}
}
FixinTokenSpender.sol 162 lines
// 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/IEtherTokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
/// @dev Helpers for moving tokens around.
abstract contract FixinTokenSpender {
// Mask of the lower 20 bytes of a bytes32.
uint256 constant private ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;
/// @dev Transfers ERC20 tokens from `owner` to `to`.
/// @param token The token to spend.
/// @param owner The owner of the tokens.
/// @param to The recipient of the tokens.
/// @param amount The amount of `token` to transfer.
function _transferERC20TokensFrom(
IERC20TokenV06 token,
address owner,
address to,
uint256 amount
)
internal
{
require(address(token) != address(this), "FixinTokenSpender/CANNOT_INVOKE_SELF");
assembly {
let ptr := mload(0x40) // free memory pointer
// selector for transferFrom(address,address,uint256)
mstore(ptr, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(ptr, 0x04), and(owner, ADDRESS_MASK))
mstore(add(ptr, 0x24), and(to, ADDRESS_MASK))
mstore(add(ptr, 0x44), amount)
let success := call(
gas(),
and(token, ADDRESS_MASK),
0,
ptr,
0x64,
ptr,
32
)
let rdsize := returndatasize()
// Check for ERC20 success. ERC20 tokens should return a boolean,
// but some don't. We accept 0-length return data as success, or at
// least 32 bytes that starts with a 32-byte boolean true.
success := and(
success, // call itself succeeded
or(
iszero(rdsize), // no return data, or
and(
iszero(lt(rdsize, 32)), // at least 32 bytes
eq(mload(ptr), 1) // starts with uint256(1)
)
)
)
if iszero(success) {
returndatacopy(ptr, 0, rdsize)
revert(ptr, rdsize)
}
}
}
/// @dev Transfers ERC20 tokens from ourselves to `to`.
/// @param token The token to spend.
/// @param to The recipient of the tokens.
/// @param amount The amount of `token` to transfer.
function _transferERC20Tokens(
IERC20TokenV06 token,
address to,
uint256 amount
)
internal
{
require(address(token) != address(this), "FixinTokenSpender/CANNOT_INVOKE_SELF");
assembly {
let ptr := mload(0x40) // free memory pointer
// selector for transfer(address,uint256)
mstore(ptr, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(ptr, 0x04), and(to, ADDRESS_MASK))
mstore(add(ptr, 0x24), amount)
let success := call(
gas(),
and(token, ADDRESS_MASK),
0,
ptr,
0x44,
ptr,
32
)
let rdsize := returndatasize()
// Check for ERC20 success. ERC20 tokens should return a boolean,
// but some don't. We accept 0-length return data as success, or at
// least 32 bytes that starts with a 32-byte boolean true.
success := and(
success, // call itself succeeded
or(
iszero(rdsize), // no return data, or
and(
iszero(lt(rdsize, 32)), // at least 32 bytes
eq(mload(ptr), 1) // starts with uint256(1)
)
)
)
if iszero(success) {
returndatacopy(ptr, 0, rdsize)
revert(ptr, rdsize)
}
}
}
/// @dev Gets the maximum amount of an ERC20 token `token` that can be
/// pulled from `owner` by this address.
/// @param token The token to spend.
/// @param owner The owner of the tokens.
/// @return amount The amount of tokens that can be pulled.
function _getSpendableERC20BalanceOf(
IERC20TokenV06 token,
address owner
)
internal
view
returns (uint256)
{
return LibSafeMathV06.min256(
token.allowance(owner, address(this)),
token.balanceOf(owner)
);
}
}
NativeOrdersProtocolFees.sol 71 lines
// 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/IEtherTokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/errors/LibRichErrorsV06.sol";
import "@0x/contracts-utils/contracts/src/v06/LibSafeMathV06.sol";
import "../../fixins/FixinProtocolFees.sol";
import "../../errors/LibNativeOrdersRichErrors.sol";
import "../../vendor/v3/IStaking.sol";
/// @dev Mixin for protocol fee utility functions.
abstract contract NativeOrdersProtocolFees is
FixinProtocolFees
{
using LibSafeMathV06 for uint256;
using LibRichErrorsV06 for bytes;
constructor(
IEtherTokenV06 weth,
IStaking staking,
FeeCollectorController feeCollectorController,
uint32 protocolFeeMultiplier
)
internal
FixinProtocolFees(weth, staking, feeCollectorController, protocolFeeMultiplier)
{
// solhint-disable no-empty-blocks
}
/// @dev Transfers protocol fees from the `FeeCollector` pools into
/// the staking contract.
/// @param poolIds Staking pool IDs
function transferProtocolFeesForPools(bytes32[] calldata poolIds)
external
{
for (uint256 i = 0; i < poolIds.length; ++i) {
_transferFeesForPool(poolIds[i]);
}
}
/// @dev Get the protocol fee multiplier. This should be multiplied by the
/// gas price to arrive at the required protocol fee to fill a native order.
/// @return multiplier The protocol fee multiplier.
function getProtocolFeeMultiplier()
external
view
returns (uint32 multiplier)
{
return PROTOCOL_FEE_MULTIPLIER;
}
}
FixinProtocolFees.sol 122 lines
// 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/IEtherTokenV06.sol";
import "../external/FeeCollector.sol";
import "../external/FeeCollectorController.sol";
import "../external/LibFeeCollector.sol";
import "../vendor/v3/IStaking.sol";
/// @dev Helpers for collecting protocol fees.
abstract contract FixinProtocolFees {
/// @dev The protocol fee multiplier.
uint32 public immutable PROTOCOL_FEE_MULTIPLIER;
/// @dev The `FeeCollectorController` contract.
FeeCollectorController private immutable FEE_COLLECTOR_CONTROLLER;
/// @dev Hash of the fee collector init code.
bytes32 private immutable FEE_COLLECTOR_INIT_CODE_HASH;
/// @dev The WETH token contract.
IEtherTokenV06 private immutable WETH;
/// @dev The staking contract.
IStaking private immutable STAKING;
constructor(
IEtherTokenV06 weth,
IStaking staking,
FeeCollectorController feeCollectorController,
uint32 protocolFeeMultiplier
)
internal
{
FEE_COLLECTOR_CONTROLLER = feeCollectorController;
FEE_COLLECTOR_INIT_CODE_HASH =
feeCollectorController.FEE_COLLECTOR_INIT_CODE_HASH();
WETH = weth;
STAKING = staking;
PROTOCOL_FEE_MULTIPLIER = protocolFeeMultiplier;
}
/// @dev Collect the specified protocol fee in ETH.
/// The fee is stored in a per-pool fee collector contract.
/// @param poolId The pool ID for which a fee is being collected.
/// @return ethProtocolFeePaid How much protocol fee was collected in ETH.
function _collectProtocolFee(bytes32 poolId)
internal
returns (uint256 ethProtocolFeePaid)
{
uint256 protocolFeePaid = _getSingleProtocolFee();
if (protocolFeePaid == 0) {
// Nothing to do.
return 0;
}
FeeCollector feeCollector = _getFeeCollector(poolId);
(bool success,) = address(feeCollector).call{value: protocolFeePaid}("");
require(success, "FixinProtocolFees/ETHER_TRANSFER_FALIED");
return protocolFeePaid;
}
/// @dev Transfer fees for a given pool to the staking contract.
/// @param poolId Identifies the pool whose fees are being paid.
function _transferFeesForPool(bytes32 poolId)
internal
{
// This will create a FeeCollector contract (if necessary) and wrap
// fees for the pool ID.
FeeCollector feeCollector =
FEE_COLLECTOR_CONTROLLER.prepareFeeCollectorToPayFees(poolId);
// All fees in the fee collector should be in WETH now.
uint256 bal = WETH.balanceOf(address(feeCollector));
if (bal > 1) {
// Leave 1 wei behind to avoid high SSTORE cost of zero-->non-zero.
STAKING.payProtocolFee(
address(feeCollector),
address(feeCollector),
bal - 1);
}
}
/// @dev Compute the CREATE2 address for a fee collector.
/// @param poolId The fee collector's pool ID.
function _getFeeCollector(bytes32 poolId)
internal
view
returns (FeeCollector)
{
return FeeCollector(LibFeeCollector.getFeeCollectorAddress(
address(FEE_COLLECTOR_CONTROLLER),
FEE_COLLECTOR_INIT_CODE_HASH,
poolId
));
}
/// @dev Get the cost of a single protocol fee.
/// @return protocolFeeAmount The protocol fee amount, in ETH/WETH.
function _getSingleProtocolFee()
internal
view
returns (uint256 protocolFeeAmount)
{
return uint256(PROTOCOL_FEE_MULTIPLIER) * tx.gasprice;
}
}
FeeCollector.sol 65 lines
// 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/IEtherTokenV06.sol";
import "@0x/contracts-utils/contracts/src/v06/AuthorizableV06.sol";
import "../vendor/v3/IStaking.sol";
/// @dev The collector contract for protocol fees
contract FeeCollector is AuthorizableV06 {
/// @dev Allow ether transfers to the collector.
receive() external payable { }
constructor() public {
_addAuthorizedAddress(msg.sender);
}
/// @dev Approve the staking contract and join a pool. Only an authority
/// can call this.
/// @param weth The WETH contract.
/// @param staking The staking contract.
/// @param poolId The pool ID this contract is collecting fees for.
function initialize(
IEtherTokenV06 weth,
IStaking staking,
bytes32 poolId
)
external
onlyAuthorized
{
weth.approve(address(staking), type(uint256).max);
staking.joinStakingPoolAsMaker(poolId);
}
/// @dev Convert all held ether to WETH. Only an authority can call this.
/// @param weth The WETH contract.
function convertToWeth(
IEtherTokenV06 weth
)
external
onlyAuthorized
{
if (address(this).balance > 0) {
weth.deposit{value: address(this).balance}();
}
}
}
AuthorizableV06.sol 167 lines
// 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 "./interfaces/IAuthorizableV06.sol";
import "./errors/LibRichErrorsV06.sol";
import "./errors/LibAuthorizableRichErrorsV06.sol";
import "./OwnableV06.sol";
// solhint-disable no-empty-blocks
contract AuthorizableV06 is
OwnableV06,
IAuthorizableV06
{
/// @dev Only authorized addresses can invoke functions with this modifier.
modifier onlyAuthorized {
_assertSenderIsAuthorized();
_;
}
// @dev Whether an address is authorized to call privileged functions.
// @param 0 Address to query.
// @return 0 Whether the address is authorized.
mapping (address => bool) public override authorized;
// @dev Whether an address is authorized to call privileged functions.
// @param 0 Index of authorized address.
// @return 0 Authorized address.
address[] public override authorities;
/// @dev Initializes the `owner` address.
constructor()
public
OwnableV06()
{}
/// @dev Authorizes an address.
/// @param target Address to authorize.
function addAuthorizedAddress(address target)
external
override
onlyOwner
{
_addAuthorizedAddress(target);
}
/// @dev Removes authorizion of an address.
/// @param target Address to remove authorization from.
function removeAuthorizedAddress(address target)
external
override
onlyOwner
{
if (!authorized[target]) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetNotAuthorizedError(target));
}
for (uint256 i = 0; i < authorities.length; i++) {
if (authorities[i] == target) {
_removeAuthorizedAddressAtIndex(target, i);
break;
}
}
}
/// @dev Removes authorizion of an address.
/// @param target Address to remove authorization from.
/// @param index Index of target in authorities array.
function removeAuthorizedAddressAtIndex(
address target,
uint256 index
)
external
override
onlyOwner
{
_removeAuthorizedAddressAtIndex(target, index);
}
/// @dev Gets all authorized addresses.
/// @return Array of authorized addresses.
function getAuthorizedAddresses()
external
override
view
returns (address[] memory)
{
return authorities;
}
/// @dev Reverts if msg.sender is not authorized.
function _assertSenderIsAuthorized()
internal
view
{
if (!authorized[msg.sender]) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.SenderNotAuthorizedError(msg.sender));
}
}
/// @dev Authorizes an address.
/// @param target Address to authorize.
function _addAuthorizedAddress(address target)
internal
{
// Ensure that the target is not the zero address.
if (target == address(0)) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.ZeroCantBeAuthorizedError());
}
// Ensure that the target is not already authorized.
if (authorized[target]) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetAlreadyAuthorizedError(target));
}
authorized[target] = true;
authorities.push(target);
emit AuthorizedAddressAdded(target, msg.sender);
}
/// @dev Removes authorizion of an address.
/// @param target Address to remove authorization from.
/// @param index Index of target in authorities array.
function _removeAuthorizedAddressAtIndex(
address target,
uint256 index
)
internal
{
if (!authorized[target]) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.TargetNotAuthorizedError(target));
}
if (index >= authorities.length) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.IndexOutOfBoundsError(
index,
authorities.length
));
}
if (authorities[index] != target) {
LibRichErrorsV06.rrevert(LibAuthorizableRichErrorsV06.AuthorizedAddressMismatchError(
authorities[index],
target
));
}
delete authorized[target];
authorities[index] = authorities[authorities.length - 1];
authorities.pop();
emit AuthorizedAddressRemoved(target, msg.sender);
}
}
IAuthorizableV06.sol 76 lines
// 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 "./IOwnableV06.sol";
interface IAuthorizableV06 is
IOwnableV06
{
// Event logged when a new address is authorized.
event AuthorizedAddressAdded(
address indexed target,
address indexed caller
);
// Event logged when a currently authorized address is unauthorized.
event AuthorizedAddressRemoved(
address indexed target,
address indexed caller
);
/// @dev Authorizes an address.
/// @param target Address to authorize.
function addAuthorizedAddress(address target)
external;
/// @dev Removes authorizion of an address.
/// @param target Address to remove authorization from.
function removeAuthorizedAddress(address target)
external;
/// @dev Removes authorizion of an address.
/// @param target Address to remove authorization from.
/// @param index Index of target in authorities array.
function removeAuthorizedAddressAtIndex(
address target,
uint256 index
)
external;
/// @dev Gets all authorized addresses.
/// @return authorizedAddresses Array of authorized addresses.
function getAuthorizedAddresses()
external
view
returns (address[] memory authorizedAddresses);
/// @dev Whether an adderss is authorized to call privileged functions.
/// @param addr Address to query.
/// @return isAuthorized Whether the address is authorized.
function authorized(address addr) external view returns (bool isAuthorized);
/// @dev All addresseses authorized to call privileged functions.
/// @param idx Index of authorized address.
/// @return addr Authorized address.
function authorities(uint256 idx) external view returns (address addr);
}
LibAuthorizableRichErrorsV06.sol 120 lines
// 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 LibAuthorizableRichErrorsV06 {
// bytes4(keccak256("AuthorizedAddressMismatchError(address,address)"))
bytes4 internal constant AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR =
0x140a84db;
// bytes4(keccak256("IndexOutOfBoundsError(uint256,uint256)"))
bytes4 internal constant INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR =
0xe9f83771;
// bytes4(keccak256("SenderNotAuthorizedError(address)"))
bytes4 internal constant SENDER_NOT_AUTHORIZED_ERROR_SELECTOR =
0xb65a25b9;
// bytes4(keccak256("TargetAlreadyAuthorizedError(address)"))
bytes4 internal constant TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR =
0xde16f1a0;
// bytes4(keccak256("TargetNotAuthorizedError(address)"))
bytes4 internal constant TARGET_NOT_AUTHORIZED_ERROR_SELECTOR =
0xeb5108a2;
// bytes4(keccak256("ZeroCantBeAuthorizedError()"))
bytes internal constant ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES =
hex"57654fe4";
// solhint-disable func-name-mixedcase
function AuthorizedAddressMismatchError(
address authorized,
address target
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
AUTHORIZED_ADDRESS_MISMATCH_ERROR_SELECTOR,
authorized,
target
);
}
function IndexOutOfBoundsError(
uint256 index,
uint256 length
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
INDEX_OUT_OF_BOUNDS_ERROR_SELECTOR,
index,
length
);
}
function SenderNotAuthorizedError(address sender)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
SENDER_NOT_AUTHORIZED_ERROR_SELECTOR,
sender
);
}
function TargetAlreadyAuthorizedError(address target)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
TARGET_ALREADY_AUTHORIZED_ERROR_SELECTOR,
target
);
}
function TargetNotAuthorizedError(address target)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
TARGET_NOT_AUTHORIZED_ERROR_SELECTOR,
target
);
}
function ZeroCantBeAuthorizedError()
internal
pure
returns (bytes memory)
{
return ZERO_CANT_BE_AUTHORIZED_ERROR_BYTES;
}
}
OwnableV06.sol 69 lines
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2019 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 "./interfaces/IOwnableV06.sol";
import "./errors/LibRichErrorsV06.sol";
import "./errors/LibOwnableRichErrorsV06.sol";
contract OwnableV06 is
IOwnableV06
{
/// @dev The owner of this contract.
/// @return 0 The owner address.
address public override owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
_assertSenderIsOwner();
_;
}
/// @dev Change the owner of this contract.
/// @param newOwner New owner address.
function transferOwnership(address newOwner)
public
override
onlyOwner
{
if (newOwner == address(0)) {
LibRichErrorsV06.rrevert(LibOwnableRichErrorsV06.TransferOwnerToZeroError());
} else {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
function _assertSenderIsOwner()
internal
view
{
if (msg.sender != owner) {
LibRichErrorsV06.rrevert(LibOwnableRichErrorsV06.OnlyOwnerError(
msg.sender,
owner
));
}
}
}
LibOwnableRichErrorsV06.sol 55 lines
// 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 LibOwnableRichErrorsV06 {
// bytes4(keccak256("OnlyOwnerError(address,address)"))
bytes4 internal constant ONLY_OWNER_ERROR_SELECTOR =
0x1de45ad1;
// bytes4(keccak256("TransferOwnerToZeroError()"))
bytes internal constant TRANSFER_OWNER_TO_ZERO_ERROR_BYTES =
hex"e69edc3e";
// solhint-disable func-name-mixedcase
function OnlyOwnerError(
address sender,
address owner
)
internal
pure
returns (bytes memory)
{
return abi.encodeWithSelector(
ONLY_OWNER_ERROR_SELECTOR,
sender,
owner
);
}
function TransferOwnerToZeroError()
internal
pure
returns (bytes memory)
{
return TRANSFER_OWNER_TO_ZERO_ERROR_BYTES;
}
}
FeeCollectorController.sol 93 lines
// 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/IEtherTokenV06.sol";
import "../vendor/v3/IStaking.sol";
import "./FeeCollector.sol";
import "./LibFeeCollector.sol";
/// @dev A contract that manages `FeeCollector` contracts.
contract FeeCollectorController {
/// @dev Hash of the fee collector init code.
bytes32 public immutable FEE_COLLECTOR_INIT_CODE_HASH;
/// @dev The WETH contract.
IEtherTokenV06 private immutable WETH;
/// @dev The staking contract.
IStaking private immutable STAKING;
constructor(
IEtherTokenV06 weth,
IStaking staking
)
public
{
FEE_COLLECTOR_INIT_CODE_HASH = keccak256(type(FeeCollector).creationCode);
WETH = weth;
STAKING = staking;
}
/// @dev Deploy (if needed) a `FeeCollector` contract for `poolId`
/// and wrap its ETH into WETH. Anyone may call this.
/// @param poolId The pool ID associated with the staking pool.
/// @return feeCollector The `FeeCollector` contract instance.
function prepareFeeCollectorToPayFees(bytes32 poolId)
external
returns (FeeCollector feeCollector)
{
feeCollector = getFeeCollector(poolId);
uint256 codeSize;
assembly {
codeSize := extcodesize(feeCollector)
}
if (codeSize == 0) {
// Create and initialize the contract if necessary.
new FeeCollector{salt: bytes32(poolId)}();
feeCollector.initialize(WETH, STAKING, poolId);
}
if (address(feeCollector).balance > 1) {
feeCollector.convertToWeth(WETH);
}
return feeCollector;
}
/// @dev Get the `FeeCollector` contract for a given pool ID. The contract
/// will not actually exist until `prepareFeeCollectorToPayFees()`
/// has been called once.
/// @param poolId The pool ID associated with the staking pool.
/// @return feeCollector The `FeeCollector` contract instance.
function getFeeCollector(bytes32 poolId)
public
view
returns (FeeCollector feeCollector)
{
return FeeCollector(LibFeeCollector.getFeeCollectorAddress(
address(this),
FEE_COLLECTOR_INIT_CODE_HASH,
poolId
));
}
}
LibFeeCollector.sol 44 lines
// 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;
/// @dev Helpers for computing `FeeCollector` contract addresses.
library LibFeeCollector {
/// @dev Compute the CREATE2 address for a fee collector.
/// @param controller The address of the `FeeCollectorController` contract.
/// @param initCodeHash The init code hash of the `FeeCollector` contract.
/// @param poolId The fee collector's pool ID.
function getFeeCollectorAddress(address controller, bytes32 initCodeHash, bytes32 poolId)
internal
pure
returns (address payable feeCollectorAddress)
{
// Compute the CREATE2 address for the fee collector.
return address(uint256(keccak256(abi.encodePacked(
byte(0xff),
controller,
poolId, // pool ID is salt
initCodeHash
))));
}
}
Read Contract
EIP712_DOMAIN_SEPARATOR 0xdab400f3 → bytes32
FEATURE_NAME 0x6ae4b4f7 → string
FEATURE_VERSION 0x031b905c → uint256
PROTOCOL_FEE_MULTIPLIER 0xa0edcef5 → uint32
batchGetLimitOrderRelevantStates 0xf0cb143b → tuple[], uint128[], bool[]
batchGetRfqOrderRelevantStates 0x0c5fa78c → tuple[], uint128[], bool[]
getLimitOrderHash 0x34880c4f → bytes32
getLimitOrderInfo 0xaff818e9 → tuple
getLimitOrderRelevantState 0x1bbc5b8b → tuple, uint128, bool
getProtocolFeeMultiplier 0x487b5c20 → uint32
getRfqOrderHash 0x9782f625 → bytes32
getRfqOrderInfo 0x027de4c8 → tuple
getRfqOrderRelevantState 0x8c010fed → tuple, uint128, bool
isValidOrderSigner 0x6b52a4a8 → bool
Write Contract 22 functions
These functions modify contract state and require a wallet transaction to execute.
_fillLimitOrder 0x56c048d8
tuple order
tuple signature
uint128 takerTokenFillAmount
address taker
address sender
returns: uint128, uint128
_fillRfqOrder 0xeea8a2f2
tuple order
tuple signature
uint128 takerTokenFillAmount
address taker
bool useSelfBalance
address recipient
returns: uint128, uint128
batchCancelLimitOrders 0x73975762
tuple[] orders
batchCancelPairLimitOrders 0x86a0c8d7
address[] makerTokens
address[] takerTokens
uint256[] minValidSalts
batchCancelPairLimitOrdersWithSigner 0x9f0434f5
address maker
address[] makerTokens
address[] takerTokens
uint256[] minValidSalts
batchCancelPairRfqOrders 0x0f0e8cf7
address[] makerTokens
address[] takerTokens
uint256[] minValidSalts
batchCancelPairRfqOrdersWithSigner 0xfd5f995b
address maker
address[] makerTokens
address[] takerTokens
uint256[] minValidSalts
batchCancelRfqOrders 0x9915f953
tuple[] orders
cancelLimitOrder 0x6cc0ff11
tuple order
cancelPairLimitOrders 0xd0a55fb0
address makerToken
address takerToken
uint256 minValidSalt
cancelPairLimitOrdersWithSigner 0xb10a33f4
address maker
address makerToken
address takerToken
uint256 minValidSalt
cancelPairRfqOrders 0x9a4f809c
address makerToken
address takerToken
uint256 minValidSalt
cancelPairRfqOrdersWithSigner 0x935c82a4
address maker
address makerToken
address takerToken
uint256 minValidSalt
cancelRfqOrder 0x30b216f6
tuple order
fillLimitOrder 0x8f0d4785
tuple order
tuple signature
uint128 takerTokenFillAmount
returns: uint128, uint128
fillOrKillLimitOrder 0x2fe2ff52
tuple order
tuple signature
uint128 takerTokenFillAmount
returns: uint128
fillOrKillRfqOrder 0xa71975bf
tuple order
tuple signature
uint128 takerTokenFillAmount
returns: uint128
fillRfqOrder 0x9437e2aa
tuple order
tuple signature
uint128 takerTokenFillAmount
returns: uint128, uint128
migrate 0x8fd3ab80
No parameters
returns: bytes4
registerAllowedOrderSigner 0xea7faa61
address signer
bool allowed
registerAllowedRfqOrigins 0xb09f1fb1
address[] origins
bool allowed
transferProtocolFeesForPools 0x3cd2f026
bytes32[] poolIds
Recent Transactions
This address has 1 on-chain transactions, but only 0.6% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →